summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2021-09-06 15:17:12 +0100
committerPádraig Brady <P@draigBrady.com>2021-09-15 20:44:16 +0100
commitad6c8e1181a3966e35d68c1c354deb1c73f3e974 (patch)
tree43ec3b95effbbaa70ae782b79e6c2f26883590ea /tests
parent6a5c561b4fb3018d284d03747c612527e0c89571 (diff)
downloadcoreutils-ad6c8e1181a3966e35d68c1c354deb1c73f3e974.tar.gz
coreutils-ad6c8e1181a3966e35d68c1c354deb1c73f3e974.zip
cksum: add --algorithm option to select digest mode
* src/digest.c: Organize HASH_ALGO_CKSUM to be table driven, and amalgamate all digest algorithms. (main): Parse all options if HASH_ALGO_CKSUM, and disallow --tag, --zero, and --check with the traditional bsd, sysv, and crc checksums for now. * src/local.mk: Reorganize to include all digest modules in cksum. * tests/misc/cksum-a.sh: Add a new test. * tests/misc/b2sum.sh: Update to default to checking with cksum, as b2sum's implementation diverges a bit from the others. * tests/local.mk: Reference the new test. * doc/coreutils.texi (cksum invocation): Adjust the summary to identify the new mode, and document the new --algorithm option. * man/cksum.x: Adjust description to be more general. * man/*sum.x: Add [See Also] section referencing cksum(1). * NEWS: Mention the new feature.
Diffstat (limited to 'tests')
-rw-r--r--tests/local.mk1
-rwxr-xr-xtests/misc/b2sum.sh27
-rwxr-xr-xtests/misc/cksum-a.sh43
3 files changed, 61 insertions, 10 deletions
diff --git a/tests/local.mk b/tests/local.mk
index 4a08147df..3ddd6f1bb 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -289,6 +289,7 @@ all_tests = \
tests/misc/close-stdout.sh \
tests/misc/chroot-fail.sh \
tests/misc/cksum.sh \
+ tests/misc/cksum-a.sh \
tests/misc/comm.pl \
tests/misc/csplit.sh \
tests/misc/csplit-1000.sh \
diff --git a/tests/misc/b2sum.sh b/tests/misc/b2sum.sh
index 730516cb8..c5242bed2 100755
--- a/tests/misc/b2sum.sh
+++ b/tests/misc/b2sum.sh
@@ -17,38 +17,45 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ b2sum
+print_ver_ cksum
+
+for prog in 'b2sum' 'cksum -a blake2b'; do
+# Also check b2sum if built
+[ "$prog" = 'b2sum' ] && { $prog --version || continue; }
# Ensure we can --check the --tag format we produce
-rm check.b2sum
+rm -f check.b2sum || framework_failure_
for i in 'a' ' b' '*c' '44' ' '; do
echo "$i" > "$i"
for l in 0 128; do
- b2sum -l $l --tag "$i" >> check.b2sum
+ $prog -l $l --tag "$i" >> check.b2sum
done
done
# Note -l is inferred from the tags in the mixed format file
-b2sum --strict -c check.b2sum || fail=1
+$prog --strict -c check.b2sum || fail=1
# Also ensure the openssl tagged variant works
sed 's/ //; s/ =/=/' < check.b2sum > openssl.b2sum || framework_failure_
-b2sum --strict -c openssl.b2sum || fail=1
+$prog --strict -c openssl.b2sum || fail=1
+rm -f check.vals || framework_failure_
# Ensure we can check non tagged format
for l in 0 128; do
- b2sum -l $l /dev/null | tee -a check.vals > check.b2sum
- b2sum -l $l --strict -c check.b2sum || fail=1
- b2sum --strict -c check.b2sum || fail=1
+ $prog -l $l /dev/null | tee -a check.vals > check.b2sum
+ $prog -l $l --strict -c check.b2sum || fail=1
+ $prog --strict -c check.b2sum || fail=1
done
# Ensure the checksum values are correct. The reference
# check.vals was created with the upstream SSE reference implementation.
-b2sum -l 128 check.vals > out || fail=1
+$prog --length=128 check.vals > out || fail=1
printf '%s\n' '796485dd32fe9b754ea5fd6c721271d9 check.vals' > exp
compare exp out || fail=1
# This would segfault from coreutils-8.26 to coreutils-8.28
printf '%s\n' 'BLAKE2' 'BLAKE2b' 'BLAKE2-' 'BLAKE2(' 'BLAKE2 (' > crash.check \
|| framework_failure_
-returns_ 1 b2sum -c crash.check || fail=1
+returns_ 1 $prog -c crash.check || fail=1
+
+done
Exit $fail
diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh
new file mode 100755
index 000000000..7d95b69a4
--- /dev/null
+++ b/tests/misc/cksum-a.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Validate cksum --algorithm operation
+
+# Copyright (C) 2021 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cksum
+
+printf "
+bsd sum -r
+sysv sum -s
+crc cksum
+md5 md5um -t
+sha1 sha1sum -t
+sha224 sha224sum -t
+sha256 sha256sum -t
+sha384 sha384sum -t
+sha512 sha512sum -t
+blake2b b2sum -t
+" | while read algo prog; do
+ $prog < /dev/null >> out || continue
+ cksum --algorithm=$algo < /dev/null >> out-a || fail=1
+done
+compare out out-a || fail=1
+
+returns_ 1 cksum -a bsd --tag </dev/null
+returns_ 1 cksum -a bsd --zero </dev/null
+returns_ 1 cksum -a bsd --check </dev/null
+
+Exit $fail