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