Skip to content

Commit

Permalink
[nrf fromtree] tests: boards: nrf: qdec: modify QDEC tests to match n…
Browse files Browse the repository at this point in the history
…ew 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 <[email protected]>
(cherry picked from commit 9b5260d)
  • Loading branch information
mstasiaknordic committed Oct 18, 2024
1 parent ee226fd commit 8b02983
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions tests/boards/nrf/qdec/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Check notice on line 331 in tests/boards/nrf/qdec/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/boards/nrf/qdec/src/main.c:331 - 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); + 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);

/**
Expand Down

0 comments on commit 8b02983

Please sign in to comment.