1 /* This NetX test concentrates on the IGMP join fails when driver returns error. */
2
3 #include "tx_api.h"
4 #include "nx_api.h"
5
6 extern void test_control_return(UINT status);
7
8 #if !defined(NX_DISABLE_IPV4)
9
10 #define DEMO_STACK_SIZE 2048
11
12
13 /* Define the ThreadX and NetX object control blocks... */
14
15 static TX_THREAD ntest_0;
16
17 static NX_PACKET_POOL pool_0;
18 static NX_IP ip_0;
19
20
21 /* Define the counters used in the test application... */
22
23 static ULONG error_counter;
24 static UINT available;
25
26
27 /* Define thread prototypes. */
28
29 static void ntest_0_entry(ULONG thread_input);
30 extern void _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
31 static void test_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
32
33
34 /* Define what the initial system looks like. */
35
36 #ifdef CTEST
test_application_define(void * first_unused_memory)37 VOID test_application_define(void *first_unused_memory)
38 #else
39 void netx_igmp_join_fail_test_application_define(void *first_unused_memory)
40 #endif
41 {
42
43 CHAR *pointer;
44 UINT status;
45
46
47 /* Setup the working pointer. */
48 pointer = (CHAR *) first_unused_memory;
49
50 error_counter = 0;
51 available = NX_TRUE;
52
53 /* Create the main thread. */
54 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
55 pointer, DEMO_STACK_SIZE,
56 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
57 pointer = pointer + DEMO_STACK_SIZE;
58
59 /* Initialize the NetX system. */
60 nx_system_initialize();
61
62 /* Create a packet pool. */
63 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
64 pointer = pointer + 8192;
65
66 if (status)
67 error_counter++;
68
69 /* Create an IP instance. */
70 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, test_driver,
71 pointer, 2048, 1);
72 pointer = pointer + 2048;
73
74 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
75 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
76 pointer = pointer + 1024;
77 if (status)
78 error_counter++;
79
80 /* Enable IGMP processing for both this IP instance. */
81 status = nx_igmp_enable(&ip_0);
82
83 /* Check enable status. */
84 if (status)
85 error_counter++;
86 }
87
88
89
90 /* Define the test threads. */
91
ntest_0_entry(ULONG thread_input)92 static void ntest_0_entry(ULONG thread_input)
93 {
94
95 UINT status;
96
97
98 /* Print out test information banner. */
99 printf("NetX Test: IGMP Join Fail Test.......................................");
100
101 /* Check for earlier error. */
102 if (error_counter)
103 {
104
105 printf("ERROR!\n");
106 test_control_return(1);
107 }
108
109 /* Set available to false. */
110 available = NX_FALSE;
111
112 /* Perform IGMP join operations. */
113 status = nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,1));
114
115 /* Determine if there is an error. */
116 if (status != NX_NO_MORE_ENTRIES)
117 {
118
119 printf("ERROR!\n");
120 test_control_return(1);
121 }
122
123 /* Set available to true. */
124 available = NX_TRUE;
125
126 /* Perform IGMP join operations. */
127 status = nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224,0,0,1));
128
129 /* Determine if there is an error. */
130 if (status != NX_SUCCESS)
131 {
132
133 printf("ERROR!\n");
134 test_control_return(1);
135 }
136
137 /* Now leave the group to make sure that processing works properly. */
138 status = nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224,0,0,1));
139
140 /* Determine if there is an error. */
141 if (status)
142 {
143
144 printf("ERROR!\n");
145 test_control_return(1);
146 }
147
148 printf("SUCCESS!\n");
149 test_control_return(0);
150 }
151
152
test_driver(struct NX_IP_DRIVER_STRUCT * driver_req)153 static void test_driver(struct NX_IP_DRIVER_STRUCT *driver_req)
154 {
155 if ((driver_req -> nx_ip_driver_command == NX_LINK_MULTICAST_JOIN) &&
156 (available == NX_FALSE))
157 {
158
159 /* Return not supported. */
160 driver_req -> nx_ip_driver_status = NX_UNHANDLED_COMMAND;
161 }
162 else
163 {
164
165 /* Pass the request to ram driver. */
166 _nx_ram_network_driver_256(driver_req);
167 }
168 }
169 #else
170
171 #ifdef CTEST
test_application_define(void * first_unused_memory)172 VOID test_application_define(void *first_unused_memory)
173 #else
174 void netx_igmp_join_fail_test_application_define(void *first_unused_memory)
175 #endif
176 {
177
178 /* Print out test information banner. */
179 printf("NetX Test: IGMP Join Fail Test.......................................N/A\n");
180
181 test_control_return(3);
182 }
183 #endif
184