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 //=========================================================================
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>}]
20 //=========================================================================
22 //=========================================================================
23 import from PIPEasp_Types all;
24 import from PIPEasp_PortType all;
25 import from PIPEasp_Templates all;
27 //=========================================================================
29 //=========================================================================
31 modulepar float tsp_shellCmdTimeout :=1.0;
33 //=========================================================================
35 //=========================================================================
36 // type record TestcaseResult {
41 // type record of TestcaseResult TestCaseResultList
42 //=========================================================================
44 //=========================================================================
46 // Insert signature definitions here if applicable!
47 // You can use the signature skeleton!
49 //=========================================================================
51 //=========================================================================
53 // Insert port type defintions here if applicable!
54 // You can use the port_type skeleton!
56 //=========================================================================
58 //=========================================================================
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;
81 type component Shell_CT extends PIPE_CT {
82 var boolean v_initialized:=false;
86 type component xmlTest_CT extends Shell_CT {}
88 type component mtc_CT {}
90 //=========================================================================
92 //=========================================================================
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;
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!
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;
116 //=========================================================================
118 //=========================================================================
120 // Insert templates here if applicable!
121 // You can use the template skeleton!
123 //=========================================================================
125 //=========================================================================
127 // Insert altsteps here if applicable!
128 // You can use the altstep skeleton!
130 //=========================================================================
132 //=========================================================================
134 //=========================================================================
136 //=========================================================================
137 function f_countDelimiters(in charstring pl_string, in charstring pl_delimiter, inout integer pl_counter) {
140 var integer vl_size:=lengthof(pl_string);
141 var integer vl_delimsize:=lengthof(pl_delimiter);
143 if( substr(pl_string,pos,vl_delimsize)==pl_delimiter) { pl_counter:=pl_counter+1}
148 //=========================================================================
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);
158 if(v_ASP_PResult.code==0)
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) {
169 } else { //e.g 512: No such file or directory
170 log("Wrong result code: ",v_ASP_PResult.code, " Expected result code: ", vl_expectedResult)
176 //********* SHELL Functions ***********************
178 //=========================================================================
180 //=========================================================================
181 function f_shell_init() runs on Shell_CT {
182 if(v_initialized) { return; }
183 map(self:PIPE_PCO, system:PIPE_PCO);
187 //=========================================================================
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;
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) {
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)
213 f_shell_command( "xmllint --noout --schema " & pl_xsdFileName & " - ",oct2char(pl_xmlFileContent), pl_expected_result, pl_success);
217 //=========================================================================
219 //=========================================================================
220 function f_shell_command(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result, inout boolean pl_success)
225 var integer vl_expectedCode:=-1;
226 if(pl_expected_result==c_shell_successWithoutWarningAndError or
227 pl_expected_result==c_shell_successWithWarning) {
230 vl_expectedCode:= pl_expected_result;
233 log("Running: ", pl_command);
234 PIPE_PCO.send(t_PExecute(pl_command,pl_stdin));
236 timer t:=tsp_shellCmdTimeout;
242 [] PIPE_PCO.receive(t_PResult(?, ?, ?)) -> value v_ASP_PResult {
243 log("PResult msg received: ", v_ASP_PResult);
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!")
254 log("No Warning in the stderr string but expected");
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!")
264 log("No Error in the stderr string");
267 vl_pattern:="*(Warning|WARNING)*";
268 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
269 log("That is an unexpected Warning!")
272 log("No Warning in the stderr string");
276 case(c_shell_error) {
277 log("Command returned with ERROR as expected");
280 case(c_shell_error_noSuchFileOrDirectory) {
281 log("Command returned with No such file or directory as expected");
290 log("The result code(", v_ASP_PResult.code, ") is not the expected(", vl_expectedCode, ")");
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)
312 //=========================================================================
314 //=========================================================================
316 // Insert test cases here if applicable!
317 // You can use the test_case skeleton!
319 //=========================================================================
321 //=========================================================================
323 // Insert control part here if applicable!
324 // You can use the control_part skeleton!