Skip to content

Commit

Permalink
twister: hwmap: add script parameter support
Browse files Browse the repository at this point in the history
for pre/post/post_flash script, add timeout as param

Signed-off-by: Hake Huang <[email protected]>
  • Loading branch information
hakehuang authored and aescolar committed Sep 16, 2024
1 parent 1dde706 commit 7f63faa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
16 changes: 13 additions & 3 deletions scripts/pylib/twister/twisterlib/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,13 @@ def handle(self, harness):
pre_script = hardware.pre_script
post_flash_script = hardware.post_flash_script
post_script = hardware.post_script
script_param = hardware.script_param

if pre_script:
self.run_custom_script(pre_script, 30)
timeout = 30
if script_param:
timeout = script_param.get("pre_script_timeout", timeout)
self.run_custom_script(pre_script, timeout)

flash_timeout = hardware.flash_timeout
if hardware.flash_with_test:
Expand Down Expand Up @@ -756,7 +760,10 @@ def handle(self, harness):
flash_error = True

if post_flash_script:
self.run_custom_script(post_flash_script, 30)
timeout = 30
if script_param:
timeout = script_param.get("post_flash_timeout", timeout)
self.run_custom_script(post_flash_script, timeout)

# Connect to device after flashing it
if hardware.flash_before:
Expand Down Expand Up @@ -795,7 +802,10 @@ def handle(self, harness):
self._final_handle_actions(harness, handler_time)

if post_script:
self.run_custom_script(post_script, 30)
timeout = 30
if script_param:
timeout = script_param.get("post_script_timeout", timeout)
self.run_custom_script(post_script, timeout)

self.make_dut_available(hardware)

Expand Down
4 changes: 4 additions & 0 deletions scripts/pylib/twister/twisterlib/hardwaremap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self,
pre_script=None,
post_script=None,
post_flash_script=None,
script_param=None,
runner=None,
flash_timeout=60,
flash_with_test=False,
Expand All @@ -70,6 +71,7 @@ def __init__(self,
self.post_flash_script = post_flash_script
self.post_script = post_script
self.pre_script = pre_script
self.script_param = script_param
self.probe_id = None
self.notes = None
self.lock = Lock()
Expand Down Expand Up @@ -248,6 +250,7 @@ def load(self, map_file):
duts = scl.yaml_load_verify(map_file, hwm_schema)
for dut in duts:
pre_script = dut.get('pre_script')
script_param = dut.get('script_param')
post_script = dut.get('post_script')
post_flash_script = dut.get('post_flash_script')
flash_timeout = dut.get('flash_timeout') or self.options.device_flash_timeout
Expand Down Expand Up @@ -282,6 +285,7 @@ def load(self, map_file):
flash_before=flash_before,
post_script=post_script,
post_flash_script=post_flash_script,
script_param=script_param,
flash_timeout=flash_timeout,
flash_with_test=flash_with_test)
new_dut.fixtures = fixtures
Expand Down
13 changes: 13 additions & 0 deletions scripts/schemas/twister/hwmap-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,16 @@ sequence:
"flash_before":
type: bool
required: false
"script_param":
type: map
required: false
mapping:
"pre_script_timeout":
type: int
required: false
"post_script_timeout":
type: int
required: false
"post_flash_timeout":
type: int
required: false
14 changes: 12 additions & 2 deletions scripts/tests/twister/test_hardwaremap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def mocked_hm():
'post_flash_script': 'dummy post flash script',
'runner': 'dummy runner',
'flash_timeout': 30,
'flash_with_test': True
'flash_with_test': True,
'script_param': {
'pre_script_timeout' : 30,
'post_flash_timeout' : 30,
'post_script_timeout' : 30,
}
},
{
'lock': mock.ANY,
Expand All @@ -76,7 +81,12 @@ def mocked_hm():
'post_flash_script': 'dummy post flash script',
'runner': 'dummy runner',
'flash_timeout': 30,
'flash_with_test': True
'flash_with_test': True,
'script_param': {
'pre_script_timeout' : 30,
'post_flash_timeout' : 30,
'post_script_timeout' : 30,
}
},
'<dummy platform (dummy product) on dummy serial>'
),
Expand Down

0 comments on commit 7f63faa

Please sign in to comment.