prplos/.gitlab/tests/cram/generic/ba-cli-stdin.t
Petr Štetiar e893e4d4f2 profiles: prpl_core.yml: feed_amx: amx-cli: bump stdin fix
Bump feed_amx to f44cd0908bf6 ("amx-cli: bump to PCF-2445 stdin fix")
so prpl_core uses the amx-cli PCF-2445 MR head.

This brings the reviewed runtime change series:
- 7c78345ad543 ("ci: enable support for Cobertura XML report generation")
- 93740e7127a4 ("include_priv: align private header guards")
- 6f245591b78e ("amx-cli: ignore stdin after positional command")

The amx-cli change makes positional amx-cli and ba-cli commands exit
after the requested command instead of reading inherited stdin. This
prevents cram-over-ssh scripts from having their remaining test input
consumed by ba-cli.

Add a generic cram regression test that verifies positional ba-cli
commands preserve inherited stdin and do not wait on an open stdin pipe,
while explicit automated stdin-script mode still reads stdin.

The cram expectations for existing ba-cli calls still modeled the old
interactive output shape: prompt/header text, command output, and a
trailing prompt or blank line from the inherited stdin session. After
the stdin fix, one-shot ba-cli commands emit only command output, so
those filters either drop real data or keep obsolete blank-line
expectations.  Adjust the affected tests to filter only prompts and
empty lines so they match the corrected one-shot contract.

One syslog cram check also reuses the TR-181 PatternMatch value as a
grep -E expression. That value is stored with syslog-ng/basic-regex
escaped grouping, so the prompt cleanup left grep -E comparing DHCP log
lines against \(o|tr181-|dnsmasq-\)?dhcp. Extract only the PatternMatch
assignment and translate escaped parentheses before using the value as an
ERE, otherwise valid DHCP log lines are reported as unexpected output.

References: PCF-2445, PCF-2495, PPM-4088
Signed-off-by: Petr Štetiar <petr.stetiar@prplfoundation.org>
signed-off-by: Hela Saadani <hela.saadani_ext@softathome.com>
2026-06-01 10:41:21 +00:00

54 lines
2.1 KiB
Perl

Create R alias:
$ alias R="${CRAM_REMOTE_COMMAND:-}"
Check that one-shot positional ba-cli commands do not consume inherited stdin:
$ R " \
> rm -f /tmp/test-ba-cli-stdin.out; \
> printf '%s\n' 'BA_CLI_STDIN_SENTINEL' | ba-cli -- help > /tmp/test-ba-cli-stdin.out 2>&1; \
> if grep -q 'BA_CLI_STDIN_SENTINEL' /tmp/test-ba-cli-stdin.out; then \
> echo stdin-consumed; \
> else \
> echo stdin-preserved; \
> fi \
> " </dev/null
stdin-preserved
Check that one-shot positional ba-cli commands do not wait for open stdin:
$ R " \
> rm -f /tmp/test-ba-cli-open-stdin.fifo /tmp/test-ba-cli-open-stdin.out /tmp/test-ba-cli-open-stdin.rc; \
> mkfifo /tmp/test-ba-cli-open-stdin.fifo; \
> (sleep 5 > /tmp/test-ba-cli-open-stdin.fifo) & writer=\$!; \
> (ba-cli -- help < /tmp/test-ba-cli-open-stdin.fifo > /tmp/test-ba-cli-open-stdin.out 2>&1; echo \$? > /tmp/test-ba-cli-open-stdin.rc) & cli=\$!; \
> for _ in 1 2 3; do [ -s /tmp/test-ba-cli-open-stdin.rc ] && break; sleep 1; done; \
> if [ ! -s /tmp/test-ba-cli-open-stdin.rc ]; then \
> kill \$cli 2>/dev/null || true; \
> echo positional-hung; \
> else \
> echo positional-exited; \
> fi; \
> kill \$writer 2>/dev/null || true; \
> rm -f /tmp/test-ba-cli-open-stdin.fifo /tmp/test-ba-cli-open-stdin.rc \
> " </dev/null
positional-exited
Check that explicit automated stdin-script mode still reads stdin:
$ R " \
> rm -f /tmp/test-ba-cli-automated-stdin.out /tmp/test-ba-cli-automated-stdin.rc; \
> (printf '%s\n' '!amx exit' | ba-cli -a > /tmp/test-ba-cli-automated-stdin.out 2>&1; echo \$? > /tmp/test-ba-cli-automated-stdin.rc) & cli=\$!; \
> for _ in 1 2 3; do [ -s /tmp/test-ba-cli-automated-stdin.rc ] && break; sleep 1; done; \
> if [ ! -s /tmp/test-ba-cli-automated-stdin.rc ]; then \
> kill \$cli 2>/dev/null || true; \
> echo automated-stdin-hung; \
> elif [ \"\$(cat /tmp/test-ba-cli-automated-stdin.rc)\" = 0 ]; then \
> echo automated-stdin-exited; \
> else \
> echo automated-stdin-failed; \
> fi; \
> rm -f /tmp/test-ba-cli-automated-stdin.rc \
> " </dev/null
automated-stdin-exited