test_tle_tcp_stream.cpp revision aa97dd1c
1/*
2 * Copyright (c) 2016  Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "test_tle_tcp_stream.h"
17
18/* --------- Basic tests for opening / closing  streams, no traffic --------- */
19
20TEST_F(test_tle_tcp_stream, tcp_stream_test_open_nullctx)
21{
22	stream = tle_tcp_stream_open(nullptr,
23			(const struct tle_tcp_stream_param *)&stream_prm);
24	EXPECT_EQ(stream, nullptr);
25	EXPECT_EQ(rte_errno, EINVAL);
26
27	ret = tle_tcp_stream_close(stream);
28	EXPECT_EQ(ret, -EINVAL);
29}
30
31TEST_F(test_tle_tcp_stream, tcp_stream_test_open_null_stream_prm)
32{
33	stream = tle_tcp_stream_open(ctx, nullptr);
34	EXPECT_EQ(stream, nullptr);
35	EXPECT_EQ(rte_errno, EINVAL);
36
37	ret = tle_tcp_stream_close(stream);
38	EXPECT_EQ(ret, -EINVAL);
39}
40
41TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_ipv4)
42{
43	stream = tle_tcp_stream_open(ctx,
44			(const struct tle_tcp_stream_param *)&stream_prm);
45	ASSERT_NE(stream, nullptr);
46
47	ret = tle_tcp_stream_close(stream);
48	ASSERT_EQ(ret, 0);
49}
50
51TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_ipv6)
52{
53	stream6 = tle_tcp_stream_open(ctx,
54			(const struct tle_tcp_stream_param *)&stream_prm6);
55	ASSERT_NE(stream, nullptr);
56
57	ret = tle_tcp_stream_close(stream6);
58	ASSERT_EQ(ret, 0);
59}
60
61TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_open_close)
62{
63	stream = tle_tcp_stream_open(ctx,
64			(const struct tle_tcp_stream_param *)&stream_prm);
65	ASSERT_NE(stream, nullptr);
66
67	ret = tle_tcp_stream_close(stream);
68	ASSERT_EQ(ret, 0);
69
70	stream = tle_tcp_stream_open(ctx,
71			(const struct tle_tcp_stream_param*)&stream_prm);
72	ASSERT_NE(stream, nullptr);
73
74	ret = tle_tcp_stream_close(stream);
75	ASSERT_EQ(ret, 0);
76}
77
78TEST_F(test_tle_tcp_stream, tcp_stream_test_open_duplicate_ipv4)
79{
80	struct tle_stream *stream_dup;
81
82	stream = tle_tcp_stream_open(ctx,
83			(const struct tle_tcp_stream_param *)&stream_prm);
84	ASSERT_NE(stream, nullptr);
85
86	stream_dup = tle_tcp_stream_open(ctx,
87			(const struct tle_tcp_stream_param*)&stream_prm);
88	ASSERT_EQ(stream_dup, nullptr);
89	ASSERT_EQ(rte_errno, EEXIST);
90
91	ret = tle_tcp_stream_close(stream);
92	ASSERT_EQ(ret, 0);
93}
94
95TEST_F(test_tle_tcp_stream, tcp_stream_test_open_duplicate_ipv6)
96{
97	struct tle_stream *stream_dup;
98
99	stream6 = tle_tcp_stream_open(ctx,
100			(const struct tle_tcp_stream_param *)&stream_prm6);
101	ASSERT_NE(stream, nullptr);
102
103	stream_dup = tle_tcp_stream_open(ctx,
104			(const struct tle_tcp_stream_param*)&stream_prm6);
105	ASSERT_EQ(stream_dup, nullptr);
106	ASSERT_EQ(rte_errno, EEXIST);
107
108	ret = tle_tcp_stream_close(stream6);
109	ASSERT_EQ(ret, 0);
110}
111
112TEST_F(test_tle_tcp_stream, tcp_stream_test_close_null)
113{
114	ret = tle_tcp_stream_close(nullptr);
115	EXPECT_EQ(ret, -EINVAL);
116}
117
118TEST_F(test_tle_tcp_stream, tcp_stream_test_closed_already)
119{
120	stream = tle_tcp_stream_open(ctx,
121			(const struct tle_tcp_stream_param *)&stream_prm);
122	ASSERT_NE(stream, nullptr);
123
124	ret = tle_tcp_stream_close(stream);
125	EXPECT_EQ(ret, 0);
126
127	ret = tle_tcp_stream_close(stream);
128	EXPECT_NE(ret, 0);
129}
130
131/* --------- Tests for get_addr call  --------- */
132
133TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_null_stream)
134{
135	struct tle_tcp_stream_addr addr;
136
137	ret = tle_tcp_stream_get_addr(nullptr, &addr);
138	EXPECT_EQ(ret, -EINVAL);
139}
140
141TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_null_addr)
142{
143	ret = tle_tcp_stream_get_addr(stream, NULL);
144	EXPECT_EQ(ret, -EINVAL);
145}
146
147TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_ipv4)
148{
149	struct tle_tcp_stream_addr addr;
150
151	memset(&addr, 0, sizeof(addr));
152	ret = tle_tcp_stream_get_addr(stream, &addr);
153	ASSERT_EQ(ret, 0);
154
155	ret = memcmp(&addr, &stream_prm.addr, sizeof(tle_tcp_stream_addr));
156	ASSERT_EQ(ret, 0);
157}
158
159TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_ipv6)
160{
161	struct tle_tcp_stream_addr addr;
162
163	memset(&addr, 0, sizeof(addr));
164	ret = tle_tcp_stream_get_addr(stream6, &addr);
165	ASSERT_EQ(ret, 0);
166
167	ret = memcmp(&addr, &stream_prm6.addr, sizeof(tle_tcp_stream_addr));
168	ASSERT_EQ(ret, 0);
169}
170
171/* --------- Basic tests for listen call, no incoming connections  --------- */
172
173TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_null_stream)
174{
175	ret = tle_tcp_stream_listen(nullptr);
176	EXPECT_EQ(ret, -EINVAL);
177}
178
179TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_ipv4)
180{
181	ret = tle_tcp_stream_listen(stream);
182	ASSERT_EQ(ret, 0);
183
184	ret = tle_tcp_stream_close(stream);
185	ASSERT_EQ(ret, 0);
186}
187
188TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_ipv6)
189{
190	ret = tle_tcp_stream_listen(stream6);
191	ASSERT_EQ(ret, 0);
192
193	ret = tle_tcp_stream_close(stream6);
194	ASSERT_EQ(ret, 0);
195}
196