@@ -89,7 +89,7 @@ static void qenc_emulate_stop(void)
8989}
9090
9191static void qenc_emulate_verify_reading (int emulator_period_ms , int emulation_duration_ms ,
92- bool forward , bool overflow_possible )
92+ bool forward , bool overflow_expected )
9393{
9494 int rc ;
9595 struct sensor_value val = {0 };
@@ -107,13 +107,17 @@ static void qenc_emulate_verify_reading(int emulator_period_ms, int emulation_du
107107 k_msleep (emulation_duration_ms );
108108
109109 rc = sensor_sample_fetch (qdec_dev );
110- zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
110+
111+ if (!overflow_expected ) {
112+ zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
113+ } else {
114+ zassert_true (rc == - EOVERFLOW , "Failed to detect overflow" );
115+ }
111116
112117 rc = sensor_channel_get (qdec_dev , SENSOR_CHAN_ROTATION , & val );
113118 zassert_true (rc == 0 , "Failed to get sample (%d)" , rc );
114119
115- TC_PRINT ("QDEC reading: %d\n" , val .val1 );
116- if (!overflow_possible ) {
120+ if (!overflow_expected ) {
117121 zassert_within (val .val1 , expected_reading , delta ,
118122 "Expected reading: %d, but got: %d" , expected_reading , val .val1 );
119123 }
@@ -197,6 +201,9 @@ ZTEST(qdec_sensor, test_sensor_trigger_set)
197201 rc = k_sem_take (& sem , K_MSEC (200 ));
198202 zassert_true (rc == 0 , "qdec handler should be triggered (%d)" , rc );
199203
204+ rc = sensor_sample_fetch (qdec_dev );
205+ zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
206+
200207 rc = sensor_channel_get (qdec_dev , SENSOR_CHAN_ROTATION , & val );
201208 zassert_true (rc == 0 , "Failed to fetch sample (%d)" , rc );
202209
@@ -241,7 +248,6 @@ ZTEST(qdec_sensor, test_qdec_readings)
241248 qenc_emulate_verify_reading (10 , 100 , true, false);
242249 qenc_emulate_verify_reading (2 , 500 , true, false);
243250 qenc_emulate_verify_reading (10 , 200 , false, false);
244- /* may lead to overflows but currently driver does not detects that */
245251 qenc_emulate_verify_reading (1 , 1000 , false, true);
246252 qenc_emulate_verify_reading (1 , 1000 , true, true);
247253}
@@ -313,18 +319,15 @@ ZTEST(qdec_sensor, test_sensor_channel_get)
313319 /* subsequent calls of sensor_channel_get without calling sensor_sample_fetch
314320 * should yield the same value
315321 */
316- /* zassert_true(val_first.val1 == val_second.val1,
317- * "Expected the same readings: %d vs %d",
318- * val_first.val1,
319- * val_second.val1);
320- */
321- TC_PRINT ("Expected the same readings: %d vs %d - ignore!\n" , val_first .val1 ,
322- val_second .val1 );
323- /* zassert_true(val_first.val2 == val_second.val2, "Expected the same readings: %d vs %d",
324- * val_first.val2, val_second.val2);
325- */
326- TC_PRINT ("Expected the same readings: %d vs %d - ignore!\n" , val_first .val2 ,
327- val_second .val2 );
322+ zassert_true (val_first .val1 == val_second .val1 ,
323+ "Expected the same readings: %d vs %d" ,
324+ val_first .val1 ,
325+ val_second .val1 );
326+
327+ zassert_true (val_first .val2 == val_second .val2 ,
328+ "Expected the same readings: %d vs %d" ,
329+ val_first .val2 ,
330+ val_second .val2 );
328331}
329332
330333/**
0 commit comments