Skip to content

Commit

Permalink
button press test
Browse files Browse the repository at this point in the history
  • Loading branch information
charles37 committed Oct 31, 2024
1 parent 6c0092c commit 1b9280b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/treadmill-ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hwci/tests/button_print.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
50 changes: 50 additions & 0 deletions hwci/tests/button_print_should_fail.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1b9280b

Please sign in to comment.