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)])
def main() -> None: path = download_wiki("en-latest-all-titles-in") ensure_dependencies() own_sort_exe = find_executable("sort", project_path()) if own_sort_exe is None: warn(f"executable 'sort' not found in {project_path()}") sys.exit(1) 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 128MB limit"): with open(path) as stdin, open(coreutils_sort, "w") as stdout: run_with_ulimit("sort", stdin, stdout) with subtest("Run own sort with 128MB limit"): with open(path) as stdin, open(own_sort, "w") as stdout: run_with_ulimit(own_sort_exe, stdin, stdout) with subtest("Check if both results matches"): run(["cmp", str(coreutils_sort), str(own_sort)])
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))
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Create files with same name in different dirs"): node_list = [ "foo", "bar", os.path.join("foo", "foo"), os.path.join("bar", "foo"), ] try: os.mkdir(os.path.join(mnt_path, node_list[0])) except Exception as e: print(e) fuse_unmount(mnt_path) sys.exit(1) try: os.mkdir(os.path.join(mnt_path, node_list[1])) except Exception as e: print(e) fuse_unmount(mnt_path) sys.exit(1) try: os.mknod(os.path.join(mnt_path, node_list[2])) except Exception as e: print(e) fuse_unmount(mnt_path) sys.exit(1) try: os.mknod(os.path.join(mnt_path, node_list[3])) except Exception as e: print(e) fuse_unmount(mnt_path) sys.exit(1) if sorted(os.listdir(mnt_path)) != sorted(["foo", "bar"]): fuse_unmount(mnt_path) sys.exit(1) if os.listdir(os.path.join(mnt_path, node_list[0])) != ["foo"]: fuse_unmount(mnt_path) sys.exit(1) if os.listdir(os.path.join(mnt_path, node_list[1])) != ["foo"]: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") with subtest("Check mount"): fuse_check_mnt(tmpdir, mnt_path) fuse_unmount(mnt_path) sys.exit(0)
def fuse_mount(temp_path: Path, mt_pt: str) -> str: assert_executable("fusermount", "fusermount not found") mnt_path = gen_mnt_path(temp_path, mt_pt) with subtest("Mount filesystem"): exe_path = run_find_project_executable("memfs") try: proc = run_background([exe_path, mnt_path]) except Exception as e: fuse_unmount(mnt_path) sys.exit(1) return mnt_path
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Check if mount point is a directory"): if not os.path.isdir(mnt_path): fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Check empty directory on mount"): path_nodes = os.listdir(mnt_path) if len(path_nodes) != 0: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Create hierarchical files"): dir_list = [ "foo", os.path.join("foo", "bar"), ] for dir in dir_list: os.mkdir(os.path.join(mnt_path, dir)) file_list = [ "hello", os.path.join("foo", "hello_one"), os.path.join("", *["foo", "bar", "hello_two"]) ] for file in file_list: os.mknod(os.path.join(mnt_path, file)) flat_file_list = ["hello"] check_dir_list = os.listdir(mnt_path) for file in flat_file_list: if file not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) hier_file_list_level_one = ["hello_one"] check_dir_list = os.listdir(os.path.join("", *[mnt_path, "foo"])) for file in hier_file_list_level_one: if file not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) hier_file_list_level_two = ["hello_two"] check_dir_list = os.listdir(os.path.join("", *[mnt_path, "foo", "bar"])) for file in hier_file_list_level_two: if file not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Create hierarchical directories with distinct names"): dir_list = [ "foo", "bar", "foobar", "barfoo", os.path.join("foo", "b"), os.path.join("foo", "f"), os.path.join("", *["foo", "b", "foob"]), os.path.join("", *["foo", "b", "ba"]), ] for dir in dir_list: os.mkdir(os.path.join(mnt_path, dir)) flat_dir_list = ["foo", "bar", "foobar", "barfoo"] check_dir_list = os.listdir(mnt_path) for dir in flat_dir_list: if dir not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) hier_dir_level_one = ["f", "b"] check_dir_list = os.listdir(os.path.join(mnt_path, "foo")) for dir in hier_dir_level_one: if dir not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) hier_dir_level_two = ["foob", "ba"] check_dir_list = os.listdir( os.path.join(mnt_path, os.path.join("foo", "b"))) for dir in hier_dir_level_two: if dir not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest("Create flat directories"): dir_list = ["foo", "bar", "foobar", "barfoo"] for dir in dir_list: os.mkdir(os.path.join(mnt_path, dir)) check_dir_list = os.listdir(mnt_path) for dir in dir_list: if dir not in check_dir_list: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest( "Check that file and dir cannot have same name in same dir when file is created first" ): file_list = ["foo"] for file in file_list: os.mkdir(os.path.join(mnt_path, file)) try: os.mknod(os.path.join(mnt_path, file_list[0])) fuse_unmount(mnt_path) sys.exit(1) except FileExistsError as e: fuse_unmount(mnt_path) sys.exit(0)
def main() -> None: with tempfile.TemporaryDirectory() as tmpdir: temp_path = Path(tmpdir) mnt_path = fuse_mount(temp_path, "memfs_mnt") fuse_check_mnt(tmpdir, mnt_path) with subtest(""): run([os.path.join("tests", "file_io.sh"), "-o", os.path.join(mnt_path, "foo"), "hello"]) proc = run([os.path.join("tests", "file_io.sh"), "-d", os.path.join(mnt_path, "foo")], stdout=subprocess.PIPE) try: if proc.stdout != "hello\n": fuse_unmount(mnt_path) print("Written and read data don't match") sys.exit(1) except Exception as e: fuse_unmount(mnt_path) sys.exit(1) fuse_unmount(mnt_path) sys.exit(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)