コード例 #1
0
 def testFunction(tests):
     parentPath = paths.parentSecureExePath
     altParentPath = paths.parentBuildPath
     buildArgs = make.getBuildArgs(testArgs = testArgs)
     result = tests.parentBuildInstall(buildArgs)
     builtParentCorrectly = result == InitCode.parentInitSuccess
     testIndex = 0
     while testIndex < testCount:
         runExpected = (testIndex % 2) == 0
         requireExpected = (testIndex // 2 % 2) == 0
         requireSecure = (testIndex // 4 % 2 ) == 0
         testIndex += 1
         execPath = parentPath if runExpected else altParentPath
         description = ('Correct' if runExpected else 'Incorrect') \
                       + ' path, path checks ' \
                       + ('enabled,' if requireExpected else 'disabled,') \
                       + ' path security checks ' \
                       + ('enabled.' if requireSecure else 'disabled.')
         expectedResult = ExitCode.success
         if requireExpected and not runExpected:
             expectedResult = ExitCode.badParentPath
         elif requireSecure and not runExpected:
             expectedResult = ExitCode.insecureParentDir
         if builtParentCorrectly:
             pathTarget = parentPath if requireExpected else None
             daemonArgs = make.getBuildArgs(parentPath = pathTarget, \
                                            secureParent = requireSecure, \
                                            testArgs = testArgs)
             result = tests.daemonBuildInstall(daemonArgs)
             if result == InitCode.daemonInitSuccess:
                result = tests.execTest(execPath)
         tests.checkResult(Result(result, expectedResult), description)
コード例 #2
0
 def testFunction(tests):
     daemonPath = paths.daemonSecureExePath
     altDaemonPath = paths.daemonBuildPath
     testIndex = 0
     while testIndex < testCount:
         runExpected = (testIndex % 2) == 0
         requireExpected = (testIndex // 2 % 2) == 0
         requireSecure = (testIndex // 4 % 2) == 0
         testIndex += 1
         description = ('Correct' if runExpected else 'Incorrect') \
                        + ' path, path checking ' \
                        + ('enabled,' if requireExpected else 'disabled,') \
                        + ' path security checks ' \
                        + ('enabled.' if requireSecure else 'disabled.')
         targetPath = daemonPath if runExpected else altDaemonPath
         parentArgs = make.getBuildArgs(testArgs = testArgs, \
                                        securePath = requireSecure, \
                                        daemonPath = targetPath)
         result = tests.parentBuildInstall(parentArgs)
         expectedResult = ExitCode.success
         if requireExpected and not runExpected:
             expectedResult = ExitCode.badDaemonPath
         elif requireSecure and not runExpected:
             expectedResult = ExitCode.insecureDaemonDir
         if result == InitCode.parentInitSuccess:
             daemonArgs = make.getBuildArgs(checkPath = requireExpected, \
                                            securePath = requireSecure, \
                                            testArgs = testArgs)
             result = tests.daemonBuildInstall(daemonArgs)
             if result == InitCode.daemonInitSuccess:
                 result = tests.execTest(paths.parentSecureExePath)
         tests.checkResult(Result(result, expectedResult), description)
コード例 #3
0
 def testFailedBuild(enableIn, enableOut):
     inPath = paths.inPipePath if enableIn else None
     outPath = paths.outPipePath if enableOut else None
     buildArgs = make.getBuildArgs(testArgs = testArgs, \
                                   lockPath = None, \
                                   inPipePath = inPath, \
                                   outPipePath = outPath)
     resultCode = tests.daemonBuildInstall(buildArgs)
     description = 'Checking that builds fail with the ' \
                 + 'DF_LOCK_FILE_PATH undefined, input pipe ' \
                 + ('enabled' if enableIn else 'disabled') \
                 + ', output pipe ' \
                 + ('enabled.' if enableOut else 'disabled.')
     tests.checkResult(Result(resultCode, InitCode.daemonBuildFailure), \
                       description)
コード例 #4
0
    def testFunction(tests):
        """ 
        Test that daemon builds fail with pipes enabled and no lock file:
        Keyword Arguments:
        enableIn  -- Whether the daemon is built with the input pipe enabled.
        enableOut -- Whether the daemon is built with the output pipe enabled.
        """
        def testFailedBuild(enableIn, enableOut):
            inPath = paths.inPipePath if enableIn else None
            outPath = paths.outPipePath if enableOut else None
            buildArgs = make.getBuildArgs(testArgs = testArgs, \
                                          lockPath = None, \
                                          inPipePath = inPath, \
                                          outPipePath = outPath)
            resultCode = tests.daemonBuildInstall(buildArgs)
            description = 'Checking that builds fail with the ' \
                        + 'DF_LOCK_FILE_PATH undefined, input pipe ' \
                        + ('enabled' if enableIn else 'disabled') \
                        + ', output pipe ' \
                        + ('enabled.' if enableOut else 'disabled.')
            tests.checkResult(Result(resultCode, InitCode.daemonBuildFailure), \
                              description)

        testFailedBuild(True, False)
        testFailedBuild(False, True)
        testFailedBuild(True, True)

        # Build parent with standard options:
        buildArgs = make.getBuildArgs(testArgs=testArgs)
        parentBuildResult = tests.parentBuildInstall(buildArgs)
        """
        Test if the BasicParent runs as expected.
        Keyword Arguments:
        description    -- The description to print with the test results.
        buildResult    -- The result code obtained by running testBuild.
                          If this is a failed test result, the test execution
                          will be cancelled and the test will use this as its
                          result code.
        expectedResult -- The expected result of the test.
        """

        def testRun(description, buildResult, expectedResult):
            parentRunArgs = ['--timeout', '1']
            resultCode = buildResult
            if buildResult == InitCode.daemonInitSuccess:
                resultCode = tests.execTest(paths.parentSecureExePath, \
                                            parentRunArgs)
            tests.checkResult(Result(resultCode, expectedResult), description)

        # Build/install the daemon as long as the parent was built and
        # installed correctly:
        daemonBuildResult = parentBuildResult
        if parentBuildResult == InitCode.parentInitSuccess:
            buildArgs = make.getBuildArgs(timeout = 0, \
                                          debugBuild = testArgs.debugBuild,\
                                          verbose = testArgs.useVerbose)
            daemonBuildResult = tests.daemonBuildInstall(buildArgs)

        # Test launching the background parent/daemon processes:
        bgProcess = None
        bgLaunchResult = daemonBuildResult
        if daemonBuildResult == InitCode.daemonInitSuccess:
            bgProcess = subprocess.Popen(paths.parentSecureExePath, \
                                         stdout = subprocess.DEVNULL)
            bgProcess.poll()
            if bgProcess.returncode is None:
                bgLaunchResult = InitCode.daemonRunSuccess
            elif bgProcess.returncode < 0:
                print('Background daemon process exited with signal ' \
                      + str(resultCode * -1))
            else:
                bgLaunchResult = ExitCode(bgProcess.returncode)
        description = 'Testing background daemon launch.'
        tests.checkResult(Result(bgLaunchResult, \
                          InitCode.daemonRunSuccess), description)

        # Test execution while the background processes are running:
        description = 'Testing execution with another instance already running.'
        expected = ExitCode.daemonAlreadyRunning
        testRun(description, daemonBuildResult, expected)

        # Test execution after killing background processes:
        if bgProcess is not None:
            bgProcess.kill()
            bgProcess.wait()
            if bgProcess.returncode is None:
                print('Error: Failed to kill background daemon process.')
        description = 'Testing execution after closing other daemon process.'
        testRun(description, daemonBuildResult, ExitCode.success)
コード例 #5
0
 def testFunction(testObject):
     parentPath = paths.parentSecureExePath
     makeArgs = make.getBuildArgs(testArgs=testArgs)
     result = testObject.fullTest(makeArgs, parentPath)
     testObject.checkResult(result, 'Basic build/install/run test')
コード例 #6
0
#!/usr/bin/python
"""Runs all DaemonFramework tests."""

from testModules import basicBuild, daemonPathChecking, parentPathChecking, \
                        singleRunningDaemon
from supportModules import testArgs, make, pathConstants
import sys, subprocess

args = testArgs.read()
if (args.printHelp):
    testArgs.printHelp('TestAll.py', 'Runs all DaemonFramework tests.')

print("Building and running unit tests:")
if make.buildUnitTests(make.getBuildArgs(testArgs=args), None):
    process = subprocess.run(pathConstants.paths.unitTestBuildPath)
    if process.returncode != 0 and args.exitOnFailure:
        sys.exit(process.returncode)
else:
    print("Failed to build unit tests!")
    if args.exitOnFailure:
        sys.exit(1)

print("Running python tests:")
testModules = [basicBuild, daemonPathChecking, parentPathChecking, \
               singleRunningDaemon]
testObjects = []
testCount = 0
testsPassed = 0
for testModule in testModules:
    testObject = testModule.getTests(args)
    testCount += testObject.testCount