summaryrefslogtreecommitdiff
path: root/test/regression/dhcp_test/netx_dhcp_client_nxe_api_test.c
blob: f7784489e13f6a864f5bacf2f612be0559ef835a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/


#include   "tx_api.h"
#include   "nx_api.h"

extern void    test_control_return(UINT status);

#if !defined(NX_DISABLE_ERROR_CHECKING) && defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_IPV4)
#include   "nxd_dhcp_client.h"
#include   "nxd_dhcp_server.h"

#define     DEMO_STACK_SIZE             4096
#define     NX_PACKET_SIZE              1536
#define     NX_PACKET_POOL_SIZE         NX_PACKET_SIZE * 8

#define     NX_DHCP_SERVER_IP_ADDRESS_0 IP_ADDRESS(10,0,0,1)   
#define     START_IP_ADDRESS_LIST_0     IP_ADDRESS(10,0,0,10)
#define     END_IP_ADDRESS_LIST_0       IP_ADDRESS(10,0,0,19)

#define     NX_DHCP_SUBNET_MASK_0       IP_ADDRESS(255,255,255,0)
#define     NX_DHCP_DEFAULT_GATEWAY_0   IP_ADDRESS(10,0,0,1)
#define     NX_DHCP_DNS_SERVER_0        IP_ADDRESS(10,0,0,1)
static NX_IP ip_0;
static NX_DHCP dhcp_client;
static NX_PACKET_POOL pool_0;
static NX_PACKET_POOL pool_1;
ULONG  stack_area[100];

static void error_checking_test(void);
extern volatile ULONG _tx_thread_system_state;
extern TX_THREAD *_tx_thread_current_ptr;
extern TX_THREAD _tx_timer_thread;

extern void    _nx_ram_network_driver_1024(struct NX_IP_DRIVER_STRUCT *driver_req);

#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void    netx_dhcp_client_nxe_api_test_application_define(void *first_unused_memory)
#endif
{

static CHAR                    *pointer;

    printf("NetX Test:   DHCP Client Error Checking  Test..........................");

    /* Create an IP instance for the DHCP Client.  */
    pointer =  (CHAR *) first_unused_memory;

    /* Initialize the NetX system.  */
    nx_system_initialize();

    nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1024, pointer, NX_PACKET_POOL_SIZE);
    pointer = pointer + NX_PACKET_POOL_SIZE;
    nx_ip_create(&ip_0, "DHCP Client", IP_ADDRESS(0, 0, 0, 0), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_1024, pointer, 2048, 1);

    
    _tx_thread_system_state = 0;    
    error_checking_test();
    _tx_thread_system_state = 1;
    error_checking_test();
    _tx_thread_system_state = 0;
    _tx_thread_current_ptr = TX_NULL;
    error_checking_test();
    _tx_thread_current_ptr = &_tx_timer_thread;
    error_checking_test();

    printf("SUCCESS!\n");
    test_control_return(0);    

}

