Skip to content
Myr

Streaming parser torture tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nicolas Williams · parent 845ad5e · Browse files · 2 files+95 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+95 added−4 removed

  • tests:+95 added−4 removed

2 files+95 added−4 removed

added:tests/modules/streaming.jq+41 added
12# Filter and adjust streamed values so that only values from the .th3# level are output.4def trunc(inputs):5 . as $n | inputs | . as $input | if (.[0]|length) > 1 then setpath([0];$input[0][1:]) else empty end;67# Reduce streamed values back to normal8def tovalues(i):9 foreach i as $item (10 # [<current value being built>,11 # <is current value valid?>,12 # <previous, complete value>,13 # <is previous value valid?>]14 [null,false,null,false];1516 # Updator17 # 18 # If the new $item is a top-level value,19 # then clear out the current value20 if ($item[0]|length) == 0 then [null,false,.[2],.[3]]21 # else if the new $item terminates the current value,22 # then rotate the current value into the previous value slot.23 elif ($item|length) == 1 and ($item[0]|length) < 2 then [null,false,.[0],.[1]]24 else . end |25 . as $state |26 # If the new $item has a leaf, upate the current value27 if ($item|length) > 1 and ($item[0]|length) > 0 then28 [.[0]|setpath(($item|.[0]); ($item|.[1])), # update current value29 true, # current value is now valid (if, perhaps, incomplete)30 $state[2], # previous value is unchanged31 $state[3]] # previous value is unchanged32 else .33 end;3435 # Extractor36 #37 # If previous value is valid, output it38 if ($item[0]|length) == 1 and ($item|length == 1) and .[3] then .[2] else empty end,39 # and/or if the new $item is a top-level scalar, output it40 if ($item[0]|length) == 0 then $item[1] else empty end41 );
modified:tests/run+54 added-4 removed
10 unmodified lines
11fi1213cat $@ | $VALGRIND $Q ./jq --run-tests1415set -x1617mods=$PWD/tests/modules1819clean=true20d=16trap '[ -n "$d" ] && rm -rf "$d"' EXIT21clean () {22 if ! $clean; then23 echo "See temp files in $d!"24 elif [ -n "$d" ]; then25 rm -rf "$d"26 fi27}28trap clean EXIT29d=`mktemp -d -t || true`30if [ -z "$d" ]; then31 echo "Your OS does not support mktemp(1) -d" 1>&232 exit 0
101 unmodified lines
134$VALGRIND $Q ./jq -c '. as $d|path(..) as $p|$d|getpath($p)|scalars_or_empty|[$p,.]' < "$PWD/tests/torture/input0.json" > $d/out0135$VALGRIND $Q ./jq --stream -c '.|select(length==2)' < "$PWD/tests/torture/input0.json" > $d/out1136diff $d/out0 $d/out1137138clean=false139if which seq > /dev/null 2>&1; then140 # XXX We should try every prefix of input0.json, but that makes this141 # test very, very slow when run with valgrind, and the whole point142 # is to run it with valgrind.143 #144 #len=`wc -c < "$PWD/tests/torture/input0.json"`145 if [ -z "$VALGRIND" ]; then146 start=1147 end=`wc -c < "$PWD/tests/torture/input0.json"`148 else149 start=120150 end=151151 fi152 for i in `seq $start $end`; do153 dd "if=tests/torture/input0.json" bs=$i count=1 2>/dev/null |154 $VALGRIND ./jq -c . > $d/out0 2>$d/err || true155 if [ -n "$VALGRIND" ]; then156 grep '^==[0-9][0-9]*== ERROR SUMMARY: 0 errors' $d/err > /dev/null157 else158 tail -1 $d/err | egrep -i 'assert|abort|core' && false159 fi160161 dd "if=tests/torture/input0.json" bs=$i count=1 2>/dev/null |162 $VALGRIND ./jq -cn --stream -L "$mods" 'import streaming; tovalues(inputs)' > $d/out1 2>$d/err || true163 if [ -n "$VALGRIND" ]; then164 grep '^==[0-9][0-9]*== ERROR SUMMARY: 0 errors' $d/err > /dev/null165 else166 tail -1 $d/err | egrep -i 'assert|abort|core' && false167 fi168169 diff $d/out0 $d/out1170 done171else172 echo "Not doing torture tests"173fi174175## Fuzz parser176177clean=false178if dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null; then179 # Have a /dev/urandom, good130 set -x180 $VALGRIND $Q ./jq --seq . $d/rand >/dev/null 2>&1181 $VALGRIND $Q ./jq --seq --stream . $d/rand >/dev/null 2>&1182 dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null183 $VALGRIND $Q ./jq --seq . $d/rand >/dev/null 2>&1
1 unmodified line
185 dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null186 $VALGRIND $Q ./jq --seq . $d/rand >/dev/null 2>&1187 $VALGRIND $Q ./jq --seq --stream . $d/rand >/dev/null 2>&1188fi189clean=true190191## Test library/module system192143mods=$PWD/tests/modules144193if [ "`HOME="$mods" $VALGRIND $Q ./jq -nr fg`" != foobar ]; then194 echo "Bug #479 appears to be back" 1>&2195 exit 1196fi
52 unmodified lines
249 echo "Memory errors when programs have syntax errors" 1>&2250 cat $d/out251 exit 1252fi253254exit 0