VirtualBox

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

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

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdAddBasic1.py 76553 2019-01-01 01:45:53Z 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: 76553 $"
31
32
33# Standard Python imports.
34import os;
35import sys;
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;
52
53
54class tdAddBasic1(vbox.TestDriver): # pylint: disable=R0902
55 """
56 Additions Basics #1.
57 """
58 ## @todo
59 # - More of the settings stuff can be and need to be generalized!
60 #
61
62 def __init__(self):
63 vbox.TestDriver.__init__(self);
64 self.oTestVmSet = self.oTestVmManager.getSmokeVmSet('nat');
65 self.asTestsDef = ['guestprops', 'stdguestprops', 'guestcontrol'];
66 self.asTests = self.asTestsDef;
67 self.asRsrcs = None
68
69 self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
70
71 #
72 # Overridden methods.
73 #
74 def showUsage(self):
75 rc = vbox.TestDriver.showUsage(self);
76 reporter.log('');
77 reporter.log('tdAddBasic1 Options:');
78 reporter.log(' --tests <s1[:s2[:]]>');
79 reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
80 reporter.log(' --quick');
81 reporter.log(' Same as --virt-modes hwvirt --cpu-counts 1.');
82 return rc;
83
84 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
85 if asArgs[iArg] == '--tests':
86 iArg += 1;
87 if iArg >= len(asArgs): raise base.InvalidOption('The "--tests" takes a colon separated list of tests');
88 self.asTests = asArgs[iArg].split(':');
89 for s in self.asTests:
90 if s not in self.asTestsDef:
91 raise base.InvalidOption('The "--tests" value "%s" is not valid; valid values are: %s' \
92 % (s, ' '.join(self.asTestsDef)));
93
94 elif asArgs[iArg] == '--quick':
95 self.parseOption(['--virt-modes', 'hwvirt'], 0);
96 self.parseOption(['--cpu-counts', '1'], 0);
97
98 else:
99 return vbox.TestDriver.parseOption(self, asArgs, iArg);
100 return iArg + 1;
101
102 def getResourceSet(self):
103 if self.asRsrcs is None:
104 self.asRsrcs = []
105 for oSubTstDrv in self.aoSubTstDrvs:
106 self.asRsrcs.extend(oSubTstDrv.asRsrcs)
107 self.asRsrcs.extend(self.oTestVmSet.getResourceSet())
108 return self.asRsrcs
109
110 def actionConfig(self):
111 if not self.importVBoxApi(): # So we can use the constant below.
112 return False;
113
114 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT;
115 sGaIso = self.getGuestAdditionsIso();
116 return self.oTestVmSet.actionConfig(self, eNic0AttachType = eNic0AttachType, sDvdImage = sGaIso);
117
118 def actionExecute(self):
119 return self.oTestVmSet.actionExecute(self, self.testOneCfg);
120
121
122 #
123 # Test execution helpers.
124 #
125
126 def testOneCfg(self, oVM, oTestVm):
127 """
128 Runs the specified VM thru the tests.
129
130 Returns a success indicator on the general test execution. This is not
131 the actual test result.
132 """
133 fRc = False;
134
135 self.logVmInfo(oVM);
136 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = True, \
137 sFileCdWait = 'AUTORUN.INF');
138 if oSession is not None:
139 self.addTask(oTxsSession);
140 # Do the testing.
141 reporter.testStart('Install');
142 fRc, oTxsSession = self.testInstallAdditions(oSession, oTxsSession, oTestVm);
143 reporter.testDone();
144 fSkip = not fRc;
145
146 reporter.testStart('Guest Properties');
147 if not fSkip:
148 fRc = self.testGuestProperties(oSession, oTxsSession, oTestVm) and fRc;
149 reporter.testDone(fSkip);
150
151 reporter.testStart('Guest Control');
152 if not fSkip:
153 (fRc2, oTxsSession) = self.aoSubTstDrvs[0].testIt(oTestVm, oSession, oTxsSession);
154 fRc = fRc2 and fRc;
155 reporter.testDone(fSkip);
156
157 ## @todo Save and restore test.
158
159 ## @todo Reset tests.
160
161 ## @todo Final test: Uninstallation.
162
163 # Cleanup.
164 self.removeTask(oTxsSession);
165 self.terminateVmBySession(oSession)
166 return fRc;
167
168 def testInstallAdditions(self, oSession, oTxsSession, oTestVm):
169 """
170 Tests installing the guest additions
171 """
172 if oTestVm.isWindows():
173 (fRc, oTxsSession) = self.testWindowsInstallAdditions(oSession, oTxsSession, oTestVm);
174 else:
175 reporter.error('Guest Additions installation not implemented for %s yet! (%s)' % \
176 (oTestVm.sKind, oTestVm.sVmName));
177 fRc = False;
178
179 #
180 # Verify installation of Guest Additions using commmon bits.
181 #
182 if fRc is True:
183 #
184 # Wait for the GAs to come up.
185 #
186
187 ## @todo need to signed up for a OnAdditionsStateChanged and wait runlevel to
188 # at least reach Userland.
189
190 #
191 # Check if the additions are operational.
192 #
193 try: oGuest = oSession.o.console.guest;
194 except:
195 reporter.errorXcpt('Getting IGuest failed.');
196 return (False, oTxsSession);
197
198 # Check the additionsVersion attribute. It must not be empty.
199 reporter.testStart('IGuest::additionsVersion');
200 fRc = self.testIGuest_additionsVersion(oGuest);
201 reporter.testDone();
202
203 reporter.testStart('IGuest::additionsRunLevel');
204 self.testIGuest_additionsRunLevel(oGuest, oTestVm);
205 reporter.testDone();
206
207 ## @todo test IAdditionsFacilities.
208
209 return (fRc, oTxsSession);
210
211 def testWindowsInstallAdditions(self, oSession, oTxsSession, oTestVm):
212 """
213 Installs the Windows guest additions using the test execution service.
214 Since this involves rebooting the guest, we will have to create a new TXS session.
215 """
216 asLogFile = [];
217
218 fHaveSetupApiDevLog = False;
219
220 # Delete relevant log files.
221 if oTestVm.sKind in ('WindowsNT4',):
222 sWinDir = 'C:/WinNT/';
223 else:
224 sWinDir = 'C:/Windows/';
225 asLogFile = [sWinDir+'setupapi.log', sWinDir+'setupact.log', sWinDir+'setuperr.log'];
226
227 # Apply The SetupAPI logging level so that we also get the (most verbose) setupapi.dev.log file.
228 ## @todo !!! HACK ALERT !!! Add the value directly into the testing source image. Later.
229 fHaveSetupApiDevLog = self.txsRunTest(oTxsSession, 'Enabling setupapi.dev.log', 30 * 1000, \
230 'c:\\Windows\\System32\\reg.exe', ('c:\\Windows\\System32\\reg.exe', \
231 'add', '"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Setup"', '/v', 'LogLevel', '/t', 'REG_DWORD', \
232 '/d', '0xFF'));
233
234 # On some guests the files in question still can be locked by the OS, so ignore deletion
235 # errors from the guest side (e.g. sharing violations) and just continue.
236 for sFile in asLogFile:
237 self.txsRmFile(oSession, oTxsSession, sFile, 10 * 1000, fIgnoreErrors = True);
238
239 # Install the public signing key.
240 if oTestVm.sKind not in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003'):
241 ## TODO
242 pass;
243
244 #
245 # The actual install.
246 # Enable installing the optional auto-logon modules (VBoxGINA/VBoxCredProv) + (Direct)3D support.
247 # Also tell the installer to produce the appropriate log files.
248 #
249 fRc = self.txsRunTest(oTxsSession, 'VBoxWindowsAdditions.exe', 5 * 60 * 1000, \
250 '${CDROM}/VBoxWindowsAdditions.exe', ('${CDROM}/VBoxWindowsAdditions.exe', '/S', '/l', '/with_autologon'));
251 ## @todo For testing the installation (D)3D stuff ('/with_d3d') we need to boot up in safe mode.
252
253 #
254 # Reboot the VM and reconnect the TXS session.
255 #
256 if fRc is True:
257 (fRc, oTxsSession) = self.txsRebootAndReconnectViaTcp(oSession, oTxsSession, cMsTimeout = 3 * 60000);
258
259 if fRc is True:
260 # Add the Windows Guest Additions installer files to the files we want to download
261 # from the guest.
262 sGuestAddsDir = 'C:/Program Files/Oracle/VirtualBox Guest Additions/';
263 asLogFile.append(sGuestAddsDir + 'install.log');
264 # Note: There won't be a install_ui.log because of the silent installation.
265 asLogFile.append(sGuestAddsDir + 'install_drivers.log');
266 asLogFile.append('C:/Windows/setupapi.log');
267
268 # Note: setupapi.dev.log only is available since Windows 2000.
269 if fHaveSetupApiDevLog:
270 asLogFile.append('C:/Windows/setupapi.dev.log');
271
272 #
273 # Download log files.
274 # Ignore errors as all files above might not be present (or in different locations)
275 # on different Windows guests.
276 #
277 self.txsDownloadFiles(oSession, oTxsSession, asLogFile, fIgnoreErrors = True);
278
279 return (fRc, oTxsSession);
280
281 def testIGuest_additionsVersion(self, oGuest):
282 """
283 Returns False if no version string could be obtained, otherwise True
284 even though errors are logged.
285 """
286 try:
287 sVer = oGuest.additionsVersion;
288 except:
289 reporter.errorXcpt('Getting the additions version failed.');
290 return False;
291 reporter.log('IGuest::additionsVersion="%s"' % (sVer,));
292
293 if sVer.strip() == '':
294 reporter.error('IGuest::additionsVersion is empty.');
295 return False;
296
297 if sVer != sVer.strip():
298 reporter.error('IGuest::additionsVersion is contains spaces: "%s".' % (sVer,));
299
300 asBits = sVer.split('.');
301 if len(asBits) < 3:
302 reporter.error('IGuest::additionsVersion does not contain at least tree dot separated fields: "%s" (%d).'
303 % (sVer, len(asBits)));
304
305 ## @todo verify the format.
306 return True;
307
308 def testIGuest_additionsRunLevel(self, oGuest, oTestVm):
309 """
310 Do run level tests.
311 """
312 if oTestVm.isLoggedOntoDesktop():
313 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Desktop;
314 else:
315 eExpectedRunLevel = vboxcon.AdditionsRunLevelType_Userland;
316
317 ## @todo Insert wait for the desired run level.
318 try:
319 iLevel = oGuest.additionsRunLevel;
320 except:
321 reporter.errorXcpt('Getting the additions run level failed.');
322 return False;
323 reporter.log('IGuest::additionsRunLevel=%s' % (iLevel,));
324
325 if iLevel != eExpectedRunLevel:
326 pass; ## @todo We really need that wait!!
327 #reporter.error('Expected runlevel %d, found %d instead' % (eExpectedRunLevel, iLevel));
328 return True;
329
330
331 def testGuestProperties(self, oSession, oTxsSession, oTestVm):
332 """
333 Test guest properties.
334 """
335 _ = oSession; _ = oTxsSession; _ = oTestVm;
336 return True;
337
338if __name__ == '__main__':
339 sys.exit(tdAddBasic1().main(sys.argv));
340
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