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