def main() -> None:
    path = download_wiki("scowiki-latest-all-titles-in")

    ensure_dependencies()

    with TemporaryDirectory() as tempdir:
        temp_path = Path(tempdir)
        coreutils_sort = temp_path.joinpath(path.name + ".coreutils-sort")
        own_sort = temp_path.joinpath(path.name + ".own-sort")

        with subtest("Run coreutils sort..."):
            with open(path) as stdin, open(coreutils_sort, "w") as stdout:
                run(
                    ["sort", "-r"],
                    stdin=stdin,
                    stdout=stdout,
                    extra_env=dict(LC_ALL="C"),
                )

        with subtest("Run own sort..."):
            with open(path) as stdin, open(own_sort, "w") as stdout:
                run_project_executable("sort", ["-r"], stdin=stdin, stdout=stdout)

        with subtest("Check if both results matches"):
            run(["cmp", str(coreutils_sort), str(own_sort)])
Пример #2
0
def main() -> None:
    # Run the test program
    test_mutual_exclusion = test_root().joinpath("test_mutual_exclusion")
    if not test_mutual_exclusion.exists():
        run(["make", "-C", str(test_root()), str(test_mutual_exclusion)])

    with subtest("Checking mutual exclusion"):
        run_project_executable(str(test_mutual_exclusion))
Пример #3
0
def main() -> None:
    # Replace with the executable you want to test
    try:
        info("Run someprojectbinary...")
        run_project_executable("someprojectbinary")
        info("OK")
    except OSError as e:
        warn(f"Failed to run command: {e}")
        sys.exit(1)
Пример #4
0
def main() -> None:
    # Run the test program
    lib = ensure_library("liblockhashmap.so")
    extra_env = {"LD_LIBRARY_PATH": str(os.path.dirname(lib))}
    test_lock_hashmap = test_root().joinpath("lock_hashmap")
    if not test_lock_hashmap.exists():
        run(["make", "-C", str(test_root()), str(test_lock_hashmap)])
    times = []
    with tempfile.TemporaryDirectory() as tmpdir:
        with open(f"{tmpdir}/stdout", "w+") as stdout:
            run_project_executable(
                str(test_lock_hashmap),
                args=["-d20000", "-i10000", "-n4", "-r10000", "-u100", "-b1"],
                stdout=stdout,
                extra_env=extra_env,
            )
            output = open(f"{tmpdir}/stdout").readlines()
            sanity_check(output[1:], 1, 10000, 4)
        with subtest("Checking 1 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d2000000", "-i100000", "-n1", "-r100000", "-u10"
                        ],
                        stdout=stdout,
                        extra_env=extra_env,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 512, 100000, 1)
                times.append(runtime / 3)
        with subtest("Checking 2 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d2000000", "-i100000", "-n2", "-r100000", "-u10"
                        ],
                        stdout=stdout,
                        extra_env=extra_env,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 512, 100000, 2)
                times.append(runtime / 3)
        with subtest("Checking 4 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d2000000", "-i100000", "-n4", "-r100000", "-u10"
                        ],
                        stdout=stdout,
                        extra_env=extra_env,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 512, 100000, 4)
                times.append(runtime / 3)

        f1 = times[0] / times[1]
        f2 = times[1] / times[2]
        if f1 < 1.4 or f2 < 1.4:
            warn("Hashmap is not scaling properly: " + str(times))
            exit(1)
def main() -> None:
    # Run the test program
    test_lock_hashmap = test_root().joinpath("lockfree_hashmap")
    if not test_lock_hashmap.exists():
        run(["make", "-C", str(test_root()), str(test_lock_hashmap)])
    times = []
    with tempfile.TemporaryDirectory() as tmpdir:
        with subtest("Checking correctness"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                run_project_executable(
                    str(test_lock_hashmap),
                    args=[
                        "-d20000", "-i10000", "-n4", "-r10000", "-u100", "-b1"
                    ],
                    stdout=stdout,
                )
                output = open(f"{tmpdir}/stdout").readlines()
                sanity_check(output[1:], 1, 10000, 4)
        with subtest("Checking 1 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d20000", "-i10000", "-n1", "-r10000", "-u10",
                            "-b1"
                        ],
                        stdout=stdout,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 1, 10000, 1)
                times.append(runtime / 3)
        with subtest("Checking 2 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d20000", "-i10000", "-n2", "-r10000", "-u10",
                            "-b1"
                        ],
                        stdout=stdout,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 1, 10000, 2)
                times.append(runtime / 3)
        with subtest("Checking 4 thread time"):
            with open(f"{tmpdir}/stdout", "w+") as stdout:
                runtime = 0.0
                for i in range(0, 3):
                    run_project_executable(
                        str(test_lock_hashmap),
                        args=[
                            "-d20000", "-i10000", "-n4", "-r10000", "-u10",
                            "-b1"
                        ],
                        stdout=stdout,
                    )
                    output = open(f"{tmpdir}/stdout").readlines()
                    runtime += float(output[0].strip())
                    sanity_check(output[1:], 1, 10000, 4)
                times.append(runtime / 3)

        f1 = times[0] / times[1]
        f2 = times[1] / times[2]
        if f1 < 1.4 or f2 < 1.4:
            warn("Hashmap is not scaling properly: " + str(times))
            exit(1)

        with subtest("Checking if hashmap cleans up items when removing"):
            test_cleanup_lockfree = test_root().joinpath(
                "test_cleanup_lockfree")

            if not test_cleanup_lockfree.exists():
                run([
                    "make", "-C",
                    str(test_root()),
                    str(test_cleanup_lockfree)
                ])

            with open(f"{tmpdir}/stdout", "w+") as stdout:
                run_project_executable(str(test_cleanup_lockfree),
                                       stdout=stdout)

                stdout.seek(0)
                lines = stdout.readlines()
                first = float(lines[0])
                second = float(lines[1])

                if second / first > 1.5:
                    warn(
                        f"Hashmap does not cleanup properly when removing items: {first}, {second}"
                    )
                    exit(1)