diff --git a/tests/local.mk b/tests/local.mk index 2dea58e7b..dd168ce3f 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -138,7 +138,9 @@ nix_tests = \ toString-path.sh overlay-local-store-tests := \ - $(d)/overlay-local-store/outer.sh \ + $(d)/overlay-local-store/check-post-init.sh \ + $(d)/overlay-local-store/redundant-add.sh \ + $(d)/overlay-local-store/build.sh \ $(d)/overlay-local-store/bad-uris.sh install-tests-groups += overlay-local-store diff --git a/tests/overlay-local-store/build-inner.sh b/tests/overlay-local-store/build-inner.sh new file mode 100755 index 000000000..969de282d --- /dev/null +++ b/tests/overlay-local-store/build-inner.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +set -x + +source common.sh + +storeDirs + +initLowerStore + +mountOverlayfs + +### Do a build in overlay store + +path=$(nix-build ../hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB" --no-out-link) + +# Checking for path in lower layer (should fail) +expect 1 stat $(toRealPath "$storeA/nix/store" "$path") + +# Checking for path in upper layer +stat $(toRealPath "$storeBTop" "$path") + +# Verifying path in overlay store +nix-store --verify-path --store "$storeB" "$path" diff --git a/tests/overlay-local-store/outer.sh b/tests/overlay-local-store/build.sh similarity index 50% rename from tests/overlay-local-store/outer.sh rename to tests/overlay-local-store/build.sh index ba55f1d06..758585400 100755 --- a/tests/overlay-local-store/outer.sh +++ b/tests/overlay-local-store/build.sh @@ -2,4 +2,4 @@ source common.sh requireEnvironment setupConfig -exec unshare --mount --map-root-user ./inner.sh +execUnshare ./build-inner.sh diff --git a/tests/overlay-local-store/inner.sh b/tests/overlay-local-store/check-post-init-inner.sh similarity index 68% rename from tests/overlay-local-store/inner.sh rename to tests/overlay-local-store/check-post-init-inner.sh index adbe29557..421b64934 100755 --- a/tests/overlay-local-store/inner.sh +++ b/tests/overlay-local-store/check-post-init-inner.sh @@ -65,29 +65,3 @@ hashPart=$(echo $path | sed "s^$NIX_STORE_DIR/^^" | sed 's/-.*//') # merged store can find from hash part [[ $(nix store --store $storeB path-from-hash-part $hashPart) == $path ]] - -### Do a redundant add - -# upper layer should not have it -expect 1 stat $(toRealPath "$storeBTop/nix/store" "$path") - -path=$(nix-store --store "$storeB" --add ../dummy) - -# lower store should have it from before -stat $(toRealPath "$storeA/nix/store" "$path") - -# upper layer should still not have it (no redundant copy) -expect 1 stat $(toRealPath "$storeB/nix/store" "$path") - -### Do a build in overlay store - -path=$(nix-build ../hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB" --no-out-link) - -# Checking for path in lower layer (should fail) -expect 1 stat $(toRealPath "$storeA/nix/store" "$path") - -# Checking for path in upper layer -stat $(toRealPath "$storeBTop" "$path") - -# Verifying path in overlay store -nix-store --verify-path --store "$storeB" "$path" diff --git a/tests/overlay-local-store/check-post-init.sh b/tests/overlay-local-store/check-post-init.sh new file mode 100755 index 000000000..985bf978e --- /dev/null +++ b/tests/overlay-local-store/check-post-init.sh @@ -0,0 +1,5 @@ +source common.sh + +requireEnvironment +setupConfig +execUnshare ./check-post-init-inner.sh diff --git a/tests/overlay-local-store/common.sh b/tests/overlay-local-store/common.sh index 6d9b69b4c..149102000 100644 --- a/tests/overlay-local-store/common.sh +++ b/tests/overlay-local-store/common.sh @@ -1,23 +1,23 @@ source ../common.sh requireEnvironment () { - requireSandboxSupport - [[ $busybox =~ busybox ]] || skipTest "no busybox" - if [[ $(uname) != Linux ]]; then skipTest "Need Linux for overlayfs"; fi - needLocalStore "The test uses --store always so we would just be bypassing the daemon" + requireSandboxSupport + [[ $busybox =~ busybox ]] || skipTest "no busybox" + if [[ $(uname) != Linux ]]; then skipTest "Need Linux for overlayfs"; fi + needLocalStore "The test uses --store always so we would just be bypassing the daemon" } setupConfig () { - echo "drop-supplementary-groups = false" >> "$NIX_CONF_DIR"/nix.conf - echo "build-users-group = " >> "$NIX_CONF_DIR"/nix.conf + echo "drop-supplementary-groups = false" >> "$NIX_CONF_DIR"/nix.conf + echo "build-users-group = " >> "$NIX_CONF_DIR"/nix.conf } storeDirs () { - storeA="$TEST_ROOT/store-a" - storeBTop="$TEST_ROOT/store-b" - storeB="local-overlay?root=$TEST_ROOT/merged-store&lower-store=$storeA&upper-layer=$storeBTop" - # Creating testing directories - mkdir -p "$TEST_ROOT"/{store-a/nix/store,store-b,merged-store/nix/store,workdir} + storeA="$TEST_ROOT/store-a" + storeBTop="$TEST_ROOT/store-b" + storeB="local-overlay?root=$TEST_ROOT/merged-store&lower-store=$storeA&upper-layer=$storeBTop" + # Creating testing directories + mkdir -p "$TEST_ROOT"/{store-a/nix/store,store-b,merged-store/nix/store,workdir} } # Mounting Overlay Store @@ -50,3 +50,7 @@ initLowerStore () { drvPath=$(nix-instantiate --store $storeA ../hermetic.nix --arg busybox "$busybox" --arg seed 1) path=$(nix-store --store "$storeA" --realise $drvPath) } + +execUnshare () { + exec unshare --mount --map-root-user "$@" +} diff --git a/tests/overlay-local-store/redundant-add-inner.sh b/tests/overlay-local-store/redundant-add-inner.sh new file mode 100755 index 000000000..921069c25 --- /dev/null +++ b/tests/overlay-local-store/redundant-add-inner.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +set -x + +source common.sh + +storeDirs + +initLowerStore + +mountOverlayfs + +### Do a redundant add + +# upper layer should not have it +expect 1 stat $(toRealPath "$storeBTop/nix/store" "$path") + +path=$(nix-store --store "$storeB" --add ../dummy) + +# lower store should have it from before +stat $(toRealPath "$storeA/nix/store" "$path") + +# upper layer should still not have it (no redundant copy) +expect 1 stat $(toRealPath "$storeB/nix/store" "$path") diff --git a/tests/overlay-local-store/redundant-add.sh b/tests/overlay-local-store/redundant-add.sh new file mode 100755 index 000000000..fbd4799e7 --- /dev/null +++ b/tests/overlay-local-store/redundant-add.sh @@ -0,0 +1,5 @@ +source common.sh + +requireEnvironment +setupConfig +execUnshare ./redundant-add-inner.sh