added tests for kernel ports
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16644 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a0795c6fe3
commit
89107618d5
@ -3,6 +3,14 @@ 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 port_close_test_2 :
|
||||
port_close_test_2.cpp
|
||||
;
|
||||
|
||||
SimpleTest transfer_area_test :
|
||||
transfer_area_test.cpp
|
||||
;
|
||||
|
61
src/tests/system/kernel/port_close_test_1.cpp
Normal file
61
src/tests/system/kernel/port_close_test_1.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2006, Marcus Overhagen, <marcus@overhagen.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
port_id id;
|
||||
status_t s;
|
||||
size_t size;
|
||||
int32 code;
|
||||
|
||||
char data[100];
|
||||
|
||||
|
||||
id = create_port(10, "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));
|
||||
|
||||
s = write_port(id, 0x5678, data, 20);
|
||||
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
s = close_port(id);
|
||||
printf("close port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
// BeBook: does return B_BAD_PORT_ID if port was closed
|
||||
s = write_port(id, 0x5678, data, 20);
|
||||
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = port_buffer_size(id);
|
||||
printf("port_buffer_size %ld\n", size);
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = read_port(id, &code, data, sizeof(data));
|
||||
printf("read port size %ld, code %lx, result 0x%08lx (%s)\n", size, code, s, strerror(s));
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = port_buffer_size(id);
|
||||
printf("port_buffer_size %ld\n", size);
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = read_port(id, &code, data, sizeof(data));
|
||||
printf("read port size %ld, code %lx, result 0x%08lx (%s)\n", size, code, s, strerror(s));
|
||||
|
||||
printf("should block now\n");
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = port_buffer_size(id);
|
||||
printf("port_buffer_size %ld\n", size);
|
||||
|
||||
return 0;
|
||||
}
|
61
src/tests/system/kernel/port_close_test_2.cpp
Normal file
61
src/tests/system/kernel/port_close_test_2.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2006, Marcus Overhagen, <marcus@overhagen.de>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
port_id id;
|
||||
status_t s;
|
||||
size_t size;
|
||||
int32 code;
|
||||
|
||||
char data[100];
|
||||
|
||||
|
||||
id = create_port(10, "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));
|
||||
|
||||
s = write_port(id, 0x5678, data, 20);
|
||||
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
s = close_port(id);
|
||||
printf("close port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
// BeBook: does return B_BAD_PORT_ID if port was closed
|
||||
s = write_port(id, 0x5678, data, 20);
|
||||
printf("write port result 0x%08lx (%s)\n", s, strerror(s));
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = port_buffer_size(id);
|
||||
printf("port_buffer_size %ld\n", size);
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = read_port(id, &code, data, sizeof(data));
|
||||
printf("read port size %ld, code %lx, result 0x%08lx (%s)\n", size, code, s, strerror(s));
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = port_buffer_size(id);
|
||||
printf("port_buffer_size %ld\n", size);
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = read_port(id, &code, data, sizeof(data));
|
||||
printf("read port size %ld, code %lx, result 0x%08lx (%s)\n", size, code, s, strerror(s));
|
||||
|
||||
printf("should block now\n");
|
||||
|
||||
// BeBook: does block when port is empty, and unblocks when port is written to or deleted
|
||||
size = read_port(id, &code, data, sizeof(data));
|
||||
printf("read port size %ld, code %lx, result 0x%08lx (%s)\n", size, code, s, strerror(s));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user