[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 3/4] tests: Ein einfacher Threadtest



+ tests: Thread starten, Parameterübergabe prüfen, TIDs vergleichen
  (alles direkt mit Syscalls, kein pthread)

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 tests/libc/Makefile      |    5 ++-
 tests/libc/main_thread.c |   92 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/libc/run_test.sh   |    2 +
 3 files changed, 98 insertions(+), 1 deletions(-)
 create mode 100644 tests/libc/main_thread.c

diff --git a/tests/libc/Makefile b/tests/libc/Makefile
index fb07cf2..e1beb12 100644
--- a/tests/libc/Makefile
+++ b/tests/libc/Makefile
@@ -11,12 +11,15 @@ LDFLAGS=-T ../../src/modules/user-i386.ld --start-group ../../src/lib/library.a
 
 export QEMU
 
-qemu: main
+qemu: main main_thread
 	@./run_test.sh
 
 main: main.o qsort.o bsearch.o sprintf.o stdio.o ../lib/testlib.o
 	@$(LD) $^ $(LDFLAGS) -o $@
 
+main_thread: main_thread.o ../lib/testlib.o
+	@$(LD) $^ $(LDFLAGS) -o $@
+
 %.o: %.c
 	@$(CC) $(CFLAGS) -o $@ $^
 
diff --git a/tests/libc/main_thread.c b/tests/libc/main_thread.c
new file mode 100644
index 0000000..6d841f0
--- /dev/null
+++ b/tests/libc/main_thread.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2013 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 <stdbool.h>
+#include <syscall.h>
+
+#include "testlib.h"
+
+const char* test_name;
+
+struct test1_data {
+    int a;
+    tid_t ctid;
+};
+
+static void test1_t1(void* arg)
+{
+    struct test1_data* data = arg;
+    test_assert(data->a == 42);
+    data->a = 43;
+    data->ctid = get_tid();
+    exit_thread();
+    test_assert(false);
+}
+
+static void test1(void)
+{
+    tid_t tid, ctid;
+    struct test1_data data = {
+        .a = 42,
+    };
+
+    test_name = "sys_threads";
+    tid = get_tid();
+
+    ctid = create_thread((uint32_t) &test1_t1, &data);
+    while (data.a == 42) {
+        yield();
+    }
+
+    test_assert(data.a == 43);
+    test_assert(data.ctid == ctid);
+    test_assert(get_tid() == tid);
+
+    printf("* PASS %s\n", test_name);
+}
+
+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
index 2842dae..c6c05dc 100755
--- a/tests/libc/run_test.sh
+++ b/tests/libc/run_test.sh
@@ -32,3 +32,5 @@ run_test main 1
 run_test main 2
 run_test main 3
 run_test main 4
+
+run_test main_thread 1
-- 
1.7.7