11use std:: thread:: JoinHandle ;
2+ use std:: time:: Duration ;
23
34use anyhow:: { Context , Result } ;
45use camino:: { Utf8Path , Utf8PathBuf } ;
@@ -299,14 +300,21 @@ fn parse_plan_metadata(
299300struct RunPlanResult {
300301 plan_name : String ,
301302 passed : bool ,
303+ time_taken : Option < Duration > ,
302304 run_id : Option < String > ,
303305}
304306
305307impl RunPlanResult {
306- fn new ( plan_name : String , passed : bool , run_id : Option < String > ) -> Self {
308+ fn new (
309+ plan_name : String ,
310+ passed : bool ,
311+ time_taken : Option < Duration > ,
312+ run_id : Option < String > ,
313+ ) -> Self {
307314 Self {
308315 plan_name,
309316 passed,
317+ time_taken,
310318 run_id,
311319 }
312320 }
@@ -329,7 +337,7 @@ fn run_plan(
329337 Ok ( sh) => sh,
330338 Err ( err) => {
331339 eprintln ! ( "Failed to create new shell instance: {err:?}" ) ;
332- return RunPlanResult :: new ( plan, false , None ) ;
340+ return RunPlanResult :: new ( plan, false , None , None ) ;
333341 }
334342 } ;
335343
@@ -344,7 +352,7 @@ fn run_plan(
344352
345353 if let Err ( e) = launch_result {
346354 eprintln ! ( "Failed to launch VM for plan {}: {:#}" , plan, e) ;
347- return RunPlanResult :: new ( plan, false , None ) ;
355+ return RunPlanResult :: new ( plan, false , None , None ) ;
348356 }
349357
350358 // Ensure VM cleanup happens even on error (unless --preserve-vm is set)
@@ -368,7 +376,7 @@ fn run_plan(
368376 Err ( e) => {
369377 eprintln ! ( "Failed to get VM info for plan {}: {:#}" , plan, e) ;
370378 cleanup_vm ( ) ;
371- return RunPlanResult :: new ( plan, false , None ) ;
379+ return RunPlanResult :: new ( plan, false , None , None ) ;
372380 }
373381 } ;
374382
@@ -382,7 +390,7 @@ fn run_plan(
382390 Err ( e) => {
383391 eprintln ! ( "Failed to create SSH key file for plan {}: {:#}" , plan, e) ;
384392 cleanup_vm ( ) ;
385- return RunPlanResult :: new ( plan, false , None ) ;
393+ return RunPlanResult :: new ( plan, false , None , None ) ;
386394 }
387395 } ;
388396
@@ -394,14 +402,14 @@ fn run_plan(
394402 Err ( e) => {
395403 eprintln ! ( "Failed to convert key path for plan {}: {:#}" , plan, e) ;
396404 cleanup_vm ( ) ;
397- return RunPlanResult :: new ( plan, false , None ) ;
405+ return RunPlanResult :: new ( plan, false , None , None ) ;
398406 }
399407 } ;
400408
401409 if let Err ( e) = std:: fs:: write ( & key_path, ssh_key) {
402410 eprintln ! ( "Failed to write SSH key for plan {}: {:#}" , plan, e) ;
403411 cleanup_vm ( ) ;
404- return RunPlanResult :: new ( plan, false , None ) ;
412+ return RunPlanResult :: new ( plan, false , None , None ) ;
405413 }
406414
407415 // Set proper permissions on the key file (SSH requires 0600)
@@ -411,7 +419,7 @@ fn run_plan(
411419 if let Err ( e) = std:: fs:: set_permissions ( & key_path, perms) {
412420 eprintln ! ( "Failed to set key permissions for plan {}: {:#}" , plan, e) ;
413421 cleanup_vm ( ) ;
414- return RunPlanResult :: new ( plan, false , None ) ;
422+ return RunPlanResult :: new ( plan, false , None , None ) ;
415423 }
416424 }
417425
@@ -420,13 +428,15 @@ fn run_plan(
420428 if let Err ( e) = verify_ssh_connectivity ( & sh, ssh_port, & key_path) {
421429 eprintln ! ( "SSH verification failed for plan {}: {:#}" , plan, e) ;
422430 cleanup_vm ( ) ;
423- return RunPlanResult :: new ( plan, false , None ) ;
431+ return RunPlanResult :: new ( plan, false , None , None ) ;
424432 }
425433
426434 println ! ( "SSH connectivity verified" ) ;
427435
428436 let ssh_port_str = ssh_port. to_string ( ) ;
429437
438+ let time_start = std:: time:: Instant :: now ( ) ;
439+
430440 // Run tmt for this specific plan using connect provisioner
431441 println ! ( "Running tmt tests for plan {}..." , plan) ;
432442
@@ -448,6 +458,8 @@ fn run_plan(
448458 )
449459 . run ( ) ;
450460
461+ let elapsed = time_start. elapsed ( ) ;
462+
451463 // Log disk usage after each test run to help diagnose "no space left on device" failures
452464 println ! ( "Disk usage after plan {}:" , plan) ;
453465 let _ = cmd ! ( sh, "df -h" ) . run ( ) ;
@@ -458,11 +470,11 @@ fn run_plan(
458470 let plan_result = match test_result {
459471 Ok ( _) => {
460472 println ! ( "Plan {} completed successfully" , plan) ;
461- RunPlanResult :: new ( plan, true , Some ( run_id) )
473+ RunPlanResult :: new ( plan, true , Some ( elapsed ) , Some ( run_id) )
462474 }
463475 Err ( e) => {
464476 eprintln ! ( "Plan {} failed: {:#}" , plan, e) ;
465- RunPlanResult :: new ( plan, false , Some ( run_id) )
477+ RunPlanResult :: new ( plan, false , Some ( elapsed ) , Some ( run_id) )
466478 }
467479 } ;
468480
@@ -641,14 +653,13 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
641653 install_opts. push ( format ! ( "--karg={k}" ) ) ;
642654 }
643655
656+ let start = std:: time:: Instant :: now ( ) ;
657+
644658 println ! ( "Creating base disk..." ) ;
645659 let opts = install_opts. clone ( ) ;
646660 cmd ! ( sh, "bcvk libvirt to-base-disk {opts...} localhost/bootc" ) . run ( ) ?;
647661
648- // println!(
649- // "Created base disk {}",
650- // std::str::from_utf8(&created_disk.stdout).unwrap_or("bcvk output was not valid UTF-8")
651- // );
662+ println ! ( "Creating base disk took: {:#?}" , start. elapsed( ) ) ;
652663
653664 // Generate a random suffix for VM names
654665 let random_suffix = generate_random_suffix ( ) ;
@@ -788,9 +799,13 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
788799 println ! ( "\n ========================================" ) ;
789800 println ! ( "Test Summary" ) ;
790801 println ! ( "========================================" ) ;
802+
803+ test_results. sort_by ( |a, b| b. time_taken . cmp ( & a. time_taken ) ) ;
804+
791805 for RunPlanResult {
792806 plan_name : plan,
793807 passed,
808+ time_taken,
794809 ..
795810 } in & test_results
796811 {
@@ -800,7 +815,12 @@ pub(crate) fn run_tmt(sh: &Shell, args: &RunTmtArgs) -> Result<()> {
800815 all_passed = false ;
801816 "FAILED"
802817 } ;
803- println ! ( "{}: {}" , plan, status) ;
818+ println ! (
819+ "{}: {} ({:?})" ,
820+ plan,
821+ status,
822+ time_taken. unwrap_or( Duration :: from_secs( 0 ) )
823+ ) ;
804824 }
805825 println ! ( "========================================\n " ) ;
806826
0 commit comments