Skip to content

Commit 6788d86

Browse files
tbr-ttcarlescufi
authored andcommitted
tests: can.frame: use enums for rtr and id_type
Make use of the the enums for rtr and id_type as described in drivers/can.h. Signed-off-by: Martin Åberg <[email protected]>
1 parent 265d848 commit 6788d86

File tree

1 file changed

+14
-17
lines changed
  • tests/subsys/canbus/frame/src

1 file changed

+14
-17
lines changed

tests/subsys/canbus/frame/src/main.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ static void test_can_frame_to_zcan_frame(void)
2828
frame.can_dlc = sizeof(data);
2929
memcpy(frame.data, data, sizeof(frame.data));
3030

31-
expected.rtr = 1U;
32-
expected.id_type = 1U;
31+
expected.rtr = CAN_REMOTEREQUEST;
32+
expected.id_type = CAN_EXTENDED_IDENTIFIER;
3333
expected.id = 1234U;
3434
expected.dlc = sizeof(data);
3535

@@ -41,7 +41,7 @@ static void test_can_frame_to_zcan_frame(void)
4141

4242
zassert_equal(msg.rtr, expected.rtr, "RTR bit not set");
4343
zassert_equal(msg.id_type, expected.id_type, "Id-type bit not set");
44-
zassert_equal(msg.id, expected.id, "Std CAN id invalid");
44+
zassert_equal(msg.id, expected.id, "CAN id invalid");
4545
zassert_equal(msg.dlc, expected.dlc, "Msg length invalid");
4646
}
4747

@@ -57,8 +57,8 @@ static void test_zcan_frame_to_can_frame(void)
5757
expected.can_dlc = sizeof(data);
5858
memcpy(expected.data, data, sizeof(expected.data));
5959

60-
msg.rtr = 1U;
61-
msg.id_type = 1U;
60+
msg.rtr = CAN_REMOTEREQUEST;
61+
msg.id_type = CAN_EXTENDED_IDENTIFIER;
6262
msg.id = 1234U;
6363
msg.dlc = sizeof(data);
6464
memcpy(msg.data, data, sizeof(data));
@@ -69,8 +69,7 @@ static void test_zcan_frame_to_can_frame(void)
6969
LOG_HEXDUMP_DBG((const uint8_t *)&msg, sizeof(msg), "msg");
7070
LOG_HEXDUMP_DBG((const uint8_t *)&expected, sizeof(expected), "expected");
7171

72-
zassert_mem_equal(&frame.can_id, &expected.can_id, sizeof(frame.can_id),
73-
"CAN ID not same");
72+
zassert_equal(frame.can_id, expected.can_id, "CAN ID not same");
7473
zassert_mem_equal(&frame.data, &expected.data, sizeof(frame.data),
7574
"CAN data not same");
7675
zassert_equal(frame.can_dlc, expected.can_dlc,
@@ -86,8 +85,8 @@ static void test_can_filter_to_zcan_filter(void)
8685
filter.can_id = BIT(31) | BIT(30) | 1234;
8786
filter.can_mask = BIT(31) | BIT(30) | 1234;
8887

89-
expected.rtr = 1U;
90-
expected.id_type = 1U;
88+
expected.rtr = CAN_REMOTEREQUEST;
89+
expected.id_type = CAN_EXTENDED_IDENTIFIER;
9190
expected.id = 1234U;
9291
expected.rtr_mask = 1U;
9392
expected.id_mask = 1234U;
@@ -103,11 +102,11 @@ static void test_can_filter_to_zcan_filter(void)
103102
zassert_equal(msg_filter.id_type, expected.id_type,
104103
"Id-type bit not set");
105104
zassert_equal(msg_filter.id, expected.id,
106-
"Std CAN id invalid");
105+
"CAN id invalid");
107106
zassert_equal(msg_filter.rtr_mask, expected.rtr_mask,
108107
"RTR mask bit not set");
109108
zassert_equal(msg_filter.id_mask, expected.id_mask,
110-
"Std id mask not set");
109+
"id mask not set");
111110
}
112111

113112
static void test_zcan_filter_to_can_filter(void)
@@ -119,8 +118,8 @@ static void test_zcan_filter_to_can_filter(void)
119118
expected.can_id = BIT(31) | BIT(30) | 1234;
120119
expected.can_mask = BIT(31) | BIT(30) | 1234;
121120

122-
msg_filter.rtr = 1U;
123-
msg_filter.id_type = 1U;
121+
msg_filter.rtr = CAN_REMOTEREQUEST;
122+
msg_filter.id_type = CAN_EXTENDED_IDENTIFIER;
124123
msg_filter.id = 1234U;
125124
msg_filter.rtr_mask = 1U;
126125
msg_filter.id_mask = 1234U;
@@ -132,10 +131,8 @@ static void test_zcan_filter_to_can_filter(void)
132131
LOG_HEXDUMP_DBG((const uint8_t *)&filter, sizeof(filter), "filter");
133132
LOG_HEXDUMP_DBG((const uint8_t *)&expected, sizeof(expected), "expected");
134133

135-
zassert_mem_equal(&filter.can_id, &expected.can_id,
136-
sizeof(filter.can_id), "CAN ID not same");
137-
zassert_mem_equal(&filter.can_mask, &expected.can_mask,
138-
sizeof(filter.can_mask), "CAN mask not same");
134+
zassert_equal(filter.can_id, expected.can_id, "CAN ID not same");
135+
zassert_equal(filter.can_mask, expected.can_mask, "CAN mask not same");
139136
}
140137

141138
void test_main(void)

0 commit comments

Comments
 (0)