diff --git a/nvx-rs/src/guest/exec/tests.rs b/nvx-rs/src/guest/exec/tests.rs index 5eddf1a0a..d17c6c623 100644 --- a/nvx-rs/src/guest/exec/tests.rs +++ b/nvx-rs/src/guest/exec/tests.rs @@ -38,6 +38,12 @@ const PATIENCE: Duration = Duration::from_secs(20); /// the execution, and the allowance that they grant each stream at a time. const MAX_EVENT_BYTES: usize = 4096; +/// More bytes than a program's output pipe can hold, even after the program grows the pipe, as +/// uutils' `head -c` (Ubuntu 26.04's `head`) does to fit what it copies. Without privileges, a +/// program can grow a pipe to `/proc/sys/fs/pipe-max-size` at most, 1 MiB by default, and uutils +/// grows it to 1 MiB at most. +const MORE_THAN_A_PIPE_HOLDS: usize = 4 * 1024 * 1024; + /// Spawns `command` with new pipes, its standard input piped if `input`, in a process group of /// its own, and starts its execution with `options`. fn start(command: Command, input: bool, options: Options) -> Execution { @@ -288,7 +294,7 @@ fn concurrent_executions_progress_independently() { #[test] fn a_stalled_sink_stalls_only_its_own_execution_and_loses_nothing() { - const LENGTH: usize = 256 * 1024; + const LENGTH: usize = MORE_THAN_A_PIPE_HOLDS; let mut stalled = start( shell(&format!("head -c {LENGTH} /dev/zero")), false, @@ -337,7 +343,10 @@ fn a_stalled_sink_stalls_only_its_own_execution_and_loses_nothing() { fn cancellation_ends_a_stalled_program_and_the_caller_discards_the_rest() { // The program fills its pipe with the first page, which any pipe holds, before it says so. let mut execution = start( - shell("head -c 4096 /dev/zero; printf ready >&2; exec head -c 262144 /dev/zero"), + shell(&format!( + "head -c 4096 /dev/zero; printf ready >&2; \ + exec head -c {MORE_THAN_A_PIPE_HOLDS} /dev/zero" + )), true, Options::new(), ); diff --git a/nvx-rs/src/guest/managed_agent/dispatch/tests.rs b/nvx-rs/src/guest/managed_agent/dispatch/tests.rs index fa1f74019..881b2c5dc 100644 --- a/nvx-rs/src/guest/managed_agent/dispatch/tests.rs +++ b/nvx-rs/src/guest/managed_agent/dispatch/tests.rs @@ -1375,12 +1375,14 @@ fn output_beyond_the_cap_ends_the_workload_after_the_reads_that_fit() -> TestRes let (temporary, mut harness) = direct_harness(); // As the C agent did, the agent forwards each read of up to 32 KiB while the output // stays within 1 MiB, and ends the workload at the first read beyond it, before the - // workload could leave its marker. + // workload could leave its marker. The workload writes 3 MiB into a pipe that holds 1 MiB + // at most, even after uutils' `head -c` (Ubuntu 26.04's `head`) grows it to fit what it + // copies, so it can finish only after the agent has read 2 MiB. let chunk = 32 * 1024; let marker = temporary.path().join("survived"); let script = format!( "head -c {} /dev/zero; touch '{}'", - protocol::MAX_OUTPUT_BYTES + protocol::MAX_OUTPUT_BYTES / 2, + 3 * protocol::MAX_OUTPUT_BYTES, marker.display() ); let mut replies = harness.request_all( diff --git a/scripts/test_nvx_tools.py b/scripts/test_nvx_tools.py index ca2c3729d..de16efcaa 100644 --- a/scripts/test_nvx_tools.py +++ b/scripts/test_nvx_tools.py @@ -11472,16 +11472,18 @@ def test_linux_runners_terminate_openvmm_left_by_earlier_jobs(self): self.assertIn("\nname=openvmm\n", script) if sys.platform != "linux": return - sleep = shutil.which("sleep") - if sleep is None: - self.skipTest("needs sleep") with tempfile.TemporaryDirectory() as temporary: # A uniquely named stand-in, so that the test never ends a real - # OpenVMM of the account that runs it. + # OpenVMM of the account that runs it: Python, through a link + # with the stand-in's name, since the kernel names a process after + # the file that it runs. A copy of sleep would not do: a + # multi-call coreutils, such as Ubuntu 26.04's, knows no program + # by that name. stand_in = f"nvx-leak-{os.getpid() % 100000}" executable = Path(temporary) / stand_in - shutil.copy(sleep, executable) + executable.symlink_to(sys.executable) + sleeper = [str(executable), "-c", "import time; time.sleep(300)"] check = script.replace("\nname=openvmm\n", f"\nname={stand_in}\n", 1) def run( @@ -11498,13 +11500,9 @@ def run( # The second stand-in ignores SIGTERM, which leaves SIGKILL. for command, status in ( - ([str(executable), "300"], -signal.SIGTERM), + (sleeper, -signal.SIGTERM), ( - [ - "bash", - "-c", - f"trap '' TERM; exec {shlex.quote(str(executable))} 300", - ], + ["bash", "-c", f"trap '' TERM; exec {shlex.join(sleeper)}"], -signal.SIGKILL, ), ): @@ -11532,7 +11530,9 @@ def run( self.assertIn( ", which an earlier job left running\n", result.stdout ) - self.assertIn(f" command: {executable} 300\n", result.stdout) + self.assertIn( + f" command: {' '.join(sleeper)}\n", result.stdout + ) self.assertEqual(leaked.returncode, status) finally: if leaked.poll() is None: @@ -11540,7 +11540,7 @@ def run( leaked.wait() # A zombie has already exited and its parent reaps it, and without # a leftover process, the step says nothing. - zombie = subprocess.Popen([executable, "300"]) + zombie = subprocess.Popen(sleeper) try: zombie.kill() stat = Path(f"/proc/{zombie.pid}/stat")