patchtest.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. #
  5. # patchtest: Run patchtest on commits starting at master
  6. #
  7. # Copyright (c) 2017, Intel Corporation.
  8. # All rights reserved.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. #
  24. set -o errexit
  25. # Default values
  26. pokydir=''
  27. usage() {
  28. CMD=$(basename $0)
  29. cat <<EOM
  30. Usage: $CMD [-h] [-p pokydir]
  31. -p pokydir Defaults to current directory
  32. EOM
  33. >&2
  34. exit 1
  35. }
  36. function clone() {
  37. local REPOREMOTE=$1
  38. local REPODIR=$2
  39. if [ ! -d $REPODIR ]; then
  40. git clone $REPOREMOTE $REPODIR --quiet
  41. else
  42. ( cd $REPODIR; git pull --quiet )
  43. fi
  44. }
  45. while getopts ":p:h" opt; do
  46. case $opt in
  47. p)
  48. pokydir=$OPTARG
  49. ;;
  50. h)
  51. usage
  52. ;;
  53. \?)
  54. echo "Invalid option: -$OPTARG" >&2
  55. usage
  56. ;;
  57. :)
  58. echo "Option -$OPTARG requires an argument." >&2
  59. usage
  60. ;;
  61. esac
  62. done
  63. shift $((OPTIND-1))
  64. CDIR="$PWD"
  65. # default pokydir to current directory if user did not specify one
  66. if [ -z "$pokydir" ]; then
  67. pokydir="$CDIR"
  68. fi
  69. PTENV="$PWD/patchtest"
  70. PT="$PTENV/patchtest"
  71. PTOE="$PTENV/patchtest-oe"
  72. if ! which virtualenv > /dev/null; then
  73. echo "Install virtualenv before proceeding"
  74. exit 1;
  75. fi
  76. # activate the virtual env
  77. virtualenv $PTENV --quiet
  78. source $PTENV/bin/activate
  79. cd $PTENV
  80. # clone or pull
  81. clone git://git.yoctoproject.org/patchtest $PT
  82. clone git://git.yoctoproject.org/patchtest-oe $PTOE
  83. # install requirements
  84. pip install -r $PT/requirements.txt --quiet
  85. pip install -r $PTOE/requirements.txt --quiet
  86. PATH="$PT:$PT/scripts:$PATH"
  87. # loop through parent to HEAD and execute patchtest on each commit
  88. for commit in $(git rev-list master..HEAD --reverse)
  89. do
  90. shortlog="$(git log "$commit^1..$commit" --pretty='%h: %aN: %cd: %s')"
  91. log="$(git format-patch "$commit^1..$commit" --stdout | patchtest - -r $pokydir -s $PTOE/tests --base-commit $commit^1 --json 2>/dev/null | create-summary --fail --only-results)"
  92. if [ -z "$log" ]; then
  93. shortlog="$shortlog: OK"
  94. else
  95. shortlog="$shortlog: FAIL"
  96. fi
  97. echo "$shortlog"
  98. echo "$log" | sed -n -e '/Issue/p' -e '/Suggested fix/p'
  99. echo ""
  100. done
  101. deactivate
  102. cd $CDIR