@@ -20,6 +20,7 @@ use hyperlight_host::sandbox::SandboxConfiguration;
20
20
#[ cfg( gdb) ]
21
21
use hyperlight_host:: sandbox:: config:: DebugInfo ;
22
22
use hyperlight_host:: { MultiUseSandbox , UninitializedSandbox } ;
23
+ use serial_test:: serial;
23
24
24
25
/// Build a sandbox configuration that enables GDB debugging when the `gdb` feature is enabled.
25
26
fn get_sandbox_cfg ( ) -> Option < SandboxConfiguration > {
@@ -72,6 +73,13 @@ fn main() -> hyperlight_host::Result<()> {
72
73
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox. evolve ( ) ?;
73
74
74
75
// Call guest function
76
+ multi_use_sandbox_dbg
77
+ . call :: < ( ) > (
78
+ "UseSSE2Registers" ,
79
+ ( ) ,
80
+ )
81
+ . unwrap ( ) ;
82
+
75
83
let message =
76
84
"Hello, World! I am executing inside of a VM with debugger attached :)\n " . to_string ( ) ;
77
85
multi_use_sandbox_dbg
@@ -106,44 +114,23 @@ mod tests {
106
114
107
115
use super :: * ;
108
116
109
- fn write_cmds_file ( cmd_file_path : & str , out_file_path : & str ) -> io:: Result < ( ) > {
110
- let manifest_dir = std :: env :: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Failed to get manifest dir" ) ;
117
+ fn write_cmds_file ( cmd_file_path : & str , cmd : & str ) -> io:: Result < ( ) > {
118
+
111
119
let file = File :: create ( cmd_file_path) ?;
112
120
let mut writer = BufWriter :: new ( file) ;
113
121
114
122
// write from string to file
115
123
writer. write_all (
116
- format ! (
117
- "file {manifest_dir}/../tests/rust_guests/bin/debug/simpleguest
118
- target remote :8080
119
-
120
- set pagination off
121
- set logging file {out_file_path}
122
- set logging on
123
-
124
- break hyperlight_main
125
- commands
126
- echo \" Stopped at hyperlight_main breakpoint\\ n\"
127
- backtrace
128
- continue
129
- end
130
-
131
- continue
132
-
133
- set logging off
134
- quit
135
- "
136
- )
137
- . as_bytes ( ) ,
124
+ cmd. as_bytes ( ) ,
138
125
) ?;
139
126
140
127
writer. flush ( )
141
128
}
142
129
143
- fn run_guest_and_gdb ( cmd_file_path : & str , out_file_path : & str ) -> Result < ( ) > {
130
+ fn run_guest_and_gdb ( cmd_file_path : & str , out_file_path : & str , cmd : & str , checker : fn ( String ) -> bool ) -> Result < ( ) > {
144
131
// write gdb commands to file
145
132
146
- write_cmds_file ( & cmd_file_path, & out_file_path )
133
+ write_cmds_file ( & cmd_file_path, cmd )
147
134
. expect ( "Failed to write gdb commands to file" ) ;
148
135
149
136
#[ cfg( mshv2) ] // mshv3 is a default feature is mutually exclusive with the mshv2 feature
@@ -215,17 +202,17 @@ mod tests {
215
202
}
216
203
}
217
204
218
- check_output ( & out_file_path)
205
+ check_output ( & out_file_path, checker )
219
206
}
220
207
221
- fn check_output ( out_file_path : & str ) -> Result < ( ) > {
208
+ fn check_output ( out_file_path : & str , checker : fn ( contents : String ) -> bool ) -> Result < ( ) > {
222
209
let results = File :: open ( out_file_path)
223
210
. map_err ( |e| new_error ! ( "Failed to open gdb.output file: {}" , e) ) ?;
224
211
let mut reader = BufReader :: new ( results) ;
225
212
let mut contents = String :: new ( ) ;
226
213
reader. read_to_string ( & mut contents) . unwrap ( ) ;
227
214
228
- if contents . contains ( "Stopped at hyperlight_main breakpoint" ) {
215
+ if checker ( contents ) {
229
216
Ok ( ( ) )
230
217
} else {
231
218
Err ( new_error ! (
@@ -247,12 +234,84 @@ mod tests {
247
234
}
248
235
249
236
#[ test]
237
+ #[ serial]
250
238
fn test_gdb_end_to_end ( ) {
251
239
let out_dir = std:: env:: var ( "OUT_DIR" ) . expect ( "Failed to get out dir" ) ;
240
+ let manifest_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Failed to get manifest dir" ) ;
252
241
let out_file_path = format ! ( "{out_dir}/gdb.output" ) ;
253
242
let cmd_file_path = format ! ( "{out_dir}/gdb-commands.txt" ) ;
254
243
255
- let result = run_guest_and_gdb ( & cmd_file_path, & out_file_path) ;
244
+ let cmd = format ! (
245
+ "file {manifest_dir}/../tests/rust_guests/bin/debug/simpleguest
246
+ target remote :8080
247
+
248
+ set pagination off
249
+ set logging file {out_file_path}
250
+ set logging on
251
+
252
+ break hyperlight_main
253
+ commands
254
+ echo \" Stopped at hyperlight_main breakpoint\\ n\"
255
+ backtrace
256
+
257
+ continue
258
+ end
259
+
260
+ continue
261
+
262
+ set logging off
263
+ quit
264
+ "
265
+ ) ;
266
+
267
+ let checker = |contents : String | { contents. contains ( "Stopped at hyperlight_main breakpoint" ) } ;
268
+
269
+ let result = run_guest_and_gdb ( & cmd_file_path, & out_file_path, & cmd, checker) ;
270
+
271
+ // cleanup
272
+ let cleanup_result = cleanup ( & out_file_path, & cmd_file_path) ;
273
+ assert ! ( cleanup_result. is_ok( ) , "{}" , cleanup_result. unwrap_err( ) ) ;
274
+ // check if the test passed - done at the end to ensure cleanup is done
275
+ assert ! ( result. is_ok( ) , "{}" , result. unwrap_err( ) ) ;
276
+ }
277
+
278
+ #[ test]
279
+ #[ serial]
280
+ fn test_gdb_sse_check ( ) {
281
+ let out_dir = std:: env:: var ( "OUT_DIR" ) . expect ( "Failed to get out dir" ) ;
282
+ let manifest_dir = std:: env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Failed to get manifest dir" ) ;
283
+ let out_file_path = format ! ( "{out_dir}/gdb-sse.output" ) ;
284
+ let cmd_file_path = format ! ( "{out_dir}/gdb-sse--commands.txt" ) ;
285
+
286
+ let cmd = format ! (
287
+ "file {manifest_dir}/../tests/rust_guests/bin/debug/simpleguest
288
+ target remote :8080
289
+
290
+ set pagination off
291
+ set logging file {out_file_path}
292
+ set logging on
293
+
294
+ break main.rs:simpleguest::use_sse2_registers
295
+ commands 1
296
+ print $xmm1.v4_float
297
+ break +2
298
+ commands 2
299
+ print $xmm1.v4_float
300
+ continue
301
+ end
302
+ continue
303
+ end
304
+
305
+
306
+ continue
307
+
308
+ set logging off
309
+ quit
310
+ "
311
+ ) ;
312
+
313
+ let checker = |contents : String | { contents. contains ( "$2 = [1.20000005, 0, 0, 0]" ) } ;
314
+ let result = run_guest_and_gdb ( & cmd_file_path, & out_file_path, & cmd, checker) ;
256
315
257
316
// cleanup
258
317
let cleanup_result = cleanup ( & out_file_path, & cmd_file_path) ;
0 commit comments