-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·124 lines (111 loc) · 3.82 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·124 lines (111 loc) · 3.82 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
124
#!/usr/bin/env bash
cd $(dirname $0)
echo "Workdir : $(pwd)"
main_dir=$(pwd)
if [ ! -z $1 ] && [ $1 = "nobuild" ] ; then
echo "Skipping building ...";
else
echo "Starting to build ...";
./configure
./build.sh
if [ $? -ne 0 ] ; then
echo "Building failed";
exit 2;
fi
export PATH=$PATH:${main_dir}/build/install/bin
fi
echo "Start to running sanity tests";
cd ./testcase/simple
echo "Workdir : $(pwd)"
run_test_fail() {
((ongoing=ongoing + 1))
opts="$*"
echo "[${ongoing}/${total}] Running to-fail test >> [compiler ${opts}]";
compiler ${opts} &> test.log
ret=$?
if [ $ret -eq 0 ] ; then
echo "[${ongoing}/${total}] Testing of running 'compiler $opts' failed with $ret, it should have reported error";
exit 2;
fi
}
run_test_pass() {
opts="$*"
((ongoing=ongoing + 1))
echo "[${ongoing}/${total}] Running test >> [compiler ${opts}]";
compiler ${opts} &> test.log
ret=$?
if [ $ret -ne 0 ] ; then
echo "[${ongoing}/${total}] Testing of running 'compiler $opts' failed with $ret, it should have returned 0";
exit 2;
fi
}
total=11;
ongoing=0;
run_test_pass -h;
run_test_fail -S -O2;
run_test_pass -S a.c;
run_test_pass a.c -O2 -S -o b.s;
run_test_pass -S a.c -m32;
run_test_fail -S a.c -c;
run_test_pass -S a.c -x c++;
run_test_pass -S a.c -x c;
run_test_pass -S a.c -x java;
run_test_pass -S a.c -o a.s -x c -m32;
run_test_pass -S a.c -o a.s -x c -m32 -I. -I/a/b/c;
echo "[${ongoing}/${total}] Testing completed."
# ===========================================================================
# 二进制 IR dump / load round-trip 测试 (Step 11 / Step 12)
# ===========================================================================
echo
echo "Start to running IR dump/load round-trip tests";
irb_dir=/tmp/iririo_test
rm -rf "$irb_dir"
mkdir -p "$irb_dir"
# Layer 2: textual round-trip — dump 后 load+再 dump, 两份 .txt 必须一致
# Layer 3: .s 端到端 — 直接编译 vs. dump-then-load 编译, .s 必须字节相同
irb_total=0
irb_pass=0
irb_fail=0
run_irb_test() {
local f="$1"
local base=$(basename "$f" .sy)
((irb_total=irb_total + 1))
# Layer 2: textual round-trip
compiler --feonly --dump-ir-after=fe="$irb_dir/$base.fe.irb" \
--dump-textual "$f" >/dev/null 2>&1
if [ ! -s "$irb_dir/$base.fe.irb" ]; then
echo "[IRB][$base] FAIL — first dump produced empty file";
((irb_fail=irb_fail + 1)); return;
fi
compiler --load-ir="$irb_dir/$base.fe.irb" --feonly \
--dump-ir-after=fe="$irb_dir/$base.reload.irb" \
--dump-textual "$f" >/dev/null 2>&1
if ! diff -q "$irb_dir/$base.fe.irb.txt" "$irb_dir/$base.reload.irb.txt" >/dev/null 2>&1; then
echo "[IRB][$base] FAIL — textual round-trip diff";
((irb_fail=irb_fail + 1)); return;
fi
# Layer 3: .s 端到端 diff
compiler -S "$f" -o "$irb_dir/$base.A.s" >/dev/null 2>&1
compiler --load-ir="$irb_dir/$base.fe.irb" -S "$f" \
-o "$irb_dir/$base.B.s" >/dev/null 2>&1
if [ ! -s "$irb_dir/$base.A.s" ] || [ ! -s "$irb_dir/$base.B.s" ]; then
echo "[IRB][$base] FAIL — .s output missing (A=$(stat -f%z "$irb_dir/$base.A.s" 2>/dev/null || echo 0), B=$(stat -f%z "$irb_dir/$base.B.s" 2>/dev/null || echo 0))";
((irb_fail=irb_fail + 1)); return;
fi
if ! diff -q "$irb_dir/$base.A.s" "$irb_dir/$base.B.s" >/dev/null 2>&1; then
echo "[IRB][$base] FAIL — .s diff between direct vs. load-ir";
((irb_fail=irb_fail + 1)); return;
fi
((irb_pass=irb_pass + 1))
echo "[IRB][$base] OK"
}
# 选取若干 .sy 用例做 round-trip
for f in add1.sy ; do
if [ -f "$f" ]; then
run_irb_test "$f"
fi
done
echo "[IRB] Summary: $irb_pass/$irb_total passed, $irb_fail failed"
if [ $irb_fail -gt 0 ]; then
exit 3;
fi