Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e9529a8a1c214cd7ab5727209be988d16c147b90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
RoomModel TCPTest {

	import etrice.api.types.int16
	import etrice.api.types.int32
	import etrice.api.tcp.DTcpPayload
	import etrice.api.tcp.DTcpControl
	import etrice.api.tcp.PTcpPayload
	import etrice.api.tcp.PTcpControl
	import etrice.api.tcp.ATcpClient
	import etrice.api.tcp.ATcpServer
	import etrice.api.annotations.TestInstance

	ActorClass TCPTestTop {
		@TestInstance
		Structure {
			ActorRef ref0: ATcpServer
			ActorRef ref1 [ 5 ]: ATcpClient
			ActorRef ref2: Tester
			Binding ref2.p1 and ref0.PayloadPort
			Binding ref2.p0 and ref0.ControlPort
			Binding ref2.p2 and ref1.ControlPort
			Binding ref2.p3 and ref1.PayloadPort
		}
		Behavior {
		}
	}

	ActorClass Tester {
		Interface {
			conjugated Port p0: PTcpControl
			conjugated Port p1: PTcpPayload
			conjugated Port p2 [*]: PTcpControl
			conjugated Port p3 [5]: PTcpPayload
		}
		Structure {
			external Port p0
			external Port p1
			external Port p2
			external Port p3
			Attribute controlData: DTcpControl
			Attribute testData: DTcpPayload
			Attribute counter: int32
			Attribute resultPattern: int32
			Attribute pattern: int32
			Attribute caseId: int32
			Attribute resultlist [3]: int16 = "{1,2,3}"
		}
		Behavior {
			ctor '''caseId = etUnit_openAll("log", "TCPTest", "org.eclipse.etrice.generator.java.tests.TCPTest", "TCPTest_case");'''
			dtor '''etUnit_closeAll(caseId);'''
			StateMachine {
				Transition init: initial -> state0 {
					action '''
						EXPECT_ORDER_START(caseId,resultlist,3);
						EXPECT_ORDER(caseId,"<|MODEL_LOCATION|>", 1);
						// open Server
						controlData.setIPAddr("127.0.0.1");
						controlData.setTcpPort(4711);
						p0.open(controlData);'''
				}
				Transition tr0: state0 -> state1 {
					triggers {
						<established: p0>
					}
					action '''
						// open 5 clients
						for (int i=0;i<p2.getReplication();i++){
						p2[i].open(controlData);
						}
						counter=0;'''
				}
				Transition tr1: state1 -> cp cp0 {
					triggers {
						<established: p2>
					}
					action '''counter++;'''
				}
				Transition tr4: cp cp0 -> state1
				Transition tr5: cp cp0 -> state2 {
					cond '''counter>=p2.getReplication()'''
					action '''
						String s=new String ("Test!");
						testData.setData(s.getBytes());
						testData.setLength(s.length());
						testData.setConnectionId(0);
						for (int i=0; i<p3.getReplication();i++){
							p3[i].send(testData);
						}
						counter=0;
						resultPattern=0;'''
				}
				Transition tr8: state2 -> cp cp2 {
					triggers {
						<receive: p3>
					}
					action '''
						resultPattern+=p3.getIndexOf(ifitem);
						//System.out.printf("c:%d, Idx:%d!\n", counter,p3.getIndexOf(ifitem));
						counter++;'''
				}
				Transition tr9: cp cp2 -> state2
				Transition tr10: cp cp2 -> cp cp1 {
					cond '''counter>=p2.getReplication()'''
					action '''
						int i;
						p0.close();
						// close all clients
						p2.close();
						pattern=0;
						for (i=0;i<p2.getReplication();i++){
							pattern+=i;
						}'''
				}
				Transition tr3: state2 -> state2 {
					triggers {
						<receive: p1>
					}
					action '''p1.send(transitionData);'''
				}
				Transition tr2: cp cp1 -> test_failed
				Transition tr6: cp cp1 -> test_ok {
					cond '''pattern==resultPattern'''
				}
				ChoicePoint cp0
				ChoicePoint cp2
				ChoicePoint cp1
				State state0
				State state1
				State state2
				State test_ok {
					entry '''
						EXPECT_ORDER(caseId,"<|MODEL_LOCATION|>", 2);
						EXPECT_ORDER_END(caseId,"<|MODEL_LOCATION|>", 3);
						etUnit_testFinished(caseId);'''
				}
				State test_failed {
					entry '''
						EXPECT_ORDER(caseId,"<|MODEL_LOCATION|>", 0xFF);
						EXPECT_ORDER_END(caseId,"<|MODEL_LOCATION|>", 3);
						etUnit_testFinished(caseId);'''
				}
			}
		}
	}
}

Back to the top