diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-15 15:15:28 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-21 19:27:42 +0000 |
commit | ef7681b6991e45b4d1dc2e0831442fff3443ba55 (patch) | |
tree | 443d2ab5299ceaeec637ff686117aa0a7d596074 | |
parent | functional_tests: add basic mining tests (diff) | |
download | monero-ef7681b6991e45b4d1dc2e0831442fff3443ba55.tar.xz |
functional_tests: plug RPC tests into the cmake machinery
-rw-r--r-- | tests/functional_tests/CMakeLists.txt | 7 | ||||
-rwxr-xr-x | tests/functional_tests/functional_tests_rpc.py | 116 |
2 files changed, 120 insertions, 3 deletions
diff --git a/tests/functional_tests/CMakeLists.txt b/tests/functional_tests/CMakeLists.txt index 2e3519994..60060f56f 100644 --- a/tests/functional_tests/CMakeLists.txt +++ b/tests/functional_tests/CMakeLists.txt @@ -49,6 +49,7 @@ target_link_libraries(functional_tests ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_LIBRARIES}) -set_property(TARGET functional_tests - PROPERTY - FOLDER "tests") + +add_test( + NAME functional_tests_rpc + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/functional_tests_rpc.py" "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" all) diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py new file mode 100755 index 000000000..5e1ee34e6 --- /dev/null +++ b/tests/functional_tests/functional_tests_rpc.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python + +from __future__ import print_function +import sys +import time +import subprocess +from signal import SIGTERM +import socket +import string + +USAGE = 'usage: functional_tests_rpc.py <python> <srcdir> <builddir> [<tests-to-run> | all]' +DEFAULT_TESTS = ['daemon_info', 'blockchain', 'wallet_address', 'mining'] +try: + python = sys.argv[1] + srcdir = sys.argv[2] + builddir = sys.argv[3] +except: + print(USAGE) + sys.exit(1) + +try: + sys.argv[4] +except: + print(USAGE) + print('Available tests: ' + string.join(DEFAULT_TESTS, ', ')) + print('Or run all with "all"') + sys.exit(0) + +try: + tests = sys.argv[4:] + if tests == ['all']: + tests = DEFAULT_TESTS +except: + tests = DEFAULT_TESTS + +monerod = [builddir + "/bin/monerod", "--regtest", "--fixed-difficulty", "1", "--offline", "--no-igd", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--log-level", "1"] +wallet = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", builddir + "/functional-tests-directory", "--rpc-bind-port", "18083", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1"] + +monerod_output = open(builddir + '/tests/functional_tests/monerod.log', 'a+') +wallet_output = open(builddir + '/tests/functional_tests/wallet.log', 'a+') + +print('Starting servers...') +monerod_process = None +wallet_process = None +try: + #print 'Running: ' + str(monerod) + monerod_process = subprocess.Popen(monerod, stdout = monerod_output) + #print 'Running: ' + str(wallet) + wallet_process = subprocess.Popen(wallet, stdout = wallet_output) +except Exception, e: + print('Error: ' + str(e)) + sys.exit(1) + +def kill(): + try: wallet_process.send_signal(SIGTERM) + except: pass + try: monerod_process.send_signal(SIGTERM) + except: pass + +# wait for error/startup +for i in range(10): + time.sleep(1) + all_open = True + for port in [18081, 18083]: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(1) + if s.connect_ex(('127.0.0.1', port)) != 0: + all_open = False + break + s.close() + if all_open: + break + +if not all_open: + print('Failed to start wallet or daemon') + kill() + sys.exit(1) + +PASS = [] +FAIL = [] +for test in tests: + try: + print('[TEST STARTED] ' + test) + cmd = [python, srcdir + '/' + test + ".py"] + subprocess.check_call(cmd) + PASS.append(test) + print('[TEST PASSED] ' + test) + except: + FAIL.append(test) + print('[TEST FAILED] ' + test) + pass + +print('Stopping servers...') +kill() + +# wait for exit, the poll method does not work (https://bugs.python.org/issue2475) so we wait, possibly forever if the process hangs +if True: + wallet_process.wait() + monerod_process.wait() +else: + for i in range(10): + wallet_process.poll() + monerod_process.poll() + if wallet_process.returncode and monerod_process.returncode: + print('Both done: ' + str(wallet_process.returncode) + ' and ' + str(monerod_process.returncode)) + break + time.sleep(1) + if not wallet_process.returncode: + print('Failed to stop monero-wallet-rpc') + if not monerod_process.returncode: + print('Failed to stop monerod') + +if len(FAIL) == 0: + print('Done, ' + str(len(PASS)) + '/' + str(len(tests)) + ' tests passed') +else: + print('Done, ' + str(len(FAIL)) + '/' + str(len(tests)) + ' tests failed: ' + string.join(FAIL, ', ')) |