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