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