Skip to content

Commit

Permalink
pytest: Add new test for CP/PD status reports
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Oct 9, 2023
1 parent fd65523 commit 20c4eac
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/pytest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Run Tests

`make check` on cmake builds will invoke pytest correctly. During development,
it might be useful to run an individual test (instead of everything). To do so,

```
PYTHONPATH=../../build/python/ python3 -m pytest -vv -s test_events.py::test_event_input
```
68 changes: 68 additions & 0 deletions tests/pytest/test_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Copyright (c) 2023 Siddharth Chandrasekaran <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

import time
import pytest

from testlib import *

pd_cap = PDCapabilities([
(Capability.OutputControl, 1, 1),
(Capability.LEDControl, 1, 1),
(Capability.AudibleControl, 1, 1),
(Capability.TextOutput, 1, 1),
])

pd_info = [
PDInfo(101, scbk=KeyStore.gen_key(), name='chn-0'),
]

# TODO remove this.
pd_addr = pd_info[0].address
pd = PeripheralDevice(pd_info[0], pd_cap, log_level=LogLevel.Debug)
cp = ControlPanel(pd_info)

@pytest.fixture(scope='module', autouse=True)
def setup_test():
pd.start()
cp.start()
cp.sc_wait_all()
yield
teardown_test()

def teardown_test():
cp.teardown()
pd.teardown()

def test_cp_status():
assert cp.online_wait(pd.address)
pd.stop()
assert cp.online_wait(pd.address) == False
pd.start()
assert cp.online_wait(pd.address)

def test_cp_sc_status():
assert cp.sc_wait(pd.address)
pd.stop()
assert cp.sc_wait(pd.address) == False
pd.start()
assert cp.sc_wait(pd.address)

def test_pd_status():
cp.stop()
time.sleep(1)
assert pd.is_online() == False
cp.start()
assert cp.sc_wait(pd.address)
assert pd.is_online()

def test_pd_sc_status():
cp.stop()
time.sleep(1)
assert pd.is_sc_active() == False
cp.start()
assert cp.sc_wait(pd.address)
assert pd.is_sc_active()

0 comments on commit 20c4eac

Please sign in to comment.