1#!/bin/sh
2# Validate cksum operation
3
4# Copyright (C) 2020-2023 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ cksum printf
21
22returns_ 1 cksum missing || fail=1
23
24{
25  for offset in $(seq -1 6); do
26    env printf $(env printf '\\%03o' $(seq 0 $offset));
27    env printf $(env printf '\\%03o' $(seq 0 255));
28  done
29} > in || framework_failure_
30
31cksum in > out || fail=1
32printf '%s\n' '4097727897 2077 in' > exp || framework_failure_
33compare exp out || fail=1
34
35# Make sure crc is correct for files larger than 128 bytes (4 fold pclmul)
36{
37  env printf $(env printf '\\%03o' $(seq 0 130));
38} > in || framework_failure_
39
40cksum in > out || fail=1
41printf '%s\n' '3800919234 131 in' > exp || framework_failure_
42compare exp out || fail=1
43
44# Make sure crc is correct for files larger than 32 bytes
45# but <128 bytes (1 fold pclmul)
46{
47  env printf $(env printf '\\%03o' $(seq 0 64));
48} > in || framework_failure_
49
50cksum in > out || fail=1
51printf '%s\n' '796287823 65 in' > exp || framework_failure_
52compare exp out || fail=1
53
54# Make sure crc is still handled correctly when next 65k buffer is read
55# (>32 bytes more than 65k)
56{
57  seq 1 12780
58} > in || framework_failure_
59
60cksum in > out || fail=1
61printf '%s\n' '3720986905 65574 in' > exp || framework_failure_
62compare exp out || fail=1
63
64# Make sure crc is still handled correctly when next 65k buffer is read
65# (>=128 bytes more than 65k)
66{
67  seq 1 12795
68} > in || framework_failure_
69
70cksum in > out || fail=1
71printf '%s\n' '4278270357 65664 in' > exp || framework_failure_
72compare exp out || fail=1
73
74Exit $fail
75