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