static void error_checking_test(void)
{


UINT    status;
UCHAR   buf[4];
ULONG   val_ulong;

    /* Test _nxe_dhcp_create */
    _nxe_dhcp_create(0, 0, NX_NULL);
    ip_0.nx_ip_id = 0;
    _nxe_dhcp_create(0, &ip_0, NX_NULL);
    ip_0.nx_ip_id = NX_IP_ID;
    _nxe_dhcp_create(0, &ip_0, NX_NULL);
    

    /* Test _nxe_dhcp_clear_broadcast_flag */
    _nxe_dhcp_clear_broadcast_flag(NX_NULL, 0);

    /* Test _nxe_dhcp_interface_clear_broadcast_flag */
    _nxe_dhcp_interface_clear_broadcast_flag(NX_NULL, 0, 0);
    _nxe_dhcp_interface_clear_broadcast_flag(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES, 0);

    
    /* Test _nxe_dhcp_packet_pool_set */
    _nxe_dhcp_packet_pool_set(&dhcp_client, NX_NULL);
    _nxe_dhcp_packet_pool_set(NX_NULL, NX_NULL);
    pool_1.nx_packet_pool_payload_size = 0;
    _nxe_dhcp_packet_pool_set(&dhcp_client, &pool_1);

    /* Test _nxe_dhcp_reinitialize */
    _nxe_dhcp_reinitialize(NX_NULL);

    /* Test _nxe_dhcp_interface_reinitialize */
    _nxe_dhcp_interface_reinitialize(NX_NULL, 0);
    _nxe_dhcp_interface_reinitialize(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);

    /* This one shall fail at "NX_THREADS_ONLY_CALLER_CHECKING */
    _nxe_dhcp_interface_reinitialize(&dhcp_client, 0); 

    /* Test _nxe_dhcp_request_client_ip */
    _nxe_dhcp_request_client_ip(NX_NULL, 0, 0);
    _nxe_dhcp_request_client_ip(&dhcp_client, NX_BOOTP_NO_ADDRESS, 0);

    /* Test _nxe_dhcp_interface_request_client_ip */
    _nxe_dhcp_interface_request_client_ip(NX_NULL, 0, 0, 0);
    _nxe_dhcp_interface_request_client_ip(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES, 0, 0);

    /* Test _nxe_dhcp_delete */
    _nxe_dhcp_delete(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_delete(&dhcp_client);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_delete(&dhcp_client);

    /* Test _nxe_dhcp_force_renew */
    _nxe_dhcp_force_renew(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_force_renew(&dhcp_client);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_force_renew(&dhcp_client);

    /* Test _nxe_dhcp_interface_force_renew */
    _nxe_dhcp_interface_force_renew(NX_NULL, 0);
    _nxe_dhcp_interface_force_renew(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);

    /* Test _nxe_dhcp_decline */
    _nxe_dhcp_decline(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_decline(&dhcp_client);    
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_decline(&dhcp_client);    


    /* Test _nxe_dhcp_interface_decline */
    _nxe_dhcp_interface_decline(NX_NULL, 0);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_interface_decline(&dhcp_client, 0);    
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_interface_decline(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);    
    _nxe_dhcp_interface_decline(&dhcp_client, 0);    

    /* Test _nxe_dhcp_release */
    _nxe_dhcp_release(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_release(&dhcp_client);    
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_release(&dhcp_client);    

    /* _nxe_dhcp_interface_release */
    _nxe_dhcp_interface_release(NX_NULL, 0);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_interface_release(&dhcp_client,  0);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_interface_release(&dhcp_client,  NX_MAX_PHYSICAL_INTERFACES);
    _nxe_dhcp_interface_release(&dhcp_client,  0);

    /* Test _nxe_dhcp_start */
    _nxe_dhcp_start(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_start(&dhcp_client);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_start(&dhcp_client);

    /* Test _nxe_dhcp_interface_start */
    _nxe_dhcp_interface_start(NX_NULL, 0);
    _nxe_dhcp_interface_start(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);
    _nxe_dhcp_interface_start(&dhcp_client, 0);

    /* Test _nxe_dhcp_interface_enable */
    _nxe_dhcp_interface_enable(NX_NULL, 0);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_interface_enable(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);


    /* Test _nxe_dhcp_interface_disable */
    _nxe_dhcp_interface_disable(NX_NULL, 0);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_interface_disable(&dhcp_client, 0);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_interface_disable(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);

    /* Test _nxe_dhcp_state_change_notify */
    _nxe_dhcp_state_change_notify(NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = 0;    
    _nxe_dhcp_state_change_notify(&dhcp_client, NX_NULL);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;    
    _nxe_dhcp_state_change_notify(&dhcp_client, NX_NULL);

    /* _nxe_dhcp_interface_state_change_notify */
    _nxe_dhcp_interface_state_change_notify(NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = 0;    
    _nxe_dhcp_interface_state_change_notify(&dhcp_client, NX_NULL);

    /* Test _nxe_dhcp_stop */
//    nx_dhcp_create(&dhcp_client, &ip_0, "dhcp_client");
    _nxe_dhcp_stop(NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_stop(&dhcp_client);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_stop(&dhcp_client);
//    nx_dhcp_delete(&dhcp_client);


    /* Test _nxe_dhcp_interface_stop  */
    _nxe_dhcp_interface_stop(NX_NULL, 0);
    _nxe_dhcp_interface_stop(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);
    _nxe_dhcp_interface_stop(&dhcp_client, 0);

    /* Test _nxe_dhcp_user_option_retrieve */
    _nxe_dhcp_user_option_retrieve(NX_NULL, 0, NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_user_option_retrieve(&dhcp_client, 0, NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;    
    _nxe_dhcp_user_option_retrieve(&dhcp_client, 0, NX_NULL, NX_NULL);
    _nxe_dhcp_user_option_retrieve(&dhcp_client, 0, buf, NX_NULL);
    status = sizeof(buf);
    _nxe_dhcp_user_option_retrieve(&dhcp_client, 0, buf, &status);

    /* Test _nxe_dhcp_user_option_request */
    _nxe_dhcp_user_option_request(NX_NULL, 0);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_user_option_request(&dhcp_client, 0);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_user_option_request(&dhcp_client, 0);
    
    /* Test _nxe_dhcp_interface_user_option_retrieve */
    _nxe_dhcp_interface_user_option_retrieve(NX_NULL, 0, 0, NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
    _nxe_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, NX_NULL, NX_NULL);
    _nxe_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buf, NX_NULL);
    _nxe_dhcp_interface_user_option_retrieve(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES, 0, buf, &status);
    _nxe_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buf, &status);

    /* Test _nxe_dhcp_user_option_convert */
    _nxe_dhcp_user_option_convert(NX_NULL);

    /* Test _nxe_dhcp_user_option_add_callback_set */
    _nxe_dhcp_user_option_add_callback_set(NX_NULL, NX_NULL);
    dhcp_client.nx_dhcp_id = 0;
    _nxe_dhcp_user_option_add_callback_set(&dhcp_client, NX_NULL);

    /* Test _nxe_dhcp_server_address_get */
    _nxe_dhcp_server_address_get(NX_NULL, NX_NULL);
    _nxe_dhcp_server_address_get(&dhcp_client, NX_NULL);
    _nxe_dhcp_server_address_get(&dhcp_client, &val_ulong);

    /* Test _nxe_dhcp_interface_server_address_get */
    _nxe_dhcp_interface_server_address_get(NX_NULL, 0, NX_NULL);
    _nxe_dhcp_interface_server_address_get(&dhcp_client, 0, NX_NULL);
    _nxe_dhcp_interface_server_address_get(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES, &val_ulong);
    _nxe_dhcp_interface_server_address_get(&dhcp_client, 0, &val_ulong);
    

    /* Test _nxe_dhcp_set_interface_index  */
    _nxe_dhcp_set_interface_index(NX_NULL, 0);
    _nxe_dhcp_set_interface_index(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES);

    /* Test _nxe_dhcp_send_request */
    _nxe_dhcp_send_request(NX_NULL, 0);
    _nxe_dhcp_send_request(&dhcp_client, 0);
    _nxe_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPFORCERENEW + 1);

    /* Test _nxe_dhcp_interface_send_request*/
    nx_dhcp_interface_send_request(NX_NULL, 0, 0);
    nx_dhcp_interface_send_request(&dhcp_client, NX_MAX_PHYSICAL_INTERFACES + 1, 0);
    nx_dhcp_interface_send_request(&dhcp_client, 0, 0);

    dhcp_client.nx_dhcp_id = NX_DHCP_ID;
}
#else

#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void    netx_dhcp_client_nxe_api_test_application_define(void *first_unused_memory)
#endif
{

static CHAR                    *pointer;

    printf("NetX Test:   DHCP Client Error Checking  Test..........................N/A\n");

    test_control_return(3);
}
#endif