Build and test with Trezor T emulator
This commit is contained in:
parent
ef816628e1
commit
84315dd5de
@ -20,6 +20,9 @@ parser = argparse.ArgumentParser(description='Setup the testing environment and
|
|||||||
trezor_group = parser.add_mutually_exclusive_group()
|
trezor_group = parser.add_mutually_exclusive_group()
|
||||||
trezor_group.add_argument('--no_trezor', help='Do not run Trezor test with emulator', action='store_true')
|
trezor_group.add_argument('--no_trezor', help='Do not run Trezor test with emulator', action='store_true')
|
||||||
trezor_group.add_argument('--trezor', help='Path to Trezor emulator.', default='work/trezor-firmware/legacy/firmware/trezor.elf')
|
trezor_group.add_argument('--trezor', help='Path to Trezor emulator.', default='work/trezor-firmware/legacy/firmware/trezor.elf')
|
||||||
|
trezor_t_group = parser.add_mutually_exclusive_group()
|
||||||
|
trezor_t_group.add_argument('--no_trezor_t', help='Do not run Trezor T test with emulator', action='store_true')
|
||||||
|
trezor_t_group.add_argument('--trezor_t', help='Path to Trezor T emulator.', default='work/trezor-firmware/core/emu.sh')
|
||||||
coldcard_group = parser.add_mutually_exclusive_group()
|
coldcard_group = parser.add_mutually_exclusive_group()
|
||||||
coldcard_group.add_argument('--no_coldcard', help='Do not run Coldcard test with simulator', action='store_true')
|
coldcard_group.add_argument('--no_coldcard', help='Do not run Coldcard test with simulator', action='store_true')
|
||||||
coldcard_group.add_argument('--coldcard', help='Path to Coldcard simulator.', default='work/firmware/unix/headless.py')
|
coldcard_group.add_argument('--coldcard', help='Path to Coldcard simulator.', default='work/firmware/unix/headless.py')
|
||||||
@ -45,7 +48,7 @@ if sys.platform.startswith("linux"):
|
|||||||
suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(TestUdevRulesInstaller))
|
suite.addTests(unittest.defaultTestLoader.loadTestsFromTestCase(TestUdevRulesInstaller))
|
||||||
|
|
||||||
|
|
||||||
if not args.no_trezor or not args.no_coldcard or args.ledger or not args.no_bitbox or not args.no_keepkey:
|
if not args.no_trezor or not args.no_coldcard or args.ledger or not args.no_bitbox or not args.no_keepkey or not args.no_trezor_t:
|
||||||
# Start bitcoind
|
# Start bitcoind
|
||||||
rpc, userpass = start_bitcoind(args.bitcoind)
|
rpc, userpass = start_bitcoind(args.bitcoind)
|
||||||
|
|
||||||
@ -55,6 +58,8 @@ if not args.no_coldcard:
|
|||||||
suite.addTest(coldcard_test_suite(args.coldcard, rpc, userpass, args.interface))
|
suite.addTest(coldcard_test_suite(args.coldcard, rpc, userpass, args.interface))
|
||||||
if not args.no_trezor:
|
if not args.no_trezor:
|
||||||
suite.addTest(trezor_test_suite(args.trezor, rpc, userpass, args.interface))
|
suite.addTest(trezor_test_suite(args.trezor, rpc, userpass, args.interface))
|
||||||
|
if not args.no_trezor_t:
|
||||||
|
suite.addTest(trezor_test_suite(args.trezor_t, rpc, userpass, args.interface, True))
|
||||||
if not args.no_keepkey:
|
if not args.no_keepkey:
|
||||||
suite.addTest(keepkey_test_suite(args.keepkey, rpc, userpass, args.interface))
|
suite.addTest(keepkey_test_suite(args.keepkey, rpc, userpass, args.interface))
|
||||||
if args.ledger:
|
if args.ledger:
|
||||||
|
|||||||
@ -42,6 +42,17 @@ fi
|
|||||||
pipenv run script/cibuild
|
pipenv run script/cibuild
|
||||||
# Delete any emulator.img file
|
# Delete any emulator.img file
|
||||||
find . -name "emulator.img" -exec rm {} \;
|
find . -name "emulator.img" -exec rm {} \;
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Build trezor t emulator. This is pretty fast, so rebuilding every time is ok
|
||||||
|
# But there should be some caching that makes this faster
|
||||||
|
cd core
|
||||||
|
if [ "$trezor_setup_needed" == true ] ; then
|
||||||
|
make vendor
|
||||||
|
fi
|
||||||
|
make build_unix
|
||||||
|
# Delete any emulator.img file
|
||||||
|
rm /var/tmp/trezor.flash
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
# Clone coldcard firmware if it doesn't exist, or update it if it does
|
# Clone coldcard firmware if it doesn't exist, or update it if it does
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import atexit
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@ -36,7 +37,7 @@ class TrezorEmulator(DeviceEmulator):
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# Start the Trezor emulator
|
# Start the Trezor emulator
|
||||||
self.emulator_proc = subprocess.Popen(['./' + os.path.basename(self.emulator_path)], cwd=os.path.dirname(self.emulator_path))
|
self.emulator_proc = subprocess.Popen(['./' + os.path.basename(self.emulator_path)], cwd=os.path.dirname(self.emulator_path), stdout=subprocess.DEVNULL, env={'SDL_VIDEODRIVER': 'dummy', 'PYOPT': '0'}, shell=True, preexec_fn=os.setsid)
|
||||||
# Wait for emulator to be up
|
# Wait for emulator to be up
|
||||||
# From https://github.com/trezor/trezor-mcu/blob/master/script/wait_for_emulator.py
|
# From https://github.com/trezor/trezor-mcu/blob/master/script/wait_for_emulator.py
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
@ -64,8 +65,8 @@ class TrezorEmulator(DeviceEmulator):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.emulator_proc.kill()
|
os.killpg(os.getpgid(self.emulator_proc.pid), signal.SIGINT)
|
||||||
self.emulator_proc.wait()
|
os.waitpid(self.emulator_proc.pid, 0)
|
||||||
|
|
||||||
class TrezorTestCase(unittest.TestCase):
|
class TrezorTestCase(unittest.TestCase):
|
||||||
def __init__(self, emulator, interface='library', methodName='runTest'):
|
def __init__(self, emulator, interface='library', methodName='runTest'):
|
||||||
@ -103,10 +104,10 @@ class TrezorTestCase(unittest.TestCase):
|
|||||||
return process_commands(args)
|
return process_commands(args)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'trezor: {}'.format(super().__str__())
|
return 'trezor 1: {}'.format(super().__str__())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'trezor: {}'.format(super().__repr__())
|
return 'trezor 1: {}'.format(super().__repr__())
|
||||||
|
|
||||||
# Trezor specific getxpub test because this requires device specific thing to set xprvs
|
# Trezor specific getxpub test because this requires device specific thing to set xprvs
|
||||||
class TestTrezorGetxpub(TrezorTestCase):
|
class TestTrezorGetxpub(TrezorTestCase):
|
||||||
@ -277,18 +278,22 @@ class TestTrezorManCommands(TrezorTestCase):
|
|||||||
self.assertFalse(dev['needs_passphrase_sent'])
|
self.assertFalse(dev['needs_passphrase_sent'])
|
||||||
self.assertNotEqual(dev['fingerprint'], fpr)
|
self.assertNotEqual(dev['fingerprint'], fpr)
|
||||||
|
|
||||||
def trezor_test_suite(emulator, rpc, userpass, interface):
|
def trezor_test_suite(emulator, rpc, userpass, interface, model_t=False):
|
||||||
# Redirect stderr to /dev/null as it's super spammy
|
# Redirect stderr to /dev/null as it's super spammy
|
||||||
sys.stderr = open(os.devnull, 'w')
|
sys.stderr = open(os.devnull, 'w')
|
||||||
|
|
||||||
# Device info for tests
|
# Device info for tests
|
||||||
type = 'trezor'
|
type = 'trezor'
|
||||||
full_type = 'trezor_1'
|
|
||||||
path = 'udp:127.0.0.1:21324'
|
path = 'udp:127.0.0.1:21324'
|
||||||
fingerprint = '95d8f670'
|
fingerprint = '95d8f670'
|
||||||
master_xpub = 'xpub6D1weXBcFAo8CqBbpP4TbH5sxQH8ZkqC5pDEvJ95rNNBZC9zrKmZP2fXMuve7ZRBe18pWQQsGg68jkq24mZchHwYENd8cCiSb71u3KD4AFH'
|
master_xpub = 'xpub6D1weXBcFAo8CqBbpP4TbH5sxQH8ZkqC5pDEvJ95rNNBZC9zrKmZP2fXMuve7ZRBe18pWQQsGg68jkq24mZchHwYENd8cCiSb71u3KD4AFH'
|
||||||
dev_emulator = TrezorEmulator(emulator)
|
dev_emulator = TrezorEmulator(emulator)
|
||||||
|
|
||||||
|
if model_t:
|
||||||
|
full_type = 'trezor_t'
|
||||||
|
else:
|
||||||
|
full_type = 'trezor_1'
|
||||||
|
|
||||||
# Generic Device tests
|
# Generic Device tests
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(DeviceTestCase.parameterize(TestDeviceConnect, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
suite.addTest(DeviceTestCase.parameterize(TestDeviceConnect, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
||||||
@ -296,8 +301,9 @@ def trezor_test_suite(emulator, rpc, userpass, interface):
|
|||||||
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
||||||
suite.addTest(DeviceTestCase.parameterize(TestDisplayAddress, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
suite.addTest(DeviceTestCase.parameterize(TestDisplayAddress, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
||||||
suite.addTest(DeviceTestCase.parameterize(TestSignMessage, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
suite.addTest(DeviceTestCase.parameterize(TestSignMessage, rpc, userpass, type, full_type, path, fingerprint, master_xpub, emulator=dev_emulator, interface=interface))
|
||||||
suite.addTest(TrezorTestCase.parameterize(TestTrezorGetxpub, emulator=dev_emulator, interface=interface))
|
if not model_t:
|
||||||
suite.addTest(TrezorTestCase.parameterize(TestTrezorManCommands, emulator=dev_emulator, interface=interface))
|
suite.addTest(TrezorTestCase.parameterize(TestTrezorGetxpub, emulator=dev_emulator, interface=interface))
|
||||||
|
suite.addTest(TrezorTestCase.parameterize(TestTrezorManCommands, emulator=dev_emulator, interface=interface))
|
||||||
return suite
|
return suite
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -305,10 +311,11 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument('emulator', help='Path to the Trezor emulator')
|
parser.add_argument('emulator', help='Path to the Trezor emulator')
|
||||||
parser.add_argument('bitcoind', help='Path to bitcoind binary')
|
parser.add_argument('bitcoind', help='Path to bitcoind binary')
|
||||||
parser.add_argument('--interface', help='Which interface to send commands over', choices=['library', 'cli', 'bindist'], default='library')
|
parser.add_argument('--interface', help='Which interface to send commands over', choices=['library', 'cli', 'bindist'], default='library')
|
||||||
|
parser.add_argument('--model_t', help='The emulator is for the Trezor T', action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Start bitcoind
|
# Start bitcoind
|
||||||
rpc, userpass = start_bitcoind(args.bitcoind)
|
rpc, userpass = start_bitcoind(args.bitcoind)
|
||||||
|
|
||||||
suite = trezor_test_suite(args.emulator, rpc, userpass, args.interface)
|
suite = trezor_test_suite(args.emulator, rpc, userpass, args.interface, args.model_t)
|
||||||
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(suite)
|
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run(suite)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user