@@ -30,11 +30,11 @@ mod host {
30
30
} ) ;
31
31
}
32
32
33
- fn add_console_port (
33
+ fn test_port (
34
34
ctx : u32 ,
35
35
console_id : u32 ,
36
36
name : & str ,
37
- ) -> anyhow:: Result < ( UnixStream , UnixStream ) > {
37
+ ) -> anyhow:: Result < ( ) > {
38
38
let ( guest, host) = UnixStream :: pair ( ) ?;
39
39
let name_cstring = CString :: new ( name) ?;
40
40
unsafe {
@@ -46,7 +46,9 @@ mod host {
46
46
guest. as_raw_fd( )
47
47
) ) ?;
48
48
}
49
- Ok ( ( guest, host) )
49
+ mem:: forget ( guest) ;
50
+ spawn_ping_pong_responder ( host) ;
51
+ Ok ( ( ) )
50
52
}
51
53
52
54
impl Test for TestMultiportConsole {
@@ -55,36 +57,22 @@ mod host {
55
57
krun_call ! ( krun_set_log_level( KRUN_LOG_LEVEL_WARN ) ) ?;
56
58
let ctx = krun_call_u32 ! ( krun_create_ctx( ) ) ?;
57
59
58
- // Disable implicit console
59
60
krun_call ! ( krun_disable_implicit_console( ctx) ) ?;
60
61
61
- // Add a default console with STDIN/STDOUT/STDERR
62
+ // Add a default console (as with other tests this uses stdout for writing "OK")
62
63
krun_call ! ( krun_add_virtio_console_default(
63
64
ctx,
64
- std :: io :: stdin ( ) . as_raw_fd ( ) ,
65
+ - 1 ,
65
66
std:: io:: stdout( ) . as_raw_fd( ) ,
66
- std :: io :: stderr ( ) . as_raw_fd ( )
67
+ - 1 ,
67
68
) ) ?;
68
69
69
- // Create a multiport console
70
70
let console_id = krun_call_u32 ! ( krun_add_virtio_console_multiport( ctx) ) ?;
71
71
72
- // Add 3 inout ports with different names
73
- let ( port1_guest, port1_host) =
74
- add_console_port ( ctx, console_id, "test-port-alpha" ) ?;
75
- let ( port2_guest, port2_host) =
76
- add_console_port ( ctx, console_id, "test-port-beta" ) ?;
77
- let ( port3_guest, port3_host) =
78
- add_console_port ( ctx, console_id, "test-port-gamma" ) ?;
72
+ test_port ( ctx, console_id, "test-port-alpha" ) ?;
73
+ test_port ( ctx, console_id, "test-port-beta" ) ?;
74
+ test_port ( ctx, console_id, "test-port-gamma" ) ?;
79
75
80
- spawn_ping_pong_responder ( port1_host) ;
81
- spawn_ping_pong_responder ( port2_host) ;
82
- spawn_ping_pong_responder ( port3_host) ;
83
-
84
- // Keep the guest-side streams open for the VM
85
- mem:: forget ( port1_guest) ;
86
- mem:: forget ( port2_guest) ;
87
- mem:: forget ( port3_guest) ;
88
76
89
77
krun_call ! ( krun_set_vm_config( ctx, 1 , 1024 ) ) ?;
90
78
setup_fs_and_enter ( ctx, test_setup) ?;
@@ -116,13 +104,12 @@ mod guest {
116
104
let mut response = String :: new ( ) ;
117
105
reader. read_line ( & mut response) . unwrap ( ) ;
118
106
119
- let expected = message. replace ( "PING" , "PONG" ) . trim ( ) . to_string ( ) ;
120
- assert_eq ! ( response. trim ( ) , expected, "{}: wrong response" , name) ;
107
+ let expected = message. replace ( "PING" , "PONG" ) . to_string ( ) ;
108
+ assert_eq ! ( response, expected, "{}: wrong response" , name) ;
121
109
}
122
110
123
111
impl Test for TestMultiportConsole {
124
112
fn in_guest ( self : Box < Self > ) {
125
- // List all virtio ports to find our named ports
126
113
let ports_dir = "/sys/class/virtio-ports" ;
127
114
128
115
let mut port_map = std:: collections:: HashMap :: new ( ) ;
@@ -144,7 +131,10 @@ mod guest {
144
131
}
145
132
}
146
133
147
- // Verify we have all three ports
134
+ assert ! (
135
+ port_map. contains_key( "krun-stdout" ) ,
136
+ "krun-stdout not found"
137
+ ) ;
148
138
assert ! (
149
139
port_map. contains_key( "test-port-alpha" ) ,
150
140
"test-port-alpha not found"
@@ -158,6 +148,9 @@ mod guest {
158
148
"test-port-gamma not found"
159
149
) ;
160
150
151
+ // We shouldn't have any more than configured here
152
+ assert_eq ! ( port_map. len( ) , 4 ) ;
153
+
161
154
test_port ( & port_map, "test-port-alpha" , "PING-ALPHA\n " ) ;
162
155
test_port ( & port_map, "test-port-beta" , "PING-BETA\n " ) ;
163
156
test_port ( & port_map, "test-port-gamma" , "PING-GAMMA\n " ) ;
0 commit comments