samples: sensor: sensor_shell: add pytest
Use pytest to test the shell commands. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
d462ed4d95
commit
46ed467339
2 changed files with 84 additions and 1 deletions
70
samples/sensor/sensor_shell/pytest/test_sensor_shell.py
Normal file
70
samples/sensor/sensor_shell/pytest/test_sensor_shell.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Copyright (c) 2024 Meta Platforms
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import logging
|
||||
|
||||
from twister_harness import Shell
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_sensor_shell_info(shell: Shell):
|
||||
logger.info('send "sensor info" command')
|
||||
|
||||
lines = shell.exec_command('sensor info')
|
||||
assert any(['device name: sensor@0' in line for line in lines]), 'expected response not found'
|
||||
assert any(['device name: sensor@1' in line for line in lines]), 'expected response not found'
|
||||
|
||||
logger.info('response is valid')
|
||||
|
||||
|
||||
def test_sensor_shell_get(shell: Shell):
|
||||
logger.info('send "sensor get" command')
|
||||
|
||||
lines = shell.exec_command('sensor get sensor@0 voltage')
|
||||
assert any(['channel type=31(voltage)' in line for line in lines]), 'expected response not found'
|
||||
|
||||
lines = shell.exec_command('sensor get sensor@1 53')
|
||||
assert any(['channel type=53(gauge_time_to_empty)' in line for line in lines]), 'expected response not found'
|
||||
|
||||
logger.info('response is valid')
|
||||
|
||||
|
||||
def test_sensor_shell_attr_get(shell: Shell):
|
||||
logger.info('send "sensor attr_get" command')
|
||||
|
||||
lines = shell.exec_command('sensor attr_get sensor@0 co2 sampling_frequency')
|
||||
assert any(['sensor@0(channel=co2, attr=sampling_frequency)' in line for line in lines]), 'expected response not found'
|
||||
|
||||
lines = shell.exec_command('sensor attr_get sensor@1 53 3')
|
||||
assert any(['sensor@1(channel=gauge_time_to_empty, attr=slope_th)' in line for line in lines]), 'expected response not found'
|
||||
|
||||
logger.info('response is valid')
|
||||
|
||||
|
||||
def test_sensor_shell_attr_set(shell: Shell):
|
||||
logger.info('send "sensor attr_set" command')
|
||||
|
||||
lines = shell.exec_command('sensor attr_set sensor@0 co2 sampling_frequency 1')
|
||||
expected_line = 'sensor@0 channel=co2, attr=sampling_frequency set to value=1'
|
||||
assert any([expected_line in line for line in lines]), 'expected response not found'
|
||||
|
||||
lines = shell.exec_command('sensor attr_set sensor@1 53 3 1')
|
||||
expected_line = 'sensor@1 channel=gauge_time_to_empty, attr=slope_th set to value=1'
|
||||
assert any([expected_line in line for line in lines]), 'expected response not found'
|
||||
|
||||
logger.info('response is valid')
|
||||
|
||||
|
||||
def test_sensor_shell_trig(shell: Shell):
|
||||
logger.info('send "sensor trig" command')
|
||||
|
||||
lines = shell.exec_command('sensor trig sensor@0 on data_ready')
|
||||
expected_line = 'Enabled trigger idx=1 data_ready on device sensor@0'
|
||||
assert any([expected_line in line for line in lines]), 'expected response not found'
|
||||
|
||||
lines = shell.exec_command('sensor trig sensor@0 off data_ready')
|
||||
expected_line = 'Disabled trigger idx=1 data_ready on device sensor@0'
|
||||
assert any([expected_line in line for line in lines]), 'expected response not found'
|
||||
|
||||
logger.info('response is valid')
|
|
@ -1,5 +1,10 @@
|
|||
sample:
|
||||
name: Shell Sensor Module Sample
|
||||
common:
|
||||
tags:
|
||||
- sensor
|
||||
- shell
|
||||
|
||||
tests:
|
||||
sample.sensor.shell:
|
||||
integration_platforms:
|
||||
|
@ -7,7 +12,15 @@ tests:
|
|||
# TODO Remove once #63414 is resolved
|
||||
platform_exclude: gd32l233r_eval
|
||||
filter: ( CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_INTERRUPT )
|
||||
tags: shell
|
||||
harness: keyboard
|
||||
min_ram: 20
|
||||
min_flash: 33
|
||||
sample.sensor.shell.pytest:
|
||||
filter: CONFIG_SERIAL and dt_chosen_enabled("zephyr,shell-uart")
|
||||
min_ram: 40
|
||||
harness: pytest
|
||||
extra_configs:
|
||||
- arch:posix:CONFIG_NATIVE_UART_0_ON_STDINOUT=y
|
||||
- CONFIG_SAMPLES_SENSOR_SHELL_FAKE_SENSOR=y
|
||||
integration_platforms:
|
||||
- native_sim
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue