1 /* This NetX test concentrates on the basic packet operations. */
2
3 #include "tx_api.h"
4 #include "nx_api.h"
5 #include "nx_packet.h"
6
7 #define DEMO_STACK_SIZE 2048
8
9 #define TEST_SIZE (NX_UDP_PACKET+28)
10
11 #ifndef NX_PACKET_ALIGNMENT
12 #define NX_PACKET_ALIGNMENT sizeof(ULONG)
13 #endif /* NX_PACKET_ALIGNMENT */
14
15 /* Define the ThreadX and NetX object control blocks... */
16
17 static TX_THREAD ntest_0;
18 static NX_PACKET_POOL pool_0;
19
20
21 /* Define the counters used in the test application... */
22
23 static ULONG error_counter;
24 #if !defined(NX_DISABLE_PACKET_CHAIN) && defined(__PRODUCT_NETXDUO__)
25 static UCHAR buffer[2048];
26 #endif
27
28 /* Define thread prototypes. */
29
30 static void ntest_0_entry(ULONG thread_input);
31 extern void test_control_return(UINT status);
32
33 /* Define what the initial system looks like. */
34
35 #ifdef CTEST
test_application_define(void * first_unused_memory)36 VOID test_application_define(void *first_unused_memory)
37 #else
38 void netx_packet_data_append_test_application_define(void *first_unused_memory)
39 #endif
40 {
41
42 CHAR *pointer;
43 UINT status;
44
45
46 /* Setup the working pointer. */
47 pointer = (CHAR *) first_unused_memory;
48
49 error_counter = 0;
50
51 /* Create the main thread. */
52 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
53 pointer, DEMO_STACK_SIZE,
54 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
55 pointer = pointer + DEMO_STACK_SIZE;
56
57 /* Initialize the NetX system. */
58 nx_system_initialize();
59
60 /* Create the pools again. */
61 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", TEST_SIZE, pointer, (TEST_SIZE + sizeof(NX_PACKET)) * 10);
62 pointer = pointer + ((TEST_SIZE + sizeof(NX_PACKET)) * 10);
63
64 /* Check status */
65 if (status)
66 error_counter++;
67 }
68
69
70
71 /* Define the test threads. */
72
ntest_0_entry(ULONG thread_input)73 static void ntest_0_entry(ULONG thread_input)
74 {
75
76 #if !defined(NX_DISABLE_PACKET_CHAIN) && defined(__PRODUCT_NETXDUO__)
77 UINT status;
78 NX_PACKET *my_packet;
79 #endif /* !defined(NX_DISABLE_PACKET_CHAIN) && defined(__PRODUCT_NETXDUO__) */
80
81 /* Print out test information banner. */
82 printf("NetX Test: Packet Data Append Test...................................");
83
84 /* Check for earlier error. */
85 if (error_counter)
86 {
87
88 printf("ERROR!\n");
89 test_control_return(1);
90 }
91
92 #if !defined(NX_DISABLE_PACKET_CHAIN) && defined(__PRODUCT_NETXDUO__)
93
94 /* Allocate the packet. */
95 status = nx_packet_allocate(&pool_0, &my_packet, 0, NX_NO_WAIT);
96
97 /* Check for error. */
98 if (status)
99 {
100
101 printf("ERROR!\n");
102 test_control_return(1);
103 }
104
105 /* Append data that is two packet size. */
106 status = nx_packet_data_append(my_packet, buffer, TEST_SIZE * 4, &pool_0, NX_NO_WAIT);
107
108 /* Check the status. */
109 if(status)
110 {
111
112 printf("ERROR!\n");
113 test_control_return(1);
114 }
115
116 /* Release the packet. */
117 status = nx_packet_release(my_packet);
118
119 /* Check the status. */
120 if(status)
121 {
122
123 printf("ERROR!\n");
124 test_control_return(1);
125 }
126 #endif
127
128 printf("SUCCESS!\n");
129 test_control_return(0);
130 }
131
132