aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFarouk Bouabid <farouk.bouabid@theobroma-systems.com>2024-02-19 16:17:33 +0100
committerFarouk Bouabid <farouk.bouabid@theobroma-systems.com>2024-02-26 15:29:58 +0100
commit85b373a517cf930888a090161939700113ab0b4c (patch)
tree0c4bd3db11d153a9a4778f7cf6d393e3e1fc9bd9
parent86aa1f3044e3f0b64816bc90f4113c67567cd287 (diff)
testing: serial: pass baudrate list from cliHEADmaster
Some serial ports do not support specific baudrates or we are maybe not interested in testing certain baudrate when running the fuzzing test. Allow the user to pass multiple baudrates as a cli argument and have the script randomly pick one of the baudrates while fuzz testing. Signed-off-by: Farouk Bouabid <farouk.bouabid@theobroma-systems.com>
-rwxr-xr-xtesting/serial/test-serial.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/testing/serial/test-serial.py b/testing/serial/test-serial.py
index 8287e9c..e5a855e 100755
--- a/testing/serial/test-serial.py
+++ b/testing/serial/test-serial.py
@@ -59,7 +59,12 @@ def update_serial_settings(tx, rx, baudrate, size):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
- parser.add_argument("-b", "--baudrate", type=int, default=115200)
+ parser.add_argument(
+ "-b", "--baudrate",
+ type=int,
+ action='append',
+ help="Baudrate to test. Repeat the option for different baudrates to choose from"
+ ),
parser.add_argument(
"--rs485",
action="store_true",
@@ -140,13 +145,24 @@ if __name__ == "__main__":
set_rs485_mode(rx, args.rs485)
size = args.size
- baudrate = args.baudrate
- baudrate_choices = list(
- filter(
- lambda baud: args.min_baudrate <= baud <= args.max_baudrate, tx.BAUDRATES
- )
- )
- update_serial_settings(tx, rx, baudrate, size)
+
+ if (not args.fuzz or "baudrate" not in args.fuzz) and args.baudrate and len(args.baudrate) > 1:
+ raise Exception("Please enable baudrate fuzzing when passing more than one baudrate")
+
+ if args.fuzz and "baudrate" in args.fuzz:
+ if args.baudrate and len(args.baudrate) > 1:
+ baudrate_choices = args.baudrate
+ elif args.baudrate:
+ raise Exception("More baudrate arguments are required for fuzzing")
+ else:
+ baudrate_choices = list(
+ filter(
+ lambda baud: args.min_baudrate <= baud <= args.max_baudrate, tx.BAUDRATES
+ )
+ )
+ else:
+ baudrate = args.baudrate[0] if args.baudrate else 115200
+ update_serial_settings(tx, rx, baudrate, size)
tx_errors = 0
rx_errors = 0