diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 942300d..1fd481d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,8 +13,8 @@ 5173 ], "runArgs": [ - // Increase size of temporary in-memory filesystem for auto-generated binaries by test scripts - "--shm-size=1G" + // Create an in-memory filesystem for auto-generated binaries by test scripts + "--tmpfs", "/docker/memfs:rw,exec,size=2g" ], // Use 'postCreateCommand' to run commands after the container is created. // "postCreateCommand": "rustc --version", @@ -27,6 +27,4 @@ ] } } - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" } diff --git a/t.py b/t.py index eb70c3b..eff9054 100644 --- a/t.py +++ b/t.py @@ -51,18 +51,20 @@ class ParseError(Exception): def check_temp_dir(): - # test if /dev/shm is available by writing a file - temp_dir_filesystem = "/dev/shm" - delete_at_exit = False - try: - with open(os.path.join(temp_dir_filesystem, "test"), "w") as f: - f.write("test") - os.remove(os.path.join(temp_dir_filesystem, "test")) - except: - temp_dir_filesystem = tempfile.gettempdir() - delete_at_exit = True - print("WARNING: /dev/shm not available, using non-RAM " + temp_dir_filesystem) - return temp_dir_filesystem, delete_at_exit + PATHS = ["/docker/memfs", "/dev/shm"] + + for path in PATHS: + try: + testfile = os.path.join(path, "test") + with open(testfile, "w") as f: + f.write("test") + os.remove(testfile) + + return path, True + except FileNotFoundError: + pass + + return tempfile.gettempdir(), True temp_dir_filesystem, delete_at_exit = check_temp_dir() @@ -562,7 +564,7 @@ def test_parse_instruction(self): def assemble(instruction: Instruction | str) -> list[str]: # create temporary directory - with tempfile.TemporaryDirectory(prefix="ax_assemble", dir="/dev/shm") as tmpdir: + with tempfile.TemporaryDirectory(prefix="ax_assemble", dir=temp_dir_filesystem) as tmpdir: # write assembly code to file assembly_path = os.path.join(tmpdir, "a.asm") with open(assembly_path, "w", encoding='utf8') as f: @@ -994,7 +996,7 @@ def is_new(flags_set, flags_not_set, input_flags): return False return True - with tempfile.TemporaryDirectory(prefix="ax_flag_learner", dir="/dev/shm") as tmpdir: + with tempfile.TemporaryDirectory(prefix="ax_flag_learner", dir=temp_dir_filesystem) as tmpdir: def imap_func(input: tuple[int, Input]): return TestCase.learn_single_flags(input[0], assembled, instruction, input[1], tmpdir) @@ -1223,10 +1225,10 @@ def main(): if __name__ == "__main__": - try: + # try: main() - except Exception as e: - raise e - finally: - if delete_at_exit: - shutil.rmtree(temp_dir_filesystem) + # except Exception as e: + # raise e + # finally: + # if delete_at_exit: + # shutil.rmtree(temp_dir_filesystem)