From cbe5f24524ed188e4c0d7aaa4403ab7f22b92c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 9 Jan 2007 23:53:40 +0000 Subject: [PATCH] * Added fibo_load_image test based on Manuel's fibo test from NewOS - doesn't work yet due to problems with wait_for_thread(). * Minor cleanup to the Jamfile. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19757 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/system/kernel/Jamfile | 71 +++++------------- src/tests/system/kernel/fibo_load_image.cpp | 81 +++++++++++++++++++++ 2 files changed, 99 insertions(+), 53 deletions(-) create mode 100644 src/tests/system/kernel/fibo_load_image.cpp diff --git a/src/tests/system/kernel/Jamfile b/src/tests/system/kernel/Jamfile index cbadae3cee..f631f2f9b3 100644 --- a/src/tests/system/kernel/Jamfile +++ b/src/tests/system/kernel/Jamfile @@ -3,65 +3,30 @@ SubDir HAIKU_TOP src tests system kernel ; UsePrivateHeaders kernel ; UseHeaders $(TARGET_PRIVATE_KERNEL_HEADERS) : true ; -SimpleTest port_close_test_1 : - port_close_test_1.cpp - ; +SimpleTest fibo_load_image : fibo_load_image.cpp ; +#SimpleTest fibo_fork : fibo_fork.cpp ; +#SimpleTest fibo_exec : fibo_exec.cpp ; -SimpleTest port_close_test_2 : - port_close_test_2.cpp - ; +SimpleTest port_close_test_1 : port_close_test_1.cpp ; +SimpleTest port_close_test_2 : port_close_test_2.cpp ; -SimpleTest port_delete_test : - port_delete_test.cpp - ; +SimpleTest port_delete_test : port_delete_test.cpp ; -SimpleTest port_wakeup_test_1 : - port_wakeup_test_1.cpp - ; +SimpleTest port_wakeup_test_1 : port_wakeup_test_1.cpp ; +SimpleTest port_wakeup_test_2 : port_wakeup_test_2.cpp ; +SimpleTest port_wakeup_test_3 : port_wakeup_test_3.cpp ; +SimpleTest port_wakeup_test_4 : port_wakeup_test_4.cpp ; +SimpleTest port_wakeup_test_5 : port_wakeup_test_5.cpp ; +SimpleTest port_wakeup_test_6 : port_wakeup_test_6.cpp ; +SimpleTest port_wakeup_test_7 : port_wakeup_test_7.cpp ; +SimpleTest port_wakeup_test_8 : port_wakeup_test_8.cpp ; +SimpleTest port_wakeup_test_9 : port_wakeup_test_9.cpp ; -SimpleTest port_wakeup_test_2 : - port_wakeup_test_2.cpp - ; +SimpleTest transfer_area_test : transfer_area_test.cpp ; -SimpleTest port_wakeup_test_3 : - port_wakeup_test_3.cpp - ; +SimpleTest syscall_time : syscall_time.cpp ; -SimpleTest port_wakeup_test_4 : - port_wakeup_test_4.cpp - ; - -SimpleTest port_wakeup_test_5 : - port_wakeup_test_5.cpp - ; - -SimpleTest port_wakeup_test_6 : - port_wakeup_test_6.cpp - ; - -SimpleTest port_wakeup_test_7 : - port_wakeup_test_7.cpp - ; - -SimpleTest port_wakeup_test_8 : - port_wakeup_test_8.cpp - ; - -SimpleTest port_wakeup_test_9 : - port_wakeup_test_9.cpp - ; - -SimpleTest transfer_area_test : - transfer_area_test.cpp - ; - -SimpleTest syscall_time : - syscall_time.cpp - ; - -SimpleTest yield_test : - yield_test.cpp - ; +SimpleTest yield_test : yield_test.cpp ; SimpleTest lock_node_test : lock_node_test.cpp diff --git a/src/tests/system/kernel/fibo_load_image.cpp b/src/tests/system/kernel/fibo_load_image.cpp new file mode 100644 index 0000000000..651ff1ed44 --- /dev/null +++ b/src/tests/system/kernel/fibo_load_image.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2002, Manuel J. Petit. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + + +#include + +#include +#include +#include + + +static void +usage(char const *app) +{ + printf("usage: %s [-s] ###\n", app); + exit(-1); +} + + +int +main(int argc, char *argv[]) +{ + bool silent = false; + int num = 0; + int result; + + switch (argc) { + case 2: + num = atoi(argv[1]); + break; + case 3: + if (!strcmp(argv[1], "-s")) { + num = atoi(argv[2]); + silent = true; + break; + } + // supposed to fall through + + default: + usage(argv[0]); + break; + } + + if (num < 2) { + result = 1; + } else { + char buffer[64]; + char* args[]= { argv[0], "-s", buffer, NULL }; + int argCount = 3; + status_t status; + + snprintf(buffer, sizeof(buffer), "%d", num - 1); + thread_id threadA = load_image(argCount, (const char**)args, (const char**)environ); + snprintf(buffer, sizeof(buffer), "%d", num - 2); + thread_id threadB = load_image(argCount, (const char**)args, (const char**)environ); + + resume_thread(threadA); + resume_thread(threadB); + + while (wait_for_thread(threadA, &status) == B_INTERRUPTED) + ; + result = status; + + while (wait_for_thread(threadB, &status) == B_INTERRUPTED) + ; + result += status; + } + + if (silent) { + return result; + } else { + printf("%d\n", result); + return 0; + } +} +