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-2019 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: 78678 $"
|
---|
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, 'add-shared-folders', oTstDrv);
|
---|
55 |
|
---|
56 | self.asTestsDef = [ 'fsperf', ];
|
---|
57 | self.asTests = self.asTestsDef;
|
---|
58 | self.asExtraArgs = [];
|
---|
59 |
|
---|
60 | def parseOption(self, asArgs, iArg):
|
---|
61 | if asArgs[iArg] == '--add-shared-folders-tests': # 'add' as in 'additions', not the verb.
|
---|
62 | iArg += 1;
|
---|
63 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
64 | if asArgs[iArg] == 'all':
|
---|
65 | self.asTests = self.asTestsDef;
|
---|
66 | else:
|
---|
67 | self.asTests = asArgs[iArg].split(':');
|
---|
68 | for s in self.asTests:
|
---|
69 | if s not in self.asTestsDef:
|
---|
70 | raise base.InvalidOption('The "--add-shared-folders-tests" value "%s" is not valid; valid values are: %s'
|
---|
71 | % (s, ' '.join(self.asTestsDef)));
|
---|
72 | return iNext;
|
---|
73 | elif asArgs[iArg] == '--add-shared-folders-extra-arg':
|
---|
74 | iArg += 1;
|
---|
75 | iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
|
---|
76 | self.asExtraArgs.append(asArgs[iArg]);
|
---|
77 | return iNext;
|
---|
78 | return iArg;
|
---|
79 |
|
---|
80 | def showUsage(self):
|
---|
81 | base.SubTestDriverBase.showUsage(self);
|
---|
82 | reporter.log(' --add-shared-folders-tests <t1[:t2[:]]>');
|
---|
83 | reporter.log(' Default: all (%s)' % (':'.join(self.asTestsDef)));
|
---|
84 | reporter.log(' --add-shared-folders-extra-args <fsperf-arg>');
|
---|
85 | reporter.log(' Adds an extra FsPerf argument. Can be repeated.');
|
---|
86 |
|
---|
87 | return True;
|
---|
88 |
|
---|
89 | def testIt(self, oTestVm, oSession, oTxsSession):
|
---|
90 | """
|
---|
91 | Executes the test.
|
---|
92 |
|
---|
93 | Returns fRc, oTxsSession. The latter may have changed.
|
---|
94 | """
|
---|
95 | reporter.log("Active tests: %s" % (self.asTests,));
|
---|
96 |
|
---|
97 | #
|
---|
98 | # Skip the test if before 6.0
|
---|
99 | #
|
---|
100 | if self.oTstDrv.fpApiVer < 6.0:
|
---|
101 | reporter.log('Requires 6.0 or later (for now)');
|
---|
102 | return (None, oTxsSession);
|
---|
103 |
|
---|
104 | #
|
---|
105 | # Create the host directory to share. Empty except for a 'candle.dir' subdir
|
---|
106 | # that we use to check that it mounted correctly.
|
---|
107 | #
|
---|
108 | sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1');
|
---|
109 | reporter.log2('Creating shared host folder "%s"...' % (sSharedFolder1,));
|
---|
110 | if os.path.exists(sSharedFolder1):
|
---|
111 | try: shutil.rmtree(sSharedFolder1);
|
---|
112 | except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
113 | try: os.mkdir(sSharedFolder1);
|
---|
114 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
115 | try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir'));
|
---|
116 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
117 |
|
---|
118 | # Guess a free mount point inside the guest.
|
---|
119 | if oTestVm.isWindows() or oTestVm.isOS2():
|
---|
120 | sMountPoint1 = 'V:';
|
---|
121 | sGuestSlash = '\\';
|
---|
122 | else:
|
---|
123 | sMountPoint1 = '/mnt/shfl1';
|
---|
124 | sGuestSlash = '/';
|
---|
125 |
|
---|
126 | #
|
---|
127 | # Automount a shared folder in the guest.
|
---|
128 | #
|
---|
129 | reporter.testStart('Automount');
|
---|
130 |
|
---|
131 | reporter.log2('Creating shared folder shfl1...');
|
---|
132 | try:
|
---|
133 | oConsole = oSession.o.console;
|
---|
134 | oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1);
|
---|
135 | except:
|
---|
136 | reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1));
|
---|
137 | reporter.testDone();
|
---|
138 | return (False, oTxsSession);
|
---|
139 |
|
---|
140 | # Check whether we can see the shared folder now. Retry for 30 seconds.
|
---|
141 | msStart = base.timestampMilli();
|
---|
142 | while True:
|
---|
143 | fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir');
|
---|
144 | reporter.log2('candle.dir check -> %s' % (fRc,));
|
---|
145 | if fRc is not False:
|
---|
146 | break;
|
---|
147 | if base.timestampMilli() - msStart > 30000:
|
---|
148 | reporter.error('Shared folder mounting timed out!');
|
---|
149 | break;
|
---|
150 | self.oTstDrv.sleep(1);
|
---|
151 |
|
---|
152 | reporter.testDone();
|
---|
153 | if fRc is not True:
|
---|
154 | return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
|
---|
155 |
|
---|
156 | #
|
---|
157 | # Run FsPerf inside the guest.
|
---|
158 | #
|
---|
159 | fSkip = 'fsperf' not in self.asTests;
|
---|
160 | if fSkip is False:
|
---|
161 | cMbFree = utils.getDiskUsage(sSharedFolder1);
|
---|
162 | if cMbFree >= 16:
|
---|
163 | reporter.log2('Free space: %u MBs' % (cMbFree,));
|
---|
164 | else:
|
---|
165 | reporter.log('Skipping FsPerf because only %u MB free on %s' % (cMbFree, sSharedFolder1,));
|
---|
166 | fSkip = True;
|
---|
167 | if fSkip is False:
|
---|
168 | # Common arguments:
|
---|
169 | asArgs = ['FsPerf', '-d', sMountPoint1 + sGuestSlash + 'fstestdir-1', '-s8'];
|
---|
170 |
|
---|
171 | # Skip part of mmap on older windows systems without CcCoherencyFlushAndPurgeCache (>= w7).
|
---|
172 | reporter.log2('oTestVm.sGuestOsType=%s' % (oTestVm.sGuestOsType,));
|
---|
173 | if oTestVm.getNonCanonicalGuestOsType() \
|
---|
174 | in [ 'WindowsNT3x', 'WindowsNT4', 'Windows2000', 'WindowsXP', 'WindowsXP_64', 'Windows2003',
|
---|
175 | 'Windows2003_64', 'WindowsVista', 'WindowsVista_64', 'Windows2008', 'Windows2008_64']:
|
---|
176 | asArgs.append('--no-mmap-coherency');
|
---|
177 |
|
---|
178 | # Configure I/O block sizes according to guest memory size:
|
---|
179 | cbMbRam = 128;
|
---|
180 | try: cbMbRam = oSession.o.machine.memorySize;
|
---|
181 | except: reporter.errorXcpt();
|
---|
182 | reporter.log2('cbMbRam=%s' % (cbMbRam,));
|
---|
183 | asArgs.append('--set-block-size=1');
|
---|
184 | asArgs.append('--add-block-size=512');
|
---|
185 | asArgs.append('--add-block-size=4096');
|
---|
186 | asArgs.append('--add-block-size=16384');
|
---|
187 | asArgs.append('--add-block-size=65536');
|
---|
188 | asArgs.append('--add-block-size=1048576'); # 1 MiB
|
---|
189 | if cbMbRam >= 512:
|
---|
190 | asArgs.append('--add-block-size=33554432'); # 32 MiB
|
---|
191 | if cbMbRam >= 768:
|
---|
192 | asArgs.append('--add-block-size=134217728'); # 128 MiB
|
---|
193 |
|
---|
194 | # Putting lots (10000) of files in a single directory causes issues on OS X
|
---|
195 | # (HFS+ presumably, though could be slow disks) and some linuxes (slow disks,
|
---|
196 | # maybe ext2/3?). So, generally reduce the file count to 4096 everywhere
|
---|
197 | # since we're not here to test the host file systems, and 3072 on macs.
|
---|
198 | if utils.getHostOs() in [ 'darwin', ]:
|
---|
199 | asArgs.append('--many-files=3072');
|
---|
200 | elif utils.getHostOs() in [ 'linux', ]:
|
---|
201 | asArgs.append('--many-files=4096');
|
---|
202 |
|
---|
203 | # Add the extra arguments from the command line and kick it off:
|
---|
204 | asArgs.extend(self.asExtraArgs);
|
---|
205 | reporter.log2('Starting guest FsPerf (%s)...' % (asArgs,));
|
---|
206 | fRc = self.oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 30 * 60 * 1000,
|
---|
207 | '${CDROM}/vboxvalidationkit/${OS/ARCH}/FsPerf${EXESUFF}', asArgs);
|
---|
208 | reporter.log2('FsPerf -> %s' % (fRc,));
|
---|
209 |
|
---|
210 | sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1');
|
---|
211 | if os.path.exists(sTestDir):
|
---|
212 | fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
|
---|
213 | try: shutil.rmtree(sTestDir);
|
---|
214 | except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,));
|
---|
215 | else:
|
---|
216 | reporter.testStart('FsPerf');
|
---|
217 | reporter.testDone(fSkip or fRc is None);
|
---|
218 |
|
---|
219 | return (fRc, oTxsSession);
|
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 | if __name__ == '__main__':
|
---|
224 | reporter.error('Cannot run standalone, use tdAddBasic1.py');
|
---|
225 | sys.exit(1);
|
---|
226 |
|
---|