xref: /aosp_15_r20/external/toybox/tests/cksum.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Worker
6*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
7*cf5a6c84SAndroid Build Coastguard Worker
8*cf5a6c84SAndroid Build Coastguard Worker# Default behavior on stdin and on files.
9*cf5a6c84SAndroid Build Coastguard Workertesting "on stdin" "echo -n hello | cksum" "3287646509 5\n" "" ""
10*cf5a6c84SAndroid Build Coastguard Workerecho -n "hello" > tmpfile
11*cf5a6c84SAndroid Build Coastguard Workertesting "on file" "cksum tmpfile" "3287646509 5 tmpfile\n" "" ""
12*cf5a6c84SAndroid Build Coastguard Workerrm -f tmpfile
13*cf5a6c84SAndroid Build Coastguard Workertouch one two
14*cf5a6c84SAndroid Build Coastguard Workertesting "on multiple files" "cksum one two" "4294967295 0 one\n4294967295 0 two\n" "" ""
15*cf5a6c84SAndroid Build Coastguard Workerrm -f one two
16*cf5a6c84SAndroid Build Coastguard Worker
17*cf5a6c84SAndroid Build Coastguard Worker# Check the length suppression, both calculate the CRC on 'abc' but the second
18*cf5a6c84SAndroid Build Coastguard Worker# option has length suppression on and has the length concatenated to 'abc'.
19*cf5a6c84SAndroid Build Coastguard Workertesting "on abc including length" "cksum" "1219131554 3\n" "" 'abc'
20*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "on abc excluding length" "cksum -N" "1219131554\n" "" 'abc\x3'
21*cf5a6c84SAndroid Build Coastguard Worker
22*cf5a6c84SAndroid Build Coastguard Worker# cksum on no contents gives 0xffffffff (=4294967295)
23*cf5a6c84SAndroid Build Coastguard Workertesting "on no data post-inversion" "echo -n "" | cksum" "4294967295 0\n" "" ""
24*cf5a6c84SAndroid Build Coastguard Worker# If we do preinversion we will then get 0.
25*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "on no data pre+post-inversion" "echo -n "" | cksum -P" "0 0\n" "" ""
26*cf5a6c84SAndroid Build Coastguard Worker# If we skip the post-inversion we also get 0
27*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "on no data no inversion" "echo -n "" | cksum -I" "0 0\n" "" ""
28*cf5a6c84SAndroid Build Coastguard Worker# Two wrongs make a right.
29*cf5a6c84SAndroid Build Coastguard Workertoyonly testing "on no data pre-inversion" "echo -n "" | cksum -PI" "4294967295 0\n" "" ""
30