1 /******************************************************************************
2 * Copyright (c) 2000-2014 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 ******************************************************************************/
12 import from PIPEasp_Types all;
13 import from PIPEasp_PortType all;
14 import from PIPEasp_Templates all;
17 modulepar float tsp_shellCmdTimeout := 6.0;
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;
38 type component Shell_CT extends PIPE_CT {
39 var boolean v_initialized:=false;
42 type component mtc_CT {}
44 //=========================================================================
46 //=========================================================================
48 const integer c_shell_successWithoutWarningAndError:=0;
49 const integer c_shell_success := 0;
50 const integer c_shell_successWithWarning:=1; //temp until licence is solved
51 const integer c_shell_error:=256;
52 const integer c_shell_error_noSuchFileOrDirectory:=512;
54 //Expected and accepted diffs:
55 // Line "Copyright Ericsson AB 2013" - 4 diffs
56 // Line "XSD to TTCN-3 Translator version:" - 4 diffs
57 // Line "File" - 4 diffs
58 // Line "Updated: " - 4 diffs
59 // Line "module www_" - 4 diffs
60 // Line "ETSI ES 201 873-9 V4.1.2" - 2 diffs ???? << Fix it !
61 // Line "variant \"namespace as" - 4 diffs
62 // Script counts the strings "\n" thus N different lines mean N-1 numOfDiff
63 //Possible values: 19,21,23,25 but 21 and 25 should be eliminated!
65 const integer c_numOfDiff_headerAndModuleName := 19;
66 const integer c_numOfDiff_headerModNameAndNamespace := 23;
67 const integer c_numOfDiff_headerModNameAndImport := 23;
69 function f_countDelimiters(in charstring pl_string, in charstring pl_delimiter, inout integer pl_counter) {
72 var integer vl_size:=lengthof(pl_string);
73 var integer vl_delimsize:=lengthof(pl_delimiter);
75 if( substr(pl_string,pos,vl_delimsize)==pl_delimiter) { pl_counter:=pl_counter+1}
80 //=========================================================================
82 //=========================================================================
83 //pl_diffLimit: upper limit of acceptable diff lines. 4 means one acceptable difference
84 function f_compareFiles(in charstring pl_file1, in charstring pl_file2, in integer pl_diffLimit) runs on Shell_CT {
85 var integer vl_expectedResult:=0
86 if(pl_diffLimit>0) { vl_expectedResult:=256; }
87 var boolean vl_success:=false;
88 f_shell_command("diff -w " & pl_file1 & " " & pl_file2,"",vl_expectedResult,vl_success);
90 if(v_ASP_PResult.code==0)
94 else if(v_ASP_PResult.code==256) {
95 var integer vl_counter:=0;
96 f_countDelimiters(v_ASP_PResult.stdout,"\n",vl_counter);
97 log("Counted lines: ",vl_counter, " diffLimit: ", pl_diffLimit)
98 if(vl_counter>pl_diffLimit) {
101 } else { //e.g 512: No such file or directory
102 log("Wrong result code: ",v_ASP_PResult.code, " Expected result code: ", vl_expectedResult)
108 //********* SHELL Functions ***********************
110 //=========================================================================
112 //=========================================================================
113 function f_shell_init() runs on Shell_CT {
114 if(v_initialized) { return; }
115 map(self:PIPE_PCO, system:PIPE_PCO);
119 //=========================================================================
121 //=========================================================================
122 function f_shell_cleanup() runs on Shell_CT {
123 if(not v_initialized) { return; }
124 unmap(self:PIPE_PCO, system:PIPE_PCO);
125 v_initialized:=false;
127 //=========================================================================
128 // f_setverdictfromBool
129 //=========================================================================
130 function f_setverdictfromBool(in boolean pl_result, in boolean pl_expected_result:=true) {
131 if(pl_result==pl_expected_result) {
138 //=========================================================================
139 // f_shell_validateXml
140 // Compares pl_xmlFileContent (e.g encoding result) against pl_xsdFileName
141 //=========================================================================
142 function f_shell_validateXml(in octetstring pl_xmlFileContent, in charstring pl_xsdFileName, in integer pl_expected_result, inout boolean pl_success)
145 f_shell_command( "xmllint --noout --schema " & pl_xsdFileName & " - ",oct2char(pl_xmlFileContent), pl_expected_result, pl_success);
149 //=========================================================================
151 //=========================================================================
152 function f_shell_command(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result, inout boolean pl_success)
157 var integer vl_expectedCode:=-1;
158 if(pl_expected_result==c_shell_successWithoutWarningAndError or
159 pl_expected_result==c_shell_successWithWarning) {
162 vl_expectedCode:= pl_expected_result;
165 log("Running: ", pl_command);
166 PIPE_PCO.send(t_PExecute(pl_command,pl_stdin));
168 timer t:=tsp_shellCmdTimeout;
174 [] PIPE_PCO.receive(t_PResult(?, ?, ?)) -> value v_ASP_PResult {
175 log("PResult msg received: ", v_ASP_PResult);
177 if(v_ASP_PResult.code==vl_expectedCode ) {
178 var charstring vl_pattern:="";
179 select(pl_expected_result) {
180 case(c_shell_successWithWarning) {
181 vl_pattern:="*(Warning|WARNING|warning)*";
182 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
183 log("That is an expected Warning!")
186 log("No Warning in the stderr string but expected");
190 case(c_shell_successWithoutWarningAndError) {
191 vl_pattern:="*(Error|ERROR|error)*";
192 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
193 log("That is an unexpected Error!")
196 log("No Error in the stderr string");
199 vl_pattern:="*(Warning|WARNING)*";
200 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
201 log("That is an unexpected Warning!")
204 log("No Warning in the stderr string");
208 case(c_shell_error) {
209 log("Command returned with ERROR as expected");
212 case(c_shell_error_noSuchFileOrDirectory) {
213 log("Command returned with No such file or directory as expected");
222 log("The result code(", v_ASP_PResult.code, ") is not the expected(", vl_expectedCode, ")");
234 //=========================================================================
235 // Name: f_shellCommandWithVerdict
236 // Description: sets verdict for pass, if the command execution returns with the expected value
237 //=========================================================================
238 function f_shellCommandWithVerdict(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result) runs on Shell_CT {
239 var boolean vl_success:=false;
240 f_shell_command(pl_command, pl_stdin, pl_expected_result, vl_success);
241 f_setverdictfromBool(vl_success)