summaryrefslogtreecommitdiffhomepage
path: root/tests/zos/fuzz.sh
blob: 3bc921c97cee2d619e98c8affee4901227d1bc70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# z/OS: a bounded, deterministic fuzz of the paths only z/OS has.
#
# The other z/OS tests claim what the output should be.  This one only
# claims that nothing falls over: every iteration must end with a small
# status, no runtime message from a protection exception or an ABEND,
# and a file that ls -T can still look at afterwards.
#
# The generator is inline and not a function: a function called in $( )
# runs in a subshell and would never advance the seed.  A fixed seed
# means a failure can be repeated by hand.  The arithmetic stays inside
# 32 bits so that /bin/sh (ksh) runs this too without warning about an
# overflow.
command -v chtag >/dev/null 2>&1 || exit 77

# The nearest thing z/OS has to ASan: a check zone after every heap
# element and a heap check on each request, both above the 2 GB bar as
# well as below.  An overlay abends the shell (U4042) and prints CEE3716I,
# either of which the loop below counts as a crash.
_CEE_RUNOPTS='HEAPZONES(0,ABEND,32,ABEND) HEAPCHK(ON)'
export _CEE_RUNOPTS

echo text >of   # so every branch below has a file to look at
seed=12345
crashes=0
i=0
while [ $i -lt 200 ]; do
    i=$((i + 1))
    seed=$(((seed * 75 + 74) % 65537))
    n=$((seed % 12))
    seed=$(((seed * 75 + 74) % 65537))
    k=$((seed % 9999))
    case $n in
    0) echo text >of ;;
    1) _TAG_REDIR_OUT=TXT printf 'a\nb\n' >of ;;
    2) _TAG_REDIR_OUT=BIN printf 'a\nb\n' >of; chtag -tc IBM-1047 of; cat of ;;
    3) printf 'a b c\n' | cat | tr -d ' ' >of ;;
    4) { echo a; cat of; } >of ;;
    5) { echo a >&3; echo b; } 3>&1 1>/dev/null >of ;;
    6) chtag -tc "IBM-$k" of >/dev/null 2>&1; tag of >/dev/null ;;
    7) cp -T "//'$k'" of >/dev/null 2>&1 ;;
    8) alloc "dd(f$i)" "da('sys1.maclib(getmain)')" "$((k % 2))" >/dev/null 2>&1
       free "dd(f$i)" >/dev/null 2>&1 ;;
    9) echo x | cat | cat | cat | cat | cat >of ;;
    10) read -t 0 v <of 2>/dev/null; : "$v" ;;
    11) { echo a; } 4<of 5>of2; cat of2 2>/dev/null ;;
    esac >/dev/null 2>err
    st=$?
    if [ "$st" -ge 128 ]; then
        crashes=$((crashes + 1))
        echo "iteration $i: status $st from case $n"
    fi
    if grep -q -E 'CEE3|S0C[0-9]|ABEND' err; then
        crashes=$((crashes + 1))
        echo "iteration $i: $(head -n 1 err)"
    fi
    ls -T of >/dev/null 2>&1 || echo "iteration $i: no tag for of"
done

echo "iterations: $i"
echo "crashes: $crashes"