Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b81cf80
tests: Extend test framework for driverless board qualification scena…
nedseb Mar 13, 2026
bc70f05
tests: Add hardware marker and guard board scenarios against driver a…
nedseb Mar 13, 2026
222efc2
tests: Add board qualification tests for user pins.
nedseb Mar 13, 2026
9679596
tests: Clarify pin tests as smoke tests and simplify ADC assertions.
nedseb Mar 13, 2026
6ad9b3a
tests: Skip printing bare boolean results in test output.
nedseb Mar 13, 2026
4922d57
tests: Return raw values in pin tests for visual control.
nedseb Mar 13, 2026
bd31220
tests: Add board qualification tests for buzzer.
nedseb Mar 13, 2026
88d4474
tests: Fix buzzer tests to use pyb.Timer instead of machine.PWM.
nedseb Mar 13, 2026
7223472
tests: Fix buzzer sweep timing and remove double initial note.
nedseb Mar 13, 2026
0569351
tests: Add Ode to Joy melody test for buzzer qualification.
nedseb Mar 13, 2026
c3c4578
tests: Add board qualification tests for A/B/Menu buttons.
nedseb Mar 13, 2026
84c12e4
tests: Add released-state check and use wait false for button tests.
nedseb Mar 13, 2026
2d80e7b
tests: Add interrupt tests and rename existing to polling for buttons.
nedseb Mar 13, 2026
0aaac6b
tests: Add D-PAD buttons and timeout on release-wait loops.
nedseb Mar 13, 2026
273e2bb
tests: Add board qualification tests for user LEDs.
nedseb Mar 13, 2026
6cc9cf9
tests: Add pre_prompt to LED tests and align white duration.
nedseb Mar 13, 2026
d57c678
tests: Remove unnecessary pre_prompt pauses between LED tests.
nedseb Mar 13, 2026
2f1d107
tests: Rephrase pre_prompt to clarify Enter starts the test.
nedseb Mar 13, 2026
89cb612
tests: Add board qualification test for I2C bus scan.
nedseb Mar 13, 2026
f38ec8c
tests: Return missing/unexpected addresses for better diagnostics.
nedseb Mar 13, 2026
fbc2643
tests: Fix I2C scan addresses and add WHO_AM_I checks per device.
nedseb Mar 13, 2026
b0699ff
tests: Add LIS2MDL to expected I2C addresses list.
nedseb Mar 13, 2026
dcd9d67
tests: Release MCP23009E from reset before D-PAD button tests.
nedseb Mar 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def pytest_configure(config):
config.addinivalue_line("markers", "mock: tests that run with FakeI2C (no hardware)")
config.addinivalue_line("markers", "hardware: tests that require a real board")
config.addinivalue_line("markers", "manual: tests that require human validation")
config.addinivalue_line("markers", "board: board qualification tests (no driver, hardware only)")


def pytest_collection_modifyitems(config, items):
Expand Down
15 changes: 15 additions & 0 deletions tests/runner/mpremote_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ def run_script(
last_line = output.strip().rsplit("\n", 1)[-1]
return json.loads(last_line)

def run_raw_script(self, script):
"""Run a raw MicroPython script on the board without driver context.

The script must set a ``result`` variable. Returns the
JSON-decoded value of ``result``.
"""
code = (
f"import json\n"
f"{script}\n"
f"print(json.dumps(result))"
)
output = self._run(code)
last_line = output.strip().rsplit("\n", 1)[-1]
return json.loads(last_line)

def scan_bus(self, i2c_config):
"""Scan I2C bus and return list of addresses."""
i2c_init = _i2c_init_code(i2c_config)
Expand Down
287 changes: 287 additions & 0 deletions tests/scenarios/board_buttons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
type: board
name: "board_buttons"

# --- Polling tests (one per button) ---
# LED_GREEN signals when the board is ready to read the button.

tests:
- name: "Button A press (polling)"
action: hardware_script
pre_prompt: "Test polling boutons : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par A."
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("A_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button B press (polling)"
action: hardware_script
pre_prompt: "Bouton B"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("B_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button MENU press (polling)"
action: hardware_script
pre_prompt: "Bouton MENU"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("MENU_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

# --- D-PAD buttons via MCP23009E (I2C 0x20, GPIO register 0x09) ---
# Read directly via I2C without importing the driver.
# Bit mapping: UP=bit7, DOWN=bit5, LEFT=bit6, RIGHT=bit4.

- name: "D-PAD UP press (polling)"
action: hardware_script
pre_prompt: "Test polling D-PAD : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP."
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
# Release MCP23009E from reset
rst = Pin("RST_EXPANDER", Pin.OUT)
rst.on()
sleep_ms(10)
led = Pin("LED_GREEN", Pin.OUT)
Comment thread
nedseb marked this conversation as resolved.
i2c = I2C(1)
bit = 7
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD DOWN press (polling)"
action: hardware_script
pre_prompt: "Bouton DOWN"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 5
led.on()
Comment thread
nedseb marked this conversation as resolved.
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD LEFT press (polling)"
action: hardware_script
pre_prompt: "Bouton LEFT"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 6
led.on()
Comment thread
nedseb marked this conversation as resolved.
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD RIGHT press (polling)"
action: hardware_script
pre_prompt: "Bouton RIGHT"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 4
led.on()
Comment thread
nedseb marked this conversation as resolved.
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

# --- Interrupt tests (GPIO direct buttons) ---
# LED_GREEN signals when the board is ready; uses Pin.irq() to detect press.

- name: "Button A press (interrupt)"
action: hardware_script
pre_prompt: "Test interrupt boutons : appuyez brièvement sur chaque bouton quand la LED verte s'allume (5s). Commençons par A."
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("A_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button B press (interrupt)"
action: hardware_script
pre_prompt: "Bouton B"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("B_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button MENU press (interrupt)"
action: hardware_script
pre_prompt: "Bouton MENU"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("MENU_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]
Loading
Loading