Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: sensors: Emulator Backend API and Generic Test #60394

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

tristan-google
Copy link
Collaborator

Note: this PR depends on #60275 You may ignore the bottom 4 commits.

This PR introduces a backend API to be implemented by sensor emulators
that creates a standardized mechanism for setting expected sensor
readings in tests. This unlocks the ability to create a generic sensor
test that can automatically set expected values in supported sensor
emulators and verify them through the existing sensor API. An
implementation of this API is provided for the AKM09918C magnetometer.

A generic sensor test is also created to exercise this implementation.
Observe that this test knows nothing about the AKM09918C; info about
supported channels and sample ranges is discovered through the backend
API. The test iterates over all devices attached to the virtual I2C and
SPI buses in the test binary's device tree, which (theoretically) covers
all sensors. Sensors whose emulator does not exist yet or does not
support the backend API are skipped.

@teburd teburd changed the title WIP: Emulator Backend API and Generic Test WIP: Sensors Emulator Backend API and Generic Test Jul 14, 2023
drivers/sensor/akm09918c/akm09918c.h Outdated Show resolved Hide resolved
include/zephyr/drivers/emul_sensor.h Outdated Show resolved Hide resolved
tests/drivers/build_all/sensor/Kconfig Outdated Show resolved Hide resolved
@tristan-google tristan-google force-pushed the emul-backend-api branch 2 times, most recently from af26858 to b94ecc3 Compare July 18, 2023 19:17
@tristan-google tristan-google changed the title WIP: Sensors Emulator Backend API and Generic Test tests: sensors: Emulator Backend API and Generic Test Jul 18, 2023
alevkoy
alevkoy previously approved these changes Jul 19, 2023
Copy link
Contributor

@alevkoy alevkoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits and typos.

tests/drivers/build_all/sensor/src/generic_test.c Outdated Show resolved Hide resolved
tests/drivers/build_all/sensor/src/generic_test.c Outdated Show resolved Hide resolved
drivers/sensor/akm09918c/akm09918c_emul.c Outdated Show resolved Hide resolved
drivers/sensor/akm09918c/akm09918c_emul.c Outdated Show resolved Hide resolved
aaronemassey
aaronemassey previously approved these changes Jul 19, 2023
Copy link
Member

@aaronemassey aaronemassey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but +1 to Abe's nits.

The sensor driver uses the value 500 to convert bit counts to microgauss
values, but it should actually be 1500. Edit the driver unit test to use
the macro instead of a magic number.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
@tristan-google tristan-google dismissed stale reviews from aaronemassey and alevkoy via b6031b7 July 24, 2023 17:53
@tristan-google tristan-google force-pushed the emul-backend-api branch 2 times, most recently from b6031b7 to 915986a Compare July 24, 2023 18:11

#include <zephyr/drivers/emul.h>
#include <zephyr/drivers/sensor.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define a doxygen group similar to this.

Also add a reference to the sensor documentation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a reference to the sensor documentation here

Would that just involve adding .. doxygengroup:: my_new_group_name below the current last line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a reference to the sensor documentation here

Would that just involve adding .. doxygengroup:: my_new_group_name below the current last line?

Yes, that's correct.

RTIO_DEFINE_WITH_MEMPOOL(sensor_read_rtio_ctx, 1, 1, 1, 64, 4);

/** Number of test points to use in the generic test. These are automatically generated. */
#define NUM_EXPECTED_VALS (5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a Kconfig in the test?

This PR introduces a backend API to be implemented by sensor emulators
that creates a standardized mechanism for setting expected sensor
readings in tests. This unlocks the ability to create a generic sensor
test that can automatically set expected values in supported sensor
emulators and verify them through the existing sensor API. An
implementation of this API is provided for the AKM09918C magnetometer.

