179
179
my $iteration = 0;
180
180
my $successes = 0;
181
181
my $stty_orig ;
182
+ my $run_command_status = 0;
182
183
183
184
my $bisect_good ;
184
185
my $bisect_bad ;
@@ -1325,26 +1326,44 @@ sub eval_option {
1325
1326
1326
1327
sub reboot {
1327
1328
my ($time ) = @_ ;
1329
+ my $powercycle = 0;
1328
1330
1329
- # Make sure everything has been written to disk
1330
- run_ssh(" sync" );
1331
+ # test if the machine can be connected to within 5 seconds
1332
+ my $stat = run_ssh(" echo check machine status" , 5);
1333
+ if (!$stat ) {
1334
+ doprint(" power cycle\n " );
1335
+ $powercycle = 1;
1336
+ }
1337
+
1338
+ if ($powercycle ) {
1339
+ run_command " $power_cycle " ;
1331
1340
1332
- if (defined ($time )) {
1333
1341
start_monitor;
1334
1342
# flush out current monitor
1335
1343
# May contain the reboot success line
1336
1344
wait_for_monitor 1;
1337
- }
1338
1345
1339
- # try to reboot normally
1340
- if (run_command $reboot ) {
1341
- if (defined ($powercycle_after_reboot )) {
1342
- sleep $powercycle_after_reboot ;
1346
+ } else {
1347
+ # Make sure everything has been written to disk
1348
+ run_ssh(" sync" );
1349
+
1350
+ if (defined ($time )) {
1351
+ start_monitor;
1352
+ # flush out current monitor
1353
+ # May contain the reboot success line
1354
+ wait_for_monitor 1;
1355
+ }
1356
+
1357
+ # try to reboot normally
1358
+ if (run_command $reboot ) {
1359
+ if (defined ($powercycle_after_reboot )) {
1360
+ sleep $powercycle_after_reboot ;
1361
+ run_command " $power_cycle " ;
1362
+ }
1363
+ } else {
1364
+ # nope? power cycle it.
1343
1365
run_command " $power_cycle " ;
1344
1366
}
1345
- } else {
1346
- # nope? power cycle it.
1347
- run_command " $power_cycle " ;
1348
1367
}
1349
1368
1350
1369
if (defined ($time )) {
@@ -1412,6 +1431,10 @@ sub dodie {
1412
1431
system (" stty $stty_orig " );
1413
1432
}
1414
1433
1434
+ if (defined ($post_test )) {
1435
+ run_command $post_test ;
1436
+ }
1437
+
1415
1438
die @_ , " \n " ;
1416
1439
}
1417
1440
@@ -1624,10 +1647,6 @@ sub save_logs {
1624
1647
1625
1648
sub fail {
1626
1649
1627
- if (defined ($post_test )) {
1628
- run_command $post_test ;
1629
- }
1630
-
1631
1650
if ($die_on_failure ) {
1632
1651
dodie @_ ;
1633
1652
}
@@ -1660,23 +1679,26 @@ sub fail {
1660
1679
save_logs " fail" , $store_failures ;
1661
1680
}
1662
1681
1682
+ if (defined ($post_test )) {
1683
+ run_command $post_test ;
1684
+ }
1685
+
1663
1686
return 1;
1664
1687
}
1665
1688
1666
1689
sub run_command {
1667
- my ($command , $redirect ) = @_ ;
1690
+ my ($command , $redirect , $timeout ) = @_ ;
1668
1691
my $start_time ;
1669
1692
my $end_time ;
1670
1693
my $dolog = 0;
1671
1694
my $dord = 0;
1672
1695
my $pid ;
1673
1696
1674
- $start_time = time ;
1675
-
1676
1697
$command =~ s /\$ SSH_USER/ $ssh_user / g ;
1677
1698
$command =~ s /\$ MACHINE/ $machine / g ;
1678
1699
1679
1700
doprint(" $command ... " );
1701
+ $start_time = time ;
1680
1702
1681
1703
$pid = open (CMD, " $command 2>&1 |" ) or
1682
1704
(fail " unable to exec $command " and return 0);
@@ -1693,13 +1715,30 @@ sub run_command {
1693
1715
$dord = 1;
1694
1716
}
1695
1717
1696
- while (<CMD>) {
1697
- print LOG if ($dolog );
1698
- print RD if ($dord );
1718
+ my $hit_timeout = 0;
1719
+
1720
+ while (1) {
1721
+ my $fp = \*CMD;
1722
+ if (defined ($timeout )) {
1723
+ doprint " timeout = $timeout \n " ;
1724
+ }
1725
+ my $line = wait_for_input($fp , $timeout );
1726
+ if (!defined ($line )) {
1727
+ my $now = time ;
1728
+ if (defined ($timeout ) && (($now - $start_time ) >= $timeout )) {
1729
+ doprint " Hit timeout of $timeout , killing process\n " ;
1730
+ $hit_timeout = 1;
1731
+ kill 9, $pid ;
1732
+ }
1733
+ last ;
1734
+ }
1735
+ print LOG $line if ($dolog );
1736
+ print RD $line if ($dord );
1699
1737
}
1700
1738
1701
1739
waitpid ($pid , 0);
1702
- my $failed = $? ;
1740
+ # shift 8 for real exit status
1741
+ $run_command_status = $? >> 8;
1703
1742
1704
1743
close (CMD);
1705
1744
close (LOG) if ($dolog );
@@ -1714,21 +1753,25 @@ sub run_command {
1714
1753
doprint " [$delta seconds] " ;
1715
1754
}
1716
1755
1717
- if ($failed ) {
1756
+ if ($hit_timeout ) {
1757
+ $run_command_status = 1;
1758
+ }
1759
+
1760
+ if ($run_command_status ) {
1718
1761
doprint " FAILED!\n " ;
1719
1762
} else {
1720
1763
doprint " SUCCESS\n " ;
1721
1764
}
1722
1765
1723
- return !$failed ;
1766
+ return !$run_command_status ;
1724
1767
}
1725
1768
1726
1769
sub run_ssh {
1727
- my ($cmd ) = @_ ;
1770
+ my ($cmd , $timeout ) = @_ ;
1728
1771
my $cp_exec = $ssh_exec ;
1729
1772
1730
1773
$cp_exec =~ s /\$ SSH_COMMAND/ $cmd / g ;
1731
- return run_command " $cp_exec " ;
1774
+ return run_command " $cp_exec " , undef , $timeout ;
1732
1775
}
1733
1776
1734
1777
sub run_scp {
@@ -2489,10 +2532,6 @@ sub halt {
2489
2532
sub success {
2490
2533
my ($i ) = @_ ;
2491
2534
2492
- if (defined ($post_test )) {
2493
- run_command $post_test ;
2494
- }
2495
-
2496
2535
$successes ++;
2497
2536
2498
2537
my $name = " " ;
@@ -2517,6 +2556,10 @@ sub success {
2517
2556
doprint " Reboot and wait $sleep_time seconds\n " ;
2518
2557
reboot_to_good $sleep_time ;
2519
2558
}
2559
+
2560
+ if (defined ($post_test )) {
2561
+ run_command $post_test ;
2562
+ }
2520
2563
}
2521
2564
2522
2565
sub answer_bisect {
@@ -2537,16 +2580,15 @@ sub answer_bisect {
2537
2580
}
2538
2581
2539
2582
sub child_run_test {
2540
- my $failed = 0;
2541
2583
2542
2584
# child should have no power
2543
2585
$reboot_on_error = 0;
2544
2586
$poweroff_on_error = 0;
2545
2587
$die_on_failure = 1;
2546
2588
2547
- run_command $run_test , $testlog or $failed = 1 ;
2589
+ run_command $run_test , $testlog ;
2548
2590
2549
- exit $failed ;
2591
+ exit $run_command_status ;
2550
2592
}
2551
2593
2552
2594
my $child_done ;
@@ -2629,7 +2671,7 @@ sub do_run_test {
2629
2671
}
2630
2672
2631
2673
waitpid $child_pid , 0;
2632
- $child_exit = $? ;
2674
+ $child_exit = $? >> 8 ;
2633
2675
2634
2676
my $end_time = time ;
2635
2677
$test_time = $end_time - $start_time ;
@@ -3330,7 +3372,6 @@ sub config_bisect {
3330
3372
save_config \%good_configs , $good_config ;
3331
3373
save_config \%bad_configs , $bad_config ;
3332
3374
3333
-
3334
3375
if (defined ($config_bisect_check ) && $config_bisect_check ne " 0" ) {
3335
3376
if ($config_bisect_check ne " good" ) {
3336
3377
doprint " Testing bad config\n " ;
0 commit comments