From a07c68f05edd754e389e0757ed2deefd70aad364 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 17 Nov 2010 15:30:07 +0000 Subject: [PATCH] * Finally, a test for the binary patch functionality. --- tests/Makefile.am | 3 ++- tests/binary-patching.nix | 15 +++++++++++++++ tests/binary-patching.sh | 33 +++++++++++++++++++++++++++++++++ tests/init.sh | 6 +++++- tests/nix-push.sh | 2 +- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tests/binary-patching.nix create mode 100644 tests/binary-patching.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index beb7852db..88925fbd9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,7 +7,8 @@ TESTS = init.sh hash.sh lang.sh add.sh simple.sh dependencies.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 \ gc-runtime.sh install-package.sh check-refs.sh filter-source.sh \ - remote-store.sh export.sh export-graph.sh negative-caching.sh + remote-store.sh export.sh export-graph.sh negative-caching.sh \ + binary-patching.sh XFAIL_TESTS = diff --git a/tests/binary-patching.nix b/tests/binary-patching.nix new file mode 100644 index 000000000..781bd76eb --- /dev/null +++ b/tests/binary-patching.nix @@ -0,0 +1,15 @@ +{ version }: + +with import ./config.nix; + +mkDerivation { + name = "foo-${toString version}"; + builder = builtins.toFile "builder.sh" + '' + mkdir $out + seq 1 1000000 > $out/foo + ${if version == 2 then '' + echo bla >> $out/foo + '' else ""} + ''; +} diff --git a/tests/binary-patching.sh b/tests/binary-patching.sh new file mode 100644 index 000000000..8d7788fb6 --- /dev/null +++ b/tests/binary-patching.sh @@ -0,0 +1,33 @@ +source common.sh + +mkdir -p $TEST_ROOT/cache2 $TEST_ROOT/patches + +RESULT=$TEST_ROOT/result + +# Build version 1 and 2 of the "foo" package. +$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest1 \ + $($nixbuild -o $RESULT binary-patching.nix --arg version 1) + +out2=$($nixbuild -o $RESULT binary-patching.nix --arg version 2) +$NIX_BIN_DIR/nix-push --copy $TEST_ROOT/cache2 $TEST_ROOT/manifest2 $out2 +rm $RESULT + +# Generate a binary patch. +$NIX_BIN_DIR/generate-patches.pl $TEST_ROOT/cache2 $TEST_ROOT/patches \ + file://$TEST_ROOT/patches $TEST_ROOT/manifest1 $TEST_ROOT/manifest2 + +grep -q "patch {" $TEST_ROOT/manifest2 + +# Get rid of version 2. +$nixstore --delete $out2 +! test -e $out2 + +# Pull the manifest containing the patch. +clearManifests +$NIX_BIN_DIR/nix-pull file://$TEST_ROOT/manifest2 + +# To make sure that we're using the patch, delete the full NARs. +rm -f $TEST_ROOT/cache2/* + +# Now rebuild it. This should use the patch generated above. +$nixbuild -o $RESULT binary-patching.nix --arg version 2 diff --git a/tests/init.sh b/tests/init.sh index 64947031b..cdc7aca83 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -23,6 +23,8 @@ ln -s $nixinstantiate $NIX_BIN_DIR/ ln -s $nixhash $NIX_BIN_DIR/ ln -s $nixenv $NIX_BIN_DIR/ ln -s $nixworker $NIX_BIN_DIR/ +ln -s $TOP/src/bsdiff-*/bsdiff $NIX_BIN_DIR/ +ln -s $TOP/src/bsdiff-*/bspatch $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-prefetch-url $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-collect-garbage $NIX_BIN_DIR/ ln -s $TOP/scripts/nix-build $NIX_BIN_DIR/ @@ -34,6 +36,7 @@ ln -s $bzip2_bin_test/bzip2 $NIX_BIN_DIR/nix/ ln -s $bzip2_bin_test/bunzip2 $NIX_BIN_DIR/nix/ ln -s $TOP/scripts/copy-from-other-stores.pl $NIX_BIN_DIR/nix/ ln -s $TOP/scripts/download-using-manifests.pl $NIX_BIN_DIR/nix/ +ln -s $TOP/scripts/generate-patches.pl $NIX_BIN_DIR/ ln -s $TOP/scripts/readmanifest.pm $NIX_BIN_DIR/nix/ cat > "$NIX_CONF_DIR"/nix.conf < $i.tmp \ -e "s^$REAL_BIN_DIR/nix-store^$NIX_BIN_DIR/nix-store^" \ diff --git a/tests/nix-push.sh b/tests/nix-push.sh index a9a2f5f9c..0a35e3b97 100644 --- a/tests/nix-push.sh +++ b/tests/nix-push.sh @@ -5,7 +5,7 @@ outPath=$($nixstore -r $drvPath) echo "pushing $drvPath" -mkdir $TEST_ROOT/cache +mkdir -p $TEST_ROOT/cache $NIX_BIN_DIR/nix-push \ --copy $TEST_ROOT/cache $TEST_ROOT/manifest $drvPath