Skip to content

Commit

Permalink
Removed stm monitor, as it's now part of docker-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ssecsd committed Dec 19, 2024
1 parent 6c6ac7d commit 07a42d7
Showing 1 changed file with 0 additions and 71 deletions.
71 changes: 0 additions & 71 deletions scripts/testops.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,14 @@
#!/usr/bin/env python3
import re
import threading
import time
from datetime import datetime
from queue import Queue
from typing import Optional

import serial
from flipper.app import App
from flipper.storage import FlipperStorage
from flipper.utils.cdc import resolve_port


class SerialMonitor:
def __init__(self, port, baudrate=230400):
self.port = port
self.baudrate = baudrate
self.output = []
self.running = False
self.serial = None
self.thread = None
self.queue = Queue()

def start(self):
try:
self.serial = serial.Serial(self.port, self.baudrate, timeout=1)
self.running = True
self.thread = threading.Thread(target=self._read_serial)
self.thread.daemon = True
self.thread.start()
except serial.SerialException as e:
raise RuntimeError(f"Failed to open serial port {self.port}: {e}")

def stop(self):
self.running = False
if self.thread:
self.thread.join(timeout=1)
if self.serial:
self.serial.close()

def _read_serial(self):
while self.running:
try:
if self.serial.in_waiting:
line = self.serial.readline().decode("utf-8", errors="replace")
if line:
line = re.sub(r"[\x00-\x1F\x7F-\x9F]", "", line)
datetime_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")
line = f"{datetime_str} {line} \n"
self.output.append(line)
self.queue.put(line)
except Exception as e:
self.queue.put(f"Error reading serial: {e}")
break

def get_output(self):
return "".join(self.output)


class Main(App):
def __init__(self, no_exit=False):
super().__init__(no_exit)
Expand All @@ -68,9 +19,6 @@ def init(self):
self.parser.add_argument(
"-t", "--timeout", help="Timeout in seconds", type=int, default=10
)
self.parser.add_argument(
"-s", "--stm-port", help="Additional STM32 Serial Port", default=None
)

self.subparsers = self.parser.add_subparsers(help="sub-command help")

Expand Down Expand Up @@ -118,17 +66,6 @@ def run_units(self):
if not (flipper := self._get_flipper(retry_count=10)):
return 1

stm_monitor = None
if self.args.stm_port:
try:
stm_monitor = SerialMonitor(self.args.stm_port)
stm_monitor.start()
self.logger.info(f"Started monitoring STM32 port: {self.args.stm_port}")
except Exception as e:
self.logger.error(f"Failed to start STM32 monitoring: {e}")
flipper.stop()
return 1

self.logger.info("Running unit tests")
flipper.send("unit_tests" + "\r")
self.logger.info("Waiting for unit tests to complete")
Expand Down Expand Up @@ -215,12 +152,6 @@ def run_units(self):
with open(output_file, "w") as f:
f.write(test_results["full_output"])

if stm_monitor:
test_results["stm_output"] = stm_monitor.get_output()
stm_output_file = "unit_tests_stm_output.txt"
with open(stm_output_file, "w") as f:
f.write(test_results["stm_output"])

print(
f"::notice:: Total tests: {total} Failed tests: {tests} Status: {status} Elapsed time: {elapsed_time / 1000} s Memory leak: {leak} bytes"
)
Expand All @@ -239,8 +170,6 @@ def run_units(self):
return 0

finally:
if stm_monitor:
stm_monitor.stop()
flipper.stop()


Expand Down

0 comments on commit 07a42d7

Please sign in to comment.