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