runtests.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/bash
  2. # Really simple test runner.
  3. # Runs a bunch of python unit tests as standalone programs
  4. # and collects the results.
  5. ###########################
  6. # Environment setup
  7. ###########################
  8. # Try to guess which python points to python 3
  9. if [[ "`which python3`" == "" ]]; then
  10. PYTHON=`which python`
  11. else
  12. PYTHON=`which python3`
  13. fi
  14. if [[ "$PYTHON" == "" ]]; then
  15. echo "Could not find python!"
  16. exit 1
  17. fi
  18. # verify that it is a python3
  19. $PYTHON -c "import sys; sys.exit(0 if sys.version.startswith('3.') else 1)"
  20. if [[ "$?" == 1 ]]; then
  21. echo "Wrong version of python, need python 3.x, got `$PYTHON --version`"
  22. exit 1
  23. fi
  24. echo "Using python at $PYTHON"
  25. # set python path if necessary
  26. if [[ "$PYTHONPATH" == "" ]]; then
  27. export PYTHONPATH=`cd ..; pwd`
  28. echo "Set PYTHONPATH to $PYTHONPATH"
  29. fi
  30. # Counts of each test result type
  31. OK=0
  32. SKIPPED=0
  33. FAILED=0
  34. ERROR=0
  35. # Run a single test and update the counts. Takes one argument: the test name.
  36. # A .py will be appended to get the python filename. The standard output
  37. # goes into $TEST.out and the standard error to $TEST.err. These are not
  38. # kept unless the test fails.
  39. function runtest {
  40. TEST=$1
  41. echo -n "Running $TEST"
  42. $PYTHON $TEST.py >$TEST.out 2>$TEST.err
  43. rc=$?
  44. if [[ "$rc" == 0 ]]; then
  45. # got a success. Now check whether skipped.
  46. tail -1 $TEST.err | grep -q 'OK (skipped'
  47. skiprc=$?
  48. if [[ "$skiprc" == "0" ]]; then
  49. echo " SKIPPED"
  50. SKIPPED=$((SKIPPED+1))
  51. rm $TEST.err $TEST.out
  52. else
  53. tail -1 $TEST.err | grep -q 'OK'
  54. okrc=$?
  55. if [[ "$okrc" == "0" ]]; then
  56. echo " OK"
  57. OK=$((OK+1))
  58. rm $TEST.err $TEST.out
  59. else
  60. # did not find the OK
  61. echo " UNKNOWN!"
  62. ERROR=$((ERROR+1))
  63. fi # okrc
  64. fi # skiprc
  65. else # non-zero return code
  66. tail -1 $TEST.err | grep -q 'FAILED'
  67. failrc=$?
  68. if [[ "$failrc" == "0" ]]; then
  69. echo " FAILED"
  70. FAILED=$((FAILED+1))
  71. else
  72. echo " ERROR"
  73. ERROR=$((ERROR+1))
  74. fi # failrc
  75. fi # rc
  76. }
  77. ###########################
  78. # Run the tests
  79. ###########################
  80. rm -f *.err *.out
  81. echo ">>>>>>>>>>>>>>>>>>>> Starting Tests"
  82. runtest test_base
  83. runtest test_scheduler
  84. runtest test_utils
  85. runtest test_end_to_end
  86. echo ">>>>>>>>>>>>>>>>>>>> Finished Tests"
  87. echo "$OK Tests successful."
  88. echo "$SKIPPED Tests skipped."
  89. echo "$FAILED Tests failed."
  90. echo "$ERROR Tests had errors."
  91. exit $((FAILED + ERROR))