| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script runs a given executable using qemu, and compare its standard |
| 4 | # output with an expected plugin output. |
| 5 | # Each line of output is searched (as a regexp) in the expected plugin output. |
| 6 | |
| 7 | set -euo pipefail |
| 8 | |
| 9 | die() |
| 10 | { |
| 11 | echo "$@" 1>&2 |
| 12 | exit 1 |
| 13 | } |
| 14 | |
| 15 | check() |
| 16 | { |
| 17 | file=$1 |
| 18 | pattern=$2 |
| 19 | grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in $file" |
| 20 | } |
| 21 | |
| 22 | [ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file" |
| 23 | |
| 24 | qemu_bin=$1; shift |
| 25 | exe=$1;shift |
| 26 | plugin_out=$1; shift |
| 27 | |
| 28 | expected() |
| 29 | { |
| 30 | $qemu_bin $exe || |
| 31 | die "running $exe failed" |
| 32 | } |
| 33 | |
| 34 | expected | while read line; do |
| 35 | check "$plugin_out" "$line" |
| 36 | done |