#!/usr/bin/env python # -*- coding: utf-8 -*- """ VirtualBox Validation Kit - Shared Folders """ __copyright__ = \ """ Copyright (C) 2010-2019 Oracle Corporation This file is part of VirtualBox Open Source Edition (OSE), as available from http://www.virtualbox.org. This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) as published by the Free Software Foundation, in version 2 as it comes in the "COPYING" file of the VirtualBox OSE distribution. VirtualBox OSE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. The contents of this file may alternatively be used under the terms of the Common Development and Distribution License Version 1.0 (CDDL) only, as it comes in the "COPYING.CDDL" file of the VirtualBox OSE distribution, in which case the provisions of the CDDL are applicable instead of those of the GPL. You may elect to license modified versions of this file under the terms and conditions of either the GPL or the CDDL or both. """ __version__ = "$Revision: 78642 $" # Standard Python imports. import os import shutil import sys # Only the main script needs to modify the path. try: __file__ except: __file__ = sys.argv[0]; g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))); sys.path.append(g_ksValidationKitDir); # Validation Kit imports. from testdriver import reporter; from testdriver import base; from testdriver import vbox; from testdriver import vboxcon; from testdriver import vboxwrappers; from common import utils; # Python 3 hacks: if sys.version_info[0] >= 3: long = int # pylint: disable=W0622,C0103 class SubTstDrvAddSharedFolders1(base.SubTestDriverBase): """ Sub-test driver for executing shared folders tests. """ def __init__(self, oTstDrv): base.SubTestDriverBase.__init__(self, 'add-shared-folders', oTstDrv); self.asTestsDef = [ 'fsperf', ]; self.asTests = self.asTestsDef; def parseOption(self, asArgs, iArg): if asArgs[iArg] == '--add-shared-folders-tests': # 'add' as in 'additions', not the verb. iArg += 1; iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg); if asArgs[iArg] == 'all': self.asTests = self.asTestsDef; else: self.asTests = asArgs[iArg].split(':'); for s in self.asTests: if s not in self.asTestsDef: raise base.InvalidOption('The "--add-shared-folders-tests" value "%s" is not valid; valid values are: %s' % (s, ' '.join(self.asTestsDef))); return iNext; return iArg; def showUsage(self): base.SubTestDriverBase.showUsage(self); reporter.log(' --add-shared-folders-tests '); reporter.log(' Default: all (%s)' % (':'.join(self.asTestsDef))); return True; def testIt(self, oTestVm, oSession, oTxsSession): """ Executes the test. Returns fRc, oTxsSession. The latter may have changed. """ reporter.log("Active tests: %s" % (self.asTests,)); # # Skip the test if before 6.0 # if self.oTstDrv.fpApiVer < 6.0: return None; # # Create the host directory to share. Empty except for a 'candle.dir' subdir # that we use to check that it mounted correctly. # sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1'); if os.path.exists(sSharedFolder1): try: shutil.rmtree(sSharedFolder1); except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession); try: os.mkdir(sSharedFolder1); except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession); try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir')); except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession); # Guess a free mount point inside the guest. if oTestVm.isWindows() or oTestVm.isOS2(): sMountPoint1 = 'V:'; sGuestSlash = '\\'; else: sMountPoint1 = '/mnt/shfl1'; sGuestSlash = '/'; # # Automount a shared folder in the guest. # reporter.testStart('Automount'); try: oConsole = oSession.o.console; oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1); except: reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1)); reporter.testDone(); return (False, oTxsSession); # Check whether we can see the shared folder now. Retry for 30 seconds. msStart = base.timestampMilli(); while True: fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir'); if fRc is not False: break; if base.timestampMilli() - msStart > 30000: reporter.error('Shared folder mounting timed out!'); break; oTstDrv.sleep(1); reporter.testDone(); if fRc is not None: return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder. # # Run FsPerf inside the guest. # reporter.testStart('FsPerf'); fSkip = 'fsperf' not in self.asTests; if fSkip is False: cMbFree = utils.getDiskUsage(sSharedFolders1); if cMbFree < 16: reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sSharedFolder1,)); fSkip = True; if fSkip is False: asArgs = ['FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', ]; if oTestVm.sGuestOsType in []: asArgs.append('--no-mmap'); # Fails on older than win7 (CcCoherencyFlushAndPurgeCache). fRc = oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 10 * 60 * 1000, '${CDROM}/${OS/ARCH}/FsPerf${EXESUFF}', asArgs); sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1'); if os.path.exists(sTestDir): fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,)); try: shutil.rmtree(sTestDir); except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,)); reporter.testDone(fSkip or fRc is None); return (fRc, oTxsSession); if __name__ == '__main__': reporter.error('Cannot run standalone, use tdAddBasic1.py'); sys.exit(1);