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
8 changes: 6 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ELFUSE_HOST_NOFILE_MIN ?= $(shell bash "$(CURDIR)/tests/test-config.sh" --host-n
test-sysroot-create-paths test-fork-ipc-protocol-host \
test-vcpu-run-hooks-host test-identity-override-host \
test-dynamic-array-host test-string-builder-host test-gdbstub-host \
test-config \
test-config test-runner \
test-mremap-tail-emfile \
test-proctitle-host test-proctitle-low-stack \
test-sysroot-procfs-exec test-sysroot-fd-magiclink \
Expand Down Expand Up @@ -66,6 +66,10 @@ test-hello: $(ELFUSE_BIN) $(TEST_HELLO_DEP)
test-config:
@bash tests/test-config-cli.sh

## Verify output matching and exit status checks in the shared shell runner
test-runner:
@bash tests/test-runner.sh

## Run the libc-based file-backed region removal EMFILE regression probe
test-mremap-tail-emfile: $(ELFUSE_BIN) $(BUILD_DIR)/test-mremap-tail-emfile
@printf "$(BLUE)▸ Running$(RESET) test-mremap-tail-emfile\n"
Expand Down Expand Up @@ -283,7 +287,7 @@ check-sanitizer: $(ELFUSE_BIN) $(TEST_DEPS) $(CHECK_HOST_UNIT_BINS)
$(CHECK_SHARED_LANES)

## Run the unit test suite plus busybox applet validation
check: $(ELFUSE_BIN) $(TEST_DEPS) check-syscall-coverage check-eintr-contract check-lock-order check-atomics check-ascii check-svc-tails check-skill-refs test-config \
check: $(ELFUSE_BIN) $(TEST_DEPS) check-syscall-coverage check-eintr-contract check-lock-order check-atomics check-ascii check-svc-tails check-skill-refs test-config test-runner \
$(CHECK_HOST_UNIT_BINS)
@bash tests/driver.sh -e $(ELFUSE_BIN) -d $(TEST_DIR) -v
$(CHECK_SHARED_LANES)
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/test-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ run_check()
test_report fail "$tool" " (exit rc=$rc)"
test_excerpt "$output"
fail=$((fail + 1))
elif printf "%s\n" "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Six identical copies of this pipeline survive outside this file, all under set -euo pipefail: tests/test-matrix.sh:565,633 and tests/test-static-bins.sh:93,127,161,358. They lose a matching pattern on large output exactly the way these two did, and the new lane does not reach them. Apply the same here-string to all six.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the here-string change to all six checks in 6a85186.

test_report ok "$tool"
pass=$((pass + 1))
else
Expand Down Expand Up @@ -324,7 +324,7 @@ run_pipe()
test_report fail "$tool" " (exit rc=$rc)"
test_excerpt "$output"
fail=$((fail + 1))
elif printf "%s\n" "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$tool"
pass=$((pass + 1))
else
Expand Down
4 changes: 2 additions & 2 deletions tests/test-matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ test_check()
test_report fail "$label" " (exit $rc)"
test_excerpt "$output"
fail=$((fail + 1))
elif echo "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down Expand Up @@ -630,7 +630,7 @@ test_pipe()
test_report fail "$label" " (exit $rc)"
test_excerpt "$output"
fail=$((fail + 1))
elif echo "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down
59 changes: 59 additions & 0 deletions tests/test-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# Copyright 2026 elfuse contributors
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

if [ "${1:-}" = "--emit" ]; then
awk 'BEGIN {
print "match-begin"
# Keep output larger than pipe capacity to expose early-match SIGPIPE.
for (i = 0; i < 30000; i++)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30000 is load-bearing: it is what pushes the emitted output past the pipe buffer so the pre-fix writer takes SIGPIPE. Nothing here says so, so a later trim to something that fits in 64 KB leaves this lane green against the bug it exists to catch. State the constraint in one line above the loop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the pipe-capacity constraint above the loop in d1275e0.

print "abcdefghijklmnopqrstuvwxyz"
print "match-end"
}'
exit "$2"
fi

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
export TEST_SAMPLE_TIMEOUTS=0
TEST_RUNNER=("$BASH")
BIN="$SCRIPT_DIR"

# shellcheck source=tests/lib/test-runner.sh
. "$SCRIPT_DIR/lib/test-runner.sh"

checks=0
failures=0

expect_result()
{
local runner="$1" label="$2" pattern="$3" rc="$4" want="$5"
local output
checks=$((checks + 1))
# Each subshell inherits zero pass and fail counts and discards updates.
if output=$(
if [ "$runner" = run_pipe ]; then
run_pipe test-runner.sh "$pattern" input --emit "$rc"
else
run_check test-runner.sh "$pattern" --emit "$rc"
fi
[ "$pass" -eq "$want" ] && [ "$fail" -eq "$((1 - want))" ]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads the counters from the sourced lib and only sees a zero baseline because the command substitution gives each call its own subshell. Drop that subshell later and every assertion after the first compares accumulated totals instead. Name the dependency in one line so the next reader does not refactor it away.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented the subshell isolation of the pass/fail counters in d1275e0.

); then
printf 'PASS: %s %s\n' "$runner" "$label"
else
printf 'FAIL: %s %s\n%s\n' "$runner" "$label" "$output" >&2
failures=$((failures + 1))
fi
}

for runner in run_check run_pipe; do
expect_result "$runner" early-match '^match-begin$' 0 1
expect_result "$runner" late-match '^match-end$' 0 1
expect_result "$runner" missing-pattern '^absent$' 0 0
expect_result "$runner" failed-command '^match-begin$' 7 0
done

printf 'test-runner: %s checks, %s failures\n' "$checks" "$failures"
[ "$failures" -eq 0 ]
8 changes: 4 additions & 4 deletions tests/test-static-bins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ srun_check()
if [ "$rc" -eq 124 ]; then
test_report fail "$label" " (timeout)"
fail=$((fail + 1))
elif echo "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down Expand Up @@ -124,7 +124,7 @@ srun_pipe()
if [ "$rc" -eq 124 ]; then
test_report fail "$label" " (timeout)"
fail=$((fail + 1))
elif echo "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down Expand Up @@ -158,7 +158,7 @@ srun_script()
if [ "$rc" -eq 124 ]; then
test_report fail "$label" " (timeout)"
fail=$((fail + 1))
elif echo "$output" | grep -qE "$pattern"; then
elif grep -qE "$pattern" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down Expand Up @@ -355,7 +355,7 @@ if [ -n "$DIFF_BIN" ]; then
if [ "$rc" -eq 124 ]; then
test_report fail "$label" " (timeout)"
fail=$((fail + 1))
elif [ "$rc" = "1" ] && echo "$output" | grep -qE "^[<>]"; then
elif [ "$rc" = "1" ] && grep -qE "^[<>]" <<< "$output"; then
test_report ok "$label"
pass=$((pass + 1))
else
Expand Down