Skip to content

Commit 42f0259

Browse files
committed
[nrf fromlist] tests: drivers: can: api: Validate CAN statistics
Extend CAN stats test. Add validation of returned data. Assume that current value of error counters is smaller than arbitrary threshold. This is to detect bug in CAN driver implementation where CAN stats are not correctly initialized. Upstream PR #: 99796 Signed-off-by: Sebastian Głąb <[email protected]>
1 parent 0985cce commit 42f0259

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/drivers/can/api/src/stats.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include "common.h"
1111

12+
/* Arbitrary threshold */
13+
#define THRESHOLD 10
14+
1215
/**
1316
* @addtogroup t_driver_can
1417
* @{
@@ -24,13 +27,21 @@ ZTEST_USER(can_stats, test_can_stats_accessors)
2427
uint32_t val;
2528

2629
val = can_stats_get_bit_errors(can_dev);
30+
zassert_true(val < THRESHOLD, "CAN bit errors are too high");
2731
val = can_stats_get_bit0_errors(can_dev);
32+
zassert_true(val < THRESHOLD, "CAN bit0 errors are too high");
2833
val = can_stats_get_bit1_errors(can_dev);
34+
zassert_true(val < THRESHOLD, "CAN bit1 errors are too high");
2935
val = can_stats_get_stuff_errors(can_dev);
36+
zassert_true(val < THRESHOLD, "CAN stuff errors are too high");
3037
val = can_stats_get_crc_errors(can_dev);
38+
zassert_true(val < THRESHOLD, "CAN crc errors are too high");
3139
val = can_stats_get_form_errors(can_dev);
40+
zassert_true(val < THRESHOLD, "CAN form errors are too high");
3241
val = can_stats_get_ack_errors(can_dev);
42+
zassert_true(val < THRESHOLD, "CAN ack errors are too high");
3343
val = can_stats_get_rx_overruns(can_dev);
44+
zassert_true(val < THRESHOLD, "CAN rx overruns are too high");
3445
}
3546

3647
void *can_stats_setup(void)

0 commit comments

Comments
 (0)