* Added test that has multiple readers on a single port, and that drops into the
same panic as #5119. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34680 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
118fa8936e
commit
697255873e
@ -30,6 +30,8 @@ SimpleTest port_close_test_2 : port_close_test_2.cpp ;
|
||||
|
||||
SimpleTest port_delete_test : port_delete_test.cpp ;
|
||||
|
||||
SimpleTest port_multi_read_test : port_multi_read_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 ;
|
||||
|
73
src/tests/system/kernel/port_multi_read_test.cpp
Normal file
73
src/tests/system/kernel/port_multi_read_test.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
#define THREAD_COUNT 20
|
||||
|
||||
|
||||
status_t
|
||||
read_thread(void* _data)
|
||||
{
|
||||
port_id port = (port_id)_data;
|
||||
|
||||
printf("[%ld] read port...\n", find_thread(NULL));
|
||||
|
||||
while (true) {
|
||||
ssize_t bytesWaiting = port_buffer_size(port);
|
||||
printf("[%ld] buffer size %ld waiting\n", find_thread(NULL),
|
||||
bytesWaiting);
|
||||
|
||||
char buffer[256];
|
||||
int32 code;
|
||||
status_t status = read_port(port, &code, buffer, sizeof(buffer));
|
||||
printf("[%ld] read port result (code %lx): %s\n", find_thread(NULL),
|
||||
code, strerror(status));
|
||||
if (status == B_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
port_id port = create_port(1, "test port");
|
||||
printf("created port %ld\n", port);
|
||||
|
||||
thread_id threads[THREAD_COUNT];
|
||||
for (int32 i = 0; i < THREAD_COUNT; i++) {
|
||||
threads[i] = spawn_thread(read_thread, "read thread", B_NORMAL_PRIORITY,
|
||||
(void*)port);
|
||||
resume_thread(threads[i]);
|
||||
}
|
||||
|
||||
printf("snooze for a bit, all threads should be waiting now.");
|
||||
snooze(100000);
|
||||
|
||||
for (int32 i = 0; i < THREAD_COUNT; i++) {
|
||||
size_t bytes = 20 + i;
|
||||
char buffer[bytes];
|
||||
memset(buffer, 0x55, bytes);
|
||||
|
||||
printf("send %ld bytes\n", bytes);
|
||||
write_port(port, 0x42, buffer, bytes);
|
||||
snooze(10000);
|
||||
}
|
||||
|
||||
printf("waiting for threads to terminate\n");
|
||||
for (int32 i = 0; i < THREAD_COUNT; i++) {
|
||||
wait_for_thread(threads[i], NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user