# -*- coding: utf-8 -*-
# $Id$
"""
VirtualBox Validation Kit - Unit Tests.
"""
__copyright__ = \
"""
Copyright (C) 2010-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard Python imports.
import os
import sys
import re
import subprocess
import shutil
# Only the main script needs to modify the path.
try: __file__
# Validation Kit imports.
"""
Unit Tests.
"""
## The temporary exclude list.
## @note This shall be empty before we release 4.3!
'darwin': {
},
'solaris': {
'testcase/tstIntNet-1': '', # Fails opening rge0, probably a generic issue figuring which nic to use.
},
'win': {
'tscpasswd': '', # ??
'tstVMREQ': '', # ?? Same as darwin.x86?
}
};
kdTestCasesBuggy = {
};
## The permanent exclude list.
# @note Stripped extensions!
'testcase/tstClipboardX11Smoke': '',
'testcase/tstFileLock': '',
'testcase/tstFileAppendWin-1': '',
'testcase/tstGlobalConfig': '',
'tstAnimate': '', # parameters required
'tstAPI': '', # user interaction required
'tstCollector': '', # takes forever
'tstHeadless': '', # parameters required
'tstMicroRC': '', # required by tstMicro
'tstVBoxDbg': '', # interactive test
'tstTestServMgr': '', # some strange xpcom18a4 test, does not work
'tstPDMAsyncCompletion': '', # parameters required
'tstXptDump': '', # parameters required
'tstnsIFileEnumerator': '', # some strange xpcom18a4 test, does not work
'tstSimpleTypeLib': '', # parameters required
'tstXptLink': '', # parameters required
'tstXPCOMCGlue': '', # user interaction required
'tstTestCallTemplates': '', # some strange xpcom18a4 test, segfaults
# later
# slow stuff
# failed or hang
'tstOVF': '', # hang (only ancient version, now in new place)
'testcase/tstGuestControlSvc': '', # failed: line 288: testHost(&svcTable): expected VINF_SUCCESS, got VERR_NOT_FOUND
'testcase/tstCryptoPkcs7Sign': '',# failed: 29330:error:02001002:lib(2):func(1):reason(2):NA:0:fopen('server.pem': '','r')
# for 'RTZipBlock/LZJB' (#4): VERR_NOT_SUPPORTED
'testcase/tstLdr-4': '', # failed: Failed to get bits for '/home/vbox/test/tmp/bin/testcase/tstLdrObjR0.r0'/0,
# rc=VERR_SYMBOL_VALUE_TOO_BIG. aborting test
'tstPDMAsyncCompletionStress': '', # VERR_INVALID_PARAMETER (cbSize = 0)
'tstMicro': '', # doesn't work on solaris, fix later if we care.
'tstVMM-HwAccm': '', # failed: Only checked AMD-V on linux
'tstVMM-HM': '', # failed: Only checked AMD-V on linux
'tstVMMFork': '', # failed: xtracker 6171
'tstTestFactory': '', # some strange xpcom18a4 test, does not work
'testcase/tstRTSemXRoads': '', # sporadically failed: Traffic - 8 threads per direction, 10 sec : FAILED (8 errors)
'tstVBoxAPILinux': '', # creates VirtualBox directories for root user because of sudo (should be in vbox)
'tstVMStructRC': '', # This is a C-code generator.
'tstDeviceStructSizeRC': '', # This is a C-code generator.
};
# Suffix exclude list.
'.r0',
'.gc',
'.debug',
'.rel',
'.sys',
'.ko',
'.o',
'.obj',
'.lib',
'.a',
'.so',
'.dll',
'.dylib',
'.tmp',
'.log',
'.py',
'.pyc',
'.pyo',
'.pdb',
'.dSYM',
'.sym',
];
## The exclude list.
# @note Stripped extensions!
kasHardened = [
"testcase/tstR0ThreadPreemptionDriver", # VBox 4.3
"tstInt",
"tstVMM",
"tstVMMFork",
"tstVMREQ",
]
## Argument lists
kdArguments = {
};
## Status code translations.
## @{
kdExitCodeNames = {
0: 'RTEXITCODE_SUCCESS',
1: 'RTEXITCODE_FAILURE',
2: 'RTEXITCODE_SYNTAX',
3: 'RTEXITCODE_INIT',
4: 'RTEXITCODE_SKIPPED',
};
-1073741515: 'STATUS_DLL_NOT_FOUND',
-1073741512: 'STATUS_ORDINAL_NOT_FOUND',
-1073741511: 'STATUS_ENTRYPOINT_NOT_FOUND',
-1073741502: 'STATUS_DLL_INIT_FAILED',
-1073741500: 'STATUS_UNHANDLED_EXCEPTION',
-1073741499: 'STATUS_APP_INIT_FAILURE',
-1073741819: 'STATUS_ACCESS_VIOLATION',
-1073741571: 'STATUS_STACK_OVERFLOW',
};
## @}
"""
Reinitialize child class instance.
"""
self.oTestVmSet = None;
self.sVBoxInstallRoot = None
self.sUnitTestsPathBase = None
# For testing testcase logic.
"""
Internal worker for actionVerify and actionExecute that detects paths.
"""
#
# We need a VBox install (/ build) to test.
#
if False:
if not self.importVBoxApi():
return False
else:
self._detectBuild();
return False;
#
# Where are the files installed?
# Solaris requires special handling because of it's multi arch subdirs.
#
# Add the installation root to the PATH on windows so we can get DLLs from it.
sPathName = 'PATH';
sPathName = 'Path';
sPath += ';';
#
# The unittests are generally not installed, so look for them.
#
asCandidates = [
];
for sCandidat in asCandidates:
return True;
return False;
#
# Overridden methods.
#
return self._detectPaths();
return False;
#
# Test execution helpers.
#
""" Tries to figure which VBox version this is, setting self.aiVBoxVer. """
try:
except:
return False;
return True;
"""
Compares the give version string with the vbox version string,
returning a result similar to C strcmp(). aiVer is on the right side.
"""
for i in range(cComponents):
return -1;
return 1;
""" Checks if the testcase is excluded or not. """
if sFullExpr == '':
return True;
# Consider each exclusion expression. These are generally ranges,
# either open ended or closed: "<4.3.51r12345", ">=4.3.0 && <=4.3.4".
# Split it on the and operator and process each sub expression.
# Split out the comparison operator and the version value.
else:
# Convert the version value, making sure we've got a valid one.
except: aiValue = ();
reporter.error('Invalid exclusion expression for %s: "%s" [%s]' % (sTest, sSubExpr, dExclList[sTest]));
return True;
# Do the compare.
# Did the expression match?
if fResult:
return True;
return False;
"""
Executes a sudo child process synchronously.
Returns True if the process executed successfully and returned 0,
otherwise False is returned.
"""
try:
except:
return False;
return iRc is 0;
"""
Creates the directory specified sPath (including parents).
"""
else:
return True;
"""
Copies a file.
"""
else:
return True;
"""
Deletes a file.
"""
else:
return True;
"""
Removes a directory.
"""
else:
return True;
"""
Executes a test case.
"""
#
# If hardening is enabled, some test cases and their dependencies
# needs to be copied to and execute from the sVBoxInstallRoot
# directory in order to work. They also have to be executed as
# root, i.e. via sudo.
#
asFilesToRemove = []; # Stuff to clean up.
asDirsToRemove = []; # Ditto.
# Copy any associated .dll/.so/.dylib.
# Copy any associated .r0, .rc and .gc modules.
if offDriver > 0:
#
# Set up arguments and environment.
#
#
# Execute the test case.
#
# Windows is confusing output. Trying a few things to get rid of this.
# First, flush both stderr and stdout before running the child. Second,
# assign the child stderr to stdout. If this doesn't help, we'll have
# to capture the child output.
#
except: pass;
except: pass;
try:
if fHardened:
oChild = utils.sudoProcessPopen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);
else:
except:
]:
else:
iRc = 1023;
oChild = None;
if oChild is not None:
else:
iRc = 0;
#
# Clean up
#
for sPath in asFilesToRemove:
for sPath in asDirsToRemove:
#
# Report.
#
if fHardened:
else:
if iRc == 0:
elif fSkipped:
else:
if sName != '':
if iRc != 1:
else:
return fSkipped;
"""
Run subset of the unit tests set.
"""
try:
except:
oDevNull = None;
# Determin the host OS specific exclusion lists.
#
# Process the file list and run everything looking like a testcase.
#
# Separate base and suffix and morph the base into something we
# can use for reporting and array lookups.
if sTestCaseSubDir != '.':
# Basic exclusion.
continue
# Check if the testcase is black listed or buggy before executing it.
else:
sFullPath = os.path.normpath(os.path.join(self.sUnitTestsPathBase, os.path.join(sTestCaseSubDir, sFilename)));
try:
except:
if __name__ == '__main__':