mk4 se1 cases
This commit is contained in:
parent
c098b861c1
commit
86925820d3
@ -699,8 +699,34 @@ def settings_remove(sim_exec):
|
||||
|
||||
return doit
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def repl(dev=None):
|
||||
@pytest.fixture(scope='module')
|
||||
def repl(request, is_mark4):
|
||||
return request.getfixturevalue('mk4_repl' if is_mark4 else 'old_mk_repl')
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def mk4_repl(sim_eval, sim_exec):
|
||||
# Provide an interactive connection to the REPL, using the debug build USB commands
|
||||
|
||||
class Mk4USBRepl:
|
||||
def eval(self, cmd, max_time=3):
|
||||
# send a command, wait for it to finish
|
||||
print("eval: %r" % cmd)
|
||||
resp = sim_eval(cmd)
|
||||
if 'Traceback' in resp:
|
||||
raise RuntimeError(resp)
|
||||
return eval(resp)
|
||||
|
||||
def exec(self, cmd, proc_time=1):
|
||||
# send a (one line) command and read the one-line response
|
||||
print("exec: %r" % cmd)
|
||||
|
||||
return sim_exec(cmd)
|
||||
|
||||
return Mk4USBRepl()
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def old_mk_repl(dev=None):
|
||||
# Provide an interactive connection to the REPL. Has to be real device, with
|
||||
# dev features enabled. Best really with unit in factory mode.
|
||||
import sys, serial
|
||||
@ -709,6 +735,7 @@ def repl(dev=None):
|
||||
# NOTE:
|
||||
# - tested only on Mac, but might work elsewhere.
|
||||
# - board needs to be reset between runs, because USB protocol (not serial) is disabled by this
|
||||
# - relies on virtual COM port present on Mk1-3 but not mk4
|
||||
|
||||
class USBRepl:
|
||||
def __init__(self):
|
||||
|
||||
@ -11,14 +11,14 @@
|
||||
# - provide "--mk 3" on command line for newer hardware stuff
|
||||
# - always run with "-s" so you have something to watch: very slow.
|
||||
# - mark2 no longer supported here, assumes mk3+, nor "secondary" pin's
|
||||
# - XXX mark4 needs work still
|
||||
# - mark4 works over USB protocol, so must be logged in so can't be empty pin
|
||||
#
|
||||
import time, pytest, os
|
||||
from ckcc_protocol.protocol import CCProtocolPacker, CCProtoError, MAX_TXN_LEN, CCUserRefused
|
||||
from binascii import b2a_hex, a2b_hex
|
||||
from pprint import pprint
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
@pytest.fixture(scope='module')
|
||||
def setup_repl(repl):
|
||||
repl.exec('from glob import dis; from pincodes import pa; import callgate')
|
||||
|
||||
@ -32,11 +32,12 @@ def test_eval(repl):
|
||||
assert repl.eval("'a'+'b'") == "ab"
|
||||
|
||||
@pytest.mark.parametrize('pin', [ '12-12', '123456-123456'])
|
||||
def test_pin_set(repl, setup_repl, pin):
|
||||
def test_pin_set(repl, setup_repl, pin, only_mk3):
|
||||
# always clear it after!
|
||||
# might need for recovery:
|
||||
# might need for setup/recovery:
|
||||
# pa.setup(b'12-12'); pa.login(); pa.change(new_pin=b'')
|
||||
#
|
||||
# Mk4: broken, because can't do anything w/ empty pin over USB
|
||||
|
||||
assert pin != ''
|
||||
|
||||
@ -81,7 +82,7 @@ def test_prefix_words(repl, setup_repl):
|
||||
assert a3 != a2
|
||||
assert a1 == a3
|
||||
|
||||
def test_greenlight(repl, setup_repl):
|
||||
def test_greenlight(repl, setup_repl, is_mark4):
|
||||
from random import randint
|
||||
|
||||
# NOTE: the return values and names of these functions are all stupid.
|
||||
@ -95,12 +96,17 @@ def test_greenlight(repl, setup_repl):
|
||||
assert repl.eval("callgate.set_genuine()", max_time=5) == 0
|
||||
assert repl.eval("callgate.get_genuine()") == 1
|
||||
|
||||
# this changes flash.
|
||||
assert repl.eval("open('/flash/test', 'wb').write(b'hi %06d')" % randint(1,1e6)) >= 3
|
||||
time.sleep(1)
|
||||
|
||||
# 'set_genuine' really means "test if genuine" here
|
||||
assert repl.eval("callgate.set_genuine()", max_time=5) == -1
|
||||
if is_mark4:
|
||||
# TODO: need a way to break 'genuine' state on mk4?
|
||||
assert repl.eval("callgate.set_genuine()", max_time=5) == 0
|
||||
else:
|
||||
# this changes flash and so affects genuine status
|
||||
assert repl.eval("open('/flash/test', 'wb').write(b'hi %06d')" % randint(1,1e6)) >= 3
|
||||
time.sleep(1)
|
||||
|
||||
assert repl.eval("callgate.set_genuine()", max_time=5) == -1
|
||||
|
||||
assert repl.eval("callgate.get_genuine()") == 1
|
||||
|
||||
assert repl.eval("pa.greenlight_firmware()", max_time=5) == None
|
||||
@ -108,9 +114,9 @@ def test_greenlight(repl, setup_repl):
|
||||
assert repl.eval("callgate.set_genuine()", max_time=5) == 0
|
||||
assert repl.eval("callgate.get_genuine()") == 1
|
||||
|
||||
assert repl.eval("dis.clear(); dis.text(0,0, 'done'); dis.show()") == 28
|
||||
repl.exec("dis.clear(); dis.text(0,0, 'done'); dis.show()")
|
||||
|
||||
def test_duress(repl, setup_repl):
|
||||
def test_duress(repl, setup_repl, only_mk3):
|
||||
ss = repl.eval("pa.setup(b'')")
|
||||
assert ss&0xf == 3
|
||||
|
||||
@ -126,59 +132,14 @@ def test_duress(repl, setup_repl):
|
||||
# cleanup
|
||||
repl.eval("pa.setup(b'')")
|
||||
|
||||
@pytest.mark.parametrize('nfails', [1, 3])
|
||||
def test_bad_logins_mark2(mk_num, repl, setup_repl, nfails):
|
||||
ss = repl.eval("pa.setup(b'')")
|
||||
|
||||
if ss&0xf != 3:
|
||||
# robustness
|
||||
repl.eval("pa.setup(b'12-12')")
|
||||
repl.eval("[pa.delay() for i in range(pa.delay_required)]")
|
||||
assert repl.eval("pa.login()") == True
|
||||
|
||||
assert repl.eval("pa.change(new_pin=b'12-12')") == None
|
||||
assert repl.eval("pa.setup(b'12-12')")&0xf == 0
|
||||
assert repl.eval("pa.login()") == True
|
||||
|
||||
def prepare_attempt(pin):
|
||||
assert repl.eval("pa.setup(%r)" % pin)&0xf == 0
|
||||
nf = repl.eval('pa.num_fails')
|
||||
nd = repl.eval('pa.delay_required')
|
||||
if nf: assert nd >= 1
|
||||
for x in range(nd):
|
||||
repl.eval('pa.delay()')
|
||||
assert repl.eval('pa.delay_required') == repl.eval('pa.delay_achieved')
|
||||
return nf
|
||||
|
||||
# try wrong pin a few times
|
||||
for n in range(nfails):
|
||||
nf = prepare_attempt(b'xx')
|
||||
|
||||
assert nf == n
|
||||
|
||||
with pytest.raises(RuntimeError) as ee:
|
||||
repl.eval("pa.login()")
|
||||
assert 'AUTH_FAIL' in ee.value.args[0]
|
||||
|
||||
# should be successful now
|
||||
prepare_attempt(b'12-12')
|
||||
assert repl.eval("pa.login()") == True
|
||||
|
||||
# reset state
|
||||
assert repl.eval("pa.change(new_pin=b'')") == None
|
||||
assert repl.eval("pa.setup(b'')")&0xf == 3
|
||||
assert repl.eval("pa.delay_required") == 0
|
||||
assert repl.eval("pa.num_fails") == 0
|
||||
|
||||
|
||||
MAX_ATT = 13
|
||||
|
||||
@pytest.mark.parametrize('nfails', [MAX_ATT-1, 1, 3, 5])
|
||||
def test_bad_logins_mark3(repl, setup_repl, nfails):
|
||||
def test_bad_logins(repl, setup_repl, nfails):
|
||||
ss = repl.eval("pa.setup(b'')")
|
||||
|
||||
if ss&0xf != 3:
|
||||
# robustness: recover w/ probably pin
|
||||
# robustness: recover w/ probable pin
|
||||
repl.eval("pa.setup(b'12-12')")
|
||||
assert repl.eval("pa.login()") == True
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user