Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ce652356a143e4a2753756396e32130edbc60095 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
RoomModel ActorCommunicationTest {

	import etrice.api.types.boolean
	import etrice.api.types.int8
	import etrice.api.types.int16
	import etrice.api.types.int32
	import etrice.api.annotations.TestInstance
	import etrice.api.timer.PTimer
	import etrice.api.timer.ATimerService

	ActorClass ActorCommunicationTest_Top {
		@TestInstance
		Structure {
			ActorRef singleThread_Appl: Appl
			ActorRef timing: ATimerService
			LayerConnection ref singleThread_Appl satisfied_by timing.timer
		}
	}

	/*
	 * On each timing event Tester sends a message with a counter to all Testees
	 * From counter=1-9: each Testee does an expect order
	 * On counter=10: each Testee sends finish message to Tester, that does last expect order
	 */
	ActorClass Appl {
		Structure {
			ActorRef tester: Tester
			ActorRef datadriven_Testee: Datadriven_Testee
			ActorRef eventdriven_Testee: Eventdriven_Testee
			ActorRef async_Testee: Async_Testee
			Binding tester.data_counter and datadriven_Testee.data_counter
			Binding tester.data_counter_finish and datadriven_Testee.counter_finish
			Binding tester.event_counter and eventdriven_Testee.event_counter
			Binding tester.async_counter1 and async_Testee.event_counter
			Binding tester.async_counter2 and async_Testee.data_counter
		}
		Behavior {
		}
	}

	async ActorClass Tester {
		Interface {
			conjugated Port event_counter: Eventdriven_PC
			conjugated Port data_counter: Datadriven_PC
			Port data_counter_finish: Datadriven_PC
			conjugated Port async_counter1: Eventdriven_PC
			conjugated Port async_counter2: Datadriven_PC
		}
		Structure {
			external Port event_counter
			external Port data_counter
			external Port data_counter_finish
			external Port async_counter1
			external Port async_counter2
			SAP timer: PTimer
			Attribute data_caseId: int32
			Attribute event_caseId: int32
			Attribute async_caseId: int32
			Attribute counter: int32
			Attribute finish_counter: int32
			Attribute data_finish_flag: boolean
			Attribute data_result [10]: int16 = "{1,2,3,4,5,6,7,8,9,10}"
			Attribute event_result [10]: int16 = "{101,102,103,104,105,106,107,108,109,110}"
			Attribute async_result [10]: int16 = "{1051,1002,1053,1004,1055,1006,1057,1008,1059,1010}"
		}
		Behavior {
			ctor '''
				etUnit_open("log", "ActorCommunicationTest");
				etUnit_openTestSuite("org.eclipse.etrice.generator.common.tests.ActorCommunicationTest");'''
			dtor '''
				etUnit_closeTestSuite();
				etUnit_close();'''
			StateMachine {
				Transition init: initial -> tester_run {
					action '''
						data_caseId = etUnit_openTestCase("Datadriven ActorCommunicationTest");
						event_caseId = etUnit_openTestCase("Eventdriven ActorCommunicationTest");
						async_caseId = etUnit_openTestCase("Async ActorCommunicationTest");
						
						event_counter.caseId(event_caseId);
						data_counter.caseId(data_caseId);
						async_counter2.caseId(async_caseId);
						
						counter = 0;
						finish_counter = 0;
						data_finish_flag = false;
						EXPECT_ORDER_START(data_caseId, data_result, 10);
						EXPECT_ORDER_START(event_caseId, event_result, 10);
						EXPECT_ORDER_START(async_caseId, async_result, 10);
						timer.startTimer(400);'''
				}
				Transition tr0: tester_run -> tester_run {
					triggers {
						<timeout: timer guard '''counter < 10'''>
					}
					action '''
						counter++;
						event_counter.in1(counter);
						data_counter.in1(counter);
						async_counter1.in1(counter);
						async_counter2.in1(counter);'''
				}
				Transition tr1: tester_run -> tester_run {
					triggers {
						<finish: event_counter>
					}
					action '''
						EXPECT_ORDER_END(event_caseId,"<|MODEL_LOCATION|>", 110);
						etUnit_closeTestCase(event_caseId);
						finish_counter++;'''
				}
				Transition tr2: tester_run -> tester_run {
					guard '''data_counter_finish.finish == true && data_finish_flag == false'''
					action '''
						data_finish_flag = true;
						EXPECT_ORDER_END(data_caseId,"<|MODEL_LOCATION|>", 10);
						etUnit_closeTestCase(data_caseId);
						finish_counter++;'''
				}
				Transition tr3: tester_run -> tester_run {
					triggers {
						<finish: async_counter1>
					}
					action '''
						EXPECT_ORDER_END(async_caseId,"<|MODEL_LOCATION|>", 1010);
						etUnit_closeTestCase(async_caseId);
						finish_counter++;'''
				}
				Transition terminate: my tp0 -> my tp0 {
					guard '''finish_counter == 3'''
					action '''etUnit_testFinished(event_caseId);'''
				}
				TransitionPoint tp0
				State tester_run
			}
		}
	}

	async ActorClass Async_Testee {
		Interface {
			Port event_counter: Eventdriven_PC
			Port data_counter: Datadriven_PC
		}
		Structure {
			external Port event_counter
			external Port data_counter
			Attribute counter: int32
		}
		Behavior {
			StateMachine {
				Transition init: initial -> Idle {
					action '''counter = 0;'''
				}
				Transition tr0: Idle -> Idle {
					guard '''data_counter.in1 != counter && data_counter.in1 % 2 == 1'''
					action '''
						counter = data_counter.in1;
						EXPECT_ORDER(data_counter.caseId,"<|MODEL_LOCATION|>", counter + 1050);'''
				}
				Transition tr1: Idle -> Idle {
					triggers {
						<in1: event_counter guard '''transitionData % 2 == 0 && transitionData < 10'''>
					}
					action '''
						counter = transitionData;
						EXPECT_ORDER(data_counter.caseId,"<|MODEL_LOCATION|>", counter + 1000);'''
				}
				Transition tr2: Idle -> state0 {
					triggers {
						<in1: event_counter guard '''transitionData == 10'''>
					}
					action '''event_counter.finish();'''
				}
				State Idle
				State state0
			}
		}
	}

	ActorClass Eventdriven_Testee {
		Interface {
			Port event_counter: Eventdriven_PC
		}
		Structure {
			external Port event_counter
			Attribute caseId: int32
			Attribute counter: int32
		}
		Behavior {
			StateMachine {
				Transition init: initial -> state0 {
					action '''counter = 0;'''
				}
				Transition tr0: state0 -> state0 {
					triggers {
						<in1: event_counter guard '''transitionData < 10'''>
					}
					action '''EXPECT_ORDER(caseId, "<|MODEL_LOCATION|>", transitionData+100);'''
				}
				Transition tr1: state0 -> state1 {
					triggers {
						<in1: event_counter guard '''transitionData == 10'''>
					}
					action '''event_counter.finish();'''
				}
				Transition tr2: state0 -> state0 {
					triggers {
						<caseId: event_counter>
					}
					action '''caseId = transitionData;'''
				}
				State state0
				State state1
			}
		}
	}

	datadriven ActorClass Datadriven_Testee {
		Interface {
			Port data_counter: Datadriven_PC
			conjugated Port counter_finish: Datadriven_PC
		}
		Structure {
			external Port data_counter
			external Port counter_finish
			Attribute counter: int32
		}
		Behavior {
			StateMachine {
				Transition init: initial -> state0 {
					action '''
						counter = 0;
						counter_finish.finish(false);'''
				}
				Transition tr0: state0 -> state1 {
					guard '''data_counter.in1 == 10'''
					action '''counter_finish.finish(true);'''
				}
				Transition tr1: state0 -> state0 {
					guard '''data_counter.in1 != counter && counter < 10'''
					action '''
						counter = data_counter.in1;
						EXPECT_ORDER(data_counter.caseId, "<|MODEL_LOCATION|>", counter);'''
				}
				State state0
				State state1
			}
		}
	}

	datadriven ProtocolClass Datadriven_PC {
		incoming {
			Message caseId(int32)
			Message in1(int32)
			Message finish(boolean)
		}
	}

	ProtocolClass Eventdriven_PC {
		incoming {
			Message caseId(int32)
			Message in1(int32)
		}
		outgoing {
			Message finish()
		}
	}
}

Back to the top