Debian Codegraph @

regression_test/XML/XmlWorkflow/PIPEasp_CNL113334/demo/PipeTest.ttcn

raw
1 /******************************************************************************
2 * Copyright (c) 2000-2021 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 *
12 ******************************************************************************/
13 module PipeTest {
14
15 import from PIPEasp_Types all;
16 import from PIPEasp_PortType all;
17 import from PIPEasp_Templates all;
18
19 type component PIPE_CT {
20 port PIPEasp_PT PIPE_PCO;
21 var ASP_PExecute v_ASP_PExecute;
22 var ASP_PResult v_ASP_PResult;
23 var ASP_PExecuteBinary v_ASP_PExecuteBinary;
24 var ASP_PResultBinary v_ASP_PResultBinary;
25 var ASP_PExecuteBackground v_ASP_PExecuteBackground;
26 var ASP_PStdin v_ASP_PStdin;
27 var ASP_PStdout v_ASP_PStdout;
28 var ASP_PStderr v_ASP_PStderr;
29 var ASP_PStdinBinary v_ASP_PStdinBinary;
30 var ASP_PStdoutBinary v_ASP_PStdoutBinary;
31 var ASP_PStderrBinary v_ASP_PStderrBinary;
32 var ASP_PKill v_ASP_PKill;
33 var ASP_PExit v_ASP_PExit;
34 var ASP_PLineMode v_ASP_PLineMode;
35 var ASP_PError v_ASP_PError;
36 }
37
38 altstep handle_default() runs on PIPE_CT {
39 [] PIPE_PCO.receive(t_PError(?)) -> value v_ASP_PError {
40 log("Error msg received: ", v_ASP_PError);
41 repeat;
42 }
43 [] PIPE_PCO.receive(t_PExit(?)) -> value v_ASP_PExit {
44 if (v_ASP_PExit.code != 0) {
45 setverdict(fail);
46 }
47 repeat;
48 }
49 [] PIPE_PCO.receive(t_PStdout(?)) -> value v_ASP_PStdout {
50 log("Stdout msg received: ", v_ASP_PStdout);
51 repeat;
52 }
53 [] PIPE_PCO.receive(t_PStderr(?)) -> value v_ASP_PStderr {
54 log("Stderr msg received: ", v_ASP_PStderr);
55 repeat;
56 }
57 [] PIPE_PCO.receive(t_PResult(?, ?, ?)) -> value v_ASP_PResult {
58 log("PResult msg received: ", v_ASP_PResult);
59 repeat;
60 }
61 [] PIPE_PCO.receive(t_PResultBinary(?, ?, ?)) -> value v_ASP_PResultBinary {
62 log("PResultBinary msg received: ", v_ASP_PResultBinary);
63 repeat;
64 }
65 }
66
67 testcase TC_basic() runs on PIPE_CT {
68 map(self:PIPE_PCO, system:PIPE_PCO);
69
70 var default default_as := activate(handle_default());
71 timer t_guard;
72
73 PIPE_PCO.send(t_PKill(-10)); // will result in: PError: No process executing
74 PIPE_PCO.send(t_PLineMode(false));
75 PIPE_PCO.send(t_PLineMode(true));
76
77 // wait for response
78 t_guard.start(5.0);
79 alt {
80 [] t_guard.timeout {
81 log("Timer expired, continue...");
82 }
83 }
84
85 /*// These cannot be sent:
86 log("Sending forbidden messages...");
87 PIPE_PCO.send(t_PResult("Dummy stdout", "Dummy stderr", 123));
88 PIPE_PCO.send(t_PResultBinary('1234'O, 'ABCD'O, 123));
89 PIPE_PCO.send(t_PStdout("Dummy stdout"));
90 PIPE_PCO.send(t_PStderr("Dummy stderr"));
91 PIPE_PCO.send(t_PStdoutBinary('ABCDEF'O));
92 PIPE_PCO.send(t_PStderrBinary('12345678'O));
93 PIPE_PCO.send(t_PError("Dummy error"));
94 PIPE_PCO.send(t_PExit(123));
95 log("Forbidden messages sent.");
96 t_guard.start(5.0);
97 alt {
98 [] t_guard.timeout {
99 log("Timer expired, continue...");
100 }
101 }
102 */
103
104 // no such file, ExitCode: 512:
105 PIPE_PCO.send(t_PExecuteBackground("neditxxx"));
106 t_guard.start(5.0);
107 alt {
108 [] t_guard.timeout {
109 log("Timer expired, continue...");
110 }
111 }
112 // OK, but Exitcode is 256
113 PIPE_PCO.send(t_PExecuteBackground("nedit -v"));
114 t_guard.start(5.0);
115 alt {
116 [] t_guard.timeout {
117 log("Timer expired, continue...");
118 }
119 }
120
121 // Will exit if not closed manually within 5 sec
122 PIPE_PCO.send(t_PExecuteBackground("nedit xxx"));
123 PIPE_PCO.send(t_PStdinBinary('ABCD'O));
124 PIPE_PCO.send(t_PStdin("abcd"));
125
126 t_guard.start(5.0);
127 alt {
128 [] t_guard.timeout {
129 log("Timer expired, continue...");
130 }
131 }
132
133 // Kill nedit if not closed, otherwise: No process executing is received
134 PIPE_PCO.send(t_PKill(9));
135
136 // If nedit is killed: exitcode: 9, otherwise: 0
137 t_guard.start(5.0);
138 alt {
139 [] t_guard.timeout {
140 log("Timer expired, continue...");
141 }
142 }
143
144 // start shell and execute commands:
145 PIPE_PCO.send(t_PExecuteBackground("tcsh"));
146 PIPE_PCO.send(t_PStdin("ls"));
147 PIPE_PCO.send(t_PStdinBinary('ABCD'O));
148 PIPE_PCO.send(t_PStdin("abcd"));
149
150 t_guard.start(5.0);
151 alt {
152 [] t_guard.timeout {
153 log("Timer expired, continue...");
154 }
155 }
156
157 // execute more commands, then exit the shell, exitcode: 0
158 PIPE_PCO.send(t_PStdin("ls -ltr"));
159 PIPE_PCO.send(t_PStdin("exit"));
160
161 t_guard.start(5.0);
162 alt {
163 [] t_guard.timeout {
164 log("Timer expired, continue...");
165 }
166 }
167
168 // other way to execute shell commands, exitcodes: 0
169 PIPE_PCO.send(t_PExecute("tcsh", "ls a*;exit"));
170 // this should return PError: command already executing:
171 PIPE_PCO.send(t_PExecute("echo XXX", ""));
172 t_guard.start(5.0);
173 alt {
174 [] t_guard.timeout {
175 log("Timer expired, continue...");
176 }
177 }
178
179 // start nedit, should be stopped manually
180 // execution stops here until nedit exits with 0
181 PIPE_PCO.send(t_PExecute("nedit yyy_PLEASE_CLOSE_MANUALLY", "abcd"));
182 PIPE_PCO.send(t_PStdin("ls -ltr")); // should get a PError for this
183
184 // exit code 0
185 t_guard.start(5.0);
186 alt {
187 [] t_guard.timeout {
188 log("Timer expired, continue...");
189 }
190 }
191
192 // same, but with binary data
193 PIPE_PCO.send(t_PExecuteBinary("nedit zzz", 'abcd'O));
194
195 t_guard.start(5.0);
196 alt {
197 [] t_guard.timeout {
198 log("Timer expired, continue...");
199 }
200 }
201 // This should kill the nedit process.
202 PIPE_PCO.send(t_PKill(9));
203
204 // wait 10 sec then exit the testcase
205 t_guard.start(10.0);
206 alt {
207 [] t_guard.timeout {
208 log("Timer expired, exiting...");
209 }
210 }
211 setverdict(pass);
212 }
213
214 testcase TC_executeSomeUnixCommands() runs on PIPE_CT {
215 map(self:PIPE_PCO, system:PIPE_PCO);
216
217 PIPE_PCO.send(t_PLineMode(false));
218 PIPE_PCO.send(t_PExecute("echo shaap", ""));
219 PIPE_PCO.receive(t_PResult(?,?,?));
220 PIPE_PCO.send(t_PLineMode(true));
221
222 PIPE_PCO.send(t_PExecute("/bin/ls -l PipeTest.ttcn", ""));
223 PIPE_PCO.receive(t_PResult(?,?,?));
224
225 PIPE_PCO.send(t_PExecuteBinary("echo foo", ''O));
226 PIPE_PCO.receive(t_PResultBinary(?,?,?));
227 PIPE_PCO.send(t_PKill(9));
228 PIPE_PCO.receive(t_PError(?));
229
230 PIPE_PCO.send(t_PExecuteBackground("tcsh"));
231 PIPE_PCO.send(t_PStdin("barf"));
232 PIPE_PCO.receive(t_PStderr(?));
233 PIPE_PCO.send(t_PStdin("echo 1; echo 2"));
234 PIPE_PCO.receive(t_PStdout(?));
235 PIPE_PCO.receive(t_PStdout(?));
236 PIPE_PCO.send(t_PStdin("echo going...; kill -9 $$"));
237 PIPE_PCO.receive(t_PStdout(?));
238 PIPE_PCO.receive(t_PExit(?));
239
240 setverdict(pass);
241 }
242
243 function WindowNotice(in charstring pl_notice) runs on PIPE_CT {
244
245 var charstring v_WindowCommand := "";
246 PIPE_PCO.send(t_PExecute("sh", "echo $ShellTestDir/ShellNotice.sh; exit"));
247 alt {
248 [] PIPE_PCO.receive(t_PResult(?,?,0)) -> value v_ASP_PResult {
249 v_WindowCommand := v_ASP_PResult.stdout;
250
251 PIPE_PCO.send(t_PExecute(v_WindowCommand, pl_notice));
252 alt {
253 [] PIPE_PCO.receive(t_PResult("",?,0)) -> value v_ASP_PResult {
254 }
255 [] PIPE_PCO.receive {
256 setverdict(fail);
257 }
258 }
259 }
260 [] PIPE_PCO.receive {
261 setverdict(fail);
262 }
263 }
264 }
265
266 function WindowQuestionString(
267 in charstring pl_question,
268 out charstring pl_answer) runs on PIPE_CT {
269
270 var charstring v_WindowCommand := "";
271 PIPE_PCO.send(t_PExecute("sh", "echo $ShellTestDir/ShellQuestionString.sh; exit"));
272 alt {
273 [] PIPE_PCO.receive(t_PResult(?,?,0)) -> value v_ASP_PResult {
274 v_WindowCommand := v_ASP_PResult.stdout;
275
276 PIPE_PCO.send(t_PExecute(v_WindowCommand, pl_question));
277 alt {
278 [] PIPE_PCO.receive(t_PResult(?,?,0)) -> value v_ASP_PResult {
279 pl_answer := v_ASP_PResult.stdout;
280 }
281 [] PIPE_PCO.receive {
282 setverdict(fail);
283 }
284 }
285 }
286 [] PIPE_PCO.receive {
287 setverdict(fail);
288 }
289 }
290 }
291
292 function WindowQuestionYesNo(
293 in charstring pl_question,
294 out boolean pl_answer) runs on PIPE_CT {
295
296 var charstring v_WindowCommand := "";
297 PIPE_PCO.send(t_PExecute("sh", "echo $ShellTestDir/ShellQuestionYesNo.sh; exit"));
298 alt {
299 [] PIPE_PCO.receive(t_PResult(?,?,0)) -> value v_ASP_PResult {
300 v_WindowCommand := v_ASP_PResult.stdout;
301
302 PIPE_PCO.send(t_PExecute(v_WindowCommand, pl_question));
303 alt {
304 [] PIPE_PCO.receive(t_PResult("Yes",?,0)) -> value v_ASP_PResult {
305 pl_answer := true;
306 }
307 [] PIPE_PCO.receive(t_PResult("No",?,0)) -> value v_ASP_PResult {
308 pl_answer := false;
309 }
310 [] PIPE_PCO.receive {
311 setverdict(fail);
312 }
313 }
314 }
315 [] PIPE_PCO.receive {
316 setverdict(fail);
317 }
318 }
319 }
320
321 testcase TC_TrySomeWindows() runs on PIPE_CT {
322 map(self:PIPE_PCO, system:PIPE_PCO);
323
324 var charstring v_answerS := "";
325 var boolean v_answerB := false;
326 label L;
327 WindowNotice("This is the first notice!");
328 WindowQuestionString("This is the first question", v_answerS);
329 log("Answer is: ", v_answerS);
330
331 WindowQuestionYesNo("Shall we repeat this again?", v_answerB);
332 log("Continue? :", v_answerB);
333 if (v_answerB) {
334 goto L;
335 }
336 setverdict(pass);
337 }
338
339 }