@@ -11,6 +11,12 @@ const QEMU_ARGS: &[&str] = &[
1111] ;
1212
1313pub fn run_test_kernel ( kernel_binary_path : & str ) {
14+ run_test_kernel_on_uefi ( kernel_binary_path) ;
15+ run_test_kernel_on_uefi_pxe ( kernel_binary_path) ;
16+ // TODO: run tests with BIOS bootloader too
17+ }
18+
19+ pub fn run_test_kernel_on_uefi ( kernel_binary_path : & str ) {
1420 let kernel_path = Path :: new ( kernel_binary_path) ;
1521 let out_fat_path = kernel_path. with_extension ( "fat" ) ;
1622 bootloader:: create_boot_partition ( kernel_path, & out_fat_path) . unwrap ( ) ;
@@ -19,8 +25,6 @@ pub fn run_test_kernel(kernel_binary_path: &str) {
1925 let out_mbr_path = kernel_path. with_extension ( "mbr" ) ;
2026 bootloader:: create_bios_disk_image ( & out_fat_path, & out_mbr_path) . unwrap ( ) ;
2127
22- // TODO: run tests with BIOS bootloader too
23-
2428 let mut run_cmd = Command :: new ( "qemu-system-x86_64" ) ;
2529 run_cmd
2630 . arg ( "-drive" )
@@ -42,3 +46,33 @@ pub fn run_test_kernel(kernel_binary_path: &str) {
4246 other => panic ! ( "Test failed with unexpected exit code `{:?}`" , other) ,
4347 }
4448}
49+
50+ pub fn run_test_kernel_on_uefi_pxe ( kernel_binary_path : & str ) {
51+ let kernel_path = Path :: new ( kernel_binary_path) ;
52+ let out_tftp_path = kernel_path. with_extension ( ".tftp" ) ;
53+
54+ bootloader:: create_uefi_pxe_tftp_folder ( kernel_path, & out_tftp_path) . unwrap ( ) ;
55+
56+ let mut run_cmd = Command :: new ( "qemu-system-x86_64" ) ;
57+ run_cmd. arg ( "-netdev" ) . arg ( format ! (
58+ "user,id=net0,net=192.168.17.0/24,tftp={},bootfile=bootloader,id=net0" ,
59+ out_tftp_path. display( )
60+ ) ) ;
61+ run_cmd. arg ( "-device" ) . arg ( "virtio-net-pci,netdev=net0" ) ;
62+ run_cmd. args ( QEMU_ARGS ) ;
63+ run_cmd. arg ( "-bios" ) . arg ( ovmf_prebuilt:: ovmf_pure_efi ( ) ) ;
64+
65+ let child_output = run_cmd. output ( ) . unwrap ( ) ;
66+ strip_ansi_escapes:: Writer :: new ( std:: io:: stderr ( ) )
67+ . write_all ( & child_output. stderr )
68+ . unwrap ( ) ;
69+ strip_ansi_escapes:: Writer :: new ( std:: io:: stderr ( ) )
70+ . write_all ( & child_output. stdout )
71+ . unwrap ( ) ;
72+
73+ match child_output. status . code ( ) {
74+ Some ( 33 ) => { } // success
75+ Some ( 35 ) => panic ! ( "Test failed" ) ,
76+ other => panic ! ( "Test failed with unexpected exit code `{:?}`" , other) ,
77+ }
78+ }
0 commit comments