Beispiel #1
0
def _inner_generate(repo_dir, revision, artifactsHandler, per_test_cursor,
                    per_chunk_cursor, executor):
    per_test_cursor.execute(
        "CREATE TABLE file_to_chunk (path text, platform text, chunk text)")
    per_test_cursor.execute(
        "CREATE TABLE chunk_to_test (platform text, chunk text, path text)")
    per_test_cursor.execute(
        "CREATE TABLE file_to_test (source text, test text)")

    per_chunk_cursor.execute(
        "CREATE TABLE file_to_chunk (path text, platform text, chunk text)")
    per_chunk_cursor.execute(
        "CREATE TABLE chunk_to_test (platform text, chunk text, path text)")

    logger.info("Populating file_to_test table.")
    test_coverage_suites = get_test_coverage_suites()
    logger.info("Found {} test suites.".format(len(test_coverage_suites)))
    for suites in group_by_20k(test_coverage_suites):
        test_coverage_tests = get_test_coverage_tests(suites)
        for tests in group_by_20k(test_coverage_tests):
            tests_files_data = get_test_coverage_files(tests)

            source_names = tests_files_data["source.file.name"]
            test_iter = enumerate(tests_files_data["test.name"])
            source_test_iter = ((source_names[i], test)
                                for i, test in test_iter)

            per_test_cursor.executemany(
                "INSERT INTO file_to_test VALUES (?,?)", source_test_iter)

    futures = {}
    for platform in PLATFORMS:
        logger.info(
            "Reading chunk coverage artifacts for {}.".format(platform))
        for chunk in artifactsHandler.get_chunks(platform):
            assert chunk.strip() != "", "chunk can not be an empty string"

            artifacts = artifactsHandler.get(platform=platform, chunk=chunk)

            assert len(artifacts) > 0, "There should be at least one artifact"

            future = executor.submit(grcov.files_list,
                                     artifacts,
                                     source_dir=repo_dir)
            futures[future] = (platform, chunk)

        logger.info("Populating chunk_to_test table for {}.".format(platform))
        for suite in get_suites(revision):
            tests_data = get_tests_chunks(revision, platform, suite)
            if len(tests_data) == 0:
                logger.warn(
                    "No tests found for platform {} and suite {}.".format(
                        platform, suite))
                continue

            logger.info("Adding tests for platform {} and suite {}".format(
                platform, suite))
            task_names = tests_data["run.key"]

            def chunk_test_iter():
                test_iter = enumerate(tests_data["result.test"])
                return ((platform, taskcluster.name_to_chunk(task_names[i]),
                         test) for i, test in test_iter)

            if is_chunk_only_suite(suite):
                per_test_cursor.executemany(
                    "INSERT INTO chunk_to_test VALUES (?,?,?)",
                    chunk_test_iter())

            per_chunk_cursor.executemany(
                "INSERT INTO chunk_to_test VALUES (?,?,?)", chunk_test_iter())

    logger.info("Populating file_to_chunk table.")
    for future in concurrent.futures.as_completed(futures):
        (platform, chunk) = futures[future]
        files = future.result()

        suite = taskcluster.chunk_to_suite(chunk)
        if is_chunk_only_suite(suite):
            per_test_cursor.executemany(
                "INSERT INTO file_to_chunk VALUES (?,?,?)",
                ((f, platform, chunk) for f in files),
            )

        per_chunk_cursor.executemany(
            "INSERT INTO file_to_chunk VALUES (?,?,?)",
            ((f, platform, chunk) for f in files),
        )
def test_chunk_to_suite(chunk, expected):
    assert taskcluster.chunk_to_suite(chunk) == expected