def download_all(self): os.makedirs(self.parent_dir, exist_ok=True) # The test tasks for the Linux and Windows builds are in the same group, # but the following code is generic and supports build tasks split in # separate groups. groups = set([ taskcluster.get_task_details(build_task_id)['taskGroupId'] for build_task_id in self.task_ids.values() ]) test_tasks = [ task for group in groups for task in taskcluster.get_tasks_in_group(group) if taskcluster.is_coverage_task(task) ] for test_task in test_tasks: status = test_task['status']['state'] while status not in FINISHED_STATUSES: assert status in ALL_STATUSES, "State '{}' not recognized".format( status) logger.info('Waiting for task {} to finish...'.format( test_task['status']['taskId'])) time.sleep(60) status = taskcluster.get_task_status( test_task['status']['taskId']) # Choose best tasks to download (e.g. 'completed' is better than 'failed') download_tasks = {} for test_task in test_tasks: status = test_task['status']['state'] assert status in FINISHED_STATUSES, "State '{}' not recognized".format( status) chunk_name = taskcluster.get_chunk( test_task['task']['metadata']['name']) platform_name = taskcluster.get_platform( test_task['task']['metadata']['name']) # Ignore awsy and talos as they aren't actually suites of tests. if any(to_ignore in chunk_name for to_ignore in self.suites_to_ignore): continue if (chunk_name, platform_name) not in download_tasks: # If the chunk hasn't been downloaded before, this is obviously the best task # to download it from. download_tasks[(chunk_name, platform_name)] = test_task else: # Otherwise, compare the status of this task with the previously selected task. prev_task = download_tasks[(chunk_name, platform_name)] if STATUS_VALUE[status] > STATUS_VALUE[prev_task['status'] ['state']]: download_tasks[(chunk_name, platform_name)] = test_task with ThreadPoolExecutorResult() as executor: for test_task in download_tasks.values(): executor.submit(self.download, test_task) logger.info('Code coverage artifacts downloaded')
def test_get_platform(): tests = [ ('test-linux64-ccov/debug-mochitest-1', 'linux'), ('test-windows10-64-ccov/debug-mochitest-1', 'windows'), ] for (name, platform) in tests: assert taskcluster.get_platform(name) == platform
def __init__( self, repository, revision, task_name_filter, cache_root, working_dir, required_platforms=[], ): os.makedirs(working_dir, exist_ok=True) self.artifacts_dir = os.path.join(working_dir, "ccov-artifacts") self.reports_dir = os.path.join(working_dir, "ccov-reports") logger.info( "Local storage initialized.", artifacts=self.artifacts_dir, reports=self.reports_dir, ) self.repository = repository self.revision = revision assert (self.revision is not None and self.repository is not None), "Missing repo/revision" logger.info("Mercurial setup", repository=self.repository, revision=self.revision) if cache_root is not None: assert os.path.isdir( cache_root), f"Cache root {cache_root} is not a dir." self.repo_dir = os.path.join(cache_root, self.branch) # Load coverage tasks for all platforms decision_task_id = taskcluster.get_decision_task( self.branch, self.revision) assert decision_task_id is not None, "The decision task couldn't be found" group = taskcluster.get_task_details(decision_task_id)["taskGroupId"] test_tasks = [ task for task in taskcluster.get_tasks_in_group(group) if taskcluster.is_coverage_task(task["task"]) ] # Check the required platforms are present platforms = set( taskcluster.get_platform(test_task["task"]) for test_task in test_tasks) for platform in required_platforms: assert platform in platforms, f"{platform} missing in the task group." self.artifactsHandler = ArtifactsHandler(test_tasks, self.artifacts_dir, task_name_filter)
def download(self, test_task): chunk_name = taskcluster.get_chunk(test_task['task']['metadata']['name']) platform_name = taskcluster.get_platform(test_task['task']['metadata']['name']) test_task_id = test_task['status']['taskId'] for artifact in taskcluster.get_task_artifacts(test_task_id): if not any(n in artifact['name'] for n in ['code-coverage-grcov.zip', 'code-coverage-jsvm.zip']): continue artifact_path = self.generate_path(platform_name, chunk_name, artifact) taskcluster.download_artifact(artifact_path, test_task_id, artifact['name']) logger.info('%s artifact downloaded' % artifact_path)
def test_get_platform(): tests = [ ("test-linux64-ccov/debug-mochitest-1", "linux"), ("test-windows10-64-ccov/debug-mochitest-1", "windows"), ("build-linux64-ccov/debug", "linux"), ("build-win64-ccov/debug", "windows"), ("build-android-test-ccov/opt", "android-test"), ("test-android-em-4.3-arm7-api-16-ccov/debug-robocop-2", "android-emulator"), ] for (name, platform) in tests: assert taskcluster.get_platform(name) == platform
def test_get_platform(): tests = [ ('test-linux64-ccov/debug-mochitest-1', 'linux'), ('test-windows10-64-ccov/debug-mochitest-1', 'windows'), ('build-linux64-ccov/debug', 'linux'), ('build-win64-ccov/debug', 'windows'), ('build-android-test-ccov/opt', 'android-test'), ('test-android-em-4.3-arm7-api-16-ccov/debug-robocop-2', 'android-emulator'), ] for (name, platform) in tests: assert taskcluster.get_platform(name) == platform
def download_all(self): os.makedirs(self.parent_dir, exist_ok=True) logger.info("Downloading artifacts from {} tasks".format(len(self.test_tasks))) for test_task in self.test_tasks: status = test_task["status"]["state"] task_id = test_task["status"]["taskId"] while status not in FINISHED_STATUSES: assert status in ALL_STATUSES, "State '{}' not recognized".format( status ) logger.info(f"Waiting for task {task_id} to finish...") time.sleep(60) task_status = taskcluster.get_task_status(task_id) status = task_status["status"]["state"] # Update the task status, as we will use it to compare statuses later. test_task["status"]["state"] = status # Choose best tasks to download (e.g. 'completed' is better than 'failed') download_tasks = {} for test_task in self.test_tasks: status = test_task["status"]["state"] assert status in FINISHED_STATUSES, "State '{}' not recognized".format( status ) chunk_name = taskcluster.get_chunk(test_task["task"]) platform_name = taskcluster.get_platform(test_task["task"]) if any(to_ignore in chunk_name for to_ignore in SUITES_TO_IGNORE): continue if (chunk_name, platform_name) not in download_tasks: # If the chunk hasn't been downloaded before, this is obviously the best task # to download it from. download_tasks[(chunk_name, platform_name)] = test_task else: # Otherwise, compare the status of this task with the previously selected task. prev_task = download_tasks[(chunk_name, platform_name)] if STATUS_VALUE[status] > STATUS_VALUE[prev_task["status"]["state"]]: download_tasks[(chunk_name, platform_name)] = test_task with ThreadPoolExecutorResult() as executor: for test_task in download_tasks.values(): executor.submit(self.download, test_task) logger.info("Code coverage artifacts downloaded")
def download(self, test_task): chunk_name = taskcluster.get_chunk( test_task["task"]["metadata"]["name"]) platform_name = taskcluster.get_platform( test_task["task"]["metadata"]["name"]) test_task_id = test_task["status"]["taskId"] for artifact in taskcluster.get_task_artifacts(test_task_id): if not any(n in artifact["name"] for n in ["code-coverage-grcov.zip", "code-coverage-jsvm.zip"]): continue artifact_path = self.generate_path(platform_name, chunk_name, artifact) taskcluster.download_artifact(artifact_path, test_task_id, artifact["name"]) logger.info("%s artifact downloaded" % artifact_path)
def download_all(self): os.makedirs(self.parent_dir, exist_ok=True) # The test tasks for the Linux and Windows builds are in the same group, # but the following code is generic and supports build tasks split in # separate groups. groups = set([ taskcluster.get_task_details(build_task_id)["taskGroupId"] for build_task_id in self.task_ids.values() if build_task_id is not None ]) test_tasks = [ task for group in groups for task in taskcluster.get_tasks_in_group(group) if taskcluster.is_coverage_task(task["task"]) and not self.is_filtered_task(task) ] logger.info("Downloading artifacts from {} tasks".format( len(test_tasks))) for test_task in test_tasks: status = test_task["status"]["state"] task_id = test_task["status"]["taskId"] while status not in FINISHED_STATUSES: assert status in ALL_STATUSES, "State '{}' not recognized".format( status) logger.info(f"Waiting for task {task_id} to finish...") time.sleep(60) task_status = taskcluster.get_task_status(task_id) status = task_status["status"]["state"] # Update the task status, as we will use it to compare statuses later. test_task["status"]["state"] = status # Choose best tasks to download (e.g. 'completed' is better than 'failed') download_tasks = {} for test_task in test_tasks: status = test_task["status"]["state"] assert status in FINISHED_STATUSES, "State '{}' not recognized".format( status) chunk_name = taskcluster.get_chunk(test_task["task"]) platform_name = taskcluster.get_platform(test_task["task"]) if any(to_ignore in chunk_name for to_ignore in SUITES_TO_IGNORE): continue if (chunk_name, platform_name) not in download_tasks: # If the chunk hasn't been downloaded before, this is obviously the best task # to download it from. download_tasks[(chunk_name, platform_name)] = test_task else: # Otherwise, compare the status of this task with the previously selected task. prev_task = download_tasks[(chunk_name, platform_name)] if STATUS_VALUE[status] > STATUS_VALUE[prev_task["status"] ["state"]]: download_tasks[(chunk_name, platform_name)] = test_task with ThreadPoolExecutorResult() as executor: for test_task in download_tasks.values(): executor.submit(self.download, test_task) logger.info("Code coverage artifacts downloaded")
def test_get_platform(task_name, expected): task = json.load(open(os.path.join(FIXTURES_DIR, f"{task_name}.json"))) assert taskcluster.get_platform(task) == expected