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: 78675 $"
|
---|
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 | return None;
|
---|
102 |
|
---|
103 | #
|
---|
104 | # Create the host directory to share. Empty except for a 'candle.dir' subdir
|
---|
105 | # that we use to check that it mounted correctly.
|
---|
106 | #
|
---|
107 | sSharedFolder1 = os.path.join(self.oTstDrv.sScratchPath, 'shfl1');
|
---|
108 | reporter.log2('Creating shared host folder "%s"...' % (sSharedFolder1,));
|
---|
109 | if os.path.exists(sSharedFolder1):
|
---|
110 | try: shutil.rmtree(sSharedFolder1);
|
---|
111 | except: return (reporter.errorXcpt('shutil.rmtree(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
112 | try: os.mkdir(sSharedFolder1);
|
---|
113 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
114 | try: os.mkdir(os.path.join(sSharedFolder1, 'candle.dir'));
|
---|
115 | except: return (reporter.errorXcpt('os.mkdir(%s)' % (sSharedFolder1,)), oTxsSession);
|
---|
116 |
|
---|
117 | # Guess a free mount point inside the guest.
|
---|
118 | if oTestVm.isWindows() or oTestVm.isOS2():
|
---|
119 | sMountPoint1 = 'V:';
|
---|
120 | sGuestSlash = '\\';
|
---|
121 | else:
|
---|
122 | sMountPoint1 = '/mnt/shfl1';
|
---|
123 | sGuestSlash = '/';
|
---|
124 |
|
---|
125 | #
|
---|
126 | # Automount a shared folder in the guest.
|
---|
127 | #
|
---|
128 | reporter.testStart('Automount');
|
---|
129 |
|
---|
130 | reporter.log2('Creating shared folder shfl1...');
|
---|
131 | try:
|
---|
132 | oConsole = oSession.o.console;
|
---|
133 | oConsole.createSharedFolder('shfl1', sSharedFolder1, True, True, sMountPoint1);
|
---|
134 | except:
|
---|
135 | reporter.errorXcpt('createSharedFolder(shfl1,%s,True,True,%s)' % (sSharedFolder1,sMountPoint1));
|
---|
136 | reporter.testDone();
|
---|
137 | return (False, oTxsSession);
|
---|
138 |
|
---|
139 | # Check whether we can see the shared folder now. Retry for 30 seconds.
|
---|
140 | msStart = base.timestampMilli();
|
---|
141 | while True:
|
---|
142 | fRc = oTxsSession.syncIsDir(sMountPoint1 + sGuestSlash + 'candle.dir');
|
---|
143 | reporter.log2('candle.dir check -> %s' % (fRc,));
|
---|
144 | if fRc is not False:
|
---|
145 | break;
|
---|
146 | if base.timestampMilli() - msStart > 30000:
|
---|
147 | reporter.error('Shared folder mounting timed out!');
|
---|
148 | break;
|
---|
149 | self.oTstDrv.sleep(1);
|
---|
150 |
|
---|
151 | reporter.testDone();
|
---|
152 | if fRc is not True:
|
---|
153 | return (False, oTxsSession); # skip the remainder if we cannot auto mount the folder.
|
---|
154 |
|
---|
155 | #
|
---|
156 | # Run FsPerf inside the guest.
|
---|
157 | #
|
---|
158 | reporter.testStart('FsPerf');
|
---|
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 | asArgs.extend(self.asExtraArgs);
|
---|
195 | reporter.log2('Starting guest FsPerf (%s)...' % (asArgs,));
|
---|
196 | fRc = self.oTstDrv.txsRunTest(oTxsSession, 'FsPerf', 10 * 60 * 1000,
|
---|
197 | '${CDROM}/vboxvalidationkit/${OS/ARCH}/FsPerf${EXESUFF}', asArgs);
|
---|
198 | reporter.log2('FsPerf -> %s' % (fRc,));
|
---|
199 |
|
---|
200 | sTestDir = os.path.join(sSharedFolder1, 'fstestdir-1');
|
---|
201 | if os.path.exists(sTestDir):
|
---|
202 | fRc = reporter.errorXcpt('test directory lingers: %s' % (sTestDir,));
|
---|
203 | try: shutil.rmtree(sTestDir);
|
---|
204 | except: fRc = reporter.errorXcpt('shutil.rmtree(%s)' % (sTestDir,));
|
---|
205 |
|
---|
206 | reporter.testDone(fSkip or fRc is None);
|
---|
207 |
|
---|
208 |
|
---|
209 | return (fRc, oTxsSession);
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 | if __name__ == '__main__':
|
---|
214 | reporter.error('Cannot run standalone, use tdAddBasic1.py');
|
---|
215 | sys.exit(1);
|
---|
216 |
|
---|