From f9c339ef02de170c0d29f1a6ca2ce770a78290f9 Mon Sep 17 00:00:00 2001 From: Markus Kauppila Date: Fri, 20 May 2011 13:50:52 +0300 Subject: [PATCH] Bootstrapping build process using proof-of-concept test runner. --- test/test-automation/.hgignore | 23 ++++++++ test/test-automation/Makefile.in | 52 +++++++++++++++++ test/test-automation/config.h.in | 70 ++++++++++++++++++++++ test/test-automation/configure.ac | 23 ++++++++ test/test-automation/runner.c | 97 +++++++++++++++++++++++++++++++ test/test-automation/test.c | 45 ++++++++++++++ test/test-automation/test.h | 30 ++++++++++ 7 files changed, 340 insertions(+) create mode 100644 test/test-automation/.hgignore create mode 100644 test/test-automation/Makefile.in create mode 100644 test/test-automation/config.h.in create mode 100644 test/test-automation/configure.ac create mode 100644 test/test-automation/runner.c create mode 100644 test/test-automation/test.c create mode 100644 test/test-automation/test.h diff --git a/test/test-automation/.hgignore b/test/test-automation/.hgignore new file mode 100644 index 000000000..24a79dc29 --- /dev/null +++ b/test/test-automation/.hgignore @@ -0,0 +1,23 @@ +syntax: glob + +.DS_Store + +autom4te* +configure +config.h +config.cache +config.log +config.status +Makefile +runner +*.o +*.so + +*.dSYM + +# for vim +*.swp + +# for Eclipse +.project +.cproject diff --git a/test/test-automation/Makefile.in b/test/test-automation/Makefile.in new file mode 100644 index 000000000..d732150e6 --- /dev/null +++ b/test/test-automation/Makefile.in @@ -0,0 +1,52 @@ +# @configure_input@ + +CFLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT +LDFLAGS = `sdl-config --libs` + +CC = @CC@ +#CFLAGS = @CFLAGS@ +#LDFLAGS = @LIBS@ + +#@SET_MAKE@ +SHELL = @SHELL@ +srcdir = @srcdir@ + +SRC = runner.c + +TEST_SRC = test.c +TEST_OBJ = test.o + +ALL_TESTS = libtest.so + +.PHONY: all clean + +all: runner $(ALL_TESTS) + +runner: $(SRC) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ + +tests: $(ALL_TESTS) + +libtest.so: test.o + $(CC) -shared -wl,-soname,$@ -o $@ $+ + +test.o: $(TEST_SRC) + $(CC) -fPIC $(CFLAGS) -c $+ -o $@ + +Makefile: Makefile.in config.status + $(SHELL) /config.status $@ + +Makefile.in: + ; + +clean: + rm -f runner $(TESTS_ALL) *.o *.so + +distclean: clean + rm -f Makefile + rm -f config.{h,log,status} + rm -f configure configure.scan + rm -f autoscan.log + rm -Rf autom4te* *.dSYM + + diff --git a/test/test-automation/config.h.in b/test/test-automation/config.h.in new file mode 100644 index 000000000..391c3d963 --- /dev/null +++ b/test/test-automation/config.h.in @@ -0,0 +1,70 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `fork' function. */ +#undef HAVE_FORK + +/* Define to 1 if you have the header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if you have the `vfork' function. */ +#undef HAVE_VFORK + +/* Define to 1 if you have the header file. */ +#undef HAVE_VFORK_H + +/* Define to 1 if `fork' works. */ +#undef HAVE_WORKING_FORK + +/* Define to 1 if `vfork' works. */ +#undef HAVE_WORKING_VFORK + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the home page for this package. */ +#undef PACKAGE_URL + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Define to `int' if does not define. */ +#undef pid_t + +/* Define as `fork' if `vfork' does not work. */ +#undef vfork diff --git a/test/test-automation/configure.ac b/test/test-automation/configure.ac new file mode 100644 index 000000000..418ff99b2 --- /dev/null +++ b/test/test-automation/configure.ac @@ -0,0 +1,23 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.65]) +AC_INIT([runner], [0.01], [markus.kauppila@gmail.com]) +AC_CONFIG_SRCDIR([runner.c]) +AC_CONFIG_HEADERS([config.h]) + +# Checks for programs. +AC_PROG_CC + +# Checks for libraries. + +# Checks for header files. +AC_CHECK_HEADERS([stdlib.h unistd.h]) + +# Checks for typedefs, structures, and compiler characteristics. + +# Checks for library functions. +AC_FUNC_FORK + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/test/test-automation/runner.c b/test/test-automation/runner.c new file mode 100644 index 000000000..1456de2f4 --- /dev/null +++ b/test/test-automation/runner.c @@ -0,0 +1,97 @@ +/* + Copyright (C) 2011 Markus Kauppila + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "SDL/SDL_loadso.h" + +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + int pid = getpid(); + int testsFailed = 0, testsPassed = 0; + + char *libName = "libtest.so"; + printf("%d: Loading .so containing tests\n", pid); + void *library = SDL_LoadObject(libName); + if(library == NULL) { + printf("Loading %s failed\n", libName); + printf("%s\n", SDL_GetError()); + } + + printf("%d: Asking for the test case names\n", pid); + char **(*suite)(void); + suite = (char **(*)(void)) SDL_LoadFunction(library, "suite"); + if(suite == NULL) { + printf("%d: Retrieving test names failed, suite == NULL\n", pid); + printf("%s\n", SDL_GetError()); + } else { + char **tests = suite(); + + char *testname = NULL; + int counter = 0; + for(; (testname = tests[counter]); ++counter) { + int childpid = fork(); + if(childpid == 0) { + pid = getpid(); + + printf("%d: Loading test: %s\n", pid, testname); + + void (*test)(void *arg); + + test = (void (*)(void *)) SDL_LoadFunction(library, testname); + if(test == NULL) { + printf("%d: Loading test failed, tests == NULL\n", pid); + printf("%s\n", SDL_GetError()); + } else { + test(0x0); + } + return 0; // exit the child if the test didn't exit + } else { + int stat_lock = -1; + int child = wait(&stat_lock); + + if(WIFEXITED(stat_lock)) { + int rv = WEXITSTATUS(stat_lock); + printf("%d: %d exited normally with value %d\n", pid, child, rv); + + testsPassed++; + } else if(WIFSIGNALED(stat_lock)) { + int signal = WTERMSIG(stat_lock); + printf("%d: %d was killed by signal nro %d\n", pid, child, signal); + + testsFailed++; + } else if(WIFSTOPPED(stat_lock)) { + //int signal = WSTOPSIG(stat_lock); + //printf("%d: %d was stopped by signal nro %d\n", pid, child, signal); + } + } + } + } + + printf("%d: all tests executed\n", pid); + printf("%d: %d tests passed\n", pid, testsPassed); + printf("%d: %d tests failed\n", pid, testsFailed); + + SDL_UnloadObject(library); + + return 0; +} diff --git a/test/test-automation/test.c b/test/test-automation/test.c new file mode 100644 index 000000000..6d610f000 --- /dev/null +++ b/test/test-automation/test.c @@ -0,0 +1,45 @@ +/* + Copyright (C) 2011 Markus Kauppila + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef _TEST_C +#define _TEST_C + +#include + +char *names[] = {"hello", "hello2", "hello3"}; + +char **suite() { + return names; +} + +void hello(void *arg){ + printf("hello\n"); +} + +void hello2(void *arg) { + char *msg = "eello"; + msg[0] = 'H'; +} + +void hello3(void *arg) { + printf("hello\n"); +} + +#endif diff --git a/test/test-automation/test.h b/test/test-automation/test.h new file mode 100644 index 000000000..0b52d0208 --- /dev/null +++ b/test/test-automation/test.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2011 Markus Kauppila + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef _TEST_H +#define _TEST_H + +char **suite(); + +void hello(void *arg); +void hello2(void *arg); +void hello3(void *arg); + +#endif