test-branch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #! /bin/bash
  2. #
  3. # For testing commits on a branch.
  4. #
  5. # The script loops through all commits in a branch (or between two given commits),
  6. # checks out each, builds INET, and launches a script that runs some simulations.
  7. # If the script exits with nonzero exit code, the commit is tagged in the git repo,
  8. # so commits that break things can be viewed with 'gitk'.
  9. #
  10. if [ $# -eq 0 ]
  11. then
  12. echo "Usage: test-branch <start> <end>"
  13. exit
  14. fi
  15. # range of commits to test; edit to your needs
  16. STARTREV=$1
  17. ENDREV=$2
  18. # build and fingerprint threads
  19. THREADS=7
  20. # the command to run on each commit
  21. COMMAND="./fingerprints -t $THREADS"
  22. # the label (actually, branch) names added to commits where command output changes
  23. LABEL=error
  24. BLABEL=build-error
  25. INET_ROOT=../..
  26. # get the list of commits
  27. commits=`git rev-list --reverse $STARTREV..$ENDREV || exit 1`
  28. # make clean
  29. (cd $INET_ROOT && make cleanall)
  30. rm .buildlog-*
  31. rm *.csv.UPDATED
  32. rm *.csv.diff-*
  33. #clean old branches
  34. i=0
  35. for commit in $commits; do
  36. (( i += 1 ))
  37. git branch -d "$LABEL-$i" 2>/dev/null
  38. git branch -d "$BLABEL-$i" 2>/dev/null
  39. done
  40. i=0
  41. for commit in $commits; do
  42. (( i += 1 ))
  43. echo
  44. echo ---------------------------------------------------
  45. echo -n $i ": "
  46. git log -n 1 --pretty=oneline $commit | cat || exit 1
  47. git checkout -q $commit || exit 1
  48. echo "Building..."
  49. (cd $INET_ROOT && make -f makemakefiles)
  50. if (cd $INET_ROOT && make -j$THREADS) > .buildlog 2>&1; then
  51. : # build OK
  52. else
  53. echo "BUILD ERROR! Tagging with '$BLABEL-$i'"
  54. git branch -f "$BLABEL-$i"
  55. cp .buildlog ".buildlog-$i"
  56. continue
  57. fi
  58. echo "Running test script..."
  59. if $COMMAND > "fp_out-$i.out"; then
  60. rm "fp_out-$i.out"
  61. echo "OK"
  62. else
  63. echo "ERROR! Tagging with '$LABEL-$i'"
  64. git branch -f "$LABEL-$i"
  65. diff -u examples.csv examples.csv.UPDATED >"examples.csv.diff-$i"
  66. diff -u manet.csv manet.csv.UPDATED >"manet.csv.diff-$i"
  67. rm *.csv.UPDATED
  68. fi
  69. done