-
Notifications
You must be signed in to change notification settings - Fork 26
Avoid SIGPIPE in output pattern checks #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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++) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))" ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ] | ||
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.