A generic sensor test is also created to exercise this implementation.
Observe that this test knows nothing about the AKM09918C; info about
supported channels and sample ranges is discovered through the backend
API. The test iterates over all devices attached to the virtual I2C and
SPI buses in the test binary's device tree, which (theoretically) covers
all sensors. Sensors whose emulator does not exist yet or does not
support the backend API are skipped.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
@carlescufi carlescufi merged commit 171c1fc into zephyrproject-rtos:main Jul 28, 2023
17 checks passed
tristan-google added a commit to tristan-google/zephyr that referenced this pull request Aug 1, 2023
Implement the backend emul API for the ICM42688 motion sensor so it can
be automatically tested by the generic sensor test (see zephyrproject-rtos#60394).
Supports all channels (temp, accel XYZ, and gyro XYZ) at each of the
programmable full-scale accel and gyro ranges.

Also fixes an arithmetic bug in the driver that was causing a minor
error in the returned readings.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
tristan-google added a commit to tristan-google/zephyr that referenced this pull request Aug 2, 2023
This test was turned off last weekend when a sensor misbehaved and broke
the CI, but that issue was resolved in zephyrproject-rtos#61016. This PR turns the test
back on.

For more info on what this test does, please see zephyrproject-rtos#60394.

For more context see also the comments under zephyrproject-rtos#60959

Signed-off-by: Tristan Honscheid <honscheid@google.com>
carlescufi pushed a commit that referenced this pull request Aug 3, 2023
This test was turned off last weekend when a sensor misbehaved and broke
the CI, but that issue was resolved in #61016. This PR turns the test
back on.

For more info on what this test does, please see #60394.

For more context see also the comments under #60959

Signed-off-by: Tristan Honscheid <honscheid@google.com>
kunoh pushed a commit to kunoh/zephyr that referenced this pull request Aug 7, 2023
This test was turned off last weekend when a sensor misbehaved and broke
the CI, but that issue was resolved in zephyrproject-rtos#61016. This PR turns the test
back on.

For more info on what this test does, please see zephyrproject-rtos#60394.

For more context see also the comments under zephyrproject-rtos#60959

Signed-off-by: Tristan Honscheid <honscheid@google.com>
fabiobaltieri pushed a commit that referenced this pull request Aug 9, 2023
Implement the backend emul API for the ICM42688 motion sensor so it can
be automatically tested by the generic sensor test (see #60394).
Supports all channels (temp, accel XYZ, and gyro XYZ) at each of the
programmable full-scale accel and gyro ranges.

Also fixes an arithmetic bug in the driver that was causing a minor
error in the returned readings.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
umarnisar92 pushed a commit to nisarumar/zephyr that referenced this pull request Aug 15, 2023
This test was turned off last weekend when a sensor misbehaved and broke
the CI, but that issue was resolved in zephyrproject-rtos#61016. This PR turns the test
back on.

For more info on what this test does, please see zephyrproject-rtos#60394.

For more context see also the comments under zephyrproject-rtos#60959

Signed-off-by: Tristan Honscheid <honscheid@google.com>
umarnisar92 pushed a commit to nisarumar/zephyr that referenced this pull request Aug 15, 2023
Implement the backend emul API for the ICM42688 motion sensor so it can
be automatically tested by the generic sensor test (see zephyrproject-rtos#60394).
Supports all channels (temp, accel XYZ, and gyro XYZ) at each of the
programmable full-scale accel and gyro ranges.

Also fixes an arithmetic bug in the driver that was causing a minor
error in the returned readings.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
meshium pushed a commit to meshium/zephyr that referenced this pull request Aug 16, 2023
This test was turned off last weekend when a sensor misbehaved and broke
the CI, but that issue was resolved in zephyrproject-rtos#61016. This PR turns the test
back on.

For more info on what this test does, please see zephyrproject-rtos#60394.

For more context see also the comments under zephyrproject-rtos#60959

Signed-off-by: Tristan Honscheid <honscheid@google.com>
meshium pushed a commit to meshium/zephyr that referenced this pull request Aug 16, 2023
Implement the backend emul API for the ICM42688 motion sensor so it can
be automatically tested by the generic sensor test (see zephyrproject-rtos#60394).
Supports all channels (temp, accel XYZ, and gyro XYZ) at each of the
programmable full-scale accel and gyro ranges.

Also fixes an arithmetic bug in the driver that was causing a minor
error in the returned readings.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants