zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
9.91k stars 6.1k forks source link

samples: sensor_shell: add fake sensor driver & pytest #72833

Closed ycsin closed 3 weeks ago

ycsin commented 4 weeks ago

Add a fake sensor driver so that the sample can be played with in a more meaningful way.

Then, use pytest to test the shell commands.

Sample doc preview

ycsin commented 3 weeks ago

Updated the fake driver to handle 3-axis data properly:

uart:~$ sensor get sensor@0 4
channel idx=7 gyro_xyz shift=0 num_samples=0 value=4294967295ns, (-0.000000, -0.000000, -0.000000)
[870:26:48.134,000] <inf> fake_sensor: [sample_fetch] dev: 0x8000e2b8, chan: 59
[870:26:48.134,000] <inf> fake_sensor: [channel_get] dev: 0x8000e2b8, chan: 4
uart:~$ sensor get sensor@0 7
channel idx=7 gyro_xyz shift=3 num_samples=1 value=9220133425350000000ns, (7.000000, 7.000000, 7.000000)
[870:26:48.134,000] <inf> fake_sensor: [sample_fetch] dev: 0x8000e2b8, chan: 59
[870:26:48.134,000] <inf> fake_sensor: [channel_get] dev: 0x8000e2b8, chan: 7
uart:~$ sensor get sensor@0 11
channel idx=11 magn_xyz shift=4 num_samples=1 value=9220133425350000000ns, (11.000000, 11.000000, 11.000000)
[870:26:48.134,000] <inf> fake_sensor: [sample_fetch] dev: 0x8000e2b8, chan: 59
[870:26:48.134,000] <inf> fake_sensor: [channel_get] dev: 0x8000e2b8, chan: 11
uart:~$ sensor get sensor@0 12
channel idx=12 die_temp shift=4 num_samples=1 value=9220133425350000000ns (12.000000)
[870:26:48.134,000] <inf> fake_sensor: [sample_fetch] dev: 0x8000e2b8, chan: 59
[870:26:48.134,000] <inf> fake_sensor: [channel_get] dev: 0x8000e2b8, chan: 12

@teburd @ubieda @jeppenodgaard PTAL again, thanks

ycsin commented 3 weeks ago

Update the test with the new sensor shell output and now the CI pass

@teburd @ubieda @jeppenodgaard @MaureenHelm PTAL again, thanks