diff --git a/mmgen/autosign.py b/mmgen/autosign.py index f2132037..43756b9f 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -81,7 +81,13 @@ class SwapMgrBase: class SwapMgrLinux(SwapMgrBase): def get_active(self): - cp = run(['/sbin/swapon', '--show=NAME', '--noheadings'], stdout=PIPE, text=True, check=True) + for cmd in ('/sbin/swapon', 'swapon'): + try: + cp = run([cmd, '--show=NAME', '--noheadings'], stdout=PIPE, text=True, check=True) + break + except Exception: + if cmd == 'swapon': + raise res = cp.stdout.splitlines() return [e for e in res if not e.startswith('/dev/zram')] if self.ignore_zram else res @@ -418,7 +424,7 @@ class Autosign: linux_mount_subdir = 'mmgen_autosign' macOS_ramdisk_name = 'AutosignRamDisk' wallet_subdir = 'autosign' - linux_blkid_cmd = '/sbin/blkid -s LABEL -o value' + linux_blkid_cmd = 'sudo blkid -s LABEL -o value' cmds = ('setup', 'xmr_setup', 'sign', 'wait') diff --git a/mmgen/daemon.py b/mmgen/daemon.py index 897bb1bc..960a7b7c 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -488,10 +488,7 @@ class CoinDaemon(Daemon): "remove the network's datadir" assert self.test_suite, 'datadir removal restricted to test suite' if self.state == 'stopped': - run([ - ('rm' if self.platform == 'win32' else '/bin/rm'), - '-rf', - self.datadir]) + run(['rm', '-rf', self.datadir]) set_vt100() else: msg(f'Cannot remove {self.network_datadir!r} - daemon is not stopped') diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index a5c43b88..af456be1 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -42,10 +42,7 @@ def check_or_create_dir(path): if os.getenv('MMGEN_TEST_SUITE'): if os.path.exists(path): # path is a link or regular file from subprocess import run - run([ - ('rm' if sys.platform == 'win32' else '/bin/rm'), - '-rf', - str(path)]) + run(['rm', '-rf', str(path)]) set_vt100() try: os.makedirs(path, 0o700) diff --git a/test/cmdtest_d/ct_autosign.py b/test/cmdtest_d/ct_autosign.py index 7aadbf00..71631ac1 100755 --- a/test/cmdtest_d/ct_autosign.py +++ b/test/cmdtest_d/ct_autosign.py @@ -134,19 +134,30 @@ class CmdTestAutosignBase(CmdTestBase): def _set_e2label(self, label): imsg(f'Setting label to {label}') - run(['/sbin/e2label', str(self.txdev.img_path), label], check=True) + for cmd in ('/sbin/e2label', 'e2label'): + try: + run([cmd, str(self.txdev.img_path), label], check=True) + break + except: + if cmd == 'e2label': + raise def _create_removable_device(self): if sys.platform == 'linux': self.txdev.create() self.txdev.attach(silent=True) - cmd = [ - '/sbin/mkfs.ext2', + args = [ '-E', 'root_owner={}:{}'.format(os.getuid(), os.getgid()), '-L', self.asi.dev_label, str(self.txdev.img_path)] redir = DEVNULL - run(cmd, stdout=redir, stderr=redir, check=True) + for cmd in ('/sbin/mkfs.ext2', 'mkfs.ext2'): + try: + run([cmd] + args, stdout=redir, stderr=redir, check=True) + break + except: + if cmd == 'mkfs.ext2': + raise self.txdev.detach(silent=True) elif sys.platform == 'darwin': cmd = [ diff --git a/test/daemontest_d/ut_rpc.py b/test/daemontest_d/ut_rpc.py index c2d434f0..98fef8b3 100755 --- a/test/daemontest_d/ut_rpc.py +++ b/test/daemontest_d/ut_rpc.py @@ -15,7 +15,7 @@ from mmgen.daemon import CoinDaemon from mmgen.proto.xmr.rpc import MoneroRPCClient, MoneroWalletRPCClient from mmgen.proto.xmr.daemon import MoneroWalletDaemon -from ..include.common import cfg, qmsg, vmsg +from ..include.common import cfg, qmsg, vmsg, in_nix_environment, test_exec async def cfg_file_auth_test(cfg, d, bad_auth=False): m = 'missing credentials' if bad_auth else f'credentials from {d.cfg_file}' @@ -181,6 +181,9 @@ class unit_tests: return await run_test(['eth', 'eth_tn', 'eth_rt'], daemon_ids=['erigon']) async def parity(self, name, ut): + if in_nix_environment() and not test_exec('parity --help'): + ut.skip_msg('Nix environment') + return True return await run_test(['etc']) async def xmrwallet(self, name, ut): diff --git a/test/include/common.py b/test/include/common.py index 750e98da..db0ae247 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -337,6 +337,19 @@ def check_solc_ver(): def do_run(cmd, check=True): return run(cmd, stdout=PIPE, stderr=DEVNULL, check=check) +def test_exec(cmd): + try: + do_run(cmd.split()) + return True + except Exception: + return False + +def in_nix_environment(): + for path in os.getenv('PATH').split(':'): + if os.path.realpath(path).startswith('/nix/store'): + return True + return False + def VirtBlockDevice(img_path, size): if sys.platform == 'linux': return VirtBlockDeviceLinux(img_path, size) @@ -407,20 +420,20 @@ class VirtBlockDeviceLinux(VirtBlockDeviceBase): self.size = size def _get_associations(self): - cmd = ['/sbin/losetup', '-n', '-O', 'NAME', '-j', str(self.img_path)] + cmd = ['sudo', 'losetup', '-n', '-O', 'NAME', '-j', str(self.img_path)] return do_run(cmd).stdout.decode().splitlines() def get_new_dev(self): - return do_run(['sudo', '/sbin/losetup', '-f']).stdout.decode().strip() + return do_run(['sudo', 'losetup', '-f']).stdout.decode().strip() def do_create(self, size, path): do_run(['truncate', f'--size={size}', str(path)]) def do_attach(self, path, dev): - do_run(['sudo', '/sbin/losetup', dev, str(path)]) + do_run(['sudo', 'losetup', dev, str(path)]) def do_detach(self, dev, check=True): - do_run(['sudo', '/sbin/losetup', '-d', dev], check=check) + do_run(['sudo', 'losetup', '-d', dev], check=check) class VirtBlockDeviceMacOS(VirtBlockDeviceBase): diff --git a/test/modtest_d/ut_testdep.py b/test/modtest_d/ut_testdep.py index f419821a..4daab0c4 100755 --- a/test/modtest_d/ut_testdep.py +++ b/test/modtest_d/ut_testdep.py @@ -28,7 +28,13 @@ class unit_tests: def losetup(self, name, ut): os.stat('/dev/loop0') - run(['/sbin/losetup', '-f'], check=True, stdout=DEVNULL) + for cmd in ('/sbin/losetup', '/usr/sbin/losetup', 'losetup'): + try: + run([cmd, '-f'], check=True, stdout=DEVNULL) + break + except: + if cmd == 'losetup': + raise return True def pycoin(self, name, ut): diff --git a/test/test-release.d/cfg.sh b/test/test-release.d/cfg.sh index 9b23d780..5564e986 100755 --- a/test/test-release.d/cfg.sh +++ b/test/test-release.d/cfg.sh @@ -27,7 +27,7 @@ init_groups() { noalt_ok_tests='lint' [ "$MSYS2" ] && SKIP_LIST='autosign autosign_live' - [ "$ARM32" -o "$ARM64" ] && SKIP_LIST+=' etc' + [ "$ARM32" -o "$ARM64" -o "$SKIP_PARITY" ] && SKIP_LIST+=' etc' true } @@ -239,6 +239,7 @@ init_tests() { d_etc="operations for Ethereum Classic using devnet" t_etc="parity $cmdtest_py --coin=etc ethdev" + [ "$SKIP_PARITY" ] && t_etc_skip='parity' d_xmr="Monero xmrwallet operations" t_xmr=" diff --git a/test/test-release.sh b/test/test-release.sh index 8c038c03..179c4c34 100755 --- a/test/test-release.sh +++ b/test/test-release.sh @@ -217,6 +217,12 @@ do_reexec() { fi } +in_nix_environment() { + for path in ${PATH//:/ }; do + realpath -q $path | grep -q '^/nix/store/' && break + done +} + # start execution set -e @@ -368,6 +374,8 @@ do esac done +in_nix_environment && parity --help >/dev/null 2>&1 || SKIP_PARITY=1 + [ "$MMGEN_DISABLE_COLOR" ] || { RED="\e[31;1m" GREEN="\e[32;1m" YELLOW="\e[33;1m" BLUE="\e[34;1m" MAGENTA="\e[35;1m" CYAN="\e[36;1m" RESET="\e[0m"