* 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:
Axel Dörfler 2009-12-16 11:45:45 +00:00
parent 118fa8936e
commit 697255873e
2 changed files with 75 additions and 0 deletions

View File

@ -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 ;

View 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;
}