From 1b9280b269ae9f28ef062cae7cd82e6c26d4c937 Mon Sep 17 00:00:00 2001 From: charles37 Date: Thu, 31 Oct 2024 16:11:42 -0400 Subject: [PATCH] button press test --- .github/workflows/treadmill-ci-test.yml | 1 + hwci/tests/button_print.py | 2 +- hwci/tests/button_print_should_fail.py | 50 +++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 hwci/tests/button_print_should_fail.py diff --git a/.github/workflows/treadmill-ci-test.yml b/.github/workflows/treadmill-ci-test.yml index 450ea23..55594b7 100644 --- a/.github/workflows/treadmill-ci-test.yml +++ b/.github/workflows/treadmill-ci-test.yml @@ -51,6 +51,7 @@ jobs: tests/c_hello. tests/mpu_walk_region.py tests/button_print.py + tests/button_print_should_fail.py # tests: | # tests/ble_env_sense.py diff --git a/hwci/tests/button_print.py b/hwci/tests/button_print.py index b945314..a316049 100644 --- a/hwci/tests/button_print.py +++ b/hwci/tests/button_print.py @@ -1,4 +1,4 @@ -# hwci/tests/button_press_test.py +# hwci/tests/button_print.py # Licensed under the Apache License, Version 2.0 or the MIT License. # SPDX-License-Identifier: Apache-2.0 OR MIT diff --git a/hwci/tests/button_print_should_fail.py b/hwci/tests/button_print_should_fail.py new file mode 100644 index 0000000..3f5e1e1 --- /dev/null +++ b/hwci/tests/button_print_should_fail.py @@ -0,0 +1,50 @@ +# hwci/tests/button_print_should_fail.py + +# Licensed under the Apache License, Version 2.0 or the MIT License. +# SPDX-License-Identifier: Apache-2.0 OR MIT +# Copyright Tock Contributors 2024. + +import logging +from utils.test_helpers import OneshotTest + + +class ButtonPressTest(OneshotTest): + def __init__(self): + super().__init__(apps=["tests/button_print"]) + + def oneshot_test(self, board): + gpio = board.gpio + serial = board.serial + + button_pin = gpio.pin("P0.11") + # Set the pin as output to simulate button press (active low) + button_pin.set_mode("output") + button_pin.write(1) # Ensure button is not pressed initially + + # Start the test + logging.info("Starting Button Press Test") + + # Wait for initial message + output = serial.expect(r"\[TEST\] Button Press", timeout=10) + if not output: + raise Exception("Did not receive expected test start message") + + # Simulate button press + button_pin.write(0) # Active low, so writing 0 simulates press + logging.info("Button pressed (simulated)") + + # Wait for the expected output + output = serial.expect(r"Button Press! Button: 1 Status: 1", timeout=5) + if not output: + raise Exception("Did not receive expected button press message") + + logging.info("Button press message received") + + # Release button + button_pin.write(1) + logging.info("Button released (simulated)") + + logging.info("Button Press Test completed successfully") + + +test = ButtonPressTest()