Skip to content

Commit 212526b

Browse files
tpamborkartben
authored andcommitted
samples: sensor_shell: Wait for prompt before sending command
Cherry picking 7c0e4ae from main branch to ensure test correctly runs in CI. Wait for prompt before sending command to ensure shell is ready. Signed-off-by: Tim Pambor <[email protected]>
1 parent 9c83a8a commit 212526b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

samples/sensor/sensor_shell/pytest/test_sensor_shell.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
def test_sensor_shell_info(shell: Shell):
1212
logger.info('send "sensor info" command')
1313

14+
shell.wait_for_prompt()
1415
lines = shell.exec_command('sensor info')
1516
assert any(['device name: sensor@0' in line for line in lines]), 'expected response not found'
1617
assert any(['device name: sensor@1' in line for line in lines]), 'expected response not found'
@@ -25,6 +26,7 @@ def test_sensor_shell_get(shell: Shell):
2526
# for-loop in `parse_named_int()` will go through everything
2627
for channel in range(59):
2728
logger.info(f'channel {channel}')
29+
shell.wait_for_prompt()
2830
lines = shell.exec_command(f'sensor get sensor@0 {channel}')
2931
assert any([f'channel type={channel}' in line for line in lines]), 'expected response not found'
3032

@@ -34,9 +36,11 @@ def test_sensor_shell_get(shell: Shell):
3436
def test_sensor_shell_attr_get(shell: Shell):
3537
logger.info('send "sensor attr_get" command')
3638

39+
shell.wait_for_prompt()
3740
lines = shell.exec_command('sensor attr_get sensor@0 co2 sampling_frequency')
3841
assert any(['sensor@0(channel=co2, attr=sampling_frequency)' in line for line in lines]), 'expected response not found'
3942

43+
shell.wait_for_prompt()
4044
lines = shell.exec_command('sensor attr_get sensor@1 54 3')
4145
assert any(['sensor@1(channel=gauge_state_of_health, attr=slope_th)' in line for line in lines]), 'expected response not found'
4246

@@ -46,10 +50,12 @@ def test_sensor_shell_attr_get(shell: Shell):
4650
def test_sensor_shell_attr_set(shell: Shell):
4751
logger.info('send "sensor attr_set" command')
4852

53+
shell.wait_for_prompt()
4954
lines = shell.exec_command('sensor attr_set sensor@0 co2 sampling_frequency 1')
5055
expected_line = 'sensor@0 channel=co2, attr=sampling_frequency set to value=1'
5156
assert any([expected_line in line for line in lines]), 'expected response not found'
5257

58+
shell.wait_for_prompt()
5359
lines = shell.exec_command('sensor attr_set sensor@1 54 3 1')
5460
expected_line = 'sensor@1 channel=gauge_state_of_health, attr=slope_th set to value=1'
5561
assert any([expected_line in line for line in lines]), 'expected response not found'
@@ -60,10 +66,12 @@ def test_sensor_shell_attr_set(shell: Shell):
6066
def test_sensor_shell_trig(shell: Shell):
6167
logger.info('send "sensor trig" command')
6268

69+
shell.wait_for_prompt()
6370
lines = shell.exec_command('sensor trig sensor@0 on data_ready')
6471
expected_line = 'Enabled trigger idx=1 data_ready on device sensor@0'
6572
assert any([expected_line in line for line in lines]), 'expected response not found'
6673

74+
shell.wait_for_prompt()
6775
lines = shell.exec_command('sensor trig sensor@0 off data_ready')
6876
expected_line = 'Disabled trigger idx=1 data_ready on device sensor@0'
6977
assert any([expected_line in line for line in lines]), 'expected response not found'

0 commit comments

Comments
 (0)