1 | #!/usr/bin/env python
|
---|
2 | # -*- coding: utf-8 -*-
|
---|
3 |
|
---|
4 | """
|
---|
5 | VirtualBox Validation Kit - Shared Folders #1.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2010-2020 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 82968 $"
|
---|
30 |
|
---|
31 | # Standard Python imports.
|
---|
32 | import os
|
---|
33 | import shutil
|
---|
34 | import sys
|
---|
35 |
|
---|
36 | # Only the main script needs to modify the path.
|
---|
37 | try: __file__
|
---|
38 | except: __file__ = sys.argv[0];
|
---|
39 | g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
---|
40 | sys.path.append(g_ksValidationKitDir);
|
---|
41 |
|
---|
42 | # Validation Kit imports.
|
---|
43 | from testdriver import reporter;
|
---|
44 | from testdriver import base;
|
---|
45 | from common import utils;
|
---|
46 |
|
---|
47 |
|
---|
48 | class SubTstDrvAddSharedFolders1(base.SubTestDriverBase):
|
---|
49 | """
|
---|
50 | Sub-test driver for executing shared folders tests.
|
---|
51 | """
|
---|
52 |
|
---|
53 | def __init__(self, oTstDrv):
|
---|
54 | base.SubTestDriverBase.__init__(self, oTstDrv, 'add-shared-folders', 'Shared Folders');
|
---|
55 |
|
---|
56 | self.asTestsDef = [ 'fsperf', ];
|
---|
57 | self.asTests = self.asTestsDef;
|
---|
58 | self.asExtraArgs = [];
|
---|
59 | self.asGstFsPerfPaths = [
|
---|
60 | '${CDROM}/vboxvalidationkit/${OS/ARCH}/FsPerf${EXESUFF}',
|
---|
61 | '${CDROM}/${OS/ARCH}/FsPerf${EXESUFF}',
|
---|
62 | '${TXSDIR}/${OS/ARCH}/FsPerf${EXESUFF}',
|
---|
63 | '${TXSDIR}/FsPerf${EXESUFF}',
|
---|
64 | 'E:/vboxvalidationkit/${OS/ARCH}/FsPerf${EXESUFF}',
|
---|
65 | ];
|
---|
66 |
|
---|
67 | def parseOption(self, asArgs, iArg):
|
---|
68 | if asArgs[iArg] == '--add-shared-folders-tests': # 'add' as in 'additions', not the verb.
|
---|
69 | iArg += 1;
|
---|
70 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
71 | if asArgs[iArg] == 'all':
|
---|
72 | self.asTests = self.asTestsDef;
|
---|
73 | else:
|
---|
74 | self.asTests = asArgs[iArg].split(':');
|
---|
75 | for s in self.asTests:
|
---|
76 | if s not in self.asTestsDef:
|
---|
77 | raise base.InvalidOption('The "--add-shared-folders-tests" value "%s" is not valid; valid values are: %s'
|
---|
78 | % (s, ' '.join(self.asTestsDef)));
|
---|
79 | return iNext;
|
---|
80 | if asArgs[iArg] == '--add-shared-folders-extra-arg':
|
---|
81 | iArg += 1;
|
---|
82 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
83 | self.asExtraArgs.append(asArgs[iArg]);
|
---|
84 | return iNext;
|
---|
85 | return iArg;
|
---|
86 |
|
---|
87 | def showUsage(self):
|
---|
88 | base.SubTestDriverBase.showUsage(self);
|
---|
89 | reporter.log(' --add-shared-folders-tests <t1[:t2[:]]>');
|
---|
90 | reporter.log(' Default: all (%s)' % (':'.join(self.asTestsDef)));
|
---|
91 | reporter.log(' --add-shared-folders-extra-arg <fsperf-arg>');
|
---|
92 | reporter.log(' Adds an extra FsPerf argument. Can be repeated.');
|
---|
93 |
|
---|
94 | return True;
|
---|
95 |
|
---|
96 | def testIt(self, oTestVm, oSession, oTxsSession):
|
---|
97 | """
|
---|
98 | Executes the test.
|
---|
99 |
|
---|
100 | Returns fRc, oTxsSession. The latter may have changed.
|
---|
101 | """
|
---|
102 | reporter.log("Active tests: %s" % (self.asTests,));
|
---|
103 |
|
---|
104 | #
|
---|
105 | # Skip the test if before 6.0
|
---|
106 | #
|
---|
107 | if self.oTstDrv.fpApiVer < 6.0:
|
---|
108 | reporter.log('Requires 6.0 or later (for now)');
|
---|
109 | return (None, oTxsSession);
|
---|
110 |
|
---|
111 | #
|
---|
112 | # Create the host directory to share. Empty except for a 'candle.dir' subdir
|
---|
113 | # that we use to check that it mounted correctly.
|
---|
114 | #
|
---|
115 | sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1');
|
---|
116 | reporter.log2('Creating shared host folder "%s"...' % (sSharedFolder1,));
|
---|
117 | if os.path.exists(sSharedFolder1):
|
---|
118 | try: shutil.rmtree(sSharedFolder1);
|
---|
119 | except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
120 | try: os.mkdir(sSharedFolder1);
|
---|
121 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
122 | try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir'));
|
---|
123 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
124 |
|
---|
125 | # Guess a free mount point inside the guest.
|
---|
126 | if oTestVm.isWindows() or oTestVm.isOS2():
|
---|
127 | sMountPoint1 = 'V:';
|
---|
128 | sGuestSlash = '\\';
|
---|
129 | else:
|
---|
130 | sMountPoint1 = '/mnt/shfl1';
|
---|
131 | sGuestSlash = '/';
|
---|
132 |
|
---|
133 | #
|
---|
134 | # Automount a shared folder in the guest.
|
---|
135 | #
|
---|
136 | reporter.testStart('Automount');
|
---|
137 |
|
---|
138 | reporter.log2('Creating shared folder shfl1...');
|
---|
139 | try:
|
---|
140 | oConsole = oSession.o.console;
|
---|
141 | oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1);
|
---|
142 | except:
|
---|
143 | reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1));
|
---|
144 | reporter.testDone();
|
---|
145 | return (False, oTxsSession);
|
---|
146 |
|
---|
147 | # Check whether we can see the shared folder now. Retry for 30 seconds.
|
---|
148 | msStart = base.timestampMilli();
|
---|
149 | while True:
|
---|
150 | fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir');
|
---|
151 | reporter.log2('candle.dir check -> %s' % (fRc,));
|
---|
152 | if fRc is not False:
|
---|
153 | break;
|
---|
154 | if base.timestampMilli() - msStart > 30000:
|
---|
155 | reporter.error('Shared folder mounting timed out!');
|
---|
156 | break;
|
---|
157 | self.oTstDrv.sleep(1);
|
---|
158 |
|
---|
159 | reporter.testDone();
|
---|
160 | if fRc is not True:
|
---|
161 | return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
|
---|
162 |
|
---|
163 | #
|
---|
164 | # Run FsPerf inside the guest.
|
---|
165 | #
|
---|
166 | fSkip = 'fsperf' not in self.asTests;
|
---|
167 | if fSkip is False:
|
---|
168 | cMbFree = utils.getDiskUsage(sSharedFolder1);
|
---|
169 | if cMbFree >= 16:
|
---|
170 | reporter.log2('Free space: %u MBs' % (cMbFree,));
|
---|
171 | else:
|
---|
172 | reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sSharedFolder1,));
|
---|
173 | fSkip = True;
|
---|
174 | if fSkip is False:
|
---|
175 | # Common arguments:
|
---|
176 | asArgs = ['FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', '-s8'];
|
---|
177 |
|
---|
178 | # Skip part of mmap on older windows systems without CcCoherencyFlushAndPurgeCache (>= w7).
|
---|
179 | reporter.log2('oTestVm.sGuestOsType=%s' % (oTestVm.sGuestOsType,));
|
---|
180 | if oTestVm.getNonCanonicalGuestOsType() \
|
---|
181 | in [ 'WindowsNT3x', 'WindowsNT4', 'Windows2000', 'WindowsXP', 'WindowsXP_64', 'Windows2003',
|
---|
182 | 'Windows2003_64', 'WindowsVista', 'WindowsVista_64', 'Windows2008', 'Windows2008_64']:
|
---|
183 | asArgs.append('--no-mmap-coherency');
|
---|
184 |
|
---|
185 | # Configure I/O block sizes according to guest memory size:
|
---|
186 | cbMbRam = 128;
|
---|
187 | try: cbMbRam = oSession.o.machine.memorySize;
|
---|
188 | except: reporter.errorXcpt();
|
---|
189 | reporter.log2('cbMbRam=%s' % (cbMbRam,));
|
---|
190 | asArgs.append('--set-block-size=1');
|
---|
191 | asArgs.append('--add-block-size=512');
|
---|
192 | asArgs.append('--add-block-size=4096');
|
---|
193 | asArgs.append('--add-block-size=16384');
|
---|
194 | asArgs.append('--add-block-size=65536');
|
---|
195 | asArgs.append('--add-block-size=1048576'); # 1 MiB
|
---|
196 | if cbMbRam >= 512:
|
---|
197 | asArgs.append('--add-block-size=33554432'); # 32 MiB
|
---|
198 | if cbMbRam >= 768:
|
---|
199 | asArgs.append('--add-block-size=134217728'); # 128 MiB
|
---|
200 |
|
---|
201 | # Putting lots (10000) of files in a single directory causes issues on OS X
|
---|
202 | # (HFS+ presumably, though could be slow disks) and some linuxes (slow disks,
|
---|
203 | # maybe ext2/3?). So, generally reduce the file count to 4096 everywhere
|
---|
204 | # since we're not here to test the host file systems, and 3072 on macs.
|
---|
205 | if utils.getHostOs() in [ 'darwin', ]:
|
---|
206 | asArgs.append('--many-files=3072');
|
---|
207 | elif utils.getHostOs() in [ 'linux', ]:
|
---|
208 | asArgs.append('--many-files=4096');
|
---|
209 |
|
---|
210 | # Add the extra arguments from the command line and kick it off:
|
---|
211 | asArgs.extend(self.asExtraArgs);
|
---|
212 |
|
---|
213 | # Run FsPerf:
|
---|
214 | reporter.log2('Starting guest FsPerf (%s)...' % (asArgs,));
|
---|
215 | sFsPerfPath = self._locateGstFsPerf(oTxsSession);
|
---|
216 | fRc = self.oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 30 * 60 * 1000, sFsPerfPath, asArgs);
|
---|
217 | reporter.log2('FsPerf -> %s' % (fRc,));
|
---|
218 |
|
---|
219 | sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1');
|
---|
220 | if os.path.exists(sTestDir):
|
---|
221 | fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
|
---|
222 | try: shutil.rmtree(sTestDir);
|
---|
223 | except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,));
|
---|
224 | else:
|
---|
225 | reporter.testStart('FsPerf');
|
---|
226 | reporter.testDone(fSkip or fRc is None);
|
---|
227 |
|
---|
228 | return (fRc, oTxsSession);
|
---|
229 |
|
---|
230 |
|
---|
231 | def _locateGstFsPerf(self, oTxsSession):
|
---|
232 | """
|
---|
233 | Returns guest side path to FsPerf.
|
---|
234 | """
|
---|
235 | for sFsPerfPath in self.asGstFsPerfPaths:
|
---|
236 | if oTxsSession.syncIsFile(sFsPerfPath):
|
---|
237 | return sFsPerfPath;
|
---|
238 | reporter.log('Unable to find guest FsPerf in any of these places: %s' % ('\n '.join(self.asGstFsPerfPaths),));
|
---|
239 | return self.asGstFsPerfPaths[0];
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 | if __name__ == '__main__':
|
---|
244 | reporter.error('Cannot run standalone, use tdAddBasic1.py');
|
---|
245 | sys.exit(1);
|
---|
246 |
|
---|