Skip to content

Commit

Permalink
FIXUP - small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Oct 29, 2024
1 parent 46981d6 commit 60ae005
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions tools/run_functional_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datetime
import logging
import re
import shutil
import sys
import subprocess
import time
Expand All @@ -36,6 +37,17 @@
)


def check_external_tools():
"""
Ensure that required external tools are available.
"""
required_tools = ["openocd", "st-flash"]
missing_tools = [tool for tool in required_tools if not shutil.which(tool)]
if missing_tools:
logging.error(f"Missing required tools: {', '.join(missing_tools)}")
sys.exit(1)


def valid_file(arg: str) -> Path:
"""
Validate that the provided file exists and has the correct extension.
Expand Down Expand Up @@ -97,8 +109,8 @@ def generate_result_file(self):
self.result_filepath.touch(exist_ok=False)
logging.debug(f"Created result file at {self.result_filepath}")
except OSError as e:
logging.error(f"Could not create or open file: {self.result_filepath}")
logging.error(f"Error: {e}")
logging.exception(f"Could not create or open file: {self.result_filepath}")
logging.exception(f"Error: {e}")
sys.exit(1)

def edit_result_file(self, data: str):
Expand All @@ -110,8 +122,8 @@ def edit_result_file(self, data: str):
file.write(data)
logging.debug(f"Appended data to {self.result_filepath}")
except OSError as e:
logging.error(f"Could not write to file: {self.result_filepath}")
logging.error(f"Error: {e}")
logging.exception(f"Could not write to file: {self.result_filepath}")
logging.exception(f"Error: {e}")
sys.exit(1)

def flash(self) -> bool:
Expand Down Expand Up @@ -243,6 +255,18 @@ def check_status(self) -> bool:
logging.error(f"The file: {self.result_filepath} doesn't exist")
sys.exit(1)

def print_result_file(self):
"""
Print the contents of the result file.
"""
try:
with self.result_filepath.open("r") as file:
content = file.read()
print(content)
except OSError as e:
logging.error(f"Could not read file: {self.result_filepath}")
logging.error(f"Error: {e}")


def erase_flash():
"""
Expand Down Expand Up @@ -311,6 +335,13 @@ def parse_arguments() -> argparse.Namespace:
"--all", action="store_true", help="Select all binary executables"
)

parser.add_argument(
"-v",
"--verbose",
action="store_true",
help="Enable verbose (debug) logging",
)

return parser.parse_args()


Expand All @@ -320,6 +351,14 @@ def main() -> int:
"""
args = parse_arguments()

# Set logging level based on verbose flag
if args.verbose:
logging.getLogger().setLevel(logging.DEBUG)
logging.debug("Verbose logging enabled.")

# Check for required external tools
check_external_tools()

# Determine which binary files to use
if args.all:
bin_files = list_bin_files()
Expand Down

0 comments on commit 60ae005

Please sign in to comment.