2
0

tests.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. TESTS_DIR="./tests"
  3. CONFIG_DIR=${TESTS_DIR}"/config"
  4. CHANGES_DIR="/tmp/.uci"
  5. TMP_DIR=${TESTS_DIR}"/tmp"
  6. FULL_SUITE=${TESTS_DIR}"/full_suite.sh"
  7. UCI_BIN=${UCI_BIN:-"../uci"}
  8. [ -x "$UCI_BIN" ] || {
  9. echo "uci is not present." >&2
  10. return 1
  11. }
  12. VALGRIND="valgrind --quiet --show-leak-kinds=all --leak-check=full --track-origins=yes"
  13. UCI_BIN="${VALGRIND} ${UCI_BIN}"
  14. UCI="${UCI_BIN} -c ${CONFIG_DIR} -p ${CHANGES_DIR}"
  15. UCI_Q="${UCI_BIN} -c ${CONFIG_DIR} -p ${CHANGES_DIR} -q"
  16. REF_DIR="./references"
  17. SCRIPTS_DIR="./tests.d"
  18. DO_TEST="./shunit2/shunit2"
  19. rm -rf ${TESTS_DIR}
  20. mkdir -p ${TESTS_DIR}
  21. cat << 'EOF' > ${FULL_SUITE}
  22. setUp() {
  23. mkdir -p ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
  24. }
  25. tearDown() {
  26. rm -rf ${CONFIG_DIR} ${CHANGES_DIR} ${TMP_DIR}
  27. }
  28. assertSameFile() {
  29. local ref=$1
  30. local test=$2
  31. diff -qr $ref $test
  32. assertTrue $? || {
  33. echo "REF:"
  34. cat $ref
  35. echo "----"
  36. echo "TEST:"
  37. cat $test
  38. echo "----"
  39. }
  40. }
  41. assertNotSegFault()
  42. {
  43. [ $1 -eq 139 ] && fail "Returned with 139: segmentation fault (SIGSEGV)!!!"
  44. }
  45. assertNotIllegal()
  46. {
  47. [ $1 -eq 132 ] && fail "Returned with 132: Illegal instruction (SIGILL)!!!"
  48. }
  49. assertFailWithNoReturn() {
  50. local test="$1"
  51. value=$( $test )
  52. rv=$?
  53. assertFalse "'$test' does not fail" $rv
  54. assertNotSegFault $rv
  55. assertNotIllegal $rv
  56. assertNull "'$test' returns '$value'" "$value"
  57. }
  58. EOF
  59. for suite in "${SCRIPTS_DIR}"/*
  60. do
  61. cat "${suite}" >> ${FULL_SUITE}
  62. done
  63. echo ". ${DO_TEST}" >> ${FULL_SUITE}
  64. REF_DIR="${REF_DIR}" \
  65. CONFIG_DIR="${CONFIG_DIR}" \
  66. CHANGES_DIR="${CHANGES_DIR}" \
  67. TMP_DIR="${TMP_DIR}" \
  68. UCI="${UCI}" \
  69. UCI_Q="${UCI_Q}" \
  70. /bin/sh ${FULL_SUITE}
  71. rm -rf ${TESTS_DIR}