tail: always fail when followed files become inaccessible
[coreutils.git] / tests / cksum / cksum.sh
blob3665a070d9fdcc4219fa7fd8a8946376ae389881
1 #!/bin/sh
2 # Validate cksum operation
4 # Copyright (C) 2020-2024 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cksum printf
23 returns_ 1 cksum missing || fail=1
25 # Pass in expected crc and crc32b for file "in"
26 # Sets fail=1 upon failure
27 crc_check() {
28 for crct in crc crc32b; do
29 cksum -a $crct in > out || fail=1
30 case "$crct" in crc) crce="$1";; crc32b) crce="$2";; esac
31 size=$(stat -c %s in) || framework_failure_
32 printf '%s\n' "$crce $size in" > exp || framework_failure_
33 compare exp out || fail=1
34 done
38 # Check complete range of bytes
40 for offset in $(seq -1 6); do
41 env printf $(env printf '\\%03o' $(seq 0 $offset));
42 env printf $(env printf '\\%03o' $(seq 0 255));
43 done
44 } > in || framework_failure_
45 crc_check 4097727897 559400337
47 # Make sure crc is correct for files larger than 128 bytes (4 fold pclmul)
49 env printf $(env printf '\\%03o' $(seq 0 130));
50 } > in || framework_failure_
51 crc_check 3800919234 3739179551
53 # Make sure crc is correct for files larger than 32 bytes
54 # but <128 bytes (1 fold pclmul)
56 env printf $(env printf '\\%03o' $(seq 0 64));
57 } > in || framework_failure_
58 crc_check 796287823 1086353368
60 # Make sure crc is still handled correctly when next 65k buffer is read
61 # (>32 bytes more than 65k)
63 seq 1 12780
64 } > in || framework_failure_
65 crc_check 3720986905 388883562
67 # Make sure crc is still handled correctly when next 65k buffer is read
68 # (>=128 bytes more than 65k)
70 seq 1 12795
71 } > in || framework_failure_
72 crc_check 4278270357 2796628507
75 Exit $fail