/build
+/tests/build
.o
.a
.so
.PHONY: check
check: $(EXE)
- $(error the re-layouting has broken make check for now, sorry.)
- $(EXE) $(EXE) -o testexe
- @cmp $(EXE) testexe
- @rm testexe
- @echo "Check successful."
+ make -C tests check
.PHONY: debug
rm -f $(OBJS)
rm -f $(TESTEXES)
rm -rf $(BUILDDIR)/
+ make -C tests clean
.PHONY: distclean
--- /dev/null
+#!/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
--- /dev/null
+#!/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
--- /dev/null
+#!/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
--- /dev/null
+#!/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
--- /dev/null
+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)/
--- /dev/null
+#!/bin/sh
+
+BUILDDIR=${BUILDDIR:-build}
+mkdir -p $BUILDDIR
+
+function test_check_retval
+{
+ TEST_RETVAL=$?
+
+ if [ $TEST_RETVAL != 0 ]
+ then
+ exit $TEST_RETVAL
+ fi
+}
--- /dev/null
+#!/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
--- /dev/null
+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)
--- /dev/null
+/* 256 MB worth of data. */
+char data256mb[256*1024*1024] = {1};
--- /dev/null
+#include <stdio.h>
+
+void puts_alternative(char *arg)
+{
+ puts("puts_alternative() has been reached.");
+
+ puts(arg);
+
+ puts("puts_alternative() is returning.");
+}
--- /dev/null
+#include <stdio.h>
+
+void puts_noarg()
+{
+ puts("puts_noarg() has been reached.");
+ puts("puts_noarg() is returning.");
+}
--- /dev/null
+#include <stdio.h>
+
+int main()
+{
+ puts("puts() #1 called in main()");
+ puts("puts() #2 called in main()");
+
+ return 0;
+}
--- /dev/null
+#include <stdio.h>
+
+void sub()
+{
+ puts("sub() called.");
+}
+
+int main()
+{
+ sub();
+
+ return 0;
+}