From 6aa1d08a1ca86f46a44ed7afe802dd638c793400 Mon Sep 17 00:00:00 2001 From: Binh Vo Date: Fri, 3 Dec 2021 15:31:33 -0500 Subject: [PATCH 1/5] Change zstdless behavior to align with zless --- programs/zstdless | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/programs/zstdless b/programs/zstdless index 893799e7d95..10e7695473e 100755 --- a/programs/zstdless +++ b/programs/zstdless @@ -1,2 +1,6 @@ #!/bin/sh -zstdcat "$@" | less + +# TODO: Address quirks and bugs tied to old versions of less, provide a mechanism to pass flags directly to zstd + +export LESSOPEN="|zstd -cdfq %s" +less "$@" From e59e72bb3d2143bfeedea3368d333b89b540a2e8 Mon Sep 17 00:00:00 2001 From: Binh Vo Date: Wed, 19 Jan 2022 21:43:23 -0500 Subject: [PATCH 2/5] Add simple tests --- tests/playTests.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/playTests.sh b/tests/playTests.sh index b7a3d88a817..5dcf0deb8f6 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -89,6 +89,7 @@ PRGDIR="$SCRIPT_DIR/../programs" TESTDIR="$SCRIPT_DIR/../tests" UNAME=$(uname) ZSTDGREP="$PRGDIR/zstdgrep" +ZSTDLESS="$PRGDIR/zstdless" detectedTerminal=false if [ -t 0 ] && [ -t 1 ] @@ -322,6 +323,15 @@ ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst && die "Should have fail ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true rm -f tmp_grep* +println "\n===> zstdless tests" +rm -f tmp_less +echo "1234" > tmp_less +zstd -f tmp_less +lines=$("$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) +test 1 -eq $lines +"$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || true +rm -f tmp_less* + println "\n===> --exclude-compressed flag" rm -rf precompressedFilterTestDir mkdir -p precompressedFilterTestDir From c439f5df65a2d470bf46a0a0e907465deb9d43ac Mon Sep 17 00:00:00 2001 From: Binh Vo Date: Fri, 21 Jan 2022 11:15:14 -0500 Subject: [PATCH 3/5] Additional test and restore reverted commit --- programs/zstdless | 6 ++++-- tests/playTests.sh | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/programs/zstdless b/programs/zstdless index 10e7695473e..17726a4f6e1 100755 --- a/programs/zstdless +++ b/programs/zstdless @@ -1,6 +1,8 @@ #!/bin/sh +zstd=${ZSTD:-zstd} + # TODO: Address quirks and bugs tied to old versions of less, provide a mechanism to pass flags directly to zstd -export LESSOPEN="|zstd -cdfq %s" -less "$@" +export LESSOPEN="|-${zstd} -cdfq %s" +exec less "$@" diff --git a/tests/playTests.sh b/tests/playTests.sh index 5dcf0deb8f6..4bc6c3fb232 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -324,12 +324,16 @@ ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or rm -f tmp_grep* println "\n===> zstdless tests" -rm -f tmp_less +ln -sf "$ZSTD_BIN" zstd +rm -f tmp_less* echo "1234" > tmp_less zstd -f tmp_less -lines=$("$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) +lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) test 1 -eq $lines -"$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || true +ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated +cat tmp_less_regenerated +$DIFF tmp_less tmp_less_regenerated +ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || true rm -f tmp_less* println "\n===> --exclude-compressed flag" From 332db9d1edcf0427a226a26e852fa7b453939fb2 Mon Sep 17 00:00:00 2001 From: Binh Vo Date: Fri, 21 Jan 2022 16:48:35 -0500 Subject: [PATCH 4/5] Test fixes --- tests/playTests.sh | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/playTests.sh b/tests/playTests.sh index 4bc6c3fb232..041deb1eb18 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -324,17 +324,18 @@ ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or rm -f tmp_grep* println "\n===> zstdless tests" -ln -sf "$ZSTD_BIN" zstd -rm -f tmp_less* -echo "1234" > tmp_less -zstd -f tmp_less -lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) -test 1 -eq $lines -ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated -cat tmp_less_regenerated -$DIFF tmp_less tmp_less_regenerated -ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || true -rm -f tmp_less* +if [ -n "$(which less)" ]; then + ln -sf "$ZSTD_BIN" zstd + rm -f tmp_less* + echo "1234" > tmp_less + zstd -f tmp_less + lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) + test 1 -eq $lines + ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated + $DIFF tmp_less tmp_less_regenerated + ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || die + rm -f tmp_less* +fi println "\n===> --exclude-compressed flag" rm -rf precompressedFilterTestDir From 874e4af99f2a3c28ec229e4c991c75d101be9158 Mon Sep 17 00:00:00 2001 From: Binh Vo Date: Wed, 26 Jan 2022 10:22:37 -0500 Subject: [PATCH 5/5] Refactor zstdgrep and zstdless tests --- tests/Makefile | 12 ++++-- tests/a.txt | 4 ++ tests/playTests.sh | 27 ------------- tests/playToolTests.sh | 87 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 tests/a.txt create mode 100755 tests/playToolTests.sh diff --git a/tests/Makefile b/tests/Makefile index 132fa7a0818..e3a69b65a61 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -288,7 +288,7 @@ list: .PHONY: shortest shortest: ZSTDRTTEST= # remove long tests -shortest: test-zstd +shortest: test-zstd test-zstdtools .PHONY: check check: shortest @@ -297,7 +297,7 @@ check: shortest fuzztest: test-fuzzer test-zstream test-decodecorpus .PHONY: test -test: test-zstd test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus +test: test-zstd test-zstdtools test-fullbench test-fuzzer test-zstream test-invalidDictionaries test-legacy test-decodecorpus ifeq ($(QEMU_SYS),) test: test-pool endif @@ -308,7 +308,7 @@ test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zstream32 .PHONY: test-all test-all: test test32 valgrindTest test-decodecorpus-cli -.PHONY: test-zstd test-zstd32 test-zstd-nolegacy test-zstdgrep +.PHONY: test-zstd test-zstd32 test-zstdtools test-zstd-nolegacy test-zstdgrep test-zstd: ZSTD = $(PRGDIR)/zstd test-zstd: zstd @@ -322,6 +322,12 @@ test-zstd test-zstd32 test-zstd-nolegacy: datagen file $(ZSTD) EXE_PREFIX="$(QEMU_SYS)" ZSTD_BIN="$(ZSTD)" DATAGEN_BIN=./datagen ./playTests.sh $(ZSTDRTTEST) +test-zstdtools: ZSTD = $(PRGDIR)/zstd + +test-zstdtools: zstd + file $(ZSTD) + ZSTD_BIN="$(ZSTD)" ./playToolTests.sh + test-fullbench: fullbench datagen $(QEMU_SYS) ./fullbench -i1 $(QEMU_SYS) ./fullbench -i1 -P0 diff --git a/tests/a.txt b/tests/a.txt new file mode 100644 index 00000000000..3ded3d49b52 --- /dev/null +++ b/tests/a.txt @@ -0,0 +1,4 @@ +asdf + + +jkl diff --git a/tests/playTests.sh b/tests/playTests.sh index 041deb1eb18..0540a94fae2 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -88,8 +88,6 @@ SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) PRGDIR="$SCRIPT_DIR/../programs" TESTDIR="$SCRIPT_DIR/../tests" UNAME=$(uname) -ZSTDGREP="$PRGDIR/zstdgrep" -ZSTDLESS="$PRGDIR/zstdless" detectedTerminal=false if [ -t 0 ] && [ -t 1 ] @@ -312,31 +310,6 @@ if [ "$isWindows" = false ]; then fi fi -println "\n===> zstdgrep tests" -ln -sf "$ZSTD_BIN" zstdcat -rm -f tmp_grep -echo "1234" > tmp_grep -zstd -f tmp_grep -lines=$(ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep tmp_grep.zst | wc -l) -test 2 -eq $lines -ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst && die "Should have failed" -ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true -rm -f tmp_grep* - -println "\n===> zstdless tests" -if [ -n "$(which less)" ]; then - ln -sf "$ZSTD_BIN" zstd - rm -f tmp_less* - echo "1234" > tmp_less - zstd -f tmp_less - lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) - test 1 -eq $lines - ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated - $DIFF tmp_less tmp_less_regenerated - ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || die - rm -f tmp_less* -fi - println "\n===> --exclude-compressed flag" rm -rf precompressedFilterTestDir mkdir -p precompressedFilterTestDir diff --git a/tests/playToolTests.sh b/tests/playToolTests.sh new file mode 100755 index 00000000000..12c08ffe9d6 --- /dev/null +++ b/tests/playToolTests.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +set -e + +die() { + println "$@" 1>&2 + exit 1 +} + +zstd() { + if [ -z "$EXEC_PREFIX" ]; then + "$ZSTD_BIN" "$@" + else + "$EXEC_PREFIX" "$ZSTD_BIN" "$@" + fi +} + +println() { + printf '%b\n' "${*}" +} + +SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) +PRGDIR="$SCRIPT_DIR/../programs" +UNAME=$(uname) +ZSTDGREP="$PRGDIR/zstdgrep" +ZSTDLESS="$PRGDIR/zstdless" + +INTOVOID="/dev/null" +case "$UNAME" in + GNU) DEVDEVICE="/dev/random" ;; + *) DEVDEVICE="/dev/zero" ;; +esac +case "$OS" in + Windows*) + INTOVOID="NUL" + DEVDEVICE="NUL" + ;; +esac + +DIFF="diff" +case "$UNAME" in + SunOS) DIFF="gdiff" ;; +esac + +# check if ZSTD_BIN is defined. if not, use the default value +if [ -z "${ZSTD_BIN}" ]; then + println "\nZSTD_BIN is not set. Using the default value..." + ZSTD_BIN="$PRGDIR/zstd" +fi + +# assertions +[ -n "$ZSTD_BIN" ] || die "zstd not found at $ZSTD_BIN! \n Please define ZSTD_BIN pointing to the zstd binary. You might also consider rebuilding zstd following the instructions in README.md" +println "\nStarting playToolTests.sh EXE_PREFIX='$EXE_PREFIX' ZSTD_BIN='$ZSTD_BIN' DATAGEN_BIN='$DATAGEN_BIN'" + + + +# tool tests + +println "\n===> zstdgrep tests" +ln -sf "$ZSTD_BIN" zstdcat +rm -f tmp_grep +echo "1234" > tmp_grep +zstd -f tmp_grep +lines=$(ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep tmp_grep.zst | wc -l) +test 2 -eq $lines +ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst && die "Should have failed" +ZCAT=./zstdcat "$ZSTDGREP" 2>&1 "1234" tmp_grep_bad.zst | grep "No such file or directory" || true +rm -f tmp_grep* + +println "\n===> zstdless tests" +if [ -n "$(which less)" ]; then + ln -sf "$ZSTD_BIN" zstd + rm -f tmp_less* + echo "1234" > tmp_less + echo "foo" >> tmp_less + echo "bar" >> tmp_less + less -N -f tmp_less > tmp_less_counted + zstd -f tmp_less + lines=$(ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less.zst | wc -l) + test 3 -eq $lines + ZSTD=./zstd "$ZSTDLESS" -f tmp_less.zst > tmp_less_regenerated + $DIFF tmp_less tmp_less_regenerated + ZSTD=./zstd "$ZSTDLESS" -N -f tmp_less.zst > tmp_less_regenerated_counted + $DIFF tmp_less_counted tmp_less_regenerated_counted + ZSTD=./zstd "$ZSTDLESS" 2>&1 tmp_less_bad.zst | grep "No such file or directory" || die + rm -f tmp_less* +fi