From 7f832a1ddb4210008bf42c53fe7f7428a85f78b2 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Wed, 8 Mar 2006 15:22:07 +0000 Subject: [PATCH] more tests for port functionality git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16648 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/system/kernel/Jamfile | 36 +++++++++++ src/tests/system/kernel/port_close_test_1.cpp | 2 +- src/tests/system/kernel/port_close_test_2.cpp | 2 +- src/tests/system/kernel/port_delete_test.cpp | 2 +- .../system/kernel/port_wakeup_test_1.cpp | 60 +++++++++++++++++ .../system/kernel/port_wakeup_test_2.cpp | 64 +++++++++++++++++++ .../system/kernel/port_wakeup_test_3.cpp | 63 ++++++++++++++++++ .../system/kernel/port_wakeup_test_4.cpp | 57 +++++++++++++++++ .../system/kernel/port_wakeup_test_5.cpp | 57 +++++++++++++++++ .../system/kernel/port_wakeup_test_6.cpp | 63 ++++++++++++++++++ .../system/kernel/port_wakeup_test_7.cpp | 63 ++++++++++++++++++ .../system/kernel/port_wakeup_test_8.cpp | 62 ++++++++++++++++++ .../system/kernel/port_wakeup_test_9.cpp | 62 ++++++++++++++++++ 13 files changed, 590 insertions(+), 3 deletions(-) create mode 100644 src/tests/system/kernel/port_wakeup_test_1.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_2.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_3.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_4.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_5.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_6.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_7.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_8.cpp create mode 100644 src/tests/system/kernel/port_wakeup_test_9.cpp diff --git a/src/tests/system/kernel/Jamfile b/src/tests/system/kernel/Jamfile index 1f58d2ef04..2a68ba76cf 100644 --- a/src/tests/system/kernel/Jamfile +++ b/src/tests/system/kernel/Jamfile @@ -15,6 +15,42 @@ SimpleTest port_delete_test : port_delete_test.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 transfer_area_test : transfer_area_test.cpp ; diff --git a/src/tests/system/kernel/port_close_test_1.cpp b/src/tests/system/kernel/port_close_test_1.cpp index 23b2b48c2f..80435a8c6a 100644 --- a/src/tests/system/kernel/port_close_test_1.cpp +++ b/src/tests/system/kernel/port_close_test_1.cpp @@ -13,7 +13,7 @@ main() { port_id id; status_t s; - size_t size; + ssize_t size; int32 code; char data[100]; diff --git a/src/tests/system/kernel/port_close_test_2.cpp b/src/tests/system/kernel/port_close_test_2.cpp index 4b3983ddab..a30499435a 100644 --- a/src/tests/system/kernel/port_close_test_2.cpp +++ b/src/tests/system/kernel/port_close_test_2.cpp @@ -13,7 +13,7 @@ main() { port_id id; status_t s; - size_t size; + ssize_t size; int32 code; char data[100]; diff --git a/src/tests/system/kernel/port_delete_test.cpp b/src/tests/system/kernel/port_delete_test.cpp index 25700a5c7f..cb406e6933 100644 --- a/src/tests/system/kernel/port_delete_test.cpp +++ b/src/tests/system/kernel/port_delete_test.cpp @@ -13,7 +13,7 @@ main() { port_id id; status_t s; - size_t size; + ssize_t size; int32 code; char data[100]; diff --git a/src/tests/system/kernel/port_wakeup_test_1.cpp b/src/tests/system/kernel/port_wakeup_test_1.cpp new file mode 100644 index 0000000000..bd23d0b143 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_1.cpp @@ -0,0 +1,60 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + status_t s; + + printf("write port...\n"); + s = write_port(id, 0x5678, data, 20); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("write should block for 5 seconds now, as port is full\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + // BeBook: does block when port is empty, and unblocks when port is written to or deleted + printf("read port...\n"); + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_2.cpp b/src/tests/system/kernel/port_wakeup_test_2.cpp new file mode 100644 index 0000000000..c74054bb63 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_2.cpp @@ -0,0 +1,64 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + int32 code; + + // BeBook: does block when port is empty, and unblocks when port is written to or deleted + printf("read port...\n"); + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("read should block for 5 seconds now, as port is empty\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("write port...\n"); + s = write_port(id, 0x5678, data, 20); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_3.cpp b/src/tests/system/kernel/port_wakeup_test_3.cpp new file mode 100644 index 0000000000..29704043ae --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_3.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + + // BeBook: does block when port is empty, and unblocks when port is written to or deleted + printf("port_buffer_size...\n"); + size = port_buffer_size(id); + printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("port_buffer_size should block for 5 seconds now, as port is empty\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("write port...\n"); + s = write_port(id, 0x5678, data, 20); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_4.cpp b/src/tests/system/kernel/port_wakeup_test_4.cpp new file mode 100644 index 0000000000..2afa58c26d --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_4.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + status_t s; + + printf("write port...\n"); + s = write_port(id, 0x5678, data, 20); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + return 0; +} + + +int +main() +{ + status_t s; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("write should block for 5 seconds now, as port is full, until port is closed\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("close port...\n"); + s = close_port(id); + printf("close port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_5.cpp b/src/tests/system/kernel/port_wakeup_test_5.cpp new file mode 100644 index 0000000000..00d893f8f9 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_5.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + status_t s; + + printf("write port...\n"); + s = write_port(id, 0x5678, data, 20); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + return 0; +} + + +int +main() +{ + status_t s; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("write should block for 5 seconds now, as port is full, until port is deleted\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("delete port...\n"); + s = delete_port(id); + printf("delete port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_6.cpp b/src/tests/system/kernel/port_wakeup_test_6.cpp new file mode 100644 index 0000000000..f761715ce9 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_6.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + int32 code; + + printf("read port...\n"); + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("read should block for 5 seconds now, as port is empty, until port is closed\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("close port...\n"); + s = close_port(id); + printf("close port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_7.cpp b/src/tests/system/kernel/port_wakeup_test_7.cpp new file mode 100644 index 0000000000..fa88133d34 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_7.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + int32 code; + + printf("read port...\n"); + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("read should block for 5 seconds now, as port is empty, until port is deleted\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("delete port...\n"); + s = delete_port(id); + printf("delete port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_8.cpp b/src/tests/system/kernel/port_wakeup_test_8.cpp new file mode 100644 index 0000000000..51d3542300 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_8.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + + printf("port_buffer_size...\n"); + size = port_buffer_size(id); + printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("port_buffer_size should block for 5 seconds now, as port is empty, until port is closed\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("close port...\n"); + s = close_port(id); + printf("close port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +} diff --git a/src/tests/system/kernel/port_wakeup_test_9.cpp b/src/tests/system/kernel/port_wakeup_test_9.cpp new file mode 100644 index 0000000000..8726fddef3 --- /dev/null +++ b/src/tests/system/kernel/port_wakeup_test_9.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2006, Marcus Overhagen, + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +/* A full port can't be written to. Thus the write from thread should block, until main thread reads. + * + */ + +port_id id; +char data[100]; + +int32 +test_thread(void *) +{ + ssize_t size; + + printf("port_buffer_size...\n"); + size = port_buffer_size(id); + printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); + + return 0; +} + + +int +main() +{ + status_t s; + ssize_t size; + int32 code; + + id = create_port(1, "test port"); + printf("created port %ld\n", id); + + s = write_port(id, 0x1234, data, 10); + printf("write port result 0x%08lx (%s)\n", s, strerror(s)); + + size = read_port(id, &code, data, sizeof(data)); + printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); + + printf("port_buffer_size should block for 5 seconds now, as port is empty, until port is deleted\n"); + + thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); + resume_thread(thread); + snooze(5000000); + + printf("delete port...\n"); + s = delete_port(id); + printf("delete port result 0x%08lx (%s)\n", s, strerror(s)); + + printf("waiting for thread to terminate\n"); + wait_for_thread(thread, &s); + + return 0; +}