VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/additions/tdAddSharedFolders1.py@ 79214

Last change on this file since 79214 was 79092, checked in by vboxsync, 6 years ago

ValKit,++: Pylint 2.3.1 adjustments.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette