Commit 4e3104d0 authored by Seth Howell's avatar Seth Howell Committed by Tomasz Zawadzki
Browse files

autorun_post: rewrite the aggregateCompletedTests function.



This whole function was just written poorly. Variables weren't named
correctly, little effort was made to use proper python programming
constructs, and there was a lot of redundant code in the function that
didn't do any good.

And I can say that because I wrote it.

Change-Id: I08576698d99c35c43348b61762791415f79eebf2
Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477979


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 9436ab59
Loading
Loading
Loading
Loading
+43 −66
Original line number Diff line number Diff line
@@ -92,83 +92,60 @@ def collectOne(output_dir, dir_name):
        shutil.rmtree(d)


def aggregateCompletedTests(output_dir, repo_dir):
    test_list = {}
    test_with_asan = {}
    test_with_ubsan = {}
    test_completion_table = []
    asan_enabled = False
    ubsan_enabled = False
    test_unit_with_valgrind = False
    testFilePath = os.path.join(output_dir, '**', 'all_tests.txt')
    completionFilePath = os.path.join(output_dir, '**', 'test_completions.txt')
    testFiles = glob.glob(testFilePath, recursive=True)
    completionFiles = glob.glob(completionFilePath, recursive=True)
    testSummary = os.path.join(output_dir, "test_execution.log")

    if len(testFiles) == 0:
        print("Unable to perform test completion aggregator. No input files.")
        return 0
    item = testFiles[0]
    with open(item, 'r') as raw_test_list:
        for line in raw_test_list:
            test_list[line.strip()] = (False, False, False)
            test_completion_table.append(["None", line.strip(), False, False])
    for item in completionFiles:
        agent_name = os.path.split(os.path.split(item)[0])[1]
        with open(item, 'r') as completion_list:
            completions = completion_list.read()
def getCompletions(completionFile, test_list, test_completion_table):
    agent_name = os.path.basename(os.path.dirname(completionFile))
    with open(completionFile, 'r') as completionList:
        completions = completionList.read()

            if "asan" not in completions:
                asan_enabled = False
            else:
                asan_enabled = True
    asan_enabled = "asan" in completions
    ubsan_enabled = "ubsan" in completions

            if "ubsan" not in completions:
                ubsan_enabled = False
            else:
                ubsan_enabled = True

            if "valgrind" in completions and "unittest" in completions:
                test_unit_with_valgrind = True
                test_completion_table.append([agent_name, "valgrind", asan_enabled, ubsan_enabled])
            for line in completions.split('\n'):
    for line in completions.splitlines():
        line = line.strip()
        try:
                    test_list[line.strip()] = (True, asan_enabled | test_list[line.strip()][1], ubsan_enabled | test_list[line.strip()][2])
                    test_completion_table.append([agent_name, line.strip(), asan_enabled, ubsan_enabled])
            test_list[line] = (True, asan_enabled | test_list[line][1], ubsan_enabled | test_list[line][2])
            test_completion_table.append([agent_name, line, asan_enabled, ubsan_enabled])
            try:
                        test_completion_table.remove(["None", line.strip(), False, False])
                test_completion_table.remove(["None", line, False, False])
            except ValueError:
                continue
        except KeyError:
            continue

    with open(testSummary, 'w') as fh:
        fh.write("\n\n-----Tests Executed in Build------\n")
        for item in sorted(test_list):
            if test_list[item][0]:
                fh.write(item + "\n")

        fh.write("\n\n-----Tests Missing From Build------\n")
        if not test_unit_with_valgrind:
            fh.write("UNITTEST_WITH_VALGRIND\n")
        for item in sorted(test_list):
            if test_list[item][0] is False:
                fh.write(item + "\n")
def printList(header, test_list, index, condition):
    print("\n\n-----%s------" % header)
    executed_tests = [x for x in sorted(test_list) if test_list[x][index] is condition]
    print(*executed_tests, sep="\n")


        fh.write("\n\n-----Tests Missing ASAN------\n")
        for item in sorted(test_list):
            if test_list[item][1] is False:
                fh.write(item + "\n")
def printListInformation(table_type, test_list):
    printList("%s Executed in Build" % table_type, test_list, 0, True)
    printList("%s Missing From Build" % table_type, test_list, 0, False)
    printList("%s Missing ASAN" % table_type, test_list, 1, False)
    printList("%s Missing UBSAN" % table_type, test_list, 2, False)

        fh.write("\n\n-----Tests Missing UBSAN------\n")
        for item in sorted(test_list):
            if test_list[item][2] is False:
                fh.write(item + "\n")

    with open(testSummary, 'r') as fh:
        print(fh.read())
def aggregateCompletedTests(output_dir, repo_dir):
    test_list = {}
    test_completion_table = []

    testFiles = glob.glob(os.path.join(output_dir, '**', 'all_tests.txt'), recursive=True)
    completionFiles = glob.glob(os.path.join(output_dir, '**', 'test_completions.txt'), recursive=True)

    if len(testFiles) == 0:
        print("Unable to perform test completion aggregator. No input files.")
        return 0

    with open(testFiles[0], 'r') as raw_test_list:
        for line in raw_test_list:
            test_list[line.strip()] = (False, False, False)
            test_completion_table.append(["None", line.strip(), False, False])

    for completionFile in completionFiles:
        getCompletions(completionFile, test_list, test_completion_table)

    printListInformation("Tests", test_list)
    generateTestCompletionTables(output_dir, test_completion_table)