Capturing logs (e.g from {% c-line %}RTT{% c-line-end %}, {% c-line %}UART{% c-line-end %}, {% c-line %}BLE{% c-line-end %}, {% c-line %}MQTT{% c-line-end %}, etc) from an embedded device typically requires streaming the logs to a {% c-line %}stdout{% c-line-end %} that a test script can read from. When doing on-target testing (i.e. testing on actual hardware) in a GitHub Actions workflow, it can be a bit tricky to capture those logs. Fortunately, the Lager API makes grabbing device logs extremely easy.
Below is a snippet of python code for capturing {% c-line %}RTT{% c-line-end %} logs from a nRF52833 MCU.
{% c-block language="python" %}
import time
from lager import lager
timeout_sec = 42
dut = lager.DUT() # create DUT object
dut.disconnect() #disconnect SWD debugger from DUT
dut.connect() #connect SWD debugger to DUT
with lager.RTT() as rtt:
dut.reset(halt=False)
start_time = time.time()
while time.time() - start_time < timeout_sec:
line = rtt.read_line(timeout=1).decode().strip()
print(line)
{% c-block-end %}
This will read the {% c-line %}RTT{% c-line-end %} logs and print them inside the GH Actions container this script is running in. You could also save the logs to a file, push the logs to a S3 bucket, etc.
Then in your {% c-line %}workflow.yaml{% c-line-end %} file you call:
{% c-block language="yaml" %}
- name: My Test
run: |
lager python test.py
{% c-block-end %}
Now, whenever this workflow gets called, you can see the logs being output.
Reach out to learn more about Lager's hardware test automation platform.
Try One Month Free
hello@lagerdata.com