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
|
/***************************************************************************/
/* 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 */
/***************************************************************************/
/* NetX DNS Client API error tests. */
#include "tx_api.h"
#include "nx_api.h"
#include "nx_udp.h"
#include "nx_ip.h"
#include "nxd_dns.h"
extern void test_control_return(UINT status);
#if !defined(NX_DISABLE_IPV4)
/* DNS Client Error Checking Test. */
static void error_checking_test(void);
static NX_IP ip_0;
static NX_DNS dns_0;
static UCHAR temp_uchar;
static UINT temp_uint;
static ULONG temp_ulong;
static USHORT temp_ushort;
static USHORT temp_ushort2; // we need a second ushort to make sure this one is not 32 bit aligned
#ifdef __PRODUCT_NETXDUO__
static NXD_ADDRESS address_0;
#endif
extern volatile ULONG _tx_thread_system_state;
extern TX_THREAD *_tx_thread_current_ptr;
extern TX_THREAD _tx_timer_thread;
/* Define what the initial system looks like. */
#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void netx_dns_nxe_api_test_application_define(void *first_unused_memory)
#endif
{
printf("NetX Test: DNS Client Error Checking Test..........................\n");
static CHAR *pointer;
/* Setup the working pointer. */
pointer = (CHAR *) first_unused_memory;
error_checking_test();
printf("SUCCESS!\n");
test_control_return(0);
}
#define validate_expected_status(status,expected_status) if (expected_status != status) {printf("%s,%d: ERROR!",__FILE__, __LINE__);test_control_return(1);}
static void nxe_dns_server_add_remove_error_check_test(NX_DNS *dns_ptr, ULONG server_address, UINT expected_status)
{
//_nxe_dns_server_add(NX_DNS *dns_ptr, ULONG server_address)
validate_expected_status(_nxe_dns_server_add(dns_ptr, server_address), expected_status);
//_nxe_dns_server_remove(NX_DNS *dns_ptr, ULONG server_address)
validate_expected_status(_nxe_dns_server_remove(dns_ptr, server_address), expected_status);
//_nxe_dns_server_remove_all(NX_DNS *dns_ptr)
if (expected_status != NX_DNS_BAD_ADDRESS_ERROR) {
validate_expected_status(_nxe_dns_server_remove_all(dns_ptr), expected_status);
}
}
#ifdef __PRODUCT_NETXDUO__
static void nxde_address_error_checks() {
dns_0.nx_dns_id = NX_DNS_ID;
address_0.nxd_ip_version = NX_NULL;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_DNS_PARAM_ERROR);
address_0.nxd_ip_version = 0x1;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_DNS_INVALID_ADDRESS_TYPE);
validate_expected_status(_nxde_dns_server_remove(&dns_0, &address_0), NX_DNS_INVALID_ADDRESS_TYPE);
address_0.nxd_ip_version = NX_IP_VERSION_V4;
address_0.nxd_ip_address.v4 = 0;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_DNS_BAD_ADDRESS_ERROR);
validate_expected_status(_nxde_dns_server_remove(&dns_0, &address_0), NX_DNS_BAD_ADDRESS_ERROR);
#ifdef FEATURE_NX_IPV6
address_0.nxd_ip_version = NX_IP_VERSION_V6;
address_0.nxd_ip_address.v6[0] = 0;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_DNS_BAD_ADDRESS_ERROR);
validate_expected_status(_nxde_dns_server_remove(&dns_0, &address_0), NX_DNS_BAD_ADDRESS_ERROR);
#endif
}
#endif
static void nx_dns_id_calls(void)
{
validate_expected_status(_nxe_dns_delete(&dns_0), NX_CALLER_ERROR);
nxe_dns_server_add_remove_error_check_test(&dns_0, 1, NX_CALLER_ERROR);
validate_expected_status(_nxe_dns_get_serverlist_size(&dns_0, &temp_uint), NX_CALLER_ERROR);
validate_expected_status(_nxe_dns_server_get(&dns_0, 0, &temp_ulong), NX_CALLER_ERROR);
validate_expected_status(_nxe_dns_host_by_name_get(&dns_0, &temp_uchar, &temp_ulong, 1), NX_CALLER_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_CALLER_ERROR);
validate_expected_status(_nxe_dns_host_by_address_get(&dns_0, 1, &temp_uchar, 1, 1), NX_CALLER_ERROR);
#ifdef __PRODUCT_NETXDUO__
#ifdef FEATURE_NX_IPV6
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_CALLER_ERROR);
validate_expected_status(_nxde_dns_host_by_address_get(&dns_0, &address_0, &temp_uchar, 1, 1), NX_CALLER_ERROR);
address_0.nxd_ip_version = NX_IP_VERSION_V6;
address_0.nxd_ip_address.v6[0] = 13;
address_0.nxd_ip_address.v6[1] = 14;
address_0.nxd_ip_address.v6[2] = 13;
address_0.nxd_ip_address.v6[3] = 14;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_CALLER_ERROR);
#endif
address_0.nxd_ip_version = NX_IP_VERSION_V4;
address_0.nxd_ip_address.v4 = 1314;
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_CALLER_ERROR);
validate_expected_status(_nxde_dns_server_remove(&dns_0, &address_0), NX_CALLER_ERROR);
validate_expected_status(_nxde_dns_server_get(&dns_0, 0, &address_0), NX_CALLER_ERROR);
validate_expected_status(_nxde_dns_host_by_name_get(&dns_0, &temp_uchar, &address_0, 0, 1), NX_CALLER_ERROR);
#endif
}
static void error_checking_test(void)
{
validate_expected_status(_nxe_dns_create(NX_NULL, NX_NULL, NX_NULL), NX_PTR_ERROR);
#ifdef NX_DNS_CLIENT_USER_CREATE_PACKET_POOL
validate_expected_status(_nxe_dns_packet_pool_set(NX_NULL, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_packet_pool_set(&dns_0, NX_NULL), NX_PTR_ERROR);
#endif
validate_expected_status(_nxe_dns_delete(NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_get_serverlist_size(NX_NULL, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_server_get(NX_NULL, 0, NX_NULL), NX_PTR_ERROR);
nxe_dns_server_add_remove_error_check_test(NX_NULL, 1, NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_name_get(NX_NULL, NX_NULL, NX_NULL, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_name_get(&dns_0, NX_NULL, NX_NULL, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_name_get(&dns_0, &temp_uchar, NX_NULL, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(NX_NULL, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, NX_NULL, (void*)&temp_ulong, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, &temp_uchar, NX_NULL, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, NX_NULL, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_address_get(NX_NULL, 1, &temp_uchar, 1, 1), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_address_get(&dns_0, 1, NX_NULL, 1, 1), NX_PTR_ERROR);
#ifdef __PRODUCT_NETXDUO__
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(NX_NULL, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, NX_NULL, (void*)&temp_ulong, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, &temp_uchar, NX_NULL, 1, &temp_uint, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, NX_NULL, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_address_get(NX_NULL, &address_0, &temp_uchar, 1, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_address_get(&dns_0, NX_NULL, &temp_uchar, 1, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_address_get(&dns_0, &address_0, NX_NULL, 1, 1), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_add(NX_NULL, &address_0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_add(&dns_0, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_remove(NX_NULL, &address_0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_remove(&dns_0, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_get(NX_NULL, 0, &address_0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_get(&dns_0, 0, NX_NULL), NX_PTR_ERROR);
//_nxde_dns_host_by_name_get(NX_DNS *dns_ptr, UCHAR *host_name, NXD_ADDRESS *host_address_ptr, ULONG wait_option, UINT lookup_type)
validate_expected_status(_nxde_dns_host_by_name_get(NX_NULL, &temp_uchar, &address_0, 0, 0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_name_get(&dns_0, NX_NULL, &address_0, 0, 0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_name_get(&dns_0, &temp_uchar, NX_NULL, 0, 0), NX_PTR_ERROR);
nxde_address_error_checks();
#endif
ip_0.nx_ip_id = 0;
validate_expected_status(_nxe_dns_create(NX_NULL, &ip_0, NX_NULL), NX_PTR_ERROR);
ip_0.nx_ip_id = NX_IP_ID;
validate_expected_status(_nxe_dns_create(NX_NULL, &ip_0, NX_NULL), NX_PTR_ERROR);
dns_0.nx_dns_id = NX_DNS_ID;
validate_expected_status(_nxe_dns_host_by_address_get(&dns_0, 0, &temp_uchar, 1, 1), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxe_dns_host_by_address_get(&dns_0, 1, &temp_uchar, 0, 1), NX_DNS_PARAM_ERROR);
#ifdef __PRODUCT_NETXDUO__
validate_expected_status(_nxde_dns_host_by_address_get(&dns_0, &address_0, &temp_uchar, 0, 1), NX_DNS_PARAM_ERROR);
#endif
validate_expected_status(_nxe_dns_create(&dns_0, &ip_0, NX_NULL), NX_PTR_ERROR);
// Alignment check tests
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ushort2 - 1, 1, &temp_uint, 1), NX_PTR_ERROR);
#ifdef __PRODUCT_NETXDUO__
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ushort2 - 1, 1, &temp_uint, 1), NX_PTR_ERROR);
#endif
nxe_dns_server_add_remove_error_check_test(&dns_0, 0, NX_DNS_BAD_ADDRESS_ERROR);
validate_expected_status(_nxe_dns_get_serverlist_size(&dns_0, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_server_get(&dns_0, 0, NX_NULL), NX_PTR_ERROR);
// apis that require requires nx_dns_id == NX_DNS_ID for the thread state tests
_tx_thread_system_state = 1;
nx_dns_id_calls();
_tx_thread_system_state = 0;
_tx_thread_current_ptr = TX_NULL;
nx_dns_id_calls();
_tx_thread_current_ptr = &_tx_timer_thread;
nx_dns_id_calls();
#ifdef __PRODUCT_NETXDUO__
validate_expected_status(_nxde_dns_host_by_name_get(&dns_0, &temp_uchar, &address_0, 0, 0), NX_DNS_PARAM_ERROR);
#endif
dns_0.nx_dns_id = 0;
validate_expected_status(_nxe_dns_delete(&dns_0), NX_PTR_ERROR);
nxe_dns_server_add_remove_error_check_test(&dns_0, 1, NX_PTR_ERROR);
validate_expected_status(_nxe_dns_get_serverlist_size(&dns_0, 0), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_server_get(&dns_0, 0, NX_NULL), NX_PTR_ERROR);
validate_expected_status(_nxe_dns_host_by_name_get(&dns_0, &temp_uchar, &temp_ulong, 1), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxe_dns_ipv4_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxe_dns_host_by_address_get(&dns_0, 1, &temp_uchar, 1, 1), NX_DNS_PARAM_ERROR);
#ifdef __PRODUCT_NETXDUO__
validate_expected_status(_nxde_dns_ipv6_address_by_name_get(&dns_0, &temp_uchar, (void*)&temp_ulong, 1, &temp_uint, 1), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxde_dns_host_by_address_get(&dns_0, &address_0, &temp_uchar, 1, 1), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxde_dns_server_add(&dns_0, &address_0), NX_DNS_PARAM_ERROR);
validate_expected_status(_nxde_dns_server_remove(&dns_0, &address_0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_server_get(&dns_0, 0, &address_0), NX_PTR_ERROR);
validate_expected_status(_nxde_dns_host_by_name_get(&dns_0, &temp_uchar, &address_0, 0, 1), NX_DNS_PARAM_ERROR);
#endif
// apis that require requires nx_dns_id == 0 for the thread state tests
_tx_thread_system_state = 1;
validate_expected_status(_nxe_dns_create(&dns_0, &ip_0, NX_NULL), NX_CALLER_ERROR);
_tx_thread_system_state = 0;
_tx_thread_current_ptr = TX_NULL;
validate_expected_status(_nxe_dns_create(&dns_0, &ip_0, NX_NULL), NX_CALLER_ERROR);
_tx_thread_current_ptr = &_tx_timer_thread;
validate_expected_status(_nxe_dns_create(&dns_0, &ip_0, NX_NULL), NX_CALLER_ERROR);
}
#else
#ifdef CTEST
VOID test_application_define(void *first_unused_memory)
#else
void netx_dns_api_error_test_application_define(void *first_unused_memory)
#endif
{
/* Print out test information banner. */
printf("NetX Test: DNS Client Error Checking Test.......................N/A\n");
test_control_return(3);
}
#endif
|