aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/multiarch/check-plugin-output.sh
blob: 80607f04b5d95e1b698ccac0013f7d82661d2789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

# This script runs a given executable using qemu, and compare its standard
# output with an expected plugin output.
# Each line of output is searched (as a regexp) in the expected plugin output.

set -euo pipefail

die()
{
    echo "$@" 1>&2
    exit 1
}

check()
{
    file=$1
    pattern=$2
    grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in $file"
}

[ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file"

qemu_bin=$1; shift
exe=$1;shift
plugin_out=$1; shift

expected()
{
    $qemu_bin $exe ||
        die "running $exe failed"
}

expected | while read line; do
    check "$plugin_out" "$line"
done