Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework regtest runner #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
*.bin
*.o
*.a
*.so
*.exe
*.out
src/e9patch/e9loader_*.c
e9patch
e9tool
test/regtest/bugs
test/regtest/dl
test/regtest/fini
test/regtest/init
test/regtest/inst
test/regtest/patch
test/regtest/test
test/regtest/test.libc
test/regtest/test.pie
test/regtest/test_c
test/regtest/test_c.debug
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean install dev release debug sanitize
.PHONY: all clean install check dev release debug sanitize check-debug

#########################################################################
# BUILD COMMON
Expand Down Expand Up @@ -66,6 +66,7 @@ clean:
$(MAKE) -C contrib/zydis clean
rm -rf $(E9PATCH_OBJS) $(E9TOOL_OBJS) e9patch e9tool \
src/e9patch/e9loader_*.c e9loader_*.o e9loader_*.bin
$(MAKE) -C test/regtest clean-check

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

check: all
$(MAKE) -C test/regtest

install: all
install -d "$(DESTDIR)$(PREFIX)/bin"
install -m 755 e9patch "$(DESTDIR)$(PREFIX)/bin/e9patch"
Expand Down Expand Up @@ -164,3 +168,6 @@ debug: dev

sanitize: CXXFLAGS += -O0 -g -fsanitize=address
sanitize: dev

check-debug: debug
$(MAKE) -C test/regtest
82 changes: 60 additions & 22 deletions test/regtest/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,74 @@
.PHONY: check clean-check

E9TOOL ?= ../../e9tool
E9COMPILE ?= ../../e9compile.sh

FCF_NONE := $(shell \
if gcc -fcf-protection=none --version 2>&1 | grep -q 'unrecognized'; \
then true; \
else echo -fcf-protection=none; fi)

all:
gcc -x assembler-with-cpp -o test test.s -no-pie -nostdlib \
BASE ::= test test.pie bugs test.libc libtest.so test_c test_c.debug example.so
TRAMPOLINE ::= inst patch dl init fini
IN ::= $(wildcard *.in)
EXE ::= $(IN:.in=.exe)

check: regtest $(EXE)
./$^

%.exe: in=$(shell head -1 $<)
%.exe: %.in $(BASE) $(TRAMPOLINE) $(E9TOOL)
$(E9TOOL) $(E9TOOL_OPTIONS) -M 'addr >= &"entry"' $(in)\
-E data..data_END -E data2...text -E .text..begin -o $@

test: test.s
$(CC) -x assembler-with-cpp -o $@ $< -no-pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
gcc -x assembler-with-cpp -o test.pie test.s -pie -nostdlib \

test.pie: test.s
$(CC) -x assembler-with-cpp -o $@ $< -pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=1 \
-Wl,--export-dynamic
gcc -x assembler-with-cpp -o bugs bugs.s -no-pie -nostdlib \

bugs: bugs.s
$(CC) -x assembler-with-cpp -o $@ $< -no-pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
gcc -x assembler-with-cpp -o test.libc test_libc.s -pie -Wl,--export-dynamic
gcc -x assembler-with-cpp -shared -o libtest.so libtest.s
gcc -O2 -fPIC $(FCF_NONE) -pie -o test_c test_c.c \

test.libc: test_libc.s
$(CC) -x assembler-with-cpp -pie $< -Wl,--export-dynamic -o $@

libtest.so: libtest.s
$(CC) -x assembler-with-cpp $< -shared -o $@

test_c: test_c.c
$(CC) -O2 -fPIC $(FCF_NONE) -pie -o $@ $< \
-Wl,--export-dynamic -U_FORTIFY_SOURCE
strip test_c
gcc -O0 -g -fPIC -pie -o test_c.debug test_c.c
../../e9compile.sh inst.c -I ../../examples/
../../e9compile.sh patch.cpp -std=c++11 -I ../../examples/
NO_SIMD_CHECK=1 ../../e9compile.sh dl.c -I ../../examples/
../../e9compile.sh init.c -I ../../examples/
../../e9compile.sh fini.c -I ../../examples/
g++ -std=c++11 -fPIC -shared -o example.so -O2 \
../../examples/plugins/example.cpp -I ../../src/e9tool/
g++ -std=c++11 -pie -fPIC -o regtest regtest.cpp -O2
echo "XXX" > FILE.txt
chmod 0640 FILE.txt

clean:
rm -f *.log *.out *.exe test test.pie test.libc libtest.so inst inst.o \
patch patch.o init init.o regtest

test_c.debug: test_c.c
$(CC) -O0 -g -fPIC -pie $< -o $@

inst: inst.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

patch: patch.cpp ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -std=c++11 -I../../examples

dl: dl.c ../../examples/stdlib.c $(E9COMPILE)
NO_SIMD_CHECK=1 $(E9COMPILE) $< -I../../examples

init: init.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

fini: fini.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

example.so: ../../examples/plugins/example.cpp ../../src/e9tool/e9plugin.h
$(CXX) -std=c++11 -O2 -fPIC -I../../src/e9tool $< -shared -o $@

clean-check:
rm -f $(BASE) $(TRAMPOLINE) $(EXE)
rm -f *.out
4 changes: 1 addition & 3 deletions test/regtest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ README

To run the tests:

$ make
$ ./regtest

make E9TOOL_OPTIONS=
3 changes: 2 additions & 1 deletion test/regtest/init_dso.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LD_PRELOAD=$PWD/init_dso.exe ./test.pie
#!/bin/sh
LD_PRELOAD=./init_dso.exe ./test.pie
3 changes: 2 additions & 1 deletion test/regtest/init_dso_2.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LD_PRELOAD=$PWD/init_dso.exe ./test.pie a b c 1 2 3
#!/bin/sh
LD_PRELOAD=./init_dso.exe ./test.pie a b c 1 2 3
25 changes: 25 additions & 0 deletions test/regtest/regtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
fails=()
for exe in $*
do
tst=${exe%.exe}
cmd=$tst.cmd
out=$tst.out
exp=$tst.exp

if test -f $cmd
then ./exec.sh ./$cmd 1>$out 2>&1
else ./exec.sh ./$exe 1>$out 2>&1
fi

diff -u $out $exp
if test $? -ne 0
then fails+=($tst)
fi
done

if test "$fails"
then
echo "Failing ${#fails[@]}/$# tests: ${fails[@]}"
exit 1
fi
Loading