summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/01-noop32.test10
-rw-r--r--tests/03-injection32.test11
-rw-r--r--tests/05-detour.test11
-rw-r--r--tests/06-data256mb.test10
-rw-r--r--tests/Makefile37
-rwxr-xr-xtests/boilerplate.sh14
-rw-r--r--tests/reference/puts-alternative32.obin0 -> 1128 bytes
-rwxr-xr-xtests/reference/putsmain32bin0 -> 6101 bytes
-rwxr-xr-xtests/reference/putsmain32-clonedbin0 -> 6104 bytes
-rwxr-xr-xtests/reference/putsmain32-with-puts-alternative32bin0 -> 18696 bytes
-rwxr-xr-xtests/runtests.sh20
-rw-r--r--tests/src/Makefile22
-rw-r--r--tests/src/data256mb.c2
-rw-r--r--tests/src/puts_alternative.c10
-rw-r--r--tests/src/puts_noarg.c7
-rw-r--r--tests/src/putsmain.c9
-rw-r--r--tests/src/putsmainsub.c13
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
new file mode 100644
index 0000000..cc78018
--- /dev/null
+++ b/tests/reference/puts-alternative32.o
Binary files differ
diff --git a/tests/reference/putsmain32 b/tests/reference/putsmain32
new file mode 100755
index 0000000..9381a77
--- /dev/null
+++ b/tests/reference/putsmain32
Binary files differ
diff --git a/tests/reference/putsmain32-cloned b/tests/reference/putsmain32-cloned
new file mode 100755
index 0000000..58328b4
--- /dev/null
+++ b/tests/reference/putsmain32-cloned
Binary files differ
diff --git a/tests/reference/putsmain32-with-puts-alternative32 b/tests/reference/putsmain32-with-puts-alternative32
new file mode 100755
index 0000000..953ddad
--- /dev/null
+++ b/tests/reference/putsmain32-with-puts-alternative32
Binary files differ
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;
+}