Skip to content

Commit c7018b7

Browse files
silabs-aydoganerzr
authored andcommitted
uic: zpc: Pull request #2931: UIC-3603: zwave module unit test
Merge in UIC/uic from test/UIC-3603-zwave-module-unit-test to develop (cherry picked from commit c2296d353cc5498237924a37cb76880d55de3292) Forwarded: #11 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 13f4eaf commit c7018b7

File tree

3 files changed

+222
-18
lines changed

3 files changed

+222
-18
lines changed

applications/zpc/components/zwave/zwave_controller/test/zwave_controller_callbacks_test.c

+163-17
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,21 @@
2222
#include "sl_log.h"
2323

2424
/// Static variables
25-
static zwave_controller_callbacks_t callbacks = {};
26-
static int zwave_controller_on_frame_transmission_call_count = 0;
27-
static int zwave_controller_on_node_event_test_call_count = 0;
28-
static int zwave_controller_on_rx_frame_received_count = 0;
29-
static int zwave_controller_on_network_address_update_count = 0;
30-
static int zwave_controller_on_application_frame_received_count = 0;
31-
static zwave_controller_connection_info_t info = {};
32-
static zwave_rx_receive_options_t rx_options = {};
33-
const uint8_t frame_data[] = {0x00};
34-
const uint8_t transport_frame_data[] = {0xbb};
35-
static sl_status_t transport_return_code = SL_STATUS_OK;
25+
static zwave_controller_callbacks_t callbacks = {};
26+
static int zwave_controller_on_frame_transmission_call_count = 0;
27+
static int zwave_controller_on_node_event_test_call_count = 0;
28+
static int zwave_controller_on_rx_frame_received_count = 0;
29+
static int zwave_controller_on_network_address_update_count = 0;
30+
static int zwave_controller_on_application_frame_received_count = 0;
31+
static int zwave_controller_on_protocol_cc_encryption_request_count = 0;
32+
static int zwave_controller_on_protocol_frame_received_count = 0;
33+
static zwave_controller_connection_info_t info = {};
34+
static zwave_rx_receive_options_t rx_options = {};
35+
const uint8_t frame_data[] = {0x00};
36+
const uint8_t protocol_frame_data[] = {0x01}; // ZWAVE_CMD_CLASS_PROTOCOL
37+
const uint8_t protocol_lr_frame_data[] = {0x04}; // ZWAVE_CMD_CLASS_PROTOCOL_LR
38+
const uint8_t transport_frame_data[] = {0xbb};
39+
static sl_status_t transport_return_code = SL_STATUS_OK;
3640

