Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / profiler / 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 module Shell
10 {
11
12 import from PIPEasp_Types all;
13 import from PIPEasp_PortType all;
14 import from PIPEasp_Templates all;
15
16
17 modulepar float tsp_shellCmdTimeout := 20.0;
18
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;
36 }
37
38 type component Shell_CT extends PIPE_CT {
39 var boolean v_initialized:=false;
40 }
41
42 type component mtc_CT {}
43
44 //=========================================================================
45 // Constants
46 //=========================================================================
47
48 const integer c_shell_successWithoutWarningAndError:=0;
49 const integer c_shell_success := 0;
50 const integer c_shell_successWithWarning:=1;
51 const integer c_shell_successWithoutError:=2;
52 const integer c_shell_error:=256;
53 const integer c_shell_error_noSuchFileOrDirectory:=512;
54
55 //Expected and accepted diffs:
56 // Line "Copyright Ericsson AB 2013" - 4 diffs
57 // Line "XSD to TTCN-3 Translator version:" - 4 diffs
58 // Line "File" - 4 diffs
59 // Line "Updated: " - 4 diffs
60 // Line "module www_" - 4 diffs
61 // Line "ETSI ES 201 873-9 V4.1.2" - 2 diffs ???? << Fix it !
62 // Line "variant \"namespace as" - 4 diffs
63 // Script counts the strings "\n" thus N different lines mean N-1 numOfDiff
64 //Possible values: 19,21,23,25 but 21 and 25 should be eliminated!
65
66 const integer c_numOfDiff_headerAndModuleName := 19;
67 const integer c_numOfDiff_headerModNameAndNamespace := 23;
68 const integer c_numOfDiff_headerModNameAndImport := 23;
69
70 function f_countDelimiters(in charstring pl_string, in charstring pl_delimiter, inout integer pl_counter) {
71 pl_counter:=0;
72 var integer pos:=0;
73 var integer vl_size:=lengthof(pl_string);
74 var integer vl_delimsize:=lengthof(pl_delimiter);
75 while(pos<vl_size) {
76 if( substr(pl_string,pos,vl_delimsize)==pl_delimiter) { pl_counter:=pl_counter+1}
77 pos:=pos+1;
78 }
79 }//f_
80
81 //=========================================================================
82 // f_compareFiles
83 //=========================================================================
84 //pl_diffLimit: upper limit of acceptable diff lines. 4 means one acceptable difference
85 function f_compareFiles(in charstring pl_file1, in charstring pl_file2, in integer pl_diffLimit) runs on Shell_CT {
86 var integer vl_expectedResult:=0
87 if(pl_diffLimit>0) { vl_expectedResult:=256; }
88 var boolean vl_success:=false;
89 f_shell_command("diff -w " & pl_file1 & " " & pl_file2,"",vl_expectedResult,vl_success);
90
91 if(v_ASP_PResult.code==0)
92 {
93 setverdict(pass);
94 }
95 else if(v_ASP_PResult.code==256) {
96 var integer vl_counter:=0;
97 f_countDelimiters(v_ASP_PResult.stdout,"\n",vl_counter);
98 log("Counted lines: ",vl_counter, " diffLimit: ", pl_diffLimit)
99 if(vl_counter>pl_diffLimit) {
100 setverdict(fail);
101 }
102 } else { //e.g 512: No such file or directory
103 log("Wrong result code: ",v_ASP_PResult.code, " Expected result code: ", vl_expectedResult)
104 setverdict(fail);
105 }
106 }//f_
107
108
109 //********* SHELL Functions ***********************
110
111 //=========================================================================
112 // f_shell_init
113 //=========================================================================
114 function f_shell_init() runs on Shell_CT {
115 if(v_initialized) { return; }
116 map(self:PIPE_PCO, system:PIPE_PCO);
117 v_initialized:=true;
118 }
119
120 //=========================================================================
121 // f_shell_cleanup
122 //=========================================================================
123 function f_shell_cleanup() runs on Shell_CT {
124 if(not v_initialized) { return; }
125 unmap(self:PIPE_PCO, system:PIPE_PCO);
126 v_initialized:=false;
127 }
128 //=========================================================================
129 // f_setverdictfromBool
130 //=========================================================================
131 function f_setverdictfromBool(in boolean pl_result, in boolean pl_expected_result:=true) {
132 if(pl_result==pl_expected_result) {
133 setverdict(pass);
134 }else{
135 setverdict(fail);
136 }
137 return;
138 }
139 //=========================================================================
140 // f_shell_validateXml
141 // Compares pl_xmlFileContent (e.g encoding result) against pl_xsdFileName
142 //=========================================================================
143 function f_shell_validateXml(in octetstring pl_xmlFileContent, in charstring pl_xsdFileName, in integer pl_expected_result, inout boolean pl_success)
144 runs on Shell_CT
145 {
146 f_shell_command( "xmllint --noout --schema " & pl_xsdFileName & " - ",oct2char(pl_xmlFileContent), pl_expected_result, pl_success);
147 }
148
149
150 //=========================================================================
151 // f_shell_command
152 //=========================================================================
153 function f_shell_command(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result, inout boolean pl_success)
154 runs on Shell_CT
155 {
156 f_shell_init();
157
158 var integer vl_expectedCode:=-1;
159 if(pl_expected_result==c_shell_successWithoutWarningAndError or
160 pl_expected_result==c_shell_successWithWarning or
161 pl_expected_result==c_shell_successWithoutError) {
162 vl_expectedCode:=0
163 } else {
164 vl_expectedCode:= pl_expected_result;
165 }
166
167 log("Running: ", pl_command);
168 PIPE_PCO.send(t_PExecute(pl_command,pl_stdin));
169
170 timer t:=tsp_shellCmdTimeout;
171 t.start;
172 pl_success:=false;
173
174 alt {
175
176 [] PIPE_PCO.receive(t_PResult(?, ?, ?)) -> value v_ASP_PResult {
177 log("PResult msg received: ", v_ASP_PResult);
178
179 if(v_ASP_PResult.code==vl_expectedCode ) {
180 var charstring vl_pattern:="";
181 select(pl_expected_result) {
182 case(c_shell_successWithWarning) {
183 vl_pattern:="*(Warning|WARNING|warning)*";
184 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
185 log("That is an expected Warning!")
186 pl_success:=true;
187 } else {
188 log("No Warning in the stderr string but expected");
189 pl_success:=false;
190 }
191 }
192 case(c_shell_successWithoutWarningAndError) {
193 vl_pattern:="*(Error|ERROR|error)*";
194 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
195 log("That is an unexpected Error!")
196 pl_success:=false;
197 } else {
198 log("No Error in the stderr string");
199 pl_success:=true;
200 }
201 vl_pattern:="*(Warning|WARNING)*";
202 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
203 log("That is an unexpected Warning!")
204 pl_success:=false;
205 } else {
206 log("No Warning in the stderr string");
207 pl_success:=true;
208 }
209 }//case
210 case(c_shell_successWithoutError) {
211 vl_pattern:="*(Error|ERROR|error)*";
212 if(regexp(v_ASP_PResult.stderr,vl_pattern,0)!=""){
213 log("That is an unexpected Error!")
214 pl_success:=false;
215 } else {
216 log("No Error in the stderr string");
217 pl_success:=true;
218 }
219 }
220 case(c_shell_error) {
221 log("Command returned with ERROR as expected");
222 pl_success:=true;
223 }
224 case(c_shell_error_noSuchFileOrDirectory) {
225 log("Command returned with No such file or directory as expected");
226 pl_success:=true;
227 }
228 case else {
229 log("Other case");
230 pl_success:=false;
231 }
232 }//select
233 } else {
234 log("The result code(", v_ASP_PResult.code, ") is not the expected(", vl_expectedCode, ")");
235 pl_success:=false;
236 }//if
237 }
238 [] t.timeout {
239 pl_success:=false;
240 }
241 }//alt
242
243 f_shell_cleanup();
244 return;
245 }//f_shell_command
246 //=========================================================================
247 // Name: f_shellCommandWithVerdict
248 // Description: sets verdict for pass, if the command execution returns with the expected value
249 //=========================================================================
250 function f_shellCommandWithVerdict(in charstring pl_command, in charstring pl_stdin, in integer pl_expected_result) runs on Shell_CT {
251 var boolean vl_success:=false;
252 f_shell_command(pl_command, pl_stdin, pl_expected_result, vl_success);
253 f_setverdictfromBool(vl_success)
254 }
255
256 } // end of module
This page took 0.03617 seconds and 5 git commands to generate.