forked from auto-pts/auto-pts
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcliparser.py
More file actions
658 lines (516 loc) · 29.6 KB
/
Copy pathcliparser.py
File metadata and controls
658 lines (516 loc) · 29.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/usr/bin/env python
#
# auto-pts - The Bluetooth PTS Automation Framework
#
# Copyright (c) 2017, Intel Corporation.
# Copyright (c) 2025, Atmosic.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
import argparse
import copy
import json
import logging
import os
import shutil
import sys
import time
from itertools import zip_longest
from pathlib import Path
from autopts.config import CLIENT_PORT, FILE_PATHS, MAX_SERVER_RESTART_TIME, SERIAL_BAUDRATE, SERVER_PORT
from autopts.ptsprojects.boards import com_to_tty, get_debugger_snr, get_free_device, get_tty, tty_exists
from autopts.ptsprojects.testcase_db import DATABASE_FILE
from autopts.utils import active_hub_server_replug_usb, get_tc_from_wid, load_wid_report, raise_on_global_end, ykush_replug_usb
log = logging.debug
IUT_MODES = ['tty', 'qemu', 'native', 'btpclient_path']
class SmartDefaultsMixin:
def add_argument(self, *args, **kwargs):
default_value = kwargs.get("default", None)
iut_param = kwargs.pop("iut_param", False)
kwargs["default"] = argparse.SUPPRESS
action = super().add_argument(*args, **kwargs)
action._default_value = copy.deepcopy(default_value)
action.iut_param = iut_param
return action
def parse_args(self, *args, **kwargs):
namespace = super().parse_args(*args, **kwargs)
provided = set(vars(namespace).keys())
namespace._cli_provided = provided
for action in self._actions:
if not hasattr(action, "_default_value"):
continue
if action.dest not in provided:
setattr(namespace, action.dest, action._default_value)
return namespace
class CliParser(SmartDefaultsMixin, argparse.ArgumentParser):
def __init__(self, iut_modes=None, board_names=None, add_help=True, *args, **kwargs):
super().__init__(description='PTS automation client', add_help=add_help)
if iut_modes is None:
iut_modes = IUT_MODES
self.add_argument("--iut-mode", "--iut_mode", type=str, nargs='+',
action="extend", choices=iut_modes, default=None,
help="Specify the mode of the IUT (Identity Under Test). "
"If the option is not provided, mode will be inferred "
"from the parameters.", iut_param=True)
self.add_argument("-i", "--ip_addr", nargs="+",
help="IP address of the PTS automation servers. "
"If running with multiple servers(PTS dongles), "
"specify the IP addresses separated by a space, "
"e.g. \"-i 192.168.2.2 192.168.2.2\"")
self.add_argument("-l", "--local_addr", nargs="+", default=None,
help="Local IP address of PTS automation client. "
"If running with multiple servers(PTS dongles), "
"specify the IP addresses separated by a space, "
"e.g. \"-l 192.168.2.1 192.168.2.1\"")
self.add_argument("-a", "--bd-addr",
help="Bluetooth device address of the IUT")
self.add_argument("-d", "--debug-logs", dest="enable_max_logs",
action='store_true', default=False,
help="Enable the PTS maximum logging. Equivalent "
"to running test case in PTS GUI using "
"'Run (Debug Logs)'")
self.add_argument("-c", "--test-cases", nargs='+', default=[],
action="extend",
help="Names of test cases to run. Groups of "
"test cases can be specified by profile names."
"Option can be used multiple times.")
self.add_argument("--test-cases-file", type=argparse.FileType('r'),
help="A file with names of test cases to run. "
"One test case per line. Use instead of -c option.")
self.add_argument("-e", "--excluded", nargs='+', default=[],
help="Names of test cases to exclude. Groups of "
"test cases can be specified by profile names")
self.add_argument("--test_case_limit", nargs='?', type=int, default=0,
help="Limit of test cases to run")
self.add_argument("-r", "--retry", type=int, default=0,
help="Repeat test if failed. Parameter specifies "
"maximum repeat count per test")
self.add_argument("--no_retry_on_regression", type=bool,
help="When no_retry_on_regression is used, failed test cases are handled as follows: if test"
" failure is not a regression, test case will not be retried (i.e. retry is ignored). If"
" the failure is regression, test case will be retried for retry number of times. If"
" you set retry to zero, no failed test cases will be retried.")
self.add_argument("--repeat_until_fail", action='store_true', default=False,
help="Repeat test case until non-pass verdict")
self.add_argument("--stress_test", action='store_true', default=False,
help="Repeat every test even if previous result was PASS")
self.add_argument("-S", "--srv_port", type=int, nargs="+", default=[SERVER_PORT],
help="Specify the server port number. "
"If running with multiple servers(PTS dongles), "
"specify the ports separated by a space, "
"e.g. \"-S 65000 65002 65004\"")
self.add_argument("-C", "--cli_port", type=int, nargs="+", default=[CLIENT_PORT],
help="Specify the client port number. "
"If running with multiple servers(PTS dongles), "
"specify the ports separated by a space, "
"e.g. \"-C 65001 65003 65005\"")
self.add_argument("--tty-baudrate", "--tty_baudrate", type=int,
nargs='+', action="extend", default=SERIAL_BAUDRATE,
help="The TTY baudrate.", iut_param=True)
self.add_argument("--recovery", action='store_true', default=False,
help="Specify if autoptsclient should try to recover"
" itself after wrong status.")
self.add_argument("--not_recover", nargs='+',
default=['PASS', 'INCONC', 'FAIL', 'NOT_IMPLEMENTED', 'INDCSV'],
help="Specify at which statuses autoptsclient should "
"try to recover itself.")
self.add_argument("--superguard", default=0, metavar='MINUTES', type=float,
help="Specify amount of time in minutes, after which"
" super guard will blindly trigger recovery steps.")
self.add_argument("--ykush", metavar='YKUSH_PORT', type=str,
nargs="+", action="extend", default=None,
help="Specify ykush downstream port number, so on BTP TIMEOUT "
"the iut device could be powered off and on.", iut_param=True)
self.add_argument("--pylink_reset", action='store_true', default=False,
help="Use pylink reset.", iut_param=True)
self.add_argument('--nc', dest='copy_workspace', action='store_false',
help='Do not copy workspace, open original one. '
'Warning: workspace file might be modified', default=True)
self.add_argument("--rtscts", dest='rtscts', action="store_true", default=False,
help="Enable UART hardware flow control.", iut_param=True)
# Hidden option to save test cases data in TestCase.db
self.add_argument("-s", "--store", action="store_true",
default=False, help=argparse.SUPPRESS)
self.add_argument("--sudo", action="store_true",
default=False, help=argparse.SUPPRESS)
self.add_argument("--database-file", type=str, default=DATABASE_FILE,
help=argparse.SUPPRESS)
self.add_argument("--max_server_restart_time", type=int, default=MAX_SERVER_RESTART_TIME,
help=argparse.SUPPRESS)
self.add_argument("--tty_alias", type=str, nargs='+', action="extend",
default='', help=argparse.SUPPRESS, iut_param=True)
self.add_argument("--ykush_replug_delay", type=float, nargs='+', action="extend",
default=3, help=argparse.SUPPRESS, iut_param=True)
self.add_argument("--active-hub-server", type=str, help=argparse.SUPPRESS, iut_param=True)
self.add_argument("--usb-replug-available", "--usb_replug_available", type=bool,
default=False, help=argparse.SUPPRESS, iut_param=True)
self.add_argument("--project_path", type=str, help=argparse.SUPPRESS, iut_param=True)
# Path to tester application relative to project_path. Used for build and flash in bot mode. Only supported by
# Zephyr project.
self.add_argument("--tester_app_dir", type=Path, default=Path('tests', 'bluetooth', 'tester'),
help=argparse.SUPPRESS)
self.add_argument("--pts_addr_map", default={}, help=argparse.SUPPRESS)
self.add_argument("--restricted_pts_addrs", default=[], help=argparse.SUPPRESS)
self.add_argument("--iut_targets", default=None, help=argparse.SUPPRESS)
self.add_argument("--iut_targets_args", default={}, help=argparse.SUPPRESS)
self.add_argument("--iut_target_selection", default=None,
help="IUT target selection configuration dictionary or "
"a path to .json file that contains the dictionary.")
self.add_argument('--nb', dest='no_build', action='store_true',
help='Skip build and flash in bot mode.', default=False)
self.add_argument("--btattach-bin", "--btattach_bin", default=None, iut_param=True,
help="The path to the btattach executable, e.g. /usr/bin/btattach")
self.add_argument("--btattach-at-every-test-case", "--btattach_at_every_test_case",
action='store_true', default=False, iut_param=True,
help="The path to the btattach executable, e.g. /usr/bin/btattach")
self.add_argument("--btproxy-bin", "--btproxy_bin", default=None,
help="The path to the btproxy executable, e.g. /usr/bin/btproxy")
self.add_argument("--qemu-bin", "--qemu_bin", default=None, iut_param=True,
help="The path to the QEMU executable, e.g. /usr/bin/qemu-system-arm")
self.add_argument("--qemu-options", "--qemu_options", type=str, iut_param=True,
nargs='+', action="extend", default="",
help="Additional options for the qemu, e.g. -cpu cortex-m3 -machine lm3s6965evb")
self.add_argument("--kernel-cpu", "--kernel_cpu", type=str, nargs="+",
default="qemu_cortex_m3", iut_param=True,
help="The type of CPU that will be used for building an image, e.g. qemu_cortex_m3")
self.add_argument("--hci", type=int, default=None, iut_param=True,
help="Specify the number of the HCI controller")
self.add_argument("--hid-vid", "--hid_vid", type=str, default=None, iut_param=True,
help="Specify the VID of the USB device used as a HCI controller "
"(hexadecimal string, e.g. '2fe3')")
self.add_argument("--hid-pid", "--hid_pid", type=str, default=None, iut_param=True,
help="Specify the PID of the USB device used as a HCI controller "
"(hexadecimal string, e.g. '000b')")
self.add_argument("--hid-serial", "--hid_serial", type=str, default=None, iut_param=True,
help="Specify the serial number of the USB device used as a HCI controller")
self.add_argument("--btmgmt-bin", "--btmgmt_bin", type=str, default=None, iut_param=True,
help="The path to the btmgmt executable, e.g. /usr/bin/btmgmt")
self.add_argument("--setcap-cmd", "--setcap_cmd", type=str, default=None, iut_param=True,
help="Command to set HCI access permissions for zephyr.exe in native mode, "
"e.g. sudo /usr/sbin/setcap cap_net_raw,cap_net_admin,cap_sys_admin+ep /path/to/zephyr.exe "
"To allow sudo setcap without password, add to visudo a line like this: "
"youruser ALL=(ALL) NOPASSWD: /usr/sbin/setcap")
self.add_argument("-t", "--tty-file", type=str, nargs='+', action="extend", default=None,
help="If TTY(or COM) is specified, BTP communication "
"with OS running on hardware will be done over "
"this TTY. Hence, QEMU will not be used.", iut_param=True)
self.add_argument("--net-tty-file", dest='net_tty_file', type=str,
nargs='+', action="extend", default=None, iut_param=True,
help="This can be used to log output from network core of IUT "
"(if additional port is available). Value should match "
"the COM/tty file port that outputs log from the network core. "
"There's no indication which COM port maps to the network "
"core.")
self.add_argument("-j", "--jlink", dest="debugger_snr", type=str,
nargs='+', action="extend", default=None, iut_param=True,
help="Specify jlink serial number manually.")
self.add_argument("-b", "--board", dest='board_name', type=str, iut_param=True,
nargs='+', action="extend", default=None, choices=board_names,
help="Used DUT board. This option is used to "
"select DUT reset command that is run before "
"each test case. If board is not specified DUT "
"will not be reset.")
self.add_argument("--btmon", action='store_true', default=False, iut_param=True,
help="Capture iut btsnoop logs from device over RTT and catch them with btmon. Requires rtt "
"support on IUT. When using with native linux build CAP_NET_RAW,CAP_NET_ADMIN and "
"CAP_SYS_ADMIN permissions are required. "
"e.g. sudo setcap cap_net_raw,cap_net_admin,cap_sys_admin+ep /usr/bin/btmon ")
self.add_argument("--device_core", type=str, nargs='+', action="extend",
default='NRF52840_XXAA', iut_param=True,
help="Specify the device core for JLink related features, "
"e.g. BTMON or RTT logging.")
self.add_argument("--rtt-log",
help="Capture iut logs from device over RTT. "
"Requires rtt support on IUT.",
action='store_true', default=False, iut_param=True)
self.add_argument("--rtt-log-syncto",
help="Specify the number of seconds that the RTT logging"
"should continue after the test has finished executing.",
type=float, default=0, iut_param=True)
self.add_argument("--gdb",
help="Skip board resets to avoid gdb server disconnection.",
action='store_true', default=False, iut_param=True)
self.add_argument("--btp-tcp-ip", "--btp_tcp_ip", type=str, nargs='+',
action="extend", default='127.0.0.1',
help="IP for external btp client over TCP/IP.", iut_param=True)
self.add_argument("--btp-tcp-port", "--btp_tcp_port", type=int, nargs='+',
action="extend", default=None,
help="Port for external btp client over TCP/IP.", iut_param=True)
self.add_argument("--btpclient-path", "--btpclient_path", type=str, nargs='+',
action="extend", default=None, help="Path to btpclient.", iut_param=True)
self.add_argument("--wid_run", nargs=2, metavar=("SERVICE", "WID"),
help="Run testcases based on service and wid")
self.add_argument("--kernel-image", "--kernel_image", type=str, nargs='+',
action="extend", default=None,
help="OS kernel image to be used for testing,"
"e.g. elf file for qemu, exe for native.", iut_param=True)
self.add_argument("--external-audio", type=str, default=None,
help="External audio support type.")
self.add_positional_args()
def add_positional_args(self):
self.add_argument("workspace", nargs='?', default=None,
help="Path to PTS workspace file to use for "
"testing. It should have pqw6 extension. "
"The file should be located on the "
"machine, where automation server is running.")
self.add_argument("kernel_image", nargs='?', default=None,
help="OS kernel image to be used for testing,"
"e.g. elf file for qemu, exe for native.")
def normalize_to_list(self, x):
if x is None:
return []
if isinstance(x, list):
return x
return [x]
def remodel_args(self, configpy_args, cli_args):
iut_targets_args = {}
# Filter out options/parameters that can be configured
# separately for each IUT.
iut_params = []
not_iut_params = []
for a in self._actions:
if getattr(a, "iut_param", False):
iut_params.append(a)
else:
not_iut_params.append(a)
# Filter out options/parameters actually provided in CLI
lists = {
a.dest: self.normalize_to_list(getattr(cli_args, a.dest))
for a in iut_params if a.dest in cli_args._cli_provided
}
base_params = {
a.dest: getattr(cli_args, a.dest)
for a in not_iut_params if a.dest in cli_args._cli_provided
}
# Distribute CLI params per-IUT
cli_targets = []
for values in zip_longest(*lists.values(), fillvalue=None):
params = dict(zip(lists.keys(), values, strict=False))
if cli_targets:
first = cli_targets[0]
for k, v in params.items():
if v is None:
params[k] = first[k]
cli_targets.append(params)
# Select base source of arguments
if configpy_args:
base = configpy_args
for name in base_params:
setattr(base, name, base_params[name])
else:
base = cli_args
# Create targets
if configpy_args and configpy_args.iut_targets:
targets = configpy_args.iut_targets
if not cli_targets:
cli_targets = [{} for _ in range(len(targets))]
else:
if not cli_targets:
cli_targets = [{}]
targets = [{"name": f"iut{i}"} for i in range(len(cli_targets))]
for i, (target, cli_params) in enumerate(zip(targets, cli_targets, strict=False)):
name = target.get("name", f"iut{i}")
args_copy = copy.deepcopy(base)
# config.py target
for k, v in target.items():
if hasattr(args_copy, k):
setattr(args_copy, k, v)
# CLI override
for k, v in cli_params.items():
setattr(args_copy, k, v)
args_copy.iut_target_name = name
iut_targets_args[name] = args_copy
# Add arguments that are in the CLI parser but not in the bot parser.
for action in self._actions:
dest = action.dest
if not hasattr(args_copy, dest) and hasattr(cli_args, dest):
setattr(args_copy, dest, getattr(cli_args, dest))
base.iut_targets_args = iut_targets_args
for action in self._actions:
dest = action.dest
if not hasattr(base, dest) and hasattr(cli_args, dest):
setattr(base, dest, getattr(cli_args, dest))
if isinstance(base.iut_target_selection, str) and os.path.exists(base.iut_target_selection):
with open(base.iut_target_selection) as f:
base.iut_target_selection = json.load(f)
elif not isinstance(base.iut_target_selection, dict):
base.iut_target_selection = {'default_iut_map': {}}
for i, iut_name in enumerate(base.iut_targets_args):
base.iut_target_selection['default_iut_map'][str(i)] = iut_name
return base
def _replug_and_find_tty(self, args):
log(f'{self._replug_and_find_tty.__name__}')
if not args.ykush and not args.active_hub_server:
return False
if args.ykush:
device_id = args.tty_alias if args.tty_alias else args.tty_file
ykush_replug_usb(args.ykush, device_id=device_id, delay=args.ykush_replug_delay)
elif args.active_hub_server:
active_hub_server_replug_usb(args.active_hub_server)
if args.tty_alias:
while not os.path.islink(args.tty_alias) and not os.path.exists(os.path.realpath(args.tty_alias)):
raise_on_global_end()
log(f'Waiting for TTY {args.tty_alias} to appear...\n')
time.sleep(1)
args.tty_file = os.path.realpath(args.tty_alias)
elif args.debugger_snr:
args.tty_file = get_tty(args.debugger_snr, args.board_name)
else:
args.tty_file, args.debugger_snr = get_free_device(args.board_name)
if not tty_exists(args.tty_file):
return False
return True
def wid_run_tcs(self, args):
"""
If --wid_run SERVICE WID was provided:
- load the CSV mapping
- lookup testcases for (service, wid)
- print them before execution
- and append to args.test_cases so they get executed like normal.
"""
if not args.wid_run:
return
mapping = load_wid_report()
service, wid = args.wid_run
tcs = get_tc_from_wid(service, wid, mapping)
if not tcs:
print(f"No testcases found for service={service}, wid={wid}")
return
print(f"Testcases for {service} {wid}:")
for tc in tcs:
print(tc)
# Append found test cases to test cases list
args.test_cases = list(args.test_cases) + tcs
def find_tty(self, args):
log(f'{self.find_tty.__name__}')
if args.tty_file:
args.tty_alias = None
log(f'Using tty_file={args.tty_file}')
elif args.tty_alias:
args.tty_file = os.path.realpath(args.tty_alias)
log(f'Using tty_alias={args.tty_alias} -> tty_file={args.tty_file}')
elif args.debugger_snr:
args.tty_file = get_tty(args.debugger_snr, args.board_name)
log(f'Using debugger_snr={args.debugger_snr} -> tty_file={args.tty_file}')
else:
args.tty_file, args.debugger_snr = get_free_device(args.board_name)
log(f'Found free TTY tty_file={args.tty_file} debugger_snr={args.debugger_snr}')
if not tty_exists(args.tty_file):
log(f'The TTY tty_file={args.tty_file} does not exist.')
# If an active hub is used, the board could be unplugged right now
if not self._replug_and_find_tty(args):
return f'TTY IUT mode: {repr(args.tty_file)} serial port does not exist!\n'
if args.debugger_snr is None:
args.debugger_snr = get_debugger_snr(args.tty_file)
if args.tty_file.startswith("COM"):
try:
args.tty_file = com_to_tty(args.tty_file)
except ValueError:
return f'TTY IUT mode: Port {args.tty_file} is not a valid COM port!\n'
return ''
def check_args_tty(self, args):
if not args.board_name:
return 'TTY IUT mode: specify board_name\n'
return ''
def check_args_qemu(self, args):
if not args.qemu_bin:
return 'QEMU IUT mode: specify qemu_bin parameter to use this mode\n'
if not shutil.which(args.qemu_bin):
return f'QEMU IUT mode: qemu_bin={args.qemu_bin}, but not found!\n'
if args.kernel_image:
if not os.path.isfile(args.kernel_image):
return f'QEMU IUT mode: kernel_image={repr(args.kernel_image)} is not a file!\n'
elif not args.project_path:
return 'QEMU IUT mode: specify kernel_image or project_path to use this IUT mode\n'
return ''
def check_args_native(self, args):
if args.kernel_image:
if not os.path.isfile(args.kernel_image):
return f'Native IUT mode: kernel_image {repr(args.kernel_image)} is not a file!\n'
elif not args.project_path:
return 'Native IUT mode: specify kernel_image or project_path to use this IUT mode\n'
return ''
def check_args_btpclient_path(self, args):
if not os.path.exists(args.btpclient_path):
return (
f'btpclient: Path {repr(args.btpclient_path)} of btp client '
'does not exist!\n'
)
return ''
def check_args_btp_tcp_client(self, args):
if not 49152 <= args.btp_tcp_port <= 65535:
return (
f'btp_tcp_client mode: Invalid server port number={args.btp_tcp_port}, expected '
'range <49152,65535>'
)
return ''
def get_iut_mode(self, args):
# Specify IUT mode explicitly, or it will be inferred
# from the parameters.
if args.iut_mode:
return args.iut_mode
if args.qemu_bin:
return 'qemu'
if args.kernel_image or args.hid_serial or args.hci is not None:
return 'native'
if args.btpclient_path:
return 'btpclient_path'
if args.btp_tcp_port:
return 'btp_tcp_client'
return 'tty'
def parse(self, arg_ns=None):
"""Parsing and sanity check command line arguments
Args:
arg_ns: namespace of arguments and parameters to overwrite
with the command line arguments parser
Returns: (args, errmsg)
where
args: namespace of parameters overwritten with parsed
command line arguments
errmsg: an error message if parsing failed, otherwise empty string
"""
errmsg = ''
cli_args = self.parse_args(None, None)
args = self.remodel_args(arg_ns, cli_args)
from autopts.client import init_logging
init_logging('_' + '_'.join(str(x) for x in args.cli_port),
FILE_PATHS.get('BOT_LOG_FILE', None))
if args.btproxy_bin and not is_executable(args.btproxy_bin):
return args, f'The btproxy_bin={args.btproxy_bin} is not an executable file'
if args.btattach_bin and not is_executable(args.btattach_bin):
return args, f'The btattach_bin={args.btattach_bin} is not an executable file'
args.superguard = 60 * args.superguard
if not args.ip_addr:
args.ip_addr = ['127.0.0.1'] * len(args.srv_port)
if not args.local_addr:
args.local_addr = ['127.0.0.1'] * len(args.cli_port)
for iut_name in args.iut_targets_args:
_args = args.iut_targets_args[iut_name]
_args.iut_mode = self.get_iut_mode(_args)
_args.superguard = args.superguard
_args.ip_addr = args.ip_addr
_args.local_addr = args.local_addr
if _args.ykush or _args.active_hub_server:
_args.usb_replug_available = True
else:
_args.usb_replug_available = False
if sys.platform == "win32" and _args.iut_mode in ['qemu', 'native']:
errmsg = f'The {_args.iut_mode} mode is not supported under Windows!'
return args, errmsg
if _args.iut_mode == 'tty' or (_args.iut_mode == 'native'
and _args.tty_file or _args.tty_alias or _args.debugger_snr):
self.find_tty(_args)
check_method = getattr(self, f'check_args_{_args.iut_mode}')
errmsg = check_method(_args)
if args.wid_run:
self.wid_run_tcs(args)
return args, errmsg
def is_executable(path):
return os.path.exists(path) and os.access(path, os.X_OK)