Skip to content

Commit

Permalink
Fix suggestions from Patrick and Rick
Browse files Browse the repository at this point in the history
  • Loading branch information
LiaoU3 committed Mar 15, 2024
1 parent 8eb1560 commit b4454b8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 88 deletions.
67 changes: 0 additions & 67 deletions contrib/checkbox-provider-ce-oem/bin/serial_console_test.py

This file was deleted.

35 changes: 32 additions & 3 deletions contrib/checkbox-provider-ce-oem/bin/serial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def serial_init(self, node: str) -> serial.Serial:
def send(self, data: bytes) -> None:
try:
self.ser.write(data)
logging.info("Sent: {}".format(data.hex()))
logging.info("Sent: {}".format(data.decode()))
except Exception:
logging.exception("Not able to send data!")

Expand All @@ -106,7 +106,7 @@ def recv(self) -> bytes:
self.ser.rts = False
rcv = self.ser.read(self.data_size)
if rcv:
logging.info("Received: {}".format(rcv.hex()))
logging.info("Received: {}".format(rcv.decode()))
except Exception:
logging.exception("Received unmanageable string format")
raise SystemExit(1)
Expand Down Expand Up @@ -157,14 +157,41 @@ def client_mode(ser: Serial, data_size: int = 128):
raise SystemExit(1)


def console_mode(ser: Serial):
"""
Test the serial port when it is in console mode
This test requires DUT to loop back it self.
For example: connect the serial console port to the USB port via
serial to usb dongle
"""
try:
# Send 'Enter Key'
logging.info("Sending 'Enter Key'...")
ser.send(os.linesep.encode())
response = ser.recv().decode()
# ":~$" is the pattern for the DUT after logging in
# "login:" is the pattern for the DUT before logging in
if ":~$" in response or "login:" in response:
logging.info("[PASS] Serial console test successful.")
else:
logging.info("[FAIL] Serial console test failed.")
logging.info(
"Expected response should contain ':~$' or 'login:'"
)
raise SystemExit(1)
except Exception:
logging.exception("Caught an exception.")
raise SystemExit(1)


def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("node", help="Serial port device node e.g. /dev/ttyS1")
parser.add_argument(
"--mode",
choices=["server", "client"],
choices=["server", "client", "console"],
type=str,
help="Running mode",
required=True,
Expand Down Expand Up @@ -238,6 +265,8 @@ def main():
server_mode(ser)
elif args.mode == "client":
client_mode(ser, data_size=args.datasize)
elif args.mode == "console":
console_mode(ser)
else:
raise SystemExit(1)

Expand Down
26 changes: 8 additions & 18 deletions contrib/checkbox-provider-ce-oem/units/serial/jobs.pxu
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,17 @@ command:
if [ -z "$SERIAL_CONSOLE_PORTS" ]; then
exit 0
fi
pairs=($SERIAL_CONSOLE_PORTS)
for pair in "${pairs[@]}"; do
IFS=':' read -r -a pair_array <<< "$pair"
type="${pair_array[0]}"
node="${pair_array[1]}"
baudrate="${pair_array[2]}"
echo "type: $type"
echo "node: $node"
echo "baudrate: $baudrate"
echo ""
done
serial_config_parser.py "$SERIAL_CONSOLE_PORTS"

unit: template
template-resource: ce-oem-serial/serial-console-list
template-unit: job
template-engine: jinja2
template-id: ce-oem-serial/serial-console-tests
id: ce-oem-serial/serial-console-{{ type }}-{{ node }}-{{ baudrate }}
# imports: from com.canonical.plainbox import manifest
# requires:
# manifest.has_serial_console_loopback == True
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_serial_console_loopback == True
template-summary: To check if the serial ports can work as a console
_summary: To check if the serial port {{ type }} ({{ node }}) can work as a console
_purpose:
Expand All @@ -49,7 +39,7 @@ category_id: com.canonical.certification::serial
estimated_duration: 30
flags: also-after-suspend
command:
serial_console_test.py -d {{ node }} -b {{ baudrate }}
serial_test.py {{ node }} --mode console --type {{ type }} --baudrate {{ baudrate }}

id: ce-oem-serial/serial-list
_summary:
Expand All @@ -76,9 +66,9 @@ template-unit: job
template-engine: jinja2
template-id: ce-oem-serial/serial-transmit-data-tests
id: ce-oem-serial/serial-transmit-data-{{ type }}-{{ node }}-{{ baudrate }}
# imports: from com.canonical.plainbox import manifest
# requires:
# manifest.has_serial_ehco_server == True
imports: from com.canonical.plainbox import manifest
requires:
manifest.has_serial_ehco_server == True
template-summary:
Transmit data via {{ type }} ({{ node }}) with baudate {{ baudrate }}
_purpose:
Expand Down

0 comments on commit b4454b8

Please sign in to comment.