diff options
author | xengineering <me@xengineering.eu> | 2024-08-30 09:41:21 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-08-30 09:49:07 +0200 |
commit | 3b976f78160c3acca82fc2da53207cd85b548cdd (patch) | |
tree | 9315334cd22c1a672eae1debd3f2ca2f12456961 | |
parent | 0ff8c7370ad87ac450b32955210a1ec366413d61 (diff) | |
download | iot-contact-3b976f78160c3acca82fc2da53207cd85b548cdd.tar iot-contact-3b976f78160c3acca82fc2da53207cd85b548cdd.tar.zst iot-contact-3b976f78160c3acca82fc2da53207cd85b548cdd.zip |
firmware: Add tools/debug-network-issue.py
This script can be used to analyze an issue which causes that the
microcontroller is not able to communicate via the network after roughly
every second boot.
-rwxr-xr-x | firmware/tools/debug-network-issue.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/firmware/tools/debug-network-issue.py b/firmware/tools/debug-network-issue.py new file mode 100755 index 0000000..e89f0ce --- /dev/null +++ b/firmware/tools/debug-network-issue.py @@ -0,0 +1,73 @@ +#!/usr/bin/python3 + + +import argparse +import subprocess +import time + + +HELP = """This script can be used to debug an issue where the Zephyr-based +firmware of a target microcontroller is not able to communicate via the network +after roughly every second boot process. The Ethernet-capable microcontroller +has to be connected directly to the Linux-based host PC via an Ethernet cable +and a ST-Link. Reboots are triggered via the Open Source st-utils tool +(https://github.com/stlink-org/stlink). Connectivity is checked with ping.""" + + +def main(): + args = parse_args() + + ok = 0 + not_ok = 0 + + for i in range(args.iterations): + print(f"Iteration #{i+1}") + subprocess.run(["st-info", "--connect-under-reset"], check=True) + time.sleep(args.delay) + try: + subprocess.run( + ["ping", "-c", "1", args.address], check=True, stdout=subprocess.DEVNULL + ) + print("ok") + ok += 1 + except: + print("not ok") + not_ok += 1 + + print( + f"Success rate is {round(100 * ok / (ok + not_ok))} % ({ok} ok and {not_ok} failed)" + ) + + +def parse_args(): + parser = argparse.ArgumentParser(description=HELP) + + parser.add_argument( + "-i", + "--iterations", + default=100, + help="how often the test should be executed", + type=int, + ) + + parser.add_argument( + "-d", + "--delay", + default=10, + help="how long to wait after reset for the ICMP request", + type=int, + ) + + parser.add_argument( + "-a", + "--address", + required=True, + help="address of the microcontroller / target of ICMP request", + type=str, + ) + + return parser.parse_args() + + +if __name__ == "__main__": + main() |