Skip to content

Commit 1df1cb4

Browse files
Ta Minh Nhatquytranpzz
authored andcommitted
west: runner: rfp: support update test_rfp.py file
This commit to support update test_rfp.py file Signed-off-by: Hau Ho <hau.ho.xc@bp.renesas.com>
1 parent 2b40f17 commit 1df1cb4

File tree

1 file changed

+119
-8
lines changed

1 file changed

+119
-8
lines changed

scripts/west_commands/tests/test_rfp.py

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
TEST_RFP_PORT = 'test-rfp-serial'
1313
TEST_RFP_PORT_SPEED = '115200'
14+
TEST_RFP_TOOL = 'jlink'
15+
TEST_RFP_INTERFACE = 'swd'
1416
TEST_RFP_DEVICE = 'RA'
1517
TEST_RFP_USR_LOCAL_RFP_CLI = '/usr/local/bin/rfp-cli'
18+
TEST_RFP_RPD_FILE = 'test-zephyr.rpd'
1619

1720
EXPECTED_COMMANDS = [
1821
[
@@ -93,23 +96,55 @@
9396
],
9497
]
9598

99+
EXPECTED_COMMANDS_WITH_JLINK_HARDWARE = [
100+
[
101+
TEST_RFP_USR_LOCAL_RFP_CLI,
102+
'-tool',
103+
TEST_RFP_TOOL,
104+
'-interface',
105+
TEST_RFP_INTERFACE,
106+
'-device',
107+
TEST_RFP_DEVICE,
108+
'-run',
109+
'-erase',
110+
'-p',
111+
'-file',
112+
RC_KERNEL_HEX,
113+
],
114+
]
115+
116+
EXPECTED_COMMANDS_WITH_PARTITION_DATA = [
117+
[
118+
TEST_RFP_USR_LOCAL_RFP_CLI,
119+
'-device',
120+
TEST_RFP_DEVICE,
121+
'-tool',
122+
TEST_RFP_TOOL,
123+
'-fo',
124+
'boundary-file',
125+
TEST_RFP_RPD_FILE,
126+
'-p',
127+
],
128+
]
129+
96130

97131
def require_patch(program):
98-
assert program in ['rfp']
132+
assert program in ['rfp', 'rfp-cli', TEST_RFP_USR_LOCAL_RFP_CLI]
99133

100134

101135
os_path_isfile = os.path.isfile
102136

103137

104138
def os_path_isfile_patch(filename):
105-
if filename == RC_KERNEL_HEX:
139+
if filename == RC_KERNEL_HEX or TEST_RFP_RPD_FILE:
106140
return True
107141
return os_path_isfile(filename)
108142

109143

110144
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
111145
@patch('runners.core.ZephyrBinaryRunner.check_call')
112-
def test_rfp_init(cc, req, runner_config, tmpdir):
146+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
147+
def test_rfp_init(dr, cc, req, runner_config, tmpdir):
113148
"""
114149
Test commands using a runner created by constructor.
115150
@@ -129,7 +164,8 @@ def test_rfp_init(cc, req, runner_config, tmpdir):
129164

130165
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
131166
@patch('runners.core.ZephyrBinaryRunner.check_call')
132-
def test_rfp_create(cc, req, runner_config, tmpdir):
167+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
168+
def test_rfp_create(dr, cc, req, runner_config, tmpdir):
133169
"""
134170
Test commands using a runner created from command line parameters.
135171
@@ -154,7 +190,8 @@ def test_rfp_create(cc, req, runner_config, tmpdir):
154190

155191
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
156192
@patch('runners.core.ZephyrBinaryRunner.check_call')
157-
def test_rfp_create_with_speed(cc, req, runner_config, tmpdir):
193+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
194+
def test_rfp_create_with_speed(dr, cc, req, runner_config, tmpdir):
158195
"""
159196
Test commands using a runner created from command line parameters.
160197
@@ -185,7 +222,8 @@ def test_rfp_create_with_speed(cc, req, runner_config, tmpdir):
185222

186223
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
187224
@patch('runners.core.ZephyrBinaryRunner.check_call')
188-
def test_rfp_create_with_erase(cc, req, runner_config, tmpdir):
225+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
226+
def test_rfp_create_with_erase(dr, cc, req, runner_config, tmpdir):
189227
"""
190228
Test commands using a runner created from command line parameters.
191229
@@ -207,7 +245,8 @@ def test_rfp_create_with_erase(cc, req, runner_config, tmpdir):
207245

