VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py@ 71928

Last change on this file since 71928 was 71854, checked in by vboxsync, 7 years ago

Pylint.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 182.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# pylint: disable=C0302
4
5"""
6VirtualBox Validation Kit - Guest Control Tests.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2018 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: 71854 $"
31
32# Disable bitching about too many arguments per function.
33# pylint: disable=R0913
34
35# Disable bitching about semicolons at the end of lines.
36# pylint: disable=W0301
37
38## @todo Convert map() usage to a cleaner alternative Python now offers.
39# pylint: disable=W0141
40
41## @todo Convert the context/test classes into named tuples. Not in the mood right now, so
42# disabling it.
43# pylint: disable=R0903
44
45# Standard Python imports.
46from array import array
47import errno
48import os
49import random
50import string # pylint: disable=W0402
51import struct
52import sys
53import time
54
55# Only the main script needs to modify the path.
56try: __file__
57except: __file__ = sys.argv[0];
58g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
59sys.path.append(g_ksValidationKitDir);
60
61# Validation Kit imports.
62from testdriver import reporter;
63from testdriver import base;
64from testdriver import vbox;
65from testdriver import vboxcon;
66from testdriver import vboxwrappers;
67
68# Python 3 hacks:
69if sys.version_info[0] >= 3:
70 long = int # pylint: disable=W0622,C0103
71
72
73class GuestStream(bytearray):
74 """
75 Class for handling a guest process input/output stream.
76 """
77 def appendStream(self, stream, convertTo='<b'):
78 """
79 Appends and converts a byte sequence to this object;
80 handy for displaying a guest stream.
81 """
82 self.extend(struct.pack(convertTo, stream));
83
84class tdCtxTest(object):
85 """
86 Provides the actual test environment. Should be kept
87 as generic as possible.
88 """
89 def __init__(self, oSession, oTxsSession, oTestVm): # pylint: disable=W0613
90 ## The desired Main API result.
91 self.fRc = False;
92 ## IGuest reference.
93 self.oGuest = oSession.o.console.guest;
94 # Rest not used (yet).
95
96class tdCtxCreds(object):
97 """
98 Provides credentials to pass to the guest.
99 """
100 def __init__(self, sUser = None, sPassword = None, sDomain = None, oTestVm = None):
101 # If no user is specified, select the default user and
102 # password for the given test VM.
103 if sUser is None:
104 assert sPassword is None;
105 assert sDomain is None;
106 assert oTestVm is not None;
107
108 ## @todo fix this so all VMs have several usable test users with the same passwords (or none).
109 sUser = 'test';
110 sPassword = 'password';
111 if oTestVm.isWindows():
112 #sPassword = ''; # stupid config mistake.
113 sPassword = 'password';
114 sUser = 'Administrator';
115 sDomain = '';
116
117 self.sUser = sUser;
118 self.sPassword = sPassword if sPassword is not None else '';
119 self.sDomain = sDomain if sDomain is not None else '';
120
121class tdTestGuestCtrlBase(object):
122 """
123 Base class for all guest control tests.
124 Note: This test ASSUMES that working Guest Additions
125 were installed and running on the guest to be tested.
126 """
127 def __init__(self):
128 self.oTest = None;
129 self.oCreds = None;
130 self.timeoutMS = 30 * 1000; # 30s timeout
131 ## IGuestSession reference or None.
132 self.oGuestSession = None;
133
134 def setEnvironment(self, oSession, oTxsSession, oTestVm):
135 """
136 Sets the test environment required for this test.
137 """
138 self.oTest = tdCtxTest(oSession, oTxsSession, oTestVm);
139 return self.oTest;
140
141 def createSession(self, sName):
142 """
143 Creates (opens) a guest session.
144 Returns (True, IGuestSession) on success or (False, None) on failure.
145 """
146 if self.oGuestSession is None:
147 if sName is None:
148 sName = "<untitled>";
149 try:
150 reporter.log('Creating session "%s" ...' % (sName,));
151 self.oGuestSession = self.oTest.oGuest.createSession(self.oCreds.sUser,
152 self.oCreds.sPassword,
153 self.oCreds.sDomain,
154 sName);
155 except:
156 # Just log, don't assume an error here (will be done in the main loop then).
157 reporter.logXcpt('Creating a guest session "%s" failed; sUser="%s", pw="%s", sDomain="%s":'
158 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain));
159 return (False, None);
160
161 try:
162 reporter.log('Waiting for session "%s" to start within %dms...' % (sName, self.timeoutMS));
163 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
164 waitResult = self.oGuestSession.waitForArray(fWaitFor, self.timeoutMS);
165 #
166 # Be nice to Guest Additions < 4.3: They don't support session handling and
167 # therefore return WaitFlagNotSupported.
168 #
169 if waitResult != vboxcon.GuestSessionWaitResult_Start \
170 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
171 # Just log, don't assume an error here (will be done in the main loop then).
172 reporter.log('Session did not start successfully, returned wait result: %d' \
173 % (waitResult,));
174 return (False, None);
175 reporter.log('Session "%s" successfully started' % (sName,));
176 except:
177 # Just log, don't assume an error here (will be done in the main loop then).
178 reporter.logXcpt('Waiting for guest session "%s" (usr=%s;pw=%s;dom=%s) to start failed:'
179 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain,));
180 return (False, None);
181 else:
182 reporter.log('Warning: Session already set; this is probably not what you want');
183 return (True, self.oGuestSession);
184
185 def setSession(self, oGuestSession):
186 """
187 Sets the current guest session and closes
188 an old one if necessary.
189 """
190 if self.oGuestSession is not None:
191 self.closeSession();
192 self.oGuestSession = oGuestSession;
193 return self.oGuestSession;
194
195 def closeSession(self):
196 """
197 Closes the guest session.
198 """
199 if self.oGuestSession is not None:
200 sName = self.oGuestSession.name;
201 try:
202 reporter.log('Closing session "%s" ...' % (sName,));
203 self.oGuestSession.close();
204 self.oGuestSession = None;
205 except:
206 # Just log, don't assume an error here (will be done in the main loop then).
207 reporter.logXcpt('Closing guest session "%s" failed:' % (sName,));
208 return False;
209 return True;
210
211class tdTestCopyFrom(tdTestGuestCtrlBase):
212 """
213 Test for copying files from the guest to the host.
214 """
215 def __init__(self, sSrc = "", sDst = "", sUser = "", sPassword = "", aFlags = None):
216 tdTestGuestCtrlBase.__init__(self);
217 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
218 self.sSrc = sSrc;
219 self.sDst = sDst;
220 self.aFlags = aFlags;
221
222class tdTestCopyTo(tdTestGuestCtrlBase):
223 """
224 Test for copying files from the host to the guest.
225 """
226 def __init__(self, sSrc = "", sDst = "", sUser = "", sPassword = "", aFlags = None):
227 tdTestGuestCtrlBase.__init__(self);
228 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
229 self.sSrc = sSrc;
230 self.sDst = sDst;
231 self.aFlags = aFlags;
232
233class tdTestDirCreate(tdTestGuestCtrlBase):
234 """
235 Test for directoryCreate call.
236 """
237 def __init__(self, sDirectory = "", sUser = "", sPassword = "", fMode = 0, aFlags = None):
238 tdTestGuestCtrlBase.__init__(self);
239 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
240 self.sDirectory = sDirectory;
241 self.fMode = fMode;
242 self.aFlags = aFlags;
243
244class tdTestDirCreateTemp(tdTestGuestCtrlBase):
245 """
246 Test for the directoryCreateTemp call.
247 """
248 def __init__(self, sDirectory = "", sTemplate = "", sUser = "", sPassword = "", fMode = 0, fSecure = False):
249 tdTestGuestCtrlBase.__init__(self);
250 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
251 self.sDirectory = sDirectory;
252 self.sTemplate = sTemplate;
253 self.fMode = fMode;
254 self.fSecure = fSecure;
255
256class tdTestDirOpen(tdTestGuestCtrlBase):
257 """
258 Test for the directoryOpen call.
259 """
260 def __init__(self, sDirectory = "", sUser = "", sPassword = "",
261 sFilter = "", aFlags = None):
262 tdTestGuestCtrlBase.__init__(self);
263 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
264 self.sDirectory = sDirectory;
265 self.sFilter = sFilter;
266 self.aFlags = aFlags or [];
267
268class tdTestDirRead(tdTestDirOpen):
269 """
270 Test for the opening, reading and closing a certain directory.
271 """
272 def __init__(self, sDirectory = "", sUser = "", sPassword = "",
273 sFilter = "", aFlags = None):
274 tdTestDirOpen.__init__(self, sDirectory, sUser, sPassword, sFilter, aFlags);
275
276class tdTestExec(tdTestGuestCtrlBase):
277 """
278 Specifies exactly one guest control execution test.
279 Has a default timeout of 5 minutes (for safety).
280 """
281 def __init__(self, sCmd = "", aArgs = None, aEnv = None, \
282 aFlags = None, timeoutMS = 5 * 60 * 1000, \
283 sUser = "", sPassword = "", sDomain = "", \
284 fWaitForExit = True):
285 tdTestGuestCtrlBase.__init__(self);
286 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
287 self.sCmd = sCmd;
288 self.aArgs = aArgs if aArgs is not None else [sCmd,];
289 self.aEnv = aEnv;
290 self.aFlags = aFlags or [];
291 self.timeoutMS = timeoutMS;
292 self.fWaitForExit = fWaitForExit;
293 self.uExitStatus = 0;
294 self.iExitCode = 0;
295 self.cbStdOut = 0;
296 self.cbStdErr = 0;
297 self.sBuf = '';
298
299class tdTestFileExists(tdTestGuestCtrlBase):
300 """
301 Test for the file exists API call (fileExists).
302 """
303 def __init__(self, sFile = "", sUser = "", sPassword = ""):
304 tdTestGuestCtrlBase.__init__(self);
305 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
306 self.sFile = sFile;
307
308class tdTestFileRemove(tdTestGuestCtrlBase):
309 """
310 Test querying guest file information.
311 """
312 def __init__(self, sFile = "", sUser = "", sPassword = ""):
313 tdTestGuestCtrlBase.__init__(self);
314 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
315 self.sFile = sFile;
316
317class tdTestFileStat(tdTestGuestCtrlBase):
318 """
319 Test querying guest file information.
320 """
321 def __init__(self, sFile = "", sUser = "", sPassword = "", cbSize = 0, eFileType = 0):
322 tdTestGuestCtrlBase.__init__(self);
323 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
324 self.sFile = sFile;
325 self.cbSize = cbSize;
326 self.eFileType = eFileType;
327
328class tdTestFileIO(tdTestGuestCtrlBase):
329 """
330 Test for the IGuestFile object.
331 """
332 def __init__(self, sFile = "", sUser = "", sPassword = ""):
333 tdTestGuestCtrlBase.__init__(self);
334 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
335 self.sFile = sFile;
336
337class tdTestFileQuerySize(tdTestGuestCtrlBase):
338 """
339 Test for the file size query API call (fileQuerySize).
340 """
341 def __init__(self, sFile = "", sUser = "", sPassword = ""):
342 tdTestGuestCtrlBase.__init__(self);
343 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
344 self.sFile = sFile;
345
346class tdTestFileReadWrite(tdTestGuestCtrlBase):
347 """
348 Tests reading from guest files.
349 """
350 def __init__(self, sFile = "", sUser = "", sPassword = "",
351 sOpenMode = "r", sDisposition = "",
352 sSharingMode = "",
353 lCreationMode = 0, cbOffset = 0, cbToReadWrite = 0,
354 aBuf = None):
355 tdTestGuestCtrlBase.__init__(self);
356 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
357 self.sFile = sFile;
358 self.sOpenMode = sOpenMode;
359 self.sDisposition = sDisposition;
360 self.sSharingMode = sSharingMode;
361 self.lCreationMode = lCreationMode;
362 self.cbOffset = cbOffset;
363 self.cbToReadWrite = cbToReadWrite;
364 self.aBuf = aBuf;
365
366 def getOpenAction(self):
367 """ Converts string disposition to open action enum. """
368 if self.sDisposition == 'oe': return vboxcon.FileOpenAction_OpenExisting;
369 if self.sDisposition == 'oc': return vboxcon.FileOpenAction_OpenOrCreate;
370 if self.sDisposition == 'ce': return vboxcon.FileOpenAction_CreateNew;
371 if self.sDisposition == 'ca': return vboxcon.FileOpenAction_CreateOrReplace;
372 if self.sDisposition == 'ot': return vboxcon.FileOpenAction_OpenExistingTruncated;
373 if self.sDisposition == 'oa': return vboxcon.FileOpenAction_AppendOrCreate;
374 raise base.GenError(self.sDisposition);
375
376 def getAccessMode(self):
377 """ Converts open mode to access mode enum. """
378 if self.sOpenMode == 'r': return vboxcon.FileOpenMode_ReadOnly;
379 if self.sOpenMode == 'w': return vboxcon.FileOpenMode_WriteOnly;
380 if self.sOpenMode == 'w+': return vboxcon.FileOpenMode_ReadWrite;
381 if self.sOpenMode == 'r+': return vboxcon.FileOpenMode_ReadWrite;
382 raise base.GenError(self.sOpenMode);
383
384 def getSharingMode(self):
385 """ Converts the sharing mode. """
386 return vboxcon.FileSharingMode_All;
387
388class tdTestSession(tdTestGuestCtrlBase):
389 """
390 Test the guest session handling.
391 """
392 def __init__(self, sUser = "", sPassword = "", sDomain = "", \
393 sSessionName = ""):
394 tdTestGuestCtrlBase.__init__(self);
395 self.sSessionName = sSessionName;
396 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
397
398 def getSessionCount(self, oVBoxMgr):
399 """
400 Helper for returning the number of currently
401 opened guest sessions of a VM.
402 """
403 if self.oTest.oGuest is None:
404 return 0;
405 aoSession = oVBoxMgr.getArray(self.oTest.oGuest, 'sessions')
406 return len(aoSession);
407
408class tdTestSessionEx(tdTestGuestCtrlBase):
409 """
410 Test the guest session.
411 """
412 def __init__(self, aoSteps = None, enmUser = None):
413 tdTestGuestCtrlBase.__init__(self);
414 assert enmUser is None; # For later.
415 self.enmUser = enmUser;
416 self.aoSteps = aoSteps if aoSteps is not None else [];
417
418 def execute(self, oTstDrv, oVmSession, oTxsSession, oTestVm, sMsgPrefix):
419 """
420 Executes the test.
421 """
422 #
423 # Create a session.
424 #
425 assert self.enmUser is None; # For later.
426 self.oCreds = tdCtxCreds(oTestVm = oTestVm);
427 self.setEnvironment(oVmSession, oTxsSession, oTestVm);
428 reporter.log2('%s: %s steps' % (sMsgPrefix, len(self.aoSteps),));
429 fRc, oCurSession = self.createSession(sMsgPrefix);
430 if fRc is True:
431 #
432 # Execute the tests.
433 #
434 try:
435 fRc = self.executeSteps(oTstDrv, oCurSession, sMsgPrefix);
436 except:
437 reporter.errorXcpt('%s: Unexpected exception executing test steps' % (sMsgPrefix,));
438 fRc = False;
439
440 fRc2 = self.closeSession();
441 if fRc2 is False:
442 reporter.error('%s: Session could not be closed' % (sMsgPrefix,));
443 fRc = False;
444 else:
445 reporter.error('%s: Session creation failed' % (sMsgPrefix,));
446 fRc = False;
447 return fRc;
448
449 def executeSteps(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
450 """
451 Executes just the steps.
452 Returns True on success, False on test failure.
453 """
454 fRc = True;
455 for (i, oStep) in enumerate(self.aoSteps):
456 fRc2 = oStep.execute(oTstDrv, oGstCtrlSession, sMsgPrefix + ', step #%d' % i);
457 if fRc2 is True:
458 pass;
459 elif fRc2 is None:
460 reporter.log('skipping remaining %d steps' % (len(self.aoSteps) - i - 1,));
461 break;
462 else:
463 fRc = False;
464 return fRc;
465
466 @staticmethod
467 def executeListTestSessions(aoTests, oTstDrv, oVmSession, oTxsSession, oTestVm, sMsgPrefix):
468 """
469 Works thru a list of tdTestSessionEx object.
470 """
471 fRc = True;
472 for (i, oCurTest) in enumerate(aoTests):
473 try:
474 fRc2 = oCurTest.execute(oTstDrv, oVmSession, oTxsSession, oTestVm, '%s, test %#d' % (sMsgPrefix, i,));
475 if fRc2 is not True:
476 fRc = False;
477 except:
478 reporter.errorXcpt('Unexpected exception executing test #%d' % (i,));
479 fRc = False;
480
481 return (fRc, oTxsSession);
482
483
484class tdSessionStepBase(object):
485 """
486 Base class for the guest control session test steps.
487 """
488
489 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
490 """
491 Executes the test step.
492
493 Returns True on success.
494 Returns False on failure (must be reported as error).
495 Returns None if to skip the remaining steps.
496 """
497 reporter.error('%s: Missing execute implementation: %s' % (sMsgPrefix, self,));
498 _ = oTstDrv;
499 _ = oGstCtrlSession;
500 return False;
501
502
503class tdStepRequireMinimumApiVer(tdSessionStepBase):
504 """
505 Special test step which will cause executeSteps to skip the remaining step
506 if the VBox API is too old:
507 """
508 def __init__(self, fpMinApiVer):
509 self.fpMinApiVer = fpMinApiVer;
510
511 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
512 """ Returns None if API version is too old, otherwise True. """
513 if oTstDrv.fpApiVer >= self.fpMinApiVer:
514 return True;
515 _ = oGstCtrlSession;
516 _ = sMsgPrefix;
517 return None; # Special return value. Don't use elsewhere.
518
519
520#
521# Scheduling Environment Changes with the Guest Control Session.
522#
523
524class tdStepSessionSetEnv(tdSessionStepBase):
525 """
526 Guest session environment: schedule putenv
527 """
528 def __init__(self, sVar, sValue, hrcExpected = 0):
529 self.sVar = sVar;
530 self.sValue = sValue;
531 self.hrcExpected = hrcExpected;
532
533 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
534 """
535 Executes the step.
536 Returns True on success, False on test failure.
537 """
538 reporter.log2('tdStepSessionSetEnv: sVar=%s sValue=%s hrcExpected=%#x' % (self.sVar, self.sValue, self.hrcExpected,));
539 try:
540 if oTstDrv.fpApiVer >= 5.0:
541 oGstCtrlSession.environmentScheduleSet(self.sVar, self.sValue);
542 else:
543 oGstCtrlSession.environmentSet(self.sVar, self.sValue);
544 except vbox.ComException as oXcpt:
545 # Is this an expected failure?
546 if vbox.ComError.equal(oXcpt, self.hrcExpected):
547 return True;
548 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (setenv %s=%s)'
549 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
550 vbox.ComError.getXcptResult(oXcpt),
551 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
552 self.sVar, self.sValue,));
553 return False;
554 except:
555 reporter.errorXcpt('%s: Unexpected exception in tdStepSessionSetEnv::execute (%s=%s)'
556 % (sMsgPrefix, self.sVar, self.sValue,));
557 return False;
558
559 # Should we succeed?
560 if self.hrcExpected != 0:
561 reporter.error('%s: Expected hrcExpected=%#x, got S_OK (putenv %s=%s)'
562 % (sMsgPrefix, self.hrcExpected, self.sVar, self.sValue,));
563 return False;
564 return True;
565
566class tdStepSessionUnsetEnv(tdSessionStepBase):
567 """
568 Guest session environment: schedule unset.
569 """
570 def __init__(self, sVar, hrcExpected = 0):
571 self.sVar = sVar;
572 self.hrcExpected = hrcExpected;
573
574 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
575 """
576 Executes the step.
577 Returns True on success, False on test failure.
578 """
579 reporter.log2('tdStepSessionUnsetEnv: sVar=%s hrcExpected=%#x' % (self.sVar, self.hrcExpected,));
580 try:
581 if oTstDrv.fpApiVer >= 5.0:
582 oGstCtrlSession.environmentScheduleUnset(self.sVar);
583 else:
584 oGstCtrlSession.environmentUnset(self.sVar);
585 except vbox.ComException as oXcpt:
586 # Is this an expected failure?
587 if vbox.ComError.equal(oXcpt, self.hrcExpected):
588 return True;
589 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (unsetenv %s)'
590 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
591 vbox.ComError.getXcptResult(oXcpt),
592 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
593 self.sVar,));
594 return False;
595 except:
596 reporter.errorXcpt('%s: Unexpected exception in tdStepSessionUnsetEnv::execute (%s)'
597 % (sMsgPrefix, self.sVar,));
598 return False;
599
600 # Should we succeed?
601 if self.hrcExpected != 0:
602 reporter.error('%s: Expected hrcExpected=%#x, got S_OK (unsetenv %s)'
603 % (sMsgPrefix, self.hrcExpected, self.sVar,));
604 return False;
605 return True;
606
607class tdStepSessionBulkEnv(tdSessionStepBase):
608 """
609 Guest session environment: Bulk environment changes.
610 """
611 def __init__(self, asEnv = None, hrcExpected = 0):
612 self.asEnv = asEnv if asEnv is not None else [];
613 self.hrcExpected = hrcExpected;
614
615 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
616 """
617 Executes the step.
618 Returns True on success, False on test failure.
619 """
620 reporter.log2('tdStepSessionBulkEnv: asEnv=%s hrcExpected=%#x' % (self.asEnv, self.hrcExpected,));
621 try:
622 if oTstDrv.fpApiVer >= 5.0:
623 oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environmentChanges', self.asEnv);
624 else:
625 oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environment', self.asEnv);
626 except vbox.ComException as oXcpt:
627 # Is this an expected failure?
628 if vbox.ComError.equal(oXcpt, self.hrcExpected):
629 return True;
630 reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (asEnv=%s)'
631 % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
632 vbox.ComError.getXcptResult(oXcpt),
633 vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
634 self.asEnv,));
635 return False;
636 except:
637 reporter.errorXcpt('%s: Unexpected exception writing the environmentChanges property (asEnv=%s).'
638 % (sMsgPrefix, self.asEnv));
639 return False;
640 return True;
641
642class tdStepSessionClearEnv(tdStepSessionBulkEnv):
643 """
644 Guest session environment: clears the scheduled environment changes.
645 """
646 def __init__(self):
647 tdStepSessionBulkEnv.__init__(self);
648
649
650class tdStepSessionCheckEnv(tdSessionStepBase):
651 """
652 Check the currently scheduled environment changes of a guest control session.
653 """
654 def __init__(self, asEnv = None):
655 self.asEnv = asEnv if asEnv is not None else [];
656
657 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
658 """
659 Executes the step.
660 Returns True on success, False on test failure.
661 """
662 reporter.log2('tdStepSessionCheckEnv: asEnv=%s' % (self.asEnv,));
663
664 #
665 # Get the environment change list.
666 #
667 try:
668 if oTstDrv.fpApiVer >= 5.0:
669 asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environmentChanges');
670 else:
671 asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environment');
672 except:
673 reporter.errorXcpt('%s: Unexpected exception reading the environmentChanges property.' % (sMsgPrefix,));
674 return False;
675
676 #
677 # Compare it with the expected one by trying to remove each expected value
678 # and the list anything unexpected.
679 #
680 fRc = True;
681 asCopy = list(asCurEnv); # just in case asCurEnv is immutable
682 for sExpected in self.asEnv:
683 try:
684 asCopy.remove(sExpected);
685 except:
686 reporter.error('%s: Expected "%s" to be in the resulting environment' % (sMsgPrefix, sExpected,));
687 fRc = False;
688 for sUnexpected in asCopy:
689 reporter.error('%s: Unexpected "%s" in the resulting environment' % (sMsgPrefix, sUnexpected,));
690 fRc = False;
691
692 if fRc is not True:
693 reporter.log2('%s: Current environment: %s' % (sMsgPrefix, asCurEnv));
694 return fRc;
695
696
697#
698# File system object statistics (i.e. stat()).
699#
700
701class tdStepStat(tdSessionStepBase):
702 """
703 Stats a file system object.
704 """
705 def __init__(self, sPath, hrcExpected = 0, fFound = True, fFollowLinks = True, enmType = None):
706 self.sPath = sPath;
707 self.hrcExpected = hrcExpected;
708 self.fFound = fFound;
709 self.fFollowLinks = fFollowLinks;
710 self.enmType = enmType if enmType is not None else vboxcon.FsObjType_File;
711 self.cbExactSize = None;
712 self.cbMinSize = None;
713
714 def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
715 """
716 Execute the test step.
717 """
718 reporter.log2('tdStepStat: sPath=%s enmType=%s hrcExpected=%s fFound=%s fFollowLinks=%s'
719 % (self.sPath, self.enmType, self.hrcExpected, self.fFound, self.fFollowLinks,));
720
721 # Don't execute non-file tests on older VBox version.
722 if oTstDrv.fpApiVer >= 5.0 or self.enmType == vboxcon.FsObjType_File or not self.fFound:
723 #
724 # Call the API.
725 #
726 try:
727 if oTstDrv.fpApiVer >= 5.0:
728 oFsInfo = oGstCtrlSession.fsObjQueryInfo(self.sPath, self.fFollowLinks);
729 else:
730 oFsInfo = oGstCtrlSession.fileQueryInfo(self.sPath);
731 except vbox.ComException as oXcpt:
732 ## @todo: The error reporting in the API just plain sucks! Most of the errors are
733 ## VBOX_E_IPRT_ERROR and there seems to be no way to distinguish between
734 ## non-existing files/path and a lot of other errors. Fix API and test!
735 if not self.fFound:
736 return True;
737 if vbox.ComError.equal(oXcpt, self.hrcExpected): # Is this an expected failure?
738 return True;
739 return reporter.errorXcpt('%s: Unexpected exception for exiting path "%s" (enmType=%s, hrcExpected=%s):'
740 % (sMsgPrefix, self.sPath, self.enmType, self.hrcExpected,));
741 except:
742 return reporter.errorXcpt('%s: Unexpected exception in tdStepStat::execute (%s)'
743 % (sMsgPrefix, self.sPath,));
744 if oFsInfo is None:
745 return reporter.error('%s: "%s" got None instead of IFsObjInfo instance!' % (sMsgPrefix, self.sPath,));
746
747 #
748 # Check type expectations.
749 #
750 try:
751 enmType = oFsInfo.type;
752 except:
753 return reporter.errorXcpt('%s: Unexpected exception in reading "IFsObjInfo::type"' % (sMsgPrefix,));
754 if enmType != self.enmType:
755 return reporter.error('%s: "%s" has type %s, expected %s'
756 % (sMsgPrefix, self.sPath, enmType, self.enmType));
757
758 #
759 # Check size expectations.
760 # Note! This is unicode string here on windows, for some reason.
761 # long long mapping perhaps?
762 #
763 try:
764 cbObject = long(oFsInfo.objectSize);
765 except:
766 return reporter.errorXcpt('%s: Unexpected exception in reading "IFsObjInfo::objectSize"'
767 % (sMsgPrefix,));
768 if self.cbExactSize is not None \
769 and cbObject != self.cbExactSize:
770 return reporter.error('%s: "%s" has size %s bytes, expected %s bytes'
771 % (sMsgPrefix, self.sPath, cbObject, self.cbExactSize));
772 if self.cbMinSize is not None \
773 and cbObject < self.cbMinSize:
774 return reporter.error('%s: "%s" has size %s bytes, expected as least %s bytes'
775 % (sMsgPrefix, self.sPath, cbObject, self.cbMinSize));
776 return True;
777
778class tdStepStatDir(tdStepStat):
779 """ Checks for an existing directory. """
780 def __init__(self, sDirPath):
781 tdStepStat.__init__(self, sPath = sDirPath, enmType = vboxcon.FsObjType_Directory);
782
783class tdStepStatFile(tdStepStat):
784 """ Checks for an existing file """
785 def __init__(self, sFilePath):
786 tdStepStat.__init__(self, sPath = sFilePath, enmType = vboxcon.FsObjType_File);
787
788class tdStepStatFileSize(tdStepStat):
789 """ Checks for an existing file of a given expected size.. """
790 def __init__(self, sFilePath, cbExactSize = 0):
791 tdStepStat.__init__(self, sPath = sFilePath, enmType = vboxcon.FsObjType_File);
792 self.cbExactSize = cbExactSize;
793
794class tdStepStatFileNotFound(tdStepStat):
795 """ Checks for an existing directory. """
796 def __init__(self, sPath):
797 tdStepStat.__init__(self, sPath = sPath, fFound = False);
798
799class tdStepStatPathNotFound(tdStepStat):
800 """ Checks for an existing directory. """
801 def __init__(self, sPath):
802 tdStepStat.__init__(self, sPath = sPath, fFound = False);
803
804
805#
806#
807#
808
809class tdTestSessionFileRefs(tdTestGuestCtrlBase):
810 """
811 Tests session file (IGuestFile) reference counting.
812 """
813 def __init__(self, cRefs = 0):
814 tdTestGuestCtrlBase.__init__(self);
815 self.cRefs = cRefs;
816
817class tdTestSessionDirRefs(tdTestGuestCtrlBase):
818 """
819 Tests session directory (IGuestDirectory) reference counting.
820 """
821 def __init__(self, cRefs = 0):
822 tdTestGuestCtrlBase.__init__(self);
823 self.cRefs = cRefs;
824
825class tdTestSessionProcRefs(tdTestGuestCtrlBase):
826 """
827 Tests session process (IGuestProcess) reference counting.
828 """
829 def __init__(self, cRefs = 0):
830 tdTestGuestCtrlBase.__init__(self);
831 self.cRefs = cRefs;
832
833class tdTestUpdateAdditions(tdTestGuestCtrlBase):
834 """
835 Test updating the Guest Additions inside the guest.
836 """
837 def __init__(self, sSrc = "", aArgs = None, aFlags = None,
838 sUser = "", sPassword = "", sDomain = ""):
839 tdTestGuestCtrlBase.__init__(self);
840 self.oCreds = tdCtxCreds(sUser, sPassword, sDomain);
841 self.sSrc = sSrc;
842 self.aArgs = aArgs;
843 self.aFlags = aFlags;
844
845class tdTestResult(object):
846 """
847 Base class for test results.
848 """
849 def __init__(self, fRc = False):
850 ## The overall test result.
851 self.fRc = fRc;
852
853class tdTestResultDirRead(tdTestResult):
854 """
855 Test result for reading guest directories.
856 """
857 def __init__(self, fRc = False,
858 numFiles = 0, numDirs = 0):
859 tdTestResult.__init__(self, fRc = fRc);
860 self.numFiles = numFiles;
861 self.numDirs = numDirs;
862
863class tdTestResultExec(tdTestResult):
864 """
865 Holds a guest process execution test result,
866 including the exit code, status + aFlags.
867 """
868 def __init__(self, fRc = False, \
869 uExitStatus = 500, iExitCode = 0, \
870 sBuf = None, cbBuf = 0, \
871 cbStdOut = 0, cbStdErr = 0):
872 tdTestResult.__init__(self);
873 ## The overall test result.
874 self.fRc = fRc;
875 ## Process exit stuff.
876 self.uExitStatus = uExitStatus;
877 self.iExitCode = iExitCode;
878 ## Desired buffer length returned back from stdout/stderr.
879 self.cbBuf = cbBuf;
880 ## Desired buffer result from stdout/stderr. Use with caution!
881 self.sBuf = sBuf;
882 self.cbStdOut = cbStdOut;
883 self.cbStdErr = cbStdErr;
884
885class tdTestResultFileStat(tdTestResult):
886 """
887 Test result for stat'ing guest files.
888 """
889 def __init__(self, fRc = False,
890 cbSize = 0, eFileType = 0):
891 tdTestResult.__init__(self, fRc = fRc);
892 self.cbSize = cbSize;
893 self.eFileType = eFileType;
894 ## @todo Add more information.
895
896class tdTestResultFileReadWrite(tdTestResult):
897 """
898 Test result for reading + writing guest directories.
899 """
900 def __init__(self, fRc = False,
901 cbProcessed = 0, cbOffset = 0, aBuf = None):
902 tdTestResult.__init__(self, fRc = fRc);
903 self.cbProcessed = cbProcessed;
904 self.cbOffset = cbOffset;
905 self.aBuf = aBuf;
906
907class tdTestResultSession(tdTestResult):
908 """
909 Test result for guest session counts.
910 """
911 def __init__(self, fRc = False, cNumSessions = 0):
912 tdTestResult.__init__(self, fRc = fRc);
913 self.cNumSessions = cNumSessions;
914
915class SubTstDrvAddGuestCtrl(base.SubTestDriverBase):
916 """
917 Sub-test driver for executing guest control (VBoxService, IGuest) tests.
918 """
919
920 def __init__(self, oTstDrv):
921 base.SubTestDriverBase.__init__(self, 'add-guest-ctrl', oTstDrv);
922
923 ## @todo base.TestBase.
924 self.asTestsDef = \
925 [
926 'session_basic', 'session_env', 'session_file_ref', 'session_dir_ref', 'session_proc_ref',
927 'exec_basic', 'exec_errorlevel', 'exec_timeout',
928 'dir_create', 'dir_create_temp', 'dir_read',
929 'file_remove', 'file_stat', 'file_read', 'file_write',
930 'copy_to', 'copy_from',
931 'update_additions'
932 ];
933 self.asTests = self.asTestsDef;
934
935 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
936 if asArgs[iArg] == '--add-guest-ctrl-tests':
937 iArg += 1;
938 if asArgs[iArg] == 'all': # Nice for debugging scripts.
939 self.asTests = self.asTestsDef;
940 return iArg + 1;
941
942 iNext = self.oTstDrv.requireMoreArgs(1, asArgs, iArg);
943 self.asTests = asArgs[iArg].split(':');
944 for s in self.asTests:
945 if s not in self.asTestsDef:
946 raise base.InvalidOption('The "--add-guest-ctrl-tests" value "%s" is not valid; valid values are: %s' \
947 % (s, ' '.join(self.asTestsDef)));
948 return iNext;
949 return iArg;
950
951 def showUsage(self):
952 base.SubTestDriverBase.showUsage(self);
953 reporter.log(' --add-guest-ctrl-tests <s1[:s2[:]]>');
954 reporter.log(' Default: %s (all)' % (':'.join(self.asTestsDef)));
955 return True;
956
957 def testIt(self, oTestVm, oSession, oTxsSession):
958 """
959 Executes the test.
960
961 Returns fRc, oTxsSession. The latter may have changed.
962 """
963 reporter.log("Active tests: %s" % (self.asTests,));
964
965 fRc = True;
966
967 # Do the testing.
968 reporter.testStart('Session Basics');
969 fSkip = 'session_basic' not in self.asTests;
970 if fSkip is False:
971 fRc, oTxsSession = self.testGuestCtrlSession(oSession, oTxsSession, oTestVm);
972 reporter.testDone(fSkip);
973
974 reporter.testStart('Session Environment');
975 fSkip = 'session_env' not in self.asTests or fRc is False;
976 if fSkip is False:
977 fRc, oTxsSession = self.testGuestCtrlSessionEnvironment(oSession, oTxsSession, oTestVm);
978 reporter.testDone(fSkip);
979
980 reporter.testStart('Session File References');
981 fSkip = 'session_file_ref' not in self.asTests;
982 if fSkip is False:
983 fRc, oTxsSession = self.testGuestCtrlSessionFileRefs(oSession, oTxsSession, oTestVm);
984 reporter.testDone(fSkip);
985
986 ## @todo Implement this.
987 #reporter.testStart('Session Directory References');
988 #fSkip = 'session_dir_ref' not in self.asTests;
989 #if fSkip is False:
990 # fRc, oTxsSession = self.testGuestCtrlSessionDirRefs(oSession, oTxsSession, oTestVm);
991 #reporter.testDone(fSkip);
992
993 reporter.testStart('Session Process References');
994 fSkip = 'session_proc_ref' not in self.asTests or fRc is False;
995 if fSkip is False:
996 fRc, oTxsSession = self.testGuestCtrlSessionProcRefs(oSession, oTxsSession, oTestVm);
997 reporter.testDone(fSkip);
998
999 reporter.testStart('Execution');
1000 fSkip = 'exec_basic' not in self.asTests or fRc is False;
1001 if fSkip is False:
1002 fRc, oTxsSession = self.testGuestCtrlExec(oSession, oTxsSession, oTestVm);
1003 reporter.testDone(fSkip);
1004
1005 reporter.testStart('Execution Error Levels');
1006 fSkip = 'exec_errorlevel' not in self.asTests or fRc is False;
1007 if fSkip is False:
1008 fRc, oTxsSession = self.testGuestCtrlExecErrorLevel(oSession, oTxsSession, oTestVm);
1009 reporter.testDone(fSkip);
1010
1011 reporter.testStart('Execution Timeouts');
1012 fSkip = 'exec_timeout' not in self.asTests or fRc is False;
1013 if fSkip is False:
1014 fRc, oTxsSession = self.testGuestCtrlExecTimeout(oSession, oTxsSession, oTestVm);
1015 reporter.testDone(fSkip);
1016
1017 reporter.testStart('Creating directories');
1018 fSkip = 'dir_create' not in self.asTests or fRc is False;
1019 if fSkip is False:
1020 fRc, oTxsSession = self.testGuestCtrlDirCreate(oSession, oTxsSession, oTestVm);
1021 reporter.testDone(fSkip);
1022
1023 reporter.testStart('Creating temporary directories');
1024 fSkip = 'dir_create_temp' not in self.asTests or fRc is False;
1025 if fSkip is False:
1026 fRc, oTxsSession = self.testGuestCtrlDirCreateTemp(oSession, oTxsSession, oTestVm);
1027 reporter.testDone(fSkip);
1028
1029 reporter.testStart('Reading directories');
1030 fSkip = 'dir_read' not in self.asTests or fRc is False;
1031 if fSkip is False:
1032 fRc, oTxsSession = self.testGuestCtrlDirRead(oSession, oTxsSession, oTestVm);
1033 reporter.testDone(fSkip);
1034
1035 reporter.testStart('Copy to guest');
1036 fSkip = 'copy_to' not in self.asTests or fRc is False;
1037 if fSkip is False:
1038 fRc, oTxsSession = self.testGuestCtrlCopyTo(oSession, oTxsSession, oTestVm);
1039 reporter.testDone(fSkip);
1040
1041 reporter.testStart('Copy from guest');
1042 fSkip = 'copy_from' not in self.asTests or fRc is False;
1043 if fSkip is False:
1044 fRc, oTxsSession = self.testGuestCtrlCopyFrom(oSession, oTxsSession, oTestVm);
1045 reporter.testDone(fSkip);
1046
1047 reporter.testStart('Removing files');
1048 fSkip = 'file_remove' not in self.asTests or fRc is False;
1049 if fSkip is False:
1050 fRc, oTxsSession = self.testGuestCtrlFileRemove(oSession, oTxsSession, oTestVm);
1051 reporter.testDone(fSkip);
1052
1053 reporter.testStart('Querying file information (stat)');
1054 fSkip = 'file_stat' not in self.asTests or fRc is False;
1055 if fSkip is False:
1056 fRc, oTxsSession = self.testGuestCtrlFileStat(oSession, oTxsSession, oTestVm);
1057 reporter.testDone(fSkip);
1058
1059 # FIXME: Failing tests.
1060 # reporter.testStart('File read');
1061 # fSkip = 'file_read' not in self.asTests or fRc is False;
1062 # if fSkip is False:
1063 # fRc, oTxsSession = self.testGuestCtrlFileRead(oSession, oTxsSession, oTestVm);
1064 # reporter.testDone(fSkip);
1065
1066 # reporter.testStart('File write');
1067 # fSkip = 'file_write' not in self.asTests or fRc is False;
1068 # if fSkip is False:
1069 # fRc, oTxsSession = self.testGuestCtrlFileWrite(oSession, oTxsSession, oTestVm);
1070 # reporter.testDone(fSkip);
1071
1072 reporter.testStart('Updating Guest Additions');
1073 fSkip = 'update_additions' not in self.asTests or fRc is False;
1074 # Skip test for updating Guest Additions if we run on a too old (Windows) guest.
1075 fSkip = oTestVm.sKind in ('WindowsNT4', 'Windows2000', 'WindowsXP', 'Windows2003');
1076 if fSkip is False:
1077 fRc, oTxsSession = self.testGuestCtrlUpdateAdditions(oSession, oTxsSession, oTestVm);
1078 reporter.testDone(fSkip);
1079
1080 return (fRc, oTxsSession);
1081
1082 def gctrlCopyFileFrom(self, oGuestSession, sSrc, sDst, aFlags):
1083 """
1084 Helper function to copy a single file from the guest to the host.
1085 """
1086 fRc = True; # Be optimistic.
1087 try:
1088 reporter.log2('Copying guest file "%s" to host "%s"' % (sSrc, sDst));
1089 if self.oTstDrv.fpApiVer >= 5.0:
1090 curProgress = oGuestSession.fileCopyFromGuest(sSrc, sDst, aFlags);
1091 else:
1092 curProgress = oGuestSession.copyFrom(sSrc, sDst, aFlags);
1093 if curProgress is not None:
1094 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlFileCopyFrom");
1095 try:
1096 oProgress.wait();
1097 if not oProgress.isSuccess():
1098 oProgress.logResult(fIgnoreErrors = True);
1099 fRc = False;
1100 except:
1101 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
1102 fRc = False;
1103 else:
1104 reporter.error('No progress object returned');
1105 fRc = False;
1106 except:
1107 # Just log, don't assume an error here (will be done in the main loop then).
1108 reporter.logXcpt('Copy from exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
1109 fRc = False;
1110
1111 return fRc;
1112
1113 def gctrlCopyFileTo(self, oGuestSession, sSrc, sDst, aFlags):
1114 """
1115 Helper function to copy a single file from host to the guest.
1116 """
1117 fRc = True; # Be optimistic.
1118 try:
1119 reporter.log2('Copying host file "%s" to guest "%s"' % (sSrc, sDst));
1120 if self.oTstDrv.fpApiVer >= 5.0:
1121 curProgress = oGuestSession.fileCopyToGuest(sSrc, sDst, aFlags);
1122 else:
1123 curProgress = oGuestSession.copyTo(sSrc, sDst, aFlags);
1124 if curProgress is not None:
1125 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlCopyFileTo");
1126 try:
1127 oProgress.wait();
1128 if not oProgress.isSuccess():
1129 oProgress.logResult(fIgnoreErrors = True);
1130 fRc = False;
1131 except:
1132 reporter.logXcpt('Wait exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
1133 fRc = False;
1134 else:
1135 reporter.error('No progress object returned');
1136 fRc = False;
1137 except:
1138 # Just log, don't assume an error here (will be done in the main loop then).
1139 reporter.logXcpt('Copy to exception for sSrc="%s", sDst="%s":' % (sSrc, sDst));
1140 fRc = False;
1141
1142 return fRc;
1143
1144 def gctrlCreateDir(self, oTest, oRes, oGuestSession):
1145 """
1146 Helper function to create a guest directory specified in
1147 the current test.
1148 """
1149 fRc = True; # Be optimistic.
1150 reporter.log2('Creating directory "%s"' % (oTest.sDirectory,));
1151
1152 try:
1153 oGuestSession.directoryCreate(oTest.sDirectory, \
1154 oTest.fMode, oTest.aFlags);
1155 if self.oTstDrv.fpApiVer >= 5.0:
1156 fDirExists = oGuestSession.directoryExists(oTest.sDirectory, False);
1157 else:
1158 fDirExists = oGuestSession.directoryExists(oTest.sDirectory);
1159 if fDirExists is False \
1160 and oRes.fRc is True:
1161 # Directory does not exist but we want it to.
1162 fRc = False;
1163 except:
1164 reporter.logXcpt('Directory create exception for directory "%s":' % (oTest.sDirectory,));
1165 if oRes.fRc is True:
1166 # Just log, don't assume an error here (will be done in the main loop then).
1167 fRc = False;
1168 # Directory creation failed, which was the expected result.
1169
1170 return fRc;
1171
1172 def gctrlReadDir(self, oTest, oRes, oGuestSession, subDir = ''): # pylint: disable=R0914
1173 """
1174 Helper function to read a guest directory specified in
1175 the current test.
1176 """
1177 sDir = oTest.sDirectory;
1178 sFilter = oTest.sFilter;
1179 aFlags = oTest.aFlags;
1180
1181 fRc = True; # Be optimistic.
1182 cDirs = 0; # Number of directories read.
1183 cFiles = 0; # Number of files read.
1184
1185 try:
1186 sCurDir = os.path.join(sDir, subDir);
1187 #reporter.log2('Directory="%s", filter="%s", aFlags="%s"' % (sCurDir, sFilter, aFlags));
1188 oCurDir = oGuestSession.directoryOpen(sCurDir, sFilter, aFlags);
1189 while fRc:
1190 try:
1191 oFsObjInfo = oCurDir.read();
1192 if oFsObjInfo.name == "." \
1193 or oFsObjInfo.name == "..":
1194 #reporter.log2('\tSkipping "%s"' % oFsObjInfo.name);
1195 continue; # Skip "." and ".." entries.
1196 if oFsObjInfo.type is vboxcon.FsObjType_Directory:
1197 #reporter.log2('\tDirectory "%s"' % oFsObjInfo.name);
1198 cDirs += 1;
1199 sSubDir = oFsObjInfo.name;
1200 if subDir != "":
1201 sSubDir = os.path.join(subDir, oFsObjInfo.name);
1202 fRc, cSubDirs, cSubFiles = self.gctrlReadDir(oTest, oRes, oGuestSession, sSubDir);
1203 cDirs += cSubDirs;
1204 cFiles += cSubFiles;
1205 elif oFsObjInfo.type is vboxcon.FsObjType_File:
1206 #reporter.log2('\tFile "%s"' % oFsObjInfo.name);
1207 cFiles += 1;
1208 elif oFsObjInfo.type is vboxcon.FsObjType_Symlink:
1209 #reporter.log2('\tSymlink "%s" -- not tested yet' % oFsObjInfo.name);
1210 pass;
1211 else:
1212 reporter.error('\tDirectory "%s" contains invalid directory entry "%s" (type %d)' % \
1213 (sCurDir, oFsObjInfo.name, oFsObjInfo.type));
1214 fRc = False;
1215 except Exception as oXcpt:
1216 # No necessarily an error -- could be VBOX_E_OBJECT_NOT_FOUND. See reference.
1217 if vbox.ComError.equal(oXcpt, vbox.ComError.VBOX_E_OBJECT_NOT_FOUND):
1218 #reporter.log2('\tNo more directory entries for "%s"' % (sCurDir,));
1219 break
1220 # Just log, don't assume an error here (will be done in the main loop then).
1221 reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
1222 fRc = False;
1223 break;
1224 oCurDir.close();
1225 except:
1226 # Just log, don't assume an error here (will be done in the main loop then).
1227 reporter.logXcpt('\tDirectory open exception for directory="%s":' % (sCurDir,));
1228 fRc = False;
1229
1230 return (fRc, cDirs, cFiles);
1231
1232 def gctrlExecDoTest(self, i, oTest, oRes, oGuestSession):
1233 """
1234 Wrapper function around gctrlExecute to provide more sanity checking
1235 when needed in actual execution tests.
1236 """
1237 reporter.log('Testing #%d, cmd="%s" ...' % (i, oTest.sCmd));
1238 fRc = self.gctrlExecute(oTest, oGuestSession);
1239 if fRc is oRes.fRc:
1240 if fRc is True:
1241 # Compare exit status / code on successful process execution.
1242 if oTest.uExitStatus != oRes.uExitStatus \
1243 or oTest.iExitCode != oRes.iExitCode:
1244 reporter.error('Test #%d failed: Got exit status + code %d,%d, expected %d,%d'
1245 % (i, oTest.uExitStatus, oTest.iExitCode, oRes.uExitStatus, oRes.iExitCode));
1246 return False;
1247 if fRc is True:
1248 # Compare test / result buffers on successful process execution.
1249 if oTest.sBuf is not None \
1250 and oRes.sBuf is not None:
1251 if bytes(oTest.sBuf) != bytes(oRes.sBuf):
1252 reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)'
1253 % (i, map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), \
1254 map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
1255 return False;
1256 else:
1257 reporter.log2('Test #%d passed: Buffers match (%d bytes)' % (i, len(oRes.sBuf)));
1258 elif oRes.sBuf is not None \
1259 and oRes.sBuf:
1260 reporter.error('Test #%d failed: Got no buffer data, expected\n%s (%dbytes)' %
1261 (i, map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
1262 return False;
1263 elif oRes.cbStdOut > 0 \
1264 and oRes.cbStdOut != oTest.cbStdOut:
1265 reporter.error('Test #%d failed: Got %d stdout data, expected %d'
1266 % (i, oTest.cbStdOut, oRes.cbStdOut));
1267 return False;
1268 else:
1269 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, oRes.fRc));
1270 return False;
1271 return True;
1272
1273 def gctrlExecute(self, oTest, oGuestSession):
1274 """
1275 Helper function to execute a program on a guest, specified in
1276 the current test.
1277 """
1278 fRc = True; # Be optimistic.
1279
1280 ## @todo Compare execution timeouts!
1281 #tsStart = base.timestampMilli();
1282
1283 reporter.log2('Using session user=%s, sDomain=%s, session name=%s, session timeout=%d' \
1284 % (oGuestSession.user, oGuestSession.domain, \
1285 oGuestSession.name, oGuestSession.timeout));
1286 reporter.log2('Executing cmd=%s, aFlags=%s, timeout=%d, args=%s, env=%s' \
1287 % (oTest.sCmd, oTest.aFlags, oTest.timeoutMS, \
1288 oTest.aArgs, oTest.aEnv));
1289 try:
1290 curProc = oGuestSession.processCreate(oTest.sCmd,
1291 oTest.aArgs if self.oTstDrv.fpApiVer >= 5.0 else oTest.aArgs[1:],
1292 oTest.aEnv, oTest.aFlags, oTest.timeoutMS);
1293 if curProc is not None:
1294 reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,));
1295 fWaitFor = [ vboxcon.ProcessWaitForFlag_Start ];
1296 waitResult = curProc.waitForArray(fWaitFor, oTest.timeoutMS);
1297 reporter.log2('Wait result returned: %d, current process status is: %d' % (waitResult, curProc.status));
1298
1299 if curProc.status == vboxcon.ProcessStatus_Started:
1300 fWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];
1301 if vboxcon.ProcessCreateFlag_WaitForStdOut in oTest.aFlags:
1302 fWaitFor.append(vboxcon.ProcessWaitForFlag_StdOut);
1303 if vboxcon.ProcessCreateFlag_WaitForStdErr in oTest.aFlags:
1304 fWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr);
1305 ## @todo Add vboxcon.ProcessWaitForFlag_StdIn.
1306 reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' \
1307 % (curProc.PID, oTest.timeoutMS, fWaitFor));
1308 while True:
1309 waitResult = curProc.waitForArray(fWaitFor, oTest.timeoutMS);
1310 reporter.log2('Wait returned: %d' % (waitResult,));
1311 try:
1312 # Try stdout.
1313 if waitResult == vboxcon.ProcessWaitResult_StdOut \
1314 or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
1315 reporter.log2('Reading stdout ...');
1316 abBuf = curProc.Read(1, 64 * 1024, oTest.timeoutMS);
1317 if abBuf:
1318 reporter.log2('Process (PID %d) got %d bytes of stdout data' % (curProc.PID, len(abBuf)));
1319 oTest.cbStdOut += len(abBuf);
1320 oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now.
1321 # Try stderr.
1322 if waitResult == vboxcon.ProcessWaitResult_StdErr \
1323 or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
1324 reporter.log2('Reading stderr ...');
1325 abBuf = curProc.Read(2, 64 * 1024, oTest.timeoutMS);
1326 if abBuf:
1327 reporter.log2('Process (PID %d) got %d bytes of stderr data' % (curProc.PID, len(abBuf)));
1328 oTest.cbStdErr += len(abBuf);
1329 oTest.sBuf = abBuf; # Appending does *not* work atm, so just assign it. No time now.
1330 # Use stdin.
1331 if waitResult == vboxcon.ProcessWaitResult_StdIn \
1332 or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
1333 pass; #reporter.log2('Process (PID %d) needs stdin data' % (curProc.pid,));
1334 # Termination or error?
1335 if waitResult == vboxcon.ProcessWaitResult_Terminate \
1336 or waitResult == vboxcon.ProcessWaitResult_Error \
1337 or waitResult == vboxcon.ProcessWaitResult_Timeout:
1338 reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' \
1339 % (curProc.PID, waitResult, curProc.status));
1340 break;
1341 except:
1342 # Just skip reads which returned nothing.
1343 pass;
1344 reporter.log2('Final process status (PID %d) is: %d' % (curProc.PID, curProc.status));
1345 reporter.log2('Process (PID %d) %d stdout, %d stderr' % (curProc.PID, oTest.cbStdOut, oTest.cbStdErr));
1346 oTest.uExitStatus = curProc.status;
1347 oTest.iExitCode = curProc.exitCode;
1348 reporter.log2('Process (PID %d) has exit code: %d' % (curProc.PID, oTest.iExitCode));
1349 except KeyboardInterrupt:
1350 reporter.error('Process (PID %d) execution interrupted' % (curProc.PID,));
1351 if curProc is not None:
1352 curProc.close();
1353 except:
1354 # Just log, don't assume an error here (will be done in the main loop then).
1355 reporter.logXcpt('Execution exception for command "%s":' % (oTest.sCmd,));
1356 fRc = False;
1357
1358 return fRc;
1359
1360 def testGuestCtrlSessionEnvironment(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
1361 """
1362 Tests the guest session environment changes.
1363 """
1364 aoTests = [
1365 # Check basic operations.
1366 tdTestSessionEx([ # Initial environment is empty.
1367 tdStepSessionCheckEnv(),
1368 # Check clearing empty env.
1369 tdStepSessionClearEnv(),
1370 tdStepSessionCheckEnv(),
1371 # Check set.
1372 tdStepSessionSetEnv('FOO', 'BAR'),
1373 tdStepSessionCheckEnv(['FOO=BAR',]),
1374 tdStepRequireMinimumApiVer(5.0), # 4.3 can't cope with the remainder.
1375 tdStepSessionClearEnv(),
1376 tdStepSessionCheckEnv(),
1377 # Check unset.
1378 tdStepSessionUnsetEnv('BAR'),
1379 tdStepSessionCheckEnv(['BAR']),
1380 tdStepSessionClearEnv(),
1381 tdStepSessionCheckEnv(),
1382 # Set + unset.
1383 tdStepSessionSetEnv('FOO', 'BAR'),
1384 tdStepSessionCheckEnv(['FOO=BAR',]),
1385 tdStepSessionUnsetEnv('FOO'),
1386 tdStepSessionCheckEnv(['FOO']),
1387 # Bulk environment changes (via attrib) (shall replace existing 'FOO').
1388 tdStepSessionBulkEnv( ['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
1389 tdStepSessionCheckEnv(['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
1390 ]),
1391 tdTestSessionEx([ # Check that setting the same value several times works.
1392 tdStepSessionSetEnv('FOO','BAR'),
1393 tdStepSessionCheckEnv([ 'FOO=BAR',]),
1394 tdStepSessionSetEnv('FOO','BAR2'),
1395 tdStepSessionCheckEnv([ 'FOO=BAR2',]),
1396 tdStepSessionSetEnv('FOO','BAR3'),
1397 tdStepSessionCheckEnv([ 'FOO=BAR3',]),
1398 tdStepRequireMinimumApiVer(5.0), # 4.3 can't cope with the remainder.
1399 # Add a little unsetting to the mix.
1400 tdStepSessionSetEnv('BAR', 'BEAR'),
1401 tdStepSessionCheckEnv([ 'FOO=BAR3', 'BAR=BEAR',]),
1402 tdStepSessionUnsetEnv('FOO'),
1403 tdStepSessionCheckEnv([ 'FOO', 'BAR=BEAR',]),
1404 tdStepSessionSetEnv('FOO','BAR4'),
1405 tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR',]),
1406 # The environment is case sensitive.
1407 tdStepSessionSetEnv('foo','BAR5'),
1408 tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo=BAR5']),
1409 tdStepSessionUnsetEnv('foo'),
1410 tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo']),
1411 ]),
1412 tdTestSessionEx([ # Bulk settings merges stuff, last entry standing.
1413 tdStepSessionBulkEnv(['FOO=bar', 'foo=bar', 'FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
1414 tdStepSessionCheckEnv(['FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
1415 tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy!
1416 tdStepSessionBulkEnv(['2=1+1', 'FOO=doofus2', ]),
1417 tdStepSessionCheckEnv(['2=1+1', 'FOO=doofus2' ]),
1418 ]),
1419 # Invalid variable names.
1420 tdTestSessionEx([
1421 tdStepSessionSetEnv('', 'FOO', vbox.ComError.E_INVALIDARG),
1422 tdStepSessionCheckEnv(),
1423 tdStepRequireMinimumApiVer(5.0), # 4.3 is too relaxed checking input!
1424 tdStepSessionSetEnv('=', '===', vbox.ComError.E_INVALIDARG),
1425 tdStepSessionCheckEnv(),
1426 tdStepSessionSetEnv('FOO=', 'BAR', vbox.ComError.E_INVALIDARG),
1427 tdStepSessionCheckEnv(),
1428 tdStepSessionSetEnv('=FOO', 'BAR', vbox.ComError.E_INVALIDARG),
1429 tdStepSessionCheckEnv(),
1430 tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy and too relaxed!
1431 tdStepSessionBulkEnv(['', 'foo=bar'], vbox.ComError.E_INVALIDARG),
1432 tdStepSessionCheckEnv(),
1433 tdStepSessionBulkEnv(['=', 'foo=bar'], vbox.ComError.E_INVALIDARG),
1434 tdStepSessionCheckEnv(),
1435 tdStepSessionBulkEnv(['=FOO', 'foo=bar'], vbox.ComError.E_INVALIDARG),
1436 tdStepSessionCheckEnv(),
1437 ]),
1438 # A bit more weird keys/values.
1439 tdTestSessionEx([ tdStepSessionSetEnv('$$$', ''),
1440 tdStepSessionCheckEnv([ '$$$=',]), ]),
1441 tdTestSessionEx([ tdStepSessionSetEnv('$$$', '%%%'),
1442 tdStepSessionCheckEnv([ '$$$=%%%',]),
1443 ]),
1444 tdTestSessionEx([ tdStepRequireMinimumApiVer(5.0), # 4.3 is buggy!
1445 tdStepSessionSetEnv(u'ß$%ß&', ''),
1446 tdStepSessionCheckEnv([ u'ß$%ß&=',]),
1447 ]),
1448 # Misc stuff.
1449 tdTestSessionEx([ tdStepSessionSetEnv('FOO', ''),
1450 tdStepSessionCheckEnv(['FOO=',]),
1451 ]),
1452 tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
1453 tdStepSessionCheckEnv(['FOO=BAR',])
1454 ],),
1455 tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
1456 tdStepSessionSetEnv('BAR', 'BAZ'),
1457 tdStepSessionCheckEnv([ 'FOO=BAR', 'BAR=BAZ',]),
1458 ]),
1459 ];
1460 return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'SessionEnv');
1461
1462 def testGuestCtrlSession(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
1463 """
1464 Tests the guest session handling.
1465 """
1466
1467 if oTestVm.isWindows():
1468 sUser = "Administrator";
1469 else:
1470 sUser = "vbox";
1471 sPassword = "password";
1472
1473 aaTests = [
1474 # Invalid parameters.
1475 [ tdTestSession(),
1476 tdTestResultSession(fRc = False) ],
1477 [ tdTestSession(sUser = ''),
1478 tdTestResultSession(fRc = False) ],
1479 [ tdTestSession(sPassword = 'bar'),
1480 tdTestResultSession(fRc = False) ],
1481 [ tdTestSession(sDomain = 'boo'),
1482 tdTestResultSession(fRc = False) ],
1483 [ tdTestSession(sPassword = 'bar', sDomain = 'boo'),
1484 tdTestResultSession(fRc = False) ],
1485 # User account without a passwort - forbidden.
1486 [ tdTestSession(sUser = sUser),
1487 tdTestResultSession(fRc = False) ],
1488 # Wrong credentials.
1489 # Note: On Guest Additions < 4.3 this always succeeds because these don't
1490 # support creating dedicated sessions. Instead, guest process creation
1491 # then will fail. See note below.
1492 [ tdTestSession(sUser = 'foo', sPassword = 'bar', sDomain = 'boo'),
1493 tdTestResultSession(fRc = False) ],
1494 # Correct credentials.
1495 [ tdTestSession(sUser = sUser, sPassword = sPassword),
1496 tdTestResultSession(fRc = True, cNumSessions = 1) ]
1497 ];
1498
1499 # Parameters.
1500 fRc = True;
1501 for (i, aTest) in enumerate(aaTests):
1502 curTest = aTest[0]; # tdTestSession, use an index, later.
1503 curRes = aTest[1]; # tdTestResult
1504 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
1505 reporter.log('Testing #%d, user="%s", sPassword="%s", sDomain="%s" ...' \
1506 % (i, curTest.oCreds.sUser, curTest.oCreds.sPassword, curTest.oCreds.sDomain));
1507 curGuestSessionName = 'testGuestCtrlSession: Test #%d' % (i);
1508 fRc2, curGuestSession = curTest.createSession(curGuestSessionName);
1509 # See note about < 4.3 Guest Additions above.
1510 if curGuestSession is not None \
1511 and curGuestSession.protocolVersion >= 2 \
1512 and fRc2 is not curRes.fRc:
1513 reporter.error('Test #%d failed: Session creation failed: Got %s, expected %s' \
1514 % (i, fRc2, curRes.fRc));
1515 fRc = False;
1516 if fRc2:
1517 # On Guest Additions < 4.3 getSessionCount() always will return 1, so skip the
1518 # check then.
1519 if curGuestSession.protocolVersion >= 2:
1520 curSessionCount = curTest.getSessionCount(self.oTstDrv.oVBoxMgr);
1521 if curSessionCount is not curRes.cNumSessions:
1522 reporter.error('Test #%d failed: Session count does not match: Got %d, expected %d' \
1523 % (i, curSessionCount, curRes.cNumSessions));
1524 fRc = False;
1525 break;
1526 if curGuestSession is not None \
1527 and curGuestSession.name != curGuestSessionName:
1528 reporter.error('Test #%d failed: Session name does not match: Got "%s", expected "%s"' \
1529 % (i, curGuestSession.name, curGuestSessionName));
1530 fRc = False;
1531 break;
1532 fRc2 = curTest.closeSession();
1533 if fRc2 is False:
1534 reporter.error('Test #%d failed: Session could not be closed' % (i,));
1535 fRc = False;
1536 break;
1537
1538 if fRc is False:
1539 return (False, oTxsSession);
1540
1541 # Multiple sessions.
1542 iMaxGuestSessions = 31; # Maximum number of concurrent guest session allowed.
1543 # Actually, this is 32, but we don't test session 0.
1544 multiSession = {};
1545 reporter.log2('Opening multiple guest tsessions at once ...');
1546 for i in range(iMaxGuestSessions + 1):
1547 multiSession[i] = tdTestSession(sUser = sUser, sPassword = sPassword, sSessionName = 'MultiSession #%d' % (i,));
1548 multiSession[i].setEnvironment(oSession, oTxsSession, oTestVm);
1549 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
1550 reporter.log2('MultiSession test #%d count is %d' % (i, curSessionCount));
1551 if curSessionCount is not i:
1552 reporter.error('MultiSession count #%d must be %d, got %d' % (i, i, curSessionCount));
1553 fRc = False;
1554 break;
1555 fRc2, _ = multiSession[i].createSession('MultiSession #%d' % (i,));
1556 if fRc2 is not True:
1557 if i < iMaxGuestSessions:
1558 reporter.error('MultiSession #%d test failed' % (i,));
1559 fRc = False;
1560 else:
1561 reporter.log('MultiSession #%d exceeded concurrent guest session count, good' % (i,));
1562 break;
1563
1564 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
1565 if curSessionCount is not iMaxGuestSessions:
1566 reporter.error('Final MultiSession count must be %d, got %d'
1567 % (iMaxGuestSessions, curSessionCount));
1568 return (False, oTxsSession);
1569
1570 reporter.log2('Closing MultiSessions ...');
1571 iLastSession = iMaxGuestSessions - 1;
1572 for i in range(iLastSession): # Close all but the last opened session.
1573 fRc2 = multiSession[i].closeSession();
1574 reporter.log2('MultiSession #%d count is %d' % (i, multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr),));
1575 if fRc2 is False:
1576 reporter.error('Closing MultiSession #%d failed' % (i,));
1577 fRc = False;
1578 break;
1579 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
1580 if curSessionCount is not 1:
1581 reporter.error('Final MultiSession count #2 must be 1, got %d' % (curSessionCount,));
1582 fRc = False;
1583
1584 try:
1585 # r=bird: multiSession[0].oGuestSession is None! Why don't you just use 'assert' or 'if' to check
1586 # the functioning of the __testcase__?
1587
1588 # Make sure that accessing the first opened guest session does not work anymore because we just removed (closed) it.
1589 curSessionName = multiSession[0].oGuestSession.name;
1590 reporter.error('Accessing first removed MultiSession should not be possible, got name="%s"' % (curSessionName,));
1591 fRc = False;
1592 except:
1593 reporter.logXcpt('Could not access first removed MultiSession object, good:');
1594
1595 try:
1596 # Try Accessing last opened session which did not get removed yet.
1597 curSessionName = multiSession[iLastSession].oGuestSession.name;
1598 reporter.log('Accessing last standing MultiSession worked, got name="%s"' % (curSessionName,));
1599 multiSession[iLastSession].closeSession();
1600 curSessionCount = multiSession[i].getSessionCount(self.oTstDrv.oVBoxMgr);
1601 if curSessionCount is not 0:
1602 reporter.error('Final MultiSession count #3 must be 0, got %d' % (curSessionCount,));
1603 fRc = False;
1604 except:
1605 reporter.logXcpt('Could not access last standing MultiSession object:');
1606 fRc = False;
1607
1608 ## @todo Test session timeouts.
1609
1610 return (fRc, oTxsSession);
1611
1612 def testGuestCtrlSessionFileRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
1613 """
1614 Tests the guest session file reference handling.
1615 """
1616
1617 if oTestVm.isWindows():
1618 sUser = "Administrator";
1619 sPassword = "password";
1620 sDomain = "";
1621 sFile = "C:\\windows\\system32\\kernel32.dll";
1622
1623 # Number of stale guest files to create.
1624 cStaleFiles = 10;
1625
1626 fRc = True;
1627 try:
1628 oGuest = oSession.o.console.guest;
1629 oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, \
1630 "testGuestCtrlSessionFileRefs");
1631 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
1632 waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);
1633 #
1634 # Be nice to Guest Additions < 4.3: They don't support session handling and
1635 # therefore return WaitFlagNotSupported.
1636 #
1637 if waitResult != vboxcon.GuestSessionWaitResult_Start \
1638 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
1639 # Just log, don't assume an error here (will be done in the main loop then).
1640 reporter.log('Session did not start successfully, returned wait result: %d' \
1641 % (waitResult));
1642 return (False, oTxsSession);
1643 reporter.log('Session successfully started');
1644
1645 #
1646 # Open guest files and "forget" them (stale entries).
1647 # For them we don't have any references anymore intentionally.
1648 #
1649 reporter.log2('Opening stale files');
1650 for i in range(0, cStaleFiles):
1651 try:
1652 if self.oTstDrv.fpApiVer >= 5.0:
1653 oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly, vboxcon.FileOpenAction_OpenExisting, 0);
1654 else:
1655 oGuestSession.fileOpen(sFile, "r", "oe", 0);
1656 # Note: Use a timeout in the call above for not letting the stale processes
1657 # hanging around forever. This can happen if the installed Guest Additions
1658 # do not support terminating guest processes.
1659 except:
1660 reporter.errorXcpt('Opening stale file #%d failed:' % (i,));
1661 fRc = False;
1662 break;
1663
1664 if fRc:
1665 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
1666 if cFiles != cStaleFiles:
1667 reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles));
1668 fRc = False;
1669
1670 if fRc:
1671 #
1672 # Open non-stale files and close them again.
1673 #
1674 reporter.log2('Opening non-stale files');
1675 aaFiles = [];
1676 for i in range(0, cStaleFiles):
1677 try:
1678 if self.oTstDrv.fpApiVer >= 5.0:
1679 oCurFile = oGuestSession.fileOpen(sFile, vboxcon.FileAccessMode_ReadOnly,
1680 vboxcon.FileOpenAction_OpenExisting, 0);
1681 else:
1682 oCurFile = oGuestSession.fileOpen(sFile, "r", "oe", 0);
1683 aaFiles.append(oCurFile);
1684 except:
1685 reporter.errorXcpt('Opening non-stale file #%d failed:' % (i,));
1686 fRc = False;
1687 break;
1688 if fRc:
1689 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
1690 if cFiles != cStaleFiles * 2:
1691 reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));
1692 fRc = False;
1693 if fRc:
1694 reporter.log2('Closing all non-stale files again ...');
1695 for i in range(0, cStaleFiles):
1696 try:
1697 aaFiles[i].close();
1698 except:
1699 reporter.errorXcpt('Waiting for non-stale file #%d failed:' % (i,));
1700 fRc = False;
1701 break;
1702 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
1703 # Here we count the stale files (that is, files we don't have a reference
1704 # anymore for) and the opened and then closed non-stale files (that we still keep
1705 # a reference in aaFiles[] for).
1706 if cFiles != cStaleFiles:
1707 reporter.error('Test failed: Got %d total files, expected %d' \
1708 % (cFiles, cStaleFiles));
1709 fRc = False;
1710 if fRc:
1711 #
1712 # Check if all (referenced) non-stale files now are in "closed" state.
1713 #
1714 reporter.log2('Checking statuses of all non-stale files ...');
1715 for i in range(0, cStaleFiles):
1716 try:
1717 curFilesStatus = aaFiles[i].status;
1718 if curFilesStatus != vboxcon.FileStatus_Closed:
1719 reporter.error('Test failed: Non-stale file #%d has status %d, expected %d' \
1720 % (i, curFilesStatus, vboxcon.FileStatus_Closed));
1721 fRc = False;
1722 except:
1723 reporter.errorXcpt('Checking status of file #%d failed:' % (i,));
1724 fRc = False;
1725 break;
1726 if fRc:
1727 reporter.log2('All non-stale files closed');
1728 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
1729 reporter.log2('Final guest session file count: %d' % (cFiles,));
1730 # Now try to close the session and see what happens.
1731 reporter.log2('Closing guest session ...');
1732 oGuestSession.close();
1733 except:
1734 reporter.errorXcpt('Testing for stale processes failed:');
1735 fRc = False;
1736
1737 return (fRc, oTxsSession);
1738
1739 #def testGuestCtrlSessionDirRefs(self, oSession, oTxsSession, oTestVm):
1740 # """
1741 # Tests the guest session directory reference handling.
1742 # """
1743
1744 # fRc = True;
1745 # return (fRc, oTxsSession);
1746
1747 def testGuestCtrlSessionProcRefs(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
1748 """
1749 Tests the guest session process reference handling.
1750 """
1751
1752 if oTestVm.isWindows():
1753 sUser = "Administrator";
1754 sPassword = "password";
1755 sDomain = "";
1756 sCmd = "C:\\windows\\system32\\cmd.exe";
1757 aArgs = [sCmd,];
1758
1759 # Number of stale guest processes to create.
1760 cStaleProcs = 10;
1761
1762 fRc = True;
1763 try:
1764 oGuest = oSession.o.console.guest;
1765 oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, \
1766 "testGuestCtrlSessionProcRefs");
1767 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
1768 waitResult = oGuestSession.waitForArray(fWaitFor, 30 * 1000);
1769 #
1770 # Be nice to Guest Additions < 4.3: They don't support session handling and
1771 # therefore return WaitFlagNotSupported.
1772 #
1773 if waitResult != vboxcon.GuestSessionWaitResult_Start \
1774 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
1775 # Just log, don't assume an error here (will be done in the main loop then).
1776 reporter.log('Session did not start successfully, returned wait result: %d' \
1777 % (waitResult));
1778 return (False, oTxsSession);
1779 reporter.log('Session successfully started');
1780
1781 #
1782 # Fire off forever-running processes and "forget" them (stale entries).
1783 # For them we don't have any references anymore intentionally.
1784 #
1785 reporter.log2('Starting stale processes');
1786 for i in range(0, cStaleProcs):
1787 try:
1788 oGuestSession.processCreate(sCmd,
1789 aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:], [],
1790 [ vboxcon.ProcessCreateFlag_WaitForStdOut ], \
1791 30 * 1000);
1792 # Note: Use a timeout in the call above for not letting the stale processes
1793 # hanging around forever. This can happen if the installed Guest Additions
1794 # do not support terminating guest processes.
1795 except:
1796 reporter.logXcpt('Creating stale process #%d failed:' % (i,));
1797 fRc = False;
1798 break;
1799
1800 if fRc:
1801 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
1802 if cProcs != cStaleProcs:
1803 reporter.error('Test failed: Got %d stale processes, expected %d' % (cProcs, cStaleProcs));
1804 fRc = False;
1805
1806 if fRc:
1807 #
1808 # Fire off non-stale processes and wait for termination.
1809 #
1810 if oTestVm.isWindows():
1811 aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows\\system'];
1812 reporter.log2('Starting non-stale processes');
1813 aaProcs = [];
1814 for i in range(0, cStaleProcs):
1815 try:
1816 oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
1817 [], [], 0); # Infinite timeout.
1818 aaProcs.append(oCurProc);
1819 except:
1820 reporter.logXcpt('Creating non-stale process #%d failed:' % (i,));
1821 fRc = False;
1822 break;
1823 if fRc:
1824 reporter.log2('Waiting for non-stale processes to terminate');
1825 for i in range(0, cStaleProcs):
1826 try:
1827 aaProcs[i].waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
1828 curProcStatus = aaProcs[i].status;
1829 if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
1830 reporter.error('Test failed: Waiting for non-stale processes #%d'
1831 ' resulted in status %d, expected %d' \
1832 % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
1833 fRc = False;
1834 except:
1835 reporter.logXcpt('Waiting for non-stale process #%d failed:' % (i,));
1836 fRc = False;
1837 break;
1838 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
1839 # Here we count the stale processes (that is, processes we don't have a reference
1840 # anymore for) and the started + terminated non-stale processes (that we still keep
1841 # a reference in aaProcs[] for).
1842 if cProcs != (cStaleProcs * 2):
1843 reporter.error('Test failed: Got %d total processes, expected %d' \
1844 % (cProcs, cStaleProcs));
1845 fRc = False;
1846 if fRc:
1847 #
1848 # Check if all (referenced) non-stale processes now are in "terminated" state.
1849 #
1850 for i in range(0, cStaleProcs):
1851 curProcStatus = aaProcs[i].status;
1852 if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
1853 reporter.error('Test failed: Non-stale processes #%d has status %d, expected %d' \
1854 % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
1855 fRc = False;
1856 if fRc:
1857 reporter.log2('All non-stale processes terminated');
1858
1859 # Fire off blocking processes which are terminated via terminate().
1860 if oTestVm.isWindows():
1861 aArgs = [ sCmd, '/C', 'dir', '/S', 'C:\\Windows'];
1862 reporter.log2('Starting blocking processes');
1863 aaProcs = [];
1864 for i in range(0, cStaleProcs):
1865 try:
1866 oCurProc = oGuestSession.processCreate(sCmd, aArgs if self.oTstDrv.fpApiVer >= 5.0 else aArgs[1:],
1867 [], [], 30 * 1000);
1868 # Note: Use a timeout in the call above for not letting the stale processes
1869 # hanging around forever. This can happen if the installed Guest Additions
1870 # do not support terminating guest processes.
1871 aaProcs.append(oCurProc);
1872 except:
1873 reporter.logXcpt('Creating blocking process failed:');
1874 fRc = False;
1875 break;
1876 if fRc:
1877 reporter.log2('Terminating blocking processes');
1878 for i in range(0, cStaleProcs):
1879 try:
1880 aaProcs[i].terminate();
1881 except: # Termination might not be supported, just skip and log it.
1882 reporter.logXcpt('Termination of blocking process failed, skipped:');
1883 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
1884 if cProcs != (cStaleProcs * 2): # Still should be 20 processes because we terminated the 10 newest ones.
1885 reporter.error('Test failed: Got %d total processes, expected %d' % (cProcs, cStaleProcs * 2));
1886 fRc = False;
1887 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
1888 reporter.log2('Final guest session processes count: %d' % (cProcs,));
1889 # Now try to close the session and see what happens.
1890 reporter.log2('Closing guest session ...');
1891 oGuestSession.close();
1892 except:
1893 reporter.logXcpt('Testing for stale processes failed:');
1894 fRc = False;
1895
1896 return (fRc, oTxsSession);
1897
1898 def testGuestCtrlExec(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914,R0915
1899 """
1900 Tests the basic execution feature.
1901 """
1902
1903 if oTestVm.isWindows():
1904 sUser = "Administrator";
1905 else:
1906 sUser = "vbox";
1907 sPassword = "password";
1908
1909 if oTestVm.isWindows():
1910 # Outputting stuff.
1911 sImageOut = "C:\\windows\\system32\\cmd.exe";
1912 else:
1913 reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
1914 return (False, oTxsSession);
1915
1916 aaInvalid = [
1917 # Invalid parameters.
1918 [ tdTestExec(sUser = sUser, sPassword = sPassword),
1919 tdTestResultExec(fRc = False) ],
1920 # Non-existent / invalid image.
1921 [ tdTestExec(sCmd = "non-existent", sUser = sUser, sPassword = sPassword),
1922 tdTestResultExec(fRc = False) ],
1923 [ tdTestExec(sCmd = "non-existent2", sUser = sUser, sPassword = sPassword, fWaitForExit = True),
1924 tdTestResultExec(fRc = False) ],
1925 # Use an invalid format string.
1926 [ tdTestExec(sCmd = "%$%%%&", sUser = sUser, sPassword = sPassword),
1927 tdTestResultExec(fRc = False) ],
1928 # More stuff.
1929 [ tdTestExec(sCmd = u"ƒ‰‹ˆ÷‹¸", sUser = sUser, sPassword = sPassword),
1930 tdTestResultExec(fRc = False) ],
1931 [ tdTestExec(sCmd = "???://!!!", sUser = sUser, sPassword = sPassword),
1932 tdTestResultExec(fRc = False) ],
1933 [ tdTestExec(sCmd = "<>!\\", sUser = sUser, sPassword = sPassword),
1934 tdTestResultExec(fRc = False) ]
1935 # Enable as soon as ERROR_BAD_DEVICE is implemented.
1936 #[ tdTestExec(sCmd = "CON", sUser = sUser, sPassword = sPassword),
1937 # tdTestResultExec(fRc = False) ]
1938 ];
1939
1940 if oTestVm.isWindows():
1941 sVBoxControl = "C:\\Program Files\\Oracle\\VirtualBox Guest Additions\\VBoxControl.exe";
1942 aaExec = [
1943 # Basic executon.
1944 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
1945 sUser = sUser, sPassword = sPassword),
1946 tdTestResultExec(fRc = True) ],
1947 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\kernel32.dll' ],
1948 sUser = sUser, sPassword = sPassword),
1949 tdTestResultExec(fRc = True) ],
1950 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32\\nonexist.dll' ],
1951 sUser = sUser, sPassword = sPassword),
1952 tdTestResultExec(fRc = True, iExitCode = 1) ],
1953 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', '/wrongparam' ],
1954 sUser = sUser, sPassword = sPassword),
1955 tdTestResultExec(fRc = True, iExitCode = 1) ],
1956 # Paths with spaces.
1957 ## @todo Get path of installed Guest Additions. Later.
1958 [ tdTestExec(sCmd = sVBoxControl, aArgs = [ sVBoxControl, 'version' ],
1959 sUser = sUser, sPassword = sPassword),
1960 tdTestResultExec(fRc = True) ],
1961 # StdOut.
1962 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
1963 sUser = sUser, sPassword = sPassword),
1964 tdTestResultExec(fRc = True) ],
1965 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdout-non-existing' ],
1966 sUser = sUser, sPassword = sPassword),
1967 tdTestResultExec(fRc = True, iExitCode = 1) ],
1968 # StdErr.
1969 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
1970 sUser = sUser, sPassword = sPassword),
1971 tdTestResultExec(fRc = True) ],
1972 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stderr-non-existing' ],
1973 sUser = sUser, sPassword = sPassword),
1974 tdTestResultExec(fRc = True, iExitCode = 1) ],
1975 # StdOut + StdErr.
1976 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'c:\\windows\\system32' ],
1977 sUser = sUser, sPassword = sPassword),
1978 tdTestResultExec(fRc = True) ],
1979 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir', '/S', 'stdouterr-non-existing' ],
1980 sUser = sUser, sPassword = sPassword),
1981 tdTestResultExec(fRc = True, iExitCode = 1) ]
1982 # FIXME: Failing tests.
1983 # Environment variables.
1984 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_NONEXIST' ],
1985 # sUser = sUser, sPassword = sPassword),
1986 # tdTestResultExec(fRc = True, iExitCode = 1) ]
1987 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'windir' ],
1988 # sUser = sUser, sPassword = sPassword,
1989 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
1990 # tdTestResultExec(fRc = True, sBuf = 'windir=C:\\WINDOWS\r\n') ],
1991 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ],
1992 # sUser = sUser, sPassword = sPassword,
1993 # aEnv = [ 'TEST_FOO=BAR' ],
1994 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
1995 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ],
1996 # [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'set', 'TEST_FOO' ],
1997 # sUser = sUser, sPassword = sPassword,
1998 # aEnv = [ 'TEST_FOO=BAR', 'TEST_BAZ=BAR' ],
1999 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2000 # tdTestResultExec(fRc = True, sBuf = 'TEST_FOO=BAR\r\n') ]
2001
2002 ## @todo Create some files (or get files) we know the output size of to validate output length!
2003 ## @todo Add task which gets killed at some random time while letting the guest output something.
2004 ];
2005
2006 # Manual test, not executed automatically.
2007 aaManual = [
2008 [ tdTestExec(sCmd = sImageOut, aArgs = [ sImageOut, '/C', 'dir /S C:\\Windows' ],
2009 sUser = sUser, sPassword = sPassword,
2010 aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2011 tdTestResultExec(fRc = True, cbStdOut = 497917) ] ];
2012 else:
2013 reporter.log('No OS-specific tests for non-Windows yet!');
2014
2015 # Build up the final test array for the first batch.
2016 aaTests = [];
2017 aaTests.extend(aaInvalid);
2018 if aaExec is not None:
2019 aaTests.extend(aaExec);
2020 fRc = True;
2021
2022 #
2023 # Single execution stuff. Nice for debugging.
2024 #
2025 fManual = False;
2026 if fManual:
2027 curTest = aaTests[1][0]; # tdTestExec, use an index, later.
2028 curRes = aaTests[1][1]; # tdTestResultExec
2029 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2030 fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 1');
2031 if fRc is False:
2032 reporter.error('Single test failed: Could not create session');
2033 else:
2034 fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
2035 curTest.closeSession();
2036
2037 curTest = aaTests[2][0]; # tdTestExec, use an index, later.
2038 curRes = aaTests[2][1]; # tdTestResultExec
2039 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2040 fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 2');
2041 if fRc is False:
2042 reporter.error('Single test failed: Could not create session');
2043 else:
2044 fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
2045 curTest.closeSession();
2046
2047 curTest = aaTests[3][0]; # tdTestExec, use an index, later.
2048 curRes = aaTests[3][1]; # tdTestResultExec
2049 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2050 fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Single test 3');
2051 if fRc is False:
2052 reporter.error('Single test failed: Could not create session');
2053 else:
2054 fRc = self.gctrlExecDoTest(0, curTest, curRes, curGuestSession);
2055 curTest.closeSession();
2056 return (fRc, oTxsSession);
2057 else:
2058 aaManual = aaManual; # Workaround for pylint #W0612.
2059
2060 if fRc is False:
2061 return (fRc, oTxsSession);
2062
2063 #
2064 # First batch: One session per guest process.
2065 #
2066 reporter.log('One session per guest process ...');
2067 for (i, aTest) in enumerate(aaTests):
2068 curTest = aTest[0]; # tdTestExec, use an index, later.
2069 curRes = aTest[1]; # tdTestResultExec
2070 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2071 fRc, curGuestSession = curTest.createSession('testGuestCtrlExec: Test #%d' % (i,));
2072 if fRc is False:
2073 reporter.error('Test #%d failed: Could not create session' % (i,));
2074 break;
2075 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
2076 if fRc is False:
2077 break;
2078 fRc = curTest.closeSession();
2079 if fRc is False:
2080 break;
2081
2082 # No sessions left?
2083 if fRc is True:
2084 aSessions = self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions');
2085 cSessions = len(aSessions);
2086 if cSessions is not 0:
2087 reporter.error('Found %d stale session(s), expected 0:' % (cSessions,));
2088 for (i, aSession) in enumerate(aSessions):
2089 reporter.log('\tStale session #%d ("%s")' % (aSession.id, aSession.name));
2090 fRc = False;
2091
2092 if fRc is False:
2093 return (fRc, oTxsSession);
2094
2095 reporter.log('Now using one guest session for all tests ...');
2096
2097 #
2098 # Second batch: One session for *all* guest processes.
2099 #
2100 oGuest = oSession.o.console.guest;
2101 try:
2102 reporter.log('Creating session for all tests ...');
2103 curGuestSession = oGuest.createSession(sUser, sPassword, '', 'testGuestCtrlExec: One session for all tests');
2104 try:
2105 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
2106 waitResult = curGuestSession.waitForArray(fWaitFor, 30 * 1000);
2107 if waitResult != vboxcon.GuestSessionWaitResult_Start \
2108 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
2109 reporter.error('Session did not start successfully, returned wait result: %d' \
2110 % (waitResult));
2111 return (False, oTxsSession);
2112 reporter.log('Session successfully started');
2113 except:
2114 # Just log, don't assume an error here (will be done in the main loop then).
2115 reporter.logXcpt('Waiting for guest session to start failed:');
2116 return (False, oTxsSession);
2117 # Note: Not waiting for the guest session to start here
2118 # is intentional. This must be handled by the process execution
2119 # call then.
2120 for (i, aTest) in enumerate(aaTests):
2121 curTest = aTest[0]; # tdTestExec, use an index, later.
2122 curRes = aTest[1]; # tdTestResultExec
2123 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2124 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
2125 if fRc is False:
2126 break;
2127 try:
2128 reporter.log2('Closing guest session ...');
2129 curGuestSession.close();
2130 curGuestSession = None;
2131 except:
2132 # Just log, don't assume an error here (will be done in the main loop then).
2133 reporter.logXcpt('Closing guest session failed:');
2134 fRc = False;
2135 except:
2136 reporter.logXcpt('Could not create one session:');
2137
2138 # No sessions left?
2139 if fRc is True:
2140 cSessions = len(self.oTstDrv.oVBoxMgr.getArray(oSession.o.console.guest, 'sessions'));
2141 if cSessions is not 0:
2142 reporter.error('Found %d stale session(s), expected 0' % (cSessions,));
2143 fRc = False;
2144
2145 return (fRc, oTxsSession);
2146
2147 def testGuestCtrlExecErrorLevel(self, oSession, oTxsSession, oTestVm):
2148 """
2149 Tests handling of error levels from started guest processes.
2150 """
2151
2152 if oTestVm.isWindows():
2153 sUser = "Administrator";
2154 else:
2155 sUser = "vbox";
2156 sPassword = "password";
2157
2158 if oTestVm.isWindows():
2159 # Outputting stuff.
2160 sImage = "C:\\windows\\system32\\cmd.exe";
2161 else:
2162 reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
2163 return (False, oTxsSession);
2164
2165 aaTests = [];
2166 if oTestVm.isWindows():
2167 aaTests.extend([
2168 # Simple.
2169 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'wrongcommand' ],
2170 sUser = sUser, sPassword = sPassword),
2171 tdTestResultExec(fRc = True, iExitCode = 1) ],
2172 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'exit', '22' ],
2173 sUser = sUser, sPassword = sPassword),
2174 tdTestResultExec(fRc = True, iExitCode = 22) ],
2175 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=234' ],
2176 sUser = sUser, sPassword = sPassword),
2177 tdTestResultExec(fRc = True, iExitCode = 0) ],
2178 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'echo', '%WINDIR%' ],
2179 sUser = sUser, sPassword = sPassword),
2180 tdTestResultExec(fRc = True, iExitCode = 0) ],
2181 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'set', 'ERRORLEVEL=0' ],
2182 sUser = sUser, sPassword = sPassword),
2183 tdTestResultExec(fRc = True, iExitCode = 0) ],
2184 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
2185 sUser = sUser, sPassword = sPassword),
2186 tdTestResultExec(fRc = True, iExitCode = 0) ],
2187 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32\\kernel32.dll' ],
2188 sUser = sUser, sPassword = sPassword),
2189 tdTestResultExec(fRc = True, iExitCode = 0) ],
2190 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
2191 sUser = sUser, sPassword = sPassword),
2192 tdTestResultExec(fRc = True, iExitCode = 1) ],
2193 [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
2194 sUser = sUser, sPassword = sPassword),
2195 tdTestResultExec(fRc = True, iExitCode = 1) ]
2196 # FIXME: Failing tests.
2197 # With stdout.
2198 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
2199 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
2200 # tdTestResultExec(fRc = True, iExitCode = 0) ],
2201 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
2202 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
2203 # tdTestResultExec(fRc = True, iExitCode = 1) ],
2204 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
2205 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut ]),
2206 # tdTestResultExec(fRc = True, iExitCode = 1) ],
2207 # With stderr.
2208 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
2209 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2210 # tdTestResultExec(fRc = True, iExitCode = 0) ],
2211 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
2212 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2213 # tdTestResultExec(fRc = True, iExitCode = 1) ],
2214 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
2215 # sUser = sUser, sPassword = sPassword, aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2216 # tdTestResultExec(fRc = True, iExitCode = 1) ],
2217 # With stdout/stderr.
2218 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\windows\\system32' ],
2219 # sUser = sUser, sPassword = sPassword,
2220 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2221 # tdTestResultExec(fRc = True, iExitCode = 0) ],
2222 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-file' ],
2223 # sUser = sUser, sPassword = sPassword,
2224 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2225 # tdTestResultExec(fRc = True, iExitCode = 1) ],
2226 # [ tdTestExec(sCmd = sImage, aArgs = [ sImage, '/C', 'dir', 'c:\\nonexisting-dir\\' ],
2227 # sUser = sUser, sPassword = sPassword,
2228 # aFlags = [ vboxcon.ProcessCreateFlag_WaitForStdOut, vboxcon.ProcessCreateFlag_WaitForStdErr ]),
2229 # tdTestResultExec(fRc = True, iExitCode = 1) ]
2230 ## @todo Test stdin!
2231 ]);
2232 else:
2233 reporter.log('No OS-specific tests for non-Windows yet!');
2234
2235 fRc = True;
2236 for (i, aTest) in enumerate(aaTests):
2237 curTest = aTest[0]; # tdTestExec, use an index, later.
2238 curRes = aTest[1]; # tdTestResult
2239 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2240 fRc, curGuestSession = curTest.createSession('testGuestCtrlExecErrorLevel: Test #%d' % (i,));
2241 if fRc is False:
2242 reporter.error('Test #%d failed: Could not create session' % (i,));
2243 break;
2244 fRc = self.gctrlExecDoTest(i, curTest, curRes, curGuestSession);
2245 curTest.closeSession();
2246 if fRc is False:
2247 break;
2248
2249 return (fRc, oTxsSession);
2250
2251 def testGuestCtrlExecTimeout(self, oSession, oTxsSession, oTestVm):
2252 """
2253 Tests handling of timeouts of started guest processes.
2254 """
2255
2256 if oTestVm.isWindows():
2257 sUser = "Administrator";
2258 else:
2259 sUser = "vbox";
2260 sPassword = "password";
2261 sDomain = "";
2262
2263 if oTestVm.isWindows():
2264 # Outputting stuff.
2265 sImage = "C:\\windows\\system32\\cmd.exe";
2266 else:
2267 reporter.error('Implement me!'); ## @todo Implement non-Windows bits.
2268 return (False, oTxsSession);
2269
2270 fRc = True;
2271 try:
2272 oGuest = oSession.o.console.guest;
2273 oGuestSession = oGuest.createSession(sUser, sPassword, sDomain, "testGuestCtrlExecTimeout");
2274 oGuestSession.waitForArray([ vboxcon.GuestSessionWaitForFlag_Start ], 30 * 1000);
2275 # Create a process which never terminates and should timeout when
2276 # waiting for termination.
2277 try:
2278 curProc = oGuestSession.processCreate(sImage, [sImage,] if self.oTstDrv.fpApiVer >= 5.0 else [], \
2279 [], [], 30 * 1000);
2280 reporter.log('Waiting for process 1 being started ...');
2281 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
2282 if waitRes != vboxcon.ProcessWaitResult_Start:
2283 reporter.error('Waiting for process 1 to start failed, got status %d');
2284 fRc = False;
2285 if fRc:
2286 reporter.log('Waiting for process 1 to time out within 1ms ...');
2287 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 1);
2288 if waitRes != vboxcon.ProcessWaitResult_Timeout:
2289 reporter.error('Waiting for process 1 did not time out when it should (1)');
2290 fRc = False;
2291 else:
2292 reporter.log('Waiting for process 1 timed out (1), good');
2293 if fRc:
2294 reporter.log('Waiting for process 1 to time out within 5000ms ...');
2295 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 5000);
2296 if waitRes != vboxcon.ProcessWaitResult_Timeout:
2297 reporter.error('Waiting for process 1 did not time out when it should, got wait result %d' % (waitRes,));
2298 fRc = False;
2299 else:
2300 reporter.log('Waiting for process 1 timed out (5000), good');
2301 ## @todo Add curProc.terminate() as soon as it's implemented.
2302 except:
2303 reporter.errorXcpt('Exception for process 1:');
2304 fRc = False;
2305 # Create a lengthly running guest process which will be killed by VBoxService on the
2306 # guest because it ran out of execution time (5 seconds).
2307 if fRc:
2308 try:
2309 curProc = oGuestSession.processCreate(sImage, [sImage,] if self.oTstDrv.fpApiVer >= 5.0 else [], \
2310 [], [], 5 * 1000);
2311 reporter.log('Waiting for process 2 being started ...');
2312 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
2313 if waitRes != vboxcon.ProcessWaitResult_Start:
2314 reporter.error('Waiting for process 1 to start failed, got status %d');
2315 fRc = False;
2316 if fRc:
2317 reporter.log('Waiting for process 2 to get killed because it ran out of execution time ...');
2318 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
2319 if waitRes != vboxcon.ProcessWaitResult_Timeout:
2320 reporter.error('Waiting for process 2 did not time out when it should, got wait result %d' \
2321 % (waitRes,));
2322 fRc = False;
2323 if fRc:
2324 reporter.log('Waiting for process 2 indicated an error, good');
2325 if curProc.status != vboxcon.ProcessStatus_TimedOutKilled:
2326 reporter.error('Status of process 2 wrong; excepted %d, got %d' \
2327 % (vboxcon.ProcessStatus_TimedOutKilled, curProc.status));
2328 fRc = False;
2329 else:
2330 reporter.log('Status of process 2 correct (%d)' % (vboxcon.ProcessStatus_TimedOutKilled,));
2331 ## @todo Add curProc.terminate() as soon as it's implemented.
2332 except:
2333 reporter.errorXcpt('Exception for process 2:');
2334 fRc = False;
2335 oGuestSession.close();
2336 except:
2337 reporter.errorXcpt('Could not handle session:');
2338 fRc = False;
2339
2340 return (fRc, oTxsSession);
2341
2342 def testGuestCtrlDirCreate(self, oSession, oTxsSession, oTestVm):
2343 """
2344 Tests creation of guest directories.
2345 """
2346
2347 if oTestVm.isWindows():
2348 sUser = "Administrator";
2349 else:
2350 sUser = "vbox";
2351 sPassword = "password";
2352
2353 if oTestVm.isWindows():
2354 sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlDirCreate\\";
2355
2356 aaTests = [];
2357 if oTestVm.isWindows():
2358 aaTests.extend([
2359 # Invalid stuff.
2360 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '' ),
2361 tdTestResult(fRc = False) ],
2362 # More unusual stuff.
2363 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '..\\..\\' ),
2364 tdTestResult(fRc = False) ],
2365 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '../../' ),
2366 tdTestResult(fRc = False) ],
2367 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = 'z:\\' ),
2368 tdTestResult(fRc = False) ],
2369 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = '\\\\uncrulez\\foo' ),
2370 tdTestResult(fRc = False) ],
2371 # Creating directories.
2372 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = sScratch ),
2373 tdTestResult(fRc = False) ],
2374 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'),
2375 aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),
2376 tdTestResult(fRc = True) ],
2377 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword, sDirectory = os.path.join(sScratch, 'foo\\bar\\baz'),
2378 aFlags = [ vboxcon.DirectoryCreateFlag_Parents ] ),
2379 tdTestResult(fRc = True) ],
2380 # Long (+ random) stuff.
2381 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
2382 sDirectory = os.path.join(sScratch,
2383 "".join(random.choice(string.ascii_lowercase) for i in range(32))) ),
2384 tdTestResult(fRc = True) ],
2385 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
2386 sDirectory = os.path.join(sScratch,
2387 "".join(random.choice(string.ascii_lowercase) for i in range(128))) ),
2388 tdTestResult(fRc = True) ],
2389 # Following two should fail on Windows (paths too long). Both should timeout.
2390 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
2391 sDirectory = os.path.join(sScratch,
2392 "".join(random.choice(string.ascii_lowercase) for i in range(255))) ),
2393 tdTestResult(fRc = False) ],
2394 [ tdTestDirCreate(sUser = sUser, sPassword = sPassword,
2395 sDirectory = os.path.join(sScratch,
2396 "".join(random.choice(string.ascii_lowercase) for i in range(1024)))
2397 ),
2398 tdTestResult(fRc = False) ]
2399 ]);
2400 else:
2401 reporter.log('No OS-specific tests for non-Windows yet!');
2402
2403 fRc = True;
2404 for (i, aTest) in enumerate(aaTests):
2405 curTest = aTest[0]; # tdTestExec, use an index, later.
2406 curRes = aTest[1]; # tdTestResult
2407 reporter.log('Testing #%d, sDirectory="%s" ...' % (i, curTest.sDirectory));
2408 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2409 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreate: Test #%d' % (i,));
2410 if fRc is False:
2411 reporter.error('Test #%d failed: Could not create session' % (i,));
2412 break;
2413 fRc = self.gctrlCreateDir(curTest, curRes, curGuestSession);
2414 curTest.closeSession();
2415 if fRc is False:
2416 reporter.error('Test #%d failed' % (i,));
2417 fRc = False;
2418 break;
2419
2420 return (fRc, oTxsSession);
2421
2422 def testGuestCtrlDirCreateTemp(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
2423 """
2424 Tests creation of temporary directories.
2425 """
2426
2427 if oTestVm.isWindows():
2428 sUser = "Administrator";
2429 else:
2430 sUser = "vbox";
2431 sPassword = "password";
2432
2433 # if oTestVm.isWindows():
2434 # sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlDirCreateTemp\\";
2435
2436 aaTests = [];
2437 if oTestVm.isWindows():
2438 aaTests.extend([
2439 # Invalid stuff.
2440 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sDirectory = ''),
2441 tdTestResult(fRc = False) ],
2442 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows',
2443 fMode = 1234),
2444 tdTestResult(fRc = False) ],
2445 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = '',
2446 sDirectory = 'C:\\Windows', fMode = 1234),
2447 tdTestResult(fRc = False) ],
2448 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'xXx',
2449 sDirectory = 'C:\\Windows', fMode = 0o700),
2450 tdTestResult(fRc = False) ],
2451 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'xxx',
2452 sDirectory = 'C:\\Windows', fMode = 0o700),
2453 tdTestResult(fRc = False) ],
2454 # More unusual stuff.
2455 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'foo',
2456 sDirectory = 'z:\\'),
2457 tdTestResult(fRc = False) ],
2458 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'foo',
2459 sDirectory = '\\\\uncrulez\\foo'),
2460 tdTestResult(fRc = False) ],
2461 # Non-existing stuff.
2462 [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'bar',
2463 sDirectory = 'c:\\Apps\\nonexisting\\foo'),
2464 tdTestResult(fRc = False) ],
2465 # FIXME: Failing test. Non Windows path
2466 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'bar',
2467 # sDirectory = '/tmp/non/existing'),
2468 # tdTestResult(fRc = False) ]
2469 ]);
2470 else:
2471 reporter.log('No OS-specific tests for non-Windows yet!');
2472
2473 # FIXME: Failing tests.
2474 # aaTests.extend([
2475 # Non-secure variants.
2476 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2477 # sDirectory = sScratch),
2478 # tdTestResult(fRc = True) ],
2479 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2480 # sDirectory = sScratch),
2481 # tdTestResult(fRc = True) ],
2482 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'X',
2483 # sDirectory = sScratch),
2484 # tdTestResult(fRc = True) ],
2485 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'X',
2486 # sDirectory = sScratch),
2487 # tdTestResult(fRc = True) ],
2488 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2489 # sDirectory = sScratch,
2490 # fMode = 0o700),
2491 # tdTestResult(fRc = True) ],
2492 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2493 # sDirectory = sScratch,
2494 # fMode = 0o700),
2495 # tdTestResult(fRc = True) ],
2496 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2497 # sDirectory = sScratch,
2498 # fMode = 0o755),
2499 # tdTestResult(fRc = True) ],
2500 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2501 # sDirectory = sScratch,
2502 # fMode = 0o755),
2503 # tdTestResult(fRc = True) ],
2504 # Secure variants.
2505 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2506 # sDirectory = sScratch, fSecure = True),
2507 # tdTestResult(fRc = True) ],
2508 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2509 # sDirectory = sScratch, fSecure = True),
2510 # tdTestResult(fRc = True) ],
2511 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2512 # sDirectory = sScratch, fSecure = True),
2513 # tdTestResult(fRc = True) ],
2514 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2515 # sDirectory = sScratch, fSecure = True),
2516 # tdTestResult(fRc = True) ],
2517 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2518 # sDirectory = sScratch,
2519 # fSecure = True, fMode = 0o700),
2520 # tdTestResult(fRc = True) ],
2521 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2522 # sDirectory = sScratch,
2523 # fSecure = True, fMode = 0o700),
2524 # tdTestResult(fRc = True) ],
2525 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2526 # sDirectory = sScratch,
2527 # fSecure = True, fMode = 0o755),
2528 # tdTestResult(fRc = True) ],
2529 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = 'XXX',
2530 # sDirectory = sScratch,
2531 # fSecure = True, fMode = 0o755),
2532 # tdTestResult(fRc = True) ],
2533 # Random stuff.
2534 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword,
2535 # sTemplate = "XXX-".join(random.choice(string.ascii_lowercase) for i in range(32)),
2536 # sDirectory = sScratch,
2537 # fSecure = True, fMode = 0o755),
2538 # tdTestResult(fRc = True) ],
2539 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = "".join('X' for i in range(32)),
2540 # sDirectory = sScratch,
2541 # fSecure = True, fMode = 0o755),
2542 # tdTestResult(fRc = True) ],
2543 # [ tdTestDirCreateTemp(sUser = sUser, sPassword = sPassword, sTemplate = "".join('X' for i in range(128)),
2544 # sDirectory = sScratch,
2545 # fSecure = True, fMode = 0o755),
2546 # tdTestResult(fRc = True) ]
2547 # ]);
2548
2549 fRc = True;
2550 for (i, aTest) in enumerate(aaTests):
2551 curTest = aTest[0]; # tdTestExec, use an index, later.
2552 curRes = aTest[1]; # tdTestResult
2553 reporter.log('Testing #%d, sTemplate="%s", fMode=%#o, path="%s", secure="%s" ...' %
2554 (i, curTest.sTemplate, curTest.fMode, curTest.sDirectory, curTest.fSecure));
2555 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2556 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirCreateTemp: Test #%d' % (i,));
2557 if fRc is False:
2558 reporter.error('Test #%d failed: Could not create session' % (i,));
2559 break;
2560 sDirTemp = "";
2561 try:
2562 sDirTemp = curGuestSession.directoryCreateTemp(curTest.sTemplate, curTest.fMode,
2563 curTest.sDirectory, curTest.fSecure);
2564 except:
2565 if curRes.fRc is True:
2566 reporter.errorXcpt('Creating temp directory "%s" failed:' % (curTest.sDirectory,));
2567 fRc = False;
2568 break;
2569 else:
2570 reporter.logXcpt('Creating temp directory "%s" failed expectedly, skipping:' % (curTest.sDirectory,));
2571 curTest.closeSession();
2572 if sDirTemp != "":
2573 reporter.log2('Temporary directory is: %s' % (sDirTemp,));
2574 if self.oTstDrv.fpApiVer >= 5.0:
2575 fExists = curGuestSession.directoryExists(sDirTemp, False);
2576 else:
2577 fExists = curGuestSession.directoryExists(sDirTemp);
2578 if fExists is False:
2579 reporter.error('Test #%d failed: Temporary directory "%s" does not exists' % (i, sDirTemp));
2580 fRc = False;
2581 break;
2582 return (fRc, oTxsSession);
2583
2584 def testGuestCtrlDirRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
2585 """
2586 Tests opening and reading (enumerating) guest directories.
2587 """
2588
2589 if oTestVm.isWindows():
2590 sUser = "Administrator";
2591 else:
2592 sUser = "vbox";
2593 sPassword = "password";
2594
2595 aaTests = [];
2596 if oTestVm.isWindows():
2597 aaTests.extend([
2598 # Invalid stuff.
2599 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = ''),
2600 tdTestResultDirRead(fRc = False) ],
2601 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows', aFlags = [ 1234 ]),
2602 tdTestResultDirRead(fRc = False) ],
2603 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'C:\\Windows', sFilter = '*.foo'),
2604 tdTestResultDirRead(fRc = False) ],
2605 # More unusual stuff.
2606 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'z:\\'),
2607 tdTestResultDirRead(fRc = False) ],
2608 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = '\\\\uncrulez\\foo'),
2609 tdTestResultDirRead(fRc = False) ],
2610 # Non-existing stuff.
2611 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Apps\\nonexisting'),
2612 tdTestResultDirRead(fRc = False) ],
2613 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Apps\\testDirRead'),
2614 tdTestResultDirRead(fRc = False) ]
2615 ]);
2616
2617 if oTestVm.sVmName == 'tst-xppro':
2618 aaTests.extend([
2619 # Reading directories.
2620 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = '../../Windows/Fonts'),
2621 tdTestResultDirRead(fRc = True, numFiles = 191) ],
2622 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Windows\\Help'),
2623 tdTestResultDirRead(fRc = True, numDirs = 13, numFiles = 569) ],
2624 [ tdTestDirRead(sUser = sUser, sPassword = sPassword, sDirectory = 'c:\\Windows\\Web'),
2625 tdTestResultDirRead(fRc = True, numDirs = 3, numFiles = 55) ]
2626 ]);
2627 else:
2628 reporter.log('No OS-specific tests for non-Windows yet!');
2629
2630 fRc = True;
2631 for (i, aTest) in enumerate(aaTests):
2632 curTest = aTest[0]; # tdTestExec, use an index, later.
2633 curRes = aTest[1]; # tdTestResult
2634 reporter.log('Testing #%d, dir="%s" ...' % (i, curTest.sDirectory));
2635 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2636 fRc, curGuestSession = curTest.createSession('testGuestCtrlDirRead: Test #%d' % (i,));
2637 if fRc is False:
2638 reporter.error('Test #%d failed: Could not create session' % (i,));
2639 break;
2640 (fRc2, cDirs, cFiles) = self.gctrlReadDir(curTest, curRes, curGuestSession);
2641 curTest.closeSession();
2642 reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles));
2643 if fRc2 is curRes.fRc:
2644 if fRc2 is True:
2645 if curRes.numFiles != cFiles:
2646 reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, curRes.numFiles));
2647 fRc = False;
2648 break;
2649 if curRes.numDirs != cDirs:
2650 reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, curRes.numDirs));
2651 fRc = False;
2652 break;
2653 else:
2654 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
2655 fRc = False;
2656 break;
2657
2658 return (fRc, oTxsSession);
2659
2660 def testGuestCtrlFileRemove(self, oSession, oTxsSession, oTestVm):
2661 """
2662 Tests removing guest files.
2663 """
2664
2665 if oTestVm.isWindows():
2666 sUser = "Administrator";
2667 else:
2668 sUser = "vbox";
2669 sPassword = "password";
2670
2671 aaTests = [];
2672 if oTestVm.isWindows():
2673 aaTests.extend([
2674 # Invalid stuff.
2675 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = ''),
2676 tdTestResult(fRc = False) ],
2677 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows'),
2678 tdTestResult(fRc = False) ],
2679 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows'),
2680 tdTestResult(fRc = False) ],
2681 # More unusual stuff.
2682 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'z:\\'),
2683 tdTestResult(fRc = False) ],
2684 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\foo'),
2685 tdTestResult(fRc = False) ],
2686 # Non-existing stuff.
2687 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Apps\\nonexisting'),
2688 tdTestResult(fRc = False) ],
2689 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Apps\\testFileRemove'),
2690 tdTestResult(fRc = False) ],
2691 # Try to delete system files.
2692 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\pagefile.sys'),
2693 tdTestResult(fRc = False) ],
2694 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\kernel32.sys'),
2695 tdTestResult(fRc = False) ]
2696 ]);
2697
2698 if oTestVm.sVmName == 'tst-xppro':
2699 aaTests.extend([
2700 # Try delete some unimportant media stuff.
2701 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chimes.wav'),
2702 tdTestResult(fRc = True) ],
2703 # Second attempt should fail.
2704 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chimes.wav'),
2705 tdTestResult(fRc = False) ],
2706 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chord.wav'),
2707 tdTestResult(fRc = True) ],
2708 [ tdTestFileRemove(sUser = sUser, sPassword = sPassword, sFile = 'c:\\Windows\\Media\\chord.wav'),
2709 tdTestResult(fRc = False) ]
2710 ]);
2711 else:
2712 reporter.log('No OS-specific tests for non-Windows yet!');
2713
2714 fRc = True;
2715 for (i, aTest) in enumerate(aaTests):
2716 curTest = aTest[0]; # tdTestExec, use an index, later.
2717 curRes = aTest[1]; # tdTestResult
2718 reporter.log('Testing #%d, file="%s" ...' % (i, curTest.sFile));
2719 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2720 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRemove: Test #%d' % (i,));
2721 if fRc is False:
2722 reporter.error('Test #%d failed: Could not create session' % (i,));
2723 break;
2724 try:
2725 if self.oTstDrv.fpApiVer >= 5.0:
2726 curGuestSession.fsObjRemove(curTest.sFile);
2727 else:
2728 curGuestSession.fileRemove(curTest.sFile);
2729 except:
2730 if curRes.fRc is True:
2731 reporter.errorXcpt('Removing file "%s" failed:' % (curTest.sFile,));
2732 fRc = False;
2733 break;
2734 else:
2735 reporter.logXcpt('Removing file "%s" failed expectedly, skipping:' % (curTest.sFile,));
2736 curTest.closeSession();
2737 return (fRc, oTxsSession);
2738
2739 def testGuestCtrlFileStat(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
2740 """
2741 Tests querying file information through stat.
2742 """
2743
2744 # Basic stuff, existing stuff.
2745 aoTests = [
2746 tdTestSessionEx([ tdStepStatDir('.'),
2747 tdStepStatDir('..'),
2748 ]),
2749 ];
2750 if oTestVm.isWindows():
2751 aoTests += [ tdTestSessionEx([ tdStepStatDir('C:\\Windows'),
2752 tdStepStatDir('C:\\Windows\\System32'),
2753 tdStepStatDir('C:\\Windows\\System32\\'),
2754 tdStepStatDir('C:\\Windows\\System32\\.'),
2755 tdStepStatDir('C:\\Windows\\System32\\.\\'),
2756 tdStepStatDir('C:\\Windows\\System32\\..'),
2757 tdStepStatDir('C:\\Windows\\System32\\..\\'),
2758 tdStepStatDir('C:\\Windows\\System32\\..\\\\'),
2759 tdStepStatDir('C:\\Windows\\System32\\\\..\\\\'),
2760 tdStepStatDir('C:/Windows/System32'),
2761 tdStepStatDir('C:/Windows/System32/'),
2762 tdStepStatDir('c:/winDowS/sYsTeM32/'),
2763 tdStepStatDir('C:/Windows/System32/.'),
2764 tdStepStatDir('C:/Windows/System32/./'),
2765 tdStepStatDir('C:/Windows/System32/..'),
2766 tdStepStatDir('C:/Windows/System32/../'),
2767 tdStepStatDir('C:/Windows/System32/..//'),
2768 tdStepStatDir('C:/Windows/System32//..//'),
2769 tdStepStatFile('C:\\Windows\\System32\\kernel32.dll'),
2770 tdStepStatFile('C:/Windows/System32/kernel32.dll')
2771 ]) ];
2772 elif oTestVm.isOS2():
2773 aoTests += [ tdTestSessionEx([ tdStepStatDir('C:\\OS2'),
2774 tdStepStatDir('C:\\OS2\\DLL'),
2775 tdStepStatDir('C:\\OS2\\DLL\\'),
2776 tdStepStatDir('C:/OS2/DLL'),
2777 tdStepStatDir('c:/OS2/DLL'),
2778 tdStepStatDir('c:/OS2/DLL/'),
2779 tdStepStatFile('C:\\CONFIG.SYS'),
2780 tdStepStatFile('C:\\OS2\\DLL\\DOSCALL1.DLL'),
2781 ]) ];
2782 else: # generic unix.
2783 aoTests += [ tdTestSessionEx([ tdStepStatDir('/'),
2784 tdStepStatDir('///'),
2785 tdStepStatDir('/usr/bin/.'),
2786 tdStepStatDir('/usr/bin/./'),
2787 tdStepStatDir('/usr/bin/..'),
2788 tdStepStatDir('/usr/bin/../'),
2789 tdStepStatFile('/bin/ls'),
2790 tdStepStatFile('/bin/cp'),
2791 tdStepStatFile('/bin/date'),
2792 ]) ];
2793 # None existing stuff.
2794 if oTestVm.isWindows() or oTestVm.isOS2():
2795 aoTests += [ tdTestSessionEx([ tdStepStatFileNotFound('C:\\NoSuchFileOrDirectory', ),
2796 tdStepStatPathNotFound('C:\\NoSuchDirectory\\'),
2797 tdStepStatPathNotFound('C:/NoSuchDirectory/'),
2798 tdStepStatPathNotFound('C:\\NoSuchDirectory\\.'),
2799 tdStepStatPathNotFound('C:/NoSuchDirectory/.'),
2800 tdStepStatPathNotFound('C:\\NoSuchDirectory\\NoSuchFileOrDirectory'),
2801 tdStepStatPathNotFound('C:/NoSuchDirectory/NoSuchFileOrDirectory'),
2802 tdStepStatPathNotFound('C:/NoSuchDirectory/NoSuchFileOrDirectory/'),
2803 tdStepStatPathNotFound('N:\\'), # ASSUMES nothing mounted on N:!
2804 tdStepStatPathNotFound('\\\\NoSuchUncServerName\\NoSuchShare'),
2805 ]) ];
2806 else: # generic unix.
2807 aoTests += [ tdTestSessionEx([ tdStepStatFileNotFound('/NoSuchFileOrDirectory', ),
2808 tdStepStatFileNotFound('/bin/NoSuchFileOrDirectory'),
2809 tdStepStatPathNotFound('/NoSuchDirectory/'),
2810 tdStepStatPathNotFound('/NoSuchDirectory/.'),
2811 ]) ];
2812 # Invalid parameter check.
2813 aoTests += [ tdTestSessionEx([ tdStepStat('', vbox.ComError.E_INVALIDARG), ]), ];
2814
2815 # Some test VM specific tests.
2816 if oTestVm.sVmName == 'tst-xppro':
2817 aoTests += [ tdTestSessionEx([ tdStepStatFileSize('c:\\Windows\\system32\\kernel32.dll', 926720), ]) ];
2818
2819 #
2820 # Execute the tests.
2821 #
2822 return tdTestSessionEx.executeListTestSessions(aoTests, self.oTstDrv, oSession, oTxsSession, oTestVm, 'FsStat');
2823
2824 def testGuestCtrlFileRead(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
2825 """
2826 Tests reading from guest files.
2827 """
2828
2829 if oTestVm.isWindows():
2830 sUser = "Administrator";
2831 else:
2832 sUser = "vbox";
2833 sPassword = "password";
2834
2835 if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileRead') is False:
2836 reporter.error('Could not create scratch directory on guest');
2837 return (False, oTxsSession);
2838
2839 aaTests = [];
2840 aaTests.extend([
2841 # Invalid stuff.
2842 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, cbToReadWrite = 0),
2843 tdTestResultFileReadWrite(fRc = False) ],
2844 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = ''),
2845 tdTestResultFileReadWrite(fRc = False) ],
2846 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file'),
2847 tdTestResultFileReadWrite(fRc = False) ],
2848 # Wrong open mode.
2849 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
2850 sOpenMode = 'rt', sDisposition = 'oe'),
2851 tdTestResultFileReadWrite(fRc = False) ],
2852 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
2853 sOpenMode = 'tr', sDisposition = 'oe'),
2854 tdTestResultFileReadWrite(fRc = False) ],
2855 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
2856 sOpenMode = 'wr', sDisposition = 'oe'),
2857 tdTestResultFileReadWrite(fRc = False) ],
2858 # Wrong disposition.
2859 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
2860 sOpenMode = 'r', sDisposition = 'e'),
2861 tdTestResultFileReadWrite(fRc = False) ],
2862 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
2863 sOpenMode = 'r', sDisposition = 'o'),
2864 tdTestResultFileReadWrite(fRc = False) ],
2865 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
2866 sOpenMode = 'r', sDisposition = 'c'),
2867 tdTestResultFileReadWrite(fRc = False) ],
2868 # Opening non-existing file when it should exist.
2869 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'non-existing.file', \
2870 sOpenMode = 'r', sDisposition = 'oe'),
2871 tdTestResultFileReadWrite(fRc = False) ],
2872 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '\\\\uncrulez\\non-existing.file', \
2873 sOpenMode = 'r', sDisposition = 'oe'),
2874 tdTestResultFileReadWrite(fRc = False) ],
2875 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = '../../non-existing.file', \
2876 sOpenMode = 'r', sDisposition = 'oe'),
2877 tdTestResultFileReadWrite(fRc = False) ]
2878 ]);
2879
2880 if oTestVm.isWindows():
2881 aaTests.extend([
2882 # Create a file which must not exist (but it hopefully does).
2883 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\calc.exe', \
2884 sOpenMode = 'w', sDisposition = 'ce'),
2885 tdTestResultFileReadWrite(fRc = False) ],
2886 # Open a file which must exist.
2887 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\kernel32.dll', \
2888 sOpenMode = 'r', sDisposition = 'oe'),
2889 tdTestResultFileReadWrite(fRc = True) ],
2890 # Try truncating a file which already is opened with a different sharing mode (and thus should fail).
2891 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\kernel32.dll', \
2892 sOpenMode = 'w', sDisposition = 'ot'),
2893 tdTestResultFileReadWrite(fRc = False) ]
2894 ]);
2895
2896 if oTestVm.sKind == "WindowsXP":
2897 aaTests.extend([
2898 # Reading from beginning.
2899 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\eula.txt', \
2900 sOpenMode = 'r', sDisposition = 'oe', cbToReadWrite = 33),
2901 tdTestResultFileReadWrite(fRc = True, aBuf = 'Microsoft Windows XP Professional', \
2902 cbProcessed = 33, cbOffset = 33) ],
2903 # Reading from offset.
2904 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = 'C:\\Windows\\System32\\eula.txt', \
2905 sOpenMode = 'r', sDisposition = 'oe', cbOffset = 17782, cbToReadWrite = 26),
2906 tdTestResultFileReadWrite(fRc = True, aBuf = 'LINKS TO THIRD PARTY SITES', \
2907 cbProcessed = 26, cbOffset = 17782 + 26) ]
2908 ]);
2909
2910 fRc = True;
2911 for (i, aTest) in enumerate(aaTests):
2912 curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
2913 curRes = aTest[1]; # tdTestResult
2914 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \
2915 (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
2916 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
2917 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileRead: Test #%d' % (i,));
2918 if fRc is False:
2919 reporter.error('Test #%d failed: Could not create session' % (i,));
2920 break;
2921 try:
2922 if curTest.cbOffset > 0: # The offset parameter is gone.
2923 if self.oTstDrv.fpApiVer >= 5.0:
2924 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
2925 curTest.getSharingMode(), curTest.lCreationMode, []);
2926 curFile.seek(curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);
2927 else:
2928 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \
2929 curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);
2930 curOffset = long(curFile.offset);
2931 resOffset = long(curTest.cbOffset);
2932 if curOffset != resOffset:
2933 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \
2934 % (i, curOffset, resOffset));
2935 fRc = False;
2936 else:
2937 if self.oTstDrv.fpApiVer >= 5.0:
2938 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
2939 curTest.lCreationMode);
2940 else:
2941 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition, \
2942 curTest.lCreationMode);
2943 if fRc \
2944 and curTest.cbToReadWrite > 0:
2945 ## @todo Split this up in 64K reads. Later.
2946 ## @todo Test timeouts.
2947 aBufRead = curFile.read(curTest.cbToReadWrite, 30 * 1000);
2948 if curRes.cbProcessed > 0 \
2949 and curRes.cbProcessed is not len(aBufRead):
2950 reporter.error('Test #%d failed: Read buffer length does not match: Got %d, expected %d' \
2951 % (i, len(aBufRead), curRes.cbProcessed));
2952 fRc = False;
2953 if fRc:
2954 if curRes.aBuf is not None \
2955 and bytes(curRes.aBuf) != bytes(aBufRead):
2956 reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)' \
2957 % (i, map(hex, map(ord, aBufRead)), len(aBufRead), \
2958 map(hex, map(ord, curRes.aBuf)), len(curRes.aBuf)));
2959 reporter.error('Test #%d failed: Got buffer\n%s, expected\n%s' \
2960 % (i, aBufRead, curRes.aBuf));
2961 fRc = False;
2962 # Test final offset.
2963 curOffset = long(curFile.offset);
2964 resOffset = long(curRes.cbOffset);
2965 if curOffset != resOffset:
2966 reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \
2967 % (i, curOffset, resOffset));
2968 fRc = False;
2969 curFile.close();
2970 except:
2971 reporter.logXcpt('Opening "%s" failed:' % (curTest.sFile,));
2972 fRc = False;
2973
2974 curTest.closeSession();
2975
2976 if fRc != curRes.fRc:
2977 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
2978 fRc = False;
2979 break;
2980
2981 return (fRc, oTxsSession);
2982
2983 def testGuestCtrlFileWrite(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
2984 """
2985 Tests writing to guest files.
2986 """
2987
2988 if oTestVm.isWindows():
2989 sUser = "Administrator";
2990 else:
2991 sUser = "vbox";
2992 sPassword = "password";
2993
2994 if oTestVm.isWindows():
2995 sScratch = "C:\\Temp\\vboxtest\\testGuestCtrlFileWrite\\";
2996
2997 if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlFileWrite') is False:
2998 reporter.error('Could not create scratch directory on guest');
2999 return (False, oTxsSession);
3000
3001 aaTests = [];
3002
3003 cScratchBuf = 512;
3004 aScratchBuf = array('b', [random.randint(-128, 127) for i in range(cScratchBuf)]);
3005 aaTests.extend([
3006 # Write to a non-existing file.
3007 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = sScratch + 'testGuestCtrlFileWrite.txt', \
3008 sOpenMode = 'w+', sDisposition = 'ce', cbToReadWrite = cScratchBuf,
3009 aBuf = aScratchBuf),
3010 tdTestResultFileReadWrite(fRc = True, aBuf = aScratchBuf, \
3011 cbProcessed = cScratchBuf, cbOffset = cScratchBuf) ]
3012 ]);
3013
3014 aScratchBuf2 = array('b', [random.randint(-128, 127) for i in range(cScratchBuf)]);
3015 aaTests.extend([
3016 # Append the same amount of data to the just created file.
3017 [ tdTestFileReadWrite(sUser = sUser, sPassword = sPassword, sFile = sScratch + 'testGuestCtrlFileWrite.txt', \
3018 sOpenMode = 'w+', sDisposition = 'oa', cbToReadWrite = cScratchBuf,
3019 cbOffset = cScratchBuf, aBuf = aScratchBuf2),
3020 tdTestResultFileReadWrite(fRc = True, aBuf = aScratchBuf2, \
3021 cbProcessed = cScratchBuf, cbOffset = cScratchBuf * 2) ],
3022 ]);
3023
3024 fRc = True;
3025 for (i, aTest) in enumerate(aaTests):
3026 curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
3027 curRes = aTest[1]; # tdTestResult
3028 reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' %
3029 (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
3030 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
3031 fRc, curGuestSession = curTest.createSession('testGuestCtrlFileWrite: Test #%d' % (i,));
3032 if fRc is False:
3033 reporter.error('Test #%d failed: Could not create session' % (i,));
3034 break;
3035
3036 try:
3037 if curTest.cbOffset > 0: # The offset parameter is gone.
3038 if self.oTstDrv.fpApiVer >= 5.0:
3039 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
3040 curTest.getSharingMode(), []);
3041 curFile.seek(curTest.cbOffset, vboxcon.FileSeekOrigin_Begin);
3042 else:
3043 curFile = curGuestSession.fileOpenEx(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,
3044 curTest.sSharingMode, curTest.lCreationMode, curTest.cbOffset);
3045 curOffset = long(curFile.offset);
3046 resOffset = long(curTest.cbOffset);
3047 if curOffset != resOffset:
3048 reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d'
3049 % (i, curOffset, resOffset));
3050 fRc = False;
3051 else:
3052 if self.oTstDrv.fpApiVer >= 5.0:
3053 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.getAccessMode(), curTest.getOpenAction(),
3054 curTest.lCreationMode);
3055 else:
3056 curFile = curGuestSession.fileOpen(curTest.sFile, curTest.sOpenMode, curTest.sDisposition,
3057 curTest.lCreationMode);
3058 if fRc and curTest.cbToReadWrite > 0:
3059 ## @todo Split this up in 64K writes. Later.
3060 ## @todo Test timeouts.
3061 cBytesWritten = curFile.write(curTest.aBuf, 30 * 1000);
3062 if curRes.cbProcessed > 0 \
3063 and curRes.cbProcessed != cBytesWritten:
3064 reporter.error('Test #%d failed: Written buffer length does not match: Got %d, expected %d'
3065 % (i, cBytesWritten, curRes.cbProcessed));
3066 fRc = False;
3067 if fRc:
3068 # Verify written content by seeking back to the initial offset and
3069 # re-read & compare the written data.
3070 try:
3071 if self.oTstDrv.fpApiVer >= 5.0:
3072 curFile.seek(-(curTest.cbToReadWrite), vboxcon.FileSeekOrigin_Current);
3073 else:
3074 curFile.seek(-(curTest.cbToReadWrite), vboxcon.FileSeekType_Current);
3075 except:
3076 reporter.logXcpt('Seeking back to initial write position failed:');
3077 fRc = False;
3078 if fRc and long(curFile.offset) != curTest.cbOffset:
3079 reporter.error('Test #%d failed: Initial write position does not match current position, '
3080 'got %d, expected %d' % (i, long(curFile.offset), curTest.cbOffset));
3081 fRc = False;
3082 if fRc:
3083 aBufRead = curFile.read(curTest.cbToReadWrite, 30 * 1000);
3084 if len(aBufRead) != curTest.cbToReadWrite:
3085 reporter.error('Test #%d failed: Got buffer length %d, expected %d'
3086 % (i, len(aBufRead), curTest.cbToReadWrite));
3087 fRc = False;
3088 if fRc \
3089 and curRes.aBuf is not None \
3090 and curRes.aBuf != aBufRead:
3091 reporter.error('Test #%d failed: Got buffer\n%s, expected\n%s'
3092 % (i, aBufRead, curRes.aBuf));
3093 fRc = False;
3094 # Test final offset.
3095 curOffset = long(curFile.offset);
3096 resOffset = long(curRes.cbOffset);
3097 if curOffset != resOffset:
3098 reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d'
3099 % (i, curOffset, resOffset));
3100 fRc = False;
3101 curFile.close();
3102 except:
3103 reporter.logXcpt('Opening "%s" failed:' % (curTest.sFile,));
3104 fRc = False;
3105
3106 curTest.closeSession();
3107
3108 if fRc != curRes.fRc:
3109 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
3110 fRc = False;
3111 break;
3112
3113 return (fRc, oTxsSession);
3114
3115 def testGuestCtrlCopyTo(self, oSession, oTxsSession, oTestVm):
3116 """
3117 Tests copying files from host to the guest.
3118 """
3119
3120 if oTestVm.isWindows():
3121 sUser = "Administrator";
3122 sScratchGst = "C:\\Temp\\vboxtest\\testGuestCtrlCopyTo/";
3123 sScratchGstNotExist = "C:\\does-not-exist\\";
3124 sScratchGstInvalid = "[]?:";
3125 else:
3126 sUser = "vbox";
3127 sScratchGst = "/tmp/testGuestCtrlCopyTo/";
3128 sScratchGstNotExist = "/tmp/does-not-exist/";
3129 sScratchGstInvalid = "/";
3130 sPassword = "password";
3131
3132 if oTxsSession.syncMkDir('${SCRATCH}/testGuestCtrlCopyTo') is False:
3133 reporter.error('Could not create scratch directory on guest');
3134 return (False, oTxsSession);
3135
3136 # Some stupid trickery to guess the location of the iso.
3137 sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
3138 if not os.path.isfile(sVBoxValidationKitISO):
3139 sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
3140 if not os.path.isfile(sVBoxValidationKitISO):
3141 sCur = os.getcwd();
3142 for i in range(0, 10):
3143 sVBoxValidationKitISO = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
3144 if os.path.isfile(sVBoxValidationKitISO):
3145 break;
3146 sVBoxValidationKitISO = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
3147 if os.path.isfile(sVBoxValidationKitISO):
3148 break;
3149 sCur = os.path.abspath(os.path.join(sCur, '..'));
3150 if i is None: pass; # shut up pychecker/pylint.
3151 if os.path.isfile(sVBoxValidationKitISO):
3152 reporter.log('Validation Kit .ISO found at: %s' % (sVBoxValidationKitISO,));
3153 else:
3154 reporter.log('Warning: Validation Kit .ISO not found -- some tests might fail');
3155
3156 aaTests = [];
3157 if oTestVm.isWindows():
3158 aaTests.extend([
3159 # Destination missing.
3160 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = ''),
3161 tdTestResult(fRc = False) ],
3162 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows',
3163 aFlags = [ 80 ] ),
3164 tdTestResult(fRc = False) ],
3165 # Source missing.
3166 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sDst = ''),
3167 tdTestResult(fRc = False) ],
3168 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sDst = 'C:\\Windows',
3169 aFlags = [ 80 ] ),
3170 tdTestResult(fRc = False) ],
3171 # Testing DirectoryCopyFlag flags.
3172 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3173 sDst = sScratchGstInvalid, aFlags = [ 80 ] ),
3174 tdTestResult(fRc = False) ],
3175 # Testing FileCopyFlag flags.
3176 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3177 sDst = sScratchGstInvalid, aFlags = [ 80 ] ),
3178 tdTestResult(fRc = False) ],
3179 # Nothing to copy (source and/or destination is empty).
3180 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'z:\\'),
3181 tdTestResult(fRc = False) ],
3182 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = '\\\\uncrulez\\foo'),
3183 tdTestResult(fRc = False) ],
3184 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'non-exist',
3185 sDst = os.path.join(sScratchGst, 'non-exist.dll')),
3186 tdTestResult(fRc = False) ]
3187 ]);
3188
3189 #
3190 # Single file handling.
3191 #
3192 if self.oTstDrv.fpApiVer > 5.2:
3193 aaTests.extend([
3194 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3195 sDst = sScratchGstInvalid),
3196 tdTestResult(fRc = False) ],
3197 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3198 sDst = sScratchGstNotExist),
3199 tdTestResult(fRc = False) ],
3200 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3201 sDst = sScratchGstNotExist),
3202 tdTestResult(fRc = False) ],
3203 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3204 sDst = os.path.join(sScratchGstNotExist, 'renamedfile.dll')),
3205 tdTestResult(fRc = False) ],
3206 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3207 sDst = os.path.join(sScratchGst, 'HostGuestAdditions.iso')),
3208 tdTestResult(fRc = True) ],
3209 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3210 sDst = os.path.join(sScratchGst, 'HostGuestAdditions.iso')),
3211 tdTestResult(fRc = True) ],
3212 # Note: Copying files into directories via Main is supported only in versions > 5.2.
3213 # Destination is a directory.
3214 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3215 sDst = sScratchGst),
3216 tdTestResult(fRc = True) ],
3217 # Copy over file again into same directory (overwrite).
3218 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO,
3219 sDst = sScratchGst),
3220 tdTestResult(fRc = True) ]
3221 ]);
3222
3223 #
3224 # Directory handling.
3225 #
3226 if self.oTstDrv.fpApiVer > 5.2: # Copying directories via Main is supported only in versions > 5.2.
3227 if self.oTstDrv.sHost == "win":
3228 aaTests.extend([
3229 # Copying directories with contain files we don't have read access to.
3230 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\security',
3231 sDst = sScratchGst),
3232 tdTestResult(fRc = False) ],
3233 # Copying directories with regular files.
3234 [ tdTestCopyTo(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Help',
3235 sDst = sScratchGst),
3236 tdTestResult(fRc = True) ]
3237 ]);
3238 else:
3239 reporter.log('No OS-specific tests for non-Windows yet!');
3240
3241 fRc = True;
3242 for (i, aTest) in enumerate(aaTests):
3243 curTest = aTest[0]; # tdTestExec, use an index, later.
3244 curRes = aTest[1]; # tdTestResult
3245 reporter.log('Testing #%d, sSrc="%s", sDst="%s", aFlags="%s" ...' % \
3246 (i, curTest.sSrc, curTest.sDst, curTest.aFlags));
3247 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
3248 fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyTo: Test #%d' % (i,));
3249 if fRc is False:
3250 reporter.error('Test #%d failed: Could not create session' % (i,));
3251 break;
3252
3253 fRc2 = False;
3254 if os.path.isdir(curTest.sSrc):
3255 try:
3256 curProgress = curGuestSession.directoryCopyToGuest(curTest.sSrc, curTest.sDst, curTest.aFlags);
3257 if curProgress is not None:
3258 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \
3259 "gctrlDirCopyTo");
3260 try:
3261 oProgress.wait();
3262 if not oProgress.isSuccess():
3263 oProgress.logResult(fIgnoreErrors = True);
3264 fRc = False;
3265 except:
3266 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
3267 fRc2 = False;
3268 else:
3269 reporter.error('No progress object returned');
3270 fRc2 = False;
3271 except:
3272 fRc2 = False;
3273 else:
3274 fRc2 = self.gctrlCopyFileTo(curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags);
3275
3276 curTest.closeSession();
3277
3278 if fRc2 is curRes.fRc:
3279 ## @todo Verify the copied results (size, checksum?).
3280 pass;
3281 else:
3282 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
3283 fRc = False;
3284 break;
3285
3286 return (fRc, oTxsSession);
3287
3288 def testGuestCtrlCopyFrom(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
3289 """
3290 Tests copying files from guest to the host.
3291 """
3292
3293 if oTestVm.isWindows():
3294 sUser = "Administrator";
3295 else:
3296 sUser = "vbox";
3297 sPassword = "password";
3298
3299 if self.oTstDrv.sHost == "win":
3300 sScratchHstInvalid = "[]?:";
3301 else:
3302 sScratchHstInvalid = "/";
3303
3304 sScratchHst = os.path.join(self.oTstDrv.sScratchPath, "testGctrlCopyFrom");
3305 try:
3306 os.makedirs(sScratchHst);
3307 except OSError as e:
3308 if e.errno != errno.EEXIST:
3309 reporter.error('Failed: Unable to create scratch directory \"%s\"' % (sScratchHst,));
3310 return (False, oTxsSession);
3311 reporter.log('Scratch path is: %s' % (sScratchHst,));
3312
3313 aaTests = [];
3314 if oTestVm.isWindows():
3315 aaTests.extend([
3316 # Destination missing.
3317 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = ''),
3318 tdTestResult(fRc = False) ],
3319 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'Something',
3320 aFlags = [ 80 ] ),
3321 tdTestResult(fRc = False) ],
3322 # Source missing.
3323 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sDst = ''),
3324 tdTestResult(fRc = False) ],
3325 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sDst = 'Something',
3326 aFlags = [ 80 ] ),
3327 tdTestResult(fRc = False) ],
3328 # Testing DirectoryCopyFlag flags.
3329 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32',
3330 sDst = sScratchHstInvalid, aFlags = [ 80 ] ),
3331 tdTestResult(fRc = False) ],
3332 # Testing FileCopyFlag flags.
3333 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3334 sDst = sScratchHstInvalid, aFlags = [ 80 ] ),
3335 tdTestResult(fRc = False) ],
3336 # Nothing to copy (sDst is empty / unreachable).
3337 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'z:\\'),
3338 tdTestResult(fRc = False) ],
3339 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = '\\\\uncrulez\\foo'),
3340 tdTestResult(fRc = False) ],
3341 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'non-exist',
3342 sDst = os.path.join(sScratchHst, 'non-exist.dll')),
3343 tdTestResult(fRc = False) ]
3344 ]);
3345
3346 #
3347 # Single file handling.
3348 #
3349 if self.oTstDrv.fpApiVer > 5.2:
3350 aaTests.extend([
3351 # Copying single files.
3352 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3353 sDst = sScratchHstInvalid),
3354 tdTestResult(fRc = False) ],
3355 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3356 sDst = os.path.join(sScratchHstInvalid, 'renamedfile.dll')),
3357 tdTestResult(fRc = False) ],
3358 # Copy over file using a different destination name.
3359 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3360 sDst = os.path.join(sScratchHst, 'renamedfile.dll')),
3361 tdTestResult(fRc = True) ],
3362 # Copy over same file (and overwrite existing one).
3363 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3364 sDst = os.path.join(sScratchHst, 'renamedfile.dll')),
3365 tdTestResult(fRc = True) ],
3366 # Note: Copying files into directories via Main is supported only in versions > 5.2.
3367 # Destination is a directory with a trailing slash (should work).
3368 # See "cp" syntax.
3369 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3370 sDst = sScratchHst + "/"),
3371 tdTestResult(fRc = True) ],
3372 # Destination is a directory (without a trailing slash, should also work).
3373 # See "cp" syntax.
3374 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3375 sDst = sScratchHst),
3376 tdTestResult(fRc = True) ],
3377 # Destination is a non-existing directory.
3378 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\system32\\ole32.dll',
3379 sDst = sScratchHst + "/non-existing-directory/"),
3380 tdTestResult(fRc = False) ]
3381 ]);
3382
3383 #
3384 # Directory handling.
3385 #
3386 if self.oTstDrv.fpApiVer > 5.2: # Copying directories via Main is supported only in versions > 5.2.
3387 aaTests.extend([
3388 # Copying entire directories (destination is "<sScratch>", which exists, which should fail).
3389 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
3390 sDst = sScratchHst),
3391 tdTestResult(fRc = False) ],
3392 # Ditto, with trailing slash.
3393 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
3394 sDst = sScratchHst + "/"),
3395 tdTestResult(fRc = False) ],
3396 # Next try with the DirectoryCopyFlag_CopyIntoExisting flag being set.
3397 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
3398 sDst = sScratchHst, aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
3399 tdTestResult(fRc = True) ],
3400 # Ditto, with trailing slash.
3401 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web',
3402 sDst = sScratchHst + "/", aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
3403 tdTestResult(fRc = True) ],
3404 # Copying contents of directories into a non-existing directory chain on the host which fail.
3405 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
3406 sDst = sScratchHst + "/not/existing/",
3407 aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
3408 tdTestResult(fRc = False) ],
3409 # Copying contents of directories into a non-existing directory on the host, which should succeed.
3410 [ tdTestCopyFrom(sUser = sUser, sPassword = sPassword, sSrc = 'C:\\Windows\\Web\\',
3411 sDst = sScratchHst + "/no-existing/",
3412 aFlags = [ vboxcon.DirectoryCopyFlag_CopyIntoExisting ]),
3413 tdTestResult(fRc = True) ]
3414 ]);
3415 else:
3416 reporter.log('No OS-specific tests for non-Windows yet!');
3417
3418 fRc = True;
3419 for (i, aTest) in enumerate(aaTests):
3420 curTest = aTest[0]; # tdTestExec, use an index, later.
3421 curRes = aTest[1]; # tdTestResult
3422 reporter.log('Testing #%d, sSrc="%s", sDst="%s", aFlags="%s" ...' % \
3423 (i, curTest.sSrc, curTest.sDst, curTest.aFlags));
3424 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
3425 fRc, curGuestSession = curTest.createSession('testGuestCtrlCopyFrom: Test #%d' % (i,));
3426 if fRc is False:
3427 reporter.error('Test #%d failed: Could not create session' % (i,));
3428 break;
3429
3430 fRc2 = True;
3431
3432 try:
3433 if self.oTstDrv.fpApiVer >= 5.0:
3434 oFsInfo = curGuestSession.fsObjQueryInfo(curTest.sSrc, True); # fFollowSymlinks
3435 else:
3436 oFsInfo = curGuestSession.fileQueryInfo(curTest.sSrc);
3437
3438 if oFsInfo.type is vboxcon.FsObjType_Directory:
3439 curProgress = curGuestSession.directoryCopyFromGuest(curTest.sSrc, curTest.sDst, curTest.aFlags);
3440 if curProgress is not None:
3441 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, \
3442 "gctrlDirCopyFrom");
3443 try:
3444 oProgress.wait();
3445 if not oProgress.isSuccess():
3446 oProgress.logResult(fIgnoreErrors = True);
3447 fRc2 = False;
3448 except:
3449 reporter.logXcpt('Waiting exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
3450 fRc2 = False;
3451 else:
3452 reporter.error('No progress object returned');
3453 fRc2 = False;
3454 elif oFsInfo.type is vboxcon.FsObjType_File:
3455 fRc2 = self.gctrlCopyFileFrom(curGuestSession, curTest.sSrc, curTest.sDst, curTest.aFlags);
3456 else:
3457 reporter.log2('Element "%s" not handled (yet), skipping' % oFsInfo.name);
3458
3459 except:
3460 reporter.logXcpt('Query information exception for sSrc="%s", sDst="%s":' % (curTest.sSrc, curTest.sDst));
3461 fRc2 = False;
3462
3463 curTest.closeSession();
3464 if fRc2 is curRes.fRc:
3465 ## @todo Verify the copied results (size, checksum?).
3466 pass;
3467 else:
3468 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc2, curRes.fRc));
3469 fRc = False;
3470 break;
3471
3472 return (fRc, oTxsSession);
3473
3474 def testGuestCtrlUpdateAdditions(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914
3475 """
3476 Tests updating the Guest Additions inside the guest.
3477 """
3478
3479 if oTestVm.isWindows():
3480 sUser = "Administrator";
3481 else:
3482 sUser = "vbox";
3483 sPassword = "password";
3484
3485 # Some stupid trickery to guess the location of the iso.
3486 sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
3487 if not os.path.isfile(sVBoxValidationKitISO):
3488 sVBoxValidationKitISO = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
3489 if not os.path.isfile(sVBoxValidationKitISO):
3490 sCur = os.getcwd();
3491 for i in range(0, 10):
3492 sVBoxValidationKitISO = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
3493 if os.path.isfile(sVBoxValidationKitISO):
3494 break;
3495 sVBoxValidationKitISO = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
3496 if os.path.isfile(sVBoxValidationKitISO):
3497 break;
3498 sCur = os.path.abspath(os.path.join(sCur, '..'));
3499 if i is None: pass; # shut up pychecker/pylint.
3500 if os.path.isfile(sVBoxValidationKitISO):
3501 reporter.log('Validation Kit .ISO found at: %s' % (sVBoxValidationKitISO,));
3502 else:
3503 reporter.log('Warning: Validation Kit .ISO not found -- some tests might fail');
3504
3505 sScratch = os.path.join(self.oTstDrv.sScratchPath, "testGctrlUpdateAdditions");
3506 try:
3507 os.makedirs(sScratch);
3508 except OSError as e:
3509 if e.errno != errno.EEXIST:
3510 reporter.error('Failed: Unable to create scratch directory \"%s\"' % (sScratch,));
3511 return (False, oTxsSession);
3512 reporter.log('Scratch path is: %s' % (sScratch,));
3513
3514 aaTests = [];
3515 if oTestVm.isWindows():
3516 aaTests.extend([
3517 # Source is missing.
3518 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = ''),
3519 tdTestResult(fRc = False) ],
3520 # Wrong aFlags.
3521 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso(),
3522 aFlags = [ 1234 ]),
3523 tdTestResult(fRc = False) ],
3524 # Non-existing .ISO.
3525 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = "non-existing.iso"),
3526 tdTestResult(fRc = False) ],
3527 # Wrong .ISO.
3528 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = sVBoxValidationKitISO),
3529 tdTestResult(fRc = False) ],
3530 # The real thing.
3531 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso()),
3532 tdTestResult(fRc = True) ],
3533 # Test the (optional) installer arguments. This will extract the
3534 # installer into our guest's scratch directory.
3535 [ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword, sSrc = self.oTstDrv.getGuestAdditionsIso(),
3536 aArgs = [ '/extract', '/D=' + sScratch ]),
3537 tdTestResult(fRc = True) ]
3538 # Some debg ISO. Only enable locally.
3539 #[ tdTestUpdateAdditions(sUser = sUser, sPassword = sPassword,
3540 # sSrc = "V:\\Downloads\\VBoxGuestAdditions-r80354.iso"),
3541 # tdTestResult(fRc = True) ]
3542 ]);
3543 else:
3544 reporter.log('No OS-specific tests for non-Windows yet!');
3545
3546 fRc = True;
3547 for (i, aTest) in enumerate(aaTests):
3548 curTest = aTest[0]; # tdTestExec, use an index, later.
3549 curRes = aTest[1]; # tdTestResult
3550 reporter.log('Testing #%d, sSrc="%s", aFlags="%s" ...' % \
3551 (i, curTest.sSrc, curTest.aFlags));
3552 curTest.setEnvironment(oSession, oTxsSession, oTestVm);
3553 fRc, _ = curTest.createSession('Test #%d' % (i,));
3554 if fRc is False:
3555 reporter.error('Test #%d failed: Could not create session' % (i,));
3556 break;
3557 try:
3558 curProgress = curTest.oTest.oGuest.updateGuestAdditions(curTest.sSrc, curTest.aArgs, curTest.aFlags);
3559 if curProgress is not None:
3560 oProgress = vboxwrappers.ProgressWrapper(curProgress, self.oTstDrv.oVBoxMgr, self.oTstDrv, "gctrlUpGA");
3561 try:
3562 oProgress.wait();
3563 if not oProgress.isSuccess():
3564 oProgress.logResult(fIgnoreErrors = True);
3565 fRc = False;
3566 except:
3567 reporter.logXcpt('Waiting exception for updating Guest Additions:');
3568 fRc = False;
3569 else:
3570 reporter.error('No progress object returned');
3571 fRc = False;
3572 except:
3573 # Just log, don't assume an error here (will be done in the main loop then).
3574 reporter.logXcpt('Updating Guest Additions exception for sSrc="%s", aFlags="%s":' \
3575 % (curTest.sSrc, curTest.aFlags));
3576 fRc = False;
3577 curTest.closeSession();
3578 if fRc is curRes.fRc:
3579 if fRc:
3580 ## @todo Verify if Guest Additions were really updated (build, revision, ...).
3581 pass;
3582 else:
3583 reporter.error('Test #%d failed: Got %s, expected %s' % (i, fRc, curRes.fRc));
3584 fRc = False;
3585 break;
3586
3587 return (fRc, oTxsSession);
3588
3589
3590
3591class tdAddGuestCtrl(vbox.TestDriver): # pylint: disable=R0902,R0904
3592 """
3593 Guest control using VBoxService on the guest.
3594 """
3595
3596 def __init__(self):
3597 vbox.TestDriver.__init__(self);
3598 self.oTestVmSet = self.oTestVmManager.getStandardVmSet('nat');
3599 self.fQuick = False; # Don't skip lengthly tests by default.
3600 self.addSubTestDriver(SubTstDrvAddGuestCtrl(self));
3601
3602 #
3603 # Overridden methods.
3604 #
3605 def showUsage(self):
3606 """
3607 Shows the testdriver usage.
3608 """
3609 rc = vbox.TestDriver.showUsage(self);
3610 reporter.log('');
3611 reporter.log('tdAddGuestCtrl Options:');
3612 reporter.log(' --quick');
3613 reporter.log(' Same as --virt-modes hwvirt --cpu-counts 1.');
3614 return rc;
3615
3616 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
3617 """
3618 Parses the testdriver arguments from the command line.
3619 """
3620 if asArgs[iArg] == '--quick':
3621 self.parseOption(['--virt-modes', 'hwvirt'], 0);
3622 self.parseOption(['--cpu-counts', '1'], 0);
3623 self.fQuick = True;
3624 else:
3625 return vbox.TestDriver.parseOption(self, asArgs, iArg);
3626 return iArg + 1;
3627
3628 def actionConfig(self):
3629 if not self.importVBoxApi(): # So we can use the constant below.
3630 return False;
3631
3632 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT;
3633 sGaIso = self.getGuestAdditionsIso();
3634 return self.oTestVmSet.actionConfig(self, eNic0AttachType = eNic0AttachType, sDvdImage = sGaIso);
3635
3636 def actionExecute(self):
3637 return self.oTestVmSet.actionExecute(self, self.testOneCfg);
3638
3639 #
3640 # Test execution helpers.
3641 #
3642 def testOneCfg(self, oVM, oTestVm): # pylint: disable=R0915
3643 """
3644 Runs the specified VM thru the tests.
3645
3646 Returns a success indicator on the general test execution. This is not
3647 the actual test result.
3648 """
3649
3650 self.logVmInfo(oVM);
3651
3652 fRc = True;
3653 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(oTestVm.sVmName, fCdWait = False);
3654 reporter.log("TxsSession: %s" % (oTxsSession,));
3655 if oSession is not None:
3656 self.addTask(oTxsSession);
3657
3658 fManual = False; # Manual override for local testing. (Committed version shall be False.)
3659 if not fManual:
3660 fRc, oTxsSession = self.aoSubTstDrvs[0].testIt(oTestVm, oSession, oTxsSession);
3661 else:
3662 fRc, oTxsSession = self.testGuestCtrlManual(oSession, oTxsSession, oTestVm);
3663
3664 # Cleanup.
3665 self.removeTask(oTxsSession);
3666 if not fManual:
3667 self.terminateVmBySession(oSession);
3668 else:
3669 fRc = False;
3670 return fRc;
3671
3672 def gctrlReportError(self, progress):
3673 """
3674 Helper function to report an error of a
3675 given progress object.
3676 """
3677 if progress is None:
3678 reporter.log('No progress object to print error for');
3679 else:
3680 errInfo = progress.errorInfo;
3681 if errInfo:
3682 reporter.log('%s' % (errInfo.text,));
3683 return False;
3684
3685 def gctrlGetRemainingTime(self, msTimeout, msStart):
3686 """
3687 Helper function to return the remaining time (in ms)
3688 based from a timeout value and the start time (both in ms).
3689 """
3690 if msTimeout is 0:
3691 return 0xFFFFFFFE; # Wait forever.
3692 msElapsed = base.timestampMilli() - msStart;
3693 if msElapsed > msTimeout:
3694 return 0; # No time left.
3695 return msTimeout - msElapsed;
3696
3697 def testGuestCtrlManual(self, oSession, oTxsSession, oTestVm): # pylint: disable=R0914,R0915,W0613,W0612
3698 """
3699 For manually testing certain bits.
3700 """
3701
3702 reporter.log('Manual testing ...');
3703 fRc = True;
3704
3705 sUser = 'Administrator';
3706 sPassword = 'password';
3707
3708 oGuest = oSession.o.console.guest;
3709 oGuestSession = oGuest.createSession(sUser,
3710 sPassword,
3711 "", "Manual Test");
3712
3713 aWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
3714 _ = oGuestSession.waitForArray(aWaitFor, 30 * 1000);
3715
3716 sCmd = 'c:\\windows\\system32\\cmd.exe';
3717 aArgs = [ sCmd, '/C', 'dir', '/S', 'c:\\windows' ];
3718 aEnv = [];
3719 aFlags = [];
3720
3721 for _ in range(100):
3722 oProc = oGuestSession.processCreate(sCmd, aArgs if self.fpApiVer >= 5.0 else aArgs[1:],
3723 aEnv, aFlags, 30 * 1000);
3724
3725 aWaitFor = [ vboxcon.ProcessWaitForFlag_Terminate ];
3726 _ = oProc.waitForArray(aWaitFor, 30 * 1000);
3727
3728 oGuestSession.close();
3729 oGuestSession = None;
3730
3731 time.sleep(5);
3732
3733 oSession.o.console.PowerDown();
3734
3735 return (fRc, oTxsSession);
3736
3737if __name__ == '__main__':
3738 sys.exit(tdAddGuestCtrl().main(sys.argv));
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