diff --git a/tests/boards/nrf/qdec/src/main.c b/tests/boards/nrf/qdec/src/main.c index 639e92f8510..cccd92c3293 100644 --- a/tests/boards/nrf/qdec/src/main.c +++ b/tests/boards/nrf/qdec/src/main.c @@ -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); } /**