source: mainline/uspace/srv/net/tcp/test/pdu.c@ 3f932a7e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3f932a7e was 3f932a7e, checked in by Jiri Svoboda <jiri@…>, 7 years ago

PCUT_INIT declaration also needs a terminating semicolon.

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[8ebc5b8a]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 <errno.h>
30#include <inet/endpoint.h>
[e73dbc1]31#include <mem.h>
[8ebc5b8a]32#include <pcut/pcut.h>
33#include <stdlib.h>
34
[e73dbc1]35#include "main.h"
[8ebc5b8a]36#include "../pdu.h"
37#include "../segment.h"
38
[3f932a7e]39PCUT_INIT;
[8ebc5b8a]40
41PCUT_TEST_SUITE(pdu);
42
43/** Test encode/decode round trip for control PDU */
44PCUT_TEST(encdec_syn)
45{
46 tcp_segment_t *seg, *dseg;
47 tcp_pdu_t *pdu;
48 inet_ep2_t epp, depp;
[b7fd2a0]49 errno_t rc;
[8ebc5b8a]50
51 inet_ep2_init(&epp);
52 inet_addr(&epp.local.addr, 1, 2, 3, 4);
53 inet_addr(&epp.remote.addr, 5, 6, 7, 8);
54
55 seg = tcp_segment_make_ctrl(CTL_SYN);
56 PCUT_ASSERT_NOT_NULL(seg);
57
58 seg->seq = 20;
59 seg->ack = 19;
60 seg->wnd = 18;
61 seg->up = 17;
62
63 rc = tcp_pdu_encode(&epp, seg, &pdu);
[e1b4ae0]64 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[8ebc5b8a]65 rc = tcp_pdu_decode(pdu, &depp, &dseg);
[e1b4ae0]66 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[8ebc5b8a]67
[e73dbc1]68 test_seg_same(seg, dseg);
[8ebc5b8a]69 tcp_segment_delete(seg);
70}
71
72/** Test encode/decode round trip for data PDU */
73PCUT_TEST(encdec_data)
74{
75 tcp_segment_t *seg, *dseg;
76 tcp_pdu_t *pdu;
77 inet_ep2_t epp, depp;
78 uint8_t *data;
79 size_t i, dsize;
[b7fd2a0]80 errno_t rc;
[8ebc5b8a]81
82 inet_ep2_init(&epp);
83 inet_addr(&epp.local.addr, 1, 2, 3, 4);
84 inet_addr(&epp.remote.addr, 5, 6, 7, 8);
85
86 dsize = 15;
87 data = malloc(dsize);
88 PCUT_ASSERT_NOT_NULL(data);
89
90 for (i = 0; i < dsize; i++)
91 data[i] = (uint8_t) i;
92
93 seg = tcp_segment_make_data(CTL_SYN, data, dsize);
94 PCUT_ASSERT_NOT_NULL(seg);
95
96 seg->seq = 20;
97 seg->ack = 19;
98 seg->wnd = 18;
99 seg->up = 17;
100
101 rc = tcp_pdu_encode(&epp, seg, &pdu);
[e1b4ae0]102 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[8ebc5b8a]103 rc = tcp_pdu_decode(pdu, &depp, &dseg);
[e1b4ae0]104 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
[8ebc5b8a]105
[e73dbc1]106 test_seg_same(seg, dseg);
[8ebc5b8a]107 tcp_segment_delete(seg);
108 free(data);
109}
110
111PCUT_EXPORT(pdu);
Note: See TracBrowser for help on using the repository browser.