source: mainline/uspace/srv/net/tcp/test/rqueue.c@ 39b54fe

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 39b54fe was d5c1051, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

"Obviously harmless" error handling tweaks.

  • Property mode set to 100644
File size: 3.2 KB
Line 
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
37PCUT_INIT
38
39PCUT_TEST_SUITE(rqueue);
40
41enum {
42 test_seg_max = 10
43};
44
45static void test_seg_received(inet_ep2_t *, tcp_segment_t *);
46
47static tcp_rqueue_cb_t rcb = {
48 .seg_received = test_seg_received
49};
50
51static int seg_cnt;
52static tcp_segment_t *recv_seg[test_seg_max];
53
54static void test_seg_received(inet_ep2_t *epp, tcp_segment_t *seg)
55{
56 recv_seg[seg_cnt++] = seg;
57}
58
59PCUT_TEST_BEFORE
60{
61 int rc;
62
63 /* We will be calling functions that perform logging */
64 rc = log_init("test-tcp");
65 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
66}
67
68/** Test empty queue */
69PCUT_TEST(init_fini)
70{
71 tcp_rqueue_init(&rcb);
72 tcp_rqueue_fibril_start();
73 tcp_rqueue_fini();
74}
75
76/** Test one segment */
77PCUT_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 */
100PCUT_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
129PCUT_EXPORT(rqueue);
Note: See TracBrowser for help on using the repository browser.