Skip to content

Commit 8289b1a

Browse files
committed
Rework regtest runner
The C++ script is rewritten in Makefile and shell script for concision.
1 parent 061f8dd commit 8289b1a

File tree

9 files changed

+100
-283
lines changed

9 files changed

+100
-283
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
*.bin
22
*.o
33
*.a
4+
*.so
5+
*.exe
6+
*.out
47
src/e9patch/e9loader_*.c
58
e9patch
69
e9tool
10+
test/regtest/bugs
11+
test/regtest/dl
12+
test/regtest/fini
13+
test/regtest/init
14+
test/regtest/inst
15+
test/regtest/patch
16+
test/regtest/test
17+
test/regtest/test.libc
18+
test/regtest/test.pie
19+
test/regtest/test_c
20+
test/regtest/test_c.debug

Makefile

Lines changed: 8 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

33
#########################################################################
44
# BUILD COMMON
@@ -66,6 +66,7 @@ clean:
6666
$(MAKE) -C contrib/zydis clean
6767
rm -rf $(E9PATCH_OBJS) $(E9TOOL_OBJS) e9patch e9tool \
6868
src/e9patch/e9loader_*.c e9loader_*.o e9loader_*.bin
69+
$(MAKE) -C test/regtest clean-check
6970

7071
src/e9patch/e9loader_elf.c: src/e9patch/e9loader_elf.cpp
7172
$(CXX) -std=c++11 -Wall -fno-stack-protector -Wno-unused-function -fPIC \
@@ -82,6 +83,9 @@ src/e9patch/e9loader_pe.c: src/e9patch/e9loader_pe.cpp
8283
src/e9patch/e9elf.o: src/e9patch/e9loader_elf.c
8384
src/e9patch/e9pe.o: src/e9patch/e9loader_pe.c
8485

86+
check: all
87+
$(MAKE) -C test/regtest
88+
8589
install: all
8690
install -d "$(DESTDIR)$(PREFIX)/bin"
8791
install -m 755 e9patch "$(DESTDIR)$(PREFIX)/bin/e9patch"
@@ -164,3 +168,6 @@ debug: dev
164168

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

test/regtest/Makefile

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,72 @@
1+
.PHONY: check clean-check
2+
13
FCF_NONE := $(shell \
24
if gcc -fcf-protection=none --version 2>&1 | grep -q 'unrecognized'; \
35
then true; \
46
else echo -fcf-protection=none; fi)
57

6-
all:
8+
BASE ::= test test.pie bugs test.libc libtest.so test_c test_c.debug example.so
9+
TRAMPOLINE ::= inst patch dl init fini
10+
IN ::= $(wildcard *.in)
11+
EXE ::= $(IN:.in=.exe)
12+
13+
check: regtest $(EXE)
14+
./$^
15+
16+
%.exe: in=$(shell head -1 $<)
17+
%.exe: %.in $(BASE) $(TRAMPOLINE)
18+
../../e9tool $(E9TOOL_OPTIONS) -M 'addr >= &"entry"' $(in)\
19+
-E data..data_END -E data2...text -E .text..begin -o $@
20+
21+
test:
722
gcc -x assembler-with-cpp -o test test.s -no-pie -nostdlib \
823
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
924
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
25+
26+
test.pie:
1027
gcc -x assembler-with-cpp -o test.pie test.s -pie -nostdlib \
1128
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
1229
-Wl,-z -Wl,max-page-size=4096 -DPIE=1 \
1330
-Wl,--export-dynamic
31+
32+
bugs:
1433
gcc -x assembler-with-cpp -o bugs bugs.s -no-pie -nostdlib \
1534
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
1635
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
36+
37+
test.libc:
1738
gcc -x assembler-with-cpp -o test.libc test_libc.s -pie -Wl,--export-dynamic
39+
40+
libtest.so:
1841
gcc -x assembler-with-cpp -shared -o libtest.so libtest.s
42+
43+
test_c:
1944
gcc -O2 -fPIC $(FCF_NONE) -pie -o test_c test_c.c \
2045
-Wl,--export-dynamic -U_FORTIFY_SOURCE
2146
strip test_c
47+
48+
test_c.debug:
2249
gcc -O0 -g -fPIC -pie -o test_c.debug test_c.c
50+
51+
inst:
2352
../../e9compile.sh inst.c -I ../../examples/
53+
54+
patch:
2455
../../e9compile.sh patch.cpp -std=c++11 -I ../../examples/
56+
57+
dl:
2558
NO_SIMD_CHECK=1 ../../e9compile.sh dl.c -I ../../examples/
59+
60+
init:
2661
../../e9compile.sh init.c -I ../../examples/
62+
63+
fini:
2764
../../e9compile.sh fini.c -I ../../examples/
65+
66+
example.so:
2867
g++ -std=c++11 -fPIC -shared -o example.so -O2 \
2968
../../examples/plugins/example.cpp -I ../../src/e9tool/
30-
g++ -std=c++11 -pie -fPIC -o regtest regtest.cpp -O2
31-
echo "XXX" > FILE.txt
32-
chmod 0640 FILE.txt
3369

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

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

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
LD_PRELOAD=$PWD/init_dso.exe ./test.pie
1+
#!/bin/sh
2+
LD_PRELOAD=./init_dso.exe ./test.pie

test/regtest/init_dso_2.cmd

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
LD_PRELOAD=$PWD/init_dso.exe ./test.pie a b c 1 2 3
1+
#!/bin/sh
2+
LD_PRELOAD=./init_dso.exe ./test.pie a b c 1 2 3

test/regtest/regtest

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 ./exec.sh ./$cmd 1>$out 2>&1
12+
else ./exec.sh ./$exe 1>$out 2>&1
13+
fi
14+
15+
diff -u $out $exp
16+
if test $? -ne 0
17+
then fails+=($tst)
18+
fi
19+
done
20+
21+
if test "$fails"
22+
then
23+
echo "Failing ${#fails[@]}/$# tests: ${fails[@]}"
24+
exit 1
25+
fi

0 commit comments

Comments
 (0)