|
1 | 1 | use libc::{AF_INET, AF_UNIX, SOCK_DGRAM, SOCK_STREAM}; |
2 | 2 | use libc::{accept, bind, connect, listen, shutdown, socket}; |
| 3 | +use crate::register_test; |
3 | 4 |
|
4 | 5 | pub fn test_tcp_socket_creation() { |
5 | | - print!("Testing TCP socket creation ... "); |
6 | 6 | unsafe { |
7 | 7 | let sockfd = socket(AF_INET, SOCK_STREAM, 0); |
8 | 8 | if sockfd < 0 { |
9 | 9 | panic!("Failed to create TCP socket"); |
10 | 10 | } |
11 | 11 | } |
12 | | - println!("OK"); |
13 | 12 | } |
14 | 13 |
|
| 14 | +register_test!(test_tcp_socket_creation); |
| 15 | + |
15 | 16 | pub fn test_unix_socket_creation() { |
16 | | - print!("Testing UNIX stream socket creation ... "); |
17 | 17 | unsafe { |
18 | 18 | let sockfd = socket(AF_UNIX, SOCK_STREAM, 0); |
19 | 19 | if sockfd < 0 { |
20 | 20 | panic!("Failed to create UNIX stream socket"); |
21 | 21 | } |
22 | 22 | } |
23 | | - println!("OK"); |
24 | | - |
25 | | - print!("Testing UNIX datagram socket creation ... "); |
26 | 23 | unsafe { |
27 | 24 | let sockfd = socket(AF_UNIX, SOCK_DGRAM, 0); |
28 | 25 | if sockfd < 0 { |
29 | 26 | panic!("Failed to create UNIX datagram socket"); |
30 | 27 | } |
31 | 28 | } |
32 | | - println!("OK"); |
33 | 29 | } |
34 | 30 |
|
| 31 | +register_test!(test_unix_socket_creation); |
| 32 | + |
35 | 33 | pub fn test_unix_socket_basic_functions() { |
36 | | - print!("Testing UNIX socket functions ... "); |
37 | 34 | let sockfd = unsafe { socket(AF_UNIX, SOCK_STREAM, 0) }; |
38 | 35 | if sockfd < 0 { |
39 | 36 | panic!("Failed to create UNIX stream socket for function tests"); |
@@ -67,14 +64,13 @@ pub fn test_unix_socket_basic_functions() { |
67 | 64 | if shutdown_result < 0 { |
68 | 65 | panic!("Failed to shutdown UNIX socket"); |
69 | 66 | } |
70 | | - println!("OK"); |
71 | 67 | } |
72 | 68 |
|
| 69 | +register_test!(test_unix_socket_basic_functions); |
| 70 | + |
73 | 71 | pub fn test_unix_socket_fork_msg_passing() { |
74 | 72 | use std::ptr; |
75 | 73 |
|
76 | | - print!("Testing UNIX socket fork message passing ... "); |
77 | | - |
78 | 74 | // Create server socket, bind and listen before fork |
79 | 75 | let server_fd = unsafe { socket(AF_UNIX, SOCK_STREAM, 0) }; |
80 | 76 | if server_fd < 0 { |
@@ -176,6 +172,7 @@ pub fn test_unix_socket_fork_msg_passing() { |
176 | 172 |
|
177 | 173 | unsafe { libc::close(conn_fd) }; |
178 | 174 | unsafe { libc::close(server_fd) }; |
179 | | - println!("OK"); |
180 | 175 | } |
181 | 176 | } |
| 177 | + |
| 178 | +register_test!(test_unix_socket_fork_msg_passing); |
0 commit comments