source: mainline/uspace/srv/net/tcp/test/conn.c@ 9713b0b

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

Start adding tests for TCP conn module. Make sure all connections have been freed at the end of a test.

  • Property mode set to 100644
File size: 2.7 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 <errno.h>
30#include <inet/endpoint.h>
31#include <io/log.h>
32#include <pcut/pcut.h>
33
34#include "../conn.h"
35
36PCUT_INIT
37
38PCUT_TEST_SUITE(conn);
39
40PCUT_TEST_BEFORE
41{
42 int rc;
43
44 /* We will be calling functions that perform logging */
45 rc = log_init("test-tcp");
46 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
47
48 rc = tcp_conns_init();
49 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
50}
51
52PCUT_TEST_AFTER
53{
54 tcp_conns_fini();
55}
56
57/** Test creating and deleting connection */
58PCUT_TEST(new_delete)
59{
60 tcp_conn_t *conn;
61 inet_ep2_t epp;
62
63 inet_ep2_init(&epp);
64 conn = tcp_conn_new(&epp);
65 PCUT_ASSERT_NOT_NULL(conn);
66
67 tcp_conn_lock(conn);
68 tcp_conn_reset(conn);
69 tcp_conn_unlock(conn);
70 tcp_conn_delete(conn);
71}
72
73/** Test adding, finding and removing a connection */
74PCUT_TEST(add_find_remove)
75{
76 tcp_conn_t *conn, *cfound;
77 inet_ep2_t epp;
78 int rc;
79
80 inet_ep2_init(&epp);
81
82 conn = tcp_conn_new(&epp);
83 PCUT_ASSERT_NOT_NULL(conn);
84
85 rc = tcp_conn_add(conn);
86 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
87
88 /* Find the connection */
89 cfound = tcp_conn_find_ref(&conn->ident);
90 PCUT_ASSERT_EQUALS(conn, cfound);
91 tcp_conn_delref(cfound);
92
93 /* We should have been assigned a port address, should not match */
94 cfound = tcp_conn_find_ref(&epp);
95 PCUT_ASSERT_EQUALS(NULL, cfound);
96
97 tcp_conn_lock(conn);
98 tcp_conn_reset(conn);
99 tcp_conn_unlock(conn);
100 tcp_conn_delete(conn);
101}
102
103PCUT_EXPORT(conn);
Note: See TracBrowser for help on using the repository browser.