-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest
More file actions
executable file
·123 lines (98 loc) · 3.35 KB
/
Copy pathtest
File metadata and controls
executable file
·123 lines (98 loc) · 3.35 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
bsd_md5=false
# BSD MD5 is superior!
if command -v md5 > /dev/null; then
echo "Info: using BSD md5."
bsd_md5=true
elif command -v md5sum > /dev/null; then
echo "Info: using GNU Coreutils md5sum."
else
echo "Error: could not find a md5 or md5sum command to verify tests!"
exit 1
fi
if [ $# -ne 2 ]; then
echo "Error: You need to provide 2 arguments."
if [ -z "$1" ]; then
echo "Error: The 1st argument must be redump format \"Parasite Eve (USA) (Disc 1).bin\""
elif [ -z "$2" ]; then
echo "Error: The 2nd argument must be redump format \"Ridge Racer (USA) (Track 01).bin\""
fi
exit 1
fi
# Put temp directory in /var/tmp to guarantee enough space.
tmp=$(mktemp -d /var/tmp/test-edcre.XXX)
# When this script exits, automatically delete the temp directory.
cleanup()
{
if [[ -e "$tmp" ]]; then
echo "Clearing temp files..."
rm -r "$tmp"
fi
}
trap cleanup EXIT
# Regenerate executable regardless to apply any possible code changes.
make -C "$(dirname "$0")"
# Generate checksums for verification compare before possible EDC/ECC changes.
for arg in "$@"; do
echo "Argument: $arg"
rm -f $tmp/*.bin
cp -v "$arg" $tmp
if [ "$bsd_md5" == true ]; then
md5 -q $tmp/*.bin >> $tmp/before-checksums.txt
else
md5sum $tmp/*.bin | awk '{ print $1 }' >> $tmp/before-checksums.txt
fi
done
if [ "$1" == "update" ] || [ ! -e "$(dirname "$0")"/"tests/known-good-before-checksums.txt" ]; then
cp -v $tmp/before-checksums.txt "$(dirname "$0")"/tests/known-good-before-checksums.txt
echo "Known good before checksums updated for test suite."
fi
test_number=1
fail_count=0
# Verify before checksums.
while read -r line1 && read -r line2 <&3; do
if [ "$line1" != "$line2" ]; then
echo "Before test $test_number FAILED to match known good checksum!"
((fail_count++))
else
echo "Before test $test_number matched known good checksum."
fi
((test_number++))
done < "$(dirname "$0")"/tests/known-good-before-checksums.txt 3< $tmp/before-checksums.txt
if [ $fail_count -eq 0 ]; then
echo "All before tests PASSED successfully!"
else
echo "$fail_count before test FAILED!"
fi
# Generate checksums for verification compare after possible EDC/ECC changes.
for arg in "$@"; do
rm -f $tmp/*.bin
cp -v "$arg" $tmp
build/edcre -v $tmp/*.bin
if [ "$bsd_md5" == true ]; then
md5 -q $tmp/*.bin >> $tmp/after-checksums.txt
else
md5sum $tmp/*.bin | awk '{ print $1 }' >> $tmp/after-checksums.txt
fi
done
if [ "$1" == "update" ] || [ ! -e "$(dirname "$0")"/"tests/known-good-after-checksums.txt" ]; then
cp -v $tmp/after-checksums.txt "$(dirname "$0")"/tests/known-good-after-checksums.txt
echo "Known good after checksums updated for test suite."
fi
test_number=1
fail_count=0
# Verify after checksums.
while read -r line1 && read -r line2 <&3; do
if [ "$line1" != "$line2" ]; then
echo "After test $test_number FAILED to match known good checksum!"
((fail_count++))
else
echo "After test $test_number matched known good checksum."
fi
((test_number++))
done < "$(dirname "$0")"/tests/known-good-after-checksums.txt 3< $tmp/after-checksums.txt
if [ $fail_count -eq 0 ]; then
echo "All after tests PASSED successfully!"
else
echo "$fail_count after test FAILED!"
fi