test-release.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. #!/bin/bash
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen
  9. # https://gitlab.com/mmgen/mmgen
  10. # Tested on Linux, Armbian, Raspbian, MSYS2
  11. # data.sh must implement:
  12. # list_avail_tests()
  13. # init_groups()
  14. # init_tests()
  15. . 'test/test-release.d/cfg.sh'
  16. do_test() {
  17. set +x
  18. tests="t_$1"
  19. skips="t_$1_skip"
  20. while read skip test; do
  21. [ "$test" ] || continue
  22. echo "${!skips}" | grep -q $skip && continue
  23. if [ "$LIST_CMDS" ]; then
  24. echo $test
  25. else
  26. test_disp=$YELLOW${test/\#/$RESET$MAGENTA\#}$RESET
  27. if [ "${test:0:1}" == '#' ]; then
  28. echo -e "$test_disp"
  29. else
  30. echo -e "${GREEN}Running:$RESET $test_disp"
  31. eval "$test" || {
  32. echo -e $RED"test-release.sh: test '$CUR_TEST' failed at command '$test'"$RESET
  33. exit 1
  34. }
  35. fi
  36. fi
  37. done <<<${!tests}
  38. }
  39. prompt_skip() {
  40. echo -n "Enter 's' to skip, or ENTER to continue: "; read -n1; echo
  41. [ "$REPLY" == 's' ] && return 0
  42. return 1
  43. }
  44. run_tests() {
  45. [ "$LIST_CMDS" ] || echo "Running tests: $1"
  46. for t in $1; do
  47. if [ "$SKIP_ALT_DEP" ]; then
  48. ok=$(for a in $noalt_tests; do if [ $t == $a ]; then echo 'ok'; fi; done)
  49. if [ ! "$ok" ]; then
  50. echo -e "${BLUE}Skipping altcoin test '$t'$RESET"
  51. continue
  52. fi
  53. fi
  54. if [ "$LIST_CMDS" ]; then
  55. eval echo -e '\\n#' $(echo \$i_$t) "\($t\)"
  56. else
  57. eval echo -e "'\n'"\${GREEN}'###' Running $(echo \$i_$t) tests\$RESET
  58. eval echo -e $(echo \$s_$t)
  59. fi
  60. [ "$PAUSE" ] && prompt_skip && continue
  61. CUR_TEST=$t
  62. do_test $t
  63. [ "$LIST_CMDS" ] || eval echo -e $(echo \$f_$t)
  64. done
  65. }
  66. check_tests() {
  67. for i in $tests; do
  68. echo "$dfl_tests $extra_tests" | grep -q "\<$i\>" || {
  69. echo "$i: unrecognized argument"
  70. exit 1
  71. }
  72. done
  73. }
  74. remove_skipped_tests() {
  75. tests=$(for t in $tests; do
  76. [ "$(for s in $SKIP_LIST; do [ $t == $s ] && echo y; done)" ] && continue
  77. echo $t
  78. done)
  79. tests=$(echo $tests)
  80. }
  81. list_group_symbols() {
  82. echo -e "Default tests:\n $dfl_tests"
  83. echo -e "Extra tests:\n $extra_tests"
  84. echo -e "'noalt' test group:\n $noalt_tests"
  85. echo -e "'quick' test group:\n $quick_tests"
  86. echo -e "'qskip' test group:\n $qskip_tests"
  87. }
  88. if [ "$(uname -m)" == 'armv7l' ]; then
  89. ARM32=1
  90. elif [ "$(uname -m)" == 'aarch64' ]; then
  91. ARM64=1
  92. elif uname -a | grep -q 'MSYS'; then
  93. MSYS2=1;
  94. fi
  95. trap 'echo -e "${GREEN}Exiting at user request$RESET"; exit' INT
  96. umask 0022
  97. export MMGEN_TEST_SUITE=1
  98. export MMGEN_NO_LICENSE=1
  99. export PYTHONPATH=.
  100. test_py='test/test.py -n'
  101. objtest_py='test/objtest.py'
  102. objattrtest_py='test/objattrtest.py'
  103. unit_tests_py='test/unit_tests.py --names --quiet'
  104. tooltest_py='test/tooltest.py'
  105. tooltest2_py='test/tooltest2.py --names --quiet'
  106. gentest_py='test/gentest.py --quiet'
  107. scrambletest_py='test/scrambletest.py'
  108. altcoin_mod_opts='--quiet'
  109. mmgen_tool='cmds/mmgen-tool'
  110. python='python3'
  111. rounds=100 rounds_min=20 rounds_mid=250 rounds_max=500
  112. ORIG_ARGS=$@
  113. PROGNAME=$(basename $0)
  114. init_groups
  115. while getopts hAbCdDfFLlNOps:StvV OPT
  116. do
  117. case "$OPT" in
  118. h) printf " %-16s Test MMGen release\n" "${PROGNAME}:"
  119. echo " USAGE: $PROGNAME [options] [tests or test group]"
  120. echo " OPTIONS: -h Print this help message"
  121. echo " -A Skip tests requiring altcoin modules or daemons"
  122. echo " -b Buffer keypresses for all invocations of 'test/test.py'"
  123. echo " -C Run tests in coverage mode"
  124. echo " -d Enable Python Development Mode"
  125. echo " -D Run tests in deterministic mode"
  126. echo " -f Speed up the tests by using fewer rounds"
  127. echo " -F Reduce rounds even further"
  128. echo " -L List available tests and test groups with description"
  129. echo " -l List the test name symbols"
  130. echo " -N Pass the --no-timings switch to test/test.py"
  131. echo " -O Use pexpect.spawn rather than popen_spawn where applicable"
  132. echo " -p Pause between tests"
  133. echo " -s LIST Skip tests in LIST (space-separated)"
  134. echo " -S Build SDIST distribution, unpack, and run test"
  135. echo " -t Print the tests without running them"
  136. echo " -v Run test/test.py with '--exact-output' and other commands"
  137. echo " with '--verbose' switch"
  138. echo " -V Run test/test.py and other commands with '--verbose' switch"
  139. exit ;;
  140. A) SKIP_ALT_DEP=1
  141. test_py+=" --no-altcoin"
  142. unit_tests_py+=" --no-altcoin-deps"
  143. scrambletest_py+=" --no-altcoin" ;;
  144. b) test_py+=" --buf-keypress" ;;
  145. C) mkdir -p 'test/trace'
  146. touch 'test/trace.acc'
  147. test_py+=" --coverage"
  148. tooltest_py+=" --coverage"
  149. tooltest2_py+=" --fork --coverage"
  150. scrambletest_py+=" --coverage"
  151. python="python3 -m trace --count --file=test/trace.acc --coverdir=test/trace"
  152. unit_tests_py="$python $unit_tests_py"
  153. objtest_py="$python $objtest_py"
  154. objattrtest_py="$python $objattrtest_py"
  155. gentest_py="$python $gentest_py"
  156. mmgen_tool="$python $mmgen_tool" ;&
  157. d) export PYTHONDEVMODE=1
  158. export PYTHONWARNINGS='error' ;;
  159. D) export MMGEN_TEST_SUITE_DETERMINISTIC=1
  160. export MMGEN_DISABLE_COLOR=1 ;;
  161. f) FAST=1 rounds=10 rounds_min=3 rounds_mid=25 rounds_max=50 unit_tests_py+=" --fast" ;;
  162. F) FAST=1 rounds=3 rounds_min=1 rounds_mid=3 rounds_max=5 unit_tests_py+=" --fast" ;;
  163. L) list_avail_tests; exit ;;
  164. l) list_group_symbols; exit ;;
  165. N) test_py+=" --no-timings" ;;
  166. O) test_py+=" --pexpect-spawn" ;;
  167. p) PAUSE=1 ;;
  168. s) SKIP_LIST+=" $OPTARG" ;;
  169. S) SDIST_TEST=1 ;;
  170. t) LIST_CMDS=1 ;;
  171. v) EXACT_OUTPUT=1 test_py+=" --exact-output" ;&
  172. V) VERBOSE='--verbose'
  173. [ "$EXACT_OUTPUT" ] || test_py+=" --verbose"
  174. unit_tests_py="${unit_tests_py/--quiet/--verbose}"
  175. altcoin_mod_opts="${altcoin_mod_opts/--quiet/--verbose}"
  176. tooltest2_py="${tooltest2_py/--quiet/--verbose}"
  177. gentest_py="${gentest_py/--quiet/--verbose}"
  178. tooltest_py+=" --verbose"
  179. mmgen_tool+=" --verbose"
  180. objattrtest_py+=" --verbose"
  181. scrambletest_py+=" --verbose" ;;
  182. *) exit ;;
  183. esac
  184. done
  185. [ "$MMGEN_DISABLE_COLOR" ] || {
  186. RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m"
  187. RESET="\e[0m"
  188. }
  189. [ "$MSYS2" -a ! "$FAST" ] && tooltest2_py+=' --fork'
  190. [ "$EXACT_OUTPUT" -o "$VERBOSE" ] || objtest_py+=" -S"
  191. shift $((OPTIND-1))
  192. [ "$SDIST_TEST" -a -z "$MMGEN_TEST_RELEASE_IN_SDIST" ] && {
  193. test_dir='.sdist-test'
  194. rm -rf build dist MMGen.egg-info $test_dir
  195. python3 -m build --no-isolation --sdist
  196. mkdir $test_dir
  197. tar -C $test_dir -axf dist/*.tar.gz
  198. cd $test_dir/MMGen-*
  199. python3 setup.py build_ext --inplace
  200. echo -e "\n${BLUE}Running 'test/test-release $ORIG_ARGS'$RESET $YELLOW[PWD=$PWD]$RESET\n"
  201. export MMGEN_TEST_RELEASE_IN_SDIST=1
  202. test/test-release.sh $ORIG_ARGS
  203. exit
  204. }
  205. case $1 in
  206. '') tests=$dfl_tests ;;
  207. 'default') tests=$dfl_tests ;;
  208. 'extra') tests=$extra_tests ;;
  209. 'noalt') tests=$noalt_tests
  210. SKIP_ALT_DEP=1
  211. test_py+=" --no-altcoin"
  212. unit_tests_py+=" --no-altcoin-deps"
  213. scrambletest_py+=" --no-altcoin" ;;
  214. 'quick') tests=$quick_tests ;;
  215. 'qskip') tests=$qskip_tests ;;
  216. *) tests="$*" ;;
  217. esac
  218. set -e
  219. init_tests
  220. remove_skipped_tests
  221. check_tests
  222. start_time=$(date +%s)
  223. run_tests "$tests"
  224. elapsed=$(($(date +%s)-start_time))
  225. elapsed_fmt=$(printf %02d:%02d $((elapsed/60)) $((elapsed%60)))
  226. [ "$LIST_CMDS" ] || {
  227. if [ "$MMGEN_TEST_SUITE_DETERMINISTIC" ]; then
  228. echo -e "${GREEN}All OK"
  229. else
  230. echo -e "${GREEN}All OK. Total elapsed time: $elapsed_fmt$RESET"
  231. fi
  232. }