tests: boards: nrf: qdec: modify QDEC tests to match new api
Overflow errorcode is now correctly detected when expected. Subsequent sensor_channel_get() yield the same values, so the check can be no longer ignored. Added a sensor_sample_fetch() where missing for correct sensor_channel_get() calls. Signed-off-by: Michał Stasiak <michal.stasiak@nordicsemi.no>
This commit is contained in:
parent
2e6c83dd4c
commit
9b5260de9a
1 changed files with 20 additions and 17 deletions
|
|
@ -89,7 +89,7 @@ static void qenc_emulate_stop(void)
|
|||
}
|
||||
|
||||
static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_duration_ms,
|
||||
bool forward, bool overflow_possible)
|
||||
bool forward, bool overflow_expected)
|
||||
{
|
||||
int rc;
|
||||
struct sensor_value val = {0};
|
||||
|
|
@ -107,13 +107,17 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du
|
|||
k_msleep(emulation_duration_ms);
|
||||
|
||||
rc = sensor_sample_fetch(qdec_dev);
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
|
||||
if (!overflow_expected) {
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
} else {
|
||||
zassert_true(rc == -EOVERFLOW, "Failed to detect overflow");
|
||||
}
|
||||
|
||||
rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val);
|
||||
zassert_true(rc == 0, "Failed to get sample (%d)", rc);
|
||||
|
||||
TC_PRINT("QDEC reading: %d\n", val.val1);
|
||||
if (!overflow_possible) {
|
||||
if (!overflow_expected) {
|
||||
zassert_within(val.val1, expected_reading, delta,
|
||||
"Expected reading: %d, but got: %d", expected_reading, val.val1);
|
||||
}
|
||||
|
|
@ -197,6 +201,9 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
|
|||
rc = k_sem_take(&sem, K_MSEC(200));
|
||||
zassert_true(rc == 0, "qdec handler should be triggered (%d)", rc);
|
||||
|
||||
rc = sensor_sample_fetch(qdec_dev);
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
|
||||
rc = sensor_channel_get(qdec_dev, SENSOR_CHAN_ROTATION, &val);
|
||||
zassert_true(rc == 0, "Failed to fetch sample (%d)", rc);
|
||||
|
||||
|
|
@ -241,7 +248,6 @@ ZTEST(qdec_sensor, test_qdec_readings)
|
|||
qenc_emulate_verify_reading(10, 100, true, false);
|
||||
qenc_emulate_verify_reading(2, 500, true, false);
|
||||
qenc_emulate_verify_reading(10, 200, false, false);
|
||||
/* may lead to overflows but currently driver does not detects that */
|
||||
qenc_emulate_verify_reading(1, 1000, false, true);
|
||||
qenc_emulate_verify_reading(1, 1000, true, true);
|
||||
}
|
||||
|
|
@ -313,18 +319,15 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
|
|||
/* subsequent calls of sensor_channel_get without calling sensor_sample_fetch
|
||||
* should yield the same value
|
||||
*/
|
||||
/* zassert_true(val_first.val1 == val_second.val1,
|
||||
* "Expected the same readings: %d vs %d",
|
||||
* val_first.val1,
|
||||
* val_second.val1);
|
||||
*/
|
||||
TC_PRINT("Expected the same readings: %d vs %d - ignore!\n", val_first.val1,
|
||||
val_second.val1);
|
||||
/* zassert_true(val_first.val2 == val_second.val2, "Expected the same readings: %d vs %d",
|
||||
* val_first.val2, val_second.val2);
|
||||
*/
|
||||
TC_PRINT("Expected the same readings: %d vs %d - ignore!\n", val_first.val2,
|
||||
val_second.val2);
|
||||
zassert_true(val_first.val1 == val_second.val1,
|
||||
"Expected the same readings: %d vs %d",
|
||||
val_first.val1,
|
||||
val_second.val1);
|
||||
|
||||
zassert_true(val_first.val2 == val_second.val2,
|
||||
"Expected the same readings: %d vs %d",
|
||||
val_first.val2,
|
||||
val_second.val2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue