|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <windows.h> |
|
17 #include <iostream> |
|
18 #include <fstream> |
|
19 #include <string> |
|
20 #include <stdlib.h> |
|
21 #include <direct.h> |
|
22 |
|
23 |
|
24 using namespace std; |
|
25 STARTUPINFO startupInfo; |
|
26 PROCESS_INFORMATION processInfo; |
|
27 STARTUPINFO startupInfoTls; |
|
28 PROCESS_INFORMATION processInfoTls; |
|
29 const char* CodenomiconPath = "C:/Program Files/Codenomicon/tlsc-31/testtool/tlsc-31.jar"; |
|
30 const char* TestToolWrapperPath = "D:\\TlsTestWrapper\\"; |
|
31 |
|
32 int ReadConfigurations(const string& fileName, string& configSettings); |
|
33 int GetPlatformAndBuild(const string& fileName, string& platform, string& build); |
|
34 int RunTlsTestTool(const string& config, const string& jarPath); |
|
35 int RunEpocTlsTest(const string& platform, const string& build); |
|
36 int ParseLog(const string& fileDir, string& reportName); |
|
37 int GetLogDirectory(const string& configFileName, string& logDir); |
|
38 void ConvertPath(string& path); |
|
39 int GetPlatformAndBuild(const string& fileName, string& platform, string& build); |
|
40 void GetEpocDrive(string& drive); |
|
41 void RemoveSpacesAround(string& inString); |
|
42 int EpocPreTestConfig(const string& drive, const string& platform, const string& build); |
|
43 int EpocPostTestConfig(const string& drive, const string& platform, const string& build); |
|
44 void WaitForEpocTest(); |
|
45 |
|
46 /* this function is used to read the configuration settings from the config file |
|
47 for Codenomicon TLS Client test tool |
|
48 |
|
49 its parameters are: |
|
50 1) fileName(in): this contains the name of the config file |
|
51 2) configSettings(out): on return, this contains the configuration settings |
|
52 */ |
|
53 int ReadConfigurations(const string& fileName, string& configSettings) |
|
54 { |
|
55 ifstream configFile(fileName.c_str()); |
|
56 if(configFile.is_open()) |
|
57 { |
|
58 string configLine; |
|
59 |
|
60 // go to the codenomicon params section |
|
61 getline(configFile,configLine); |
|
62 while(configLine.find("[params]", 0) == string::npos) |
|
63 { |
|
64 getline(configFile,configLine); |
|
65 if(configFile.eof()) |
|
66 { |
|
67 cout<<"\ncould not find [params] section in config file"<<endl; |
|
68 return -1; |
|
69 } |
|
70 } |
|
71 |
|
72 // reached the params section, now read the configuration settings |
|
73 while(!configFile.eof()) |
|
74 { |
|
75 getline(configFile, configLine); |
|
76 |
|
77 if(!configLine.empty()) |
|
78 { |
|
79 // chop off any blank spaces before the config options |
|
80 while(configLine[0] == ' ') |
|
81 { |
|
82 configLine.erase(0, 1); |
|
83 } |
|
84 |
|
85 // add to config string only if the line is not a comment |
|
86 if(configLine[0] != '/' && configLine[1] != '/') |
|
87 { |
|
88 // codenomicon expects each config setting to be preceeded with -- |
|
89 configSettings = configSettings + " --" + configLine; |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 configFile.close(); |
|
95 } |
|
96 else |
|
97 { |
|
98 cout << "Unable to open config file: "<< fileName; |
|
99 return -1; |
|
100 } |
|
101 } |
|
102 |
|
103 /* this function is used to remove spaces before as well as after a word |
|
104 |
|
105 its parameter is: |
|
106 1) inString (in/out): this contains the input string and on return is contains |
|
107 the string without any spaces before or after the word |
|
108 */ |
|
109 |
|
110 void RemoveSpacesAround(string& inString) |
|
111 { |
|
112 int i = 0; |
|
113 while(inString[i] == ' ') |
|
114 { |
|
115 inString.erase(i, 1); |
|
116 ++i; |
|
117 } |
|
118 |
|
119 i = inString.length(); |
|
120 while(inString[i] == ' ') |
|
121 { |
|
122 inString.erase(i, 1); |
|
123 --i; |
|
124 } |
|
125 |
|
126 } |
|
127 |
|
128 /* this function is used to read the platform and build from the config file for |
|
129 which the test has to be run |
|
130 |
|
131 its parameters are: |
|
132 1) fileName(in): this contains the name of the config file |
|
133 2) platform(out): on return, this contains the platform |
|
134 3) build(out): on return, this contains the build |
|
135 */ |
|
136 |
|
137 int GetPlatformAndBuild(const string& fileName, string& platform, string& build) |
|
138 { |
|
139 ifstream configFile(fileName.c_str()); |
|
140 if(!configFile.is_open()) |
|
141 { |
|
142 cout<<"Failed to open config file: "<<fileName<<endl; |
|
143 return -1; |
|
144 } |
|
145 |
|
146 string configLine; |
|
147 bool foundPlatform = false; |
|
148 bool foundBuild = false; |
|
149 int posPlatform = -1; |
|
150 int posBuild = -1; |
|
151 |
|
152 |
|
153 // read the platform and build section from the file in a single pass |
|
154 while(!configFile.eof()) |
|
155 { |
|
156 getline(configFile,configLine); |
|
157 posPlatform = configLine.find("[platform]", 0); |
|
158 if(posPlatform != string::npos) |
|
159 { |
|
160 // found platform section, its value is after the [platform], i.e. 10 positions after it |
|
161 platform = configLine.substr(posPlatform + 10, configLine.length()); |
|
162 RemoveSpacesAround(platform); |
|
163 foundPlatform = true; |
|
164 if(foundBuild) |
|
165 { |
|
166 configFile.close(); |
|
167 return 0; |
|
168 } |
|
169 } |
|
170 |
|
171 posBuild = configLine.find("[build]", 0); |
|
172 if(posBuild != string::npos) |
|
173 { |
|
174 // found the build section, its value is after the [build], i.e. 7 positions after it |
|
175 build = configLine.substr(posBuild + 7, configLine.length()); |
|
176 RemoveSpacesAround(build); |
|
177 foundBuild = true; |
|
178 if(foundPlatform) |
|
179 { |
|
180 configFile.close(); |
|
181 return 0; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 // could not find either platform or build or both |
|
187 if(!foundPlatform) |
|
188 { |
|
189 cout<<"\nCould not find Platform section"<<endl; |
|
190 } |
|
191 if(!foundBuild) |
|
192 { |
|
193 cout<<"Could not find Build section"<<endl; |
|
194 } |
|
195 |
|
196 configFile.close(); |
|
197 return -1; |
|
198 } |
|
199 |
|
200 |
|
201 /* this function runs the TLS test tool i.e. Codenomicon. |
|
202 |
|
203 its parameters are: |
|
204 1) config(in): the configuration options for the Codenomicon tool |
|
205 2) jarPath(in): the path of the Codenomicon jar file |
|
206 */ |
|
207 |
|
208 int RunTlsTestTool(const string& config, const string& jarPath) |
|
209 { |
|
210 string command = "java -Xmx128M -jar " + jarPath + config; |
|
211 //cout<<endl<<command<<endl; |
|
212 |
|
213 //return system(command.c_str()); |
|
214 |
|
215 |
|
216 ZeroMemory(&startupInfoTls, sizeof(startupInfoTls)); |
|
217 startupInfoTls.cb = sizeof(startupInfoTls); |
|
218 |
|
219 ZeroMemory(&processInfoTls, sizeof(processInfoTls)); |
|
220 |
|
221 // string tlsTestProgram = driveLetter +":/epoc32/RELEASE/"+ platform +"/"+ build +"/TlsClientTest"; |
|
222 //cout<<"\ntls test program path: "<<tlsTestProgram<<endl; |
|
223 |
|
224 cout<<"Launching Codenomicon TLS test tool"<<endl; |
|
225 // create a separate process for Codenomicon TLS test tool |
|
226 if(!CreateProcess( NULL, // no module name (use command line) |
|
227 (char*)command.c_str(), // Codenomicon TLS test tool |
|
228 NULL, // process handle not inheritable |
|
229 NULL, // thread handle not inheritable |
|
230 FALSE, // set handle inheritance to FALSE |
|
231 0, // no creation flags |
|
232 NULL, // use parent's environment block |
|
233 NULL, // use parent's starting directory |
|
234 &startupInfoTls, // pointer to STARTUPINFO structure |
|
235 &processInfoTls) // pointer to PROCESS_INFORMATION structure |
|
236 ) |
|
237 { |
|
238 int ret = GetLastError(); |
|
239 cout<<"CreateProcess for Codenomicon TLS test tool failed: "<<ret<<endl; |
|
240 return ret; |
|
241 } |
|
242 |
|
243 return 0; |
|
244 } |
|
245 |
|
246 /* this function parses the log file and prepares a report file |
|
247 |
|
248 its parameters are: |
|
249 1) logDir (in): the logging directory |
|
250 2) reportName (out): name of the report file |
|
251 */ |
|
252 |
|
253 int ParseLog(const string& logDir, string& reportName) |
|
254 { |
|
255 int totalError = 0; // keeps track of the total number of errors |
|
256 int length = logDir.length(); |
|
257 |
|
258 string summaryFileName; // stores the name of the summary file generated by Codenomicon |
|
259 if(logDir[length-1] == '/') |
|
260 { |
|
261 summaryFileName = logDir + "summary.txt"; |
|
262 } |
|
263 else |
|
264 { |
|
265 summaryFileName = logDir + "/summary.txt"; |
|
266 } |
|
267 |
|
268 string logFileName; // stores the name of log file generated by Codenomicon |
|
269 if(logDir[length-1] == '/') |
|
270 { |
|
271 logFileName = logDir + "main.log"; |
|
272 } |
|
273 else |
|
274 { |
|
275 logFileName = logDir + "/main.log"; |
|
276 } |
|
277 |
|
278 // create a report file in the log directory |
|
279 string report = logDir + reportName; |
|
280 ofstream outFile(report.c_str()); |
|
281 if(!outFile.is_open()) |
|
282 { |
|
283 cout << "Unable to create report file"; |
|
284 return -1; |
|
285 } |
|
286 |
|
287 // open the summary file and copy its contents to the report file |
|
288 // also find out the total number of tests run |
|
289 int totalTests = 0; |
|
290 |
|
291 ifstream summaryFile(summaryFileName.c_str()); |
|
292 if(summaryFile.is_open()) |
|
293 { |
|
294 string summaryLine; |
|
295 while(!summaryFile.eof()) |
|
296 { |
|
297 getline(summaryFile, summaryLine); |
|
298 |
|
299 // check if the line has total number of tests |
|
300 if(summaryLine.find("Test cases", 0) != string::npos) |
|
301 { |
|
302 // found the line, now get the number from the string |
|
303 // the number is in the end of the line and it has spaces before it |
|
304 int len = summaryLine.length(); |
|
305 int i = len; |
|
306 while(summaryLine[i--] != ' ') |
|
307 { } |
|
308 |
|
309 string totalTestsString = summaryLine.substr(i, summaryLine.length()); |
|
310 totalTests = atoi(totalTestsString.c_str()); |
|
311 } |
|
312 } |
|
313 |
|
314 summaryFile.close(); |
|
315 } |
|
316 else |
|
317 { |
|
318 cout << "Unable to open summary file generated by Codenomicon"; |
|
319 outFile.close(); |
|
320 return -1; |
|
321 } |
|
322 |
|
323 // open the log file |
|
324 ifstream logFile(logFileName.c_str()); |
|
325 string line; |
|
326 string nextLine; |
|
327 |
|
328 if(!logFile.is_open()) |
|
329 { |
|
330 cout << "Unable to open log file"; |
|
331 outFile.close(); |
|
332 return -1; |
|
333 } |
|
334 |
|
335 //outFile<<"List of test cases failed"<<endl<<"========================="<<endl; |
|
336 while(!logFile.eof()) |
|
337 { |
|
338 getline (logFile,line); |
|
339 if((!line.empty()) && ((line.find("ERROR", 0) != string::npos) || (line.find("error", 0) != string::npos))) |
|
340 { |
|
341 /* if(line.find("ERROR Expected", 0) == string::npos) */ |
|
342 { |
|
343 // read next line and check if it contains the string "Test case #" |
|
344 getline(logFile,nextLine); |
|
345 if((!nextLine.empty()) && (nextLine.find("Test case #", 0) != string::npos)) |
|
346 { |
|
347 totalError++; |
|
348 |
|
349 // write line and nextLine to report |
|
350 //outFile<<line<<endl<<nextLine<<endl; |
|
351 } |
|
352 else |
|
353 { |
|
354 // get the next line as sometimes a line is in between for events and octets |
|
355 getline(logFile, nextLine); |
|
356 if((!nextLine.empty()) && (nextLine.find("Test case #", 0) != string::npos)) |
|
357 { |
|
358 totalError++; |
|
359 |
|
360 // write line and nextLine to report |
|
361 //outFile<<line<<endl<<nextLine<<endl; |
|
362 } |
|
363 } |
|
364 } |
|
365 } |
|
366 } |
|
367 |
|
368 outFile<<totalTests-totalError<<endl; // print total no of tests passed |
|
369 outFile<<totalError<<endl; // print total no of tests failed |
|
370 logFile.close(); |
|
371 outFile.close(); |
|
372 |
|
373 return 0; |
|
374 } |
|
375 |
|
376 /* this function gets the log directory by reading the config file |
|
377 |
|
378 its parameters are: |
|
379 1) configFileName (in): the name of the config file |
|
380 2) logDir (out): on return contains the logging directory |
|
381 */ |
|
382 |
|
383 int GetLogDirectory(const string& configFileName, string& logDir) |
|
384 { |
|
385 ifstream configFile(configFileName.c_str()); |
|
386 string configLine; |
|
387 |
|
388 if(configFile.is_open()) |
|
389 { |
|
390 while(!configFile.eof()) |
|
391 { |
|
392 getline(configFile,configLine); |
|
393 if(!configLine.empty()) |
|
394 { |
|
395 unsigned int i = configLine.find("log-dir", 0); |
|
396 if(i != string::npos) |
|
397 { |
|
398 // found line containing log-dir, extract log directory |
|
399 logDir = configLine; |
|
400 |
|
401 // erase from first char of the line to the end of "log-dir" |
|
402 logDir.erase(0, i+7); |
|
403 |
|
404 // chop off any blank spaces before log directory name |
|
405 while(logDir[0] == ' ') |
|
406 { |
|
407 logDir.erase(0, 1); |
|
408 } |
|
409 } |
|
410 } |
|
411 } |
|
412 |
|
413 configFile.close(); |
|
414 } |
|
415 else |
|
416 { |
|
417 cout << "Unable to open file"; |
|
418 return -1; |
|
419 } |
|
420 |
|
421 } |
|
422 |
|
423 /* this function converts backward slashes "\" to forward slashes "/" . |
|
424 this is needed to prevent interpretation of backward slashes as format |
|
425 specifiers. |
|
426 |
|
427 its parameter is: |
|
428 1) path (in/out): on calling, it contains the path possibly containing backward |
|
429 slashes. on returning, it has path containing no backward slashes |
|
430 */ |
|
431 |
|
432 void ConvertPath(string& path) |
|
433 { |
|
434 for(int i = 0; i<path.length(); i++) |
|
435 { |
|
436 if(path[i] == '\\') |
|
437 { |
|
438 path[i] = '/'; |
|
439 } |
|
440 } |
|
441 } |
|
442 |
|
443 /* this function gets the epoc drive |
|
444 |
|
445 its parameters are: |
|
446 1) driveLetter (out): on return contains the epoc drive |
|
447 */ |
|
448 |
|
449 void GetEpocDrive(string& driveLetter) |
|
450 { |
|
451 // get the current drive |
|
452 char currentDrive = _getdrive(); |
|
453 currentDrive = currentDrive + 'A' -1; |
|
454 |
|
455 driveLetter = "C"; |
|
456 driveLetter[0] = currentDrive; |
|
457 } |
|
458 |
|
459 /* this function launches the epoc side TLS test. |
|
460 |
|
461 its parameters are: |
|
462 1) drive (in): the epoc drive |
|
463 2) platform (in): the platform for which the test will be run (e.g. WINSCW) |
|
464 3) build (in): the build for which the test will be run (e.g. UDEB) |
|
465 */ |
|
466 |
|
467 int RunEpocTlsTest(const string& driveLetter, const string& platform, const string& build) |
|
468 { |
|
469 ZeroMemory(&startupInfo, sizeof(startupInfo)); |
|
470 startupInfo.cb = sizeof(startupInfo); |
|
471 |
|
472 ZeroMemory(&processInfo, sizeof(processInfo)); |
|
473 |
|
474 string tlsTestProgram = driveLetter +":/epoc32/RELEASE/"+ platform +"/"+ build +"/TlsClientTest"; |
|
475 |
|
476 |
|
477 //before we launch the TLS test program we have to configure Epoc |
|
478 cout<<"\nConfiguring Epoc for TLS test program"<<endl; |
|
479 int ret = EpocPreTestConfig(driveLetter, platform, build); |
|
480 if(ret != 0) |
|
481 { |
|
482 return ret; |
|
483 } |
|
484 |
|
485 cout<<"Launching epoc client side test"<<endl; |
|
486 // create a separate process for epoc test |
|
487 if(!CreateProcess( NULL, // no module name (use command line) |
|
488 (char*)tlsTestProgram.c_str(), // epoc TLS client test |
|
489 NULL, // process handle not inheritable |
|
490 NULL, // thread handle not inheritable |
|
491 FALSE, // set handle inheritance to FALSE |
|
492 0, // no creation flags |
|
493 NULL, // use parent's environment block |
|
494 NULL, // use parent's starting directory |
|
495 &startupInfo, // pointer to STARTUPINFO structure |
|
496 &processInfo) // pointer to PROCESS_INFORMATION structure |
|
497 ) |
|
498 { |
|
499 int ret = GetLastError(); |
|
500 cout<<"CreateProcess failed: "<<ret<<endl; |
|
501 cout<<"Tried to execute: "<<tlsTestProgram<<endl; |
|
502 |
|
503 // restore the original settings for epoc |
|
504 ret = EpocPostTestConfig(driveLetter, platform, build); |
|
505 if(ret != 0) |
|
506 { |
|
507 cout<<"Failed to restore original commsDat settings: "<<ret<<endl; |
|
508 } |
|
509 return ret; |
|
510 } |
|
511 |
|
512 return 0; |
|
513 } |
|
514 |
|
515 /* this function configures Epoc for running the TLS test. this involves backing |
|
516 up the current commsDat and configuring the commsDat for loopback using WinTAP |
|
517 |
|
518 its parameters are: |
|
519 1) drive (in): the drive on which epoc is mapped |
|
520 2) platform (in): the platform (e.g. WINSCW) |
|
521 3) build (in): the build (e.g. UDEB) |
|
522 */ |
|
523 |
|
524 int EpocPreTestConfig(const string& drive, const string& platform, const string& build) |
|
525 { |
|
526 string testToolPath = TestToolWrapperPath; |
|
527 |
|
528 // create a directory for backup |
|
529 string backupDir = "mkdir "+ testToolPath + "backup"; |
|
530 int ret = system(backupDir.c_str()); |
|
531 |
|
532 // make backup of existing epoc.ini and secdlg.dll |
|
533 string backupEpoc = "copy /Y " + drive + ":\\epoc32\\data\\epoc.ini " + testToolPath + "backup\\epoc.ini"; |
|
534 ret = system(backupEpoc.c_str()); |
|
535 /* if(ret != 0) |
|
536 { |
|
537 cout<<"failed to copy epoc.ini: "<<endl<<backupEpoc<<endl<<" failed"<<endl; |
|
538 return ret; |
|
539 } |
|
540 */ |
|
541 string backupSec = "copy /Y " + drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\secdlg.dll " + testToolPath + "backup\\secdlg.dll"; |
|
542 ret = system(backupSec.c_str()); |
|
543 /* if(ret != 0) |
|
544 { |
|
545 cout<<"failed to copy secdlg.dll: "<<endl<<backupSec<<endl<<" failed"<<endl; |
|
546 return ret; |
|
547 } */ |
|
548 |
|
549 // delete secdlg.dll from epoc drive |
|
550 string deletesecdlg = "del " + drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\secdlg.dll "; |
|
551 ret = system(deletesecdlg.c_str()); |
|
552 /* if(ret != 0) |
|
553 { |
|
554 cout<<"failed to delete secdlg.dll: "<<endl<<deletesecdlg<<endl<<" failed"<<endl; |
|
555 return ret; |
|
556 } |
|
557 */ |
|
558 // copy the epoc_shell.ini, wintapstaticnogateway.xml, ethertap.pdd and tsecdlg.dll to epoc |
|
559 |
|
560 string copyShellIni = "copy /Y " + testToolPath + "epoc_shell.ini " + drive + ":\\epoc32\\data\\epoc.ini"; |
|
561 ret = system(copyShellIni.c_str()); |
|
562 if(ret != 0) |
|
563 { |
|
564 cout<<"failed to copy epoc.ini: "<<endl<<copyShellIni<<endl<<" failed"<<endl; |
|
565 return ret; |
|
566 } |
|
567 |
|
568 string copyXml = "copy /Y " + testToolPath + "wintapstaticnogateway.xml " + drive + ":\\epoc32\\" + platform + "\\c"; |
|
569 ret = system(copyXml.c_str()); |
|
570 if(ret != 0) |
|
571 { |
|
572 cout<<"failed to copy wintapstaticnogateway.xml: "<<endl<<copyXml<<endl<<" failed"<<endl; |
|
573 return ret; |
|
574 } |
|
575 |
|
576 string copyPdd = "copy /Y " + testToolPath + "ethertap.pdd " + drive + ":\\epoc32\\release\\" + platform + "\\udeb"; |
|
577 ret = system(copyPdd.c_str()); |
|
578 if(ret != 0) |
|
579 { |
|
580 cout<<"failed to copy ethertap.pdd: "<<endl<<copyPdd<<endl<<" failed"<<endl; |
|
581 return ret; |
|
582 } |
|
583 |
|
584 string copyDll = "copy /Y " + testToolPath + "tsecdlg.dll " + drive + ":\\epoc32\\release\\" + platform + "\\udeb"; |
|
585 ret = system(copyDll.c_str()); |
|
586 if(ret != 0) |
|
587 { |
|
588 cout<<"failed to copy tsecdlg.dll: "<<endl<<copyDll<<endl<<" failed"<<endl; |
|
589 return ret; |
|
590 } |
|
591 |
|
592 // launch 'ceddump' to retrieve the current commsDat configuration |
|
593 string cedDump = drive + ":/epoc32/release/" + platform + "/" + build + "/ceddump"; |
|
594 ret = system(cedDump.c_str()); |
|
595 if(ret != 0) |
|
596 { |
|
597 cout<<"failed to launch ceddump: "<<endl<<cedDump<<endl<<"failed"<<endl; |
|
598 return ret; |
|
599 } |
|
600 |
|
601 // delete the old backup file, if it exists |
|
602 string delBackup = "del " + drive + ":\\epoc32\\" + platform + "\\c\\tlsbackup.cfg"; |
|
603 cout<<"\ntrying to delete old backup file: tlsbackup.cfg"<<endl; |
|
604 ret = system(delBackup.c_str()); |
|
605 if(ret != 0) |
|
606 {} |
|
607 |
|
608 // make a backup of current commsDat configuration |
|
609 string backup = "rename " + drive + ":\\epoc32\\" + platform + "\\c\\cedout.cfg tlsbackup.cfg"; |
|
610 ret = system(backup.c_str()); |
|
611 if(ret != 0) |
|
612 { |
|
613 cout<<"failed to save current commsDat: "<<endl<<backup<<endl<<"failed"<<endl; |
|
614 return ret; |
|
615 } |
|
616 |
|
617 // set up commsDat for loopback using WinTAP |
|
618 string winTap = drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\ced c:\\WinTapStaticNoGateway.xml"; |
|
619 ret = system(winTap.c_str()); |
|
620 if(ret != 0) |
|
621 { |
|
622 cout<<"failed commsDat setup for WinTap: "<<endl<<winTap<<endl<<"failed"<<endl; |
|
623 return ret; |
|
624 } |
|
625 // copy epoc.ini so that the techview boots up in GUI mode - the test runs only in GUI mode |
|
626 string copyIni = "copy /Y " + testToolPath + "epoc.ini " + drive + ":\\epoc32\\data\\epoc.ini"; |
|
627 ret = system(copyIni.c_str()); |
|
628 if(ret != 0) |
|
629 { |
|
630 cout<<"failed to copy epoc.ini: "<<endl<<copyIni<<endl<<" failed"<<endl; |
|
631 return ret; |
|
632 } |
|
633 |
|
634 |
|
635 return 0; |
|
636 } |
|
637 |
|
638 /* this function restores the commsDat setup to the original settings (i.e. to that |
|
639 of before running TLS test |
|
640 |
|
641 its parameters are: |
|
642 1) drive (in): the drive on which epoc is mapped |
|
643 2) platform (in): the platform (e.g. WINSCW) |
|
644 3) build (in): the build (e.g. UDEB) |
|
645 */ |
|
646 |
|
647 int EpocPostTestConfig(const string& drive, const string& platform, const string& build) |
|
648 { |
|
649 string testToolPath = TestToolWrapperPath; |
|
650 |
|
651 string copyShellIni = "copy /Y " + testToolPath + "epoc_shell.ini " + drive + ":\\epoc32\\data\\epoc.ini"; |
|
652 int ret = system(copyShellIni.c_str()); |
|
653 if(ret != 0) |
|
654 { |
|
655 cout<<"failed to copy epoc.ini: "<<endl<<copyShellIni<<endl<<" failed"<<endl; |
|
656 return ret; |
|
657 } |
|
658 |
|
659 // restore previous commsDat setup |
|
660 string prevSetting = drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\ced c:\\tlsbackup.cfg"; |
|
661 ret = system(prevSetting.c_str()); |
|
662 if(ret != 0) |
|
663 { |
|
664 cout<<"failed to restore previous commsDat setup: "<<endl<<prevSetting<<endl<<"failed"<<endl; |
|
665 return ret; |
|
666 } |
|
667 |
|
668 // rename the backup file to original |
|
669 string backup = "rename " + drive + ":\\epoc32\\" + platform + "\\c\\tlsbackup.cfg cedout.cfg"; |
|
670 ret = system(backup.c_str()); |
|
671 if(ret != 0) |
|
672 { |
|
673 cout<<"failed to restore backup file: "<<endl<<backup<<endl<<"failed"<<endl; |
|
674 return ret; |
|
675 } |
|
676 |
|
677 // restore original epoc.ini and secdlg.dll |
|
678 string backupEpoc = "copy /Y " + testToolPath + "backup\\epoc.ini " + drive + ":\\epoc32\\data\\epoc.ini " ; |
|
679 ret = system(backupEpoc.c_str()); |
|
680 if(ret != 0) |
|
681 { |
|
682 cout<<"failed to copy epoc.ini: "<<endl<<backupEpoc<<endl<<" failed"<<endl; |
|
683 return ret; |
|
684 } |
|
685 |
|
686 string backupSec = "copy /Y " + testToolPath + "backup\\secdlg.dll " + drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\secdlg.dll " ; |
|
687 ret = system(backupSec.c_str()); |
|
688 if(ret != 0) |
|
689 { |
|
690 cout<<"failed to copy secdlg.dll: "<<endl<<backupSec<<endl<<" failed"<<endl; |
|
691 return ret; |
|
692 } |
|
693 // delete tsecdlg.dll from epoc drive |
|
694 string deletesecdlg = "del " + drive + ":\\epoc32\\release\\" + platform + "\\" + build + "\\tsecdlg.dll "; |
|
695 ret = system(deletesecdlg.c_str()); |
|
696 if(ret != 0) |
|
697 { |
|
698 cout<<"failed to delete tsecdlg.dll: "<<endl<<deletesecdlg<<endl<<" failed"<<endl; |
|
699 return ret; |
|
700 } |
|
701 |
|
702 |
|
703 return 0; |
|
704 |
|
705 } |
|
706 |
|
707 /* this function waits for Epoc TLS client test to finish |
|
708 */ |
|
709 |
|
710 void WaitForEpocTest() |
|
711 { |
|
712 DWORD dwExitCode; |
|
713 GetExitCodeProcess(processInfo.hProcess, &dwExitCode); |
|
714 while(dwExitCode == STILL_ACTIVE) |
|
715 { |
|
716 cout<<"."; |
|
717 GetExitCodeProcess(processInfo.hProcess, &dwExitCode); |
|
718 Sleep(1000); |
|
719 } |
|
720 } |
|
721 |
|
722 bool ProcessRunning(HANDLE handle) |
|
723 { |
|
724 DWORD dwExitCode; |
|
725 GetExitCodeProcess(handle, &dwExitCode); |
|
726 if(dwExitCode == STILL_ACTIVE) |
|
727 { |
|
728 return true; |
|
729 } |
|
730 else |
|
731 { |
|
732 return false; |
|
733 } |
|
734 } |
|
735 |
|
736 int PingEpoc() |
|
737 { |
|
738 int ret = system("ping -n 1 -w 20000 192.168.0.2"); |
|
739 return ret; |
|
740 } |
|
741 |
|
742 /* this program takes one argument: |
|
743 1) config file in text format |
|
744 */ |
|
745 int main(int argc, char* argv[]) |
|
746 { |
|
747 if(argc != 2) |
|
748 { |
|
749 cout << argv[0] |
|
750 << " [config file] "<<endl; |
|
751 |
|
752 return -1; |
|
753 } |
|
754 |
|
755 string fileName = argv[1]; |
|
756 |
|
757 string configSettings = " --no-gui "; |
|
758 int ret = ReadConfigurations(fileName, configSettings); |
|
759 if(ret != 0) |
|
760 { |
|
761 return ret; |
|
762 } |
|
763 |
|
764 string drive; |
|
765 string platform; |
|
766 string build; |
|
767 |
|
768 GetEpocDrive(drive); |
|
769 |
|
770 ret = GetPlatformAndBuild(fileName, platform, build); |
|
771 if(ret != 0) |
|
772 { |
|
773 return ret; |
|
774 } |
|
775 |
|
776 // kill the previously running tlsclienttest program, if any |
|
777 // cout<<"zzz before killing"<<endl; |
|
778 // ret = system("TASKKILL /F /IM tlsclienttest.exe /T"); |
|
779 // cout<<"zzz after killing1: "<<ret<<endl; |
|
780 // ret = system("TASKKILL /F /IM java.exe /T"); |
|
781 // cout<<"zzz after killing2: "<<ret<<endl; |
|
782 // run epoc side TLS test client |
|
783 ret = RunEpocTlsTest(drive, platform, build); |
|
784 if(ret != 0) |
|
785 { |
|
786 cout<<"Exiting program"<<endl; |
|
787 return ret; |
|
788 } |
|
789 |
|
790 string jarPath = CodenomiconPath; |
|
791 jarPath += "\""; |
|
792 string quotedJarPath = "\"" + jarPath; |
|
793 |
|
794 // run Codenomicon TLS Client test tool |
|
795 cout<<"Launching Codenomicon TLS Client test tool"<<endl; |
|
796 ret = RunTlsTestTool(configSettings, quotedJarPath); |
|
797 if(ret != 0) |
|
798 { |
|
799 return ret; |
|
800 } |
|
801 |
|
802 // now Epoc TLS Client test should be executed till Codenomicon tool is running |
|
803 /* while(TlsTestToolRunning()) |
|
804 { |
|
805 WaitForEpocTest(); |
|
806 |
|
807 // check if the Codenomicon test tool is still running |
|
808 if(TlsTestToolRunning()) |
|
809 { |
|
810 // Codenomicon test tool still running, run epoc side TLS test client again |
|
811 ret = RunEpocTlsTest(drive, platform, build); |
|
812 if(ret != 0) |
|
813 { |
|
814 cout<<"Exiting program"<<endl; |
|
815 return ret; |
|
816 } |
|
817 } |
|
818 } |
|
819 */ |
|
820 |
|
821 HANDLE handles[2]; |
|
822 handles[0] = processInfo.hProcess; |
|
823 handles[1] = processInfoTls.hProcess; |
|
824 /* Commented code starts-*/ |
|
825 // wait for any of the process to finish |
|
826 WaitForMultipleObjects(2, handles, false, INFINITE); |
|
827 |
|
828 // if epoc side TLS test finished and Codenomicon |
|
829 // tool is still running, then terminate Codenomicon process |
|
830 if(!ProcessRunning(processInfo.hProcess)) |
|
831 { |
|
832 if(ProcessRunning(processInfoTls.hProcess)) |
|
833 { |
|
834 // not a clean way, but have to terminate Codenomicon test tool |
|
835 TerminateProcess(processInfoTls.hProcess, 1); |
|
836 } |
|
837 } |
|
838 |
|
839 // if Codenomicon test tool is finished, then terminate the epoc side test |
|
840 if(!ProcessRunning(processInfoTls.hProcess)) |
|
841 { |
|
842 if(ProcessRunning(processInfo.hProcess)) |
|
843 { |
|
844 // not a clean way, but we have to terminate epoc test |
|
845 TerminateProcess(processInfo.hProcess, 1); |
|
846 } |
|
847 } |
|
848 |
|
849 /* commented code ends*/ |
|
850 |
|
851 // change started **************** |
|
852 |
|
853 // while(ProcessRunning(processInfo.hProcess) && ProcessRunning(processInfoTls.hProcess)) |
|
854 /* while(1) |
|
855 { |
|
856 // wait for any of the process to finish |
|
857 WaitForMultipleObjects(2, handles, false, 20000); |
|
858 |
|
859 // if epoc side TLS test finished and Codenomicon |
|
860 // tool is still running, then terminate Codenomicon process |
|
861 if(!ProcessRunning(processInfo.hProcess)) |
|
862 { |
|
863 cout<<"\nepoc finished, terminating codenomicon"<<endl; |
|
864 if(ProcessRunning(processInfoTls.hProcess)) |
|
865 { |
|
866 // not a clean way, but have to terminate Codenomicon test tool |
|
867 TerminateProcess(processInfoTls.hProcess, 1); |
|
868 return 0; |
|
869 } |
|
870 } |
|
871 |
|
872 // if Codenomicon test tool is finished, then terminate the epoc side test |
|
873 if(!ProcessRunning(processInfoTls.hProcess)) |
|
874 { |
|
875 cout<<"\ncodenomicon finished, terminating epoc"<<endl; |
|
876 if(ProcessRunning(processInfo.hProcess)) |
|
877 { |
|
878 // not a clean way, but we have to terminate epoc test |
|
879 TerminateProcess(processInfo.hProcess, 1); |
|
880 return 0; |
|
881 } |
|
882 } |
|
883 |
|
884 // check if the epoc side TLS test has crashed |
|
885 ret = PingEpoc(); |
|
886 if(ret != 0) |
|
887 { |
|
888 // epoc not responding, kill the processes and return |
|
889 if(ProcessRunning(processInfoTls.hProcess)) |
|
890 { |
|
891 TerminateProcess(processInfoTls.hProcess, 1); |
|
892 } |
|
893 |
|
894 if(ProcessRunning(processInfo.hProcess)) |
|
895 { |
|
896 TerminateProcess(processInfo.hProcess, 1); |
|
897 } |
|
898 |
|
899 return ret; |
|
900 } |
|
901 } |
|
902 |
|
903 */ |
|
904 |
|
905 // change ends **************** |
|
906 |
|
907 /* now that the test tool has executed, we need to get the results from the log file |
|
908 but first we need the log directory for reading the log file |
|
909 */ |
|
910 /* string logDir; |
|
911 ret = GetLogDirectory(fileName, logDir); |
|
912 if(ret != 0) |
|
913 { |
|
914 cout<<"\nwaiting for Epoc TLS Client test to exit"; |
|
915 // wait for epoc tls test to finish |
|
916 WaitForEpocTest(); |
|
917 |
|
918 // restore previous commsDat settings |
|
919 ret = EpocPostTestConfig(drive, platform, build); |
|
920 return ret; |
|
921 } |
|
922 */ |
|
923 // convert the backward slashes to forward slashes in the path |
|
924 // ConvertPath(logDir); |
|
925 |
|
926 // prepare a report from the log file |
|
927 // string outFile("report.txt"); |
|
928 // ret = ParseLog(logDir, outFile); |
|
929 |
|
930 // wait for epoc tls test to finish |
|
931 // cout<<"\nwaiting for Epoc TLS Client test to exit"; |
|
932 // WaitForEpocTest(); |
|
933 |
|
934 // restore previous commsDat settings |
|
935 // cout<<"\nrestoring previous commsDat settings"<<endl; |
|
936 ret = EpocPostTestConfig(drive, platform, build); |
|
937 |
|
938 return ret; |
|
939 } |
|
940 |