208246
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
209247
@patch('runners.core.ZephyrBinaryRunner.check_call')
210-
def test_rfp_create_with_verify(cc, req, runner_config, tmpdir):
248+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
249+
def test_rfp_create_with_verify(dr, cc, req, runner_config, tmpdir):
211250
"""
212251
Test commands using a runner created from command line parameters.
213252
@@ -229,7 +268,8 @@ def test_rfp_create_with_verify(cc, req, runner_config, tmpdir):
229268

230269
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
231270
@patch('runners.core.ZephyrBinaryRunner.check_call')
232-
def test_rfp_create_with_rfp_cli(cc, req, runner_config, tmpdir):
271+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
272+
def test_rfp_create_with_rfp_cli(dr, cc, req, runner_config, tmpdir):
233273
"""
234274
Test commands using a runner created from command line parameters.
235275
@@ -254,3 +294,74 @@ def test_rfp_create_with_rfp_cli(cc, req, runner_config, tmpdir):
254294
with patch('os.path.isfile', side_effect=os_path_isfile_patch):
255295
runner.run('flash')
256296
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_RFP_CLI]
297+
298+
299+
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
300+
@patch('runners.core.ZephyrBinaryRunner.check_call')
301+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
302+
def test_rfp_create_with_jlink_hardware(dr, cc, req, runner_config, tmpdir):
303+
"""
304+
Test commands using a jlink hardware.
305+
306+
Input:
307+
--rfp-cli /usr/local/bin/rfp-cli
308+
309+
Output:
310+
/usr/local/bin/rfp-cli
311+
"""
312+
args = [
313+
'--device',
314+
str(TEST_RFP_DEVICE),
315+
'--tool',
316+
str(TEST_RFP_TOOL),
317+
'--interface',
318+
str(TEST_RFP_INTERFACE),
319+
'--erase',
320+
'--rfp-cli',
321+
str(TEST_RFP_USR_LOCAL_RFP_CLI),
322+
]
323+
parser = argparse.ArgumentParser(allow_abbrev=False)
324+
RfpBinaryRunner.add_parser(parser)
325+
arg_namespace = parser.parse_args(args)
326+
runner = RfpBinaryRunner.create(runner_config, arg_namespace)
327+
with patch('os.path.isfile', side_effect=os_path_isfile_patch):
328+
runner.run('flash')
329+
assert cc.call_args_list == [call(x) for x in EXPECTED_COMMANDS_WITH_JLINK_HARDWARE]
330+
331+
332+
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
333+
@patch('runners.core.ZephyrBinaryRunner.check_call')
334+
@patch('runners.rfp.RfpBinaryRunner.default_rfp')
335+
def test_rfp_create_with_partition_data(dr, cc, req, runner_config, tmpdir):
336+
"""
337+
Test commands using reresas partition data.
338+
339+
Input:
340+
--rfp-cli /usr/local/bin/rfp-cli
341+
342+
Output:
343+
/usr/local/bin/rfp-cli
344+
"""
345+
args = [
346+
'--device',
347+
str(TEST_RFP_DEVICE),
348+
'--tool',
349+
str(TEST_RFP_TOOL),
350+
'--interface',
351+
str(TEST_RFP_INTERFACE),
352+
'--rpd-file',
353+
str(TEST_RFP_RPD_FILE),
354+
'--erase',
355+
'--rfp-cli',
356+
str(TEST_RFP_USR_LOCAL_RFP_CLI),
357+
]
358+
parser = argparse.ArgumentParser(allow_abbrev=False)
359+
RfpBinaryRunner.add_parser(parser)
360+
arg_namespace = parser.parse_args(args)
361+
print(runner_config)
362+
runner = RfpBinaryRunner.create(runner_config, arg_namespace)
363+
with patch('os.path.isfile', side_effect=os_path_isfile_patch):
364+
runner.run('flash')
365+
print(cc.call_args_list)
366+
assert [cc.call_args_list[0]] == [call(x) for x in EXPECTED_COMMANDS_WITH_PARTITION_DATA]
367+
assert [cc.call_args_list[1]] == [call(x) for x in EXPECTED_COMMANDS_WITH_JLINK_HARDWARE]

0 commit comments

Comments
 (0)