xref: /haiku/src/tests/system/kernel/port_delete_test.cpp (revision 7f832a1ddb4210008bf42c53fe7f7428a85f78b2)
1da9b743bSMarcus Overhagen /*
2da9b743bSMarcus Overhagen  * Copyright 2006, Marcus Overhagen, <marcus@overhagen.de>
3da9b743bSMarcus Overhagen  * Distributed under the terms of the MIT License.
4da9b743bSMarcus Overhagen  */
5da9b743bSMarcus Overhagen 
6da9b743bSMarcus Overhagen 
7da9b743bSMarcus Overhagen #include <OS.h>
8da9b743bSMarcus Overhagen #include <stdio.h>
9da9b743bSMarcus Overhagen #include <string.h>
10da9b743bSMarcus Overhagen 
11da9b743bSMarcus Overhagen int
main()12da9b743bSMarcus Overhagen main()
13da9b743bSMarcus Overhagen {
14da9b743bSMarcus Overhagen 	port_id id;
15da9b743bSMarcus Overhagen 	status_t s;
16*7f832a1dSMarcus Overhagen 	ssize_t size;
17da9b743bSMarcus Overhagen 	int32 code;
18da9b743bSMarcus Overhagen 
19da9b743bSMarcus Overhagen 	char data[100];
20da9b743bSMarcus Overhagen 
21da9b743bSMarcus Overhagen 
22da9b743bSMarcus Overhagen 	id = create_port(10, "test port");
23da9b743bSMarcus Overhagen 	printf("created port %ld\n", id);
24da9b743bSMarcus Overhagen 
25da9b743bSMarcus Overhagen 	s = write_port(id, 0x1234, data, 10);
26da9b743bSMarcus Overhagen 	printf("write port result 0x%08lx (%s)\n", s, strerror(s));
27da9b743bSMarcus Overhagen 
28da9b743bSMarcus Overhagen 	s = write_port(id, 0x5678, data, 20);
29da9b743bSMarcus Overhagen 	printf("write port result 0x%08lx (%s)\n", s, strerror(s));
30da9b743bSMarcus Overhagen 
31da9b743bSMarcus Overhagen 	s = delete_port(id);
32da9b743bSMarcus Overhagen 	printf("delete port result 0x%08lx (%s)\n", s, strerror(s));
33da9b743bSMarcus Overhagen 
34da9b743bSMarcus Overhagen 	printf("everything should fail now\n");
35da9b743bSMarcus Overhagen 
36da9b743bSMarcus Overhagen 	// BeBook: does return B_BAD_PORT_ID if port was closed
37da9b743bSMarcus Overhagen 	s = write_port(id, 0x5678, data, 20);
38da9b743bSMarcus Overhagen 	printf("write port result 0x%08lx (%s)\n", s, strerror(s));
39da9b743bSMarcus Overhagen 
40da9b743bSMarcus Overhagen 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
41da9b743bSMarcus Overhagen 	size = port_buffer_size(id);
42da9b743bSMarcus Overhagen 	printf("port_buffer_size %ld (0x%08lx) (%s)\n", size, size, strerror(size));
43da9b743bSMarcus Overhagen 
44da9b743bSMarcus Overhagen 	// BeBook: does block when port is empty, and unblocks when port is written to or deleted
45da9b743bSMarcus Overhagen 	size = read_port(id, &code, data, sizeof(data));
46da9b743bSMarcus Overhagen 	printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
47da9b743bSMarcus Overhagen 
48da9b743bSMarcus Overhagen 	return 0;
49da9b743bSMarcus Overhagen }
50