3741
// A Z-Wave Controller transport:
3842
static sl_status_t test_transport_on_frame_received(
@@ -82,6 +86,27 @@ static void zwave_controller_on_application_frame_received(
8286
zwave_controller_on_application_frame_received_count += 1;
8387
}
8488

89+
static void zwave_controller_on_protocol_cc_encryption_request(
90+
const zwave_node_id_t destination_node_id,
91+
const uint8_t payload_length,
92+
const uint8_t *const payload,
93+
const uint8_t protocol_metadata_length,
94+
const uint8_t *const protocol_metadata,
95+
const uint8_t use_supervision,
96+
const uint8_t session_id)
97+
{
98+
zwave_controller_on_protocol_cc_encryption_request_count += 1;
99+
}
100+
101+
static void zwave_controller_on_protocol_frame_received(
102+
const zwave_controller_connection_info_t *connection_info,
103+
const zwave_rx_receive_options_t *rx_options,
104+
const uint8_t *frame_data,
105+
uint16_t frame_length)
106+
{
107+
zwave_controller_on_protocol_frame_received_count += 1;
108+
}
109+
85110
static void zwave_controller_on_node_event_test(zwave_node_id_t node_id)
86111
{
87112
zwave_controller_on_node_event_test_call_count += 1;
@@ -102,12 +127,14 @@ int suiteTearDown(int num_failures)
102127

103128
void setUp()
104129
{
105-
zwave_controller_on_frame_transmission_call_count = 0;
106-
zwave_controller_on_node_event_test_call_count = 0;
107-
zwave_controller_on_rx_frame_received_count = 0;
108-
zwave_controller_on_network_address_update_count = 0;
109-
zwave_controller_on_application_frame_received_count = 0;
110-
transport_return_code = SL_STATUS_OK;
130+
zwave_controller_on_frame_transmission_call_count = 0;
131+
zwave_controller_on_node_event_test_call_count = 0;
132+
zwave_controller_on_rx_frame_received_count = 0;
133+
zwave_controller_on_network_address_update_count = 0;
134+
zwave_controller_on_application_frame_received_count = 0;
135+
zwave_controller_on_protocol_cc_encryption_request_count = 0;
136+
zwave_controller_on_protocol_frame_received_count = 0;
137+
transport_return_code = SL_STATUS_OK;
111138
zwave_controller_callbacks_init();
112139
}
113140

@@ -266,6 +293,125 @@ void test_zwave_controller_on_controller_application_frames()
266293
callbacks.on_application_frame_received = NULL;
267294
}
268295

296+
void test_zwave_controller_on_protocol_cc_encryption_request_received()
297+
{
298+
zwave_node_id_t destination_node_id = 3;
299+
uint8_t payload[] = {0xF1, 0xF2};
300+
uint8_t payload_length = sizeof(payload);
301+
uint8_t protocol_metadata[] = {0x1E, 0x2E};
302+
uint8_t protocol_metadata_length = sizeof(protocol_metadata);
303+
uint8_t use_supervision = 1;
304+
uint8_t session_id = 2;
305+
306+
zwave_controller_on_protocol_cc_encryption_request_received(
307+
destination_node_id,
308+
payload_length,
309+
payload,
310+
protocol_metadata_length,
311+
protocol_metadata,
312+
use_supervision,
313+
session_id);
314+
TEST_ASSERT_EQUAL(0,
315+
zwave_controller_on_protocol_cc_encryption_request_count);
316+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
317+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
318+
319+
callbacks.on_rx_frame_received
320+
= &zwave_controller_on_rx_frame_received_callback;
321+
callbacks.on_application_frame_received
322+
= &zwave_controller_on_application_frame_received;
323+
callbacks.on_protocol_cc_encryption_request
324+
= &zwave_controller_on_protocol_cc_encryption_request;
325+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
326+
zwave_controller_register_callbacks(&callbacks));
327+
328+
zwave_controller_on_protocol_cc_encryption_request_received(
329+
destination_node_id,
330+
payload_length,
331+
payload,
332+
protocol_metadata_length,
333+
protocol_metadata,
334+
use_supervision,
335+
session_id);
336+
TEST_ASSERT_EQUAL(1,
337+
zwave_controller_on_protocol_cc_encryption_request_count);
338+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
339+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
340+
341+
// remove these callbacks:
342+
callbacks.on_rx_frame_received = NULL;
343+
callbacks.on_application_frame_received = NULL;
344+
callbacks.on_protocol_cc_encryption_request = NULL;
345+
}
346+
347+
void test_zwave_controller_on_controller_protocol_frames()
348+
{
349+
// We need to inject a valid frame, as this will go through the transports
350+
zwave_controller_on_frame_received(&info,
351+
&rx_options,
352+
protocol_frame_data,
353+
sizeof(protocol_frame_data));
354+
TEST_ASSERT_EQUAL(0, zwave_controller_on_protocol_frame_received_count);
355+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
356+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
357+
358+
callbacks.on_rx_frame_received
359+
= &zwave_controller_on_rx_frame_received_callback;
360+
callbacks.on_application_frame_received
361+
= &zwave_controller_on_application_frame_received;
362+
callbacks.on_protocol_frame_received
363+
= &zwave_controller_on_protocol_frame_received;
364+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
365+
zwave_controller_register_callbacks(&callbacks));
366+
367+
zwave_controller_on_frame_received(&info,
368+
&rx_options,
369+
protocol_frame_data,
370+
sizeof(protocol_frame_data));
371+
TEST_ASSERT_EQUAL(1, zwave_controller_on_protocol_frame_received_count);
372+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
373+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
374+
375+
// remove these callbacks:
376+
callbacks.on_rx_frame_received = NULL;
377+
callbacks.on_application_frame_received = NULL;
378+
callbacks.on_protocol_frame_received = NULL;
379+
}
380+
381+
void test_zwave_controller_on_controller_protocol_lr_frames()
382+
{
383+
// We need to inject a valid frame, as this will go through the transports
384+
zwave_controller_on_frame_received(&info,
385+
&rx_options,
386+
protocol_lr_frame_data,
387+
sizeof(protocol_lr_frame_data));
388+
TEST_ASSERT_EQUAL(0, zwave_controller_on_protocol_frame_received_count);
389+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
390+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
391+
392+
callbacks.on_rx_frame_received
393+
= &zwave_controller_on_rx_frame_received_callback;
394+
callbacks.on_application_frame_received
395+
= &zwave_controller_on_application_frame_received;
396+
callbacks.on_protocol_frame_received
397+
= &zwave_controller_on_protocol_frame_received;
398+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
399+
zwave_controller_register_callbacks(&callbacks));
400+
401+
zwave_controller_on_frame_received(&info,
402+
&rx_options,
403+
protocol_lr_frame_data,
404+
sizeof(protocol_lr_frame_data));
405+
TEST_ASSERT_EQUAL(1, zwave_controller_on_protocol_frame_received_count);
406+
TEST_ASSERT_EQUAL(0, zwave_controller_on_application_frame_received_count);
407+
TEST_ASSERT_EQUAL(0, zwave_controller_on_rx_frame_received_count);
408+
409+
// remove these callbacks:
410+
callbacks.on_rx_frame_received = NULL;
411+
callbacks.on_application_frame_received = NULL;
412+
callbacks.on_protocol_frame_received = NULL;
413+
}
414+
269415
void test_zwave_controller_on_network_address_update()
270416
{
271417
// Nothing happens with no callback registered

applications/zpc/components/zwave/zwave_controller/test/zwave_controller_test.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "zpc_config_mock.h"
1818
#include "zwapi_protocol_basis_mock.h"
1919
#include "zwave_s2_transport_mock.h"
20+
#include "zwapi_protocol_controller_mock.h"
2021

2122
/// Setup the test suite (called once before all test_xxx functions are called)
2223
void suiteSetUp() {}
@@ -68,4 +69,20 @@ void test_zwave_controller_set_secure_nif()
6869

6970
zwave_controller_set_secure_application_nif(command_classes,
7071
sizeof(command_classes));
71-
}
72+
}
73+
74+
void test_zwave_controller_request_protocol_cc_encryption_callback()
75+
{
76+
uint8_t status = TRANSMIT_COMPLETE_VERIFIED;
77+
zwapi_tx_report_t tx_info = {0};
78+
uint8_t session_id = 0;
79+
80+
zwapi_request_protocol_cc_encryption_callback_ExpectAndReturn(status,
81+
&tx_info,
82+
session_id,
83+
SL_STATUS_OK);
84+
85+
zwave_controller_request_protocol_cc_encryption_callback(status,
86+
&tx_info,
87+
session_id);
88+
}

