Skip to content

Commit 703e5c6

Browse files
committed
Rework regtest runner
The C++ script is rewritten in Makefile and shell script for concision.
1 parent 29dc57d commit 703e5c6

File tree

7 files changed

+84
-280
lines changed

7 files changed

+84
-280
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all clean install dev release debug sanitize
1+
.PHONY: all clean install check dev release debug sanitize check-debug
22
.SECONDEXPANSION:
33

44
#########################################################################
@@ -89,6 +89,9 @@ contrib/zydis/libZydis.a:
8989
contrib/libdw/libdw.a:
9090
$(MAKE) -C contrib/libdw
9191

92+
check: e9tool
93+
$(MAKE) -C test/regtest
94+
9295
install: all
9396
install -d "$(DESTDIR)$(PREFIX)/bin"
9497
install -m 755 e9patch "$(DESTDIR)$(PREFIX)/bin/e9patch"
@@ -165,3 +168,6 @@ debug: dev
165168

166169
sanitize: CXXFLAGS += -O0 -g -fsanitize=address
167170
sanitize: dev
171+
172+
check-debug: debug
173+
$(MAKE) -C test/regtest

test/regtest/Makefile

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,69 @@ FCF_NONE := $(shell \
33
then true; \
44
else echo -fcf-protection=none; fi)
55

6-
all:
6+
BASE ::= test test.pie bugs test.libc libtest.so test_c test_c.debug example.so
7+
TRAMPOLINE ::= inst patch dl init fini
8+
IN ::= $(wildcard *.in)
9+
EXE ::= $(IN:.in=.exe)
10+
11+
check: regtest $(EXE)
12+
./$^
13+
14+
%.exe: in=$(shell head -1 $<)
15+
%.exe: %.in $(BASE) $(TRAMPOLINE)
16+
../../e9tool $(E9TOOL_OPTIONS) -M 'addr >= &"entry"' $(in)\
17+
-E data..data_END -E data2...text -E .text..begin -o $@
18+
19+
test:
720
gcc -x assembler-with-cpp -o test test.s -no-pie -nostdlib \
821
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
922
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
23+
24+
test.pie:
1025
gcc -x assembler-with-cpp -o test.pie test.s -pie -nostdlib \
1126
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
1227
-Wl,-z -Wl,max-page-size=4096 -DPIE=1 \
1328
-Wl,--export-dynamic
29+
30+
bugs:
1431
gcc -x assembler-with-cpp -o bugs bugs.s -no-pie -nostdlib \
1532
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
1633
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
34+
35+
test.libc:
1736
gcc -x assembler-with-cpp -o test.libc test_libc.s -pie -Wl,--export-dynamic
37+
38+
libtest.so:
1839
gcc -x assembler-with-cpp -shared -o libtest.so libtest.s
40+
41+
test_c:
1942
gcc -O2 -fPIC $(FCF_NONE) -pie -o test_c test_c.c \
2043
-Wl,--export-dynamic -U_FORTIFY_SOURCE
2144
strip test_c
45+
46+
test_c.debug:
2247
gcc -O0 -g -fPIC -pie -o test_c.debug test_c.c
48+
49+
inst:
2350
../../e9compile.sh inst.c -I ../../examples/
51+
52+
patch:
2453
../../e9compile.sh patch.cpp -std=c++11 -I ../../examples/
54+
55+
dl:
2556
NO_SIMD_CHECK=1 ../../e9compile.sh dl.c -I ../../examples/
57+
58+
init:
2659
../../e9compile.sh init.c -I ../../examples/
60+
61+
fini:
2762
../../e9compile.sh fini.c -I ../../examples/
63+
64+
example.so:
2865
g++ -std=c++11 -fPIC -shared -o example.so -O2 \
2966
../../examples/plugins/example.cpp -I ../../src/e9tool/
30-
g++ -std=c++11 -pie -fPIC -o regtest regtest.cpp -O2
3167

32-
clean:
33-
rm -f *.log *.out *.exe test test.pie test.libc libtest.so inst inst.o \
34-
patch patch.o init init.o regtest
68+
clean-check:
69+
rm -f $(BASE) $(TRAMPOLINE) $(EXE)
70+
71+
.PHONY: check clean-check

test/regtest/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ README
33

44
To run the tests:
55

6-
$ make
7-
$ ./regtest
8-
6+
make E9TOOL_OPTIONS=

test/regtest/init_dso.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
LD_PRELOAD=$PWD/init_dso.exe ./test.pie
1+
LD_PRELOAD=./init_dso.exe ./test.pie

test/regtest/init_dso_2.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
LD_PRELOAD=$PWD/init_dso.exe ./test.pie a b c 1 2 3
1+
LD_PRELOAD=./init_dso.exe ./test.pie a b c 1 2 3

test/regtest/regtest

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
fails=()
3+
for exe in $*
4+
do
5+
tst=${exe%.exe}
6+
cmd=$tst.cmd
7+
out=$tst.out
8+
exp=$tst.exp
9+
10+
if test -f $cmd
11+
then env $(cat $cmd) 1>$out 2>&1
12+
else ./$exe 1>$out 2>&1
13+
fi 2>/dev/null
14+
case $? in
15+
"132") echo Illegal instruction;;
16+
"133") echo Trace/breakpoint trap;;
17+
"134") echo Aborted;;
18+
"138") echo User defined signal 1;;
19+
"139") echo Segmentation fault;;
20+
esac >>$out
21+
22+
diff -u $out $exp
23+
if test $? -ne 0
24+
then fails+=($tst)
25+
fi
26+
done
27+
28+
if test "$fails"
29+
then
30+
echo "Failing ${#fails[@]}/$# tests: ${fails[@]}"
31+
exit 1
32+
fi

0 commit comments

Comments
 (0)