Changeset 79193 in vbox for trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
- Timestamp:
- Jun 17, 2019 5:41:18 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131366
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
r79185 r79193 239 239 240 240 class tdTestCopyFromDir(tdTestCopyFrom): 241 pass; 241 242 def __init__(self, sSrc = "", sDst = "", sUser = None, sPassword = None, fFlags = None, oSrc = None, fIntoDst = False): 243 tdTestCopyFrom.__init__(self, sSrc, sDst, sUser, sPassword, fFlags, oSrc); 244 self.fIntoDst = fIntoDst; # hint to the verification code that sDst == oSrc, rather than sDst+oSrc.sNAme == oSrc. 242 245 243 246 class tdTestCopyFromFile(tdTestCopyFrom): … … 259 262 os.rmdir(self.sDir); 260 263 except: 261 re porter.errorXcpt('%s: sDir=%s' % (sMsgPrefix, self.sDir,));264 return reporter.errorXcpt('%s: sDir=%s' % (sMsgPrefix, self.sDir,)); 262 265 return True; 263 266 … … 1124 1127 _ = oSession; 1125 1128 1126 #reporter.log('Take snapshot now!');1127 #self.oTstDrv.sleep(22);1128 #return False;1129 1130 1129 # Make sure the temporary directory exists. 1131 1130 for sDir in [self.getGuestTempDir(oTestVm), ]: … … 1142 1141 # 1143 1142 1144 def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected):1143 def gctrlCopyFileFrom(self, oGuestSession, oTest, fExpected): 1145 1144 """ 1146 1145 Helper function to copy a single file from the guest to the host. 1147 1146 """ 1148 reporter.log2('Copying guest file "%s" to host "%s"' % (sSrc, sDst)); 1147 # 1148 # Do the copying. 1149 # 1150 reporter.log2('Copying guest file "%s" to host "%s"' % (oTest.sSrc, oTest.sDst)); 1149 1151 try: 1150 1152 if self.oTstDrv.fpApiVer >= 5.0: 1151 oCurProgress = oGuestSession.fileCopyFromGuest( sSrc, sDst,fFlags);1153 oCurProgress = oGuestSession.fileCopyFromGuest(oTest.sSrc, oTest.sDst, oTest.fFlags); 1152 1154 else: 1153 oCurProgress = oGuestSession.copyFrom( sSrc, sDst,fFlags);1155 oCurProgress = oGuestSession.copyFrom(oTest.sSrc, oTest.sDst, oTest.fFlags); 1154 1156 except: 1155 reporter.maybeErrXcpt(fExpected, 'Copy from exception for sSrc="%s", sDst="%s":' % ( sSrc,sDst,));1157 reporter.maybeErrXcpt(fExpected, 'Copy from exception for sSrc="%s", sDst="%s":' % (oTest.sSrc, oTest.sDst,)); 1156 1158 return False; 1157 1159 if oCurProgress is None: … … 1162 1164 oProgress.logResult(fIgnoreErrors = not fExpected); 1163 1165 return False; 1166 1167 # 1168 # Check the result if we can. 1169 # 1170 if oTest.oSrc: 1171 assert isinstance(oTest.oSrc, testfileset.TestFile); 1172 sDst = oTest.sDst; 1173 if os.path.isdir(sDst): 1174 sDst = os.path.join(sDst, oTest.oSrc.sName); 1175 try: 1176 oFile = open(sDst, 'rb'); 1177 except: 1178 return reporter.errorXcpt('open(%s) failed during verfication' % (sDst,)); 1179 fEqual = oTest.oSrc.equalFile(oFile); 1180 oFile.close(); 1181 if not fEqual: 1182 return reporter.error('Content differs for "%s"' % (sDst,)); 1183 1164 1184 return True; 1165 1185 1166 def gctrlCopyDirFrom(self, oGuestSession, sSrc, sDst, fFlags, fExpected): 1186 def __compareTestDir(self, oDir, sHostPath): # type: (testfileset.TestDir, str) -> bool 1187 """ 1188 Recursively compare the content of oDir and sHostPath. 1189 1190 Returns True on success, False + error logging on failure. 1191 1192 Note! This ASSUMES that nothing else was copied to sHostPath! 1193 """ 1194 # 1195 # First check out all the entries and files in the directory. 1196 # 1197 dLeftUpper = dict(oDir.dChildrenUpper); 1198 try: 1199 asEntries = os.listdir(sHostPath); 1200 except: 1201 return reporter.errorXcpt('os.listdir(%s) failed' % (sHostPath,)); 1202 1203 fRc = True; 1204 for sEntry in asEntries: 1205 sEntryUpper = sEntry.upper(); 1206 if sEntryUpper not in dLeftUpper: 1207 fRc = reporter.error('Unexpected entry "%s" in "%s"' % (sEntry, sHostPath,)); 1208 else: 1209 oFsObj = dLeftUpper[sEntryUpper]; 1210 del dLeftUpper[sEntryUpper]; 1211 1212 if isinstance(oFsObj, testfileset.TestFile): 1213 sFilePath = os.path.join(sHostPath, oFsObj.sName); 1214 try: 1215 oFile = open(sFilePath, 'rb'); 1216 except: 1217 fRc = reporter.errorXcpt('open(%s) failed during verfication' % (sFilePath,)); 1218 else: 1219 fEqual = oFsObj.equalFile(oFile); 1220 oFile.close(); 1221 if not fEqual: 1222 fRc = reporter.error('Content differs for "%s"' % (sFilePath,)); 1223 1224 # List missing entries: 1225 for sKey in dLeftUpper: 1226 oEntry = dLeftUpper[sKey]; 1227 fRc = reporter.error('%s: Missing %s "%s" (src path: %s)' 1228 % (sHostPath, oEntry.sName, 1229 'file' if isinstance(oEntry, testfileset.TestFile) else 'directory', oEntry.sPath)); 1230 1231 # 1232 # Recurse into subdirectories. 1233 # 1234 for oFsObj in oDir.aoChildren: 1235 if isinstance(oFsObj, testfileset.TestDir): 1236 fRc = self.__compareTestDir(oFsObj, os.path.join(sHostPath, oFsObj.sName)) and fRc; 1237 return fRc; 1238 1239 def gctrlCopyDirFrom(self, oGuestSession, oTest, fExpected): 1167 1240 """ 1168 1241 Helper function to copy a directory from the guest to the host. 1169 1242 """ 1170 reporter.log2('Copying guest dir "%s" to host "%s"' % (sSrc, sDst)); 1243 # 1244 # Do the copying. 1245 # 1246 reporter.log2('Copying guest dir "%s" to host "%s"' % (oTest.sSrc, oTest.sDst)); 1171 1247 try: 1172 oCurProgress = oGuestSession.directoryCopyFromGuest( sSrc, sDst,fFlags);1248 oCurProgress = oGuestSession.directoryCopyFromGuest(oTest.sSrc, oTest.sDst, oTest.fFlags); 1173 1249 except: 1174 reporter.maybeErrXcpt(fExpected, 'Copy dir from exception for sSrc="%s", sDst="%s":' % ( sSrc,sDst,));1250 reporter.maybeErrXcpt(fExpected, 'Copy dir from exception for sSrc="%s", sDst="%s":' % (oTest.sSrc, oTest.sDst,)); 1175 1251 return False; 1176 1252 if oCurProgress is None: … … 1182 1258 oProgress.logResult(fIgnoreErrors = not fExpected); 1183 1259 return False; 1260 1261 # 1262 # Check the result if we can. 1263 # 1264 if oTest.oSrc: 1265 assert isinstance(oTest.oSrc, testfileset.TestDir); 1266 sDst = oTest.sDst; 1267 if oTest.fIntoDst: 1268 return self.__compareTestDir(oTest.oSrc, os.path.join(sDst, oTest.oSrc.sName)); 1269 oDummy = testfileset.TestDir(None, 'dummy'); 1270 oDummy.aoChildren = [oTest.oSrc,] 1271 oDummy.dChildrenUpper = { oTest.oSrc.sName.upper(): oTest.oSrc, }; 1272 return self.__compareTestDir(oDummy, sDst); 1184 1273 return True; 1185 1274 … … 3576 3665 # 3577 3666 sScratchHst = os.path.join(self.oTstDrv.sScratchPath, "testGctrlCopyFrom"); 3667 sScratchDstDir1Hst = os.path.join(sScratchHst, "dstdir1"); 3668 sScratchDstDir2Hst = os.path.join(sScratchHst, "dstdir2"); 3669 sScratchDstDir3Hst = os.path.join(sScratchHst, "dstdir3"); 3578 3670 oExistingFileGst = self.oTestFiles.chooseRandomFile(); 3579 3671 oNonEmptyDirGst = self.oTestFiles.chooseRandomDirFromTree(fNonEmpty = True); … … 3594 3686 else: 3595 3687 try: 3596 os.mkdir(sScratchHst) 3688 os.mkdir(sScratchHst); 3597 3689 except: 3598 return reporter.errorXcpt('sScratchHst=%s' % (sScratchHst, )); 3690 return reporter.errorXcpt('os.mkdir(%s)' % (sScratchHst, )); 3691 3692 for sSubDir in (sScratchDstDir1Hst, sScratchDstDir2Hst, sScratchDstDir3Hst): 3693 try: 3694 os.mkdir(sSubDir); 3695 except: 3696 return reporter.errorXcpt('os.mkdir(%s)' % (sSubDir, )); 3599 3697 3600 3698 # … … 3679 3777 atTests.extend([ 3680 3778 # Copy the empty guest directory (should end up as sScratchHst/empty): 3681 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst), tdTestResultSuccess() ],3779 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst), tdTestResultSuccess() ], 3682 3780 # Repeat -- this time it should fail, as the destination directory already exists (and 3683 3781 # DirectoryCopyFlag_CopyIntoExisting is not specified): 3684 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst), tdTestResultFailure() ],3782 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst), tdTestResultFailure() ], 3685 3783 # Add the DirectoryCopyFlag_CopyIntoExisting flag being set and it should work. 3686 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst,3784 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst, 3687 3785 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting, ]), tdTestResultSuccess() ], 3688 # Try again with trailing slash 3689 [ tdTestRemoveHostDir(os.path.join(sScratch Hst, 'empty')), tdTestResult() ],3690 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst + os.path.sep),3786 # Try again with trailing slash, should yield the same result: 3787 [ tdTestRemoveHostDir(os.path.join(sScratchDstDir1Hst, 'empty')), tdTestResult() ], 3788 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst + os.path.sep), 3691 3789 tdTestResultSuccess() ], 3692 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst + os.path.sep),3790 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst + os.path.sep), 3693 3791 tdTestResultFailure() ], 3694 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratch Hst + os.path.sep,3792 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = sScratchDstDir1Hst + os.path.sep, 3695 3793 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting, ]), tdTestResultSuccess() ], 3696 # Copy with a different destination name :3697 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = os.path.join(sScratchHst, 'empty2') ),3794 # Copy with a different destination name just for the heck of it: 3795 [ tdTestCopyFromDir(oSrc = oEmptyDirGst, sDst = os.path.join(sScratchHst, 'empty2'), fIntoDst = True), 3698 3796 tdTestResultFailure() ], 3699 3797 # Now the same using a directory with files in it: 3700 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratch Hst), tdTestResultSuccess() ],3701 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratch Hst), tdTestResultFailure() ],3702 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratch Hst,3798 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratchDstDir2Hst), tdTestResultSuccess() ], 3799 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratchDstDir2Hst), tdTestResultFailure() ], 3800 [ tdTestCopyFromDir(oSrc = oNonEmptyDirGst, sDst = sScratchDstDir2Hst, 3703 3801 fFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting, ]), tdTestResultSuccess() ], 3704 3802 # Copy the entire test tree: 3705 [ tdTestCopyFromDir(sSrc = self.oTestFiles.oTreeDir.sPath, sDst = sScratch Hst), tdTestResultSuccess() ],3803 [ tdTestCopyFromDir(sSrc = self.oTestFiles.oTreeDir.sPath, sDst = sScratchDstDir3Hst), tdTestResultSuccess() ], 3706 3804 ]); 3707 3805 … … 3733 3831 3734 3832 if isinstance(oCurTest, tdTestCopyFromFile): 3735 fRc2 = self.gctrlCopyFileFrom(oCurGuestSession, oCurTest .sSrc, oCurTest.sDst, oCurTest.fFlags, oCurRes.fRc);3833 fRc2 = self.gctrlCopyFileFrom(oCurGuestSession, oCurTest, oCurRes.fRc); 3736 3834 else: 3737 fRc2 = self.gctrlCopyDirFrom(oCurGuestSession, oCurTest .sSrc, oCurTest.sDst, oCurTest.fFlags, oCurRes.fRc);3835 fRc2 = self.gctrlCopyDirFrom(oCurGuestSession, oCurTest, oCurRes.fRc); 3738 3836 3739 3837 if fRc2 != oCurRes.fRc: 3740 3838 fRc = reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, oCurRes.fRc)); 3741 3839 fRc2 = False; 3742 3743 if fRc2 is True:3744 pass; ## @todo verify the result.3745 3840 3746 3841 fRc = oCurTest.closeSession(fIsError = True) and fRc;
Note:
See TracChangeset
for help on using the changeset viewer.