1# Copyright (c) 2024 Meta Platforms 2# SPDX-License-Identifier: Apache-2.0 3 4import logging 5 6from twister_harness import Shell 7 8logger = logging.getLogger(__name__) 9 10 11def test_sensor_shell_info(shell: Shell): 12 logger.info('send "sensor info" command') 13 14 lines = shell.exec_command('sensor info') 15 assert any(['device name: sensor@0' in line for line in lines]), 'expected response not found' 16 assert any(['device name: sensor@1' in line for line in lines]), 'expected response not found' 17 18 logger.info('response is valid') 19 20 21def test_sensor_shell_get(shell: Shell): 22 logger.info('send "sensor get" command') 23 24 # Channel should be the last one before 'all' (because 'all' doesn't print anything) so that the 25 # for-loop in `parse_named_int()` will go through everything 26 for channel in range(59): 27 logger.info(f'channel {channel}') 28 lines = shell.exec_command(f'sensor get sensor@0 {channel}') 29 assert any([f'channel type={channel}' in line for line in lines]), 'expected response not found' 30 31 logger.info('response is valid') 32 33 34def test_sensor_shell_attr_get(shell: Shell): 35 logger.info('send "sensor attr_get" command') 36 37 lines = shell.exec_command('sensor attr_get sensor@0 co2 sampling_frequency') 38 assert any(['sensor@0(channel=co2, attr=sampling_frequency)' in line for line in lines]), 'expected response not found' 39 40 lines = shell.exec_command('sensor attr_get sensor@1 54 3') 41 assert any(['sensor@1(channel=gauge_state_of_health, attr=slope_th)' in line for line in lines]), 'expected response not found' 42 43 logger.info('response is valid') 44 45 46def test_sensor_shell_attr_set(shell: Shell): 47 logger.info('send "sensor attr_set" command') 48 49 lines = shell.exec_command('sensor attr_set sensor@0 co2 sampling_frequency 1') 50 expected_line = 'sensor@0 channel=co2, attr=sampling_frequency set to value=1' 51 assert any([expected_line in line for line in lines]), 'expected response not found' 52 53 lines = shell.exec_command('sensor attr_set sensor@1 54 3 1') 54 expected_line = 'sensor@1 channel=gauge_state_of_health, attr=slope_th set to value=1' 55 assert any([expected_line in line for line in lines]), 'expected response not found' 56 57 logger.info('response is valid') 58 59 60def test_sensor_shell_trig(shell: Shell): 61 logger.info('send "sensor trig" command') 62 63 lines = shell.exec_command('sensor trig sensor@0 on data_ready') 64 expected_line = 'Enabled trigger idx=1 data_ready on device sensor@0' 65 assert any([expected_line in line for line in lines]), 'expected response not found' 66 67 lines = shell.exec_command('sensor trig sensor@0 off data_ready') 68 expected_line = 'Disabled trigger idx=1 data_ready on device sensor@0' 69 assert any([expected_line in line for line in lines]), 'expected response not found' 70 71 logger.info('response is valid') 72