Skip to content

Commit 689c62b

Browse files
committed
fix(zwapi): Add test for zwapi_connection_tx
Without (revert HEAD~1) the previous fix change, the test should segfault. Note that it has been observed thats smaller buffers overflows are not causing segfault. Origin: SiliconLabsSoftware#127 Bug-SiliconLabs: UIC-3666 Bug-SLVDBBP: 3169925 Signed-off-by: Philippe Coval <[email protected]>
1 parent b34817a commit 689c62b

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

applications/zpc/components/zwave_api/test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ EXCLUDE zwapi_connection.c
5959
zwapi_session.c
6060
zwapi_init.c
6161
)
62+
63+
target_add_unittest(zwave_api
64+
NAME zwapi_connection_test
65+
SOURCES zwapi_connection_test.c
66+
zwapi_internal_init_mock.c
67+
DEPENDS zwapi_internal_mock
68+
zwave_api_mock
69+
EXCLUDE zwapi_session.c
70+
zwapi_init.c
71+
)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2025 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
#include "unity.h"
14+
//#include "zwapi_protocol_basis.h"
15+
//#include "zwapi_func_ids.h"
16+
17+
// Session mock:2
18+
#include "zwapi_session_mock.h"
19+
20+
#include <unity.h>
21+
#include "zwapi_connection.h"
22+
23+
#ifdef __clang__
24+
#pragma clang diagnostic ignored "-Woverflow"
25+
#endif
26+
27+
#ifdef __GNUC__
28+
#pragma GCC diagnostic ignored "-Woverflow"
29+
#endif
30+
31+
/// Setup the test suite (called once before all test_xxx functions are called)
32+
void suiteSetUp() {}
33+
34+
/// Teardown the test suite (called once after all test_xxx functions are called)
35+
int suiteTearDown(int num_failures)
36+
{
37+
return num_failures;
38+
}
39+
40+
/// Called before each and every test
41+
void setUp() {}
42+
43+
void test_zwapi_connection_tx_invalid_payload_length()
44+
{
45+
uint8_t cmd = 0x01;
46+
uint8_t type = 0x02;
47+
uint8_t buffer[8 * 1024 * 1024] = {0}; //< Exceeding the maximum allowed payload length
48+
uint8_t len = sizeof(buffer);
49+
bool ack_needed = true;
50+
51+
// Expect the function to not crash
52+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
53+
}
54+
55+
void test_zwapi_connection_tx_valid_inputs()
56+
{
57+
uint8_t cmd = 0x01;
58+
uint8_t type = 0x02;
59+
uint8_t buffer[10] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0};
60+
uint8_t len = sizeof(buffer);
61+
bool ack_needed = true;
62+
63+
// Expect the function to execute without errors
64+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
65+
}
66+
67+
void test_zwapi_connection_tx_null_buffer()
68+
{
69+
uint8_t cmd = 0x01;
70+
uint8_t type = 0x02;
71+
uint8_t *buffer = NULL;
72+
uint8_t len = 0;
73+
bool ack_needed = true;
74+
75+
// Expect the function to not crash
76+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
77+
}

0 commit comments

Comments
 (0)