-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·83 lines (74 loc) · 2.33 KB
/
tests.sh
File metadata and controls
executable file
·83 lines (74 loc) · 2.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# Runs a series of sample programs in QEMU and checks that the standard output
# is as expected.
# Set this to 1 to exit on the first error
EXIT_FAST=0
FAILURE=0
fail_build() {
echo "***************************************************"
echo "test.sh FAIL: Binary $1 for target $2 returned non-zero"
echo "***************************************************"
FAILURE=1
if [ $EXIT_FAST == "1" ]; then
exit 1
fi
}
fail_diff() {
echo "***************************************************"
echo "test.sh MISMATCH: Binary $1 for target $2 mismatched"
echo "(You can re-run with UPDATE_OUT=1 to replace the reference file)"
echo "***************************************************"
FAILURE=1
if [ $EXIT_FAST == "1" ]; then
exit 1
fi
}
mkdir -p ./target
my_diff() {
file_a=$1
file_b=$2
# - Fix Windows path separators (\\) to look like UNIX ones (/) in the QEMU
# output
# - Fix the CRLF line endings in the files on disk, because git adds them to
# text files.
if [ "${UPDATE_OUT}" == "1" ]; then
# echo "Copying $file_b to $file_a... in $(pwd)"
cp $file_b $file_a
fi
if [ ! -f $1 ]; then
echo "File $1 is missing?!"
return 1
elif [ ! -f $1 ]; then
echo "File $2 is missing?!"
return 1
else
diff <(cat $file_a | tr -d '\r') <(cat $file_b | sed 's~\\\\~/~g')
result=$?
return $result
fi
}
directory=$1
shift
target=$1
shift
flags="$*"
echo "Running directory=$directory target=$target flags=$flags"
pushd $directory
cargo build --target=$target $flags || exit 1
for bin_path in src/bin/*.rs; do
filename=$(basename $bin_path)
binary=${filename%.rs}
cargo run --target=$target --bin $binary $flags > ./target/$binary-$target.out || fail_build $binary $target
my_diff ./reference/$binary-$target.out ./target/$binary-$target.out || fail_diff $binary $target
done
popd
if [ "$FAILURE" == "1" ]; then
echo "***************************************************"
echo "test.sh: Output comparison failed!"
echo "***************************************************"
exit 1
else
echo "***************************************************"
echo "test.sh: Everything matches :)"
echo "***************************************************"
fi