Skip to content

Commit 0e21047

Browse files
committed
reworked firstboot tests
1 parent 10aac42 commit 0e21047

File tree

3 files changed

+33
-67
lines changed

3 files changed

+33
-67
lines changed

src/ttboard/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
@author: Pat Deegan
77
@copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com
88
'''
9-
VERSION='0.9.4'
9+
VERSION='0.9.5'

src/ttboard/boot/first.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@
3939
import ttboard.logging as logging
4040
log = logging.getLogger(__name__)
4141

42+
def doEval(command:str, loc_vals:dict):
43+
ret_val = None
44+
if ttboard.util.platform.IsRP2040:
45+
ret_val = eval(command, loc_vals)
46+
else:
47+
ret_val = eval(command, loc_vals, loc_vals)
48+
49+
return ret_val
50+
4251
class FirstBootConfig(ConfigFile):
4352
'''
4453
Wrapper for the first_boot.ini config file
@@ -68,14 +77,14 @@ def execute(self, run_context:dict) -> bool:
6877
cmd = self.get('command')
6978
demoboard = self.ttdemoboard
7079
try:
71-
self.operation_return_value = eval(f'fbops.{cmd}', {'fbops':fbops,
80+
self.operation_return_value = doEval(f'fbops.{cmd}', {'fbops':fbops,
7281
'demoboard':demoboard,
7382
'context':run_context})
74-
except:
75-
log.error(f"Error executing {cmd}")
83+
except Exception as e:
84+
log.error(f"Error executing {cmd}: {e}")
7685
return False
7786

78-
return True
87+
return self.operation_return_value
7988

8089
class SetupOperation(FirstBootOperation):
8190
pass
@@ -146,7 +155,7 @@ def run(self):
146155
log.error('Could not execute setup -- abort!')
147156
return False
148157

149-
demoboard = DemoBoard()
158+
demoboard = DemoBoard.get()
150159
num_fails = 0
151160
keep_running_tests = True
152161
for section in sorted(self.config.sections):

src/ttboard/boot/firstboot_operations.py

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,31 @@
1818
from ttboard.demoboard import DemoBoard, Pins
1919
import ttboard.util.time as time
2020
from ttboard.mode import RPMode
21+
import ttboard.util.shuttle_tests as shut_tests
2122

2223

2324
import ttboard.logging as logging
2425
log = logging.getLogger(__name__)
2526

2627

2728
def get_demoboard() -> DemoBoard:
28-
return locals()['demoboard']
29+
locvars = locals()
30+
if 'demoboard' in locvars:
31+
return locvars['demoboard']
32+
33+
return DemoBoard.get()
2934

3035
def get_context() -> dict:
31-
return locals()['context']
36+
locvars = locals()
37+
if 'context' in locvars:
38+
return locvars['context']
39+
40+
raise KeyError('Cannot find context in localvars??')
3241

3342
def setup_somehow():
3443
# any setup we might need done
3544
print("nothing much to setup")
45+
return True
3646

3747
def firstboot_completed():
3848
# called when all tests passed.
@@ -62,43 +72,12 @@ def test_bidirs(max_idx:int, delay_interval_ms:int=1):
6272
# a test, must return True to consider a pass
6373
tt = get_demoboard()
6474
print(f'Testing bidirs up to {max_idx} on {tt}')
75+
err = shut_tests.factory_test_bidirs(tt, max_idx, delay_interval_ms)
6576

66-
# select the project from the shuttle
67-
update_delay_ms = delay_interval_ms
68-
auto_clock_freq = 1e3
69-
tt.shuttle.tt_um_test.enable()
70-
curMode = tt.mode
71-
tt.mode = RPMode.ASIC_ON_BOARD # make sure we're controlling everything
72-
73-
tt.in0(0) # want this low
74-
tt.clock_project_PWM(auto_clock_freq) # clock it real good
75-
76-
log.info('First boot: starting bidirection pins tests')
77-
for bp in tt.bidirs:
78-
bp.mode = Pins.OUT
79-
bp(0) # start low
80-
81-
errCount = 0
82-
for i in range(max_idx):
83-
tt.bidir_byte = i
84-
time.sleep_ms(update_delay_ms)
85-
outbyte = tt.output_byte
86-
if outbyte != i:
87-
log.warn(f'MISMATCH between bidir val {i} and output {outbyte}')
88-
errCount += 1
89-
90-
# reset everything
91-
for bp in tt.bidirs:
92-
bp.mode = Pins.IN
93-
94-
tt.clock_project_stop()
95-
tt.mode = curMode
96-
97-
if errCount:
98-
log.error(f'{errCount} ERRORS encountered')
77+
if err is not None:
78+
log.error(err)
9979
return False
10080

101-
log.info('Bi-directional pins acting pretty nicely as inputs!')
10281
return True
10382

10483

@@ -107,39 +86,17 @@ def test_clocking(max_idx:int=30, delay_interval_ms:int=50):
10786
# a test, must return True to consider a pass
10887
tt = get_demoboard()
10988
print(f'Testing manual clocking up to {max_idx} on {tt}')
110-
111-
112-
# select the project from the shuttle
113-
tt.shuttle.tt_um_test.enable()
114-
tt.mode = RPMode.ASIC_ON_BOARD # make sure we're controlling everything
115-
116-
117-
tt.reset_project(True)
118-
tt.input_byte = 1
119-
tt.clock_project_stop()
120-
tt.reset_project(False)
121-
122-
errCount = 0
123-
for i in range(max_idx):
124-
tt.clock_project_once()
125-
time.sleep_ms(delay_interval_ms)
126-
if tt.output_byte != i:
127-
log.warn(f'MISMATCH between bidir val {i} and output {tt.output_byte}')
128-
errCount += 1
129-
130-
131-
if errCount:
132-
log.error(f'{errCount} ERRORS encountered')
89+
err = shut_tests.factory_test_clocking(tt, max_idx, delay_interval_ms)
90+
if err is not None:
91+
log.error(err)
13392
return False
13493

135-
log.info('RP2040 clocking acting pretty nicely')
13694
return True
13795

13896

13997

14098

14199

142-
143100
def say_hello(delay_interval_ms:int=100, times:int=1):
144101
# a test, must return True to consider a pass
145102
print(f'Saying hello')

0 commit comments

Comments
 (0)