Skip to content

Commit 970b209

Browse files
silabs-aydoganerzr
authored andcommitted
uic: zpc: Pull request #2921: UIC-3595: Add unit test to zwave_tx module for protocol frame
Merge in UIC/uic from feature/UIC-3595-add-zwave_tx-unit-test to develop (cherry picked from commit 5eea13e0e5c7ab41e72493fd06844d0653221c05) Forwarded: #11 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent d14cdd6 commit 970b209

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

applications/zpc/components/zwave/zwave_tx/test/zwave_tx_test.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,66 @@ void test_zwave_tx_send_data_happy_case()
258258
TEST_ASSERT_EQUAL_PTR(NULL, received_user_pointer);
259259
}
260260

261+
void test_zwave_tx_send_protocol_data_happy_case()
262+
{
263+
protocol_metadata_t protocol_metadata = {
264+
.tx_session_id = NULL,
265+
.session_id = 1,
266+
.data_length = 7,
267+
.data = {0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA},
268+
};
269+
270+
zwave_controller_transport_send_data_ExpectWithArrayAndReturn(
271+
&test_connection_4,
272+
sizeof(test_connection_4),
273+
sizeof(test_expected_frame_data_1),
274+
test_expected_frame_data_1,
275+
sizeof(test_expected_frame_data_1),
276+
&test_tx_options_protocol_frame,
277+
sizeof(test_tx_options_protocol_frame),
278+
NULL,
279+
(void *)&protocol_metadata,
280+
sizeof(void *),
281+
NULL,
282+
SL_STATUS_OK);
283+
284+
zwave_controller_transport_send_data_IgnoreArg_session();
285+
zwave_controller_transport_send_data_IgnoreArg_on_send_complete();
286+
287+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
288+
zwave_tx_send_data(&test_connection_4,
289+
sizeof(test_expected_frame_data_1),
290+
test_expected_frame_data_1,
291+
&test_tx_options_protocol_frame,
292+
send_data_callback,
293+
(void *)&protocol_metadata,
294+
&test_tx_session_id));
295+
296+
// We are now waiting for more frames, or a transport callback.
297+
contiki_test_helper_run_once(DEFAULT_CONTIKI_CLOCK_JUMP);
298+
299+
// Transport informs it is done.
300+
TEST_ASSERT_NOT_NULL(zwave_transport_send_data_save);
301+
zwave_transport_send_data_save(TRANSMIT_COMPLETE_VERIFIED,
302+
&test_tx_report,
303+
(void *)&protocol_metadata);
304+
305+
// Now the child frame is fully done.
306+
contiki_test_helper_run_clock_increases_for_each_event(
307+
TX_BACKOFF_CONTIKI_CLOCK_JUMP);
308+
309+
// Verify that it looks looks as expected
310+
TEST_ASSERT_EQUAL(1, send_done_count);
311+
TEST_ASSERT_EQUAL(TRANSMIT_COMPLETE_VERIFIED, send_done_status);
312+
// We expect that the transmission time is copied from TX
313+
// Contiki made a clock jump of DEFAULT_CONTIKI_CLOCK_JUMP for each event
314+
send_done_tx_status.transmit_ticks = 0;
315+
TEST_ASSERT_EQUAL_MEMORY(&test_tx_report,
316+
&send_done_tx_status,
317+
sizeof(zwapi_tx_report_t));
318+
TEST_ASSERT_EQUAL_PTR((void *)&protocol_metadata, received_user_pointer);
319+
}
320+
261321
void test_zwave_tx_send_data_fast_track()
262322
{
263323
zwave_controller_transport_send_data_ExpectWithArrayAndReturn(

applications/zpc/components/zwave/zwave_tx/test/zwave_tx_test.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ static const zwave_controller_connection_info_t test_connection_3 = {
5454
.encapsulation = ZWAVE_CONTROLLER_ENCAPSULATION_NONE,
5555
};
5656

57+
static const zwave_controller_connection_info_t test_connection_4 = {
58+
.local = {.node_id = 10, .endpoint_id = 10, .is_multicast = false},
59+
.remote = {.node_id = 5, .endpoint_id = 0, .is_multicast = false},
60+
.encapsulation = ZWAVE_CONTROLLER_ENCAPSULATION_NONE,
61+
};
62+
5763
static const zwave_tx_options_t test_tx_options_1
5864
= {.number_of_responses = 0,
5965
.discard_timeout_ms = 0,
@@ -124,6 +130,21 @@ static const zwave_tx_options_t test_tx_options_test_frame
124130
.group_id = ZWAVE_TX_INVALID_GROUP,
125131
}};
126132

133+
static const zwave_tx_options_t test_tx_options_protocol_frame
134+
= {.number_of_responses = 1,
135+
.discard_timeout_ms = 5000,
136+
.qos_priority = ZWAVE_TX_QOS_MAX_PRIORITY,
137+
.fasttrack = false,
138+
.send_follow_ups = false,
139+
.transport = {
140+
.is_first_follow_up = false,
141+
.is_test_frame = false,
142+
.is_protocol_frame = true,
143+
.ignore_incoming_frames_back_off = false,
144+
.rf_power = MINUS_3_DBM,
145+
.group_id = ZWAVE_TX_INVALID_GROUP,
146+
}};
147+
127148
static const zwave_tx_options_t test_tx_options_group_id
128149
= {.number_of_responses = 1,
129150
.discard_timeout_ms = 0,

0 commit comments

Comments
 (0)