From a9858c9f26c5be743e0bbe1949954f6bd2497306 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 May 2004 17:04:17 +0000 Subject: [PATCH] * A test to verify that Nix executes build jobs in parallel, if possible. This test fails right now because this hasn't been implemented right now. Yes, I'm doing Test-Driven Development! ;-) --- substitute.mk | 1 + tests/Makefile.am | 12 +++++++++--- tests/parallel.builder.sh | 32 ++++++++++++++++++++++++++++++++ tests/parallel.nix.in | 19 +++++++++++++++++++ tests/parallel.sh | 20 ++++++++++++++++++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 tests/parallel.builder.sh create mode 100644 tests/parallel.nix.in create mode 100644 tests/parallel.sh diff --git a/substitute.mk b/substitute.mk index 848029a02..7d3f6d863 100644 --- a/substitute.mk +++ b/substitute.mk @@ -1,5 +1,6 @@ %: %.in Makefile sed \ + -e "s^@extra1\@^$(extra1)^g" \ -e "s^@prefix\@^$(prefix)^g" \ -e "s^@bindir\@^$(bindir)^g" \ -e "s^@sysconfdir\@^$(sysconfdir)^g" \ diff --git a/tests/Makefile.am b/tests/Makefile.am index ba45a3ad8..d540290b4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ TEST_ROOT = $(shell pwd)/test-tmp +extra1 = $(TEST_ROOT)/shared + TESTS_ENVIRONMENT = TEST_ROOT=$(TEST_ROOT) \ NIX_STORE_DIR=$(TEST_ROOT)/store \ NIX_DATA_DIR=$(TEST_ROOT)/data \ @@ -7,19 +9,23 @@ TESTS_ENVIRONMENT = TEST_ROOT=$(TEST_ROOT) \ NIX_STATE_DIR=$(TEST_ROOT)/state \ NIX_DB_DIR=$(TEST_ROOT)/db \ TOP=$(shell pwd)/.. \ + SHARED=$(extra1) \ $(SHELL) -e -x simple.sh: simple.nix dependencies.sh: dependencies.nix locking.sh: locking.nix +parallel.sh: parallel.nix -TESTS = init.sh simple.sh dependencies.sh locking.sh +TESTS = init.sh simple.sh dependencies.sh parallel.sh +#locking.sh parallel.sh -XFAIL_TESTS = +XFAIL_TESTS = parallel.sh include ../substitute.mk EXTRA_DIST = $(TESTS) \ simple.nix.in simple.builder.sh \ dependencies.nix.in dependencies.builder*.sh \ - locking.nix.in locking.builder.sh \ No newline at end of file + locking.nix.in locking.builder.sh \ + parallel.nix.in parallel.builder.sh diff --git a/tests/parallel.builder.sh b/tests/parallel.builder.sh new file mode 100644 index 000000000..d6d0bedf4 --- /dev/null +++ b/tests/parallel.builder.sh @@ -0,0 +1,32 @@ +echo "DOING $text" + + +export PATH=/bin:/usr/bin:$PATH + + +# increase counter +while ! ln -s x $shared.lock; do + sleep 1 +done +test -f $shared.cur || echo 0 > $shared.cur +test -f $shared.max || echo 0 > $shared.max +new=$(($(cat $shared.cur) + 1)) +if test $new -gt $(cat $shared.max); then + echo $new > $shared.max +fi +echo $new > $shared.cur +rm $shared.lock + + +echo -n $(cat $inputs)$text > $out + +sleep 3 + + +# decrease counter +while ! ln -s x $shared.lock; do + sleep 1 +done +test -f $shared.cur || echo 0 > $shared.cur +echo $(($(cat $shared.cur) - 1)) > $shared.cur +rm $shared.lock diff --git a/tests/parallel.nix.in b/tests/parallel.nix.in new file mode 100644 index 000000000..41d6776d1 --- /dev/null +++ b/tests/parallel.nix.in @@ -0,0 +1,19 @@ +let { + + mkDrv = text: inputs: derivation { + name = "parallel"; + system = "@system@"; + builder = "@shell@"; + args = ["-e" "-x" ./parallel.builder.sh]; + shared = "@extra1@"; + inherit text inputs; + }; + + a = mkDrv "a" []; + b = mkDrv "b" [a]; + c = mkDrv "c" [b]; + d = mkDrv "d" [c]; + e = mkDrv "e" [b c d]; + + body = e; +} \ No newline at end of file diff --git a/tests/parallel.sh b/tests/parallel.sh new file mode 100644 index 000000000..7040f7ad9 --- /dev/null +++ b/tests/parallel.sh @@ -0,0 +1,20 @@ +storeExpr=$($TOP/src/nix-instantiate/nix-instantiate parallel.nix) + +echo "store expr is $storeExpr" + +for i in $(seq 1 5); do + echo "WORKER $i" + $TOP/src/nix-store/nix-store -rvvB "$storeExpr" & +done + +sleep 5 + +outPath=$($TOP/src/nix-store/nix-store -qnfvvvvv "$storeExpr") + +echo "output path is $outPath" + +text=$(cat "$outPath") +if test "$text" != "aabcade"; then exit 1; fi + +if test "$(cat $SHARED.cur)" != 0; then exit 1; fi +if test "$(cat $SHARED.max)" != 3; then exit 1; fi