Skip to content

Commit 8af98c5

Browse files
committed
Testing tempfs
1 parent 47efd5e commit 8af98c5

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

.devcontainer/devcontainer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
5173
1414
],
1515
"runArgs": [
16-
// Increase size of temporary in-memory filesystem for auto-generated binaries by test scripts
17-
"--shm-size=1G"
16+
// Create an in-memory filesystem for auto-generated binaries by test scripts
17+
"--tmpfs", "/docker/memfs:rw,exec,size=2g"
1818
],
1919
// Use 'postCreateCommand' to run commands after the container is created.
2020
// "postCreateCommand": "rustc --version",
@@ -27,6 +27,4 @@
2727
]
2828
}
2929
}
30-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
31-
// "remoteUser": "root"
3230
}

t.py

+22-20
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@ class ParseError(Exception):
5151

5252

5353
def check_temp_dir():
54-
# test if /dev/shm is available by writing a file
55-
temp_dir_filesystem = "/dev/shm"
56-
delete_at_exit = False
57-
try:
58-
with open(os.path.join(temp_dir_filesystem, "test"), "w") as f:
59-
f.write("test")
60-
os.remove(os.path.join(temp_dir_filesystem, "test"))
61-
except:
62-
temp_dir_filesystem = tempfile.gettempdir()
63-
delete_at_exit = True
64-
print("WARNING: /dev/shm not available, using non-RAM " + temp_dir_filesystem)
65-
return temp_dir_filesystem, delete_at_exit
54+
PATHS = ["/docker/memfs", "/dev/shm"]
55+
56+
for path in PATHS:
57+
try:
58+
testfile = os.path.join(path, "test")
59+
with open(testfile, "w") as f:
60+
f.write("test")
61+
os.remove(testfile)
62+
63+
return path, True
64+
except FileNotFoundError:
65+
pass
66+
67+
return tempfile.gettempdir(), True
6668

6769

6870
temp_dir_filesystem, delete_at_exit = check_temp_dir()
@@ -562,7 +564,7 @@ def test_parse_instruction(self):
562564

563565
def assemble(instruction: Instruction | str) -> list[str]:
564566
# create temporary directory
565-
with tempfile.TemporaryDirectory(prefix="ax_assemble", dir="/dev/shm") as tmpdir:
567+
with tempfile.TemporaryDirectory(prefix="ax_assemble", dir=temp_dir_filesystem) as tmpdir:
566568
# write assembly code to file
567569
assembly_path = os.path.join(tmpdir, "a.asm")
568570
with open(assembly_path, "w", encoding='utf8') as f:
@@ -994,7 +996,7 @@ def is_new(flags_set, flags_not_set, input_flags):
994996
return False
995997
return True
996998

997-
with tempfile.TemporaryDirectory(prefix="ax_flag_learner", dir="/dev/shm") as tmpdir:
999+
with tempfile.TemporaryDirectory(prefix="ax_flag_learner", dir=temp_dir_filesystem) as tmpdir:
9981000
def imap_func(input: tuple[int, Input]):
9991001
return TestCase.learn_single_flags(input[0], assembled, instruction, input[1], tmpdir)
10001002

@@ -1223,10 +1225,10 @@ def main():
12231225

12241226

12251227
if __name__ == "__main__":
1226-
try:
1228+
# try:
12271229
main()
1228-
except Exception as e:
1229-
raise e
1230-
finally:
1231-
if delete_at_exit:
1232-
shutil.rmtree(temp_dir_filesystem)
1230+
# except Exception as e:
1231+
# raise e
1232+
# finally:
1233+
# if delete_at_exit:
1234+
# shutil.rmtree(temp_dir_filesystem)

0 commit comments

Comments
 (0)