-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.sh
executable file
·141 lines (133 loc) · 2.46 KB
/
test.sh
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Execution Tests with Binary Files
function echo_ndisasm() {
echo "ndisasm -b 32 $1"
echo
ndisasm -b 32 $1
echo
}
function echo_output() {
echo "./dax86 $1"
echo
echo "$2"
echo
}
function run_test() {
test_dir="./tests/exec/$1"
test_path="$test_dir/$1.bin"
expected_path="$test_dir/expected.txt"
verbose=false
if [ "$2" == "-v" ]; then
verbose=true
fi
# start of test
echo "------------------------------------------------"
echo "Building test binary $1..."
build_output=$(make -C $test_dir)
if [ "$verbose" = true ]; then
echo
echo "$build_output"
echo
fi
echo "Running test with $1..."
output=$(./dax86 $test_path test -v)
if [[ $output == *"End of program :)"* ]]; then
echo "[Run: SUCCESS]"
if [ "$verbose" = true ]; then
echo
echo_ndisasm "$test_path"
echo_output "$test_path" "$output"
fi
else
echo "[Run: FAILURE]"
echo
echo_ndisasm "$test_path"
echo_output "$test_path" "$output"
exit 1
fi
if [ -f "${expected_path}" ]
then
echo "[Assertion]"
line_num=0
while IFS= read -r line; do
if [[ $output == *"$line"* ]]; then
if [ "$verbose" = true ]; then
echo "Line ${line_num}: Pass"
fi
else
echo "Line ${line_num}: Fail"
echo
echo_ndisasm "$test_path"
echo_output "$test_path" "$output"
exit 1
fi
line_num=$((line_num+1))
done < "${expected_path}"
echo "All check passed."
else
echo "expected.txt Not Found"
fi
echo
}
# Files below do not run after 0x7c00 offset:
# tests/mov_jmp/mov_jmp.bin
#
# Files below require input:
# tests/io/in.bin
# tests/io/in_display.bin
# tests/rep/rep.bin
#
# Binary is more than 512 bytes (1 sector):
# tests/mp/mp.bin (prints "c" "i" "m" "p"): requires 1024 bytes.
# tests/console/console.bin (prints "test123"): requires 2048 bytes.
function test_all() {
for i in \
"modrm"\
"org_jmp"\
"call"\
"main_func"\
"args"\
"if"\
"flags_set"\
"flags_clear"\
"if"\
"jmp_c"\
"io_out"\
"seg"\
"or"\
"sub"\
"and"\
"xor"\
"pusha"\
"code_80"\
"test"\
"xchg"\
"mov"\
"pop"\
"code_c0"\
"loop"\
"jmp_far"\
"jmp_far16"\
"call_far"\
"call_far16"\
"moffs"\
"str_8"\
"str_32"\
"gdt"\
"mul"\
"div"\
"disk"\
"movzx"\
"lapic"\
"ioapic"
do
run_test $i
done
}
function main() {
if [ -z "$1" ]; then
test_all
else
run_test $1 "-v"
fi
}
main $1