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: 84446 $"
|
---|
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 | self.sGuestSlash = '';
|
---|
67 |
|
---|
68 | def parseOption(self, asArgs, iArg):
|
---|
69 | if asArgs[iArg] == '--add-shared-folders-tests': # 'add' as in 'additions', not the verb.
|
---|
70 | iArg += 1;
|
---|
71 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
72 | if asArgs[iArg] == 'all':
|
---|
73 | self.asTests = self.asTestsDef;
|
---|
74 | else:
|
---|
75 | self.asTests = asArgs[iArg].split(':');
|
---|
76 | for s in self.asTests:
|
---|
77 | if s not in self.asTestsDef:
|
---|
78 | raise base.InvalidOption('The "--add-shared-folders-tests" value "%s" is not valid; valid values are: %s'
|
---|
79 | % (s, ' '.join(self.asTestsDef)));
|
---|
80 | return iNext;
|
---|
81 | if asArgs[iArg] == '--add-shared-folders-extra-arg':
|
---|
82 | iArg += 1;
|
---|
83 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
84 | self.asExtraArgs.append(asArgs[iArg]);
|
---|
85 | return iNext;
|
---|
86 | return iArg;
|
---|
87 |
|
---|
88 | def showUsage(self):
|
---|
89 | base.SubTestDriverBase.showUsage(self);
|
---|
90 | reporter.log(' --add-shared-folders-tests <t1[:t2[:]]>');
|
---|
91 | reporter.log(' Default: all (%s)' % (':'.join(self.asTestsDef)));
|
---|
92 | reporter.log(' --add-shared-folders-extra-arg <fsperf-arg>');
|
---|
93 | reporter.log(' Adds an extra FsPerf argument. Can be repeated.');
|
---|
94 |
|
---|
95 | return True;
|
---|
96 |
|
---|
97 | def mountShareEx(self, oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint, fMustSucceed):
|
---|
98 | """
|
---|
99 | Automount a shared folder in the guest, extended version.
|
---|
100 |
|
---|
101 | Returns success status, based on fMustSucceed.
|
---|
102 | """
|
---|
103 | reporter.testStart('Automounting "%s"' % (sShareName,));
|
---|
104 |
|
---|
105 | reporter.log2('Creating shared folder "%s" at "%s" ...' % (sShareName, sGuestMountPoint));
|
---|
106 | try:
|
---|
107 | oConsole = oSession.o.console;
|
---|
108 | oConsole.createSharedFolder(sShareName, sHostPath, True, True, sGuestMountPoint);
|
---|
109 | except:
|
---|
110 | if fMustSucceed:
|
---|
111 | reporter.errorXcpt('createSharedFolder(%s,%s,True,True,%s)' % (sShareName, sHostPath, sGuestMountPoint));
|
---|
112 | else:
|
---|
113 | reporter.log('createSharedFolder(%s,%s,True,True,%s) failed, good' % (sShareName, sHostPath, sGuestMountPoint));
|
---|
114 | reporter.testDone();
|
---|
115 | return False is fMustSucceed;
|
---|
116 |
|
---|
117 | # Check whether we can see the shared folder now. Retry for 30 seconds.
|
---|
118 | msStart = base.timestampMilli();
|
---|
119 | while True:
|
---|
120 | fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir');
|
---|
121 | reporter.log2('candle.dir check -> %s' % (fRc,));
|
---|
122 | if fRc is fMustSucceed:
|
---|
123 | break;
|
---|
124 | if base.timestampMilli() - msStart > 30000:
|
---|
125 | reporter.error('Shared folder mounting timed out!');
|
---|
126 | break;
|
---|
127 | self.oTstDrv.sleep(1);
|
---|
128 |
|
---|
129 | reporter.testDone();
|
---|
130 |
|
---|
131 | return fRc == fMustSucceed;
|
---|
132 |
|
---|
133 | def mountShare(self, oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint):
|
---|
134 | """
|
---|
135 | Automount a shared folder in the guest.
|
---|
136 |
|
---|
137 | Returns success status.
|
---|
138 | """
|
---|
139 | return self.mountShareEx(oSession, oTxsSession, sShareName, sHostPath, sGuestMountPoint, fMustSucceed = True);
|
---|
140 |
|
---|
141 | def unmountShareEx(self, oSession, oTxsSession, sShareName, sGuestMountPoint, fMustSucceed):
|
---|
142 | """
|
---|
143 | Unmounts a shared folder in the guest.
|
---|
144 |
|
---|
145 | Returns success status, based on fMustSucceed.
|
---|
146 | """
|
---|
147 | reporter.log2('Autounmount');
|
---|
148 | try:
|
---|
149 | oConsole = oSession.o.console;
|
---|
150 | oConsole.removeSharedFolder(sShareName);
|
---|
151 | except:
|
---|
152 | if fMustSucceed:
|
---|
153 | reporter.errorXcpt('removeSharedFolder(%s)' % (sShareName,));
|
---|
154 | else:
|
---|
155 | reporter.log('removeSharedFolder(%s)' % (sShareName,));
|
---|
156 | reporter.testDone();
|
---|
157 | return False is fMustSucceed;
|
---|
158 |
|
---|
159 | # Check whether the shared folder is gone on the guest now. Retry for 30 seconds.
|
---|
160 | msStart = base.timestampMilli();
|
---|
161 | while True:
|
---|
162 | fRc = oTxsSession.syncIsDir(sGuestMountPoint + self.sGuestSlash + 'candle.dir');
|
---|
163 | reporter.log2('candle.dir check -> %s' % (fRc,));
|
---|
164 | if fRc is not fMustSucceed:
|
---|
165 | break;
|
---|
166 | if base.timestampMilli() - msStart > 30000:
|
---|
167 | reporter.error('Shared folder unmounting timed out!');
|
---|
168 | fRc = False;
|
---|
169 | break;
|
---|
170 | self.oTstDrv.sleep(1);
|
---|
171 |
|
---|
172 | reporter.testDone();
|
---|
173 |
|
---|
174 | return fRc is not fMustSucceed;
|
---|
175 |
|
---|
176 | def unmountShare(self, oSession, oTxsSession, sShareName, sGuestMountPoint):
|
---|
177 | """
|
---|
178 | Unmounts a shared folder in the guest, extended version.
|
---|
179 |
|
---|
180 | Returns success status, based on fMustSucceed.
|
---|
181 | """
|
---|
182 | return self.unmountShareEx(oSession, oTxsSession, sShareName, sGuestMountPoint, fMustSucceed = True);
|
---|
183 |
|
---|
184 | def testIt(self, oTestVm, oSession, oTxsSession):
|
---|
185 | """
|
---|
186 | Executes the test.
|
---|
187 |
|
---|
188 | Returns fRc, oTxsSession. The latter may have changed.
|
---|
189 | """
|
---|
190 | reporter.log("Active tests: %s" % (self.asTests,));
|
---|
191 |
|
---|
192 | #
|
---|
193 | # Skip the test if before 6.0
|
---|
194 | #
|
---|
195 | if self.oTstDrv.fpApiVer < 6.0:
|
---|
196 | reporter.log('Requires 6.0 or later (for now)');
|
---|
197 | return (None, oTxsSession);
|
---|
198 |
|
---|
199 | # Guess a free mount point inside the guest.
|
---|
200 | if oTestVm.isWindows() or oTestVm.isOS2():
|
---|
201 | self.sGuestSlash = '\\';
|
---|
202 | else:
|
---|
203 | self.sGuestSlash = '/';
|
---|
204 |
|
---|
205 | #
|
---|
206 | # Create the host directory to share. Empty except for a 'candle.dir' subdir
|
---|
207 | # that we use to check that it mounted correctly.
|
---|
208 | #
|
---|
209 | sShareName1 = 'shfl1';
|
---|
210 | sShareHostPath1 = os.path.join(self.oTstDrv.sScratchPath, sShareName1);
|
---|
211 | reporter.log2('Creating shared host folder "%s"...' % (sShareHostPath1,));
|
---|
212 | if os.path.exists(sShareHostPath1):
|
---|
213 | try: shutil.rmtree(sShareHostPath1);
|
---|
214 | except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sShareHostPath1,)), oTxsSession);
|
---|
215 | try: os.mkdir(sShareHostPath1);
|
---|
216 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sShareHostPath1,)), oTxsSession);
|
---|
217 | try: os.mkdir(os.path.join(sShareHostPath1, 'candle.dir'));
|
---|
218 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sShareHostPath1,)), oTxsSession);
|
---|
219 |
|
---|
220 | # Guess a free mount point inside the guest.
|
---|
221 | if oTestVm.isWindows() or oTestVm.isOS2():
|
---|
222 | sMountPoint1 = 'V:';
|
---|
223 | else:
|
---|
224 | sMountPoint1 = '/mnt/' + sShareName1;
|
---|
225 |
|
---|
226 | fRc = self.mountShare(oSession, oTxsSession, sShareName1, sShareHostPath1, sMountPoint1);
|
---|
227 | if fRc is not True:
|
---|
228 | return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
|
---|
229 |
|
---|
230 | #
|
---|
231 | # Run FsPerf inside the guest.
|
---|
232 | #
|
---|
233 | fSkip = 'fsperf' not in self.asTests;
|
---|
234 | if fSkip is False:
|
---|
235 | cMbFree = utils.getDiskUsage(sShareHostPath1);
|
---|
236 | if cMbFree >= 16:
|
---|
237 | reporter.log2('Free space: %u MBs' % (cMbFree,));
|
---|
238 | else:
|
---|
239 | reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sShareHostPath1,));
|
---|
240 | fSkip = True;
|
---|
241 | if fSkip is False:
|
---|
242 | # Common arguments:
|
---|
243 | asArgs = ['FsPerf', '-d', sMountPoint1 + self.sGuestSlash + 'fstestdir-1', '-s8'];
|
---|
244 |
|
---|
245 | # Skip part of mmap on older windows systems without CcCoherencyFlushAndPurgeCache (>= w7).
|
---|
246 | reporter.log2('oTestVm.sGuestOsType=%s' % (oTestVm.sGuestOsType,));
|
---|
247 | if oTestVm.getNonCanonicalGuestOsType() \
|
---|
248 | in [ 'WindowsNT3x', 'WindowsNT4', 'Windows2000', 'WindowsXP', 'WindowsXP_64', 'Windows2003',
|
---|
249 | 'Windows2003_64', 'WindowsVista', 'WindowsVista_64', 'Windows2008', 'Windows2008_64']:
|
---|
250 | asArgs.append('--no-mmap-coherency');
|
---|
251 |
|
---|
252 | # Configure I/O block sizes according to guest memory size:
|
---|
253 | cbMbRam = 128;
|
---|
254 | try: cbMbRam = oSession.o.machine.memorySize;
|
---|
255 | except: reporter.errorXcpt();
|
---|
256 | reporter.log2('cbMbRam=%s' % (cbMbRam,));
|
---|
257 | asArgs.append('--set-block-size=1');
|
---|
258 | asArgs.append('--add-block-size=512');
|
---|
259 | asArgs.append('--add-block-size=4096');
|
---|
260 | asArgs.append('--add-block-size=16384');
|
---|
261 | asArgs.append('--add-block-size=65536');
|
---|
262 | asArgs.append('--add-block-size=1048576'); # 1 MiB
|
---|
263 | if cbMbRam >= 512:
|
---|
264 | asArgs.append('--add-block-size=33554432'); # 32 MiB
|
---|
265 | if cbMbRam >= 768:
|
---|
266 | asArgs.append('--add-block-size=134217728'); # 128 MiB
|
---|
267 |
|
---|
268 | # Putting lots (10000) of files in a single directory causes issues on OS X
|
---|
269 | # (HFS+ presumably, though could be slow disks) and some linuxes (slow disks,
|
---|
270 | # maybe ext2/3?). So, generally reduce the file count to 4096 everywhere
|
---|
271 | # since we're not here to test the host file systems, and 3072 on macs.
|
---|
272 | if utils.getHostOs() in [ 'darwin', ]:
|
---|
273 | asArgs.append('--many-files=3072');
|
---|
274 | elif utils.getHostOs() in [ 'linux', ]:
|
---|
275 | asArgs.append('--many-files=4096');
|
---|
276 |
|
---|
277 | # Add the extra arguments from the command line and kick it off:
|
---|
278 | asArgs.extend(self.asExtraArgs);
|
---|
279 |
|
---|
280 | # Run FsPerf:
|
---|
281 | reporter.log2('Starting guest FsPerf (%s)...' % (asArgs,));
|
---|
282 | sFsPerfPath = self._locateGstFsPerf(oTxsSession);
|
---|
283 |
|
---|
284 | ## @todo For some odd reason the combined GA/VaKit .ISO (by IPRT/fs/isomakercmd)
|
---|
285 | # sometimes (?) contains FsPerf as non-executable (-r--r--r-- 1 root root) on Linux.
|
---|
286 | #
|
---|
287 | # So work around this for now by copying the desired FsPerf binary to the temp directory,
|
---|
288 | # make it executable and execute it from there.
|
---|
289 | fISOMakerCmdIsBuggy = oTestVm.isLinux();
|
---|
290 | if fISOMakerCmdIsBuggy:
|
---|
291 | sFsPerfImage = "FsPerf${EXESUFF}";
|
---|
292 | if oTestVm.isWindows() \
|
---|
293 | or oTestVm.isOS2():
|
---|
294 | sFsPerfPathTemp = "C:\\Temp\\" + sFsPerfImage;
|
---|
295 | sCopy = "cmd.exe";
|
---|
296 | sCopyArgs = ( sCopy, "/C", "copy", "/Y", sFsPerfPath, sFsPerfPathTemp );
|
---|
297 | else:
|
---|
298 | sFsPerfPathTemp = "/var/tmp/" + sFsPerfImage;
|
---|
299 | sCopy = "cp";
|
---|
300 | sCopyArgs = ( sCopy, "-a", "-v", sFsPerfPath, sFsPerfPathTemp );
|
---|
301 | fRc = self.oTstDrv.txsRunTest(oTxsSession, 'Copying FsPerf', 60 * 1000,
|
---|
302 | sCopy, sCopyArgs, fCheckSessionStatus = True);
|
---|
303 | fRc = fRc and oTxsSession.syncChMod(sFsPerfPathTemp, 0o755);
|
---|
304 | if fRc:
|
---|
305 | sFsPerfPath = sFsPerfPathTemp;
|
---|
306 |
|
---|
307 | fRc = self.oTstDrv.txsRunTest(oTxsSession, 'Running FsPerf', 90 * 60 * 1000, sFsPerfPath, asArgs,
|
---|
308 | fCheckSessionStatus = True);
|
---|
309 | reporter.log2('FsPerf -> %s' % (fRc,));
|
---|
310 | if fRc:
|
---|
311 | # Do a bit of diagnosis to find out why this failed.
|
---|
312 | if not oTestVm.isWindows() \
|
---|
313 | and not oTestVm.isOS2():
|
---|
314 | oTxsSession.syncExec("/bin/ls", ("/bin/ls", "-al", sFsPerfPath), fIgnoreErrors = True);
|
---|
315 | oTxsSession.syncExec("/bin/ls", ("/bin/ls", "-al", "-R", "/opt"), fIgnoreErrors = True);
|
---|
316 | oTxsSession.syncExec("/bin/ls", ("/bin/ls", "-al", "-R", "/media/cdrom"), fIgnoreErrors = True);
|
---|
317 |
|
---|
318 | sTestDir = os.path.join(sShareHostPath1, 'fstestdir-1');
|
---|
319 | if os.path.exists(sTestDir):
|
---|
320 | fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
|
---|
321 | try: shutil.rmtree(sTestDir);
|
---|
322 | except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,));
|
---|
323 | else:
|
---|
324 | reporter.testStart('FsPerf');
|
---|
325 | reporter.testDone(fSkip or fRc is None);
|
---|
326 |
|
---|
327 | #
|
---|
328 | # Check if auto-unmounting works.
|
---|
329 | #
|
---|
330 | if fRc is True:
|
---|
331 | fRc = self.unmountShare(oSession, oTxsSession, sShareName1, sMountPoint1);
|
---|
332 |
|
---|
333 | ## @todo Add tests for multiple automount shares, random unmounting, reboot test.
|
---|
334 |
|
---|
335 | return (fRc, oTxsSession);
|
---|
336 |
|
---|
337 | def _locateGstFsPerf(self, oTxsSession):
|
---|
338 | """
|
---|
339 | Returns guest side path to FsPerf.
|
---|
340 | """
|
---|
341 | for sFsPerfPath in self.asGstFsPerfPaths:
|
---|
342 | if oTxsSession.syncIsFile(sFsPerfPath):
|
---|
343 | reporter.log('Using FsPerf at "%s"' % (sFsPerfPath,));
|
---|
344 | return sFsPerfPath;
|
---|
345 | reporter.log('Unable to find guest FsPerf in any of these places: %s' % ('\n '.join(self.asGstFsPerfPaths),));
|
---|
346 | return self.asGstFsPerfPaths[0];
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 | if __name__ == '__main__':
|
---|
351 | reporter.error('Cannot run standalone, use tdAddBasic1.py');
|
---|
352 | sys.exit(1);
|
---|