applications/zpc/components/zwave/zwave_rx/test/zwave_rx_test.c

+41
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,47 @@ void test_zwave_rx_on_frame_received()
437437
TEST_ASSERT_EQUAL(0, zwave_rx_fixt_teardown());
438438
}
439439

440+
void test_zwave_rx_on_protocol_cc_encryption_request_received()
441+
{
442+
// Init zwave_rx:
443+
rx_init_successful_test_helper();
444+
445+
zwave_node_id_t destination_node_id = 3;
446+
uint8_t payload[] = {0x01, 0x02};
447+
uint8_t payload_length = sizeof(payload);
448+
uint8_t metadata[] = {0xA1, 0xA2};
449+
uint8_t metadata_length = sizeof(metadata);
450+
uint8_t use_supervision = 1;
451+
uint8_t session_id = 2;
452+
453+
// Frame dispatch
454+
zwave_controller_on_protocol_cc_encryption_request_received_ExpectWithArray(
455+
destination_node_id,
456+
payload_length,
457+
payload,
458+
payload_length,
459+
metadata_length,
460+
metadata,
461+
metadata_length,
462+
use_supervision,
463+
session_id);
464+
465+
// Trigger an on_frame_received callback
466+
registered_zwapi_callbacks->protocol_cc_encryption_request(
467+
destination_node_id,
468+
payload_length,
469+
payload,
470+
metadata_length,
471+
metadata,
472+
use_supervision,
473+
session_id);
474+
475+
// Now shut down the functionality
476+
zwapi_destroy_Expect();
477+
zwapi_log_to_file_disable_ExpectAndReturn(SL_STATUS_OK);
478+
TEST_ASSERT_EQUAL(0, zwave_rx_fixt_teardown());
479+
}
480+
440481
/// Test of rx init for on_smart_start_event callbacks
441482
void test_zwave_rx_on_smart_start_event()
442483
{

0 commit comments

Comments
 (0)