qemu: test_qmp_drive.py removes its temp dirs (Fixes #30)
ci / test (push) Successful in 10s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 48s
ci / qemu-tools (push) Successful in 1m22s
ci / quality (push) Successful in 57s
ci / badges (push) Skipped
ci / kernel-symbols (push) Successful in 4m7s
ci / test (push) Successful in 10s
ci / mcdc (push) Successful in 13s
ci / bench (push) Successful in 5s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / patches-apply (push) Successful in 48s
ci / qemu-tools (push) Successful in 1m22s
ci / quality (push) Successful in 57s
ci / badges (push) Skipped
ci / kernel-symbols (push) Successful in 4m7s
Every temp dir the module makes (a drive's out dir per run_script, the console and QMP socket dirs) now lands under one root per run, removed at exit; a run used to leave about 40 dirs in $TMPDIR. TempDirs runs one test of each kind in a child under a fresh TMPDIR and checks it is empty after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
06b86e68b4
commit
eebfd23a96
@@ -13,9 +13,11 @@ was never compared with the one the reference was captured under.
|
||||
|
||||
python3 test_qmp_drive.py
|
||||
"""
|
||||
import atexit
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -29,6 +31,15 @@ HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, HERE)
|
||||
import qmp # noqa: E402
|
||||
|
||||
# Every temp dir this module makes (a drive's out dir per run_script, the
|
||||
# console and QMP socket dirs) lands under one root per run, removed at exit,
|
||||
# so a run leaves $TMPDIR as it found it (bfe-core1106-sdk#30: about 40 dirs
|
||||
# per run used to stay behind). The prefix is short: an AF_UNIX socket path
|
||||
# under it must stay inside about 108 bytes.
|
||||
_TMP_ROOT = tempfile.mkdtemp(prefix="qdt.")
|
||||
tempfile.tempdir = _TMP_ROOT
|
||||
atexit.register(shutil.rmtree, _TMP_ROOT, True)
|
||||
|
||||
SIZE = 64
|
||||
|
||||
|
||||
@@ -1574,5 +1585,29 @@ class StallProbe(unittest.TestCase):
|
||||
self.assertTrue(qmp.is_stall("control channel: bridge: no reply from warden-ui within 30 s: hit"))
|
||||
self.assertFalse(qmp.is_stall("obj moved: box=1,2,3x4"))
|
||||
|
||||
class TempDirs(unittest.TestCase):
|
||||
# One test per kind of temp dir this module makes: a drive's out dir
|
||||
# (run_script), a console dir and a QMP socket dir.
|
||||
CHILD_TESTS = (
|
||||
"DriveVerbs.test_shot_and_region_names_cannot_escape_outdir",
|
||||
"ConsoleWatchTests.test_finds_a_marker_split_across_two_reads_and_caches_it",
|
||||
"QmpSocketTimeout.test_main_bounds_a_wedged_qmp_peer_instead_of_hanging_forever",
|
||||
)
|
||||
|
||||
@unittest.skipIf(os.environ.get("QMP_DRIVE_TEMP_CHILD"), "the child run itself")
|
||||
def test_a_run_leaves_tmpdir_as_it_found_it(self):
|
||||
fresh = tempfile.mkdtemp(prefix="fresh.", dir=os.path.dirname(_TMP_ROOT))
|
||||
try:
|
||||
env = dict(os.environ, TMPDIR=fresh, QMP_DRIVE_TEMP_CHILD="1")
|
||||
child = subprocess.run(
|
||||
[sys.executable, os.path.abspath(__file__), *self.CHILD_TESTS],
|
||||
env=env, capture_output=True, text=True, timeout=120)
|
||||
self.assertEqual(child.returncode, 0, child.stderr[-2000:])
|
||||
self.assertIn(f"Ran {len(self.CHILD_TESTS)} tests", child.stderr)
|
||||
self.assertEqual(os.listdir(fresh), [])
|
||||
finally:
|
||||
shutil.rmtree(fresh, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=1)
|
||||
|
||||
Reference in New Issue
Block a user