katnip.monitors.serial module

class katnip.monitors.serial.SerialMonitor(name, dev_name=None, baudrate=115200, capture_dir='.', logger=None)

Bases: kitty.monitors.base.BaseMonitor

SerialMonitor monitors the output of a serial connection by looking for a pattern in the serial output.

This monitor captures all the received data from the serial, but it is also able to detect successful/failed tests by looking for specific patterns in the serial output.

Note

The monitor can work either with a success pattern (failure if pattern was not found) or with a failure pattern (success if pattern was not found)

Examples:

Setting a monitor that will fail a test if a line that contains “stack smashing detected” appears in the serial

monitor = SerialMonitor('detect smash monitor', '/dev/ttyUSB0', capture_dir='serial_caps')
monitor.set_failure_pattern('stack smashing detected')

Setting a monitor that will fail a test if a line that contains either “reboot” or “restart” appears on the serial (utilizing regex)

monitor = SerialMonitor('detect reboot monitor', '/dev/ttyUSB0', capture_dir='serial_caps')
monitor.set_failure_pattern('(reboot)|(restart)')
__init__(name, dev_name=None, baudrate=115200, capture_dir='.', logger=None)
Parameters:
  • name – name of the monitor object
  • dev_name – serial device
  • baudrate – serial baudrate
  • capture_dir – where to store the captured serial output
  • logger – logger for the monitor object
add_failure_pattern(failure_pattern)

Set a pattern that declares the test as failed if received

Parameters:failure_pattern (str) – regular expression pattern of output that signifies failure (e.g. potential bug there)
add_pattern_callback(pattern, cb)

Add a pattern to search for on the serial output, and the callback that will be called when the pattern is found.

Parameters:
  • pattern (str) – regular expression pattern to be searched for in the serial output
  • cb (callable) – the callback to be called when pattern is found; must accept 3 params: (1) a SerialMonitor instance (2) the matching line (3) the re match object of the found match
add_success_pattern(success_pattern)

Set a pattern that declares the test successful if received

Parameters:success_pattern (str) – regular expression pattern of output that signifies success (e.g. no bug there)
close_fd()
post_test()
pre_test(test_number)
set_failure_pattern(failure_pattern)
set_success_pattern(success_pattern)
setup()
teardown()