def main(): global test_count # Warned about skipped tests # @note : doesn't warn if you use '-t a b c ...' to run specific tests if args.skip: for skip in args.skip: print_skipped(skip, "marked skipped on command line") test_categories = ["integration", "examples", "unit", "stress"] if args.tests: test_categories = [x for x in test_categories if x in args.tests or x == "integration"] if args.skip: test_categories = [x for x in test_categories if not x in args.skip] integration = integration_tests() if "integration" in test_categories else 0 stress = stress_test() if "stress" in test_categories else 0 unit = unit_tests() if "unit" in test_categories else 0 examples = examples_working() if "examples" in test_categories else 0 status = max(integration, stress, unit, examples) if (not test_count): print "No tests selected" exit(0) if (status == 0): print pretty.SUCCESS(str(test_count - status) + " / " + str(test_count) + " tests passed, exiting with code 0") else: print pretty.FAIL(str(status) + " / " + str(test_count) + " tests failed ") sys.exit(status)
def exit(self, status, msg, keep_running=False): # Exit may have been called allready if self._exit_complete: return self._exit_status = status self._exit_msg = msg self.stop() # Change back to test source os.chdir(self._root) info("Exit called with status", self._exit_status, "(", get_exit_code_name(self._exit_status), ")") info("Message:", msg, "Keep running: ", keep_running) if keep_running: return if self._on_exit: info("Calling on_exit") self._on_exit() if status == 0: if self._on_exit_success: info("Calling on_exit_success") self._on_exit_success() print color.SUCCESS(msg) self._exit_complete = True return self._exit_complete = True program_exit(status, msg)
def boot(self, timeout = None, multiboot = True, kernel_args = "booted with vmrunner"): # Check for sudo access, needed for tap network devices and the KVM module if os.getuid() is not 0: print color.FAIL("Call the script with sudo access") sys.exit(1) # Start the timeout thread if (timeout): self._timer = threading.Timer(timeout, self._on_timeout) self._timer.start() # Boot via hypervisor try: self._hyper.boot(multiboot, kernel_args + "/" + self._hyper.name()) except Exception as err: print color.WARNING("Exception raised while booting ") if (timeout): self._timer.cancel() raise err # Start analyzing output while self._hyper.poll() == None and not self._exit_status: line = self._hyper.readline() print color.SUBPROC("<VM> "+line.rstrip()) # Look for event-triggers for pattern, func in self._on_output.iteritems(): if re.search(pattern, line): try: res = func() except Exception as err: print color.WARNING("Exception raised in event callback: ") print_exception() res = False self.stop().wait() #NOTE: It can be 'None' without problem if res == False: self._exit_status = exit_codes["OUTSIDE_FAIL"] self.exit(self._exit_status, color.FAIL(nametag + " VM-external test failed")) # Now we either have an exit status from timer thread, or an exit status # from the subprocess, or the VM was powered off by the external test. # If the process didn't exit we need to stop it. if (self.poll() == None): self.stop() self.wait() if self._exit_status: print color.WARNING(nametag + "Found non-zero exit status but process didn't end. ") print color.FAIL(nametag + "Tests failed or program error") print color.INFO(nametag),"Done running VM. Exit status: ", self._exit_status sys.exit(self._exit_status) else: print color.SUCCESS(nametag + " VM exited with 0 exit status.") print color.INFO(nametag), "Subprocess finished. Exiting with ", self._hyper.poll() sys.exit(self._hyper.poll()) raise Exception("Unexpected termination")
def main(): # Find leaf nodes leaves = find_leaf_nodes() # Populate test objects all_tests = [Test(path) for path in leaves] # Figure out which tests are to be run test_categories_to_run = [] test_types_to_run = [] if args.tests: for argument in args.tests: if argument in test_categories and argument not in args.skip: test_categories_to_run.append(argument) elif argument in test_types and argument not in args.skip: test_types_to_run.append(argument) else: print 'Test specified is not recognised, exiting' sys.exit(1) else: test_types_to_run = test_types if test_categories_to_run: # This means that a specific category has been requested specific_tests = [ test for test in all_tests if test.category_ in test_categories_to_run ] # Print which tests are skipped print_skipped(specific_tests) # Run the tests integration = integration_tests(specific_tests) else: # Print which tests are skipped print_skipped(all_tests) # Run the tests integration = integration_tests( all_tests) if "integration" in test_types_to_run else 0 stress = stress_test() if "stress" in test_types_to_run else 0 unit = unit_tests() if "unit" in test_types_to_run else 0 examples = examples_working() if "examples" in test_types_to_run else 0 status = max(integration, stress, unit, examples) if (status == 0): print pretty.SUCCESS( str(test_count - status) + " / " + str(test_count) + " tests passed, exiting with code 0") else: print pretty.FAIL( str(status) + " / " + str(test_count) + " tests failed ") sys.exit(status)
def check_exit(line, n="0"): global T T += 1 print "Python received: ", line status = line.split(" ")[-1].lstrip().rstrip() as_expected = status == n print "Exit status is ", status, "as expected" if as_expected else "expected " + n if as_expected: vm.exit(0, color.SUCCESS("Test " + str(T) + "/" + str(N) + " passed")) else: return as_expected
def __init__(self, config, hyper = qemu): self._exit_status = 0 self._config = config self._on_success = lambda : self.exit(exit_codes["SUCCESS"], color.SUCCESS(nametag + " All tests passed")) self._on_panic = lambda : self.exit(exit_codes["VM_FAIL"], color.FAIL(nametag + self._hyper.readline())) self._on_timeout = lambda : self.exit(exit_codes["TIMEOUT"], color.FAIL(nametag + " Test timed out")) self._on_output = { "PANIC" : self._on_panic, "SUCCESS" : self._on_success } assert(issubclass(hyper, hypervisor)) self._hyper = hyper(config) self._timer = None self._on_exit_success = lambda : None self._on_exit = lambda : None
def program_exit(status, msg): global vms info("Program exit called with status", status, "(",get_exit_code_name(status),")") info("Stopping all vms") for vm in vms: vm.stop().wait() # Print status message and exit with appropriate code if (status): print color.EXIT_ERROR(get_exit_code_name(status), msg) else: print color.SUCCESS(msg) sys.exit(status)
def exit(self, status, msg): self._exit_status = status self.stop() print color.INFO(nametag),"Exit called with status", self._exit_status, "(",get_exit_code_name(self._exit_status),")" print color.INFO(nametag),"Calling on_exit" # Change back to test source os.chdir(self._root) self._on_exit() if status == 0: # Print success message and return to caller print color.SUCCESS(msg) print color.INFO(nametag),"Calling on_exit_success" return self._on_exit_success() # Print fail message and exit with appropriate code print color.EXIT_ERROR(get_exit_code_name(status), msg) sys.exit(status)