about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/common.sh.in10
-rw-r--r--tests/gc-runtime.builder.sh8
-rw-r--r--tests/gc-runtime.nix.in7
-rw-r--r--tests/gc-runtime.sh39
5 files changed, 64 insertions, 5 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8a432d8996d6..cab1f6a327a2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -13,11 +13,13 @@ fallback.sh: fallback.nix
 gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix
 user-envs.sh: user-envs.nix
 fixed.sh: fixed.nix
+gc-runtime.sh: gc-runtime.nix
 
 TESTS = init.sh hash.sh lang.sh add.sh simple.sh dependencies.sh \
   locking.sh parallel.sh build-hook.sh substitutes.sh substitutes2.sh \
   fallback.sh nix-push.sh gc.sh gc-concurrent.sh verify.sh nix-pull.sh \
-  referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh
+  referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \
+  gc-runtime.sh
 
 XFAIL_TESTS =
 
@@ -39,5 +41,6 @@ EXTRA_DIST = $(TESTS) \
   fallback.nix.in \
   user-envs.nix.in user-envs.builder.sh \
   fixed.nix.in fixed.builder1.sh fixed.builder2.sh \
+  gc-runtime.nix.in gc-runtime.builder.sh \
   $(wildcard lang/*.nix) $(wildcard lang/*.exp) \
   common.sh.in
diff --git a/tests/common.sh.in b/tests/common.sh.in
index f96f28d206c9..12162649e4b2 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -1,10 +1,12 @@
 set -e
 
-# Maybe the build directory is symlinked.
-export NIX_IGNORE_SYMLINK_STORE=1
-
 export TEST_ROOT=$(pwd)/test-tmp
-export NIX_STORE_DIR=$TEST_ROOT/store
+export NIX_STORE_DIR
+if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store); then
+    # Maybe the build directory is symlinked.
+    export NIX_IGNORE_SYMLINK_STORE=1
+    NIX_STORE_DIR=$TEST_ROOT/store
+fi
 export NIX_DATA_DIR=$TEST_ROOT/data
 export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
 export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
diff --git a/tests/gc-runtime.builder.sh b/tests/gc-runtime.builder.sh
new file mode 100644
index 000000000000..a8c2d3e09150
--- /dev/null
+++ b/tests/gc-runtime.builder.sh
@@ -0,0 +1,8 @@
+mkdir $out
+
+cat > $out/program <<EOF
+#! $SHELL
+sleep 10000
+EOF
+
+chmod +x $out/program
diff --git a/tests/gc-runtime.nix.in b/tests/gc-runtime.nix.in
new file mode 100644
index 000000000000..e54fcf2d15ad
--- /dev/null
+++ b/tests/gc-runtime.nix.in
@@ -0,0 +1,7 @@
+derivation {
+  name = "gc-runtime";
+  system = "@system@";
+  builder = "@shell@";
+  args = ["-e" "-x" ./gc-runtime.builder.sh];
+  PATH = "@coreutils@";
+}
diff --git a/tests/gc-runtime.sh b/tests/gc-runtime.sh
new file mode 100644
index 000000000000..5a6e0da8cda2
--- /dev/null
+++ b/tests/gc-runtime.sh
@@ -0,0 +1,39 @@
+source common.sh
+
+case $system in
+    *linux*)
+        ;;
+    *)
+        exit 0;
+esac
+
+set -m # enable job control, needed for kill
+
+profiles="$NIX_STATE_DIR"/profiles
+rm -f $profiles/*
+
+$nixenv -p $profiles/test -f ./gc-runtime.nix -i gc-runtime
+
+outPath=$($nixenv -p $profiles/test -q --no-name --out-path gc-runtime)
+echo $outPath
+
+echo "backgrounding program..."
+$profiles/test/program &
+child=$!
+echo PID=$child
+
+$nixenv -p $profiles/test -e gc-runtime
+$nixenv -p $profiles/test --delete-generations old
+
+cp $TOP/scripts/find-runtime-roots.pl $TEST_ROOT/foo.pl
+chmod +x $TEST_ROOT/foo.pl
+NIX_ROOT_FINDER=$TEST_ROOT/foo.pl $nixstore --gc
+
+kill -- -$child
+
+if ! test -e $outPath; then
+    echo "running program was garbage collected!"
+    exit 1
+fi
+
+exit 0