From 9f33d4c98d6c37681c92b360dfcd9b80e40a2abb Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Thu, 17 Mar 2011 13:25:27 +0000 Subject: [PATCH] --- configure.ac | 4 ++++ tests/Makefile.am | 3 +++ tests/Setup.pm | 20 +++++++++++++++++--- tests/evaluation-tests.pl.in | 8 +++++++- tests/jobs/basic.nix | 10 ++++------ tests/jobs/build-output-as-input.nix | 18 ++++++++++++++++++ tests/jobs/bzr-checkout-input.nix | 5 +++-- tests/jobs/bzr-input.nix | 5 +++-- tests/jobs/config.nix.in | 9 +++++++++ tests/jobs/empty-dir-builder.sh | 2 ++ tests/jobs/fail.sh | 1 + tests/jobs/git-input.nix | 5 +++-- tests/jobs/hg-input.nix | 5 +++-- tests/jobs/scm-builder.sh | 1 + tests/jobs/succeed-with-failed.sh | 1 + tests/jobs/svn-checkout-input.nix | 5 +++-- tests/jobs/svn-input.nix | 5 +++-- 17 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 tests/jobs/build-output-as-input.nix create mode 100644 tests/jobs/config.nix.in diff --git a/configure.ac b/configure.ac index 1a67a831..a788ad8f 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,9 @@ LIBS="$old_LIBS" PKG_CHECK_MODULES([BDW_GC], [bdw-gc]) +testPath="$(dirname $(type -p expr))" +AC_SUBST(testPath) + AC_CONFIG_FILES([ Makefile doc/Makefile @@ -56,6 +59,7 @@ AC_CONFIG_FILES([ src/root/Makefile src/script/Makefile tests/Makefile + tests/jobs/config.nix ]) AC_CONFIG_FILES([src/script/hydra_build.pl], [chmod +x src/script/hydra_build.pl]) diff --git a/tests/Makefile.am b/tests/Makefile.am index df6dbbdf..02373447 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,6 +4,7 @@ TESTS_ENVIRONMENT = \ HYDRA_DATA="$(abs_builddir)/data" \ HYDRA_HOME="$(top_srcdir)/src" \ NIX_REMOTE= \ + NIX_CONF_DIR="$(abs_builddir)/nix/etc/nix" \ NIX_STATE_DIR="$(abs_builddir)/nix/var/nix" \ NIX_STORE_DIR="$(abs_builddir)/nix/store" \ NIX_LOG_DIR="$(abs_builddir)/nix/var/log/nix" \ @@ -35,6 +36,8 @@ dirs : mkdir -p data touch data/hydra.conf mkdir -p nix + mkdir -p nix/etc/nix + touch nix/etc/nix/nix.conf mkdir -p nix/store mkdir -p nix/var diff --git a/tests/Setup.pm b/tests/Setup.pm index 4c4fd389..f3c045a4 100644 --- a/tests/Setup.pm +++ b/tests/Setup.pm @@ -2,9 +2,12 @@ package Setup; use strict; use Exporter; +use Hydra::Helper::Nix; +use Hydra::Helper::AddBuilds; +use Cwd; our @ISA = qw(Exporter); -our @EXPORT = qw(hydra_setup); +our @EXPORT = qw(hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild); sub hydra_setup { my ($db) = @_; @@ -16,14 +19,20 @@ sub nrBuildsForJobset { return $jobset->builds->search({},{})->count ; } +sub queuedBuildsForJobset { + my ($jobset) = @_; + return $jobset->builds->search({},{ join => 'schedulingInfo' }); +} + sub nrQueuedBuildsForJobset { my ($jobset) = @_; - return $jobset->builds->search({},{ join => 'schedulingInfo' })->count ; + return queuedBuildsForJobset($jobset)->count ; } sub createBaseJobset { my ($jobsetName, $nixexprpath) = @_; - my $project = $db->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"}); + + my $project = openHydraDB->resultset('Projects')->update_or_create({name => "tests", displayname => "", owner => "root"}); my $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""}); my $jobsetinput; @@ -55,4 +64,9 @@ sub evalSucceeds { return $res; } +sub runBuild { + my ($build) = @_; + return captureStdoutStderr(60, ("../src/script/hydra_build.pl", $build->id)); +} + 1; diff --git a/tests/evaluation-tests.pl.in b/tests/evaluation-tests.pl.in index 7d770346..361f80cc 100755 --- a/tests/evaluation-tests.pl.in +++ b/tests/evaluation-tests.pl.in @@ -10,7 +10,7 @@ use Setup; my $db = openHydraDB; -use Test::Simple tests => 16; +use Test::Simple tests => 22; hydra_setup($db); @@ -28,6 +28,12 @@ $jobset = createBaseJobset("basic", "basic.nix"); ok(evalSucceeds($jobset), "Evaluating jobs/basic.nix should exit with return code 0"); ok(nrQueuedBuildsForJobset($jobset) == 3 , "Evaluating jobs/basic.nix should result in 3 builds"); +for my $build (queuedBuildsForJobset($jobset)) { + ok(runBuild($build), "Build '".$build->job->name."' from jobs/basic.nix should exit with code 0"); + my $newbuild = $db->resultset('Builds')->find($build->id); + my $expected = $build->job->name eq "fails" ? 1 : 0; + ok($newbuild->buildresultinfo->buildstatus == $expected, "Build '".$build->job->name."' from jobs/basic.nix should have buildstatus $expected"); +} # Test jobset with 2 jobs, one has parameter of succeeded build of the other $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1"); diff --git a/tests/jobs/basic.nix b/tests/jobs/basic.nix index da8bf3cd..45e6306f 100644 --- a/tests/jobs/basic.nix +++ b/tests/jobs/basic.nix @@ -1,22 +1,20 @@ +with import ./config.nix; { empty_dir = - derivation { + mkDerivation { name = "empty-dir"; - system = builtins.currentSystem; builder = ./empty-dir-builder.sh; }; fails = - derivation { + mkDerivation { name = "fails"; - system = builtins.currentSystem; builder = ./fail.sh; }; succeed_with_failed = - derivation { + mkDerivation { name = "succeed-with-failed"; - system = builtins.currentSystem; builder = ./succeed-with-failed.sh; }; } diff --git a/tests/jobs/build-output-as-input.nix b/tests/jobs/build-output-as-input.nix new file mode 100644 index 00000000..a8c3063e --- /dev/null +++ b/tests/jobs/build-output-as-input.nix @@ -0,0 +1,18 @@ +with import ./config.nix; +let + jobs = { + build1 = + mkDerivation { + name = "build1"; + builder = ./empty-dir-builder.sh; + }; + + build2 = + {build1 ? jobs.build1 }: + mkDerivation { + name = "build2"; + builder = ./empty-dir-builder.sh; + inherit build1; + }; + }; +in jobs diff --git a/tests/jobs/bzr-checkout-input.nix b/tests/jobs/bzr-checkout-input.nix index 8f40fd4d..b4de66c3 100644 --- a/tests/jobs/bzr-checkout-input.nix +++ b/tests/jobs/bzr-checkout-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "bzr-checkout-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; } diff --git a/tests/jobs/bzr-input.nix b/tests/jobs/bzr-input.nix index 6bccd29e..554b94c9 100644 --- a/tests/jobs/bzr-input.nix +++ b/tests/jobs/bzr-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "bzr-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; } diff --git a/tests/jobs/config.nix.in b/tests/jobs/config.nix.in new file mode 100644 index 00000000..51b6c06f --- /dev/null +++ b/tests/jobs/config.nix.in @@ -0,0 +1,9 @@ +rec { + path = "@testPath@"; + + mkDerivation = args: + derivation ({ + system = builtins.currentSystem; + PATH = path; + } // args); +} diff --git a/tests/jobs/empty-dir-builder.sh b/tests/jobs/empty-dir-builder.sh index 03697d30..addc7ef6 100755 --- a/tests/jobs/empty-dir-builder.sh +++ b/tests/jobs/empty-dir-builder.sh @@ -1 +1,3 @@ +#! /bin/sh + mkdir $out diff --git a/tests/jobs/fail.sh b/tests/jobs/fail.sh index 379a4c98..2526efb6 100755 --- a/tests/jobs/fail.sh +++ b/tests/jobs/fail.sh @@ -1 +1,2 @@ +#! /bin/sh exit 1 diff --git a/tests/jobs/git-input.nix b/tests/jobs/git-input.nix index 55e5b87b..14552fc3 100644 --- a/tests/jobs/git-input.nix +++ b/tests/jobs/git-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "git-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; } diff --git a/tests/jobs/hg-input.nix b/tests/jobs/hg-input.nix index 902c876b..d1d69a1c 100644 --- a/tests/jobs/hg-input.nix +++ b/tests/jobs/hg-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "hg-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; } diff --git a/tests/jobs/scm-builder.sh b/tests/jobs/scm-builder.sh index 83eefbe8..92e8c22c 100755 --- a/tests/jobs/scm-builder.sh +++ b/tests/jobs/scm-builder.sh @@ -1,2 +1,3 @@ +#! /bin/sh mkdir $out cp -v $src/* $out/ diff --git a/tests/jobs/succeed-with-failed.sh b/tests/jobs/succeed-with-failed.sh index ad1be8e5..51f79931 100755 --- a/tests/jobs/succeed-with-failed.sh +++ b/tests/jobs/succeed-with-failed.sh @@ -1,2 +1,3 @@ +#! /bin/sh mkdir -p $out/nix-support/failed diff --git a/tests/jobs/svn-checkout-input.nix b/tests/jobs/svn-checkout-input.nix index 8f40fd4d..b4de66c3 100644 --- a/tests/jobs/svn-checkout-input.nix +++ b/tests/jobs/svn-checkout-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "bzr-checkout-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; } diff --git a/tests/jobs/svn-input.nix b/tests/jobs/svn-input.nix index 2d2dfb2c..a6eba674 100644 --- a/tests/jobs/svn-input.nix +++ b/tests/jobs/svn-input.nix @@ -1,9 +1,10 @@ +with import ./config.nix; { src }: { copy = - derivation { + mkDerivation { name = "svn-input"; - system = builtins.currentSystem; builder = ./scm-builder.sh; + inherit src; }; }