]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/test/iot_test_freertos_tcp.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-Plus-TCP / test / iot_test_freertos_tcp.c
1 /*
2  * FreeRTOS+TCP V2.2.1
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25
26 /* Standard includes. */
27 #include <stdint.h>
28 #include <stdbool.h>
29 #include <string.h>
30
31 /* FreeRTOS includes. */
32 #include "FreeRTOS.h"
33 #include "list.h"
34 #include "FreeRTOS_IP.h"
35 #include "FreeRTOS_IP_Private.h"
36 #include "FreeRTOS_DNS.h"
37
38 /* Test includes. */
39 #include "unity_fixture.h"
40 #include "unity.h"
41 #include "iot_freertos_tcp_test_access_declare.h"
42
43 /**
44  * @brief Configuration for this test group.
45  */
46
47 /*
48  * @brief Test group definition.
49  */
50 TEST_GROUP( Full_FREERTOS_TCP );
51
52 TEST_SETUP( Full_FREERTOS_TCP )
53 {
54 }
55
56 TEST_TEAR_DOWN( Full_FREERTOS_TCP )
57 {
58 }
59
60 TEST_GROUP_RUNNER( Full_FREERTOS_TCP )
61 {
62     /* Run a parser test. */
63     RUN_TEST_CASE( Full_FREERTOS_TCP, prvParseDnsResponse );
64     RUN_TEST_CASE( Full_FREERTOS_TCP, ulDNSHandlePacket );
65
66     /* prvCheckOptions test. */
67     RUN_TEST_CASE( Full_FREERTOS_TCP, prvCheckOptions );
68
69     /* xProcessReceivedUDPPacket test. */
70     RUN_TEST_CASE( Full_FREERTOS_TCP, UDPPacketLength );
71 }
72
73 TEST( Full_FREERTOS_TCP, prvParseDnsResponse )
74 {
75     uint8_t ucGoodDnsResponse[] =
76     {
77         0xd7, 0x66, 0x81, 0x80, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x61, 0x33, 0x37,
78         0x62, 0x78, 0x76, 0x31, 0x63, 0x62, 0x64, 0x61, 0x33, 0x6a, 0x67, 0x03, 0x69, 0x6f, 0x74, 0x09,
79         0x75, 0x73, 0x2d, 0x77, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x09, 0x61, 0x6d, 0x61, 0x7a, 0x6f, 0x6e,
80         0x61, 0x77, 0x73, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x05,
81         0x00, 0x01, 0x00, 0x00, 0x01, 0x2c, 0x00, 0x1e, 0x0c, 0x69, 0x6f, 0x74, 0x6d, 0x6f, 0x6f, 0x6e,
82         0x72, 0x61, 0x6b, 0x65, 0x72, 0x09, 0x75, 0x73, 0x2d, 0x77, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x04,
83         0x70, 0x72, 0x6f, 0x64, 0xc0, 0x1b, 0xc0, 0x48, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0xec,
84         0x00, 0x45, 0x09, 0x64, 0x75, 0x61, 0x6c, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2a, 0x69, 0x6f, 0x74,
85         0x6d, 0x6f, 0x6f, 0x6e, 0x72, 0x61, 0x6b, 0x65, 0x72, 0x2d, 0x75, 0x2d, 0x65, 0x6c, 0x62, 0x2d,
86         0x31, 0x77, 0x38, 0x71, 0x6e, 0x77, 0x31, 0x33, 0x33, 0x36, 0x7a, 0x71, 0x2d, 0x31, 0x31, 0x38,
87         0x36, 0x33, 0x34, 0x38, 0x30, 0x39, 0x32, 0x09, 0x75, 0x73, 0x2d, 0x77, 0x65, 0x73, 0x74, 0x2d,
88         0x32, 0x03, 0x65, 0x6c, 0x62, 0xc0, 0x29, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
89         0x23, 0x00, 0x04, 0x22, 0xd3, 0x41, 0xdb, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
90         0x23, 0x00, 0x04, 0x22, 0xd3, 0x53, 0xe4, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
91         0x23, 0x00, 0x04, 0x22, 0xd3, 0xb6, 0x17, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
92         0x23, 0x00, 0x04, 0x22, 0xd6, 0xf5, 0xf0, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
93         0x23, 0x00, 0x04, 0x22, 0xd7, 0xe6, 0xa4, 0xc0, 0x72, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
94         0x23, 0x00, 0x04, 0x36, 0x95, 0x5e, 0x45
95     };
96     const uint32_t ulExpectedAddress = 0xdb41d322;
97     uint8_t ucBadDnsResponseA[] =
98     {
99         0x3b, 0x6a, 0x81, 0x83, 0x01, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x09, 0x69, 0x6e, 0x73,
100         0x70, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x08, 0x75, 0x73, 0x2d, 0x77, 0x65, 0x73, 0x74, 0x32, 0x09,
101         0x61, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x61, 0x77, 0x73, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01,
102         0x00, 0x01, 0xc0, 0x1f, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x33, 0x0e, 0x64,
103         0x6e, 0x73, 0x2d, 0x64, 0x79, 0x6e, 0x2d
104     };
105     uint8_t ucBadDnsResponseB[] =
106     {
107         0xf0, 0x23, 0x81, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
108         0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0,
109         0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x01, 0x7c, 0x00, 0x1b, 0x03, 0x77, 0x77, 0x77, 0x05,
110         0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x07, 0x65, 0x64, 0x67, 0x65, 0x6b, 0x65,
111         0x79, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2b, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x1a, 0xd5,
112         0x00, 0x2f, 0x03, 0x77, 0x77, 0x77, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d,
113         0x07, 0x65, 0x64, 0x67, 0x65, 0x6b, 0x65, 0x79, 0x03, 0x6e, 0x65, 0x74, 0x0b, 0x67, 0x6c, 0x6f,
114         0x62, 0x61, 0x6c, 0x72, 0x65, 0x64, 0x69, 0x72, 0x06, 0x61, 0x6b, 0x61, 0x64, 0x6e, 0x73, 0xc0,
115         0x41, 0xc0, 0x52, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x08, 0xb3, 0x00, 0x19, 0x05, 0x65, 0x36,
116         0x38, 0x35, 0x38, 0x05, 0x64, 0x73, 0x63, 0x65, 0x39, 0x0a, 0x61, 0x6b, 0x61, 0x6d, 0x61, 0x69,
117         0x65, 0x64, 0x67, 0x65, 0xc0, 0x41, 0xc0, 0x8d, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a,
118         0x00, 0x04, 0x17, 0x4a, 0x3e, 0x96
119     };
120     uint8_t ucBadDnsResponseC[] =
121     {
122         0x3b, 0xa3, 0x81, 0x80, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
123         0x09, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66
124     };
125     uint8_t ucBadDnsResponseD[] =
126     {
127         0x95, 0x1e, 0x81, 0x80, 0x05, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
128         0x03, 0x63, 0x6e, 0x6e, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00,
129         0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x1b, 0x0a, 0x74, 0x75, 0x72, 0x6e, 0x65, 0x72,
130         0x2d, 0x74, 0x6c, 0x73, 0x03, 0x6d, 0x61, 0x70, 0x06, 0x66, 0x61, 0x73, 0x74, 0x6c, 0x79, 0x03,
131         0x6e, 0x65, 0x74, 0x00, 0xc0, 0x29, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04,
132         0x97, 0x65, 0x35, 0x43
133     };
134     uint8_t ucBadDnsResponseE[] =
135     {
136         0xa8, 0x6d, 0x81, 0x80, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
137         0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0,
138         0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x03, 0x77, 0x77, 0x77, 0x05,
139         0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x07, 0x65, 0x64, 0x67, 0x65, 0x6b, 0x65,
140         0x79, 0x03, 0x6e, 0x65, 0x74, 0x00, 0xc0, 0x2b, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x1c, 0x2c,
141         0x00, 0x2f, 0x03, 0x77, 0x77, 0x77, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d,
142         0x07, 0x65, 0x64, 0x67, 0x65, 0x6b, 0x65, 0x79, 0x03, 0x6e, 0x65, 0x74, 0x0b, 0x67, 0x6c, 0x6f,
143         0x62, 0x61, 0x6c, 0x72, 0x65, 0x64, 0x69, 0x72, 0x06, 0x61, 0x6b, 0x61, 0x64, 0x6e, 0x73, 0xc0,
144         0x41, 0xc0, 0x52, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x03, 0xd7, 0x00, 0x19, 0x05, 0x65, 0x36,
145         0x38, 0x35, 0x38, 0x05, 0x64, 0x73, 0x63, 0x65, 0x39, 0x0a, 0x61, 0x6b, 0x61, 0x6d, 0x61, 0x69,
146         0x65, 0x64, 0x67, 0x65, 0xc0, 0x41, 0xc0, 0x8d, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08,
147         0x00, 0x04, 0x17, 0x4b, 0xba, 0x13
148     };
149     uint8_t ucBadDnsResponseF[] =
150     {
151         0x6c, 0x1e, 0x81, 0x80, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
152         0x06, 0x61, 0x6d, 0x61, 0x7a, 0x6f, 0x6e, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01,
153         0xc0, 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00, 0x01, 0x57, 0x00, 0x0a, 0x03, 0x77, 0x77, 0x77,
154         0x03, 0x63, 0x64, 0x6e, 0xc0, 0x10, 0x41, 0x41, 0xc0, 0x2c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x00,
155         0x00, 0x17, 0x00, 0x1f, 0x0e, 0x64, 0x33, 0x61, 0x67, 0x34, 0x68, 0x75, 0x6b, 0x6b, 0x68, 0x36,
156         0x32, 0x79, 0x6e, 0x0a, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x03, 0x6e,
157         0x65, 0x74, 0x00, 0xc0, 0x42, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x04, 0x0d,
158         0x20, 0xa7, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x9a, 0x3a, 0x01, 0x5c, 0x31, 0x1f, 0x00,
159         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
160         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
163         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168         0x00, 0x00, 0x00
169     };
170     uint8_t ucBadDnsResponseG[] =
171     {
172         0x73, 0xe1, 0x81, 0x80, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x77, 0x77, 0x77,
173         0x06, 0x22, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x01, 0x00,
174         0x01, 0x00, 0x00, 0x01, 0x0a, 0x00, 0x04, 0xd8, 0x3a, 0xd8, 0x84, 0x00, 0x34, 0x02, 0x41, 0x01,
175         0x2c, 0xb2, 0x1a, 0x01, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
176         0x00, 0x00, 0x00
177     };
178     uint8_t ucBadDnsResponseH[] = /* Regress crash in prvReadNameField. */
179     {
180         0x10, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00,
181         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x35,
183         0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x91, 0x91, 0x91,
184         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
185         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
186         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
187         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
188         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
189         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
190         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
191         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91,
192         0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x00, 0x00, 0x00,
193         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
195     };
196     uint8_t ucBadDnsResponseI[] = /* Regress crash in prvSkipNameField. */
197     {
198         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
199         0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
200         0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x35,
201         0x0a, 0xf8, 0xf8, 0xf8, 0x27, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8,
202         0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x16, 0x16, 0x21, 0x16,
203         0x16, 0x16, 0x16, 0x16, 0x16, 0x2a, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xf8,
204         0x27, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
205         0x00, 0x16, 0x16, 0x16, 0x16, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x16, 0x5a,
206         0x00, 0x16, 0x00, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x21
207     };
208     uint32_t ulAddress = 0;
209
210     /* Parsing a valid packet should succeed. */
211     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
212         ucGoodDnsResponse,
213         sizeof( ucGoodDnsResponse ),
214         *( uint16_t * ) ucGoodDnsResponse );
215     TEST_ASSERT_EQUAL_UINT32( ulExpectedAddress, ulAddress );
216     /* End test. */
217
218     /* Parsing a bad packet should fail gracefully. */
219     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
220         ucBadDnsResponseA,
221         sizeof( ucBadDnsResponseA ),
222         *( uint16_t * ) ucBadDnsResponseA );
223     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
224     /* End test. */
225
226     /* Parsing a bad packet should fail gracefully. */
227     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
228         ucBadDnsResponseB,
229         sizeof( ucBadDnsResponseB ),
230         *( uint16_t * ) ucBadDnsResponseB );
231     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
232     /* End test. */
233
234     /* Parsing a bad packet should fail gracefully. */
235     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
236         ucBadDnsResponseC,
237         sizeof( ucBadDnsResponseC ),
238         *( uint16_t * ) ucBadDnsResponseC );
239     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
240     /* End test. */
241
242     /* Parsing a bad packet should fail gracefully. */
243     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
244         ucBadDnsResponseD,
245         sizeof( ucBadDnsResponseD ),
246         *( uint16_t * ) ucBadDnsResponseD );
247     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
248     /* End test. */
249
250     /* Parsing a bad packet should fail gracefully. */
251     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
252         ucBadDnsResponseE,
253         sizeof( ucBadDnsResponseE ),
254         *( uint16_t * ) ucBadDnsResponseE );
255     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
256     /* End test. */
257
258     /* Parsing a bad packet should fail gracefully. */
259     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
260         ucBadDnsResponseF,
261         sizeof( ucBadDnsResponseF ),
262         *( uint16_t * ) ucBadDnsResponseF );
263     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
264     /* End test. */
265
266     /* Parsing a bad packet should fail gracefully. */
267     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
268         ucBadDnsResponseG,
269         sizeof( ucBadDnsResponseG ),
270         *( uint16_t * ) ucBadDnsResponseG );
271     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
272     /* End test. */
273
274     /* Parsing a bad packet should fail gracefully. */
275     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
276         ucBadDnsResponseH,
277         sizeof( ucBadDnsResponseH ),
278         *( uint16_t * ) ucBadDnsResponseH );
279     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
280     /* End test. */
281
282     /* Parsing a bad packet should fail gracefully. */
283     ulAddress = TEST_FreeRTOS_TCP_prvParseDNSReply(
284         ucBadDnsResponseI,
285         sizeof( ucBadDnsResponseI ),
286         *( uint16_t * ) ucBadDnsResponseI );
287     TEST_ASSERT_EQUAL_UINT32( 0, ulAddress );
288     /* End test. */
289 }
290
291 TEST( Full_FREERTOS_TCP, ulDNSHandlePacket )
292 {
293     NetworkBufferDescriptor_t xNetworkBuffer = { 0 };
294     uint8_t ucPartialUdpPacket[ sizeof( ipSIZE_OF_UDP_HEADER ) - 1 ] = { 0xFF };
295     uint32_t ulResult = 0;
296
297     /* Attempting to parse a packet that's shorter than a UDP header should be
298      * a no-op. */
299     xNetworkBuffer.pucEthernetBuffer = ucPartialUdpPacket;
300     xNetworkBuffer.xDataLength = sizeof( ucPartialUdpPacket );
301     ulResult = ulDNSHandlePacket( &xNetworkBuffer );
302     TEST_ASSERT_EQUAL_UINT32( 0, ulResult );
303 }
304
305 TEST( Full_FREERTOS_TCP, prvCheckOptions )
306 {
307     uint8_t ucDivideByZero[] =
308     {
309         0x6f, 0xff, 0xff, 0xff, 0x0a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
310         0xde, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0x6f, 0x6f, 0x6d,
311         0x6f, 0xff, 0xff, 0xff, 0x0a, 0xff, 0xff, 0xff, 0xff, 0xe5, 0x6f, 0x6f,
312         0x6f, 0x6f, 0x6f, 0x6b, 0xbf, 0x6f, 0x03, 0xff, 0x04, 0x01, 0xb7, 0xff,
313         0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x02, 0x02, 0x02, 0x02,
314         0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02,
315         0x02, 0x02, 0xf8, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x05
316     };
317
318     FreeRTOS_Socket_t xSocket;
319     NetworkBufferDescriptor_t xNetworkBuffer;
320
321     xNetworkBuffer.pucEthernetBuffer = ucDivideByZero;
322     xNetworkBuffer.xDataLength = sizeof( ucDivideByZero );
323
324     TEST_FreeRTOS_TCP_prvTCPCreateWindow( &xSocket );
325     TEST_FreeRTOS_TCP_prvCheckOptions( &xSocket, &xNetworkBuffer );
326 }
327
328 TEST( Full_FREERTOS_TCP, UDPPacketLength )
329 {
330     uint8_t ucBadUdpPacketA[] =
331     {
332         0xff, 0xff
333     };
334
335     uint8_t ucBadUdpPacketB[] =
336     {
337         0x0a, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0x54, 0xbf, 0xbf, 0xbf, 0xff, 0xbf,
338         0x0a, 0xbf, 0xbf, 0xbf, 0x3f, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf, 0xbf,
339         0x88, 0x00, 0xbf, 0xbf, 0xbf, 0x00, 0x32, 0xbf, 0xbf, 0xbf, 0x00, 0x35,
340         0x0a, 0xbf, 0xbf, 0x3a, 0xbf, 0xbf, 0xbf
341     };
342
343     BaseType_t xReturn = pdPASS;
344     uint16_t usPort = 65535;
345     NetworkBufferDescriptor_t xNetworkBuffer;
346
347     xNetworkBuffer.pucEthernetBuffer = NULL;
348     xNetworkBuffer.xDataLength = 0;
349
350     xReturn = xProcessReceivedUDPPacket( &xNetworkBuffer, usPort );
351     TEST_ASSERT_EQUAL_UINT32_MESSAGE( pdFAIL, xReturn, "Failed to parse 0 size packet" );
352
353     xNetworkBuffer.pucEthernetBuffer = ucBadUdpPacketA;
354     xNetworkBuffer.xDataLength = sizeof( ucBadUdpPacketA );
355     xReturn = xProcessReceivedUDPPacket( &xNetworkBuffer, usPort );
356     TEST_ASSERT_EQUAL_UINT32_MESSAGE( pdFAIL, xReturn, "Failed to parse 2 bytes packet" );
357
358     xNetworkBuffer.pucEthernetBuffer = ucBadUdpPacketB;
359     xNetworkBuffer.xDataLength = sizeof( ucBadUdpPacketB );
360     xReturn = xProcessReceivedUDPPacket( &xNetworkBuffer, usPort );
361     TEST_ASSERT_EQUAL_UINT32( pdFAIL, xReturn );
362 }