1 /*
2 * FreeRTOS+TCP V3.1.0
3 * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * http://aws.amazon.com/freertos
25 * http://www.FreeRTOS.org
26 */
27 /* Include Unity header */
28 #include "unity.h"
29
30 /* Include standard libraries */
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdint.h>
34 #include <stdio.h>
35
36
37 #include "FreeRTOS.h"
38
39 #include "catch_assert.h"
40
41 #include "FreeRTOSConfig.h"
42 #include "FreeRTOSIPConfig.h"
43
44 #include "FreeRTOS_TCP_WIN.h"
45
46 #include "mock_list.h"
47 #include "mock_FreeRTOS_TCP_WIN_list_macros.h"
48 #include "mock_portable.h"
49 #include "mock_FreeRTOS_IP.h"
50 #include "mock_task.h"
51
52
53 static void initializeList( List_t * const pxList );
54
55 extern TCPSegment_t * xTCPSegments;
56 extern List_t xSegmentList;
57 extern BaseType_t xTCPWindowLoggingLevel;
58
59 /**
60 * @brief calls at the beginning of each test case
61 */
setUp(void)62 void setUp( void )
63 {
64 initializeList( &xSegmentList );
65 }
66
67 /**
68 * @brief calls at the end of each test case
69 */
tearDown(void)70 void tearDown( void )
71 {
72 xTCPSegments = NULL;
73 }
74
75
initializeList(List_t * const pxList)76 static void initializeList( List_t * const pxList )
77 {
78 pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
79
80 /* The list end value is the highest possible value in the list to
81 * ensure it remains at the end of the list. */
82 pxList->xListEnd.xItemValue = portMAX_DELAY;
83
84 /* The list end next and previous pointers point to itself so we know
85 * when the list is empty. */
86 pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
87 pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
88
89 pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
90 }
initializeListItem(ListItem_t * const listItem)91 static void initializeListItem( ListItem_t * const listItem )
92 {
93 listItem->pxNext = NULL;
94 listItem->pxPrevious = NULL;
95 listItem->pxContainer = NULL;
96 }
97
test_xSequenceLessThan_a_lt_b(void)98 void test_xSequenceLessThan_a_lt_b( void )
99 {
100 BaseType_t xRet;
101
102 xRet = xSequenceLessThan( 1, 2 );
103 TEST_ASSERT_EQUAL( pdTRUE, xRet );
104 }
105
test_xSequenceLessThan_a_gb_b(void)106 void test_xSequenceLessThan_a_gb_b( void )
107 {
108 BaseType_t xRet;
109
110 xRet = xSequenceLessThan( 2, 1 );
111 TEST_ASSERT_EQUAL( pdFALSE, xRet );
112 }
113
test_xSequenceGreaterThan_a_lt_b(void)114 void test_xSequenceGreaterThan_a_lt_b( void )
115 {
116 BaseType_t xRet;
117
118 xRet = xSequenceGreaterThan( 1, 2 );
119 TEST_ASSERT_EQUAL( pdFALSE, xRet );
120 }
121
test_xSequenceGreaterThan_a_gt_b(void)122 void test_xSequenceGreaterThan_a_gt_b( void )
123 {
124 BaseType_t xRet;
125
126 xRet = xSequenceGreaterThan( 2, 1 );
127 TEST_ASSERT_EQUAL( pdTRUE, xRet );
128 }
129
test_xTCPWindowRxEmpty_empty_list(void)130 void test_xTCPWindowRxEmpty_empty_list( void )
131 {
132 BaseType_t xRet;
133 TCPWindow_t xWindow = { 0 };
134
135 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
136
137 xRet = xTCPWindowRxEmpty( &xWindow );
138
139 TEST_ASSERT_EQUAL( pdFALSE, xRet );
140 }
141
test_xTCPWindowRxEmpty_greater_sequence(void)142 void test_xTCPWindowRxEmpty_greater_sequence( void )
143 {
144 BaseType_t xRet;
145 TCPWindow_t xWindow = { 0 };
146
147 xWindow.rx.ulCurrentSequenceNumber = 1;
148 xWindow.rx.ulHighestSequenceNumber = 3;
149
150 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
151
152 xRet = xTCPWindowRxEmpty( &xWindow );
153
154 TEST_ASSERT_EQUAL( pdFALSE, xRet );
155 }
156
test_xTCPWindowRxEmpty_smaller_sequence(void)157 void test_xTCPWindowRxEmpty_smaller_sequence( void )
158 {
159 BaseType_t xRet;
160 TCPWindow_t xWindow = { 0 };
161
162 xWindow.rx.ulCurrentSequenceNumber = 2;
163 xWindow.rx.ulHighestSequenceNumber = 1;
164
165 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
166
167 xRet = xTCPWindowRxEmpty( &xWindow );
168
169 TEST_ASSERT_EQUAL( pdTRUE, xRet );
170 }
171
test_vTCPWindowDestroy_uninitialised_segment_list(void)172 void test_vTCPWindowDestroy_uninitialised_segment_list( void )
173 {
174 TCPWindow_t xWindow = { 0 };
175
176 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
177 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
178
179 vTCPWindowDestroy( &xWindow );
180 }
181
test_vTCPWindowDestroy_list_length_zero(void)182 void test_vTCPWindowDestroy_list_length_zero( void )
183 {
184 TCPWindow_t xWindow = { 0 };
185
186 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
187 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE );
188 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
189
190 vTCPWindowDestroy( &xWindow );
191 }
192
test_vTCPWindowDestroy_list_length_not_zero(void)193 void test_vTCPWindowDestroy_list_length_not_zero( void )
194 {
195 TCPWindow_t xWindow = { 0 };
196 List_t * pxSegments = &( xWindow.xRxSegments );
197
198 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
199 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE );
200 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
201 listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( pxSegments );
202 /* ->vTCPWindowFree */
203 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
204 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
205 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
206
207 vTCPWindowDestroy( &xWindow );
208 }
209
test_vTCPWindowDestroy_list_no_queue_container(void)210 void test_vTCPWindowDestroy_list_no_queue_container( void )
211 {
212 TCPWindow_t xWindow = { 0 };
213 TCPSegment_t xSegment = { 0 };
214
215 xSegment.xQueueItem.pxContainer = NULL;
216
217 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
218 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE );
219 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
220 listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment );
221 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
222
223 vTCPWindowDestroy( &xWindow );
224 }
225
test_vTCPWindowDestroy_list_no_segment_container(void)226 void test_vTCPWindowDestroy_list_no_segment_container( void )
227 {
228 TCPWindow_t xWindow = { 0 };
229 TCPSegment_t xSegment = { 0 };
230
231 xSegment.xSegmentItem.pxContainer = NULL;
232
233 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE );
234 listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE );
235 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 );
236 listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment );
237 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
238
239 vTCPWindowDestroy( &xWindow );
240 }
241
test_vTCPWindowCreate_success(void)242 void test_vTCPWindowCreate_success( void )
243 {
244 TCPWindow_t xWindow = { 0 };
245 uint32_t ulRxWindowLength = 0;
246 uint32_t ulTxWindowLength = 0;
247 uint32_t ulAckNumber = 0;
248 uint32_t ulSequenceNumber = 0;
249 uint32_t ulMSS = 0;
250
251 void * mlc = malloc( ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) );
252
253 /* ->prvCreateSectors */
254 vListInitialise_ExpectAnyArgs();
255 pvPortMalloc_ExpectAnyArgsAndReturn( mlc );
256 listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
257 listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
258
259 listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
260 listSET_LIST_ITEM_OWNER_ExpectAnyArgs();
261
262 /* back */
263 vListInitialise_ExpectAnyArgs();
264 vListInitialise_ExpectAnyArgs();
265 vListInitialise_ExpectAnyArgs();
266 vListInitialise_ExpectAnyArgs();
267 vListInitialise_ExpectAnyArgs();
268
269
270 vTCPWindowCreate( &xWindow,
271 ulRxWindowLength,
272 ulTxWindowLength,
273 ulAckNumber,
274 ulSequenceNumber,
275 ulMSS );
276 free( mlc );
277 }
278
test_vTCPWindowCreate_tcp_segment_null(void)279 void test_vTCPWindowCreate_tcp_segment_null( void )
280 {
281 TCPWindow_t xWindow = { 0 };
282 uint32_t ulRxWindowLength = 0;
283 uint32_t ulTxWindowLength = 0;
284 uint32_t ulAckNumber = 0;
285 uint32_t ulSequenceNumber = 0;
286 uint32_t ulMSS = 0;
287
288 /* ->prvCreateSectors */
289 vListInitialise_ExpectAnyArgs();
290 pvPortMalloc_ExpectAnyArgsAndReturn( NULL );
291
292 vListInitialise_ExpectAnyArgs();
293 vListInitialise_ExpectAnyArgs();
294 vListInitialise_ExpectAnyArgs();
295 vListInitialise_ExpectAnyArgs();
296 vListInitialise_ExpectAnyArgs();
297
298
299 vTCPWindowCreate( &xWindow,
300 ulRxWindowLength,
301 ulTxWindowLength,
302 ulAckNumber,
303 ulSequenceNumber,
304 ulMSS );
305 }
306
test_vTCPWindowCreate_null_tcpSegment(void)307 void test_vTCPWindowCreate_null_tcpSegment( void )
308 {
309 TCPWindow_t xWindow = { 0 };
310 uint32_t ulRxWindowLength = 0;
311 uint32_t ulTxWindowLength = 0;
312 uint32_t ulAckNumber = 0;
313 uint32_t ulSequenceNumber = 0;
314 uint32_t ulMSS = 0;
315
316 xTCPSegments = ( TCPSegment_t * ) 32;
317
318 vListInitialise_ExpectAnyArgs();
319 vListInitialise_ExpectAnyArgs();
320 vListInitialise_ExpectAnyArgs();
321 vListInitialise_ExpectAnyArgs();
322 vListInitialise_ExpectAnyArgs();
323
324 vTCPWindowCreate( &xWindow,
325 ulRxWindowLength,
326 ulTxWindowLength,
327 ulAckNumber,
328 ulSequenceNumber,
329 ulMSS );
330 TEST_ASSERT_EQUAL( ulRxWindowLength, xWindow.xSize.ulRxWindowLength );
331 TEST_ASSERT_EQUAL( ulTxWindowLength, xWindow.xSize.ulTxWindowLength );
332 }
333
test_vTCPWindowInit_MSS_not_zero(void)334 void test_vTCPWindowInit_MSS_not_zero( void )
335 {
336 TCPWindow_t xWindow = { 0 };
337 uint32_t ulAckNumber = 0;
338 uint32_t ulSequenceNumber = 0;
339 uint32_t ulMSS = 1;
340
341 xWindow.usMSSInit = 2;
342 xWindow.usMSS = 2;
343
344 vTCPWindowInit( &xWindow, ulAckNumber, ulSequenceNumber, ulMSS );
345
346 TEST_ASSERT_EQUAL( ulMSS, xWindow.usMSSInit );
347 TEST_ASSERT_EQUAL( ulMSS, xWindow.usMSS );
348 }
349
test_vTCPWindowInit_MSS_not_zero_mssInit_zero(void)350 void test_vTCPWindowInit_MSS_not_zero_mssInit_zero( void )
351 {
352 TCPWindow_t xWindow = { 0 };
353 uint32_t ulAckNumber = 0;
354 uint32_t ulSequenceNumber = 0;
355 uint32_t ulMSS = 2;
356
357 xWindow.usMSSInit = 0;
358 xWindow.usMSS = 2;
359
360 vTCPWindowInit( &xWindow, ulAckNumber, ulSequenceNumber, ulMSS );
361
362 TEST_ASSERT_EQUAL( 0, xWindow.usMSSInit );
363 TEST_ASSERT_EQUAL( ulMSS, xWindow.usMSS );
364 }
365
test_vTCPWindowInit_MSS_not_zero_mss_zero(void)366 void test_vTCPWindowInit_MSS_not_zero_mss_zero( void )
367 {
368 TCPWindow_t xWindow = { 0 };
369 uint32_t ulAckNumber = 0;
370 uint32_t ulSequenceNumber = 0;
371 uint32_t ulMSS = 2;
372
373 xWindow.usMSSInit = 0;
374 xWindow.usMSS = 0;
375
376 vTCPWindowInit( &xWindow, ulAckNumber, ulSequenceNumber, ulMSS );
377
378 TEST_ASSERT_EQUAL( 0, xWindow.usMSSInit );
379 TEST_ASSERT_EQUAL( ulMSS, xWindow.usMSS );
380 }
381
382
test_vTCPSegmentCleanup_segment_null(void)383 void test_vTCPSegmentCleanup_segment_null( void )
384 {
385 xTCPSegments = NULL;
386 vTCPSegmentCleanup();
387 }
388
test_vTCPSegmentCleanup_segment_not_null(void)389 void test_vTCPSegmentCleanup_segment_not_null( void )
390 {
391 /* will be freed by the function under test */
392 xTCPSegments = ( TCPSegment_t * ) malloc( 123 );
393
394 vPortFree_Expect( xTCPSegments );
395 vTCPSegmentCleanup();
396 TEST_ASSERT_NULL( xTCPSegments );
397 }
398
test_lTCPWindowRxCheck_sequence_nums_equal(void)399 void test_lTCPWindowRxCheck_sequence_nums_equal( void )
400 {
401 int32_t lReturn;
402 TCPWindow_t xWindow = { 0 };
403 uint32_t ulSequenceNumber = 34;
404 uint32_t ulLength = 34;
405 uint32_t ulSpace = ulLength + 3U; /* space > length */
406 uint32_t ulSkipCount = 0;
407
408 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
409
410 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 );
411
412 lReturn = lTCPWindowRxCheck( &xWindow,
413 ulSequenceNumber,
414 ulLength,
415 ulSpace,
416 &ulSkipCount );
417
418 TEST_ASSERT_EQUAL( 0, lReturn );
419 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
420 xWindow.rx.ulCurrentSequenceNumber );
421 TEST_ASSERT_EQUAL( 0, ulSkipCount );
422 }
423
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX(void)424 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX( void )
425 {
426 int32_t lReturn;
427 TCPWindow_t xWindow = { 0 };
428 uint32_t ulSequenceNumber = 34;
429 uint32_t ulLength = 34;
430 uint32_t ulSpace = ulLength + 3U; /* space > length */
431 uint32_t ulSkipCount = 0;
432
433 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
434
435 /* ->prvTCPWindowRX_ExpectedRX */
436 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
437 /* -->xTCPWindowRXConfirm */
438 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
439 /* <-prvTCPWindowRX_ExpectedRX */
440 /* -->xTCPWindowRxFind */
441 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
442
443 lReturn = lTCPWindowRxCheck( &xWindow,
444 ulSequenceNumber,
445 ulLength,
446 ulSpace,
447 &ulSkipCount );
448
449 TEST_ASSERT_EQUAL( 0, lReturn );
450 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
451 xWindow.rx.ulCurrentSequenceNumber );
452 TEST_ASSERT_EQUAL( 0, ulSkipCount );
453 }
454
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_2(void)455 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_2( void )
456 {
457 int32_t lReturn;
458 TCPWindow_t xWindow = { 0 };
459 uint32_t ulSequenceNumber = 34;
460 uint32_t ulLength = 34;
461 uint32_t ulSpace = ulLength + 3U; /* space > length */
462 TCPSegment_t xSegment = { 0 };
463 ListItem_t xIterator;
464 uint32_t ulSkipCount = 0;
465
466 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
467 xSegment.ulSequenceNumber = 23;
468
469
470 /* ->prvTCPWindowRX_ExpectedRX */
471 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
472 /* -->xTCPWindowRXConfirm */
473 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
474 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
475 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
476 /* <-prvTCPWindowRX_ExpectedRX */
477 /* -->xTCPWindowRxFind */
478 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
479
480 lReturn = lTCPWindowRxCheck( &xWindow,
481 ulSequenceNumber,
482 ulLength,
483 ulSpace,
484 &ulSkipCount );
485
486 TEST_ASSERT_EQUAL( 0, lReturn );
487 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
488 xWindow.rx.ulCurrentSequenceNumber );
489 TEST_ASSERT_EQUAL( 0, ulSkipCount );
490 }
491
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_3(void)492 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_3( void )
493 {
494 int32_t lReturn;
495 TCPWindow_t xWindow = { 0 };
496 uint32_t ulSequenceNumber = 34;
497 uint32_t ulLength = 34;
498 uint32_t ulSpace = ulLength + 3U; /* space > length */
499 TCPSegment_t xSegment = { 0 };
500 ListItem_t xIterator;
501 uint32_t ulSkipCount = 0;
502
503 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
504 xSegment.ulSequenceNumber = 39;
505
506 /* ->prvTCPWindowRX_ExpectedRX */
507 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
508 /* -->xTCPWindowRXConfirm */
509 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
510 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
511 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
512 /* ->prvTCPWindowRX_ExpectedRX */
513 /* <-prvTCPWindowRX_ExpectedRX */
514 /* -->xTCPWindowRXConfirm */
515 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
516 /* <-prvTCPWindowRX_ExpectedRX */
517 /* -->xTCPWindowRxFind */
518 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
519
520 lReturn = lTCPWindowRxCheck( &xWindow,
521 ulSequenceNumber,
522 ulLength,
523 ulSpace,
524 &ulSkipCount );
525
526 TEST_ASSERT_EQUAL( 0, lReturn );
527 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
528 xWindow.rx.ulCurrentSequenceNumber );
529 TEST_ASSERT_EQUAL( 0, ulSkipCount );
530 }
531
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_4(void)532 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_4( void )
533 {
534 int32_t lReturn;
535 TCPWindow_t xWindow = { 0 };
536 uint32_t ulSequenceNumber = 34;
537 uint32_t ulLength = 34;
538 uint32_t ulSpace = ulLength + 3U; /* space > length */
539 TCPSegment_t xSegment = { 0 };
540 ListItem_t xIterator;
541 uint32_t ulSkipCount = 0;
542
543 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
544 xSegment.ulSequenceNumber = 39;
545
546 /* ->prvTCPWindowRX_ExpectedRX */
547 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
548 /* -->xTCPWindowRXConfirm */
549 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
550 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
551 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
552 /* ->prvTCPWindowRX_ExpectedRX */
553 /* -->xTCPWindowRXConfirm */
554 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
555 /* <-prvTCPWindowRX_ExpectedRX */
556 /* -->xTCPWindowRxFind */
557 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
558
559 lReturn = lTCPWindowRxCheck( &xWindow,
560 ulSequenceNumber,
561 ulLength,
562 ulSpace,
563 &ulSkipCount );
564
565 TEST_ASSERT_EQUAL( 0, lReturn );
566 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
567 xWindow.rx.ulCurrentSequenceNumber );
568 TEST_ASSERT_EQUAL( 0, ulSkipCount );
569 }
570
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_5(void)571 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_5( void )
572 {
573 int32_t lReturn;
574 TCPWindow_t xWindow = { 0 };
575 uint32_t ulSequenceNumber = 34;
576 uint32_t ulLength = 3;
577 uint32_t ulSpace = ulLength + 3U; /* space > length */
578 TCPSegment_t xSegment = { 0 };
579 ListItem_t xIterator;
580 uint32_t ulSkipCount = 0;
581
582 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
583 xSegment.ulSequenceNumber = 39;
584
585 /* ->prvTCPWindowRX_ExpectedRX */
586 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
587 /* -->xTCPWindowRXConfirm */
588 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
589 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
590 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
591 /* ->prvTCPWindowRX_ExpectedRX */
592 /* -->xTCPWindowRxFind */
593 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
594
595 lReturn = lTCPWindowRxCheck( &xWindow,
596 ulSequenceNumber,
597 ulLength,
598 ulSpace,
599 &ulSkipCount );
600
601 TEST_ASSERT_EQUAL( 0, lReturn );
602 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
603 xWindow.rx.ulCurrentSequenceNumber );
604 TEST_ASSERT_EQUAL( 0, ulSkipCount );
605 }
606
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_6(void)607 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_6( void )
608 {
609 int32_t lReturn;
610 TCPWindow_t xWindow = { 0 };
611 uint32_t ulSequenceNumber = 34;
612 uint32_t ulLength = 34;
613 uint32_t ulSpace = ulLength + 3U; /* space > length */
614 TCPSegment_t xSegment = { 0 };
615 ListItem_t xIterator;
616 uint32_t ulSkipCount = 0;
617
618 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
619 xSegment.ulSequenceNumber = 39;
620 xSegment.lDataLength = ulLength;
621
622 /* ->prvTCPWindowRX_ExpectedRX */
623 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
624 /* -->xTCPWindowRXConfirm */
625 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
626 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
627 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
628 /* ->prvTCPWindowRX_ExpectedRX */
629 /* -->xTCPWindowRXConfirm */
630 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
631 /* <-prvTCPWindowRX_ExpectedRX */
632 /* ->xTCPWindowRxFind */
633 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
634
635 lReturn = lTCPWindowRxCheck( &xWindow,
636 ulSequenceNumber,
637 ulLength,
638 ulSpace,
639 &ulSkipCount );
640
641 TEST_ASSERT_EQUAL( 0, lReturn );
642 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
643 xWindow.rx.ulCurrentSequenceNumber );
644 TEST_ASSERT_EQUAL( 0, ulSkipCount );
645 }
646
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_7(void)647 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_7( void )
648 {
649 int32_t lReturn;
650 TCPWindow_t xWindow = { 0 };
651 uint32_t ulSequenceNumber = 39;
652 uint32_t ulLength = 34;
653 uint32_t ulSpace = ulLength + 3U; /* space > length */
654 TCPSegment_t xSegment = { 0 };
655 uint32_t ulSkipCount = 0;
656 ListItem_t xIterator;
657
658 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
659 xSegment.ulSequenceNumber = 39;
660 xSegment.lDataLength = ulLength + 6;
661
662 /* ->prvTCPWindowRX_ExpectedRX */
663 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
664 /* -->xTCPWindowRXConfirm */
665 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
666 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
667 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
668 /* ->prvTCPWindowRX_ExpectedRX */
669 /* -->xTCPWindowRXConfirm */
670 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
671 /* <-prvTCPWindowRX_ExpectedRX */
672 /* ->xTCPWindowRxFind */
673 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
674
675 lReturn = lTCPWindowRxCheck( &xWindow,
676 ulSequenceNumber,
677 ulLength,
678 ulSpace,
679 &ulSkipCount );
680
681 TEST_ASSERT_EQUAL( 0, lReturn );
682 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
683 xWindow.rx.ulCurrentSequenceNumber );
684 TEST_ASSERT_EQUAL( 0, ulSkipCount );
685 }
686
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_8(void)687 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_8( void )
688 {
689 int32_t lReturn;
690 TCPWindow_t xWindow = { 0 };
691 uint32_t ulSequenceNumber = 34;
692 uint32_t ulLength = 34;
693 uint32_t ulSpace = ulLength + 3U; /* space > length */
694 TCPSegment_t xSegment = { 0 };
695 /*TCPSegment_t xBest; */
696 ListItem_t xIterator;
697 uint32_t ulSkipCount = 0;
698
699 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
700 xSegment.ulSequenceNumber = 34;
701 xSegment.lDataLength = ulLength;
702
703 /* ->prvTCPWindowRX_ExpectedRX */
704 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
705 /* -->xTCPWindowRXConfirm */
706 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
707 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
708 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
709 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
710 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
711 /* <-prvTCPWindowRX_ExpectedRX */
712 /* -->xTCPWindowRXConfirm */
713 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
714 /* <-prvTCPWindowRX_ExpectedRX */
715 /* ->xTCPWindowRxFind */
716 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
717
718 lReturn = lTCPWindowRxCheck( &xWindow,
719 ulSequenceNumber,
720 ulLength,
721 ulSpace,
722 &ulSkipCount );
723
724 TEST_ASSERT_EQUAL( 0, lReturn );
725 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
726 xWindow.rx.ulCurrentSequenceNumber );
727 TEST_ASSERT_EQUAL( 0, ulSkipCount );
728 }
729
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_9(void)730 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_9( void )
731 {
732 int32_t lReturn;
733 TCPWindow_t xWindow = { 0 };
734 uint32_t ulSequenceNumber = 34;
735 uint32_t ulLength = 34;
736 uint32_t ulSpace = ulLength + 3U; /* space > length */
737 TCPSegment_t xSegment = { 0 };
738 TCPSegment_t xSegment2 = { 0 };
739 TCPSegment_t xBest = { 0 };
740 ListItem_t xIterator;
741 uint32_t ulSkipCount = 0;
742
743 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
744 xSegment.ulSequenceNumber = 35;
745 xSegment.lDataLength = ( int32_t ) ulLength;
746 xBest.ulSequenceNumber = 34;
747
748 xSegment2.ulSequenceNumber = ulLength + ulSequenceNumber;
749 xSegment2.lDataLength = 500;
750
751 /* ->prvTCPWindowRX_ExpectedRX */
752 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
753 /* -->xTCPWindowRXConfirm */
754 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
755 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
756 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
757 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xBest );
758 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
759 /* <-prvTCPWindowRX_ExpectedRX */
760 /* -->xTCPWindowRXConfirm */
761 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
762 /* <-prvTCPWindowRX_ExpectedRX */
763 /* -->xTCPWindowRxFind */
764 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
765 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment2 );
766 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
767
768 lReturn = lTCPWindowRxCheck( &xWindow,
769 ulSequenceNumber,
770 ulLength,
771 ulSpace,
772 &ulSkipCount );
773
774 TEST_ASSERT_EQUAL( 0, lReturn );
775 TEST_ASSERT_EQUAL( ( 500UL + ulLength + ulSequenceNumber ),
776 xWindow.rx.ulCurrentSequenceNumber );
777 TEST_ASSERT_EQUAL( 0, ulSkipCount );
778 }
779
test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_10(void)780 void test_lTCPWindowRxCheck_sequence_nums_equal_prvTCPWindowRX_ExpectedRX_10( void )
781 {
782 int32_t lReturn;
783 TCPWindow_t xWindow = { 0 };
784 uint32_t ulSequenceNumber = 34;
785 uint32_t ulLength = 34;
786 uint32_t ulSpace = ulLength + 3U; /* space > length */
787 TCPSegment_t xSegment = { 0 };
788 ListItem_t xIterator;
789 uint32_t ulSkipCount = 0;
790
791 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
792 xSegment.ulSequenceNumber = 34;
793 xSegment.lDataLength = ( int32_t ) ulLength;
794
795 /* ->prvTCPWindowRX_ExpectedRX */
796 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 4 );
797 /* -->xTCPWindowRXConfirm */
798 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
799 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
800 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
801 /* ->prvTCPWindowRX_ExpectedRX */
802 /* -->xTCPWindowRXConfirm */
803 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
804 /* <-prvTCPWindowRX_ExpectedRX */
805 /* ->xTCPWindowRxFind */
806 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
807
808 lReturn = lTCPWindowRxCheck( &xWindow,
809 ulSequenceNumber,
810 ulLength,
811 ulSpace,
812 &ulSkipCount );
813
814 TEST_ASSERT_EQUAL( 0, lReturn );
815 TEST_ASSERT_EQUAL( ( ulSequenceNumber + ulLength ),
816 xWindow.rx.ulCurrentSequenceNumber );
817 TEST_ASSERT_EQUAL( 0, ulSkipCount );
818 }
819
test_lTCPWindowRxCheck_sequence_nums_equal_length_gt_space(void)820 void test_lTCPWindowRxCheck_sequence_nums_equal_length_gt_space( void )
821 {
822 int32_t lReturn;
823 TCPWindow_t xWindow = { 0 };
824 uint32_t ulSequenceNumber = 34;
825 uint32_t ulLength = 34;
826 uint32_t ulSpace = ulLength - 3U; /* space < length */
827 uint32_t ulSkipCount = 0;
828
829 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber;
830
831 lReturn = lTCPWindowRxCheck( &xWindow,
832 ulSequenceNumber,
833 ulLength,
834 ulSpace,
835 &ulSkipCount );
836
837 TEST_ASSERT_EQUAL( -1, lReturn );
838 TEST_ASSERT_EQUAL( 0, ulSkipCount );
839 }
840
test_lTCPWindowRxCheck_sequence_nums_plus_1(void)841 void test_lTCPWindowRxCheck_sequence_nums_plus_1( void )
842 {
843 int32_t lReturn;
844 TCPWindow_t xWindow;
845 uint32_t ulSequenceNumber = 34;
846 uint32_t ulLength = 0;
847 uint32_t ulSpace = ulLength + 3U; /* space > length */
848 uint32_t ulSkipCount = 0;
849
850 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber + 1U;
851
852 lReturn = lTCPWindowRxCheck( &xWindow,
853 ulSequenceNumber,
854 ulLength,
855 ulSpace,
856 &ulSkipCount );
857
858 TEST_ASSERT_EQUAL( -1, lReturn );
859 TEST_ASSERT_EQUAL( 0, ulSkipCount );
860 }
861
test_lTCPWindowRxCheck_current_sequence_lt_sequence(void)862 void test_lTCPWindowRxCheck_current_sequence_lt_sequence( void )
863 {
864 int32_t lReturn;
865 TCPWindow_t xWindow = { 0 };
866 uint32_t ulSequenceNumber = 34;
867 uint32_t ulLength = 34;
868 uint32_t ulSpace = ulLength - 9U; /* space > length */
869 uint32_t ulSkipCount = 0;
870
871 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber - 2U;
872
873 lReturn = lTCPWindowRxCheck( &xWindow,
874 ulSequenceNumber,
875 ulLength,
876 ulSpace,
877 &ulSkipCount );
878
879 TEST_ASSERT_EQUAL( -1, lReturn );
880 TEST_ASSERT_EQUAL( 0, ulSkipCount );
881 }
882
test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX(void)883 void test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX( void )
884 {
885 int32_t lReturn;
886 TCPWindow_t xWindow = { 0 };
887 uint32_t ulSequenceNumber = 34;
888 uint32_t ulLength = 34;
889 uint32_t ulSpace = ulLength + 3U; /* space > length */
890 ListItem_t xIterator;
891 TCPSegment_t xSegment;
892 uint32_t ulSkipCount = 0;
893
894 initializeListItem( &xIterator );
895
896 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber - 2U;
897 xSegment.ulSequenceNumber = ulSequenceNumber - 2U;
898
899 /* ->prvTCPWindowRx_UnexpectedRX */
900 /* ->xTCPWindowRxFind */
901 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
902 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
903 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
904
905 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
906 /* -> xTCPWindowNew */
907 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
908
909 lReturn = lTCPWindowRxCheck( &xWindow,
910 ulSequenceNumber,
911 ulLength,
912 ulSpace,
913 &ulSkipCount );
914
915 TEST_ASSERT_EQUAL( -1, lReturn );
916 TEST_ASSERT_EQUAL( 0, ulSkipCount );
917 }
918
test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX_2(void)919 void test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX_2( void )
920 {
921 int32_t lReturn;
922 TCPWindow_t xWindow = { 0 };
923 uint32_t ulSequenceNumber = 34;
924 uint32_t ulLength = 34;
925 uint32_t ulSpace = ulLength + 3U; /* space > length */
926 ListItem_t xIterator;
927 TCPSegment_t xSegment;
928 uint32_t ulSkipCount = 0;
929
930 initializeListItem( &xIterator );
931 initializeList( &xWindow.xRxSegments );
932
933 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber - 2U;
934 xSegment.ulSequenceNumber = ulSequenceNumber + ulLength;
935
936 /* ->prvTCPWindowRx_UnexpectedRX */
937 /* ->xTCPWindowRxFind */
938 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
939 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
940 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
941
942 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
943 /* -> xTCPWindowNew */
944 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
945 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment );
946 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xIterator );
947 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
948 /* -->vTCPTimerSet */
949 xTaskGetTickCount_ExpectAndReturn( 23 );
950 /* <-xTCPWindowNew */
951 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 23 );
952
953 lReturn = lTCPWindowRxCheck( &xWindow,
954 ulSequenceNumber,
955 ulLength,
956 ulSpace,
957 &ulSkipCount );
958
959 TEST_ASSERT_EQUAL( 2, lReturn );
960 TEST_ASSERT_EQUAL( 0, ulSkipCount );
961 }
962
test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX_3(void)963 void test_lTCPWindowRxCheck_current_sequence_lt_sequence_prvTCPWindowRX_3( void )
964 {
965 int32_t lReturn;
966 TCPWindow_t xWindow = { 0 };
967 uint32_t ulSequenceNumber = 34;
968 uint32_t ulLength = 34;
969 uint32_t ulSpace = ulLength + 3U; /* space > length */
970 ListItem_t xIterator;
971 TCPSegment_t xSegment;
972 uint32_t ulSkipCount = 0;
973
974 initializeListItem( &xIterator );
975
976 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber - 2U;
977 xSegment.ulSequenceNumber = ulSequenceNumber;
978
979 /* ->prvTCPWindowRx_UnexpectedRX */
980 /* -->xTCPWindowRxFind */
981 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
982 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
983 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xRxSegments.xListEnd );
984 /* <-prvTCPWindowRx_UnexpectedRX */
985 /* -->xTCPWindowRxFind */
986 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xIterator );
987 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &xSegment );
988
989 lReturn = lTCPWindowRxCheck( &xWindow,
990 ulSequenceNumber,
991 ulLength,
992 ulSpace,
993 &ulSkipCount );
994
995 TEST_ASSERT_EQUAL( -1, lReturn );
996 TEST_ASSERT_EQUAL( 0, ulSkipCount );
997 }
998
test_lTCPWindowRxCheck_distance_eq_zero(void)999 void test_lTCPWindowRxCheck_distance_eq_zero( void )
1000 {
1001 int32_t lReturn;
1002 TCPWindow_t xWindow = { 0 };
1003 uint32_t ulSequenceNumber = 34;
1004 uint32_t ulLength = 34;
1005 uint32_t ulSpace = ulLength + 3U; /* space > length */
1006 uint32_t ulSkipCount = 0;
1007
1008 /* make ldistance <= 0 */
1009 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber + ulLength;
1010
1011 lReturn = lTCPWindowRxCheck( &xWindow,
1012 ulSequenceNumber,
1013 ulLength,
1014 ulSpace,
1015 &ulSkipCount );
1016
1017 TEST_ASSERT_EQUAL( -1, lReturn );
1018 TEST_ASSERT_EQUAL( 0, ulSkipCount );
1019 }
1020
test_lTCPWindowRxCheck_distance_gt_space(void)1021 void test_lTCPWindowRxCheck_distance_gt_space( void )
1022 {
1023 int32_t lReturn;
1024 TCPWindow_t xWindow = { 0 };
1025 uint32_t ulSequenceNumber = 15;
1026 uint32_t ulLength = 64;
1027 uint32_t ulSpace = 3U; /* space > length */
1028 uint32_t ulSkipCount = 0;
1029
1030 /* make ldistance >= ulSpace */
1031 xWindow.rx.ulCurrentSequenceNumber = ulSequenceNumber + 2U;
1032
1033 lReturn = lTCPWindowRxCheck( &xWindow,
1034 ulSequenceNumber,
1035 ulLength,
1036 ulSpace,
1037 &ulSkipCount );
1038
1039 TEST_ASSERT_EQUAL( -1, lReturn );
1040 TEST_ASSERT_EQUAL( 2, ulSkipCount );
1041 }
1042
test_lTCPWindowTxAdd_nothing_to_do(void)1043 void test_lTCPWindowTxAdd_nothing_to_do( void )
1044 {
1045 int32_t lDone;
1046 TCPWindow_t xWindow = { 0 };
1047 uint32_t ulLength = 0;
1048 int32_t lPosition = 0;
1049 int32_t lMax = 0;
1050 BaseType_t xBackup = xTCPWindowLoggingLevel;
1051
1052 /* in real code, this points to a list of segments */
1053 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1054
1055 xTCPWindowLoggingLevel = 3;
1056
1057 lDone = lTCPWindowTxAdd( &xWindow,
1058 ulLength,
1059 lPosition,
1060 lMax );
1061
1062 TEST_ASSERT_EQUAL( 0, lDone );
1063
1064 xTCPWindowLoggingLevel = xBackup;
1065 free( xWindow.pxHeadSegment );
1066 }
1067
test_lTCPWindowTxAdd_null_txSegment(void)1068 void test_lTCPWindowTxAdd_null_txSegment( void )
1069 {
1070 int32_t lDone;
1071 TCPWindow_t xWindow = { 0 };
1072 uint32_t ulLength = 0;
1073 int32_t lPosition = 0;
1074 int32_t lMax = 0;
1075
1076 xWindow.pxHeadSegment = NULL;
1077
1078
1079 lDone = lTCPWindowTxAdd( &xWindow,
1080 ulLength,
1081 lPosition,
1082 lMax );
1083
1084 TEST_ASSERT_EQUAL( 0, lDone );
1085 }
1086
test_lTCPWindowTxAdd_true_outstanding_bits(void)1087 void test_lTCPWindowTxAdd_true_outstanding_bits( void )
1088 {
1089 int32_t lDone;
1090 TCPWindow_t xWindow = { 0 };
1091 uint32_t ulLength = 0;
1092 int32_t lPosition = 0;
1093 int32_t lMax = 0;
1094
1095 /* in real code, this points to a list of segments */
1096 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1097 xWindow.pxHeadSegment->lMaxLength = 300;
1098 xWindow.pxHeadSegment->lDataLength = xWindow.pxHeadSegment->lMaxLength - 3;
1099 xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
1100
1101
1102 lDone = lTCPWindowTxAdd( &xWindow,
1103 ulLength,
1104 lPosition,
1105 lMax );
1106
1107 TEST_ASSERT_EQUAL( 0, lDone );
1108 free( xWindow.pxHeadSegment );
1109 }
1110
test_lTCPWindowTxAdd_data_length_zero(void)1111 void test_lTCPWindowTxAdd_data_length_zero( void )
1112 {
1113 int32_t lDone;
1114 TCPWindow_t xWindow = { 0 };
1115 uint32_t ulLength = 0;
1116 int32_t lPosition = 0;
1117 int32_t lMax = 0;
1118
1119 /* in real code, this points to a list of segments */
1120 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1121 xWindow.pxHeadSegment->lMaxLength = 300;
1122 xWindow.pxHeadSegment->lDataLength = 0;
1123 xWindow.pxHeadSegment->u.bits.bOutstanding = pdFALSE_UNSIGNED;
1124
1125
1126 lDone = lTCPWindowTxAdd( &xWindow,
1127 ulLength,
1128 lPosition,
1129 lMax );
1130
1131 TEST_ASSERT_EQUAL( 0, lDone );
1132 free( xWindow.pxHeadSegment );
1133 }
1134
test_lTCPWindowTxAdd_bytes_left_gt_zero(void)1135 void test_lTCPWindowTxAdd_bytes_left_gt_zero( void )
1136 {
1137 int32_t lDone;
1138 TCPWindow_t xWindow = { 0 };
1139 uint32_t ulLength = 0;
1140 int32_t lPosition = 0;
1141 int32_t lMax = 0;
1142 BaseType_t xBackup = xTCPWindowLoggingLevel;
1143
1144 /* in real code, this points to a list of segments */
1145 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1146 xWindow.pxHeadSegment->lMaxLength = 300;
1147 xWindow.pxHeadSegment->lDataLength = 200;
1148 xWindow.pxHeadSegment->u.bits.bOutstanding = pdFALSE_UNSIGNED;
1149
1150 xTCPWindowLoggingLevel = 2;
1151
1152 FreeRTOS_min_int32_ExpectAnyArgsAndReturn( 20 );
1153 lDone = lTCPWindowTxAdd( &xWindow,
1154 ulLength,
1155 lPosition,
1156 lMax );
1157
1158 TEST_ASSERT_EQUAL( 20, lDone );
1159 TEST_ASSERT_NOT_NULL( xWindow.pxHeadSegment );
1160 free( xWindow.pxHeadSegment );
1161
1162 xTCPWindowLoggingLevel = xBackup;
1163 }
1164
test_lTCPWindowTxAdd_len_gt_max_len(void)1165 void test_lTCPWindowTxAdd_len_gt_max_len( void )
1166 {
1167 int32_t lDone;
1168 TCPWindow_t xWindow = { 0 };
1169 uint32_t ulLength = 20;
1170 int32_t lPosition = 0;
1171 int32_t lMax = 300;
1172 void * xHeadSegmentSave;
1173 BaseType_t xBackup = xTCPWindowLoggingLevel;
1174
1175 xTCPWindowLoggingLevel = 0;
1176 /* in real code, this points to a list of segments */
1177 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1178 xHeadSegmentSave = xWindow.pxHeadSegment;
1179 xWindow.pxHeadSegment->lMaxLength = 300;
1180 xWindow.pxHeadSegment->lDataLength = 200;
1181 xWindow.pxHeadSegment->u.bits.bOutstanding = pdFALSE_UNSIGNED;
1182
1183
1184 FreeRTOS_min_int32_ExpectAnyArgsAndReturn( 200 );
1185 lDone = lTCPWindowTxAdd( &xWindow,
1186 ulLength,
1187 lPosition,
1188 lMax );
1189
1190 TEST_ASSERT_EQUAL( 200, lDone );
1191 TEST_ASSERT_NULL( xWindow.pxHeadSegment );
1192 free( xHeadSegmentSave );
1193 xTCPWindowLoggingLevel = xBackup;
1194 }
1195
test_lTCPWindowTxAdd_lBytsLeft_gt_zero_pxSegment_NULL(void)1196 void test_lTCPWindowTxAdd_lBytsLeft_gt_zero_pxSegment_NULL( void )
1197 {
1198 int32_t lDone;
1199 TCPWindow_t xWindow = { 0 };
1200 uint32_t ulLength = 20;
1201 int32_t lPosition = 0;
1202 int32_t lMax = 0;
1203
1204 /* in real code, this points to a list of segments */
1205 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1206 xWindow.pxHeadSegment->lMaxLength = 300;
1207 xWindow.pxHeadSegment->lDataLength = 200;
1208 xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
1209
1210
1211 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1212 lDone = lTCPWindowTxAdd( &xWindow,
1213 ulLength,
1214 lPosition,
1215 lMax );
1216
1217 TEST_ASSERT_EQUAL( 0, lDone );
1218 TEST_ASSERT_NOT_NULL( xWindow.pxHeadSegment );
1219 free( xWindow.pxHeadSegment );
1220 }
1221
test_lTCPWindowTxAdd_lBytsLeft_gt_zero_data_length_gt_maxlen(void)1222 void test_lTCPWindowTxAdd_lBytsLeft_gt_zero_data_length_gt_maxlen( void )
1223 {
1224 int32_t lDone;
1225 TCPWindow_t xWindow = { 0 };
1226 TCPSegment_t mockSegment = { 0 };
1227 ListItem_t mockListItem;
1228 uint32_t ulLength = 20;
1229 int32_t lPosition = 0;
1230 int32_t lMax = 0;
1231
1232 /* in real code, this points to a list of segments */
1233 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1234 xWindow.pxHeadSegment->lMaxLength = 300;
1235 xWindow.pxHeadSegment->lDataLength = 200;
1236 xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
1237
1238 xWindow.usMSS = 20;
1239
1240 mockSegment.lMaxLength = 200;
1241 mockSegment.lDataLength = mockSegment.lMaxLength + 3;
1242 initializeList( &xWindow.xTxQueue );
1243 initializeList( &xWindow.xTxSegments );
1244
1245 /* ->xTCPWindowNew */
1246 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1247 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1248 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1249 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1250 /* -->vTCPTimerSet */
1251 xTaskGetTickCount_ExpectAndReturn( 3000 );
1252 /* ->xTCPWindowNew */
1253 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( ipconfigTCP_WIN_SEG_COUNT - 1 );
1254
1255 /* back to API */
1256 FreeRTOS_min_int32_ExpectAnyArgsAndReturn( 25 );
1257
1258 lDone = lTCPWindowTxAdd( &xWindow,
1259 ulLength,
1260 lPosition,
1261 lMax );
1262
1263 TEST_ASSERT_EQUAL( 25, lDone );
1264 TEST_ASSERT_NULL( xWindow.pxHeadSegment );
1265 free( xWindow.pxHeadSegment );
1266 }
1267
test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen(void)1268 void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen( void )
1269 {
1270 int32_t lDone;
1271 TCPWindow_t xWindow = { 0 };
1272 TCPSegment_t mockSegment = { 0 };
1273 ListItem_t mockListItem;
1274 uint32_t ulLength = 20;
1275 int32_t lPosition = 0;
1276 int32_t lMax = 0;
1277
1278 /* in real code, this points to a list of segments */
1279 xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) );
1280 xWindow.pxHeadSegment->lMaxLength = 300;
1281 xWindow.pxHeadSegment->lDataLength = 200;
1282 xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED;
1283
1284 xWindow.usMSS = 300;
1285
1286 xWindow.pxHeadSegment->lMaxLength = 300;
1287 xWindow.pxHeadSegment->lDataLength = 1;
1288
1289 initializeList( &xWindow.xTxQueue );
1290 initializeList( &xWindow.xTxSegments );
1291
1292 /* -> xTCPWindowTxNew */ /* xTCPWindowNew */
1293 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1294 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1295 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( xWindow.pxHeadSegment );
1296 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1297 /* --> vTCPTimerSet */
1298 xTaskGetTickCount_ExpectAndReturn( 3000 );
1299 /* -> xTCPWindowNew */
1300 listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( ipconfigTCP_WIN_SEG_COUNT - 1 );
1301
1302 /* back to API */
1303 FreeRTOS_min_int32_ExpectAnyArgsAndReturn( 23 );
1304
1305 lDone = lTCPWindowTxAdd( &xWindow,
1306 ulLength,
1307 lPosition,
1308 lMax );
1309
1310 TEST_ASSERT_EQUAL( 23, lDone );
1311 TEST_ASSERT_NOT_NULL( xWindow.pxHeadSegment );
1312 free( xWindow.pxHeadSegment );
1313 }
1314
1315
test_lTCPWindowTxAdd_assert_null(void)1316 void test_lTCPWindowTxAdd_assert_null( void )
1317 {
1318 TCPWindow_t xWindow = { 0 };
1319 uint32_t ulLength = 20;
1320 int32_t lPosition = 0;
1321 int32_t lMax = 0;
1322 ListItem_t mockListItem;
1323
1324 /* -> xTCPWindowTxNew */ /* xTCPWindowNew */
1325 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1326 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( NULL );
1327 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( xWindow.pxHeadSegment );
1328 catch_assert( lTCPWindowTxAdd( &xWindow,
1329 ulLength,
1330 lPosition,
1331 lMax ) );
1332
1333 /* -> xTCPWindowTxNew */ /* xTCPWindowNew */
1334 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1335 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1336 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( NULL );
1337 catch_assert( lTCPWindowTxAdd( &xWindow,
1338 ulLength,
1339 lPosition,
1340 lMax ) );
1341 }
1342
1343
1344
test_xTCPWindowTxDone(void)1345 void test_xTCPWindowTxDone( void )
1346 {
1347 BaseType_t xRet = pdFALSE;
1348 TCPWindow_t tcpWin = { 0 };
1349
1350 initializeList( &tcpWin.xTxSegments );
1351
1352 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1353
1354 xRet = xTCPWindowTxDone( &tcpWin );
1355
1356 TEST_ASSERT_TRUE( xRet );
1357 }
1358
test_xTCPWindowTxHasData_empty_list(void)1359 void test_xTCPWindowTxHasData_empty_list( void )
1360 {
1361 BaseType_t xReturn;
1362
1363 TCPWindow_t xWindow = { 0 };
1364 uint32_t ulWindowSize = 34;
1365 TickType_t ulDelay = 33;
1366
1367 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1368
1369 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1370
1371 TEST_ASSERT_TRUE( xReturn );
1372 }
1373
test_xTCPWindowTxHasData_null_segment(void)1374 void test_xTCPWindowTxHasData_null_segment( void )
1375 {
1376 BaseType_t xReturn;
1377
1378 TCPWindow_t xWindow = { 0 };
1379 uint32_t ulWindowSize = 34;
1380 TickType_t ulDelay = 33;
1381
1382 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1383 /* -> xTCPWindowPeekHead */
1384 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1385 /* -> xTCPWindowPeekHead */
1386 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1387
1388 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1389
1390 TEST_ASSERT_FALSE( xReturn );
1391 }
1392
test_xTCPWindowTxHasData_non_null_segment_maxage_lt_age(void)1393 void test_xTCPWindowTxHasData_non_null_segment_maxage_lt_age( void )
1394 {
1395 BaseType_t xReturn;
1396
1397 TCPWindow_t xWindow = { 0 };
1398 TCPSegment_t mockSegment = { 0 };
1399 ListItem_t mockListItem;
1400 uint32_t ulWindowSize = 34;
1401 TickType_t ulDelay = 33;
1402
1403 mockSegment.u.bits.ucTransmitCount = 1;
1404 mockSegment.xTransmitTimer.uxBorn = 2;
1405 xWindow.lSRTT = 1;
1406
1407 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1408 /* -> xTCPWindowPeekHead */
1409 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1410 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1411 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1412 /* -> ulTimerGetAge */
1413 xTaskGetTickCount_ExpectAndReturn( 2333 );
1414
1415 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1416
1417 TEST_ASSERT_TRUE( xReturn );
1418 }
1419
test_xTCPWindowTxHasData_non_null_segment_maxAge_gt_age(void)1420 void test_xTCPWindowTxHasData_non_null_segment_maxAge_gt_age( void )
1421 {
1422 BaseType_t xReturn;
1423
1424 TCPWindow_t xWindow = { 0 };
1425 TCPSegment_t mockSegment = { 0 };
1426 ListItem_t mockListItem;
1427 uint32_t ulWindowSize = 34;
1428 TickType_t ulDelay = 33;
1429
1430 mockSegment.u.bits.ucTransmitCount = 7;
1431 mockSegment.xTransmitTimer.uxBorn = 2;
1432 xWindow.lSRTT = 1;
1433
1434 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1435 /* -> xTCPWindowPeekHead */
1436 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1437 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1438 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1439 /* -> ulTimerGetAge */
1440 xTaskGetTickCount_ExpectAndReturn( 23 );
1441
1442 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1443
1444 TEST_ASSERT_TRUE( xReturn );
1445 }
1446
test_xTCPWindowTxHasData_no_space(void)1447 void test_xTCPWindowTxHasData_no_space( void )
1448 {
1449 BaseType_t xReturn;
1450
1451 TCPWindow_t xWindow = { 0 };
1452 TCPSegment_t mockSegment = { 0 };
1453 ListItem_t mockListItem;
1454 uint32_t ulWindowSize = 34;
1455 TickType_t ulDelay = 33;
1456
1457 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1458 /* -> xTCPWindowPeekHead */
1459 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1460 /* -> xTCPWindowPeekHead */
1461 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1462 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1463 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1464 /* -> prvTCPWindowTxHasSpace */
1465 /* --> xTCPWindowPeekHead */
1466 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1467
1468 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1469
1470 TEST_ASSERT_FALSE( xReturn );
1471 }
1472
test_xTCPWindowTxHasData_no_space_size_lt_datalength(void)1473 void test_xTCPWindowTxHasData_no_space_size_lt_datalength( void )
1474 {
1475 BaseType_t xReturn;
1476
1477 TCPWindow_t xWindow = { 0 };
1478 TCPSegment_t mockSegment = { 0 };
1479 ListItem_t mockListItem;
1480 uint32_t ulWindowSize = 34;
1481 TickType_t ulDelay = 33;
1482
1483 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1484 /* -> xTCPWindowPeekHead */
1485 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1486 /* -> xTCPWindowPeekHead */
1487 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1488 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1489 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1490 /* -> prvTCPWindowTxHasSpace */
1491 /* --> xTCPWindowPeekHead */
1492 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1493 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1494 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1495 /* -> prvTCPWindowTxHasSpace */
1496 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 300 );
1497
1498 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1499
1500 TEST_ASSERT_TRUE( xReturn );
1501 }
1502
test_xTCPWindowTxHasData_datalength_lt_maxlength(void)1503 void test_xTCPWindowTxHasData_datalength_lt_maxlength( void )
1504 {
1505 BaseType_t xReturn;
1506
1507 TCPWindow_t xWindow = { 0 };
1508 TCPSegment_t mockSegment = { 0 };
1509 ListItem_t mockListItem;
1510 uint32_t ulWindowSize = 34;
1511 TickType_t ulDelay = 33;
1512
1513 mockSegment.lMaxLength = 7;
1514 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1515 mockSegment.lDataLength = mockSegment.lMaxLength - 3;
1516
1517 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1518 /* -> xTCPWindowPeekHead */
1519 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1520 /* -> xTCPWindowPeekHead */
1521 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1522 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1523 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1524 /* -> prvTCPWindowTxHasSpace */
1525 /* --> xTCPWindowPeekHead */
1526 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1527 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1528 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1529 /* -> prvTCPWindowTxHasSpace */
1530 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 300 );
1531
1532 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1533
1534 TEST_ASSERT_FALSE( xReturn );
1535 }
1536
test_xTCPWindowTxHasData_SendFullSize(void)1537 void test_xTCPWindowTxHasData_SendFullSize( void )
1538 {
1539 BaseType_t xReturn;
1540
1541 TCPWindow_t xWindow = { 0 };
1542 TCPSegment_t mockSegment = { 0 };
1543 ListItem_t mockListItem;
1544 uint32_t ulWindowSize = 34;
1545 TickType_t ulDelay = 33;
1546
1547 mockSegment.lMaxLength = 7;
1548 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1549 mockSegment.lDataLength = mockSegment.lMaxLength + 3;
1550
1551 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1552 /* -> xTCPWindowPeekHead */
1553 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1554 /* -> xTCPWindowPeekHead */
1555 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1556 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1557 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1558 /* -> prvTCPWindowTxHasSpace */
1559 /* --> xTCPWindowPeekHead */
1560 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1561 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1562 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1563 /* -> prvTCPWindowTxHasSpace */
1564 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 300 );
1565
1566 xReturn = xTCPWindowTxHasData( &xWindow, ulWindowSize, &ulDelay );
1567
1568 TEST_ASSERT_TRUE( xReturn );
1569 }
1570
1571
test_ulTCPWindowTxGet_config_assert(void)1572 void test_ulTCPWindowTxGet_config_assert( void )
1573 {
1574 uint32_t ulReturn;
1575 TCPWindow_t xWindow = { 0 };
1576 uint32_t ulWindowSize = 400;
1577 int32_t lPosition = 0;
1578 TCPSegment_t mockSegment = { 0 };
1579 TCPSegment_t mockSegment2 = { 0 };
1580 ListItem_t mockListItem;
1581 BaseType_t xBackup = xTCPWindowLoggingLevel;
1582
1583 xTCPWindowLoggingLevel = 2;
1584 xWindow.tx.ulHighestSequenceNumber = 45;
1585 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber + 3U;
1586 mockSegment.lDataLength = 360;
1587 mockSegment.lMaxLength = 300;
1588 xWindow.pxHeadSegment = &mockSegment2;
1589 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1590
1591 mockSegment2.xQueueItem.pxContainer = NULL;
1592 mockSegment2.lDataLength = 567;
1593 mockSegment2.xQueueItem.pxContainer = &xWindow.xPriorityQueue;
1594 initializeListItem( &mockListItem );
1595 initializeList( &xWindow.xWaitQueue );
1596
1597 /* -> xTCPWindowGetHead */
1598 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1599 /* -> pxTCPWindowTx_GetWaitQueue */
1600 /* --> xTCPWindowPeekHead */
1601 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1602
1603 /* -> pxTCPWindowTx_GetTXQueue */
1604 /* --> xTCPWindowPeekHead */
1605 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1606 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1607 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1608 /* -> pxTCPWindowTx_GetTXQueue */
1609 /* -> prvTCPWindowTxHasSpace */
1610 /* --> xTCPWindowPeekHead */
1611 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1612 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1613 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1614 /* -> prvTCPWindowTxHasSpace */
1615 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 3 );
1616 /* <-pxTCPWindowTx_GetTXQueue */
1617 /* -->xTCPWindowGetHead */
1618 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1619 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1620 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment2 );
1621 /* -> pxTCPWindowTx_GetWaitQueue */
1622 /* --> xTCPWindowPeekHead */
1623 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1624
1625 catch_assert( ulTCPWindowTxGet( &xWindow,
1626 ulWindowSize,
1627 &lPosition ) );
1628
1629 xTCPWindowLoggingLevel = xBackup;
1630 }
1631
test_ulTCPWindowTxGet_empty_segment_list(void)1632 void test_ulTCPWindowTxGet_empty_segment_list( void )
1633 {
1634 uint32_t ulReturn;
1635 TCPWindow_t xWindow = { 0 };
1636 uint32_t ulWindowSize = 23;
1637 int32_t lPosition = 0;
1638
1639 /* -> xTCPWindowGetHead */
1640 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1641 /* -> pxTCPWindowTx_GetWaitQueue */
1642 /* --> xTCPWindowPeekHead */
1643 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1644
1645 /* -> pxTCPWindowTx_GetTXQueue */
1646 /* --> xTCPWindowPeekHead */
1647 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1648
1649 ulReturn = ulTCPWindowTxGet( &xWindow,
1650 ulWindowSize,
1651 &lPosition );
1652 TEST_ASSERT_EQUAL( 0, ulReturn );
1653 }
1654
test_ulTCPWindowTxGet_empty_wait_queue(void)1655 void test_ulTCPWindowTxGet_empty_wait_queue( void )
1656 {
1657 uint32_t ulReturn;
1658 TCPWindow_t xWindow = { 0 };
1659 uint32_t ulWindowSize = 300;
1660 int32_t lPosition = 0;
1661 TCPSegment_t mockSegment = { 0 };
1662 ListItem_t mockListItem;
1663
1664 xWindow.tx.ulHighestSequenceNumber = 45;
1665 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber + 3U;
1666 mockSegment.lDataLength = 360;
1667 xWindow.pxHeadSegment = &mockSegment;
1668
1669 /* -> xTCPWindowGetHead */
1670 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1671 /* -> pxTCPWindowTx_GetWaitQueue */
1672 /* --> xTCPWindowPeekHead */
1673 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1674
1675 /* -> pxTCPWindowTx_GetTXQueue */
1676 /* --> xTCPWindowPeekHead */
1677 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1678 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1679 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1680 /* -> pxTCPWindowTx_GetTXQueue */
1681 /* -->prvTCPWindowTxHasSpace */
1682 /* ---> xTCPWindowPeekHead */
1683 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1684 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1685 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1686 /* -->prvTCPWindowTxHasSpace */
1687 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 50 );
1688
1689 ulReturn = ulTCPWindowTxGet( &xWindow,
1690 ulWindowSize,
1691 &lPosition );
1692 TEST_ASSERT_EQUAL( 0, ulReturn );
1693 }
1694
test_ulTCPWindowTxGet_empty_wait_queue_2(void)1695 void test_ulTCPWindowTxGet_empty_wait_queue_2( void )
1696 {
1697 uint32_t ulReturn;
1698 TCPWindow_t xWindow = { 0 };
1699 uint32_t ulWindowSize = 300;
1700 int32_t lPosition = 0;
1701 TCPSegment_t mockSegment = { 0 };
1702 ListItem_t mockListItem;
1703
1704 xWindow.tx.ulHighestSequenceNumber = 45;
1705 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber - 3U;
1706 mockSegment.lDataLength = 360;
1707 xWindow.pxHeadSegment = &mockSegment;
1708
1709 xWindow.xSize.ulTxWindowLength = ( ( xWindow.tx.ulHighestSequenceNumber -
1710 xWindow.tx.ulCurrentSequenceNumber ) +
1711 mockSegment.lDataLength ) - 2U;
1712
1713 /* -> xTCPWindowGetHead */
1714 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1715 /* -> pxTCPWindowTx_GetWaitQueue */
1716 /* --> xTCPWindowPeekHead */
1717 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1718
1719 /* -> pxTCPWindowTx_GetTXQueue */
1720 /* --> xTCPWindowPeekHead */
1721 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1722 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1723 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1724 /* -> pxTCPWindowTx_GetTXQueue */
1725 /* -->prvTCPWindowTxHasSpace */
1726 /* ---> xTCPWindowPeekHead */
1727 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1728 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1729 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1730 /* -->prvTCPWindowTxHasSpace */
1731 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 50 );
1732
1733 ulReturn = ulTCPWindowTxGet( &xWindow,
1734 ulWindowSize,
1735 &lPosition );
1736 TEST_ASSERT_EQUAL( 0, ulReturn );
1737 }
1738
test_ulTCPWindowTxGet_empty_wait_queue_3(void)1739 void test_ulTCPWindowTxGet_empty_wait_queue_3( void )
1740 {
1741 uint32_t ulReturn;
1742 TCPWindow_t xWindow = { 0 };
1743 uint32_t ulWindowSize = 300;
1744 int32_t lPosition = 0;
1745 TCPSegment_t mockSegment = { 0 };
1746 ListItem_t mockListItem;
1747
1748 xWindow.tx.ulHighestSequenceNumber = 45;
1749 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber - 3U;
1750 mockSegment.lDataLength = 360;
1751 xWindow.pxHeadSegment = &mockSegment;
1752
1753 xWindow.xSize.ulTxWindowLength = ( ( xWindow.tx.ulHighestSequenceNumber -
1754 xWindow.tx.ulCurrentSequenceNumber ) +
1755 mockSegment.lDataLength ) + 2U;
1756
1757 /* -> xTCPWindowGetHead */
1758 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1759 /* -> pxTCPWindowTx_GetWaitQueue */
1760 /* --> xTCPWindowPeekHead */
1761 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1762
1763 /* -> pxTCPWindowTx_GetTXQueue */
1764 /* --> xTCPWindowPeekHead */
1765 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1766 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1767 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1768 /* -> pxTCPWindowTx_GetTXQueue */
1769 /* -->prvTCPWindowTxHasSpace */
1770 /* ---> xTCPWindowPeekHead */
1771 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1772 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1773 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1774 /* -->prvTCPWindowTxHasSpace */
1775 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 50 );
1776
1777 ulReturn = ulTCPWindowTxGet( &xWindow,
1778 ulWindowSize,
1779 &lPosition );
1780 TEST_ASSERT_EQUAL( 0, ulReturn );
1781 }
1782
test_ulTCPWindowTxGet_empty_wait_queue_4(void)1783 void test_ulTCPWindowTxGet_empty_wait_queue_4( void )
1784 {
1785 uint32_t ulReturn;
1786 TCPWindow_t xWindow = { 0 };
1787 uint32_t ulWindowSize = 300;
1788 int32_t lPosition = 0;
1789 TCPSegment_t mockSegment = { 0 };
1790 ListItem_t mockListItem;
1791
1792 xWindow.tx.ulHighestSequenceNumber = 45;
1793 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber + 3U;
1794 mockSegment.lDataLength = 360;
1795 mockSegment.lMaxLength = 400;
1796 xWindow.pxHeadSegment = &mockSegment;
1797 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1798
1799 /* -> xTCPWindowGetHead */
1800 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1801 /* -> pxTCPWindowTx_GetWaitQueue */
1802 /* --> xTCPWindowPeekHead */
1803 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1804 /* -> pxTCPWindowTx_GetTXQueue */
1805 /* -->prvTCPWindowTxHasSpace */
1806 /* ---> xTCPWindowPeekHead */
1807 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1808 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1809 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1810 /* -->prvTCPWindowTxHasSpace */
1811
1812 ulReturn = ulTCPWindowTxGet( &xWindow,
1813 ulWindowSize,
1814 &lPosition );
1815 TEST_ASSERT_EQUAL( 0, ulReturn );
1816 }
1817
test_ulTCPWindowTxGet_empty_wait_queue_5(void)1818 void test_ulTCPWindowTxGet_empty_wait_queue_5( void )
1819 {
1820 uint32_t ulReturn;
1821 TCPWindow_t xWindow = { 0 };
1822 uint32_t ulWindowSize = 400;
1823 int32_t lPosition = 0;
1824 TCPSegment_t mockSegment = { 0 };
1825 TCPSegment_t mockSegment2 = { 0 };
1826 ListItem_t mockListItem;
1827 BaseType_t xBackup = xTCPWindowLoggingLevel;
1828
1829 xTCPWindowLoggingLevel = 0;
1830
1831 xWindow.tx.ulHighestSequenceNumber = 45;
1832 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber + 3U;
1833 mockSegment.lDataLength = 360;
1834 mockSegment.lMaxLength = 300;
1835 xWindow.pxHeadSegment = &mockSegment2;
1836 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1837
1838 mockSegment2.xQueueItem.pxContainer = NULL;
1839 mockSegment2.lDataLength = 567;
1840 initializeListItem( &mockListItem );
1841 initializeList( &xWindow.xWaitQueue );
1842
1843 /* -> xTCPWindowGetHead */
1844 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1845 /* -> pxTCPWindowTx_GetWaitQueue */
1846 /* --> xTCPWindowPeekHead */
1847 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1848
1849 /* -> pxTCPWindowTx_GetTXQueue */
1850 /* --> xTCPWindowPeekHead */
1851 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1852 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1853 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1854 /* -> pxTCPWindowTx_GetTXQueue */
1855 /* -> prvTCPWindowTxHasSpace */
1856 /* --> xTCPWindowPeekHead */
1857 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1858 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1859 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1860 /* -> prvTCPWindowTxHasSpace */
1861 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 3 );
1862 /* <-pxTCPWindowTx_GetTXQueue */
1863 /* -->xTCPWindowGetHead */
1864 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1865 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1866 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment2 );
1867 /* -> pxTCPWindowTx_GetWaitQueue */
1868 /* --> xTCPWindowPeekHead */
1869 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1870 xTaskGetTickCount_ExpectAndReturn( 32 );
1871
1872 ulReturn = ulTCPWindowTxGet( &xWindow,
1873 ulWindowSize,
1874 &lPosition );
1875 TEST_ASSERT_EQUAL( 567, ulReturn );
1876 TEST_ASSERT_NULL( xWindow.pxHeadSegment );
1877 xTCPWindowLoggingLevel = xBackup;
1878 }
1879
test_ulTCPWindowTxGet_empty_wait_queue_6(void)1880 void test_ulTCPWindowTxGet_empty_wait_queue_6( void )
1881 {
1882 uint32_t ulReturn;
1883 TCPWindow_t xWindow = { 0 };
1884 uint32_t ulWindowSize = 400;
1885 int32_t lPosition = 0;
1886 TCPSegment_t mockSegment = { 0 };
1887 TCPSegment_t mockSegment2 = { 0 };
1888 ListItem_t mockListItem;
1889
1890 xWindow.tx.ulHighestSequenceNumber = 45;
1891 xWindow.tx.ulCurrentSequenceNumber = xWindow.tx.ulHighestSequenceNumber + 3U;
1892 mockSegment.lDataLength = 360;
1893 mockSegment.lMaxLength = 300;
1894 xWindow.pxHeadSegment = &mockSegment;
1895 xWindow.u.bits.bSendFullSize = pdTRUE_UNSIGNED;
1896
1897 mockSegment2.xQueueItem.pxContainer = NULL;
1898 mockSegment2.lDataLength = 567;
1899 initializeListItem( &mockListItem );
1900 initializeList( &xWindow.xWaitQueue );
1901
1902 /* -> xTCPWindowGetHead */
1903 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1904 /* -> pxTCPWindowTx_GetWaitQueue */
1905 /* --> xTCPWindowPeekHead */
1906 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1907
1908 /* -> pxTCPWindowTx_GetTXQueue */
1909 /* --> xTCPWindowPeekHead */
1910 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1911 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1912 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1913 /* -> pxTCPWindowTx_GetTXQueue */
1914 /* -> prvTCPWindowTxHasSpace */
1915 /* --> xTCPWindowPeekHead */
1916 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1917 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1918 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1919 /* -> prvTCPWindowTxHasSpace */
1920 FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 3 );
1921 /* <-pxTCPWindowTx_GetTXQueue */
1922 /* -->xTCPWindowGetHead */
1923 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1924 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1925 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment2 );
1926 /* -> pxTCPWindowTx_GetWaitQueue */
1927 /* --> xTCPWindowPeekHead */
1928 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1929 xTaskGetTickCount_ExpectAndReturn( 32 );
1930
1931 ulReturn = ulTCPWindowTxGet( &xWindow,
1932 ulWindowSize,
1933 &lPosition );
1934 TEST_ASSERT_NOT_NULL( xWindow.pxHeadSegment );
1935 TEST_ASSERT_EQUAL( 567, ulReturn );
1936 }
1937
ignore_test_ulTCPWindowTxGet_segment_not_null(void)1938 void ignore_test_ulTCPWindowTxGet_segment_not_null( void )
1939 {
1940 uint32_t ulReturn;
1941 TCPWindow_t xWindow = { 0 };
1942 TCPSegment_t mockSegment = { 0 };
1943 TCPSegment_t mockSegment2 = { 0 };
1944 uint32_t ulWindowSize = 23;
1945 int32_t lPosition = 0;
1946 ListItem_t mockListItem;
1947
1948 initializeList( &xWindow.xWaitQueue );
1949
1950 initializeListItem( &mockListItem );
1951 initializeListItem( &mockSegment.xQueueItem );
1952 initializeListItem( &mockSegment2.xQueueItem );
1953
1954 mockSegment.xQueueItem.pvContainer = NULL;
1955 mockSegment.u.bits.ucTransmitCount = 7;
1956 mockSegment.xTransmitTimer.uxBorn = 2;
1957 xWindow.lSRTT = 0;
1958 xWindow.usMSS = 10;
1959
1960 mockSegment2.xQueueItem = mockListItem;
1961 mockSegment2.xQueueItem.pvContainer = NULL;
1962
1963 /* -> xTCPWindowGetHead */
1964 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
1965 /* -> pxTCPWindowTx_GetWaitQueue */
1966 /* --> xTCPWindowPeekHead */
1967 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1968 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1969 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
1970 /* -> pxTCPWindowTx_GetWaitQueue */
1971 /* -->ulTimerGetAge */
1972 xTaskGetTickCount_ExpectAndReturn( 23 );
1973 /* -> pxTCPWindowTx_GetWaitQueue */
1974 /* -->xTCPWindowGetHead */
1975 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
1976 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
1977 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment2 );
1978 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
1979 /* -> pxTCPWindowTx_GetWaitQueue */
1980 /* ulTCPWindowTxGet */
1981 /* -> vTCPTimerSet */
1982 xTaskGetTickCount_ExpectAndReturn( 32 );
1983
1984 ulReturn = ulTCPWindowTxGet( &xWindow,
1985 ulWindowSize,
1986 &lPosition );
1987 TEST_ASSERT_EQUAL( 360, ulReturn );
1988 TEST_ASSERT_EQUAL( 32, mockSegment.xTransmitTimer.uxBorn );
1989 }
1990
test_ulTCPWindowTxGet_segment_null(void)1991 void test_ulTCPWindowTxGet_segment_null( void )
1992 {
1993 uint32_t ulReturn;
1994 TCPWindow_t xWindow = { 0 };
1995 uint32_t ulWindowSize = 23;
1996 int32_t lPosition = 0;
1997
1998 TCPSegment_t mockSegment = { 0 };
1999 ListItem_t mockListItem;
2000
2001 mockSegment.xQueueItem.pvContainer = NULL;
2002 mockSegment.u.bits.ucTransmitCount = 1;
2003 mockSegment.xTransmitTimer.uxBorn = 2;
2004 xWindow.lSRTT = 6;
2005 xWindow.usMSS = 10;
2006
2007 /* ->xTCPWindowGetHead */
2008 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
2009 /* ->pxTCPWindowTx_GetWaitQueue */
2010 /* -->xTCPWindowPeekHead */
2011 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2012 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2013 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2014 /* -> pxTCPWindowTx_GetWaitQueue */
2015 /* -->ulTimerGetAge */
2016 xTaskGetTickCount_ExpectAndReturn( 2 );
2017 /* -> pxTCPWindowTx_GetWaitQueue */
2018 /* <ulTCPWindowTxGet */
2019 /* ->pxTCPWindowTX_GetTxQueue */
2020 /* -->xTCPWindowPeekHead */
2021 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
2022
2023 ulReturn = ulTCPWindowTxGet( &xWindow,
2024 ulWindowSize,
2025 &lPosition );
2026 TEST_ASSERT_EQUAL( 0, ulReturn );
2027 TEST_ASSERT_EQUAL( 2, mockSegment.xTransmitTimer.uxBorn );
2028 }
2029
2030 /* covering more cases in pxTCPWindowTx_GetWaitQueue */
test_ulTCPWindowTxGet_segment_not_null_2(void)2031 void test_ulTCPWindowTxGet_segment_not_null_2( void )
2032 {
2033 uint32_t ulReturn;
2034 TCPWindow_t xWindow = { 0 };
2035 uint32_t ulWindowSize = 23;
2036 int32_t lPosition = 0;
2037 BaseType_t xBackup = xTCPWindowLoggingLevel;
2038
2039 TCPSegment_t mockSegment = { 0 };
2040 ListItem_t mockListItem;
2041 List_t xQueueList;
2042
2043 initializeList( &xWindow.xWaitQueue );
2044 initializeListItem( &mockListItem );
2045
2046 xTCPWindowLoggingLevel = 2;
2047
2048 mockSegment.xQueueItem.pvContainer = NULL;
2049
2050 mockSegment.u.bits.ucTransmitCount = 3U;
2051 mockSegment.xTransmitTimer.uxBorn = 2;
2052 xWindow.lSRTT = 2;
2053 xWindow.usMSS = 10;
2054 xWindow.xSize.ulTxWindowLength = ( xWindow.usMSS * 2 ) + 10;
2055 xWindow.pxHeadSegment = &mockSegment;
2056
2057 /* -> xTCPWindowGetHead */
2058 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
2059 /* -> pxTCPWindowTx_GetWaitQueue */
2060 /* --> xTCPWindowPeekHead */
2061 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2062 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2063 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2064 /* -> pxTCPWindowTx_GetWaitQueue */
2065 /* -->ulTimerGetAge */
2066 xTaskGetTickCount_ExpectAndReturn( 23000 );
2067 /* -> pxTCPWindowTx_GetWaitQueue */
2068 /* -->xTCPWindowGetHead */
2069 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2070 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2071 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2072 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2073 /* -> pxTCPWindowTx_GetWaitQueue */
2074 /* ulTCPWindowTxGet */
2075 /* -> vTCPTimerSet */
2076 xTaskGetTickCount_ExpectAndReturn( 32 );
2077
2078
2079
2080 ulReturn = ulTCPWindowTxGet( &xWindow,
2081 ulWindowSize,
2082 &lPosition );
2083 TEST_ASSERT_EQUAL( 0, ulReturn );
2084 TEST_ASSERT_EQUAL( 32, mockSegment.xTransmitTimer.uxBorn );
2085
2086 xTCPWindowLoggingLevel = xBackup;
2087 }
2088
2089 /* covering more cases in ulTCPWindowTxGet */
test_ulTCPWindowTxGet_segment_not_null_3(void)2090 void test_ulTCPWindowTxGet_segment_not_null_3( void )
2091 {
2092 uint32_t ulReturn;
2093 TCPWindow_t xWindow = { 0 };
2094 uint32_t ulWindowSize = 23;
2095 int32_t lPosition = 0;
2096 BaseType_t xBackup = xTCPWindowLoggingLevel;
2097
2098 TCPSegment_t mockSegment = { 0 };
2099 ListItem_t mockListItem;
2100 List_t xQueueList;
2101
2102 xTCPWindowLoggingLevel = 0;
2103
2104 mockSegment.xQueueItem.pvContainer = NULL;
2105
2106 mockSegment.u.bits.ucTransmitCount = 3U;
2107 mockSegment.xTransmitTimer.uxBorn = 2;
2108 xWindow.lSRTT = 2;
2109 xWindow.usMSS = 10;
2110 xWindow.xSize.ulTxWindowLength = ( xWindow.usMSS * 2 ) - 10;
2111 xWindow.pxHeadSegment = &mockSegment;
2112
2113 initializeList( &xWindow.xWaitQueue );
2114 initializeListItem( &mockListItem );
2115
2116 /* -> xTCPWindowGetHead */
2117 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE );
2118 /* -> pxTCPWindowTx_GetWaitQueue */
2119 /* --> xTCPWindowPeekHead */
2120 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2121 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2122 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2123 /* -> pxTCPWindowTx_GetWaitQueue */
2124 /* -->ulTimerGetAge */
2125 xTaskGetTickCount_ExpectAndReturn( 23000 );
2126 /* -> pxTCPWindowTx_GetWaitQueue */
2127 /* -->xTCPWindowGetHead */
2128 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2129 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2130 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2131 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2132 /* -> pxTCPWindowTx_GetWaitQueue */
2133 /* ulTCPWindowTxGet */
2134 /* -> vTCPTimerSet */
2135 xTaskGetTickCount_ExpectAndReturn( 32 );
2136
2137
2138
2139 ulReturn = ulTCPWindowTxGet( &xWindow,
2140 ulWindowSize,
2141 &lPosition );
2142 TEST_ASSERT_EQUAL( 0, ulReturn );
2143 TEST_ASSERT_EQUAL( 32, mockSegment.xTransmitTimer.uxBorn );
2144 xTCPWindowLoggingLevel = xBackup;
2145 }
2146
2147 /* covering more cases in ulTCPWindowTxGet */
test_ulTCPWindowTxGet_segment_not_null_4(void)2148 void test_ulTCPWindowTxGet_segment_not_null_4( void )
2149 {
2150 uint32_t ulReturn;
2151 TCPWindow_t xWindow = { 0 };
2152 TCPSegment_t mockSegment = { 0 };
2153 uint32_t ulWindowSize = 23;
2154 int32_t lPosition = 0;
2155
2156 ListItem_t mockListItem;
2157 List_t xQueueList;
2158
2159 mockSegment.xQueueItem.pvContainer = NULL;
2160
2161 mockSegment.u.bits.ucTransmitCount = 3U;
2162 mockSegment.xTransmitTimer.uxBorn = 2;
2163 xWindow.lSRTT = 2;
2164 xWindow.usMSS = 10;
2165 xWindow.xSize.ulTxWindowLength = ( xWindow.usMSS * 2 ) - 10;
2166 xWindow.pxHeadSegment = &mockSegment;
2167
2168 initializeList( &xWindow.xWaitQueue );
2169 initializeListItem( &mockListItem );
2170
2171 /* -> xTCPWindowGetHead */
2172 listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE );
2173 listGET_HEAD_ENTRY_ExpectAnyArgsAndReturn( &mockListItem );
2174 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2175 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2176 /* -> vTCPTimerSet */
2177 xTaskGetTickCount_ExpectAndReturn( 32 );
2178
2179
2180
2181 ulReturn = ulTCPWindowTxGet( &xWindow,
2182 ulWindowSize,
2183 &lPosition );
2184 TEST_ASSERT_EQUAL( 0, ulReturn );
2185 TEST_ASSERT_EQUAL( 32, mockSegment.xTransmitTimer.uxBorn );
2186 }
2187
2188
test_ulTCPWindowTxAck_curr_seq_gt_seq(void)2189 void test_ulTCPWindowTxAck_curr_seq_gt_seq( void )
2190 {
2191 uint32_t ulSequenceNumber = 0;
2192 uint32_t ulReturn;
2193 TCPWindow_t xWindow = { 0 };
2194
2195 xWindow.tx.ulCurrentSequenceNumber = 32;
2196
2197 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2198
2199 TEST_ASSERT_EQUAL( 0, ulReturn );
2200 }
2201
test_ulTCPWindowTxAck_curr_seq_lt_seq_no_list_items(void)2202 void test_ulTCPWindowTxAck_curr_seq_lt_seq_no_list_items( void )
2203 {
2204 uint32_t ulSequenceNumber = 56;
2205 uint32_t ulReturn;
2206 TCPWindow_t xWindow = { 0 };
2207
2208 xWindow.tx.ulCurrentSequenceNumber = 32;
2209 /* ->prvTCPWindowTxCheckAck */
2210 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2211
2212 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2213
2214 TEST_ASSERT_EQUAL( 0, ulReturn );
2215 }
2216
2217 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_2(void)2218 void test_ulTCPWindowTxAck_curr_seq_lt_seq_2( void )
2219 {
2220 uint32_t ulSequenceNumber = 56;
2221 uint32_t ulReturn;
2222 TCPWindow_t xWindow = { 0 };
2223 TCPSegment_t mockSegment = { 0 };
2224 ListItem_t mockListItem;
2225 ListItem_t mockNextListItem;
2226
2227 xWindow.tx.ulCurrentSequenceNumber = 32;
2228 mockSegment.ulSequenceNumber = 45;
2229 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2230 /* ->prvTCPWindowTxCheckAck */
2231 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2232 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2233 listGET_NEXT_ExpectAnyArgsAndReturn( &mockNextListItem );
2234
2235 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2236
2237 TEST_ASSERT_EQUAL( 0, ulReturn );
2238 }
2239
2240 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_3_continue_loop(void)2241 void test_ulTCPWindowTxAck_curr_seq_lt_seq_3_continue_loop( void )
2242 {
2243 uint32_t ulSequenceNumber = 56;
2244 uint32_t ulReturn;
2245 TCPWindow_t xWindow = { 0 };
2246 TCPSegment_t mockSegment = { 0 };
2247 ListItem_t mockListItem;
2248
2249 xWindow.tx.ulCurrentSequenceNumber = 32;
2250 mockSegment.ulSequenceNumber = 31;
2251 /* ->prvTCPWindowTxCheckAck */
2252 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2253 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2254 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2255
2256 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2257
2258 TEST_ASSERT_EQUAL( 0, ulReturn );
2259 }
2260
2261 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_4(void)2262 void test_ulTCPWindowTxAck_curr_seq_lt_seq_4( void )
2263 {
2264 uint32_t ulSequenceNumber = 56;
2265 uint32_t ulReturn;
2266 TCPWindow_t xWindow = { 0 };
2267 TCPSegment_t mockSegment = { 0 };
2268 ListItem_t mockListItem;
2269 ListItem_t mockNextListItem;
2270 BaseType_t xBackup = xTCPWindowLoggingLevel;
2271
2272 xTCPWindowLoggingLevel = 2;
2273 xWindow.tx.ulCurrentSequenceNumber = 32;
2274 mockSegment.ulSequenceNumber = 32;
2275 mockSegment.u.bits.bAcked = pdTRUE_UNSIGNED;
2276 mockSegment.lDataLength = 2000;
2277 /* ->prvTCPWindowTxCheckAck */
2278 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2279 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2280 listGET_NEXT_ExpectAnyArgsAndReturn( &mockNextListItem );
2281
2282 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2283
2284 TEST_ASSERT_EQUAL( 2000, ulReturn );
2285
2286 xTCPWindowLoggingLevel = xBackup;
2287 }
2288
2289 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_4_acked_false(void)2290 void test_ulTCPWindowTxAck_curr_seq_lt_seq_4_acked_false( void )
2291 {
2292 uint32_t ulSequenceNumber = 56;
2293 uint32_t ulReturn;
2294 TCPWindow_t xWindow = { 0 };
2295 TCPSegment_t mockSegment = { 0 };
2296 ListItem_t mockListItem;
2297 ListItem_t mockNextListItem;
2298
2299 xWindow.tx.ulCurrentSequenceNumber = 32;
2300 mockSegment.ulSequenceNumber = 32;
2301 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2302 mockSegment.lDataLength = 2000;
2303 /* ->prvTCPWindowTxCheckAck */
2304 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2305 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2306 listGET_NEXT_ExpectAnyArgsAndReturn( &mockNextListItem );
2307
2308 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2309
2310 TEST_ASSERT_EQUAL( 0, ulReturn );
2311 }
2312
2313 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_5_acked_false(void)2314 void test_ulTCPWindowTxAck_curr_seq_lt_seq_5_acked_false( void )
2315 {
2316 uint32_t ulSequenceNumber = 56;
2317 uint32_t ulReturn;
2318 TCPWindow_t xWindow = { 0 };
2319 TCPSegment_t mockSegment = { 0 };
2320 ListItem_t mockListItem;
2321
2322 xWindow.tx.ulCurrentSequenceNumber = 32;
2323 mockSegment.ulSequenceNumber = 32;
2324 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2325 mockSegment.lDataLength = 20;
2326 /* ->prvTCPWindowTxCheckAck */
2327 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2328 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2329 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2330
2331 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2332
2333 TEST_ASSERT_EQUAL( 20, ulReturn );
2334 }
2335
2336 /* covering code inside prvTCPWindowTxCheckAck */
test_ulTCPWindowTxAck_curr_seq_lt_seq_6_acked_false(void)2337 void test_ulTCPWindowTxAck_curr_seq_lt_seq_6_acked_false( void )
2338 {
2339 uint32_t ulSequenceNumber = 56;
2340 uint32_t ulReturn;
2341 TCPWindow_t xWindow = { 0 };
2342 TCPSegment_t mockSegment = { 0 };
2343 ListItem_t mockListItem;
2344 BaseType_t xBackup = xTCPWindowLoggingLevel;
2345
2346 xWindow.tx.ulCurrentSequenceNumber = 32;
2347 mockSegment.ulSequenceNumber = 32;
2348 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2349 mockSegment.lDataLength = 20;
2350 xTCPWindowLoggingLevel = 0;
2351
2352 mockSegment.u.bits.ucTransmitCount = 1U;
2353 /* ->prvTCPWindowTxCheckAck */
2354 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2355 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2356 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2357
2358 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2359
2360 TEST_ASSERT_EQUAL( 20, ulReturn );
2361
2362 xTCPWindowLoggingLevel = xBackup;
2363 }
2364
2365 /* covering code inside prvTCPWindowTxCheckAck */
ignore_test_ulTCPWindowTxAck_curr_seq_lt_seq_7_acked_false(void)2366 void ignore_test_ulTCPWindowTxAck_curr_seq_lt_seq_7_acked_false( void )
2367 {
2368 uint32_t ulSequenceNumber = 56;
2369 uint32_t ulReturn;
2370 TCPWindow_t xWindow;
2371 TCPSegment_t mockSegment;
2372 ListItem_t mockListItem;
2373
2374 initializeListItem( &mockListItem );
2375
2376 xWindow.tx.ulCurrentSequenceNumber = 32;
2377 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2378 mockSegment.lDataLength = 24;
2379
2380 mockSegment.u.bits.ucTransmitCount = 1U;
2381 mockSegment.ulSequenceNumber = 32;
2382 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2383 mockSegment.xQueueItem = mockListItem;
2384 mockSegment.xQueueItem.pxContainer = &xWindow.xPriorityQueue;
2385
2386 /* ->prvTCPWindowTxCheckAck */
2387 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2388 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2389 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2390 /* -->prvTCPWindowTxCheckAck_CalcSRTT */
2391 /* --->ulTimerGetAge */
2392 /* -->prvTCPWindowTxCheckAck_CalcSRTT */
2393 /* ->prvTCPWindowTxCheckAck */
2394 xTaskGetTickCount_ExpectAndReturn( 3000 );
2395 /* -->vTCPWindowFree */
2396 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2397 /* ->prvTCPWindowTxCheckAck */
2398 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2399
2400 ulReturn = ulTCPWindowTxAck( &xWindow, ulSequenceNumber );
2401
2402 TEST_ASSERT_EQUAL( 24, ulReturn );
2403 }
2404
test_ulTCPWindowTxSack(void)2405 void test_ulTCPWindowTxSack( void )
2406 {
2407 uint32_t ulAckCount;
2408 TCPWindow_t xWindow;
2409 uint32_t ulFirst = 33;
2410 uint32_t ulLast = 63;
2411 TCPSegment_t mockSegment;
2412 ListItem_t mockListItem;
2413
2414 initializeListItem( &mockListItem );
2415
2416 xWindow.tx.ulCurrentSequenceNumber = 32;
2417 xWindow.lSRTT = ipconfigTCP_SRTT_MINIMUM_VALUE_MS - 3;
2418 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2419 mockSegment.lDataLength = 30;
2420
2421 mockSegment.u.bits.ucTransmitCount = 1U;
2422 mockSegment.ulSequenceNumber = 33;
2423 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2424 mockSegment.xQueueItem = mockListItem;
2425 mockSegment.xQueueItem.pxContainer = &xWindow.xPriorityQueue;
2426
2427 /* ->prvTCPWindowTxCheckAck */
2428 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2429 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2430 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2431 /* -->prvTCPWindowTxCheckAck_CalcSRTT */
2432 /* --->ulTimerGetAge */
2433 xTaskGetTickCount_ExpectAndReturn( 23 );
2434 /* -->prvTCPWindowTxCheckAck_CalcSRTT */
2435 /* ->prvTCPWindowTxCheckAck */
2436 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2437 /* ulTCPWindowTxSack */
2438 /* ->prvTCPWindowFastRetransmit */
2439 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2440
2441 ulAckCount = ulTCPWindowTxSack( &xWindow,
2442 ulFirst,
2443 ulLast );
2444 TEST_ASSERT_EQUAL( 0, ulAckCount );
2445 TEST_ASSERT_EQUAL( ipconfigTCP_SRTT_MINIMUM_VALUE_MS, xWindow.lSRTT );
2446 }
2447
2448
test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_1(void)2449 void test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_1( void )
2450 {
2451 uint32_t ulAckCount;
2452 TCPWindow_t xWindow;
2453 uint32_t ulFirst = 33;
2454 uint32_t ulLast = 63;
2455 TCPSegment_t mockSegment;
2456 ListItem_t mockListItem;
2457
2458 initializeListItem( &mockListItem );
2459
2460 xWindow.tx.ulCurrentSequenceNumber = 32;
2461 xWindow.lSRTT = ipconfigTCP_SRTT_MINIMUM_VALUE_MS + 30;
2462 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2463 mockSegment.lDataLength = 30;
2464
2465 mockSegment.u.bits.ucTransmitCount = 1U;
2466 mockSegment.ulSequenceNumber = 33;
2467 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2468 mockSegment.xQueueItem = mockListItem;
2469 mockSegment.xQueueItem.pxContainer = NULL;
2470 mockSegment.u.bits.ucDupAckCount = 1U;
2471
2472 /* ->prvTCPWindowTxCheckAck */
2473 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2474 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2475 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2476 /* -->prvTCPWindowTxCheckAck_CalcSRTT */
2477 /* --->ulTimerGetAge */
2478 xTaskGetTickCount_ExpectAndReturn( 69 );
2479 /* <--prvTCPWindowTxCheckAck_CalcSRTT */
2480 /* <-prvTCPWindowTxCheckAck */
2481 /* ulTCPWindowTxSack */
2482 /* ->prvTCPWindowFastRetransmit */
2483 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2484 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2485 /* exit the loop */
2486 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2487
2488 ulAckCount = ulTCPWindowTxSack( &xWindow,
2489 ulFirst,
2490 ulLast );
2491 TEST_ASSERT_EQUAL( 0, ulAckCount );
2492 TEST_ASSERT_EQUAL( 65, xWindow.lSRTT );
2493 }
2494
test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_2(void)2495 void test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_2( void )
2496 {
2497 uint32_t ulAckCount;
2498 TCPWindow_t xWindow;
2499 uint32_t ulFirst = 33;
2500 uint32_t ulLast = 63;
2501 TCPSegment_t mockSegment;
2502 ListItem_t mockListItem;
2503
2504 initializeListItem( &mockListItem );
2505
2506 xWindow.tx.ulCurrentSequenceNumber = 32;
2507 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2508 mockSegment.lDataLength = 30;
2509
2510 mockSegment.u.bits.ucTransmitCount = 1U;
2511 mockSegment.ulSequenceNumber = 33;
2512 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2513 mockSegment.xQueueItem = mockListItem;
2514 mockSegment.xQueueItem.pxContainer = NULL;
2515 mockSegment.u.bits.ucDupAckCount = 1U;
2516
2517 /* ->prvTCPWindowTxCheckAck */
2518 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2519 /* ulTCPWindowTxSack */
2520 /* ->prvTCPWindowFastRetransmit */
2521 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2522 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2523 /* exit the loop */
2524 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2525
2526 ulAckCount = ulTCPWindowTxSack( &xWindow,
2527 ulFirst,
2528 ulLast );
2529 TEST_ASSERT_EQUAL( 0, ulAckCount );
2530 }
2531
test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_3(void)2532 void test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_3( void )
2533 {
2534 uint32_t ulAckCount;
2535 TCPWindow_t xWindow;
2536 uint32_t ulFirst = 33;
2537 uint32_t ulLast = 63;
2538 TCPSegment_t mockSegment;
2539 ListItem_t mockListItem;
2540 BaseType_t xBackup = xTCPWindowLoggingLevel;
2541
2542 initializeListItem( &mockListItem );
2543
2544 xTCPWindowLoggingLevel = 3;
2545 xWindow.tx.ulCurrentSequenceNumber = 32;
2546 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2547 mockSegment.lDataLength = 30;
2548
2549 mockSegment.u.bits.ucTransmitCount = 1U;
2550 mockSegment.ulSequenceNumber = 31;
2551 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2552 mockSegment.xQueueItem = mockListItem;
2553 mockSegment.xQueueItem.pxContainer = NULL;
2554 mockSegment.u.bits.ucDupAckCount = 1U;
2555
2556 /* ->prvTCPWindowTxCheckAck */
2557 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2558 /* ulTCPWindowTxSack */
2559 /* ->prvTCPWindowFastRetransmit */
2560 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2561 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2562 /* exit the loop */
2563 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2564
2565 ulAckCount = ulTCPWindowTxSack( &xWindow,
2566 ulFirst,
2567 ulLast );
2568 TEST_ASSERT_EQUAL( 0, ulAckCount );
2569
2570 xTCPWindowLoggingLevel = xBackup;
2571 }
2572
test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_LoggingGTZero(void)2573 void test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_LoggingGTZero( void )
2574 {
2575 uint32_t ulAckCount;
2576 TCPWindow_t xWindow;
2577 uint32_t ulFirst = 33;
2578 uint32_t ulLast = 63;
2579 TCPSegment_t mockSegment;
2580 ListItem_t mockListItem;
2581 BaseType_t xBackup = xTCPWindowLoggingLevel;
2582
2583 initializeListItem( &mockListItem );
2584 initializeList( &xWindow.xPriorityQueue );
2585
2586 xTCPWindowLoggingLevel = 0;
2587 xWindow.tx.ulCurrentSequenceNumber = 32;
2588 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2589 mockSegment.lDataLength = 30;
2590
2591 mockSegment.u.bits.ucTransmitCount = 1U;
2592 mockSegment.ulSequenceNumber = 31;
2593 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2594 mockSegment.xQueueItem = mockListItem;
2595 mockSegment.xQueueItem.pxContainer = NULL;
2596 mockSegment.u.bits.ucDupAckCount = 2U;
2597
2598 /* ->prvTCPWindowTxCheckAck */
2599 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2600 /* ulTCPWindowTxSack */
2601 /* ->prvTCPWindowFastRetransmit */
2602 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2603 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2604 /* exit the loop */
2605 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2606 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2607
2608 ulAckCount = ulTCPWindowTxSack( &xWindow,
2609 ulFirst,
2610 ulLast );
2611 TEST_ASSERT_EQUAL( 0, ulAckCount );
2612
2613 xTCPWindowLoggingLevel = xBackup;
2614 }
2615
test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_4_LoggingLTZero(void)2616 void test_ulTCPWindowTxSack_prvTCPWindowFastRetransmit_4_LoggingLTZero( void )
2617 {
2618 uint32_t ulAckCount;
2619 TCPWindow_t xWindow;
2620 uint32_t ulFirst = 33;
2621 uint32_t ulLast = 63;
2622 TCPSegment_t mockSegment;
2623 ListItem_t mockListItem;
2624 BaseType_t xBackup = xTCPWindowLoggingLevel;
2625
2626 xTCPWindowLoggingLevel = -1;
2627
2628 initializeListItem( &mockListItem );
2629 initializeList( &xWindow.xPriorityQueue );
2630
2631 xWindow.tx.ulCurrentSequenceNumber = 32;
2632 mockSegment.u.bits.bAcked = pdFALSE_UNSIGNED;
2633 mockSegment.lDataLength = 30;
2634
2635 mockSegment.u.bits.ucTransmitCount = 1U;
2636 mockSegment.ulSequenceNumber = 31;
2637 mockListItem.pxContainer = &xWindow.xPriorityQueue;
2638 mockSegment.xQueueItem = mockListItem;
2639 mockSegment.xQueueItem.pxContainer = NULL;
2640 mockSegment.u.bits.ucDupAckCount = 2U;
2641
2642 /* ->prvTCPWindowTxCheckAck */
2643 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xTxSegments.xListEnd );
2644 /* ulTCPWindowTxSack */
2645 /* ->prvTCPWindowFastRetransmit */
2646 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &mockListItem );
2647 listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &mockSegment );
2648 /* exit the loop */
2649 listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) &xWindow.xWaitQueue.xListEnd );
2650 uxListRemove_ExpectAnyArgsAndReturn( pdTRUE );
2651
2652 ulAckCount = ulTCPWindowTxSack( &xWindow,
2653 ulFirst,
2654 ulLast );
2655 TEST_ASSERT_EQUAL( 0, ulAckCount );
2656
2657 xTCPWindowLoggingLevel = xBackup;
2658 }
2659