Commit | Line | Data |
---|---|---|
970ed795 EL |
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 | ******************************************************************************/ | |
8 | module LogFiles | |
9 | { | |
10 | modulepar | |
11 | { | |
12 | StrList PTC_Names; | |
13 | StrList PTC_Severities; | |
14 | } | |
15 | ||
16 | type record of charstring StrList; | |
17 | ||
18 | external function readlogfile(in charstring filename) return StrList; | |
19 | ||
20 | type port MyPort message | |
21 | { | |
22 | inout charstring; | |
23 | } with { extension "internal" } | |
24 | ||
25 | type component MyComp | |
26 | { | |
27 | port MyPort p1; | |
28 | port MyPort p2; | |
29 | port MyProcPort p; | |
30 | } | |
31 | ||
32 | signature MySignature(in MyComp c) return MyComp; | |
33 | template MySignature MySignatureTemplate := { c:=? } | |
34 | ||
35 | type port MyProcPort procedure | |
36 | { | |
37 | inout MySignature; | |
38 | } | |
39 | with { extension "internal" } | |
40 | ||
41 | function myptcfn() runs on MyComp | |
42 | { | |
43 | var charstring msg; | |
44 | p1.receive(charstring:?) -> value msg; | |
45 | log(msg); | |
46 | p2.send(msg); | |
47 | setverdict(pass); | |
48 | } | |
49 | ||
50 | type record of MyComp MyCompList; | |
51 | ||
52 | testcase mytc() runs on MyComp | |
53 | { | |
54 | // create component ring with names from cfg file | |
55 | var integer i; | |
56 | var MyCompList comp_list := { }; | |
57 | for (i:=0; i<sizeof(PTC_Names); i:=i+1) | |
58 | { | |
59 | comp_list[sizeof(comp_list)] := MyComp.create(PTC_Names[i]); | |
60 | } | |
61 | connect(self:p2,comp_list[0]:p1); | |
62 | for (i:=1; i<sizeof(comp_list); i:=i+1) { connect(comp_list[i-1]:p2,comp_list[i]:p1); } | |
63 | connect(comp_list[sizeof(comp_list)-1]:p2,self:p1); | |
64 | ||
65 | for (i:=0; i<sizeof(comp_list); i:=i+1) | |
66 | { | |
67 | comp_list[i].start(myptcfn()); | |
68 | } | |
69 | ||
70 | timer T; | |
71 | var charstring msg; | |
72 | p2.send("Hello component!"); | |
73 | T.start(10.0); | |
74 | alt | |
75 | { | |
76 | [] p1.receive("Hello component!") -> value msg { log(msg); T.stop; } | |
77 | [] T.timeout { setverdict(fail); } | |
78 | } | |
79 | setverdict(pass); | |
80 | } | |
81 | ||
82 | function checkLineMatches(in charstring line, in charstring regexp_str) | |
83 | { | |
84 | var charstring match_regexp := "(" & regexp_str & ")"; | |
85 | var charstring matching_str := regexp(line, match_regexp, 0); | |
86 | if (lengthof(matching_str)==0) { setverdict(fail, "\nline=",line, "\nregexp=",match_regexp); } | |
87 | } | |
88 | ||
89 | function checkContainsMatchingLineCount(in StrList list, in charstring regexp_str, in integer required_matching_lines) | |
90 | { | |
91 | var charstring match_regexp := "(" & regexp_str & ")"; | |
92 | var integer number_of_lines_matching := 0; | |
93 | var integer i; | |
94 | for (i:=0; i<sizeof(list); i:=i+1) | |
95 | { | |
96 | var charstring matching_str := regexp(list[i], match_regexp, 0); | |
97 | if (lengthof(matching_str)!=0) { number_of_lines_matching := number_of_lines_matching + 1; } | |
98 | } | |
99 | if (number_of_lines_matching!=required_matching_lines) { | |
100 | setverdict(fail, "Number of matching lines: ", match(number_of_lines_matching, required_matching_lines)); | |
101 | log(match(number_of_lines_matching, required_matching_lines), " regexp=", match_regexp, " list=", list); | |
102 | } | |
103 | } | |
104 | ||
105 | function get_conn_p1_comp_name_pattern(in integer ptc_index) return charstring | |
106 | { | |
107 | if (ptc_index==0) { return "mtc"; } | |
108 | return PTC_Names[ptc_index-1] & "\\(\\d#(1,2)\\)"; | |
109 | } | |
110 | ||
111 | function get_conn_p2_comp_name_pattern(in integer ptc_index) return charstring | |
112 | { | |
113 | if (ptc_index>=sizeof(PTC_Names)-1) { return "mtc"; } | |
114 | return PTC_Names[ptc_index+1] & "\\(\\d#(1,2)\\)"; | |
115 | } | |
116 | ||
117 | function checkLogFile_fn(in integer index) | |
118 | { | |
119 | log("Checking ", PTC_Names[index], ".log for ", PTC_Severities[index]); | |
120 | var StrList list := readlogfile(PTC_Names[index] & ".log"); | |
121 | // check only containes the specified severity | |
122 | var charstring mypattern := "* (" & PTC_Severities[index] & "_[A-Z]#(1,100)) *"; | |
123 | var integer i; | |
124 | for (i:=0; i<sizeof(list); i:=i+1) | |
125 | { | |
126 | var charstring matching_str := regexp(list[i],mypattern,0); | |
127 | //log("matching_str = ",matching_str); | |
128 | if (lengthof(matching_str)==0) { setverdict(fail); log("line=",list[i]," regexp=",mypattern); } | |
129 | } | |
130 | // check for proper log lines: log string, log severity_subcategory, component instance name | |
131 | if (PTC_Severities[index]=="PORTEVENT") | |
132 | { | |
133 | checkContainsMatchingLineCount(list, "* PORTEVENT_STATE *Port p? was started.", 2); | |
134 | checkContainsMatchingLineCount(list, "* PORTEVENT_STATE *Port p? was stopped.", 2); | |
135 | checkContainsMatchingLineCount(list, "* PORTEVENT_MQUEUE *Message enqueued on p1 from " | |
136 | & get_conn_p1_comp_name_pattern(index) & " charstring : \"Hello component!\" id 1", 1); | |
137 | checkContainsMatchingLineCount(list, "* PORTEVENT_MCRECV *Receive operation on port p1 succeeded, message from " | |
138 | & get_conn_p1_comp_name_pattern(index) & ": charstring : \"Hello component!\" id 1", 1); | |
139 | checkContainsMatchingLineCount(list, "* PORTEVENT_MQUEUE *Message with id 1 was extracted from the queue of p1.", 1); | |
140 | checkContainsMatchingLineCount(list, "* PORTEVENT_MCSEND *Sent on p2 to " | |
141 | & get_conn_p2_comp_name_pattern(index) & " charstring : \"Hello component!\"", 1); | |
142 | } | |
143 | else if (PTC_Severities[index]=="MATCHING") | |
144 | { | |
145 | checkContainsMatchingLineCount(list, "* MATCHING_MCSUCCESS *Matching on port p1 succeeded: \"Hello component!\" with ? matched", 1); | |
146 | } | |
147 | else if (PTC_Severities[index]=="USER") | |
148 | { | |
149 | checkContainsMatchingLineCount(list, "* USER_UNQUALIFIED *\"Hello component!\"", 1); | |
150 | } | |
151 | else if (PTC_Severities[index]=="PARALLEL") | |
152 | { | |
153 | checkLineMatches(list[0], "* PARALLEL_PTC *Initializing variables, timers and ports of component type *.MyComp inside testcase *."); | |
154 | checkLineMatches(list[1], "* PARALLEL_PTC *Component type *.MyComp was initialized."); | |
155 | checkLineMatches(list[2], "* PARALLEL_PTC *Starting function myptcfn\\(\\)."); | |
156 | checkLineMatches(list[3], "* PARALLEL_PTC *Function myptcfn finished. PTC terminates."); | |
157 | checkLineMatches(list[4], "* PARALLEL_PTC *Terminating component type *.MyComp."); | |
158 | checkLineMatches(list[5], "* PARALLEL_PTC *Component type *.MyComp was shut down inside testcase *."); | |
159 | } | |
160 | else if (PTC_Severities[index]=="EXECUTOR") | |
161 | { | |
162 | checkLineMatches(list[0], "* EXECUTOR_COMPONENT *TTCN-3 Parallel Test Component started on * component name: " | |
163 | & PTC_Names[index] & ". Version: *"); | |
164 | checkLineMatches(list[1], "* EXECUTOR_LOGOPTIONS *TTCN Logger v\\d#(1,4).\\d#(1,4) options: *"); | |
165 | checkLineMatches(list[2], "* EXECUTOR_RUNTIME *Connected to MC."); | |
166 | checkLineMatches(list[3], "* EXECUTOR_RUNTIME *Disconnected from MC."); | |
167 | checkLineMatches(list[4], "* EXECUTOR_COMPONENT *TTCN-3 Parallel Test Component finished."); | |
168 | } | |
169 | else if (PTC_Severities[index]=="VERDICTOP") | |
170 | { | |
171 | checkLineMatches(list[0], "* VERDICTOP_SETVERDICT *setverdict\\(pass\\): none -> pass"); | |
172 | checkLineMatches(list[1], "* VERDICTOP_FINAL *Final verdict of PTC: pass"); | |
173 | } | |
174 | } | |
175 | ||
176 | testcase checklogfiles_tc() runs on MyComp | |
177 | { | |
178 | var integer i; | |
179 | for (i:=0; i<sizeof(PTC_Names); i:=i+1) | |
180 | { | |
181 | checkLogFile_fn(i); | |
182 | } | |
183 | setverdict(pass); | |
184 | ||
185 | // Check that EXECUTOR_EXTCOMMAND appears in the log, | |
186 | // even without being specified in the config files. | |
187 | var StrList MTClog := readlogfile("MTC.log"); | |
188 | if (lengthof(MTClog) == 0) { setverdict(fail, "MTC log empty"); } | |
189 | checkContainsMatchingLineCount(MTClog, "* Starting external command `[^']+'.", 2); | |
190 | checkContainsMatchingLineCount(MTClog, "* External command `[^']+' was executed successfully \\(exit status: 0\\).", 2); | |
191 | } | |
192 | ||
193 | // check MTC.log generated by previous execution using LogFiles.cfg | |
194 | // run from LogFiles2.cfg (second invocation) | |
195 | testcase checkMTClogfile_tc() runs on MyComp | |
196 | { | |
197 | var StrList list := readlogfile("MTC.log"); | |
198 | // check first two lines | |
199 | checkLineMatches(list[0], "* EXECUTOR_COMPONENT *TTCN-3 Main Test Component started on *. Version: *."); | |
200 | checkLineMatches(list[1], "* EXECUTOR_LOGOPTIONS *TTCN Logger v\\d#(1,4).\\d#(1,4) options: *"); | |
201 | // check timer messages | |
202 | checkContainsMatchingLineCount(list, "* TIMEROP_START *Start timer T: \\d#(1,10) s", 1); | |
203 | checkContainsMatchingLineCount(list, "* TIMEROP_STOP *Stop timer T: \\d#(1,10) s", 1); | |
204 | // check TESTCASE_xxx messages | |
205 | checkContainsMatchingLineCount(list, "* TESTCASE_START *Test case mytc started.", 1); | |
206 | checkContainsMatchingLineCount(list, "* TESTCASE_FINISH *Test case mytc finished. Verdict: pass", 1); | |
207 | // check for every created component | |
208 | var integer i; | |
209 | for (i:=0; i<sizeof(PTC_Names); i:=i+1) | |
210 | { | |
211 | checkContainsMatchingLineCount(list, "* PARALLEL_PTC *PTC was created. Component reference: \\d#(1,3), alive: (yes|no), " | |
212 | & "type: *, component name: " & PTC_Names[i] & ".", 1); | |
213 | checkContainsMatchingLineCount(list, "* PARALLEL_PTC *Starting function myptcfn\\(\\) on component " | |
214 | & PTC_Names[i] & "\\(\\d#(1,3)\\).", 1); | |
215 | checkContainsMatchingLineCount(list, "* VERDICTOP_FINAL *Local verdict of PTC " | |
216 | & PTC_Names[i] & "\\(\\d#(1,3)\\): pass \\(pass -> pass\\)", 1); | |
217 | } | |
218 | for (i:=0; i<=sizeof(PTC_Names); i:=i+1) | |
219 | { | |
220 | checkContainsMatchingLineCount(list, "* PARALLEL_PORTCONN *Connect operation on " | |
221 | & get_conn_p1_comp_name_pattern(i) & ":p2 and " & get_conn_p2_comp_name_pattern(i-1) & ":p1 finished.", 1); | |
222 | } | |
223 | setverdict(pass); | |
224 | } | |
225 | ||
226 | function myprocptcfn1() runs on MyComp | |
227 | { | |
228 | var MyComp vl_comp; | |
229 | p.call(MySignature:{self}) | |
230 | { | |
231 | [] p.getreply(MySignatureTemplate) -> value vl_comp; | |
232 | } | |
233 | log("Received component value: ", vl_comp); | |
234 | p2.send("ok."); | |
235 | setverdict(pass); | |
236 | } | |
237 | ||
238 | function myprocptcfn2() runs on MyComp | |
239 | { | |
240 | var MyComp vl_comp; | |
241 | p.getcall(MySignatureTemplate) -> param (vl_comp); | |
242 | p.reply(MySignatureTemplate value self); | |
243 | log("Received component value: ", vl_comp); | |
244 | p2.send("ok."); | |
245 | setverdict(pass); | |
246 | } | |
247 | ||
248 | // run from LogFilesProc.cfg (third invocation) | |
249 | testcase proc_tc() runs on MyComp | |
250 | { | |
251 | var MyComp c1, c2; | |
252 | c1 := MyComp.create("STAN"); | |
253 | c2 := MyComp.create("PAN"); | |
254 | connect(c1:p,c2:p); | |
255 | connect(mtc:p2,c1:p2); | |
256 | connect(mtc:p2,c2:p2); | |
257 | c1.start(myprocptcfn1()); | |
258 | c2.start(myprocptcfn2()); | |
259 | p2.receive(charstring:"ok."); | |
260 | p2.receive(charstring:"ok."); | |
261 | // check log file of STAN | |
262 | var StrList list := readlogfile("PROC_STAN.log"); | |
263 | checkLineMatches(list[0], "* PORTEVENT_PCOUT *Called on p to PAN\\(\\d#(1,3)\\) *"); | |
264 | checkLineMatches(list[1], "* PORTEVENT_PQUEUE *Reply enqueued on p from PAN\\(\\d#(1,3)\\) * value PAN\\(\\d#(1,3)\\) id 1"); | |
265 | checkLineMatches(list[2], "* MATCHING_PCSUCCESS *Matching on port p succeeded: * matched value PAN\\(\\d#(1,3)\\) with \\? matched"); | |
266 | checkLineMatches(list[3], "* PORTEVENT_PCIN *Getreply operation on port p succeeded, reply from PAN\\(\\d#(1,3)\\): * value PAN\\(\\d#(1,3)\\) id 1"); | |
267 | checkLineMatches(list[4], "* PORTEVENT_PQUEUE *Operation with id 1 was extracted from the queue of p."); | |
268 | checkLineMatches(list[5], "* USER_UNQUALIFIED *Received component value: PAN\\(\\d#(1,3)\\)"); | |
269 | // check log file of PAN | |
270 | list := readlogfile("PROC_PAN.log"); | |
271 | checkLineMatches(list[0], "* PORTEVENT_PQUEUE *Call enqueued on p from STAN\\(\\d#(1,3)\\) *.MySignature : \\{ c := STAN\\(\\d#(1,3)\\) \\} id 1"); | |
272 | checkLineMatches(list[1], "* MATCHING_PCSUCCESS *Matching on port p succeeded: \\{ c := STAN\\(\\d#(1,3)\\) with \\? matched \\}"); | |
273 | checkLineMatches(list[2], "* PORTEVENT_PCIN *Getcall operation on port p succeeded, call from STAN\\(\\d#(1,3)\\): *.MySignature : \\{ c := STAN\\(\\d#(1,3)\\) \\} id 1"); | |
274 | checkLineMatches(list[3], "* PORTEVENT_PQUEUE *Operation with id 1 was extracted from the queue of p."); | |
275 | checkLineMatches(list[4], "* PORTEVENT_PCOUT *Replied on p to STAN\\(\\d#(1,3)\\) *.MySignature : \\{ \\} value PAN\\(\\d#(1,3)\\)"); | |
276 | checkLineMatches(list[5], "* USER_UNQUALIFIED *Received component value: STAN\\(\\d#(1,3)\\)"); | |
277 | setverdict(pass); | |
278 | } | |
279 | ||
280 | // Tests for HM34022. | |
281 | function f_level2() | |
282 | { | |
283 | log("f_level2()"); | |
284 | } | |
285 | ||
286 | function f_level1() | |
287 | { | |
288 | f_level2(); | |
289 | } | |
290 | ||
291 | testcase checkifstackisstillworking_tc() runs on MyComp | |
292 | { | |
293 | f_level1(); | |
294 | var StrList list := readlogfile("MTC.log"); | |
295 | var charstring match_regexp := "(?*USER_UNQUALIFIED LogFiles.ttcn:\\d+\\(controlpart:LogFiles\\)->LogFiles.ttcn:\\d+\\(testcase:checkifstackisstillworking_tc\\)->LogFiles.ttcn:\\d+\\(function:f_level1\\)->LogFiles.ttcn:\\d+\\(function:f_level2\\) f_level2\\(?*)"; | |
296 | for (var integer i := 0; i < sizeof(list); i := i + 1) { | |
297 | var charstring match_str := regexp(list[i], match_regexp, 0); | |
298 | if (lengthof(match_str) != 0) { | |
299 | setverdict(pass); | |
300 | break; | |
301 | } | |
302 | } | |
303 | if (getverdict != pass) { | |
304 | setverdict(fail, "Something is wrong with the stack log..."); | |
305 | } | |
306 | } | |
307 | ||
308 | control // Executed from LogFiles.cfg (first invocation). | |
309 | { | |
310 | execute(mytc()); | |
311 | execute(checklogfiles_tc()); | |
312 | execute(checkifstackisstillworking_tc()); | |
313 | } | |
314 | } |