From 094267e779f4ff8741413173dad0cb2817b1786d Mon Sep 17 00:00:00 2001 From: Matt Shin Date: Wed, 1 Apr 2015 22:02:39 +0100 Subject: [PATCH] Improve test battery stability Sort keys where possible. Make it easier for a locator to not select SSH. Use number of CPU as default number of jobs for `prove`. --- bin/fcm_test_battery | 5 ++++- lib/FCM/System/Make/Build.pm | 22 ++++++++++++++++------ lib/FCM/Util/Locator/SSH.pm | 4 ++-- t/fcm-make/07-build-ns-dep.t | 2 +- t/fcm-make/08-build-dup-dep.t | 2 +- t/fcm-make/09-build-dep-o.t | 8 ++++---- t/fcm-make/14-build-etc.t | 2 +- t/fcm-make/16-build-dep-o-2.t | 2 +- t/fcm-make/17-build-cyclic.t | 2 ++ t/fcm-make/18-build-use-intrinsic.t | 2 +- t/fcm-make/36-build-fail-cont-basic.t | 11 ++++------- 11 files changed, 37 insertions(+), 25 deletions(-) diff --git a/bin/fcm_test_battery b/bin/fcm_test_battery index 50e8ba82..69005630 100755 --- a/bin/fcm_test_battery +++ b/bin/fcm_test_battery @@ -21,4 +21,7 @@ cd $(dirname $0)/.. if [[ "$PWD" != "$OLDPWD" ]]; then echo "[INFO] cd $PWD" fi -exec prove -j 9 -s -r "${@:-t}" +if [[ -f '/proc/cpuinfo' ]]; then + NPROC="$(grep -ic 'processor' '/proc/cpuinfo')" +fi +exec prove -j "${NPROC:-9}" -s -r "${@:-t}" diff --git a/lib/FCM/System/Make/Build.pm b/lib/FCM/System/Make/Build.pm index b032cc1a..dc06a91b 100644 --- a/lib/FCM/System/Make/Build.pm +++ b/lib/FCM/System/Make/Build.pm @@ -739,7 +739,7 @@ sub _targets_manager_funcs { _target_prep($state, $ctx); $state->set_value($STATE->PENDING); # Adds tasks that can be triggered by this task - for my $key (@{$target->get_triggers()}) { + for my $key (sort @{$target->get_triggers()}) { if ( exists($state_hash_ref->{$key}) && !$state_hash_ref->{$key}->is_done() && !grep {$_->get_id() eq $key} @{$stack_ref} @@ -1104,7 +1104,11 @@ sub _targets_select { ); my $target = $target_of{$key}; DEP: - for (grep {$_->[0] ne $key} @{$target->get_deps()}) { + for ( + grep {$_->[0] ne $key} + sort {$a->[0] cmp $b->[0]} + @{$target->get_deps()} + ) { my ($dep_key, $dep_type, $dep_remark) = @{$_}; # Duplicated targets if (exists($targets_of{$dep_key})) { @@ -1198,12 +1202,13 @@ sub _targets_select { } } # Walk the tree and report it - my @report_items = map {[$_]} @target_keys; + my @report_items = map {[$_]} sort @target_keys; my %reported; ITEM: while (my $item = pop(@report_items)) { my ($key, @stack) = @{$item}; - my @deps = @{$state_of{$key}->get_deps()}; + my @deps = sort {$a->[0]->get_key() cmp $b->[0]->get_key()} + @{$state_of{$key}->get_deps()}; my @more_items = reverse(map {[$_->[0]->get_key(), @stack, $key]} @deps); my $n_more_items; if (exists($reported{$key})) { @@ -1253,7 +1258,7 @@ sub _targets_select { sub _target_deps_are_done { my ($state, $state_hash_ref, $stack_ref) = @_; my @deps = map {[$_->[0]->get_key(), $_->[1]]} @{$state->get_deps()}; - for my $k (grep {$state_hash_ref->{$_}->is_ready()} map {$_->[0]} @deps) { + for my $k (sort grep {$state_hash_ref->{$_}->is_ready()} map {$_->[0]} @deps) { if (!grep {$_->get_id() eq $k} @{$stack_ref}) { push(@{$stack_ref}, $state_hash_ref->{$k}); } @@ -1450,16 +1455,21 @@ sub _target_update_ok { my $state = $state_hash_ref->{$key}; $state->set_value($STATE->DONE); # If this target is needed by other targets... + my @released_pending_states; while (my ($k, $s) = each(%{$state->get_needed_by()})) { my $pending_for_ref = $s->get_pending_for(); delete($pending_for_ref->{$key}); if ($s->is_pending() && !keys(%{$pending_for_ref})) { $s->set_value($STATE->READY); if (!grep {$_->get_id() eq $k} @{$stack_ref}) { - push(@{$stack_ref}, $s); + push(@released_pending_states, $s); } } } + push( + @{$stack_ref}, + sort {$a->get_id() cmp $b->get_id()} @released_pending_states, + ); if (defined($elapsed_time)) { # Done target update my $target0 = $ctx->get_target_of()->{$target->get_key()}; $target0->set_info_of({}); # unset diff --git a/lib/FCM/Util/Locator/SSH.pm b/lib/FCM/Util/Locator/SSH.pm index 979a21fe..17dbc2c5 100644 --- a/lib/FCM/Util/Locator/SSH.pm +++ b/lib/FCM/Util/Locator/SSH.pm @@ -57,10 +57,10 @@ sub _can_work_with { if (!$value) { return; } - my ($auth) = split(':', $value, 2); - if (!$auth) { + if (index($value, ':') < 0) { return; } + my ($auth) = split(':', $value, 2); my $host = index($auth, '@') >= 0 ? (split('@', $auth, 2))[1] : $auth; $host ? gethostbyname($host) : undef; } diff --git a/t/fcm-make/07-build-ns-dep.t b/t/fcm-make/07-build-ns-dep.t index e11a2b39..261cc875 100755 --- a/t/fcm-make/07-build-ns-dep.t +++ b/t/fcm-make/07-build-ns-dep.t @@ -60,9 +60,9 @@ file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<'__LOG__' [info] source->target main/hello.f90 -> (install) include/ hello.f90 [info] source->target main/hello.f90 -> (compile) o/ hello.o [info] target hello.exe +[info] target - greet.o [info] target - hello.o [info] target - world.o -[info] target - greet.o __LOG__ #------------------------------------------------------------------------------- exit 0 diff --git a/t/fcm-make/08-build-dup-dep.t b/t/fcm-make/08-build-dup-dep.t index 6d42ef6d..087f6219 100755 --- a/t/fcm-make/08-build-dup-dep.t +++ b/t/fcm-make/08-build-dup-dep.t @@ -52,9 +52,9 @@ file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<'__LOG__' [info] source->target main/hello.f90 -> (install) include/ hello.f90 [info] source->target main/hello.f90 -> (compile) o/ hello.o [info] target hello.exe +[info] target - greet.o [info] target - hello.o [info] target - world.o -[info] target - greet.o __LOG__ #------------------------------------------------------------------------------- exit 0 diff --git a/t/fcm-make/09-build-dep-o.t b/t/fcm-make/09-build-dep-o.t index d55247ac..64f49920 100755 --- a/t/fcm-make/09-build-dep-o.t +++ b/t/fcm-make/09-build-dep-o.t @@ -48,17 +48,17 @@ file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<'__LOG__' [info] source->target main/hi.f90 -> (install) include/ hi.f90 [info] source->target main/hi.f90 -> (compile) o/ hi.o [info] target hi.exe -[info] target - hi.o -[info] target - world.o [info] target - greet.o [info] target - - greet_fmt_mod.mod [info] target - - - greet_fmt_mod.o [info] target - greet_fmt_mod.o -[info] target hello.exe -[info] target - hello.o +[info] target - hi.o [info] target - world.o +[info] target hello.exe [info] target - greet.o (n-deps=1) [info] target - greet_fmt_mod.o +[info] target - hello.o +[info] target - world.o __LOG__ #------------------------------------------------------------------------------- exit 0 diff --git a/t/fcm-make/14-build-etc.t b/t/fcm-make/14-build-etc.t index d6d3fe33..8ff670e0 100755 --- a/t/fcm-make/14-build-etc.t +++ b/t/fcm-make/14-build-etc.t @@ -47,8 +47,8 @@ foo <- foo hello.txt <- hello.txt hi/hi-earth.txt <- hi/hi-earth.txt hi/hi-mars.txt <- hi/hi-mars.txt -.etc <- hi/.etc <- hi +.etc <- __LOG__ #------------------------------------------------------------------------------- TEST_KEY="$TEST_KEY_BASE-incr" diff --git a/t/fcm-make/16-build-dep-o-2.t b/t/fcm-make/16-build-dep-o-2.t index 9dfc9996..e8da6e0d 100755 --- a/t/fcm-make/16-build-dep-o-2.t +++ b/t/fcm-make/16-build-dep-o-2.t @@ -41,10 +41,10 @@ file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<'__LOG__' [info] source->target hello_sub.f90 -> (compile) o/ hello_sub.o [info] target hello.exe [info] target - hello.o +[info] target - hello_mod.o [info] target - hello_sub.o [info] target - - hello_mod.mod [info] target - - - hello_mod.o -[info] target - hello_mod.o __LOG__ #------------------------------------------------------------------------------- exit 0 diff --git a/t/fcm-make/17-build-cyclic.t b/t/fcm-make/17-build-cyclic.t index 52d1b2f1..afda2021 100755 --- a/t/fcm-make/17-build-cyclic.t +++ b/t/fcm-make/17-build-cyclic.t @@ -34,6 +34,8 @@ file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__ERR__' [FAIL] required by: baz.mod [FAIL] required by: foo.o [FAIL] required by: foo.mod +[FAIL] required by: meow.o +[FAIL] required by: meow.mod [FAIL] required by: hello.o [FAIL] required by: hello.exe diff --git a/t/fcm-make/18-build-use-intrinsic.t b/t/fcm-make/18-build-use-intrinsic.t index 1308b649..54809a5f 100755 --- a/t/fcm-make/18-build-use-intrinsic.t +++ b/t/fcm-make/18-build-use-intrinsic.t @@ -30,8 +30,8 @@ sed '/^\[info\] target /!d' .fcm-make/log >"$TEST_KEY.log" file_cmp "$TEST_KEY.log" "$TEST_KEY.log" <<'__LOG__' [info] target greet.exe [info] target - greet.o -[info] target - - hi.interface [info] target - - hello.interface +[info] target - - hi.interface [info] target - hello.o [info] target - hi.o __LOG__ diff --git a/t/fcm-make/36-build-fail-cont-basic.t b/t/fcm-make/36-build-fail-cont-basic.t index 73710a41..d75f6b72 100755 --- a/t/fcm-make/36-build-fail-cont-basic.t +++ b/t/fcm-make/36-build-fail-cont-basic.t @@ -43,9 +43,8 @@ sed -i 's/implicit none/implicit non/' src/greet_mod.f90 # introduce typo run_fail "$TEST_KEY" fcm make --new task_lines_from_log >"$TEST_KEY-log-tasks" file_cmp "$TEST_KEY-log-tasks" "$TEST_KEY-log-tasks" <<'__LOG__' -[FAIL] compile ???? ! greet_mod.o <- greet_mod.f90 [info] compile ???? M world_mod.o <- world_mod.f90 -[FAIL] compile ---- ! hello.o <- hello.f90 +[FAIL] compile ???? ! greet_mod.o <- greet_mod.f90 [FAIL] compile ---- ! hello2.o <- hello2.f90 [info] compile ???? M hello_sub.o <- hello_sub.f90 [info] ext-iface ???? M hello_sub.interface <- hello_sub.f90 @@ -58,8 +57,6 @@ fail_lines_from_log >"$TEST_KEY-log-fails" file_cmp "$TEST_KEY-log-fails" "$TEST_KEY-log-fails" <<'__LOG__' [FAIL] ! greet_mod.mod : depends on failed target: greet_mod.o [FAIL] ! greet_mod.o : update task failed -[FAIL] ! hello : depends on failed target: hello.o -[FAIL] ! hello.o : depends on failed target: greet_mod.mod [FAIL] ! hello2 : depends on failed target: hello2.o [FAIL] ! hello2.o : depends on failed target: greet_mod.mod __LOG__ @@ -69,8 +66,8 @@ sed -i 's/implicit non/implicit none/' src/greet_mod.f90 # fix typo run_pass "$TEST_KEY" fcm make task_lines_from_log >"$TEST_KEY-log-tasks" file_cmp "$TEST_KEY-log-tasks" "$TEST_KEY-log-tasks" <<'__LOG__' -[info] compile ???? M greet_mod.o <- greet_mod.f90 [info] compile ---- U world_mod.o <- world_mod.f90 +[info] compile ???? M greet_mod.o <- greet_mod.f90 [info] compile ???? M hello.o <- hello.f90 [info] link ???? M hello <- hello.f90 [info] compile ???? M hello2.o <- hello2.f90 @@ -91,8 +88,8 @@ sed -i 's/implicit none/implicit non/' src/hello_sub.f90 # introduce typo run_fail "$TEST_KEY" fcm make --new task_lines_from_log >"$TEST_KEY-log-tasks" file_cmp "$TEST_KEY-log-tasks" "$TEST_KEY-log-tasks" <<'__LOG__' -[info] compile ???? M greet_mod.o <- greet_mod.f90 [info] compile ???? M world_mod.o <- world_mod.f90 +[info] compile ???? M greet_mod.o <- greet_mod.f90 [info] compile ???? M hello.o <- hello.f90 [info] link ???? M hello <- hello.f90 [info] compile ???? M hello2.o <- hello2.f90 @@ -116,8 +113,8 @@ sed -i 's/implicit non/implicit none/' src/hello_sub.f90 # fix typo run_pass "$TEST_KEY" fcm make task_lines_from_log >"$TEST_KEY-log-tasks" file_cmp "$TEST_KEY-log-tasks" "$TEST_KEY-log-tasks" <<'__LOG__' -[info] compile ---- U greet_mod.o <- greet_mod.f90 [info] compile ---- U world_mod.o <- world_mod.f90 +[info] compile ---- U greet_mod.o <- greet_mod.f90 [info] compile ---- U hello.o <- hello.f90 [info] link ---- U hello <- hello.f90 [info] compile ---- U hello2.o <- hello2.f90