18
18
#include <mgmt/mcumgr/transport/smp_internal.h>
19
19
#include "smp_transport_stub.h"
20
20
21
- static struct net_buf * buf [5 ];
22
-
23
21
static uint32_t testing_user_data ;
24
22
static void * response_ptr ;
25
23
static struct net_buf * res_buf ;
@@ -35,9 +33,10 @@ int smp_client_res_cb(struct net_buf *nb, void *user_data)
35
33
ZTEST (smp_client , test_buf_alloc )
36
34
{
37
35
struct smp_client_object smp_client ;
36
+ struct net_buf * buf [5 ];
38
37
39
38
/* Allocate all 4 buffer's and verify that 5th fail */
40
- for (int i = 0 ; i < 5 ; i ++ ) {
39
+ for (int i = 0 ; i < ARRAY_SIZE ( buf ) ; i ++ ) {
41
40
buf [i ] = smp_client_buf_allocation (& smp_client , MGMT_GROUP_ID_IMAGE , 1 ,
42
41
MGMT_OP_WRITE , SMP_MCUMGR_VERSION_1 );
43
42
if (i == 4 ) {
@@ -50,9 +49,11 @@ ZTEST(smp_client, test_buf_alloc)
50
49
}
51
50
}
52
51
53
- for (int i = 0 ; i < 4 ; i ++ ) {
54
- smp_client_buf_free (buf [i ]);
55
- buf [i ] = NULL ;
52
+ for (int i = 0 ; i < ARRAY_SIZE (buf ); i ++ ) {
53
+ if (buf [i ]) {
54
+ smp_client_buf_free (buf [i ]);
55
+ buf [i ] = NULL ;
56
+ }
56
57
}
57
58
}
58
59
@@ -75,33 +76,34 @@ ZTEST(smp_client, test_msg_send_timeout)
75
76
ZTEST (smp_client , test_msg_response_handler )
76
77
{
77
78
struct smp_hdr dst_hdr ;
79
+ struct net_buf * a , * b ;
78
80
int rc ;
79
81
80
82
81
83
response_ptr = NULL ;
82
84
res_buf = NULL ;
83
85
84
- buf [ 0 ] = smp_client_buf_allocation (& smp_client , MGMT_GROUP_ID_IMAGE , 1 , MGMT_OP_WRITE ,
86
+ a = smp_client_buf_allocation (& smp_client , MGMT_GROUP_ID_IMAGE , 1 , MGMT_OP_WRITE ,
85
87
SMP_MCUMGR_VERSION_1 );
86
- zassert_not_null (buf [ 0 ] , "Buffer was Null" );
87
- rc = smp_client_send_cmd (& smp_client , buf [ 0 ] , smp_client_res_cb , & testing_user_data , 8 );
88
+ zassert_not_null (a , "Buffer was Null" );
89
+ rc = smp_client_send_cmd (& smp_client , a , smp_client_res_cb , & testing_user_data , 8 );
88
90
zassert_equal (MGMT_ERR_EOK , rc , "Expected to receive %d response %d" , MGMT_ERR_EOK , rc );
89
- buf [ 1 ] = smp_client_buf_allocation (& smp_client , MGMT_GROUP_ID_IMAGE , 1 , MGMT_OP_WRITE ,
91
+ b = smp_client_buf_allocation (& smp_client , MGMT_GROUP_ID_IMAGE , 1 , MGMT_OP_WRITE ,
90
92
SMP_MCUMGR_VERSION_1 );
91
- zassert_not_null (buf [ 0 ] , "Buffer was Null" );
93
+ zassert_not_null (b , "Buffer was Null" );
92
94
/* Read Pushed packet Header */
93
- smp_transport_read_hdr (buf [ 0 ] , & dst_hdr );
94
- smp_client_single_response (buf [ 1 ] , & dst_hdr );
95
+ smp_transport_read_hdr (a , & dst_hdr );
96
+ smp_client_single_response (b , & dst_hdr );
95
97
zassert_is_null (res_buf , "NULL pointer was not returned" );
96
98
zassert_is_null (response_ptr , "NULL pointer was not returned" );
97
99
/* Set Correct OP */
98
100
dst_hdr .nh_op = MGMT_OP_WRITE_RSP ;
99
- smp_client_single_response (buf [ 1 ] , & dst_hdr );
100
- zassert_equal_ptr (res_buf , buf [ 1 ] , "Response Buf not correct" );
101
+ smp_client_single_response (b , & dst_hdr );
102
+ zassert_equal_ptr (res_buf , b , "Response Buf not correct" );
101
103
zassert_equal_ptr (response_ptr , & testing_user_data , "User data not returned correctly" );
102
104
response_ptr = NULL ;
103
105
res_buf = NULL ;
104
- smp_client_single_response (buf [ 1 ] , & dst_hdr );
106
+ smp_client_single_response (b , & dst_hdr );
105
107
zassert_is_null (res_buf , "NULL pointer was not returned" );
106
108
zassert_is_null (response_ptr , "NULL pointer was not returned" );
107
109
}
@@ -114,15 +116,5 @@ static void *setup_custom_os(void)
114
116
return NULL ;
115
117
}
116
118
117
- static void cleanup_test (void * p )
118
- {
119
- for (int i = 0 ; i < 5 ; i ++ ) {
120
- if (buf [i ]) {
121
- smp_client_buf_free (buf [i ]);
122
- buf [i ] = NULL ;
123
- }
124
- }
125
- }
126
-
127
119
/* Main test set */
128
- ZTEST_SUITE (smp_client , NULL , setup_custom_os , NULL , cleanup_test , NULL );
120
+ ZTEST_SUITE (smp_client , NULL , setup_custom_os , NULL , NULL , NULL );
0 commit comments