From 8431761b1d01613da235897b3cb8e58a59655d7a Mon Sep 17 00:00:00 2001 From: grvvy Date: Fri, 6 Jun 2025 11:04:42 -0600 Subject: [PATCH 1/2] ci: improve sgpio-debug test reliability and error messaging --- Jenkinsfile | 4 +++- ci-scripts/test-sgpio-debug.py | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 043585f6..6dc7fedf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,7 +33,9 @@ pipeline { sh 'python3 ci-scripts/test-transfer.py rx' } sh 'hubs all off' - sh 'python3 ci-scripts/test-sgpio-debug.py' + retry(3) { + sh 'python3 ci-scripts/test-sgpio-debug.py' + } sh 'hubs all reset' } } diff --git a/ci-scripts/test-sgpio-debug.py b/ci-scripts/test-sgpio-debug.py index 657b71f4..26298fb4 100644 --- a/ci-scripts/test-sgpio-debug.py +++ b/ci-scripts/test-sgpio-debug.py @@ -4,12 +4,12 @@ import sys import subprocess from pathlib import Path -FILENAME = "/tmp/rx_100kB_" + str(os.getpid()) +FILENAME = f"/tmp/rx_100kB_{str(os.getpid())}" def program_device(): # build new firmware with SGPIO_DEBUG mode enabled - print("Programming device..") + print("Programming device...") fw_dir = os.getcwd() + "/firmware/hackrf_usb/build" del_dir = subprocess.run(["rm", "-rf", "firmware/hackrf_usb/build"]) mk_dir = subprocess.run(["mkdir", "firmware/hackrf_usb/build"]) @@ -22,30 +22,40 @@ def program_device(): def capture(): - print("Capturing data..") + print("Capturing data...") rx_100kB = subprocess.run(["host/build/hackrf-tools/src/hackrf_transfer", "-r", FILENAME, "-d", "RunningFromRAM", "-n", "50000", "-s", "20000000"], capture_output=True, encoding="UTF-8") print(rx_100kB.stdout) print(rx_100kB.stderr) - print("Wrote data to file: " + FILENAME) + print(f"Wrote capture data to file: {FILENAME}") def check(): + print(f"Checking length of {FILENAME}") rx_data = Path(FILENAME).read_bytes() # file should be 100k bytes when using 50k samples if len(rx_data) != 100000: - print("SGPIO debug test failed.") + print(f"ERROR: Only {str(len(rx_data))} bytes found in file, expected 100k.") sys.exit(1) + else: + print("Correct file size found.") # check that each byte = prev_byte + 1 except at wraparound bounds + print("Checking bytes...") for i in range(1, len(rx_data)): if rx_data[i-1] != rx_data[i] - 1: if not (rx_data[i] == 0 and rx_data[i-1] == 255): - print("SGPIO debug test failed.") + print(f"ERROR: Incorrect data value found at location {str(i)} in {FILENAME}:") + # print up to 5 values starting from at most 1 value before error occurence + j = -1 + while j < 4: + if i + j < len(rx_data) and i + j > -1: + print(f"{str(i+j)} : {str(rx_data[i+j])}") + j = j + 1 sys.exit(1) - print("SGPIO debug test passed.") + print("Successfully validated all bytes in file.\nSGPIO debug test passed.") def main(): From 132da7b421a18eca637f175ed970358526521996 Mon Sep 17 00:00:00 2001 From: grvvy Date: Fri, 1 Aug 2025 10:45:53 -0600 Subject: [PATCH 2/2] ci: check shortfall count to isolate failures in firmware --- ci-scripts/test-sgpio-debug.py | 42 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/ci-scripts/test-sgpio-debug.py b/ci-scripts/test-sgpio-debug.py index 26298fb4..73531822 100644 --- a/ci-scripts/test-sgpio-debug.py +++ b/ci-scripts/test-sgpio-debug.py @@ -22,21 +22,39 @@ def program_device(): def capture(): - print("Capturing data...") - rx_100kB = subprocess.run(["host/build/hackrf-tools/src/hackrf_transfer", - "-r", FILENAME, "-d", "RunningFromRAM", - "-n", "50000", "-s", "20000000"], - capture_output=True, encoding="UTF-8") - print(rx_100kB.stdout) - print(rx_100kB.stderr) - print(f"Wrote capture data to file: {FILENAME}") + shortfall_count = -1 + capture_tries = 0 + + while shortfall_count != 0: + print("Capturing data...") + rx_100kB = subprocess.run(["host/build/hackrf-tools/src/hackrf_transfer", + "-r", FILENAME, "-d", "RunningFromRAM", + "-n", "50000", "-s", "20000000"], + capture_output=True, encoding="UTF-8") + print(rx_100kB.stdout) + print(rx_100kB.stderr) + print(f"Wrote capture data to file: {FILENAME}") + + debug_state_proc = subprocess.run(["host/build/hackrf-tools/src/hackrf_debug", "--state"], + capture_output=True, encoding="UTF-8") + print(debug_state_proc.stdout) + print(debug_state_proc.stderr) + capture_tries += 1 + debug_state = debug_state_proc.stdout.split("\n") + shortfalls_line = [s for s in debug_state if s.startswith("Number of shortfalls")] + shortfall_count = [int(c) for c in shortfalls_line[0].split() if c.isdigit()][0] + + if capture_tries == 10: + print("Unable to transmit data with 0 shortfalls. " \ + "This is not indicative of a device failure. " \ + "Likely an issue with the testing infrastructure.") + sys.exit(1) -def check(): +def check_bytes(): print(f"Checking length of {FILENAME}") rx_data = Path(FILENAME).read_bytes() - # file should be 100k bytes when using 50k samples - if len(rx_data) != 100000: + if len(rx_data) != 100000: # file should be 100k bytes when using 50k samples print(f"ERROR: Only {str(len(rx_data))} bytes found in file, expected 100k.") sys.exit(1) else: @@ -61,7 +79,7 @@ def check(): def main(): program_device() capture() - check() + check_bytes() if __name__ == "__main__":