11
11
12
12
TEST_RFP_PORT = 'test-rfp-serial'
13
13
TEST_RFP_PORT_SPEED = '115200'
14
+ TEST_RFP_TOOL = 'jlink'
15
+ TEST_RFP_INTERFACE = 'swd'
14
16
TEST_RFP_DEVICE = 'RA'
15
17
TEST_RFP_USR_LOCAL_RFP_CLI = '/usr/local/bin/rfp-cli'
18
+ TEST_RFP_RPD_FILE = 'test-zephyr.rpd'
16
19
17
20
EXPECTED_COMMANDS = [
18
21
[
93
96
],
94
97
]
95
98
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
+
96
130
97
131
def require_patch (program ):
98
- assert program in ['rfp' ]
132
+ assert program in ['rfp' , 'rfp-cli' , TEST_RFP_USR_LOCAL_RFP_CLI ]
99
133
100
134
101
135
os_path_isfile = os .path .isfile
102
136
103
137
104
138
def os_path_isfile_patch (filename ):
105
- if filename == RC_KERNEL_HEX :
139
+ if filename == RC_KERNEL_HEX or TEST_RFP_RPD_FILE :
106
140
return True
107
141
return os_path_isfile (filename )
108
142
109
143
110
144
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
111
145
@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 ):
113
148
"""
114
149
Test commands using a runner created by constructor.
115
150
@@ -129,7 +164,8 @@ def test_rfp_init(cc, req, runner_config, tmpdir):
129
164
130
165
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
131
166
@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 ):
133
169
"""
134
170
Test commands using a runner created from command line parameters.
135
171
@@ -154,7 +190,8 @@ def test_rfp_create(cc, req, runner_config, tmpdir):
154
190
155
191
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
156
192
@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 ):
158
195
"""
159
196
Test commands using a runner created from command line parameters.
160
197
@@ -185,7 +222,8 @@ def test_rfp_create_with_speed(cc, req, runner_config, tmpdir):
185
222
186
223
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
187
224
@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 ):
189
227
"""
190
228
Test commands using a runner created from command line parameters.
191
229
@@ -207,7 +245,8 @@ def test_rfp_create_with_erase(cc, req, runner_config, tmpdir):
207
245
208
246
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
209
247
@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 ):
211
250
"""
212
251
Test commands using a runner created from command line parameters.
213
252
@@ -229,7 +268,8 @@ def test_rfp_create_with_verify(cc, req, runner_config, tmpdir):
229
268
230
269
@patch ('runners.core.ZephyrBinaryRunner.require' , side_effect = require_patch )
231
270
@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 ):
233
273
"""
234
274
Test commands using a runner created from command line parameters.
235
275
@@ -254,3 +294,74 @@ def test_rfp_create_with_rfp_cli(cc, req, runner_config, tmpdir):
254
294
with patch ('os.path.isfile' , side_effect = os_path_isfile_patch ):
255
295
runner .run ('flash' )
256
296
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