VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/additions/tdAddBasic1.py@ 78734

Last change on this file since 78734 was 78675, checked in by vboxsync, 6 years ago

tdAddBasic1.py,tdAddSharedFolders1.py: Enabled shared folder testing after more adjustments. bugref:9172

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.6 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAddBasic1.py 78675 2019-05-23 00:09:12Z vboxsync $
4
5"""
6VirtualBox Validation Kit - Additions Basics #1.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2019 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 78675 $"
31
32# Standard Python imports.
33import os;
34import sys;
35import uuid;
36
37# Only the main script needs to modify the path.
38try: __file__
39except: __file__ = sys.argv[0];
40g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
41sys.path.append(g_ksValidationKitDir);
42
43# Validation Kit imports.
44from testdriver import reporter;
45from testdriver import base;
46from testdriver import vbox;
47from testdriver import vboxcon;
48
49# Sub test driver imports.
50sys.path.append(os.path.dirname(os.path.abspath(__file__))); # For sub-test drivers.
51from tdAddGuestCtrl import SubTstDrvAddGuestCtrl;
52from tdAddSharedFolders1 import SubTstDrvAddSharedFolders1;
53
54
55class tdAddBasic1(vbox.TestDriver): # pylint: disable=R0902
56 """
57 Additions Basics #1.
58 """
59 ## @todo
60 # - More of the settings stuff can be and need to be generalized!
61 #
62
63 def __init__(self):
64 vbox.TestDriver.__init__(self);
65 self.oTestVmSet = self.oTestVmManager.getSmokeVmSet('nat');
66 self.asTestsDef = ['install', 'guestprops', 'stdguestprops', 'guestcontrol', 'sharedfolders'];
67 self.asTests = self.asTestsDef;
68 self.asRsrcs = None
69
70 self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
71 self.addSubTestDriver(SubTstDrvAddSharedFolders1(self));
72
73 #
74 # Overridden methods.
75 #
76 def showUsage(self):
77 rc = vbox.TestDriver.showUsage(self);
78 reporter.log('');
79 reporter.log('tdAddBasic1 Options:');
80 reporter.log(' --tests <s1[:s2[:]]>');
81 reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
82 reporter.log(' --quick');
83 reporter.log(' Same as --virt-modes hwvirt --cpu-counts 1.');
84 return rc;
85
86 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
87 if asArgs[iArg] == '--tests':
88 iArg += 1;
89 if iArg >= len(asArgs): raise base.InvalidOption('The "--tests" takes a colon separated list of tests');
90 self.asTests = asArgs[iArg].split(':');
91 for s in self.asTests:
92 if s not in self.asTestsDef:
93 raise base.InvalidOption('The "--tests" value "%s" is not valid; valid values are: %s'
94 % (s, ' '.join(self.asTestsDef),));
95
96 elif asArgs[iArg] == '--quick':
97 self.parseOption(['--virt-modes', 'hwvirt'], 0);
98 self.parseOption(['--cpu-counts', '1'], 0);
99
100 else:
101 return vbox.TestDriver.parseOption(self, asArgs, iArg);
102 return iArg + 1;
103
104 def getResourceSet(self):
105 if self.asRsrcs is None:
106 self.asRsrcs = []
107 for oSubTstDrv in self.aoSubTstDrvs:
108 self.asRsrcs.extend(oSubTstDrv.asRsrcs)
109 self.asRsrcs.extend(self.oTestVmSet.getResourceSet())
110 return self.asRsrcs
111
112 def actionConfig(self):
113 if not self.importVBoxApi(): # So we can use the constant below.
114 return False;
115
116 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT;
117 sGaIso = self.getGuestAdditionsIso();
118
119 # On 6.0 we merge the GAs with the ValidationKit so we can get at FsPerf.
120 # Note! Not possible to do a dboule import as both images an '/OS2' dir.
121 # So, using same dir as with unattended VISOs for the valkit.
122 if self.fpApiVer >= 6.0 and 'sharedfolders' in self.asTests:
123 sGaViso = os.path.join(self.sScratchPath, 'AdditionsAndValKit.viso');
124 ## @todo encode as bash cmd line:
125 sVisoContent = '--iprt-iso-maker-file-marker-bourne-sh %s ' \
126 '--import-iso \'%s\' ' \
127 '--push-iso \'%s\' ' \
128 '/vboxvalidationkit=/ ' \
129 '--pop ' \
130 % (uuid.uuid4(), sGaIso, self.sVBoxValidationKitIso);
131 reporter.log2('Using VISO combining GAs and ValKit "%s": %s' % (sGaViso, sVisoContent));
132 oGaViso = open(sGaViso, 'w');
133 oGaViso.write(sVisoContent);
134 oGaViso.close();
135 sGaIso = sGaViso;
136
137 return self.oTestVmSet.actionConfig(self, eNic0AttachType = eNic0AttachType, sDvdImage = sGaIso);
138
139 def actionExecute(self):
140 return self.oTestVmSet.actionExecute(self, self.testOneCfg);
141
142
143 #
144 # Test execution helpers.
145 #
146
147 def testOneCfg(self, oVM, oTestVm):
148 """
149 Runs the specified VM thru the tests.
150
151 Returns a success indicator on the general test execution. This is not
152 the actual test result.
153 """
154 fRc = False;
155
156 if oTestVm.isWindows():
157 sFileCdWait = 'VBoxWindowsAdditions.exe';
158 elif oTestVm.isLinux():
159 sFileCdWait = 'VBoxLinuxAdditions.run';
160
161 self.logVmInfo(oVM);
162 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = True, sFileCdWait = sFileCdWait);
163 if oSession is not None:
164 self.addTask(oTxsSession);
165 # Do the testing.
166 fSkip = 'install' not in self.asTests;
167 reporter.testStart('Install');
168 if not fSkip:
169 fRc, oTxsSession = self.testInstallAdditions(oSession, oTxsSession, oTestVm);
170 reporter.testDone(fSkip);
171
172 fSkip = 'guestprops' not in self.asTests;
173 reporter.testStart('Guest Properties');
174 if not fSkip:
175 fRc = self.testGuestProperties(oSession, oTxsSession, oTestVm) and fRc;
176 reporter.testDone(fSkip);
177
178 fSkip = 'guestcontrol' not in self.asTests;
179 reporter.testStart('Guest Control');
180 if not fSkip:
181 fRc, oTxsSession = self.aoSubTstDrvs[0].testIt(oTestVm, oSession, oTxsSession);
182 reporter.testDone(fSkip);
183
184 fSkip = 'sharedfolders' not in self.asTests and self.fpApiVer >= 6.0;
185 reporter.testStart('Shared Folders');
186 if not fSkip:
187 fRc, oTxsSession = self.aoSubTstDrvs[1].testIt(oTestVm, oSession, oTxsSession);
188 reporter.testDone(fSkip or fRc is None);
189
190 ## @todo Save and restore test.
191
192 ## @todo Reset tests.
193
194 ## @todo Final test: Uninstallation.
195
196 # Cleanup.
197 self.removeTask(oTxsSession);
198 self.terminateVmBySession(oSession)
199 return fRc;
200
201 def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
202 """
203 Tests installing the guest additions
204 """
205 if oTestVm.isWindows():
206 (fRc, oTxsSession) = self.testWindowsInstallAdditions(oSession, oTxsSession, oTestVm);
207 elif oTestVm.isLinux():
208 (fRc, oTxsSession) = self.testLinuxInstallAdditions(oSession, oTxsSession, oTestVm);
209 else:
210 reporter.error('Guest Additions installation not implemented for %s yet! (%s)' % \
211 (oTestVm.sKind, oTestVm.sVmName,));
212 fRc = False;
213
214 #
215 # Verify installation of Guest Additions using commmon bits.
216 #
217 if fRc is True:
218 #
219 # Wait for the GAs to come up.
220 #
221
222 ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
223 # at least reach Userland.
224
225 #
226 # Check if the additions are operational.
227 #
228 try: oGuest = oSession.o.console.guest;
229 except:
230 reporter.errorXcpt('Getting IGuest failed.');
231 return (False, oTxsSession);
232
233 # Check the additionsVersion attribute. It must not be empty.
234 reporter.testStart('IGuest::additionsVersion');
235 fRc = self.testIGuest_additionsVersion(oGuest);
236 reporter.testDone();
237
238 reporter.testStart('IGuest::additionsRunLevel');
239 self.testIGuest_additionsRunLevel(oGuest, oTestVm);
240 reporter.testDone();
241
242 ## @todo test IAdditionsFacilities.
243
244 return (fRc, oTxsSession);
245
246 def testWindowsInstallAdditions(self, oSession, oTxsSession, oTestVm):
247 """
248 Installs the Windows guest additions using the test execution service.
249 Since this involves rebooting the guest, we will have to create a new TXS session.
250 """
251 asLogFiles = [];
252
253 fHaveSetupApiDevLog = False;
254
255 # Delete relevant log files.
256 if oTestVm.sKind in ('WindowsNT4',):
257 sWinDir = 'C:/WinNT/';
258 else:
259 sWinDir = 'C:/Windows/';
260 asLogFiles = [sWinDir + 'setupapi.log', sWinDir + 'setupact.log', sWinDir + 'setuperr.log'];
261
262 # Apply The SetupAPI logging level so that we also get the (most verbose) setupapi.dev.log file.
263 ## @todo !!! HACK ALERT !!! Add the value directly into the testing source image. Later.
264 fHaveSetupApiDevLog = self.txsRunTest(oTxsSession, 'Enabling setupapi.dev.log', 30 * 1000,
265 'c:\\Windows\\System32\\reg.exe',
266 ('c:\\Windows\\System32\\reg.exe', 'add',
267 '"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup"',
268 '/v', 'LogLevel', '/t', 'REG_DWORD', '/d', '0xFF'));
269
270 # On some guests the files in question still can be locked by the OS, so ignore deletion
271 # errors from the guest side (e.g. sharing violations) and just continue.
272 for sFile in asLogFiles:
273 self.txsRmFile(oSession, oTxsSession, sFile, 10 * 1000, fIgnoreErrors = True);
274
275 # Install the public signing key.
276 if oTestVm.sKind not in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003'):
277 ## TODO
278 pass;
279
280 #
281 # The actual install.
282 # Enable installing the optional auto-logon modules (VBoxGINA/VBoxCredProv) + (Direct)3D support.
283 # Also tell the installer to produce the appropriate log files.
284 #
285 fRc = self.txsRunTest(oTxsSession, 'VBoxWindowsAdditions.exe', 5 * 60 * 1000, '${CDROM}/VBoxWindowsAdditions.exe',
286 ('${CDROM}/VBoxWindowsAdditions.exe', '/S', '/l', '/with_autologon'));
287 ## @todo For testing the installation (D)3D stuff ('/with_d3d') we need to boot up in safe mode.
288
289 #
290 # Reboot the VM and reconnect the TXS session.
291 #
292 if fRc is True:
293 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000);
294
295 if fRc is True:
296 # Add the Windows Guest Additions installer files to the files we want to download
297 # from the guest.
298 sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
299 asLogFiles.append(sGuestAddsDir + 'install.log');
300 # Note: There won't be a install_ui.log because of the silent installation.
301 asLogFiles.append(sGuestAddsDir + 'install_drivers.log');
302 asLogFiles.append('C:/Windows/setupapi.log');
303
304 # Note: setupapi.dev.log only is available since Windows 2000.
305 if fHaveSetupApiDevLog:
306 asLogFiles.append('C:/Windows/setupapi.dev.log');
307
308 #
309 # Download log files.
310 # Ignore errors as all files above might not be present (or in different locations)
311 # on different Windows guests.
312 #
313 self.txsDownloadFiles(oSession, oTxsSession, asLogFiles, fIgnoreErrors = True);
314
315 return (fRc, oTxsSession);
316
317 def testLinuxInstallAdditions(self, oSession, oTxsSession, oTestVm):
318 oSession = oSession;
319 oTestVm = oTestVm;
320
321 fRc = False;
322
323 # Install Kernel headers, which are required for actually installing the Linux Additions.
324 if oTestVm.sKind.startswith('Debian') \
325 or oTestVm.sKind.startswith('Ubuntu'):
326 fRc = self.txsRunTest(oTxsSession, 'Installing Kernel headers', 5 * 60 *1000,
327 '/usr/bin/apt-get', ('/usr/bin/apt-get', 'install', '-y', 'linux-headers-generic'));
328 if not fRc:
329 reporter.error('Error installing Kernel headers');
330 fRc = self.txsRunTest(oTxsSession, 'Installing Guest Additions depdendencies', 5 * 60 *1000, \
331 '/usr/bin/apt-get', ('/usr/bin/apt-get', 'install', '-y', 'build-essential', 'perl'));
332 if not fRc:
333 reporter.error('Error installing additional installer dependencies');
334 elif oTestVm.sKind.startswith('OL') \
335 or oTestVm.sKind.startswith('Oracle') \
336 or oTestVm.sKind.startswith('RHEL') \
337 or oTestVm.sKind.startswith('Redhat') \
338 or oTestVm.sKind.startswith('Cent'):
339 fRc = self.txsRunTest(oTxsSession, 'Installing Kernel headers', 5 * 60 *1000,
340 '/usr/bin/yum', ('/usr/bin/yum', '-y', 'install', 'kernel-headers'));
341 if not fRc:
342 reporter.error('Error installing Kernel headers');
343 fRc = self.txsRunTest(oTxsSession, 'Installing Guest Additions depdendencies', 5 * 60 *1000, \
344 '/usr/bin/yum', ('/usr/bin/yum', '-y', 'install', \
345 'make', 'automake', 'gcc', 'kernel-devel', 'dkms', 'bzip2', 'perl'));
346 if not fRc:
347 reporter.error('Error installing additional installer dependencies');
348 else:
349 reporter.error('Installing Linux Additions for kind "%s" is not supported yet' % oTestVm.sKind);
350 return (False, oTxsSession);
351
352 if fRc:
353 #
354 # The actual install.
355 # Also tell the installer to produce the appropriate log files.
356 #
357 fRc = self.txsRunTest(oTxsSession, 'VBoxLinuxAdditions.run', 5 * 60 * 1000,
358 '/bin/sh', ('/bin/sh', '${CDROM}/VBoxLinuxAdditions.run'));
359 if not fRc:
360 reporter.error('Installing Linux Additions failed (see log file for details)');
361
362 #
363 # Download log files.
364 # Ignore errors as all files above might not be present for whatever reason.
365 #
366 asLogFile = [];
367 asLogFile.append('/var/log/vboxadd-install.log');
368 self.txsDownloadFiles(oSession, oTxsSession, asLogFile, fIgnoreErrors = True);
369
370 if fRc:
371 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000);
372
373 return (fRc, oTxsSession);
374
375 def testIGuest_additionsVersion(self, oGuest):
376 """
377 Returns False if no version string could be obtained, otherwise True
378 even though errors are logged.
379 """
380 try:
381 sVer = oGuest.additionsVersion;
382 except:
383 reporter.errorXcpt('Getting the additions version failed.');
384 return False;
385 reporter.log('IGuest::additionsVersion="%s"' % (sVer,));
386
387 if sVer.strip() == '':
388 reporter.error('IGuest::additionsVersion is empty.');
389 return False;
390
391 if sVer != sVer.strip():
392 reporter.error('IGuest::additionsVersion is contains spaces: "%s".' % (sVer,));
393
394 asBits = sVer.split('.');
395 if len(asBits) < 3:
396 reporter.error('IGuest::additionsVersion does not contain at least tree dot separated fields: "%s" (%d).'
397 % (sVer, len(asBits)));
398
399 ## @todo verify the format.
400 return True;
401
402 def testIGuest_additionsRunLevel(self, oGuest, oTestVm):
403 """
404 Do run level tests.
405 """
406 if oTestVm.isLoggedOntoDesktop():
407 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Desktop;
408 else:
409 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Userland;
410
411 ## @todo Insert wait for the desired run level.
412 try:
413 iLevel = oGuest.additionsRunLevel;
414 except:
415 reporter.errorXcpt('Getting the additions run level failed.');
416 return False;
417 reporter.log('IGuest::additionsRunLevel=%s' % (iLevel,));
418
419 if iLevel != eExpectedRunLevel:
420 pass; ## @todo We really need that wait!!
421 #reporter.error('Expected runlevel %d, found %d instead' % (eExpectedRunLevel, iLevel));
422 return True;
423
424
425 def testGuestProperties(self, oSession, oTxsSession, oTestVm):
426 """
427 Test guest properties.
428 """
429 _ = oSession; _ = oTxsSession; _ = oTestVm;
430 return True;
431
432if __name__ == '__main__':
433 sys.exit(tdAddBasic1().main(sys.argv));
Note: See TracBrowser for help on using the repository browser.

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