From 76925c0d5b4d77cac1aea1758df912a336cfdebf Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 7 Dec 2019 12:37:41 +0000 Subject: [PATCH] test/{start,stop}-coin-daemons.py: test suite daemon control utility --- setup.py | 9 +++++ test/start-coin-daemons.py | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 test/start-coin-daemons.py diff --git a/setup.py b/setup.py index 638a03d3..ff25930d 100755 --- a/setup.py +++ b/setup.py @@ -53,10 +53,19 @@ class my_build_ext(build_ext): copy2(ext_src,ext_dest) copy_owner(cwd,ext_dest) +def link_or_copy(tdir,a,b): + os.chdir(tdir) + try: os.unlink(b) + except FileNotFoundError: pass + copy2(a,b) if have_msys2 else os.symlink(a,b) + copy_owner(a,b) + os.chdir(cwd) + class my_install_data(install_data): def run(self): for f in 'mmgen.cfg','mnemonic.py','mn_wordlist.c': os.chmod(os.path.join('data_files',f),0o644) + link_or_copy('test','start-coin-daemons.py','stop-coin-daemons.py') install_data.run(self) module1 = Extension( diff --git a/test/start-coin-daemons.py b/test/start-coin-daemons.py new file mode 100755 index 00000000..11b6f92d --- /dev/null +++ b/test/start-coin-daemons.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python3 + +import sys +from tests_header import repo_root +from mmgen.common import * +from mmgen.test_daemon import TestDaemon +from mmgen.regtest import MMGenRegtest + +action = g.prog_name.split('-')[0] + +opts_data = { + 'sets': [('debug',True,'verbose',True)], + 'text': { + 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()), + 'usage':'[opts] ', + 'options': """ +-h, --help Print this help message +--, --longhelp Print help message for long options (common options) +-d, --debug Produce debugging output (implies --verbose) +-r, --regtest-user=U {a} a regtest daemon for user 'U' +-s, --get-state Get the state of the daemon(s) and exit +-t, --testing Testing mode. Print commands but don't execute them +-v, --verbose Produce more verbose output +-W, --no-wait Don't wait for daemons to change state before exiting +""", + 'notes': """ +Valid network IDs: {nid}, all, or no_xmr +Valid Regtest network IDs: {rid}, or all +Valid Regtest users: {ru} +""" + }, + 'code': { + 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name), + 'notes': lambda s: s.format( + nid=', '.join(TestDaemon.network_ids), + rid=', '.join(MMGenRegtest.coins), + ru=', '.join(MMGenRegtest.users), + ) + } +} + +cmd_args = opts.init(opts_data) + +if 'all' in cmd_args or 'no_xmr' in cmd_args: + if len(cmd_args) != 1: + die(1,"'all' or 'no_xmr' must be the sole argument") + if opt.regtest_user: + ids = MMGenRegtest.coins + else: + ids = list(TestDaemon.network_ids) + if cmd_args[0] == 'no_xmr': + ids.remove('xmr') +else: + ids = cmd_args + if not ids: + opts.usage() + for i in ids: + if i not in TestDaemon.network_ids: + die(1,'{!r}: invalid network ID'.format(i)) + +for network_id in ids: + network_id = network_id.lower() + coin = network_id.replace('_tn','') + if opt.regtest_user: + datadir = '{}/test/data_dir/regtest/{}'.format(repo_root,coin) + d = MMGenRegtest(network_id,datadir).test_daemon(opt.regtest_user) + else: + datadir = '{}/test/daemons/{}'.format(repo_root,coin) + d = TestDaemon(network_id,datadir) + d.debug = opt.debug + d.wait = not opt.no_wait + if opt.get_state: + print('{} {} is {}'.format(d.net_desc,d.desc,d.state)) + elif opt.testing: + print(' '.join(getattr(d,action+'_cmd'))) + else: + d.cmd(action)