def test_simple(self): with WebPlatformTestServer(binding_address=self.GetBindingAddress()): target_params = [] filters = self.cobalt_config.GetWebPlatformTestFilters() if test_filter.DISABLE_TESTING in filters: return if test_filter.FILTER_ALL in filters: return if filters: target_params.append('--gtest_filter=-{}'.format(':'.join( filters))) if self.device_params.target_params: target_params += self.device_params.target_params launcher = abstract_launcher.LauncherFactory( self.device_params.platform, 'web_platform_tests', self.device_params.config, device_id=self.device_params.device_id, target_params=target_params, output_file=None, out_directory=self.device_params.out_directory) status = launcher.Run() self.assertEqual(status, 0)
def LoadTests(launcher_params): launcher = abstract_launcher.LauncherFactory( launcher_params.platform, 'cobalt', launcher_params.config, device_id=launcher_params.device_id, target_params=None, output_file=None, out_directory=launcher_params.out_directory, loader_platform=launcher_params.loader_platform, loader_config=launcher_params.loader_config, loader_out_directory=launcher_params.loader_out_directory) test_targets = _TESTS_NO_SIGNAL if launcher.SupportsSuspendResume(): test_targets += _TESTS_NEEDING_SYSTEM_SIGNAL if launcher.SupportsDeepLink(): test_targets += _TESTS_NEEDING_DEEP_LINK test_suite = unittest.TestSuite() for test in test_targets: test_suite.addTest(unittest.TestLoader().loadTestsFromModule( importlib.import_module(_TEST_DIR_PATH + test))) return test_suite
def main(): SetupDefaultLoggingConfig() arg_parser = argparse.ArgumentParser() command_line.AddLauncherArguments(arg_parser) arg_parser.add_argument( "-t", "--target_name", required=True, help="Name of executable target.") launcher_params = command_line.CreateLauncherParams(arg_parser) launcher = abstract_launcher.LauncherFactory( launcher_params.platform, launcher_params.target_name, launcher_params.config, device_id=launcher_params.device_id, target_params=launcher_params.target_params, out_directory=launcher_params.out_directory, loader_platform=launcher_params.loader_platform, loader_config=launcher_params.loader_config, loader_out_directory=launcher_params.loader_out_directory) def Abort(signum, frame): del signum, frame # Unused. sys.stderr.write("Killing thread\n") launcher.Kill() sys.exit(1) signal.signal(signal.SIGINT, Abort) return launcher.Run()
def main(): SetupDefaultLoggingConfig() parser = command_line.CreateParser() parser.add_argument("-t", "--target_name", required=True, help="Name of executable target.") args = parser.parse_args() target_params = [] if args.target_params: target_params = args.target_params.split(" ") launcher = abstract_launcher.LauncherFactory( args.platform, args.target_name, args.config, device_id=args.device_id, target_params=target_params, out_directory=args.out_directory) def Abort(signum, frame): del signum, frame # Unused. sys.stderr.write("Killing thread\n") launcher.Kill() sys.exit(1) signal.signal(signal.SIGINT, Abort) return launcher.Run()
def test_simple(self): with WebPlatformTestServer( binding_address=self.GetBindingAddress(), wpt_http_port=self.GetWptHttpPort()): target_params = [] filters = self.cobalt_config.GetWebPlatformTestFilters() # Regardless of our own platform, if we are Evergreen we also need to # filter the tests that are filtered by the underlying platform. For # example, the 'evergreen-arm-hardfp' needs to filter the 'raspi-2' # filtered tests when it is running on a Raspberry Pi 2. if self.launcher_params.IsEvergreen(): loader_platform_config = build.GetPlatformConfig( self.launcher_params.loader_platform) loader_platform_cobalt_config = loader_platform_config.GetApplicationConfiguration( 'cobalt') for filter in loader_platform_cobalt_config.GetWebPlatformTestFilters(): if filter not in filters: filters.append(filter) used_filters = [] for filter in filters: if filter == test_filter.DISABLE_TESTING: return if filter == test_filter.FILTER_ALL: return if isinstance(filter, test_filter.TestFilter): if filter.config and filter.config != self.launcher_params.config: continue if filter.test_name and filter.test_name == test_filter.FILTER_ALL: return used_filters.append(filter.test_name) else: used_filters.append(filter) if used_filters: target_params.append('--gtest_filter=-{}'.format( ':'.join(used_filters))) if self.launcher_params.target_params: target_params += self.launcher_params.target_params launcher = abstract_launcher.LauncherFactory( self.launcher_params.platform, 'web_platform_tests', self.launcher_params.config, device_id=self.launcher_params.device_id, target_params=target_params, output_file=None, out_directory=self.launcher_params.out_directory, env_variables={'ASAN_OPTIONS': 'intercept_tls_get_addr=0'}, loader_platform=self.launcher_params.loader_platform, loader_config=self.launcher_params.loader_config, loader_out_directory=self.launcher_params.loader_out_directory) status = launcher.Run() self.assertEqual(status, 0)
def MakeLauncher(): return abstract_launcher.LauncherFactory( self.platform, target_name, self.config, device_id=self.device_id, target_params=test_params, output_file=write_pipe, out_directory=self.out_directory, coverage_directory=self.coverage_directory, env_variables=env, loader_platform=self.loader_platform, loader_config=self.loader_config, loader_out_directory=self.loader_out_directory, launcher_args=self.launcher_args)
def GetSupportedFeatures(launcher_params): launcher = abstract_launcher.LauncherFactory( launcher_params.platform, 'cobalt', launcher_params.config, device_id=launcher_params.device_id, target_params=None, output_file=None, out_directory=launcher_params.out_directory, loader_platform=launcher_params.loader_platform, loader_config=launcher_params.loader_config, loader_out_directory=launcher_params.loader_out_directory) return { Features.SUSPEND_AND_RESUME: launcher.SupportsSystemSuspendResume(), Features.SEND_KEYS: True, }
def LoadTests(platform, config, device_id, out_directory): launcher = abstract_launcher.LauncherFactory(platform, 'cobalt', config, device_id=device_id, target_params=None, output_file=None, out_directory=out_directory) if launcher.SupportsSuspendResume(): test_targets = _TESTS_NEEDING_SYSTEM_SIGNAL + _TESTS_NO_SIGNAL else: test_targets = _TESTS_NO_SIGNAL test_suite = unittest.TestSuite() for test in test_targets: test_suite.addTest(unittest.TestLoader().loadTestsFromModule( importlib.import_module(_TEST_DIR_PATH + test))) return test_suite
def Run(self): """Construct and run app launcher.""" if self.launcher_is_running: return # Behavior to restart a killed app launcher is not clearly defined. # Let's get a new launcher for every launch. read_fd, write_fd = os.pipe() self.launcher_read_pipe = os.fdopen(read_fd, 'r') self.launcher_write_pipe = os.fdopen(write_fd, 'w') self.launcher = abstract_launcher.LauncherFactory( self.launcher_params.platform, 'cobalt', self.launcher_params.config, device_id=self.launcher_params.device_id, target_params=self.target_params, output_file=self.launcher_write_pipe, out_directory=self.launcher_params.out_directory, loader_platform=self.launcher_params.loader_platform, loader_config=self.launcher_params.loader_config, loader_out_directory=self.launcher_params.loader_out_directory) self.runner_thread = threading.Thread(target=self._RunLauncher) self.runner_thread.start() self.reader_thread = threading.Thread(target=self._HandleLine) # Make this thread daemonic so that it always exits self.reader_thread.daemon = True self.reader_thread.start() self.launcher_is_running = True try: self.WaitForStart() except KeyboardInterrupt: # potentially from thread.interrupt_main(). We will treat as # a timeout regardless. self.Exit(should_fail=True) raise TimeoutException
def test_simple(self): device_params = black_box_tests._device_params if device_params.config not in _WEB_PLATFORM_TESTS_CONFIGS: logging.warning('Can only run web platform tests on debug or devel ' 'configs.') return with WebPlatformTestServer(binding_address=self.GetBindingAddress()): target_params = [] platform_config = build.GetPlatformConfig(device_params.platform) cobalt_config = platform_config.GetApplicationConfiguration('cobalt') filters = cobalt_config.GetWebPlatformTestFilters() if test_filter.DISABLE_TESTING in filters: return if test_filter.FILTER_ALL in filters: return if filters: target_params.append('--gtest_filter=-{}'.format(':'.join( filters))) if device_params.target_params: target_params += device_params.target_params launcher = abstract_launcher.LauncherFactory( device_params.platform, 'web_platform_tests', device_params.config, device_id=device_params.device_id, target_params=target_params, output_file=None, out_directory=device_params.out_directory) status = launcher.Run() self.assertEqual(status, 0)
def _RunTest(self, target_name, test_name=None): """Runs a specific target or test and collects the output. Args: target_name: The name of the test suite to be run. test_name: The name of the specific test to be run. The entire test suite is run when this is empty. Returns: A tuple containing tests results (See "_CollectTestResults()"). """ # Get the environment variables for the test target env = {} env.update(self._platform_config.GetTestEnvVariables()) env.update(self.test_env_vars.get(target_name, {})) # Set up a pipe for processing test output read_fd, write_fd = os.pipe() read_pipe = os.fdopen(read_fd, "r") write_pipe = os.fdopen(write_fd, "w") # Filter the specified tests for this platform, if any test_params = [] gtest_filter_value = "" # If a specific test case was given, filter for the exact name given. if test_name: gtest_filter_value = test_name elif self.test_targets[target_name]: gtest_filter_value = "-" + ":".join(self.test_targets[target_name]) if gtest_filter_value: test_params.append("--gtest_filter=" + gtest_filter_value) if self.log_xml_results: # Log the xml results test_params.append("--gtest_output=xml:log") logging.info("Xml results for this test will be logged.") elif self.xml_output_dir: # Have gtest create and save a test result xml xml_output_subdir = os.path.join(self.xml_output_dir, target_name) try: os.makedirs(xml_output_subdir) except OSError: pass xml_output_path = os.path.join(xml_output_subdir, "sponge_log.xml") logging.info("Xml output for this test will be saved to: %s", xml_output_path) test_params.append("--gtest_output=xml:%s" % (xml_output_path)) test_params.extend(self.target_params) launcher = abstract_launcher.LauncherFactory( self.platform, target_name, self.config, device_id=self.device_id, target_params=test_params, output_file=write_pipe, out_directory=self.out_directory, env_variables=env) test_reader = TestLineReader(read_pipe) test_launcher = TestLauncher(launcher) self.threads.append(test_launcher) self.threads.append(test_reader) dump_params = " ARGS:" + " ".join(test_params) if test_params else "" dump_env = " ENV VARS: " + ";".join( "{}={}".format(k, v) for k, v in env.items()) if env else "" # Output either the name of the test target or the specific test case # being run. # pylint: disable=g-long-ternary sys.stdout.write("Starting {}{}{}".format( test_name if test_name else target_name, dump_params, dump_env)) if self.dry_run: # Output a newline before running the test target / case. sys.stdout.write("\n") if test_params: sys.stdout.write(" {}\n".format(test_params)) write_pipe.close() read_pipe.close() else: # Output a newline before running the test target / case. sys.stdout.write("\n") test_reader.Start() test_launcher.Start() # Wait for the launcher to exit then close the write pipe, which will # cause the reader to exit. test_launcher.Join() write_pipe.close() # Only after closing the write pipe, wait for the reader to exit. test_reader.Join() read_pipe.close() output = test_reader.GetLines() self.threads = [] return self._CollectTestResults(output, target_name, test_launcher.GetReturnCode())
def _RunTest(self, target_name): """Runs a single unit test binary and collects all of the output. Args: target_name: The name of the test target being run. Returns: A tuple containing tests results (See "_CollectTestResults()"). """ # Get the environment variables for the test target env = self.test_env_vars.get(target_name, {}) # Set up a pipe for processing test output read_fd, write_fd = os.pipe() read_pipe = os.fdopen(read_fd, "r") write_pipe = os.fdopen(write_fd, "w") # Filter the specified tests for this platform, if any test_params = [] if self.test_targets[target_name]: test_params.append("--gtest_filter=-{}".format(":".join( self.test_targets[target_name]))) if self.log_xml_results: # Log the xml results test_params.append("--gtest_output=xml:log") print "Xml results for this test will be logged." elif self.xml_output_dir: # Have gtest create and save a test result xml xml_output_subdir = os.path.join(self.xml_output_dir, target_name) try: os.makedirs(xml_output_subdir) except OSError: pass xml_output_path = os.path.join(xml_output_subdir, "sponge_log.xml") print "Xml output for this test will be saved to: %s" % xml_output_path test_params.append("--gtest_output=xml:%s" % xml_output_path) test_params.extend(self.target_params) launcher = abstract_launcher.LauncherFactory( self.platform, target_name, self.config, device_id=self.device_id, target_params=test_params, output_file=write_pipe, out_directory=self.out_directory, env_variables=env) test_reader = TestLineReader(read_pipe) test_launcher = TestLauncher(launcher) self.threads.append(test_launcher) self.threads.append(test_reader) if self.dry_run: # pylint: disable=g-long-ternary sys.stdout.write("{} {}\n".format(target_name, test_params) if test_params else "{}\n".format(target_name)) write_pipe.close() read_pipe.close() else: sys.stdout.write("Starting {}\n".format(target_name)) test_reader.Start() test_launcher.Start() # Wait for the launcher to exit then close the write pipe, which will # cause the reader to exit. test_launcher.Join() write_pipe.close() # Only after closing the write pipe, wait for the reader to exit. test_reader.Join() read_pipe.close() output = test_reader.GetLines() self.threads = [] return self._CollectTestResults(output, target_name, test_launcher.GetReturnCode())