|
- #!/bin/sh -
-
- #
- # Script to reduce a test case down to a smaller set by deleting
- # lines.
-
- # Start by making the file into a single file via:
- # cc -E -o newcfile.c -c inputfile.c
- #
- # Update the script w/ the compile command that will test for the
- # failiure you're looking for. It is at the line marked UPDATE ME.
- #
- # And then run the script:
- # sh test.case.reduce.sh newcfile.c
- #
- # After the run, it'll report how many lines were dropped, and
- # the final test case will be named test.c.
- #
- # This isn't perfect (I know there is a better tool out there, but
- # I can't remember/find it) in that it leaves blocks of code that
- # are multiple lines where any one removed causes an error when
- # compiling. This can be delt w/ by hand at the end as it's a bit
- # easier, but could be improved by trying to delete n lines instead
- # of just 1 for increasing n (or maybe decreasing n?).
- #
- # In my test case of reducing, it took a 2163 line file down to
- # 313 befor manually reducing it to 18 lines.
-
- cp "$1" "test.c"
-
- totdroppedlines=0
- droppedlines=1
- while [ $droppedlines -ne 0 ]; do
- droppedlines=0
- i=0
- while :; do
- linecount=$(wc -l < test.c)
-
- if [ $i -eq $linecount ]; then
- break
- fi
-
- while [ $i -lt $linecount ]; do
- # try to delete next line
- (if [ $i -gt 0 ]; then head -n $i test.c; fi; tail -n +$(($i + 2)) test.c ) > curtest.c
- #echo curtest line count: $(wc -l < curtest.c)
-
- # modify this function such that when the test case
- # still "fails" that it returns success.
- #
- # In this case, we are checking for a specific
- # error message.
- #
- # ====== UPDATE ME ======
- if arm-none-eabi-gcc -Werror=stringop-overflow=1 -mcpu=cortex-m3 -mthumb -O2 -g -Wall -Werror -c curtest.c 2>&1 | grep 'accessing 160 bytes in a region of size 32' > /dev/null; then
- echo dropping line $(($i + 1 + $droppedlines))
- droppedlines=$(($droppedlines + 1))
- mv curtest.c test.c
- break
- fi
- i=$(($i + 1))
- echo keeping line $(($i + $droppedlines))
- done
- done
-
- echo dropped $droppedlines lines
-
- totdroppedlines=$(($totdroppedlines + $droppedlines))
- done
-
- echo dropped $totdroppedlines lines in total
|