[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 1/2] tests: Testinfrastruktur für libc angelegt
+ tests: Eine Umgebung, in der Tests ausgeführt werden können
(größtenteils aus dem LIOv2-Branch übernommen)
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
tests/include/testlib.h | 46 ++++++++++++++++++++++++++++++++++++
tests/lib/testlib.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
tests/libc/Makefile | 21 ++++++++++++++++
tests/libc/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++
tests/libc/run_test.sh | 25 ++++++++++++++++++++
5 files changed, 209 insertions(+), 0 deletions(-)
create mode 100644 tests/.nobuild
create mode 100644 tests/include/testlib.h
create mode 100644 tests/lib/testlib.c
create mode 100644 tests/libc/Makefile
create mode 100644 tests/libc/main.c
create mode 100755 tests/libc/run_test.sh
diff --git a/tests/.nobuild b/tests/.nobuild
new file mode 100644
index 0000000..e69de29
diff --git a/tests/include/testlib.h b/tests/include/testlib.h
new file mode 100644
index 0000000..4bc47bb
--- /dev/null
+++ b/tests/include/testlib.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TESTLIB_H
+#define TESTLIB_H
+
+#include <stdbool.h>
+
+extern const char* test_name;
+
+void __attribute__((noreturn)) quit_qemu(void);
+void _test_assert(bool expr, const char* text, int line);
+void _test_assert_nonfatal(bool expr, const char* text, int line);
+
+#define test_assert(x) \
+ _test_assert((x), #x, __LINE__)
+
+#define test_assert_nonfatal(x) \
+ _test_assert_nonfatal((x), #x, __LINE__)
+
+#endif
diff --git a/tests/lib/testlib.c b/tests/lib/testlib.c
new file mode 100644
index 0000000..450d25b
--- /dev/null
+++ b/tests/lib/testlib.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2011 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "testlib.h"
+
+#include <syscall.h>
+#include <ports.h>
+#include <stdio.h>
+
+void __attribute__((noreturn)) quit_qemu(void)
+{
+ request_ports(0xb000, 8);
+ outw(0xb004, 0x2000);
+
+ /* Wird nie erreicht */
+ while(1) {
+ asm volatile("ud2");
+ }
+}
+
+void _test_assert(bool expr, const char* text, int line)
+{
+ if (!expr) {
+ printf("* FAIL %s: %s [" __FILE__ ":%d]\n", test_name, text, line);
+ quit_qemu();
+ }
+}
+
+void _test_assert_nonfatal(bool expr, const char* text, int line)
+{
+ if (!expr) {
+ printf("* FAIL %s: %s [" __FILE__ ":%d]\n", test_name, text, line);
+ }
+}
diff --git a/tests/libc/Makefile b/tests/libc/Makefile
new file mode 100644
index 0000000..32f39b4
--- /dev/null
+++ b/tests/libc/Makefile
@@ -0,0 +1,21 @@
+-include ../../Makefile.local
+
+QEMU=qemu
+CC=$(CC_BINARY)
+LD=$(LD_BINARY)
+
+LIBGCC=$(shell $(CC) -print-libgcc-file-name)
+
+CFLAGS=-I ../include -I ../../src/include -I../../src/modules/include -I ../../src/include/arch/i386 -I../../src/modules/include/arch/i386
+LDFLAGS=-T ../../src/modules/user-i386.ld --start-group ../../src/lib/library.a ../../src/modules/lib/library.a ../../src/modules/lib/crt0.o $(LIBGCC) --end-group
+
+qemu: main
+ @./run_test.sh
+
+main: main.o ../lib/testlib.o
+ @$(LD) $^ $(LDFLAGS) -o $@
+
+%.o: %.c
+ @$(CC) $(CFLAGS) -o $@ $^
+
+.PHONY: qemu
diff --git a/tests/libc/main.c b/tests/libc/main.c
new file mode 100644
index 0000000..355ad0b
--- /dev/null
+++ b/tests/libc/main.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "testlib.h"
+
+const char* test_name;
+
+static void test1(void)
+{
+}
+
+int main(int argc, char* argv[])
+{
+ if (argc < 2) {
+ printf("* ERROR Zu wenige Parameter\n");
+ quit_qemu();
+ }
+
+ switch (atoi(argv[1])) {
+ case 1:
+ test1();
+ break;
+
+ default:
+ printf("* ERROR Unbekannter Testfall\n");
+ break;
+ }
+
+ quit_qemu();
+}
diff --git a/tests/libc/run_test.sh b/tests/libc/run_test.sh
new file mode 100755
index 0000000..f10b354
--- /dev/null
+++ b/tests/libc/run_test.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
+
+kernel=../../build/output/kernel/tyndur2
+modules="../../build/output/modules/init,../../build/output/modules/pci,../../build/output/modules/ata,../../build/output/modules/ext2,../../build/output/modules/servmgr root out ata pci ext2"
+
+function filter_output()
+{
+ grep '^*' |\
+ sed -e "s/PASS/\x1b[32mPASS\x1b[0m/" |\
+ sed -e "s/FAIL/\x1b[31mFAIL\x1b[0m/" |\
+ sed -e "s/ERROR/\x1b[33mERROR\x1b[0m/"
+}
+
+function run_test()
+{
+ local testcase=$1
+ local subtest=$2
+
+ $QEMU -nographic -kernel $kernel -initrd "$modules","$testcase $subtest" | filter_output
+# $QEMU -kernel $kernel -initrd "$modules","$testcase $subtest" -serial stdio | filter_output
+}
+
+run_test main 1
--
1.6.0.2