Skip to content

add a test driver script#2850

Open
kilograham wants to merge 4 commits intodevelopfrom
test_driver
Open

add a test driver script#2850
kilograham wants to merge 4 commits intodevelopfrom
test_driver

Conversation

@kilograham
Copy link
Contributor

No description provided.

@kilograham kilograham added this to the 2.2.1 milestone Mar 5, 2026
@kilograham kilograham requested a review from peterharperuk March 5, 2026 21:19
@kilograham kilograham requested review from lurch and will-v-pi March 5, 2026 21:25
Comment on lines +106 to +107
# ====================== START MINICOM EARLY FOR FULL UART CAPTURE ======================
print(f" Starting minicom capture early on {args.serial_port} @ {args.baud} baud...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ====================== START MINICOM EARLY FOR FULL UART CAPTURE ======================
print(f" Starting minicom capture early on {args.serial_port} @ {args.baud} baud...")
# ====================== START GRABSERIAL EARLY FOR FULL UART CAPTURE ======================
print(f" Starting grabserial capture early on {args.serial_port} @ {args.baud} baud...")

)
print(f" grabserial started (PID {logger_proc.pid}) — capturing from now on")

# Give minicom a moment to open the port and settle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Give minicom a moment to open the port and settle
# Give grabserial a moment to open the port and settle


gdb_cmd = [
args.gdb, "--batch", "--nx", full_path,
"-ex", "target extended-remote localhost:3333",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an argument to support passing a different OpenOCD server, eg

Suggested change
"-ex", "target extended-remote localhost:3333",
"-ex", f"target extended-remote {args.openocd_server}",

Copy link
Contributor

@peterharperuk peterharperuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of this. I suggest using it is the best way to find issues.

The pico test utility still generates passes after some failures have occurred which is a bit annoying. I should push some fixes.

import signal

def main():
parser = argparse.ArgumentParser(description="RP2350 ELF test runner with OpenOCD + pyserial UART capture")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parser = argparse.ArgumentParser(description="RP2350 ELF test runner with OpenOCD + pyserial UART capture")
parser = argparse.ArgumentParser(description="RP2xxx ELF test runner with OpenOCD + grabserial UART capture")

I guess there's no reason why this wouldn't work with RP2040 too?

custom_float_funcs_test_pico_vfp.elf \
--path-postfix \
test/pico_float_test \
-- out_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth splitting this into

Suggested change
-- out_dir
--
out_dir

so that it look less like a typo of --out_dir ?


for seg in args.path_segments:
for elf in args.elf_filenames:
full_path = f"{args.path_prefix}/{seg}/{args.path_postfix}/{elf}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
full_path = f"{args.path_prefix}/{seg}/{args.path_postfix}/{elf}"
full_path = os.path.join(args.path_prefix, seg, args.path_postfix, elf)

--path-postfix is an optional arg, so using os.path.join means that you won't end up with // in the path.


args = parser.parse_args()

os.makedirs(args.output_dir, exist_ok=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it delete and then recreate output_dir, so that we don't get into a confusing state of output_dir containing both "old logs" and "new logs"? (You can use https://docs.python.org/3/library/shutil.html#shutil.rmtree for that)

continue

attempted += 1
sanitized_out_file = f"{seg}.{elf}.out".replace("/",".")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .replace("/",".") doesn't seem necessary, because the help-text for --path-segments says "(no slashes)" ? (Or does the help-text need updating?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh. but the examples at the top of this file shows that a slash is allowed in the ELF-filenames.

Comment on lines +35 to +43
Which will run the following if they exist, storing the output in out_dir/
gcc_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth clarify the style of the output filenames?

Suggested change
Which will run the following if they exist, storing the output in out_dir/
gcc_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
Which will run each of the following if they exist:
gcc_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico.elf
gcc_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_compiler.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_dcp.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf
storing their UART output in:
out_dir/gcc_build.custom_float_funcs_test_compiler.elf.out
out_dir/gcc_build.custom_float_funcs_test_pico_dcp.elf.out
out_dir/gcc_build.custom_float_funcs_test_pico.elf.out
out_dir/gcc_build.custom_float_funcs_test_pico_vfp.elf.out
out_dir/clang_build.custom_float_funcs_test_compiler.elf.out
out_dir/clang_build.custom_float_funcs_test_pico_dcp.elf.out
out_dir/clang_build.custom_float_funcs_test_pico.elf.out
out_dir/clang_build.custom_float_funcs_test_pico_vfp.elf.out

clang_build/test/pico_float_test/custom_float_funcs_test_pico.elf
clang_build/test/pico_float_test/custom_float_funcs_test_pico_vfp.elf

This would run the same tests:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This would run the same tests:
This would run the same tests:
(but store the output in e.g out_dir/gcc_build.pico_float_test.custom_float_funcs_test_compiler.elf.out )

gdb_result = subprocess.run(
gdb_cmd,
check=False,
timeout=60,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth adding an optional-argument for this timeout, in case you have a particularly long-running ELF file? 🤔

except:
pass

# ====================== CHECK LAST LINE ======================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# ====================== CHECK LAST LINE ======================
# ====================== CHECK WE CAPTURED SOME OUTPUT ======================

print(f"Error reading output file: {e}")

print("="*60 + "\n")
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
# ====================== CHECK LAST LINE ======================
try:


print("="*60 + "\n")
try:
with open(outfile, "r", encoding="utf-8", errors="ignore") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ned to open outfile as second time - you could just look at the last line of captured_content ?

Comment on lines +231 to +240
if attempted == 0:
print("No ELFs were found to test.")
sys.exit(0)

if succeeded == attempted:
print("All tests passed!")
sys.exit(0)
else:
print("Some tests failed.")
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be shortened to:

Suggested change
if attempted == 0:
print("No ELFs were found to test.")
sys.exit(0)
if succeeded == attempted:
print("All tests passed!")
sys.exit(0)
else:
print("Some tests failed.")
sys.exit(1)
if attempted == 0:
print("No ELFs were found to test.")
elif succeeded == attempted:
print("All tests passed!")
else:
print("Some tests failed.")
sys.exit(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants