Skip to content

Commit

Permalink
Merge pull request #186 from matthewrmshin/fix-t-sort
Browse files Browse the repository at this point in the history
Improve test battery stability
  • Loading branch information
benfitzpatrick committed Apr 23, 2015
2 parents fec2f35 + 094267e commit cab3b4b
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 25 deletions.
5 changes: 4 additions & 1 deletion bin/fcm_test_battery
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
22 changes: 16 additions & 6 deletions lib/FCM/System/Make/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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})) {
Expand Down Expand Up @@ -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})) {
Expand Down Expand Up @@ -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});
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/FCM/Util/Locator/SSH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion t/fcm-make/07-build-ns-dep.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion t/fcm-make/08-build-dup-dep.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions t/fcm-make/09-build-dep-o.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion t/fcm-make/14-build-etc.t
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion t/fcm-make/16-build-dep-o-2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions t/fcm-make/17-build-cyclic.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion t/fcm-make/18-build-use-intrinsic.t
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
11 changes: 4 additions & 7 deletions t/fcm-make/36-build-fail-cont-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit cab3b4b

Please sign in to comment.