Skip to content

Commit

Permalink
Refactor and improve fuse-overlay related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
younghojan committed Sep 2, 2024
1 parent 147b4e2 commit b63db00
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions benchexec/test_runexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,8 @@ def test_uptime_without_lxcfs(self):
def test_fuse_overlay(self):
if not container.get_fuse_overlayfs_executable():
self.skipTest("fuse-overlayfs not available")

test_dir = "/tmp/fuse_test/"
os.makedirs(test_dir, exist_ok=True)
test_file_path = os.path.join(test_dir, "test_file")

try:
with tempfile.TemporaryDirectory(prefix="BenchExec_test_") as temp_dir:
test_file_path = os.path.join(temp_dir, "test_file")
with open(test_file_path, "wb") as test_file:
test_file.write(b"TEST_TOKEN")

Expand All @@ -1216,7 +1212,7 @@ def test_fuse_overlay(self):
"/": containerexecutor.DIR_READ_ONLY,
"/home": containerexecutor.DIR_HIDDEN,
"/tmp": containerexecutor.DIR_HIDDEN,
test_dir: containerexecutor.DIR_OVERLAY,
temp_dir: containerexecutor.DIR_OVERLAY,
},
)
result, output = self.execute_run(
Expand All @@ -1238,8 +1234,6 @@ def test_fuse_overlay(self):
b"TEST_TOKEN",
f"File '{test_file_path}' content is incorrect. Expected 'TEST_TOKEN', but got:\n{test_token}",
)
finally:
shutil.rmtree(test_dir)

def test_triple_nested_runexec(self):
if not container.get_fuse_overlayfs_executable():
Expand All @@ -1260,25 +1254,29 @@ def test_triple_nested_runexec(self):
outer_cmd = [
"python3",
runexec,
"--read-only-dir",
"--full-access-dir",
"/",
"--overlay-dir",
overlay_dir,
"--full-access-dir",
output_dir,
"--hidden-dir",
"/tmp",
"--output",
mid_output_file,
"--",
]
mid_cmd = [
"python3",
runexec,
"--read-only-dir",
"--full-access-dir",
"/",
"--overlay-dir",
overlay_dir,
"--full-access-dir",
output_dir,
"--hidden-dir",
"/tmp",
"--output",
inner_output_file,
"--",
Expand All @@ -1292,10 +1290,10 @@ def test_triple_nested_runexec(self):

self.setUp(
dir_modes={
"/": containerexecutor.DIR_READ_ONLY,
"/home": containerexecutor.DIR_OVERLAY,
"/": containerexecutor.DIR_FULL_ACCESS,
"/tmp": containerexecutor.DIR_HIDDEN,
overlay_dir: containerexecutor.DIR_OVERLAY,
"/tmp": containerexecutor.DIR_FULL_ACCESS,
output_dir: containerexecutor.DIR_FULL_ACCESS,
},
)
outer_result, outer_output = self.execute_run(*combined_cmd)
Expand Down

0 comments on commit b63db00

Please sign in to comment.