Bootstrapping build process using proof-of-concept test runner.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Fri, 20 May 2011 13:50:52 +0300
changeset 5659 37e7b3b4b5e3
parent 5546 cd2167525827
child 5660 8aec500a7299
Bootstrapping build process using proof-of-concept test runner.
test/test-automation/.hgignore
test/test-automation/Makefile.in
test/test-automation/config.h.in
test/test-automation/configure.ac
test/test-automation/runner.c
test/test-automation/test.c
test/test-automation/test.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/.hgignore	Fri May 20 13:50:52 2011 +0300
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/Makefile.in	Fri May 20 13:50:52 2011 +0300
@@ -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
+
+	
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/config.h.in	Fri May 20 13:50:52 2011 +0300
@@ -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 <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> 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 <vfork.h> 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 <sys/types.h> does not define. */
+#undef pid_t
+
+/* Define as `fork' if `vfork' does not work. */
+#undef vfork
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/configure.ac	Fri May 20 13:50:52 2011 +0300
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/runner.c	Fri May 20 13:50:52 2011 +0300
@@ -0,0 +1,97 @@
+/*
+  Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
+
+  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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/test.c	Fri May 20 13:50:52 2011 +0300
@@ -0,0 +1,45 @@
+/*
+  Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
+
+  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 <stdio.h>
+
+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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test-automation/test.h	Fri May 20 13:50:52 2011 +0300
@@ -0,0 +1,30 @@
+/*
+  Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
+
+  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