This commit is contained in:
Rob Vermaas 2011-03-17 13:25:27 +00:00
parent 10e10e8a8c
commit 9f33d4c98d
17 changed files with 85 additions and 22 deletions

View file

@ -44,6 +44,9 @@ LIBS="$old_LIBS"
PKG_CHECK_MODULES([BDW_GC], [bdw-gc]) PKG_CHECK_MODULES([BDW_GC], [bdw-gc])
testPath="$(dirname $(type -p expr))"
AC_SUBST(testPath)
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
doc/Makefile doc/Makefile
@ -56,6 +59,7 @@ AC_CONFIG_FILES([
src/root/Makefile src/root/Makefile
src/script/Makefile src/script/Makefile
tests/Makefile tests/Makefile
tests/jobs/config.nix
]) ])
AC_CONFIG_FILES([src/script/hydra_build.pl], [chmod +x src/script/hydra_build.pl]) AC_CONFIG_FILES([src/script/hydra_build.pl], [chmod +x src/script/hydra_build.pl])

View file

@ -4,6 +4,7 @@ TESTS_ENVIRONMENT = \
HYDRA_DATA="$(abs_builddir)/data" \ HYDRA_DATA="$(abs_builddir)/data" \
HYDRA_HOME="$(top_srcdir)/src" \ HYDRA_HOME="$(top_srcdir)/src" \
NIX_REMOTE= \ NIX_REMOTE= \
NIX_CONF_DIR="$(abs_builddir)/nix/etc/nix" \
NIX_STATE_DIR="$(abs_builddir)/nix/var/nix" \ NIX_STATE_DIR="$(abs_builddir)/nix/var/nix" \
NIX_STORE_DIR="$(abs_builddir)/nix/store" \ NIX_STORE_DIR="$(abs_builddir)/nix/store" \
NIX_LOG_DIR="$(abs_builddir)/nix/var/log/nix" \ NIX_LOG_DIR="$(abs_builddir)/nix/var/log/nix" \
@ -35,6 +36,8 @@ dirs :
mkdir -p data mkdir -p data
touch data/hydra.conf touch data/hydra.conf
mkdir -p nix mkdir -p nix
mkdir -p nix/etc/nix
touch nix/etc/nix/nix.conf
mkdir -p nix/store mkdir -p nix/store
mkdir -p nix/var mkdir -p nix/var

View file

@ -2,9 +2,12 @@ package Setup;
use strict; use strict;
use Exporter; use Exporter;
use Hydra::Helper::Nix;
use Hydra::Helper::AddBuilds;
use Cwd;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw(hydra_setup); our @EXPORT = qw(hydra_setup nrBuildsForJobset queuedBuildsForJobset nrQueuedBuildsForJobset createBaseJobset createJobsetWithOneInput evalSucceeds runBuild);
sub hydra_setup { sub hydra_setup {
my ($db) = @_; my ($db) = @_;
@ -16,14 +19,20 @@ sub nrBuildsForJobset {
return $jobset->builds->search({},{})->count ; return $jobset->builds->search({},{})->count ;
} }
sub queuedBuildsForJobset {
my ($jobset) = @_;
return $jobset->builds->search({},{ join => 'schedulingInfo' });
}
sub nrQueuedBuildsForJobset { sub nrQueuedBuildsForJobset {
my ($jobset) = @_; my ($jobset) = @_;
return $jobset->builds->search({},{ join => 'schedulingInfo' })->count ; return queuedBuildsForJobset($jobset)->count ;
} }
sub createBaseJobset { sub createBaseJobset {
my ($jobsetName, $nixexprpath) = @_; 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 $jobset = $project->jobsets->create({name => $jobsetName, nixexprinput => "jobs", nixexprpath => $nixexprpath, emailoverride => ""});
my $jobsetinput; my $jobsetinput;
@ -55,4 +64,9 @@ sub evalSucceeds {
return $res; return $res;
} }
sub runBuild {
my ($build) = @_;
return captureStdoutStderr(60, ("../src/script/hydra_build.pl", $build->id));
}
1; 1;

View file

@ -10,7 +10,7 @@ use Setup;
my $db = openHydraDB; my $db = openHydraDB;
use Test::Simple tests => 16; use Test::Simple tests => 22;
hydra_setup($db); 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(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"); 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 # 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"); $jobset = createJobsetWithOneInput("build-output-as-input", "build-output-as-input.nix", "build1", "build", "build1");

View file

@ -1,22 +1,20 @@
with import ./config.nix;
{ {
empty_dir = empty_dir =
derivation { mkDerivation {
name = "empty-dir"; name = "empty-dir";
system = builtins.currentSystem;
builder = ./empty-dir-builder.sh; builder = ./empty-dir-builder.sh;
}; };
fails = fails =
derivation { mkDerivation {
name = "fails"; name = "fails";
system = builtins.currentSystem;
builder = ./fail.sh; builder = ./fail.sh;
}; };
succeed_with_failed = succeed_with_failed =
derivation { mkDerivation {
name = "succeed-with-failed"; name = "succeed-with-failed";
system = builtins.currentSystem;
builder = ./succeed-with-failed.sh; builder = ./succeed-with-failed.sh;
}; };
} }

View file

@ -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

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "bzr-checkout-input"; name = "bzr-checkout-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "bzr-input"; name = "bzr-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }

9
tests/jobs/config.nix.in Normal file
View file

@ -0,0 +1,9 @@
rec {
path = "@testPath@";
mkDerivation = args:
derivation ({
system = builtins.currentSystem;
PATH = path;
} // args);
}

View file

@ -1 +1,3 @@
#! /bin/sh
mkdir $out mkdir $out

View file

@ -1 +1,2 @@
#! /bin/sh
exit 1 exit 1

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "git-input"; name = "git-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "hg-input"; name = "hg-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }

View file

@ -1,2 +1,3 @@
#! /bin/sh
mkdir $out mkdir $out
cp -v $src/* $out/ cp -v $src/* $out/

View file

@ -1,2 +1,3 @@
#! /bin/sh
mkdir -p $out/nix-support/failed mkdir -p $out/nix-support/failed

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "bzr-checkout-input"; name = "bzr-checkout-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }

View file

@ -1,9 +1,10 @@
with import ./config.nix;
{ src }: { src }:
{ {
copy = copy =
derivation { mkDerivation {
name = "svn-input"; name = "svn-input";
system = builtins.currentSystem;
builder = ./scm-builder.sh; builder = ./scm-builder.sh;
inherit src;
}; };
} }