Skip to content

Commit c10c13b

Browse files
decsnykartben
authored andcommitted
tests: spi_loopback: Handle overflow of print latency
The test that checks latency also prints a measurement of the latency which is just a visual information for the test output. However, this print uses a subtraction which can have an overflow in the case where the kernel timer is behind, so just clamp to 0 in that case where there is an overflow. This change does not affect the test pass/fail logic. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent eb5014f commit c10c13b

File tree

1 file changed

+7
-2
lines changed
  • tests/drivers/spi/spi_loopback/src

1 file changed

+7
-2
lines changed

tests/drivers/spi/spi_loopback/src/spi.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
289289
buffer2_rx, BUF2_SIZE);
290290
uint32_t freq = spec->config.frequency;
291291
uint32_t start_time, end_time, cycles_spent;
292-
uint64_t time_spent_us, expected_transfer_time_us;
292+
uint64_t time_spent_us, expected_transfer_time_us, latency_measurement;
293293

294294
/* since this is a test program, there shouldn't be much to interfere with measurement */
295295
start_time = k_cycle_get_32();
@@ -329,7 +329,12 @@ ZTEST(spi_loopback, test_spi_complete_multiple_timed)
329329
zassert_true(time_spent_us >= minimum_transfer_time_us,
330330
"Transfer faster than theoretically possible");
331331

332-
TC_PRINT("Latency measurement: %llu us\n", time_spent_us - expected_transfer_time_us);
332+
/* handle overflow for print statement */
333+
latency_measurement = time_spent_us - expected_transfer_time_us;
334+
if (latency_measurement > time_spent_us) {
335+
latency_measurement = 0;
336+
}
337+
TC_PRINT("Latency measurement: %llu us\n", latency_measurement);
333338

334339
/* Allow some overhead, but not too much */
335340
zassert_true(time_spent_us <= expected_transfer_time_us * 8, "Very high latency");

0 commit comments

Comments
 (0)