Changeset 93903 in vbox for trunk/src/VBox/ValidationKit/tests/unittests
- Timestamp:
- Feb 24, 2022 8:07:29 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py
r93876 r93903 45 45 # Validation Kit imports. 46 46 from common import utils; 47 from testdriver import base; 47 48 from testdriver import reporter; 48 49 from testdriver import vbox; … … 264 265 'testcase/tstTimer': '', 265 266 'testcase/tstThread-1': '', 266 'testcase/tstUtf8': '' ,267 } 267 'testcase/tstUtf8': '' 268 }; 268 269 269 270 # Test dependency list -- libraries. … … 354 355 self.sVBoxInstallRoot = None; 355 356 357 # Testing mode being used: 358 # "local": Execute unit tests locally (same host, default). 359 # "remote-copy": Copies unit tests from host to the remote, then executing it. 360 # "remote-exec": Executes unit tests right on the remote from a given source. 361 self.sMode = 'local'; 362 356 363 self.cSkipped = 0; 357 364 self.cPassed = 0; … … 463 470 reporter.log(' --dryrun'); 464 471 reporter.log(' Performs a dryrun (no tests being executed).'); 465 reporter.log(' -- local');466 reporter.log(' Runs unit tests locally (this host).');472 reporter.log(' --mode <local|remote>'); 473 reporter.log(' Specifies the execution mode.'); 467 474 reporter.log(' --only-whitelist'); 468 475 reporter.log(' Only processes the white list.'); 469 476 reporter.log(' --quick'); 470 477 reporter.log(' Very selective testing.'); 478 reporter.log(' --unittest-source <dir>'); 479 reporter.log(' Sets the unit test source to <dir>.'); 480 reporter.log(' Also used for remote execution.'); 481 reporter.log(' --vbox-install-root <dir>'); 482 reporter.log(' Sets the VBox install root to <dir>.'); 483 reporter.log(' Also used for remote execution.'); 471 484 return fRc; 472 485 … … 477 490 if asArgs[iArg] == '--dryrun': 478 491 self.fDryRun = True; 479 elif asArgs[iArg] == '--local': 480 # Disable the test VM set and only run stuff locally. 481 self.oTestVmSet = None; 492 elif asArgs[iArg] == '--mode': 493 iArg += 1; 494 if iArg >= len(asArgs): 495 raise base.InvalidOption('Option "%s" needs a value' % (asArgs[iArg - 1])); 496 if asArgs[iArg] == 'local': 497 self.sMode = asArgs[iArg]; 498 elif asArgs[iArg] == 'remote': 499 if self.sUnitTestsPathSrc: 500 self.sMode = 'remote-exec'; 501 else: 502 self.sMode = 'remote-copy'; 503 else: 504 raise base.InvalidOption('Argument "%s" invalid' % (asArgs[iArg])); 505 elif asArgs[iArg] == '--unittest-source': 506 iArg += 1; 507 if iArg >= len(asArgs): 508 raise base.InvalidOption('Option "%s" needs a value' % (asArgs[iArg - 1])); 509 self.sUnitTestsPathSrc = asArgs[iArg]; 510 self.sMode = 'remote-exec'; 482 511 elif asArgs[iArg] == '--only-whitelist': 483 512 self.fOnlyWhiteList = True; 484 513 elif asArgs[iArg] == '--quick': 485 514 self.fOnlyWhiteList = True; 515 elif asArgs[iArg] == '--vbox-install-root': 516 iArg += 1; 517 if iArg >= len(asArgs): 518 raise base.InvalidOption('Option "%s" needs a value' % (asArgs[iArg - 1])); 519 self.sVBoxInstallRoot = asArgs[iArg]; 486 520 else: 487 521 return vbox.TestDriver.parseOption(self, asArgs, iArg); … … 503 537 504 538 # Do the configuring. 505 if self. oTestVmSet:539 if self.sMode.startswith('remote'): 506 540 if self.sNicAttachment == 'nat': eNic0AttachType = vboxcon.NetworkAttachmentType_NAT; 507 541 elif self.sNicAttachment == 'bridged': eNic0AttachType = vboxcon.NetworkAttachmentType_Bridged; … … 524 558 if self.sUnitTestsPathSrc is None and not self._detectPaths(): 525 559 return False; 560 reporter.log2('Unit test source path is "%s"\n' % self.sUnitTestsPathSrc); 526 561 527 562 if not self.sUnitTestsPathDst: 528 563 self.sUnitTestsPathDst = self.sScratchPath; 529 reporter.log('Unit test destination path is "%s"\n' % self.sUnitTestsPathDst); 530 531 if self.oTestVmSet: # Run on a test VM (guest). 564 reporter.log2('Unit test destination path is "%s"\n' % self.sUnitTestsPathDst); 565 566 if self.sMode.startswith('remote'): # Run on a test VM (guest). 567 assert self.oTestVmSet is not None; 532 568 fRc = self.oTestVmSet.actionExecute(self, self.testOneVmConfig); 533 569 else: # Run locally (host). … … 552 588 553 589 reporter.log(''); 554 reporter.log('********************'); 555 reporter.log('Target: %s' % (oTestVm.sVmName if oTestVm else 'local')); 556 reporter.log('********************'); 590 if self.fDryRun: 591 reporter.log('*********************************************************'); 592 reporter.log('DRY RUN - DRY RUN - DRY RUN - DRY RUN - DRY RUN - DRY RUN'); 593 reporter.log('*********************************************************'); 594 reporter.log('*********************************************************'); 595 reporter.log(' Target: %s' % (oTestVm.sVmName if oTestVm else 'local')); 596 reporter.log(' Mode: %s' % (self.sMode)); 597 reporter.log('Unit tests source: %s %s' % (self.sUnitTestsPathSrc, \ 598 '(on remote)' if self.sMode is 'remote-exec' else '')); 599 reporter.log('VBox install root: %s %s' % (self.sVBoxInstallRoot, \ 600 '(on remote)' if self.sMode is 'remote-exec' else '')); 601 reporter.log('*********************************************************'); 557 602 reporter.log('*** PASSED: %d' % self.cPassed); 558 603 reporter.log('*** FAILED: %d' % self.cFailed); … … 570 615 # Simple test. 571 616 self.logVmInfo(oVM); 572 # Try waiting for a bit longer (5 minutes) until the CD is available to avoid running into timeouts. 573 self.oSession, self.oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, \ 574 fCdWait = True, \ 575 cMsCdWait = 5 * 60 * 1000); 617 618 if not self.fDryRun: 619 # Try waiting for a bit longer (5 minutes) until the CD is available to avoid running into timeouts. 620 self.oSession, self.oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, \ 621 fCdWait = not self.fDryRun, \ 622 cMsCdWait = 5 * 60 * 1000); 623 if self.oSession is None: 624 return False; 625 626 self.addTask(self.oTxsSession); 627 628 # Determine the unit tests destination path. 629 self.sUnitTestsPathDst = oTestVm.pathJoin(self.getGuestTempDir(oTestVm), 'testUnitTests'); 630 631 # Run the unit tests. 632 self._testRunUnitTests(oTestVm); 633 634 # Cleanup. 576 635 if self.oSession is not None: 577 self.addTask(self.oTxsSession);578 579 # Determine the unit tests destination path.580 self.sUnitTestsPathDst = oTestVm.pathJoin(self.getGuestTempDir(oTestVm), 'testUnitTests');581 582 # Run the unit tests.583 self._testRunUnitTests(oTestVm);584 585 # Cleanup.586 636 self.removeTask(self.oTxsSession); 587 637 self.terminateVmBySession(self.oSession); 588 return True; 589 590 return False; 638 return True; 591 639 592 640 # … … 683 731 otherwise False is returned. 684 732 """ 685 reporter.log ('Executing [sudo]: %s' % (asArgs, ));686 if self. oTestVmSet:733 reporter.log2('Executing [sudo]: %s' % (asArgs, )); 734 if self.sMode.startswith('remote'): 687 735 iRc = -1; ## @todo Not used remotely yet. 688 736 else: … … 695 743 return iRc == 0; 696 744 697 def _ hardenedPathExists(self, sPath):745 def _wrapPathExists(self, sPath): 698 746 """ 699 747 Creates the directory specified sPath (including parents). 700 748 """ 701 reporter.log('_hardenedPathExists: %s' % (sPath,)); 749 reporter.log2('_wrapPathExists: %s' % (sPath,)); 750 if self.fDryRun: 751 return True; 702 752 fRc = False; 703 if self. oTestVmSet:753 if self.sMode.startswith('remote'): 704 754 fRc = self.txsIsDir(self.oSession, self.oTxsSession, sPath, fIgnoreErrors = True); 705 755 if not fRc: … … 709 759 return fRc; 710 760 711 def _ hardenedMkDir(self, sPath):761 def _wrapMkDir(self, sPath): 712 762 """ 713 763 Creates the directory specified sPath (including parents). 714 764 """ 715 reporter.log('_hardenedMkDir: %s' % (sPath,)); 765 reporter.log2('_wrapMkDir: %s' % (sPath,)); 766 if self.fDryRun: 767 return True; 716 768 fRc = True; 717 if self. oTestVmSet:769 if self.sMode.startswith('remote'): 718 770 fRc = self.txsMkDirPath(self.oSession, self.oTxsSession, sPath, fMode = 0o755); 719 771 else: … … 726 778 return True; 727 779 728 def _ hardenedCopyFile(self, sSrc, sDst, iMode):780 def _wrapCopyFile(self, sSrc, sDst, iMode): 729 781 """ 730 782 Copies a file. 731 783 """ 732 reporter.log('_hardenedCopyFile: %s -> %s (mode: %o)' % (sSrc, sDst, iMode,)); 784 reporter.log2('_wrapCopyFile: %s -> %s (mode: %o)' % (sSrc, sDst, iMode,)); 785 if self.fDryRun: 786 return True; 733 787 fRc = True; 734 if self.oTestVmSet: 735 fRc = self.txsUploadFile(self.oSession, self.oTxsSession, sSrc, sDst); 736 if fRc: 737 self.oTxsSession.syncChMod(sDst, 0o755); 788 if self.sMode.startswith('remote'): 789 if self.sMode == 'remote-exec': 790 self.oTxsSession.txsCopyFile(self.oSession, self.oTxsSession, sSrc, sDst, iMode); 791 else: 792 fRc = self.txsUploadFile(self.oSession, self.oTxsSession, sSrc, sDst); 793 if fRc: 794 self.oTxsSession.syncChMod(sDst, iMode); 738 795 else: 739 796 if utils.getHostOs() in [ 'win', 'os2' ]: … … 750 807 return True; 751 808 752 def _ hardenedDeleteFile(self, sPath):809 def _wrapDeleteFile(self, sPath): 753 810 """ 754 811 Deletes a file. 755 812 """ 756 reporter.log('_hardenedDeleteFile: %s' % (sPath,)); 813 reporter.log2('_wrapDeleteFile: %s' % (sPath,)); 814 if self.fDryRun: 815 return True; 757 816 fRc = True; 758 if self. oTestVmSet:817 if self.sMode.startswith('remote'): 759 818 if self.txsIsFile(self.oSession, self.oTxsSession, sPath): 760 819 fRc = self.txsRmFile(self.oSession, self.oTxsSession, sPath); … … 769 828 return True; 770 829 771 def _ hardenedRemoveDir(self, sPath):830 def _wrapRemoveDir(self, sPath): 772 831 """ 773 832 Removes a directory. 774 833 """ 775 reporter.log('_hardenedRemoveDir: %s' % (sPath,)); 834 reporter.log2('_wrapRemoveDir: %s' % (sPath,)); 835 if self.fDryRun: 836 return True; 776 837 fRc = True; 777 if self. oTestVmSet:838 if self.sMode.startswith('remote'): 778 839 if self.txsIsDir(self.oSession, self.oTxsSession, sPath): 779 840 fRc = self.txsRmDir(self.oSession, self.oTxsSession, sPath); … … 789 850 790 851 def _envSet(self, sName, sValue): 791 if self. oTestVmSet:852 if self.sMode.startswith('remote'): 792 853 # For remote execution we cache the environment block and pass it 793 854 # right when the process execution happens. … … 806 867 # 807 868 # If hardening is enabled, some test cases and their dependencies 808 # needs to be copied to and execute from the s VBoxInstallRoot869 # needs to be copied to and execute from the source 809 870 # directory in order to work. They also have to be executed as 810 871 # root, i.e. via sudo. 811 872 # 812 873 fHardened = False; 813 f ToRemote= False;874 fCopyToRemote = False; 814 875 fCopyDeps = False; 815 876 asFilesToRemove = []; # Stuff to clean up. … … 820 881 fHardened = True; 821 882 822 if self. oTestVmSet:823 f ToRemote = True;824 fCopyDeps = True;883 if self.sMode.startswith('remote'): 884 fCopyToRemote = True; 885 fCopyDeps = True; 825 886 826 887 if fHardened \ 827 or f ToRemote:828 if f ToRemote:888 or fCopyToRemote: 889 if fCopyToRemote: 829 890 sDstDir = os.path.join(self.sUnitTestsPathDst, sTestCaseSubDir); 830 891 else: 831 892 sDstDir = os.path.join(self.sVBoxInstallRoot, sTestCaseSubDir); 832 if not self._ hardenedPathExists(sDstDir):833 self._ hardenedMkDir(sDstDir);893 if not self._wrapPathExists(sDstDir): 894 self._wrapMkDir(sDstDir); 834 895 asDirsToRemove.append(sDstDir); 835 896 836 897 sDst = os.path.join(sDstDir, os.path.basename(sFullPath)); 837 self._ hardenedCopyFile(sFullPath, sDst, 0o755);898 self._wrapCopyFile(sFullPath, sDst, 0o755); 838 899 asFilesToRemove.append(sDst); 839 900 … … 842 903 for sLib in self.kdTestCaseDepsLibs: 843 904 for sSuff in [ '.dll', '.so', '.dylib' ]: 905 assert self.sVBoxInstallRoot is not None; 844 906 sSrc = os.path.join(self.sVBoxInstallRoot, sLib + sSuff); 845 if os.path.exists(sSrc):907 if self._wrapPathExists(sSrc): 846 908 sDst = os.path.join(sDstDir, os.path.basename(sSrc)); 847 self._ hardenedCopyFile(sSrc, sDst, 0o644);909 self._wrapCopyFile(sSrc, sDst, 0o644); 848 910 asFilesToRemove.append(sDst); 849 911 … … 853 915 if os.path.exists(sSrc): 854 916 sDst = os.path.join(sDstDir, os.path.basename(sSrc)); 855 self._ hardenedCopyFile(sSrc, sDst, 0o644);917 self._wrapCopyFile(sSrc, sDst, 0o644); 856 918 asFilesToRemove.append(sDst); 857 919 … … 863 925 if os.path.exists(sSrc): 864 926 sDst = os.path.join(sDstDir, os.path.basename(sSrc)); 865 self._ hardenedCopyFile(sSrc, sDst, 0o644);927 self._wrapCopyFile(sSrc, sDst, 0o644); 866 928 asFilesToRemove.append(sDst); 867 929 … … 880 942 self._envSet('IPRT_TEST_FILE', sXmlFile); 881 943 882 if self._ hardenedPathExists(sXmlFile):944 if self._wrapPathExists(sXmlFile): 883 945 try: os.unlink(sXmlFile); 884 except: self._ hardenedDeleteFile(sXmlFile);946 except: self._wrapDeleteFile(sXmlFile); 885 947 886 948 # … … 897 959 try: sys.stderr.flush(); 898 960 except: pass; 961 962 iRc = 0; 963 899 964 if not self.fDryRun: 900 if f ToRemote:965 if fCopyToRemote: 901 966 fRc = self.txsRunTest(self.oTxsSession, sName, 30 * 60 * 1000, asArgs[0], asArgs, self.asEnv, \ 902 fCheckSessionStatus = True);967 fCheckSessionStatus = True); 903 968 if fRc: 904 969 iRc = 0; … … 912 977 iRc = -1; ## @todo 913 978 else: 979 oChild = None; 914 980 try: 915 981 if fHardened: … … 931 997 iRc = oChild.wait(); 932 998 self.pidFileRemove(oChild.pid); 933 else:934 iRc = 0;935 936 999 # 937 1000 # Clean up 938 1001 # 939 1002 for sPath in asFilesToRemove: 940 self._ hardenedDeleteFile(sPath);1003 self._wrapDeleteFile(sPath); 941 1004 for sPath in asDirsToRemove: 942 self._ hardenedRemoveDir(sPath);1005 self._wrapRemoveDir(sPath); 943 1006 944 1007 # … … 948 1011 reporter.addSubXmlFile(sXmlFile); 949 1012 if fHardened: 950 self._ hardenedDeleteFile(sXmlFile);1013 self._wrapDeleteFile(sXmlFile); 951 1014 else: 952 1015 os.unlink(sXmlFile); … … 1002 1065 # Process the file list and run everything looking like a testcase. 1003 1066 # 1004 for sFilename in sorted(os.listdir(os.path.join(self.sUnitTestsPathSrc, sTestCaseSubDir))): 1067 if not self.fOnlyWhiteList: 1068 if self.sMode == 'local' \ 1069 or self.sMode == 'remote-copy': 1070 asFiles = sorted(os.listdir(os.path.join(self.sUnitTestsPathSrc, sTestCaseSubDir))); 1071 else: # 'remote-exec' 1072 ## @todo Implement remote file enumeration / directory listing. 1073 reporter.error('Sorry, no remote file enumeration implemented yet!\nUse --only-whitelist instead.'); 1074 return False; 1075 else: 1076 # Transform our dict into a list, where the keys are the list elements. 1077 asFiles = list(self.kdTestCasesWhiteList.keys()); 1078 # Make sure to only keep the list item's base name so that the iteration down below works 1079 # with our white list without any additional modification. 1080 asFiles = [os.path.basename(s) for s in asFiles]; 1081 1082 for sFilename in asFiles: 1005 1083 # Separate base and suffix and morph the base into something we 1006 1084 # can use for reporting and array lookups. 1007 sName, sSuffix = os.path.splitext(sFilename); 1085 sBaseName = os.path.basename(sFilename); 1086 sName, sSuffix = os.path.splitext(sBaseName); 1008 1087 if sTestCaseSubDir != '.': 1009 1088 sName = sTestCaseSubDir + '/' + sName; 1010 1089 1090 reporter.log2('sTestCasePattern=%s, sBaseName=%s, sName=%s, sFileName=%s' \ 1091 % (sTestCasePattern, sBaseName, sName, sFilename,)); 1092 1011 1093 # Process white list first, if set. 1012 1094 if self.fOnlyWhiteList \ 1013 and sName not in self.kdTestCasesWhiteList:1014 reporter.log 2('"%s" is not in white list, skipping.' % (sFilename,));1095 and not self._isExcluded(sName, self.kdTestCasesWhiteList): 1096 reporter.log('%s: SKIPPED (not in white list)' % (sName,)); 1015 1097 continue; 1016 1098 1017 1099 # Basic exclusion. 1018 if not re.match(sTestCasePattern, s Filename) \1100 if not re.match(sTestCasePattern, sBaseName) \ 1019 1101 or sSuffix in self.kasSuffixBlackList: 1020 reporter.log2('"%s" is not a test case.' % (s Filename,));1102 reporter.log2('"%s" is not a test case.' % (sName,)); 1021 1103 continue; 1022 1104
Note:
See TracChangeset
for help on using the changeset viewer.