Sync with 5.4.2
[deliverable/titan.core.git] / regression_test / XML / XmlWorkflow / src / xmlTest_Shell.ttcn
1 /******************************************************************************
2 * Copyright (c) 2000-2015 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 v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 //=========================================================================
9 // Tags denoted by <MyTag> have to be replaced implicitly!
10 // Keep the order of section! Delete headers of empty sections!
11 // Remove unused examples or parts!
12 //=========================================================================
13
14 module xmlTest_Shell
15 // [.objid{ itu_t(0) identified_organization(4) etsi(0)
16 // identified_organization(127) ericsson(5) testing(0)
17 // <put further nodes here if needed>}]
18 {
19
20 //=========================================================================
21 // Import Part
22 //=========================================================================
23 import from PIPEasp_Types all;
24 import from PIPEasp_PortType all;
25 import from PIPEasp_Templates all;
26
27 //=========================================================================
28 // Module Parameters
29 //=========================================================================
30
31 modulepar float tsp_shellCmdTimeout :=1.0;
32
33 //=========================================================================
34 // Data Types
35 //=========================================================================
36 // type record TestcaseResult {
37 // charstring tcName,
38 // boolean passed
39 // }
40 //
41 // type record of TestcaseResult TestCaseResultList
42 //=========================================================================
43 // Signatures
44 //=========================================================================
45
46 // Insert signature definitions here if applicable!
47 // You can use the signature skeleton!
48
49 //=========================================================================
50 //Port Types
51 //=========================================================================
52
53 // Insert port type defintions here if applicable!
54 // You can use the port_type skeleton!
55
56 //=========================================================================
57 //Component Types
58 //=========================================================================
59
60
61
62 type component PIPE_CT {
63 port PIPEasp_PT PIPE_PCO;
64 var ASP_PExecute v_ASP_PExecute;
65 var ASP_PResult v_ASP_PResult;
66 var ASP_PExecuteBinary v_ASP_PExecuteBinary;
67 var ASP_PResultBinary v_ASP_PResultBinary;
68 var ASP_PExecuteBackground v_ASP_PExecuteBackground;
69 var ASP_PStdin v_ASP_PStdin;
70 var ASP_PStdout v_ASP_PStdout;
71 var ASP_PStderr v_ASP_PStderr;
72 var ASP_PStdinBinary v_ASP_PStdinBinary;
73 var ASP_PStdoutBinary v_ASP_PStdoutBinary;
74 var ASP_PStderrBinary v_ASP_PStderrBinary;
75 var ASP_PKill v_ASP_PKill;
76 var ASP_PExit v_ASP_PExit;
77 var ASP_PLineMode v_ASP_PLineMode;
78 var ASP_PError v_ASP_PError;
79 }
80
81 type component Shell_CT extends PIPE_CT {
82 var boolean v_initialized:=false;
83 }
84
85
86 type component xmlTest_CT extends Shell_CT {}
87
88 type component mtc_CT {}
89
90 //=========================================================================
91 // Constants
92 //=========================================================================
93
94 const integer c_shell_successWithoutWarningAndError:=0;
95 const integer c_shell_success := 0;
96 const integer c_shell_successWithWarning:=1; //temp until licence is solved
97 const integer c_shell_error:=256;
98 const integer c_shell_error_noSuchFileOrDirectory:=512;
99
100 //Expected and accepted diffs:
101 // Line "Copyright Ericsson AB 2013" - 4 diffs
102 // Line "XSD to TTCN-3 Translator version:" - 4 diffs
103 // Line "File" - 4 diffs
104 // Line "Updated: " - 4 diffs
105 // Line "module www_" - 4 diffs
106 // Line "ETSI ES 201 873-9 V4.1.2" - 2 diffs ???? << Fix it !
107 // Line "variant \"namespace as" - 4 diffs
108 // Script counts the strings "\n" thus N different lines mean N-1 numOfDiff
109 //Possible values: 19,21,23,25 but 21 and 25 should be eliminated!
110
111 const integer c_numOfDiff_header := 13;
112 const integer c_numOfDiff_headerAndModuleName := 19;
113 const integer c_numOfDiff_headerModNameAndNamespace := 23;
114 const integer c_numOfDiff_headerModNameAndImport := 23;
115
116 //=========================================================================
117 // Templates
118 //=========================================================================
119
120 // Insert templates here if applicable!
121 // You can use the template skeleton!
122
123 //=========================================================================
124 // Altsteps
125 //=========================================================================
126
127 // Insert altsteps here if applicable!
128 // You can use the altstep skeleton!
129
130 //=========================================================================
131 // Functions
132 //=========================================================================
133
134 //=========================================================================
135 // f_countDelimiters
136 //=========================================================================
137 function f_countDelimiters(in charstring pl_string, in charstring pl_delimiter, inout integer pl_counter) {
138 pl_counter:=0;
139 var integer pos:=0;
140 var integer vl_size:=lengthof(pl_string);
141 var integer vl_delimsize:=lengthof(pl_delimiter);
142 while(pos<vl_size) {
143 if( substr(pl_string,pos,vl_delimsize)==pl_delimiter) { pl_counter:=pl_counter+1}
144 pos:=pos+1;
145 }
146 }//f_
147
148 //=========================================================================
149 // f_compareFiles
150 //=========================================================================
151 //pl_diffLimit: upper limit of acceptable diff lines. 4 means one acceptable difference
152 function f_compareFiles(in charstring pl_file1, in charstring pl_file2, in integer pl_diffLimit) runs on xmlTest_CT {
153 var integer vl_expectedResult:=0
154 if(pl_diffLimit>0) { vl_expectedResult:=256; }
155 var boolean vl_success:=false;
156 f_shell_command("diff -w " & pl_file1 & " " & pl_file2,"",vl_expectedResult,vl_success);
157
158 if(v_ASP_PResult.code==0)
159 {
160 setverdict(pass);
161 }
162 else if(v_ASP_PResult.code==256) {
163 var integer vl_counter:=0;
164 f_countDelimiters(v_ASP_PResult.stdout,"\n",vl_counter);
165 log("Counted lines: ",vl_counter, " diffLimit: ", pl_diffLimit)
166 if(vl_counter>pl_diffLimit) {
167 setverdict(fail);
168 }
169 } else { //e.g 512: No such file or directory
170 log("Wrong result code: ",v_ASP_PResult.code, " Expected result code: ", vl_expectedResult)
171 setverdict(fail);
172 }
173 }//f_
174
175
176 //********* SHELL Functions ***********************
177
178 //=========================================================================
179 // f_shell_init
180 //=========================================================================
181 function f_shell_init() runs on Shell_CT {
182 if(v_initialized) { return; }
183 map(self:PIPE_PCO, system:PIPE_PCO);
184 v_initialized:=true;
185 }
186
187 //=========================================================================
188 // f_shell_cleanup
189 //=========================================================================
190 function f_shell_cleanup() runs on Shell_CT {
191 if(not v_initialized) { return; }
192 unmap(self:PIPE_PCO, system:PIPE_PCO);
193 v_initialized:=false;
194 }
195 //=========================================================================
196 // f_setverdictfromBool
197 //=========================================================================
198 function f_setverdictfromBool(in boolean pl_result, in boolean pl_expected_result:=true) {
199 if(pl_result==pl_expected_result) {
200 setverdict(pass);
201 }else{
202 setverdict(fail);
203 }
204 return;
205 }
206 //=========================================================================
207 // f_shell_validateXml
208 // Compares pl_xmlFileContent (e.g encoding result) against pl_xsdFileName
209 //=========================================================================
210 function f_shell_validateXml(in octetstring pl_xmlFileContent, in charstring pl_xsdFileName, in integer pl_expected_result, inout boolean pl_success)
211 runs on Shell_CT
212 {
213 f_shell_command( "xmllint --noout --schema " & pl_xsdFileName & " - ",oct2char(pl_xmlFileContent), pl_expected_result, pl_success);
214 }
215
216
217 //=========================================================================
218 // f_shell_command
219 //=========================================================================
220 function f_shell_command(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result, inout boolean pl_success)
221 runs on Shell_CT
222 {
223 f_shell_init();
224
225 var integer vl_expectedCode:=-1;
226 if(pl_expected_result==c_shell_successWithoutWarningAndError or
227 pl_expected_result==c_shell_successWithWarning) {
228 vl_expectedCode:=0
229 } else {
230 vl_expectedCode:= pl_expected_result;
231 }
232
233 log("Running: ", pl_command);
234 PIPE_PCO.send(t_PExecute(pl_command,pl_stdin));
235
236 timer t:=tsp_shellCmdTimeout;
237 t.start;
238 pl_success:=false;
239
240 alt {
241
242 [] PIPE_PCO.receive(t_PResult(?, ?, ?)) -> value v_ASP_PResult {
243 log("PResult msg received: ", v_ASP_PResult);
244
245 if(v_ASP_PResult.code==vl_expectedCode ) {
246 var charstring vl_pattern:="";
247 select(pl_expected_result) {
248 case(c_shell_successWithWarning) {
249 vl_pattern:="*(Warning|WARNING)*";
250 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
251 log("That is an expected Warning!")
252 pl_success:=true;
253 } else {
254 log("No Warning in the stderr string but expected");
255 pl_success:=false;
256 }
257 }
258 case(c_shell_successWithoutWarningAndError) {
259 vl_pattern:="*(Error|ERROR)*";
260 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
261 log("That is an unexpected Error!")
262 pl_success:=false;
263 } else {
264 log("No Error in the stderr string");
265 pl_success:=true;
266 }
267 vl_pattern:="*(Warning|WARNING)*";
268 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
269 log("That is an unexpected Warning!")
270 pl_success:=false;
271 } else {
272 log("No Warning in the stderr string");
273 pl_success:=true;
274 }
275 }//case
276 case(c_shell_error) {
277 log("Command returned with ERROR as expected");
278 pl_success:=true;
279 }
280 case(c_shell_error_noSuchFileOrDirectory) {
281 log("Command returned with No such file or directory as expected");
282 pl_success:=true;
283 }
284 case else {
285 log("Other case");
286 pl_success:=false;
287 }
288 }//select
289 } else {
290 log("The result code(", v_ASP_PResult.code, ") is not the expected(", vl_expectedCode, ")");
291 pl_success:=false;
292 }//if
293 }
294 [] t.timeout {
295 pl_success:=false;
296 }
297 }//alt
298
299 f_shell_cleanup();
300 return;
301 }//f_shell_command
302 //=========================================================================
303 // Name: f_shellCommandWithVerdict
304 // Description: sets verdict for pass, if the command execution returns with the expected value
305 //=========================================================================
306 function f_shellCommandWithVerdict(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result) runs on Shell_CT {
307 var boolean vl_success:=false;
308 f_shell_command(pl_command, pl_stdin, pl_expected_result, vl_success);
309 f_setverdictfromBool(vl_success)
310 }
311
312 //=========================================================================
313 // Testcases
314 //=========================================================================
315
316 // Insert test cases here if applicable!
317 // You can use the test_case skeleton!
318
319 //=========================================================================
320 // Control
321 //=========================================================================
322
323 // Insert control part here if applicable!
324 // You can use the control_part skeleton!
325
326 } // end of module
This page took 0.053395 seconds and 5 git commands to generate.