#!/bin/bash # Test script for 2**31 read bug. # This is _really_ slow. # Takes about 30 minutes on 2.8GHz i7 # G. Margo 2011-07-26 # Flags input_generate=1 # Generate input file input_check=1 # Check input file against expected input input_remove=1 # Remove input file # Constants INPUTFILE=readtest_in.txt limit=16909400 # With line length=127, errors out after 16909321 fmt="%09d-%s-%09d" padding="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB" ########################################################################### # Generate input file with line length 127. if [ $input_generate -ne 0 ]; then rm -f "$INPUTFILE" echo "Generating input file" # The shell way, _really_ slow (14 minutes) #for (( line=1 ; line <= limit ; line++ )) #do # printf "$fmt\n" $line $padding $line #done > "$INPUTFILE" # The perl way (20 seconds) perl -e "printf \"$fmt\\n\", \$_, \"$padding\", \$_ foreach 1 .. $limit;" > "$INPUTFILE" fi ########################################################################### # Check input against expected if [ $input_check -ne 0 ]; then echo "Checking input against expected" count=0 for (( line=1 ; line <= limit ; line++ )) do read rline if [ $? -ne 0 ]; then echo "Error: early EOF on input" (( count++ )) break; fi printf -v eline $fmt $line $padding $line if [ "$rline" != "$eline" ]; then echo "Error: line $line: expected: $eline" echo "Error: line $line: received: $rline" (( count++ )) fi done < "$INPUTFILE" echo "There were $count errors in $limit lines" fi ########################################################################### # Remove input file if [ $input_remove -ne 0 ]; then rm -f "$INPUTFILE" fi