[d14840d] | 1 | /*
|
---|
| 2 | * Copyright (c) 2017 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #include <adt/prodcons.h>
|
---|
| 30 | #include <inet/endpoint.h>
|
---|
| 31 | #include <io/log.h>
|
---|
| 32 | #include <pcut/pcut.h>
|
---|
| 33 |
|
---|
| 34 | #include "../rqueue.h"
|
---|
| 35 | #include "../segment.h"
|
---|
| 36 |
|
---|
| 37 | PCUT_INIT
|
---|
| 38 |
|
---|
| 39 | PCUT_TEST_SUITE(rqueue);
|
---|
| 40 |
|
---|
| 41 | enum {
|
---|
| 42 | test_seg_max = 10
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | static void test_seg_received(inet_ep2_t *, tcp_segment_t *);
|
---|
| 46 |
|
---|
| 47 | static tcp_rqueue_cb_t rcb = {
|
---|
| 48 | .seg_received = test_seg_received
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | static int seg_cnt;
|
---|
| 52 | static tcp_segment_t *recv_seg[test_seg_max];
|
---|
| 53 |
|
---|
| 54 | static void test_seg_received(inet_ep2_t *epp, tcp_segment_t *seg)
|
---|
| 55 | {
|
---|
| 56 | recv_seg[seg_cnt++] = seg;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | PCUT_TEST_BEFORE
|
---|
| 60 | {
|
---|
| 61 | int rc;
|
---|
| 62 |
|
---|
| 63 | /* We will be calling functions that perform logging */
|
---|
| 64 | rc = log_init("test-tcp");
|
---|
[d5c1051] | 65 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
[d14840d] | 66 | }
|
---|
| 67 |
|
---|
| 68 | /** Test empty queue */
|
---|
| 69 | PCUT_TEST(init_fini)
|
---|
| 70 | {
|
---|
| 71 | tcp_rqueue_init(&rcb);
|
---|
| 72 | tcp_rqueue_fibril_start();
|
---|
| 73 | tcp_rqueue_fini();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /** Test one segment */
|
---|
| 77 | PCUT_TEST(one_segment)
|
---|
| 78 | {
|
---|
| 79 | tcp_segment_t *seg;
|
---|
| 80 | inet_ep2_t epp;
|
---|
| 81 |
|
---|
| 82 | tcp_rqueue_init(&rcb);
|
---|
| 83 | seg_cnt = 0;
|
---|
| 84 |
|
---|
| 85 | seg = tcp_segment_make_ctrl(CTL_SYN);
|
---|
| 86 | PCUT_ASSERT_NOT_NULL(seg);
|
---|
| 87 | inet_ep2_init(&epp);
|
---|
| 88 |
|
---|
| 89 | tcp_rqueue_insert_seg(&epp, seg);
|
---|
| 90 | tcp_rqueue_fibril_start();
|
---|
| 91 | tcp_rqueue_fini();
|
---|
| 92 |
|
---|
| 93 | PCUT_ASSERT_INT_EQUALS(1, seg_cnt);
|
---|
| 94 | PCUT_ASSERT_EQUALS(seg, recv_seg[0]);
|
---|
| 95 |
|
---|
| 96 | tcp_segment_delete(seg);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | /** Test multiple segments */
|
---|
| 100 | PCUT_TEST(multiple_segments)
|
---|
| 101 | {
|
---|
| 102 | tcp_segment_t *seg[test_seg_max];
|
---|
| 103 | inet_ep2_t epp;
|
---|
| 104 | int i;
|
---|
| 105 |
|
---|
| 106 | tcp_rqueue_init(&rcb);
|
---|
| 107 | seg_cnt = 0;
|
---|
| 108 |
|
---|
| 109 | inet_ep2_init(&epp);
|
---|
| 110 |
|
---|
| 111 | tcp_rqueue_fibril_start();
|
---|
| 112 |
|
---|
| 113 | for (i = 0; i < test_seg_max; i++) {
|
---|
| 114 | seg[i] = tcp_segment_make_ctrl(CTL_ACK);
|
---|
| 115 | PCUT_ASSERT_NOT_NULL(seg[i]);
|
---|
| 116 | tcp_rqueue_insert_seg(&epp, seg[i]);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | tcp_rqueue_fini();
|
---|
| 120 |
|
---|
| 121 | PCUT_ASSERT_INT_EQUALS(test_seg_max, seg_cnt);
|
---|
| 122 | for (i = 0; i < test_seg_max; i++) {
|
---|
| 123 | PCUT_ASSERT_EQUALS(seg[i], recv_seg[i]);
|
---|
| 124 | tcp_segment_delete(seg[i]);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | PCUT_EXPORT(rqueue);
|
---|