Skip to content

Commit

Permalink
run-tests: use empty fifo instead of /dev/zero if stdin is /dev/null
Browse files Browse the repository at this point in the history
To work around a qemu bug [1] we redirect stdin of virtme-run from
/dev/zero. This has the possible downside that a read from /dev/zero
always returns data. This means that anything reading stdin in the
VM will get a bunch of garbage.

Detect a closed stdin and replace it with an empty fifo.

1: amluto/virtme#33
  • Loading branch information
lmb committed May 21, 2021
1 parent 95e8687 commit d8f334f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ if [[ "${1:-}" = "--exec-vm" ]]; then
output="$(mktemp -d)"
printf -v cmd "%q " "$@"

if [[ "$(stat -c '%t:%T' -L /proc/$$/fd/0)" == "1:3" ]]; then
# stdin is /dev/null, which doesn't play well with qemu. Use a fifo as a
# blocking substitute.
mkfifo "${output}/fake-stdin"
# Open for reading and writing to avoid blocking.
exec 0<> "${output}/fake-stdin"
rm "${output}/fake-stdin"
fi

$sudo virtme-run --kimg "${input}/bzImage" --memory 768M --pwd \
--rwdir="${testdir}=${testdir}" \
--rodir=/run/input="${input}" \
--rwdir=/run/output="${output}" \
--script-sh "PATH=\"$PATH\" \"$script\" --exec-test $cmd" \
--qemu-opts -smp 2 < /dev/zero # need at least two CPUs for some tests
--qemu-opts -smp 2 # need at least two CPUs for some tests

if [[ ! -e "${output}/success" ]]; then
exit 1
Expand Down

0 comments on commit d8f334f

Please sign in to comment.