def runTestClass(test_class): """Execute one test class. This will create a TestRunner, execute one test run with one test class. Args: test_class: The test class to instantiate and execute. Returns: The TestResult object that holds the results of the test run. """ test_cls_name = test_class.__name__ if len(sys.argv) < 2: logging.warning("Missing a configuration file. Using the default.") test_configs = [config_parser.GetDefaultConfig(test_cls_name)] else: try: config_path = sys.argv[1] baseline_config = config_parser.GetDefaultConfig(test_cls_name) baseline_config[keys.ConfigKeys.KEY_TESTBED] = [ baseline_config[keys.ConfigKeys.KEY_TESTBED] ] test_configs = config_parser.load_test_config_file( config_path, baseline_config=baseline_config) except IndexError: logging.error("No valid config file found.") sys.exit(1) except Exception as e: logging.error("Unexpected exception") logging.exception(e) test_identifiers = [(test_cls_name, None)] for config in test_configs: def watchStdin(): while True: line = sys.stdin.readline() if not line: break utils.stop_current_process(base_test.TIMEOUT_SECS_TEARDOWN_CLASS) watcher_thread = threading.Thread(target=watchStdin, name="watchStdin") watcher_thread.daemon = True watcher_thread.start() tr = TestRunner(config, test_identifiers) tr.parseTestConfig(config) try: tr.runTestClass(test_class, None) except (signals.TestAbortAll, KeyboardInterrupt) as e: logging.error("Abort all test") except Exception as e: logging.error("Unexpected exception") logging.exception(e) finally: tr.stop() return tr.results
def runTestClass(test_class): """Execute one test class. This will create a TestRunner, execute one test run with one test class. Args: test_class: The test class to instantiate and execute. Returns: The TestResult object that holds the results of the test run. """ test_cls_name = test_class.__name__ if len(sys.argv) < 2: logging.warning("Missing a configuration file. Using the default.") test_configs = [config_parser.GetDefaultConfig(test_cls_name)] else: try: config_path = sys.argv[1] baseline_config = config_parser.GetDefaultConfig(test_cls_name) baseline_config[keys.ConfigKeys.KEY_TESTBED] = [ baseline_config[keys.ConfigKeys.KEY_TESTBED] ] test_configs = config_parser.load_test_config_file( config_path, baseline_config=baseline_config) except IndexError: logging.error("No valid config file found.") sys.exit(1) test_identifiers = [(test_cls_name, None)] for config in test_configs: if keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT in config: timeout_sec = int( config[keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT]) / 1000.0 else: timeout_sec = 60 * 60 * 3 logging.warning("%s unspecified. Set timeout to %s seconds.", keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT, timeout_sec) # The default SIGINT handler sends KeyboardInterrupt to main thread. # On Windows, raising CTRL_C_EVENT, which is received as SIGINT, # has no effect on non-console process. interrupt_main() works but # does not unblock main thread's IO immediately. timeout_func = (raiseSigint if not utils.is_on_windows() else thread.interrupt_main) sig_timer = threading.Timer(timeout_sec, timeout_func) tr = TestRunner(config, test_identifiers) tr.parseTestConfig(config) try: sig_timer.start() tr.runTestClass(test_class, None) except KeyboardInterrupt as e: logging.exception("Aborted by timeout or ctrl+C: %s", e) finally: sig_timer.cancel() tr.stop() return tr.results
def runTestClass(test_class): """Execute one test class. This will create a TestRunner, execute one test run with one test class. Args: test_class: The test class to instantiate and execute. Returns: The TestResult object that holds the results of the test run. """ test_cls_name = test_class.__name__ if len(sys.argv) < 2: logging.warning("Missing a configuration file. Using the default.") test_configs = [config_parser.GetDefaultConfig(test_cls_name)] else: try: config_path = sys.argv[1] baseline_config = config_parser.GetDefaultConfig(test_cls_name) baseline_config[keys.ConfigKeys.KEY_TESTBED] = [ baseline_config[keys.ConfigKeys.KEY_TESTBED] ] test_configs = config_parser.load_test_config_file( config_path, baseline_config=baseline_config) except IndexError: logging.error("No valid config file found.") sys.exit(1) test_identifiers = [(test_cls_name, None)] for config in test_configs: tr = TestRunner(config, test_identifiers) tr.parseTestConfig(config) try: # Create console signal handler to make sure TestRunner is stopped # in the event of termination. handler = config_parser.gen_term_signal_handler([tr]) signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGINT, handler) tr.runTestClass(test_class, None) finally: tr.stop() return tr.results
def GetTestModuleNames(): '''Returns a list of mobly test module specified in test configuration.''' configs = config_parser.load_test_config_file(sys.argv[1]) reduce_func = lambda x, y: x + y.get(keys.ConfigKeys.MOBLY_TEST_MODULE, []) return reduce(reduce_func, configs, [])
def runTestClass(test_class): """Execute one test class. This will create a TestRunner, execute one test run with one test class. Args: test_class: The test class to instantiate and execute. Returns: The TestResult object that holds the results of the test run. """ test_cls_name = test_class.__name__ if len(sys.argv) < 2: logging.warning("Missing a configuration file. Using the default.") test_configs = [config_parser.GetDefaultConfig(test_cls_name)] else: try: config_path = sys.argv[1] baseline_config = config_parser.GetDefaultConfig(test_cls_name) baseline_config[keys.ConfigKeys.KEY_TESTBED] = [ baseline_config[keys.ConfigKeys.KEY_TESTBED] ] test_configs = config_parser.load_test_config_file( config_path, baseline_config=baseline_config) except IndexError: logging.error("No valid config file found.") sys.exit(1) except Exception as e: logging.error("Unexpected exception") logging.exception(e) test_identifiers = [(test_cls_name, None)] for config in test_configs: if keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT in config: timeout_sec = int( config[keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT]) / 1000.0 else: timeout_sec = 60 * 60 * 3 logging.warning("%s unspecified. Set timeout to %s seconds.", keys.ConfigKeys.KEY_TEST_MAX_TIMEOUT, timeout_sec) watcher_enabled = threading.Event() def watchStdin(): while True: line = sys.stdin.readline() if not line: break watcher_enabled.wait() logging.info("Attempt to interrupt runner thread.") if not utils.is_on_windows(): # Default SIGINT handler sends KeyboardInterrupt to main thread # and unblocks it. os.kill(os.getpid(), signal.SIGINT) else: # On Windows, raising CTRL_C_EVENT, which is received as # SIGINT, has no effect on non-console process. # interrupt_main() behaves like SIGINT but does not unblock # main thread immediately. thread.interrupt_main() watcher_thread = threading.Thread(target=watchStdin, name="watchStdin") watcher_thread.daemon = True watcher_thread.start() tr = TestRunner(config, test_identifiers) tr.parseTestConfig(config) try: watcher_enabled.set() tr.runTestClass(test_class, None) except KeyboardInterrupt as e: logging.exception("Aborted") except Exception as e: logging.error("Unexpected exception") logging.exception(e) finally: watcher_enabled.clear() tr.stop() return tr.results