88 if "bld.inf" in str(bld_path).lower(): |
84 if "bld.inf" in str(bld_path).lower(): |
89 os.chdir(os.path.normpath(os.path.join(bld_path, os.pardir))) |
85 os.chdir(os.path.normpath(os.path.join(bld_path, os.pardir))) |
90 else: |
86 else: |
91 os.chdir(os.path.normpath(os.path.join(bld_path))) |
87 os.chdir(os.path.normpath(os.path.join(bld_path))) |
92 |
88 |
93 if imacros is not None: |
89 if imacros and bld_drive: |
94 includedir = os.path.join(os.path.splitdrive(bld_path)[0] + os.sep, 'epoc32', 'include') |
90 includedir = os.path.join(bld_drive + os.sep, 'epoc32', 'include') |
95 command = r"cpp -imacros %s -I %s bld.inf" % (str(imacros), includedir) |
91 command = r"cpp -imacros %s -I %s bld.inf" % (str(imacros), includedir) |
96 else: |
92 else: |
97 command = u"cpp bld.inf" |
93 command = u"cpp bld.inf" |
98 |
94 |
99 process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE) |
95 process = subprocess.Popen(command, shell = True, stdout = subprocess.PIPE) |
196 #if harness == "": harness = None |
192 #if harness == "": harness = None |
197 test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
193 test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
198 test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness |
194 test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness |
199 test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
195 test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
200 test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
196 test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
|
197 test_sets[t_case[1]]['content'][t_case[1]]['dll_files'] = mmp_parser.get_dll_files(t_case[1]) |
201 else: |
198 else: |
202 for key, value in test_sets.items(): |
199 for key, value in test_sets.items(): |
203 if t_case[0] in value['content'].keys(): |
200 if t_case[0] in value['content'].keys(): |
204 harness = mmp_parser.get_harness(t_case[1]) |
201 harness = mmp_parser.get_harness(t_case[1]) |
205 if harness is "" or harness in test_sets[key]['content'][t_case[0]]['harness']: |
202 if harness is "" or harness in test_sets[key]['content'][t_case[0]]['harness']: |
206 test_sets[key]['content'][t_case[1]] = {} |
203 test_sets[key]['content'][t_case[1]] = {} |
207 test_sets[key]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
204 test_sets[key]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
208 test_sets[key]['content'][t_case[1]]['harness'] = harness |
205 test_sets[key]['content'][t_case[1]]['harness'] = harness |
209 test_sets[key]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
206 test_sets[key]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
210 test_sets[key]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
207 test_sets[key]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
|
208 test_sets[key]['content'][t_case[1]]['dll_files'] = mmp_parser.get_dll_files(t_case[1]) |
211 else: |
209 else: |
212 test_sets[t_case[1]] = {} |
210 test_sets[t_case[1]] = {} |
213 test_sets[t_case[1]]['content'] = {} |
211 test_sets[t_case[1]]['content'] = {} |
214 test_sets[t_case[1]]['content'][t_case[1]] = {} |
212 test_sets[t_case[1]]['content'][t_case[1]] = {} |
215 test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
213 test_sets[t_case[1]]['content'][t_case[1]]['type'] = mmp_parser.get_dll_type(t_case[1]) |
216 test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness |
214 test_sets[t_case[1]]['content'][t_case[1]]['harness'] = harness |
217 test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
215 test_sets[t_case[1]]['content'][t_case[1]]['pkg_files'] = pkg_parser.get_pkg_files(t_case[1], False) |
218 test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
216 test_sets[t_case[1]]['content'][t_case[1]]['mmp_files'] = bld_parser.get_test_mmp_files(t_case[1], False) |
|
217 test_sets[t_case[1]]['content'][t_case[1]]['dll_files'] = mmp_parser.get_dll_files(t_case[1]) |
219 |
218 |
220 os.chdir(temp_path) |
219 os.chdir(temp_path) |
221 if test_sets == {}: |
220 if test_sets == {}: |
222 for itm in output_list: |
221 for itm in output_list: |
223 _logger.debug(itm) |
222 _logger.debug(itm) |
428 get_dll_type("c:\path\to\mmp") |
427 get_dll_type("c:\path\to\mmp") |
429 |
428 |
430 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp" |
429 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp" |
431 """ |
430 """ |
432 return self.read_information_from_mmp(path_to_mmp, 7) |
431 return self.read_information_from_mmp(path_to_mmp, 7) |
|
432 |
|
433 def get_dll_files(self, path_to_mmp = None): |
|
434 """ |
|
435 Returns the dll files and their harness of the test component |
|
436 """ |
|
437 return self.read_information_from_mmp(path_to_mmp, 8) |
|
438 |
|
439 def get_mmp_harness(self, libraries=None): |
|
440 """ |
|
441 Harness was actually calculated at the test component level, it has to be calculated at the |
|
442 mmp file level and it has to be stored as "dll file":"harness" in a dictionary so that while writing |
|
443 execute step in test.xml; the dlls which doesn't have any harness are skipped from being written. |
|
444 |
|
445 This method identifies the harness from the given list of list libraries found in mmp file under LIBRARY tag(s) |
|
446 Returns the harness of the libraries in mmp file |
|
447 """ |
|
448 stif = False |
|
449 eunit = False |
|
450 stifunit = False |
|
451 generic = False |
|
452 if libraries: |
|
453 if "stiftestinterface.lib" in libraries: |
|
454 stif = True |
|
455 if "eunit.lib" in libraries or "qttest.lib" in libraries: |
|
456 eunit = True |
|
457 if "stifunit.lib" in libraries: |
|
458 stifunit = True |
|
459 elif "testexecuteutils.lib" in libraries or 'testframeworkclient.lib' in libraries or 'rtest' in libraries or 'symbianunittestfw.lib' in libraries: |
|
460 generic = True |
|
461 |
|
462 return self.select_harness(generic, stif, eunit, stifunit) |
|
463 |
|
464 |
|
465 def select_harness(self, generic, stif, eunit, stifunit): |
|
466 """ |
|
467 return the harness based on the Test Framework |
|
468 """ |
|
469 harness = "" |
|
470 if generic: |
|
471 harness = "GENERIC" |
|
472 elif stif and eunit: |
|
473 #_logger.warning("both eunit.lib and stiftestinterface.lib listed in mmp file - choosing STIF.") |
|
474 harness = "STIF" |
|
475 elif stif and not eunit: |
|
476 harness = "STIF" |
|
477 elif eunit and not stif: |
|
478 harness = "EUNIT" |
|
479 elif stifunit and not stif and not eunit: |
|
480 harness = "STIFUNIT" |
|
481 |
|
482 return harness |
|
483 |
|
484 |
433 |
485 |
434 def read_information_from_mmp(self, path_to_mmp, flag = 0): |
486 def read_information_from_mmp(self, path_to_mmp, flag = 0): |
435 """ |
487 """ |
436 Returns wanted information - user can define |
488 Returns wanted information - user can define |
437 the wanted information level by setting a flag |
489 the wanted information level by setting a flag |
470 lst_mmp_paths = lst_mmp_paths + self.mmp_files |
520 lst_mmp_paths = lst_mmp_paths + self.mmp_files |
471 else: |
521 else: |
472 lst_mmp_paths.append(self.path_to_mmp) |
522 lst_mmp_paths.append(self.path_to_mmp) |
473 |
523 |
474 for mmp in lst_mmp_paths: |
524 for mmp in lst_mmp_paths: |
|
525 mmp_harness = "" |
475 mmp_file = open(mmp, 'r') |
526 mmp_file = open(mmp, 'r') |
476 for line in mmp_file: |
527 for line in mmp_file: |
477 if re.match(r"\A(target\s).*([.]\w+)", line.lower().strip()): |
528 if re.match(r"\A(target\s).*([.]\w+)", line.lower().strip()): |
478 found = re.findall(r"\Atarget[\s]*(\w+[.]\w+)", line.lower()) |
529 found = re.findall(r"\Atarget[\s]*(\w+[.]\w+)", line.lower()) |
479 if found: |
530 if found: |
480 filename = found[0] |
531 filename = found[0] |
481 elif re.match(r"\A(targettype\s).*", line.lower().strip()): |
532 elif re.match(r"\A(targettype\s).*", line.lower().strip()): |
482 found = re.findall(r"\Atargettype[\s]*(\w+)", line.lower()) |
533 found = re.findall(r"\Atargettype[\s]*(\w+)", line.lower()) |
483 if found: |
534 if found: |
484 filetype = found[0] |
535 filetype = found[0] |
485 |
536 libs = [] |
486 libraries = libraries + re.findall(r"\b(\w+[.]lib)\b", mmp.text().lower()) |
537 libs = re.findall(r"\b(\w+[.]lib)\b", mmp.text().lower()) |
|
538 # get harness for a mmp/dll file |
|
539 mmp_harness = self.get_mmp_harness(libs) |
|
540 # store the harness of every dll file, later to be used while writing test.xml execute steps |
|
541 dll_files[filename] = mmp_harness |
|
542 libraries = libraries + libs |
487 if '//rtest' in mmp.text().lower() or '* rtest' in mmp.text().lower() or '// rtest' in mmp.text().lower(): |
543 if '//rtest' in mmp.text().lower() or '* rtest' in mmp.text().lower() or '// rtest' in mmp.text().lower(): |
488 libraries.append('rtest') |
544 libraries.append('rtest') |
489 |
545 |
490 if libraries: |
546 # get harness for one (sub)component file |
491 if "stiftestinterface.lib" in libraries: |
547 harness = self.get_mmp_harness(libraries) |
492 stif = True |
|
493 if "eunit.lib" in libraries or "qttest.lib" in libraries: |
|
494 eunit = True |
|
495 if "stifunit.lib" in libraries: |
|
496 stifunit = True |
|
497 elif "testexecuteutils.lib" in libraries or 'testframeworkclient.lib' in libraries or 'rtest' in libraries: |
|
498 tef = True |
|
499 |
|
500 if tef: |
|
501 harness = "GENERIC" |
|
502 elif stif and eunit: |
|
503 #_logger.warning("both eunit.lib and stiftestinterface.lib listed in mmp file - choosing STIF.") |
|
504 harness = "STIF" |
|
505 elif stif and not eunit: |
|
506 harness = "STIF" |
|
507 elif eunit and not stif: |
|
508 harness = "EUNIT" |
|
509 elif stifunit and not stif and not eunit: |
|
510 harness = "STIFUNIT" |
|
511 |
548 |
512 if harness is "": |
549 if harness is "": |
513 dll_type = "dependent" |
550 dll_type = "dependent" |
514 elif harness is "EUNIT": |
551 elif harness is "EUNIT": |
515 dll_type = "executable" |
552 dll_type = "executable" |
516 elif harness is "STIF": |
553 elif harness is "STIF": |
517 dll_type = "executable" |
554 dll_type = "executable" |
518 |
555 |
519 except: |
556 except: |
520 traceback.print_exc() |
557 traceback.print_exc() |
521 finally: |
558 else: |
|
559 returnvals = None |
522 if flag == 0: |
560 if flag == 0: |
523 return (filename, filetype, libraries, harness) |
561 returnvals = (filename, filetype, libraries, harness) |
524 elif flag == 1: |
562 elif flag == 1: |
525 return (filename, filetype, libraries) |
563 returnvals = (filename, filetype, libraries) |
526 elif flag == 2: |
564 elif flag == 2: |
527 return (filename, filetype) |
565 returnvals = (filename, filetype) |
528 elif flag == 3: |
566 elif flag == 3: |
529 return filename |
567 returnvals = filename |
530 elif flag == 4: |
568 elif flag == 4: |
531 return filetype |
569 returnvals = filetype |
532 elif flag == 5: |
570 elif flag == 5: |
533 return libraries |
571 returnvals = libraries |
534 elif flag == 6: |
572 elif flag == 6: |
535 return harness |
573 returnvals = harness |
536 elif flag == 7: |
574 elif flag == 7: |
537 return dll_type |
575 returnvals = dll_type |
|
576 elif flag == 8: |
|
577 returnvals = dll_files |
|
578 return returnvals |
538 |
579 |
539 class PkgFileParser(object): |
580 class PkgFileParser(object): |
540 """ |
581 """ |
541 Parses .pkg files. Returns a list of: |
582 Parses .pkg files. Returns a list of: |
542 a. src path of the file |
583 a. src path of the file |
543 b. dst path on the phone |
584 b. dst path on the phone |
544 c. type of the file |
585 c. type of the file |
545 for every file in the pkg file |
586 for every file in the pkg file |
546 """ |
587 """ |
547 |
588 |
548 def __init__(self, bldpath, platform = None, specific_pkg = None, drive=''): |
589 def __init__(self, bldpath = None, platform = None, specific_pkg = None, drive=''): |
549 self.platform = platform |
590 self.platform = platform |
550 self.build_platform = None |
591 self.build_platform = None |
|
592 self.build_target = None |
551 if self.platform is not None and "_" in self.platform: |
593 if self.platform is not None and "_" in self.platform: |
552 plat_tar = re.search(r"(.*)_(.*).pkg", self.platform) |
594 plat_tar = re.search(r"(.*)_(.*).pkg", self.platform) |
553 self.build_platform, self.build_target = plat_tar.groups() |
595 self.build_platform, self.build_target = plat_tar.groups() |
554 self.drive = drive |
596 self.drive = drive |
555 self._files = [] |
597 self._files = [] |
655 #searches for the file path (src and dst) in the pkg file |
697 #searches for the file path (src and dst) in the pkg file |
656 #e.g.: "..\conf\VCXErrors.inc"-"C:\TestFramework\VCXErrors.inc" |
698 #e.g.: "..\conf\VCXErrors.inc"-"C:\TestFramework\VCXErrors.inc" |
657 result = re.search(r'^\s*"(.*?)".*?-.*?"(.*?)"', pkg_line) |
699 result = re.search(r'^\s*"(.*?)".*?-.*?"(.*?)"', pkg_line) |
658 |
700 |
659 if result is None: |
701 if result is None: |
|
702 if pkg_line.startswith('"'): |
|
703 _logger.warning(pkg_line.strip() + ' line not valid pkg format in ' + pkg_file) |
660 return None |
704 return None |
661 val1, val2 = result.groups() |
705 val1, val2 = result.groups() |
662 |
706 |
663 if val1 != "": |
707 if val1 != "": |
664 |
|
665 #replacing delimiters (${platform} and ${target}) in PKG file templates, |
708 #replacing delimiters (${platform} and ${target}) in PKG file templates, |
666 #for instance, QT tests PKG files have delimeters |
709 #for instance, QT tests PKG files have delimeters |
667 if "$(platform)" in val1.lower() and self.build_platform is not None: |
710 if "$(platform)" in val1.lower() and self.build_platform is not None: |
668 val1 = val1.lower().replace("$(platform)", self.build_platform) |
711 val1 = val1.lower().replace("$(platform)", self.build_platform) |
669 if "$(target)" in val1.lower() and self.build_target is not None: |
712 if "$(target)" in val1.lower() and self.build_target is not None: |
670 val1 = val1.lower().replace("$(target)", self.build_target) |
713 val1 = val1.lower().replace("$(target)", self.build_target) |
671 |
714 |
672 if path.isabs(path(val1).normpath()): |
715 #For MATTI PKG files in which location of the data files are unknown or can be changed |
673 map_src = os.path.normpath(os.path.join(self.drive, val1)) |
716 if "[PKG_LOC]" in val1.upper(): |
674 elif re.search(r"\A\w", val1, 1): |
717 val1 = val1.replace("[PKG_LOC]", self.pkg_file_path) |
675 map_src = str(path.joinpath(self.pkg_file_path + os.sep, os.path.normpath(val1)).normpath()) |
718 |
|
719 if os.path.exists(val1): |
|
720 map_src = os.path.abspath(val1) |
676 else: |
721 else: |
677 map_src = str(path.joinpath(self.pkg_file_path, path(val1)).normpath()) |
722 if os.path.isabs(os.path.normpath(val1)): |
678 map_dst = str(path(val2).normpath()) |
723 map_src = os.path.normpath(os.path.join(self.drive, val1)) |
|
724 elif re.search(r"\A\w", val1, 1): |
|
725 map_src = os.path.normpath(os.path.join(self.pkg_file_path + os.sep, os.path.normpath(val1))) |
|
726 else: |
|
727 map_src = os.path.normpath(os.path.join(self.pkg_file_path, val1)) |
|
728 map_dst = os.path.normpath(val2) |
679 else: |
729 else: |
680 map_src, map_dst = val1, val2 |
730 map_src, map_dst = val1, val2 |
681 map_src = map_src.strip() |
731 map_src = map_src.strip() |
682 |
732 |
683 #replaces the characters with the drive letters |
733 #replaces the characters with the drive letters |
729 file_type = "trace_init" |
782 file_type = "trace_init" |
730 elif ext == "pmd": |
783 elif ext == "pmd": |
731 file_type = "pmd" |
784 file_type = "pmd" |
732 elif ext == "script": |
785 elif ext == "script": |
733 if "testframeworkclient.lib" in _libraries_: |
786 if "testframeworkclient.lib" in _libraries_: |
734 file_type = "testscript:mtf" |
787 file_type = "testscript:mtf:testframework.exe" |
735 else: |
788 else: |
736 file_type = "testscript" |
789 file_type = "testscript:testexecute.exe" |
|
790 if ',' in pkg_line: |
|
791 exename = pkg_line.split(',')[1].strip() |
|
792 if exename == 'install_only': |
|
793 file_type = "data" |
|
794 elif exename == 'testframework.exe': |
|
795 file_type = "testscript:mtf:" + exename |
|
796 elif exename == 'testexecute.exe': |
|
797 file_type = "testscript:" + exename |
|
798 else: |
|
799 if "testframeworkclient.lib" in _libraries_: |
|
800 file_type = "testscript:mtf:" + exename |
|
801 else: |
|
802 file_type = "testscript:" + exename |
737 else: |
803 else: |
738 file_type = "data" |
804 file_type = "data" |
739 |
805 |
740 if not map_src or map_src == "." or not map_dst or map_dst == ".": |
806 if not map_src or map_src == "." or not map_dst or map_dst == ".": |
741 return None |
807 return None |