Skip to content

Commit 9a44047

Browse files
committed
fix(zwapi): Add test for zwapi_connection_tx
Without (revert HEAD~1) the previous fix change, the test will be stuck in a loop. Note that it has been observed that 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 3a7bec0 commit 9a44047

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 <stdio.h>
15+
16+
#include <unity.h>
17+
#include "zwapi_connection.h"
18+
19+
#ifdef __clang__
20+
#pragma clang diagnostic ignored "-Woverflow"
21+
#endif
22+
23+
#ifdef __GNUC__
24+
#pragma GCC diagnostic ignored "-Woverflow"
25+
#endif
26+
27+
/// Setup the test suite (called once before all test_xxx functions are called)
28+
void suiteSetUp() {}
29+
30+
/// Teardown the test suite (called once after all test_xxx functions are called)
31+
int suiteTearDown(int num_failures)
32+
{
33+
return num_failures;
34+
}
35+
36+
/// Called before each and every test
37+
void setUp() {}
38+
39+
void test_zwapi_connection_tx_invalid_payload_full()
40+
{
41+
uint8_t cmd = 0x01;
42+
uint8_t type = 0x02;
43+
uint8_t buffer [0xFF] = {0}; ///< Maximum of len type
44+
uint8_t len = sizeof(buffer);
45+
bool ack_needed = true;
46+
47+
// Expect the function to detect overflow
48+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
49+
}
50+
51+
void test_zwapi_connection_tx_valid_inputs()
52+
{
53+
uint8_t cmd = 0x01;
54+
uint8_t type = 0x02;
55+
uint8_t buffer[10]
56+
= {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0};
57+
uint8_t len = sizeof(buffer);
58+
bool ack_needed = true;
59+
60+
// Expect the function to execute without errors
61+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
62+
}
63+
64+
void test_zwapi_connection_tx_null_buffer()
65+
{
66+
uint8_t cmd = 0x01;
67+
uint8_t type = 0x02;
68+
uint8_t *buffer = NULL;
69+
uint8_t len = 0;
70+
bool ack_needed = true;
71+
72+
// Expect the function to not crash
73+
zwapi_connection_tx(cmd, type, buffer, len, ack_needed);
74+
}

0 commit comments

Comments
 (0)