VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/additions/tdAddSharedFolders1.py@ 78642

Last change on this file since 78642 was 78642, checked in by vboxsync, 6 years ago

ValKit/additions: Started writing shared folder testcase. bugref:9172

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5VirtualBox Validation Kit - Shared Folders
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2010-2019 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.virtualbox.org. This file is free software;
14you can redistribute it and/or modify it under the terms of the GNU
15General Public License (GPL) as published by the Free Software
16Foundation, in version 2 as it comes in the "COPYING" file of the
17VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
20The contents of this file may alternatively be used under the terms
21of the Common Development and Distribution License Version 1.0
22(CDDL) only, as it comes in the "COPYING.CDDL" file of the
23VirtualBox OSE distribution, in which case the provisions of the
24CDDL are applicable instead of those of the GPL.
25
26You may elect to license modified versions of this file under the
27terms and conditions of either the GPL or the CDDL or both.
28"""
29__version__ = "$Revision: 78642 $"
30
31# Standard Python imports.
32import os
33import shutil
34import sys
35
36# Only the main script needs to modify the path.
37try: __file__
38except: __file__ = sys.argv[0];
39g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
40sys.path.append(g_ksValidationKitDir);
41
42# Validation Kit imports.
43from testdriver import reporter;
44from testdriver import base;
45from testdriver import vbox;
46from testdriver import vboxcon;
47from testdriver import vboxwrappers;
48from common import utils;
49
50# Python 3 hacks:
51if sys.version_info[0] >= 3:
52 long = int # pylint: disable=W0622,C0103
53
54
55class SubTstDrvAddSharedFolders1(base.SubTestDriverBase):
56 """
57 Sub-test driver for executing shared folders tests.
58 """
59
60 def __init__(self, oTstDrv):
61 base.SubTestDriverBase.__init__(self, 'add-shared-folders', oTstDrv);
62
63 self.asTestsDef = [ 'fsperf', ];
64 self.asTests = self.asTestsDef;
65
66 def parseOption(self, asArgs, iArg):
67 if asArgs[iArg] == '--add-shared-folders-tests': # 'add' as in 'additions', not the verb.
68 iArg += 1;
69 iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
70 if asArgs[iArg] == 'all':
71 self.asTests = self.asTestsDef;
72 else:
73 self.asTests = asArgs[iArg].split(':');
74 for s in self.asTests:
75 if s not in self.asTestsDef:
76 raise base.InvalidOption('The "--add-shared-folders-tests" value "%s" is not valid; valid values are: %s'
77 % (s, ' '.join(self.asTestsDef)));
78 return iNext;
79 return iArg;
80
81 def showUsage(self):
82 base.SubTestDriverBase.showUsage(self);
83 reporter.log(' --add-shared-folders-tests <t1[:t2[:]]>');
84 reporter.log(' Default: all (%s)' % (':'.join(self.asTestsDef)));
85 return True;
86
87 def testIt(self, oTestVm, oSession, oTxsSession):
88 """
89 Executes the test.
90
91 Returns fRc, oTxsSession. The latter may have changed.
92 """
93 reporter.log("Active tests: %s" % (self.asTests,));
94
95 #
96 # Skip the test if before 6.0
97 #
98 if self.oTstDrv.fpApiVer < 6.0:
99 return None;
100
101 #
102 # Create the host directory to share. Empty except for a 'candle.dir' subdir
103 # that we use to check that it mounted correctly.
104 #
105 sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1');
106 if os.path.exists(sSharedFolder1):
107 try: shutil.rmtree(sSharedFolder1);
108 except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession);
109 try: os.mkdir(sSharedFolder1);
110 except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
111 try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir'));
112 except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
113
114 # Guess a free mount point inside the guest.
115 if oTestVm.isWindows() or oTestVm.isOS2():
116 sMountPoint1 = 'V:';
117 sGuestSlash = '\\';
118 else:
119 sMountPoint1 = '/mnt/shfl1';
120 sGuestSlash = '/';
121
122 #
123 # Automount a shared folder in the guest.
124 #
125 reporter.testStart('Automount');
126
127 try:
128 oConsole = oSession.o.console;
129 oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1);
130 except:
131 reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1));
132 reporter.testDone();
133 return (False, oTxsSession);
134
135 # Check whether we can see the shared folder now. Retry for 30 seconds.
136 msStart = base.timestampMilli();
137 while True:
138 fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir');
139 if fRc is not False:
140 break;
141 if base.timestampMilli() - msStart > 30000:
142 reporter.error('Shared folder mounting timed out!');
143 break;
144 oTstDrv.sleep(1);
145
146 reporter.testDone();
147 if fRc is not None:
148 return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
149
150 #
151 # Run FsPerf inside the guest.
152 #
153 reporter.testStart('FsPerf');
154 fSkip = 'fsperf' not in self.asTests;
155 if fSkip is False:
156 cMbFree = utils.getDiskUsage(sSharedFolders1);
157 if cMbFree < 16:
158 reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sSharedFolder1,));
159 fSkip = True;
160 if fSkip is False:
161 asArgs = ['FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', ];
162 if oTestVm.sGuestOsType in []:
163 asArgs.append('--no-mmap'); # Fails on older than win7 (CcCoherencyFlushAndPurgeCache).
164 fRc = oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 10 * 60 * 1000, '${CDROM}/${OS/ARCH}/FsPerf${EXESUFF}', asArgs);
165
166 sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1');
167 if os.path.exists(sTestDir):
168 fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
169 try: shutil.rmtree(sTestDir);
170 except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,));
171
172 reporter.testDone(fSkip or fRc is None);
173
174
175 return (fRc, oTxsSession);
176
177
178
179if __name__ == '__main__':
180 reporter.error('Cannot run standalone, use tdAddBasic1.py');
181 sys.exit(1);
182
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette