fluffy

Network Archaeology tools for Unix
git clone https://git.woozle.org/neale/fluffy.git

Neale Pickett  ·  2021-02-02

test.sh

 1#! /bin/sh
 2
 3tests=0
 4successes=0
 5failures=0
 6
 7H () {
 8    printf "\n%-20s " "$*"
 9}
10
11title() {
12    thistest="$1"
13    tests=$(($tests + 1))
14}
15
16successes=0
17pass () {
18    printf '.'
19    successes=$(($successes + 1))
20}
21
22failures=0
23fail () {
24    printf '(%s)' "$thistest"
25    failures=$(($failures + 1))
26}
27
28
29H "xor"
30
31title "single-byte decimal"
32printf 'hello' | ./xor 22 | grep -q '~szzy' && pass || fail
33
34title "single-byte hex"
35printf 'hello' | ./xor 0x16 | grep -q '~szzy' && pass || fail
36
37title "single-byte -x"
38printf 'hello' | ./xor -x 16 | grep -q '~szzy' && pass || fail
39
40
41H "hex/unhex"
42
43title "hex"
44printf ' hello' | ./hex | grep -q '68 65 6c 6c 6f' && pass || fail
45
46title "unhex"
47echo '68 65 6c 6c 6f' | ./unhex | grep -q 'hello' && pass || fail
48
49
50H "slice"
51
52title "slice begin"
53printf 'hello' | ./slice 2 | grep -qx 'llo' && pass || fail
54
55title "slice begin + end"
56printf 'hello' | ./slice 2 4 | grep -qx 'll' && pass || fail
57
58title "slice begin + end + begin"
59printf 'hello' | ./slice 0 2 4 | grep -qx 'heo' && pass || fail
60
61
62H "hd"
63
64title "hd short"
65printf 'hello' | ./hd | grep -qx '00000000  68 65 6c 6c 6f.*hello' && pass || fail
66
67
68H "Everything else"
69
70title "entropy"
71printf 'hello' | ./entropy | grep -q 1.921928 && pass || fail
72
73title "pyesc"
74printf '\0hello\n' | ./pyesc | grep -xq '.x00hello.n' && pass || fail
75
76title "freq"
77printf 'hello' | ./freq | grep -xq '2 6c l' && pass || fail
78
79title "histogram"
80printf 'hello' | ./freq | ./histogram | grep -xq '6c l ## 2' && pass || fail
81
82echo
83echo
84echo "$successes of $tests tests passed ($failures failed)."
85
86exit $failures