Set of scripts used for various projects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
2.1 KiB

  1. #!/bin/sh -
  2. #
  3. # Script to reduce a test case down to a smaller set by deleting
  4. # lines.
  5. # Start by making the file into a single file via:
  6. # cc -E -o newcfile.c -c inputfile.c
  7. #
  8. # Update the script w/ the compile command that will test for the
  9. # failiure you're looking for. It is at the line marked UPDATE ME.
  10. #
  11. # And then run the script:
  12. # sh test.case.reduce.sh newcfile.c
  13. #
  14. # After the run, it'll report how many lines were dropped, and
  15. # the final test case will be named test.c.
  16. #
  17. # This isn't perfect (I know there is a better tool out there, but
  18. # I can't remember/find it) in that it leaves blocks of code that
  19. # are multiple lines where any one removed causes an error when
  20. # compiling. This can be delt w/ by hand at the end as it's a bit
  21. # easier, but could be improved by trying to delete n lines instead
  22. # of just 1 for increasing n (or maybe decreasing n?).
  23. #
  24. # In my test case of reducing, it took a 2163 line file down to
  25. # 313 befor manually reducing it to 18 lines.
  26. cp "$1" "test.c"
  27. totdroppedlines=0
  28. droppedlines=1
  29. while [ $droppedlines -ne 0 ]; do
  30. droppedlines=0
  31. i=0
  32. while :; do
  33. linecount=$(wc -l < test.c)
  34. if [ $i -eq $linecount ]; then
  35. break
  36. fi
  37. while [ $i -lt $linecount ]; do
  38. # try to delete next line
  39. (if [ $i -gt 0 ]; then head -n $i test.c; fi; tail -n +$(($i + 2)) test.c ) > curtest.c
  40. #echo curtest line count: $(wc -l < curtest.c)
  41. # modify this function such that when the test case
  42. # still "fails" that it returns success.
  43. #
  44. # In this case, we are checking for a specific
  45. # error message.
  46. #
  47. # ====== UPDATE ME ======
  48. 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
  49. echo dropping line $(($i + 1 + $droppedlines))
  50. droppedlines=$(($droppedlines + 1))
  51. mv curtest.c test.c
  52. break
  53. fi
  54. i=$(($i + 1))
  55. echo keeping line $(($i + $droppedlines))
  56. done
  57. done
  58. echo dropped $droppedlines lines
  59. totdroppedlines=$(($totdroppedlines + $droppedlines))
  60. done
  61. echo dropped $totdroppedlines lines in total