Skip to content

Commit

Permalink
Testing tempfs
Browse files Browse the repository at this point in the history
  • Loading branch information
xarantolus committed Feb 22, 2024
1 parent 47efd5e commit 8af98c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -27,6 +27,4 @@
]
}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
42 changes: 22 additions & 20 deletions t.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit 8af98c5

Please sign in to comment.