diff options
author | norly <ny-git@enpas.org> | 2013-06-19 20:20:10 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-06-20 22:10:23 +0100 |
commit | 7f1a29e9e33059dfebdc24bb3ffaa3dac46b58f1 (patch) | |
tree | 89f3108016eb3440ec35a9b20957f46ef999cc5c /tests | |
parent | c98d704a812502c34d82e34949f37c8b87ae6018 (diff) |
Automate tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/01-noop32.test | 10 | ||||
-rw-r--r-- | tests/03-injection32.test | 11 | ||||
-rw-r--r-- | tests/05-detour.test | 11 | ||||
-rw-r--r-- | tests/06-data256mb.test | 10 | ||||
-rw-r--r-- | tests/Makefile | 37 | ||||
-rwxr-xr-x | tests/boilerplate.sh | 14 | ||||
-rw-r--r-- | tests/reference/puts-alternative32.o | bin | 0 -> 1128 bytes | |||
-rwxr-xr-x | tests/reference/putsmain32 | bin | 0 -> 6101 bytes | |||
-rwxr-xr-x | tests/reference/putsmain32-cloned | bin | 0 -> 6104 bytes | |||
-rwxr-xr-x | tests/reference/putsmain32-with-puts-alternative32 | bin | 0 -> 18696 bytes | |||
-rwxr-xr-x | tests/runtests.sh | 20 | ||||
-rw-r--r-- | tests/src/Makefile | 22 | ||||
-rw-r--r-- | tests/src/data256mb.c | 2 | ||||
-rw-r--r-- | tests/src/puts_alternative.c | 10 | ||||
-rw-r--r-- | tests/src/puts_noarg.c | 7 | ||||
-rw-r--r-- | tests/src/putsmain.c | 9 | ||||
-rw-r--r-- | tests/src/putsmainsub.c | 13 |
17 files changed, 176 insertions, 0 deletions
diff --git a/tests/01-noop32.test b/tests/01-noop32.test new file mode 100644 index 0000000..145bae3 --- /dev/null +++ b/tests/01-noop32.test @@ -0,0 +1,10 @@ +#!/bin/sh +source ./boilerplate.sh + +elfucli --input reference/putsmain32 \ + --output $BUILDDIR/putsmain32-cloned +test_check_retval + +cmp reference/putsmain32-cloned \ + $BUILDDIR/putsmain32-cloned +test_check_retval diff --git a/tests/03-injection32.test b/tests/03-injection32.test new file mode 100644 index 0000000..235f243 --- /dev/null +++ b/tests/03-injection32.test @@ -0,0 +1,11 @@ +#!/bin/sh +source ./boilerplate.sh + +elfucli --input reference/putsmain32 \ + --reladd reference/puts-alternative32.o \ + --output $BUILDDIR/putsmain32-with-puts-alternative32 +test_check_retval + +cmp reference/putsmain32-with-puts-alternative32 \ + $BUILDDIR/putsmain32-with-puts-alternative32 +test_check_retval diff --git a/tests/05-detour.test b/tests/05-detour.test new file mode 100644 index 0000000..c46ef2f --- /dev/null +++ b/tests/05-detour.test @@ -0,0 +1,11 @@ +#!/bin/sh +source ./boilerplate.sh + +elfucli --input $BUILDDIR/putsmainsub \ + --reladd $BUILDDIR/puts_noarg.o \ + --detour sub,puts_noarg \ + --output $BUILDDIR/putsmainsub-with-puts-noarg-detour +test_check_retval + +$BUILDDIR/putsmainsub-with-puts-noarg-detour | grep -q "puts_noarg() is returning." +test_check_retval diff --git a/tests/06-data256mb.test b/tests/06-data256mb.test new file mode 100644 index 0000000..55cfcd2 --- /dev/null +++ b/tests/06-data256mb.test @@ -0,0 +1,10 @@ +#!/bin/sh +source ./boilerplate.sh + +elfucli --input $BUILDDIR/putsmain \ + --reladd $BUILDDIR/data256mb.o \ + --output $BUILDDIR/putsmain-with-data256mb +test_check_retval + +$BUILDDIR/putsmain-with-data256mb | grep -q "puts() #2 called in main()" +test_check_retval diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..757ea21 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,37 @@ +BUILDDIR = build +SRCDIR = src + +SOURCES = $(shell find $(SRCDIR)/ -iname "*.c") +OBJS = $(patsubst $(SRCDIR)/%.c, $(BUILDDIR)/%.o, $(SOURCES)) +EXENAMES = putsmain putsmainsub +EXES = $(patsubst %, $(BUILDDIR)/%, $(EXENAMES)) + +CFLAGS = -Wall -pedantic + + + +.PHONY: testbase +testbase: $(OBJS) $(EXES) + + +.PHONY: check +check: testbase + ./runtests.sh + + +$(BUILDDIR)/putsmain: $(SRCDIR)/putsmain.c + @if [ ! -d $(dir $@) ] ; then mkdir -p $(dir $@) ; fi + gcc $(CFLAGS) -o $@ $^ + +$(BUILDDIR)/putsmainsub: $(SRCDIR)/putsmainsub.c + @if [ ! -d $(dir $@) ] ; then mkdir -p $(dir $@) ; fi + gcc $(CFLAGS) -o $@ $^ + +$(BUILDDIR)/%.o: $(SRCDIR)/%.c + @if [ ! -d $(dir $@) ] ; then mkdir -p $(dir $@) ; fi + gcc $(CFLAGS) -c -o $@ $< + + +.PHONY: clean +clean: + rm -rf $(BUILDDIR)/ diff --git a/tests/boilerplate.sh b/tests/boilerplate.sh new file mode 100755 index 0000000..2ebafa2 --- /dev/null +++ b/tests/boilerplate.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +BUILDDIR=${BUILDDIR:-build} +mkdir -p $BUILDDIR + +function test_check_retval +{ + TEST_RETVAL=$? + + if [ $TEST_RETVAL != 0 ] + then + exit $TEST_RETVAL + fi +} diff --git a/tests/reference/puts-alternative32.o b/tests/reference/puts-alternative32.o Binary files differnew file mode 100644 index 0000000..cc78018 --- /dev/null +++ b/tests/reference/puts-alternative32.o diff --git a/tests/reference/putsmain32 b/tests/reference/putsmain32 Binary files differnew file mode 100755 index 0000000..9381a77 --- /dev/null +++ b/tests/reference/putsmain32 diff --git a/tests/reference/putsmain32-cloned b/tests/reference/putsmain32-cloned Binary files differnew file mode 100755 index 0000000..58328b4 --- /dev/null +++ b/tests/reference/putsmain32-cloned diff --git a/tests/reference/putsmain32-with-puts-alternative32 b/tests/reference/putsmain32-with-puts-alternative32 Binary files differnew file mode 100755 index 0000000..953ddad --- /dev/null +++ b/tests/reference/putsmain32-with-puts-alternative32 diff --git a/tests/runtests.sh b/tests/runtests.sh new file mode 100755 index 0000000..1cf2665 --- /dev/null +++ b/tests/runtests.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +PATH="$PATH:$PWD/../build" + +for testfile in *.test +do + testname=${testfile%*.test} + + echo -en "\033[1m\033[37m[\033[34m \033[37m]\033[0m $testname" + bash $testfile > /dev/null 2>&1 + if [ $? -ne 0 ] + then + echo -e "\r\033[1m\033[37m[\033[31mFAILED\033[37m]\033[0m $testname" + echo -e "\033[1m\033[37m[\033[34m RERUN\033[37m]\033[0m $testname" + bash $testfile + echo -e "\033[1m\033[37m[\033[34mENDRUN\033[37m]\033[0m $testname" + else + echo -e "\r\033[1m\033[37m[\033[32m OK \033[37m]\033[0m $testname" + fi +done diff --git a/tests/src/Makefile b/tests/src/Makefile new file mode 100644 index 0000000..1a2b177 --- /dev/null +++ b/tests/src/Makefile @@ -0,0 +1,22 @@ +CFLAGS := -Wall -pedantic +EXES := putsmain putsmainsub brkmain +OBJS := puts_noarg.o puts_alternative.o puts_data.o +TARGETS := $(EXES) $(OBJS) + + +all: $(TARGETS) + + +putsmain: putsmain.c + gcc $(CFLAGS) $^ -o $@ + +putsmainsub: putsmainsub.c + gcc $(CFLAGS) $^ -o $@ + +.c.o: + gcc $(CFLAGS) -c $< -o $@ + + +.PHONY: clean +clean: + rm -f $(TARGETS) diff --git a/tests/src/data256mb.c b/tests/src/data256mb.c new file mode 100644 index 0000000..2cd3849 --- /dev/null +++ b/tests/src/data256mb.c @@ -0,0 +1,2 @@ +/* 256 MB worth of data. */ +char data256mb[256*1024*1024] = {1}; diff --git a/tests/src/puts_alternative.c b/tests/src/puts_alternative.c new file mode 100644 index 0000000..21d65cb --- /dev/null +++ b/tests/src/puts_alternative.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +void puts_alternative(char *arg) +{ + puts("puts_alternative() has been reached."); + + puts(arg); + + puts("puts_alternative() is returning."); +} diff --git a/tests/src/puts_noarg.c b/tests/src/puts_noarg.c new file mode 100644 index 0000000..fe7d494 --- /dev/null +++ b/tests/src/puts_noarg.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +void puts_noarg() +{ + puts("puts_noarg() has been reached."); + puts("puts_noarg() is returning."); +} diff --git a/tests/src/putsmain.c b/tests/src/putsmain.c new file mode 100644 index 0000000..9b2ce3c --- /dev/null +++ b/tests/src/putsmain.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main() +{ + puts("puts() #1 called in main()"); + puts("puts() #2 called in main()"); + + return 0; +} diff --git a/tests/src/putsmainsub.c b/tests/src/putsmainsub.c new file mode 100644 index 0000000..63d4171 --- /dev/null +++ b/tests/src/putsmainsub.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +void sub() +{ + puts("sub() called."); +} + +int main() +{ + sub(); + + return 0; +} |