/src/wrappers/scripts/check-cluster.sh

http://github.com/tybor/Liberty · Shell · 271 lines · 202 code · 38 blank · 31 comment · 15 complexity · da835a7f6c92e090a42efa1bd5d556da MD5 · raw file

  1. #!/bin/bash
  2. # An home-grown script to check all the classes
  3. # found in a wrapper library having a library and
  4. # example subdirectories.
  5. TIMESTAMP=.check_cluster_timestamp
  6. WRONG_CLASSES=classes-with-errors
  7. CORRECT_CLASSES=correct-classes
  8. WRONG_EXAMPLES=examples-with-errors
  9. CORRECT_EXAMPLES=correct-examples
  10. export WRONG_CLASSES CORRECT_CLASSES WRONG_EXAMPLES CORRECT_EXAMPLES
  11. check_position () {
  12. if [ ! $eiffel_libraries ]
  13. then
  14. echo "\$eiffel_libraries enviromental variable not set. Quitting"
  15. exit 5
  16. fi
  17. if [ ! -f loadpath.se ] ; then
  18. echo "Couldn't find loadpath.se in current directory cluster."
  19. exit 5
  20. fi
  21. }
  22. run_tests () {
  23. ## Run eiffeltest test
  24. if [ ! -d tests ] ; then
  25. echo "Couldn't find tests in current directory cluster"
  26. exit 5
  27. else
  28. echo "Running tests"
  29. eiffeltest tests
  30. fi
  31. }
  32. wrong_and_correct_classes () {
  33. # All the testable classes; the classes with known error are listed first
  34. if [ -s $WRONG_CLASSES ] ;
  35. then # Prepend wrong classes
  36. cat $WRONG_CLASSES
  37. # Find all classes in the library
  38. find library -iname "*.e" |
  39. # Remove stubs
  40. grep -v stub |
  41. sort --numeric-sort --reverse |
  42. # Remove classes with errors (previously prepended)
  43. grep -v -F -f $WRONG_CLASSES
  44. else find library -iname "*.e" | grep -v stub
  45. fi
  46. }
  47. changed_classes_first () {
  48. # The files ordered from the latest to the oldest
  49. ## Find in the directory "library" all Eiffel source code, print
  50. ## its change time (in seconds from epoch) and its name
  51. find library -name "*.e" -printf "%T@ %p\n" |
  52. ## remove stubs
  53. grep -v stub |
  54. sort --numeric-sort --reverse |
  55. ## Remove the first column (changetime)
  56. cut -f 2 -d ' '
  57. # if [ -f $TIMESTAMP ] ; then
  58. # find library -iname "*.e" -newer $TIMESTAMP | grep -v stub
  59. # find library -iname "*.e" ! -newer $TIMESTAMP | grep -v stub
  60. # else
  61. # find library -iname "*.e" | grep -v stub
  62. # fi
  63. # touch $TIMESTAMP
  64. }
  65. check-class () {
  66. RESULT=$(mktemp -t check-class-XXXXX)
  67. CLASS=$1
  68. echo -n "Checking $CLASS: "
  69. if se class_check $CLASS >$RESULT 2>&1
  70. then
  71. echo correct.
  72. echo >>$CORRECT_CLASSES $CLASS
  73. else
  74. echo contains errors.
  75. cat $RESULT
  76. echo >>$WRONG_CLASSES $CLASS
  77. fi
  78. rm --force $RESULT
  79. }
  80. export -f check-class # to satisfy parallel command; this command is bash specific.
  81. check_classes () {
  82. # check all the library classes
  83. if [ ! -d library ] ; then
  84. echo "Couldn't find library in current directory cluster"
  85. exit 5
  86. else
  87. echo "Testing library classes."
  88. if [ -s $WRONG_CLASSES ] ; then rm $WRONG_CLASSES; fi
  89. if [ -s $CORRECT_CLASSES ] ; then rm $CORRECT_CLASSES; fi
  90. touch $WRONG_CLASSES $CORRECT_CLASSES
  91. if which parallel >/dev/null
  92. then
  93. echo Using parallel command
  94. changed_classes_first |
  95. parallel --no-notice check-class {} 2>&1
  96. else
  97. for CLASS in $( changed_classes_first ) # $( wrong_and_correct_classes )
  98. do
  99. class_check $CLASS
  100. done
  101. fi
  102. if [ -s $CORRECT_CLASSES ]
  103. then echo $(wc -l $CORRECT_CLASSES) correct classes.
  104. fi
  105. if [ -s $WRONG_CLASSES ]
  106. then
  107. echo $(wc -l $WRONG_CLASSES) classes with errors
  108. exit 5
  109. fi
  110. fi ## library exits
  111. }
  112. compile_examples () {
  113. # re-compile all the examples that needs to be recompiled and
  114. # rechecked, run them and ask the developer to confirm the
  115. # correctness of the output.
  116. if [ ! -d examples ] ; then
  117. echo "Couldn't find examples directory in current cluster"
  118. exit 5
  119. fi
  120. echo "Testing examples."
  121. ## Create a time mark. Examples more recent than it will be run.
  122. TIME_MARK=$(mktemp -t)
  123. if touch $TIME_MARK ;
  124. then
  125. rm $WRONG_EXAMPLES $CORRECT_EXAMPLES # We're testing them anew
  126. for EXAMPLE in $(find examples -iname "*.ace")
  127. do
  128. EXAMPLE_DIR=$(dirname $EXAMPLE)
  129. EXAMPLE_NAME=$(basename $EXAMPLE)
  130. EXECUTABLE=$(se ace_check $EXAMPLE |
  131. grep system |
  132. cut --delimiter=" " --fields=2)
  133. echo -n "Testing $EXAMPLE_NAME in $EXAMPLE_DIR. "
  134. if ( cd $EXAMPLE_DIR; compile $EXAMPLE_NAME )
  135. then
  136. TESTABLE="$TESTABLE $EXAMPLE_DIR/$EXECUTABLE"
  137. echo "$EXECUTABLE successfully compiled."
  138. echo >>$CORRECT_EXAMPLES $EXAMPLE
  139. else
  140. echo Contains errors.
  141. echo >>$WRONG_EXAMPLES $EXAMPLE
  142. fi
  143. done
  144. echo Testing $TESTABLE
  145. for EXAMPLE in $TESTABLE
  146. do
  147. EXAMPLE_DIR=$(dirname $EXAMPLE)
  148. EXAMPLE_NAME=$(basename $EXAMPLE)
  149. echo Running $EXAMPLE_NAME in $EXAMPLE_DIR.
  150. ## read -p "Does $EXAMPLE behave as expected?" OK
  151. if ./$EXAMPLE
  152. then echo $EXAMPLE_NAME successful
  153. else echo $EXAMPLE_NAME NOT successful
  154. fi
  155. done
  156. rm $TIME_MARK
  157. fi
  158. }
  159. clear_temporary_files () {
  160. for EXAMPLE in $(find examples -iname "*.ace")
  161. do
  162. EXAMPLE_DIR=$(dirname $EXAMPLE)
  163. EXAMPLE_NAME=$(basename $EXAMPLE)
  164. EXECUTABLE=$(se ace_check $EXAMPLE |
  165. grep system |
  166. cut --delimiter=" " --fields=2)
  167. echo -n "Testing $EXAMPLE_NAME in $EXAMPLE_DIR. "
  168. ( cd $EXAMPLE_DIR; se clean $EXAMPLE_NAME )
  169. done
  170. }
  171. print_usage () {
  172. cat <<EOF
  173. $(basename $0) ARGUMENTS
  174. Arguments:
  175. test
  176. run eiffeltest using the "test" directory
  177. library
  178. check all the library classes, starting with those that have been
  179. changed since the last time this were launched. Those with
  180. errors are listed in "$WRONG_CLASSES", those without in
  181. "$CORRECT_CLASSES".
  182. examples
  183. re-compiles all the examples that needs to be recompiled, run them
  184. and ask the developer to confirm its correct behaviour. Those that
  185. seems to behave correctly are added to $CORRECT_EXAMPLES, the
  186. others to $WRONG_EXAMPLES.
  187. clean
  188. remove all the temporary files.
  189. Usage: run it in a cluster of the Eiffel Wrapper Library Collection,
  190. i.e. eiffel-gtk, eiffel-gda, eiffel-glib.
  191. This script would like to be (become) a good "commit-filter", i.e.: if
  192. it does not end successfully you should not commit your changes.
  193. EOF
  194. ## library was: check all the library classes, starting with those
  195. ## that had error the last time the check-cluster script were
  196. ## launched. Those with errors are listed in "$WRONG_CLASSES", those
  197. ## without in "$CORRECT_CLASSES".
  198. }
  199. until [ -z $1 ] # Until all parameters used up...
  200. do
  201. case $1 in
  202. test )
  203. # run tests
  204. run_tests
  205. ;;
  206. library )
  207. # check library classes
  208. check_classes
  209. ;;
  210. examples )
  211. # check library examples
  212. compile_examples
  213. ;;
  214. clean )
  215. # Remove temporary files
  216. clear_temporary_files
  217. ;;
  218. all )
  219. check_classes
  220. compile_examples
  221. ;;
  222. * )
  223. print_usage
  224. ;;
  225. esac
  226. shift
  227. done