Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions nvx-rs/src/guest/exec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
);
Expand Down
6 changes: 4 additions & 2 deletions nvx-rs/src/guest/managed_agent/dispatch/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 13 additions & 13 deletions scripts/test_nvx_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
),
):
Expand Down Expand Up @@ -11532,15 +11530,17 @@ 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:
leaked.kill()
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")
Expand Down
Loading