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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "test_tle_tcp_stream.h"
18 /* --------- Basic tests for opening / closing streams, no traffic --------- */
20 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_nullctx)
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);
27 ret = tle_tcp_stream_close(stream);
28 EXPECT_EQ(ret, -EINVAL);
31 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_null_stream_prm)
33 stream = tle_tcp_stream_open(ctx, nullptr);
34 EXPECT_EQ(stream, nullptr);
35 EXPECT_EQ(rte_errno, EINVAL);
37 ret = tle_tcp_stream_close(stream);
38 EXPECT_EQ(ret, -EINVAL);
41 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_ipv4)
43 stream = tle_tcp_stream_open(ctx,
44 (const struct tle_tcp_stream_param *)&stream_prm);
45 ASSERT_NE(stream, nullptr);
47 ret = tle_tcp_stream_close(stream);
51 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_ipv6)
53 stream6 = tle_tcp_stream_open(ctx,
54 (const struct tle_tcp_stream_param *)&stream_prm6);
55 ASSERT_NE(stream, nullptr);
57 ret = tle_tcp_stream_close(stream6);
61 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_close_open_close)
63 stream = tle_tcp_stream_open(ctx,
64 (const struct tle_tcp_stream_param *)&stream_prm);
65 ASSERT_NE(stream, nullptr);
67 ret = tle_tcp_stream_close(stream);
70 stream = tle_tcp_stream_open(ctx,
71 (const struct tle_tcp_stream_param*)&stream_prm);
72 ASSERT_NE(stream, nullptr);
74 ret = tle_tcp_stream_close(stream);
78 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_duplicate_ipv4)
80 struct tle_stream *stream_dup;
82 stream = tle_tcp_stream_open(ctx,
83 (const struct tle_tcp_stream_param *)&stream_prm);
84 ASSERT_NE(stream, nullptr);
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);
91 ret = tle_tcp_stream_close(stream);
95 TEST_F(test_tle_tcp_stream, tcp_stream_test_open_duplicate_ipv6)
97 struct tle_stream *stream_dup;
99 stream6 = tle_tcp_stream_open(ctx,
100 (const struct tle_tcp_stream_param *)&stream_prm6);
101 ASSERT_NE(stream, nullptr);
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);
108 ret = tle_tcp_stream_close(stream6);
112 TEST_F(test_tle_tcp_stream, tcp_stream_test_close_null)
114 ret = tle_tcp_stream_close(nullptr);
115 EXPECT_EQ(ret, -EINVAL);
118 TEST_F(test_tle_tcp_stream, tcp_stream_test_closed_already)
120 stream = tle_tcp_stream_open(ctx,
121 (const struct tle_tcp_stream_param *)&stream_prm);
122 ASSERT_NE(stream, nullptr);
124 ret = tle_tcp_stream_close(stream);
127 ret = tle_tcp_stream_close(stream);
131 /* --------- Tests for get_addr call --------- */
133 TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_null_stream)
135 struct tle_tcp_stream_addr addr;
137 ret = tle_tcp_stream_get_addr(nullptr, &addr);
138 EXPECT_EQ(ret, -EINVAL);
141 TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_null_addr)
143 ret = tle_tcp_stream_get_addr(stream, NULL);
144 EXPECT_EQ(ret, -EINVAL);
147 TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_ipv4)
149 struct tle_tcp_stream_addr addr;
151 memset(&addr, 0, sizeof(addr));
152 ret = tle_tcp_stream_get_addr(stream, &addr);
155 ret = memcmp(&addr, &stream_prm.addr, sizeof(tle_tcp_stream_addr));
159 TEST_F(test_tle_tcp_stream_ops, tcp_stream_get_addr_ipv6)
161 struct tle_tcp_stream_addr addr;
163 memset(&addr, 0, sizeof(addr));
164 ret = tle_tcp_stream_get_addr(stream6, &addr);
167 ret = memcmp(&addr, &stream_prm6.addr, sizeof(tle_tcp_stream_addr));
171 /* --------- Basic tests for listen call, no incoming connections --------- */
173 TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_null_stream)
175 ret = tle_tcp_stream_listen(nullptr);
176 EXPECT_EQ(ret, -EINVAL);
179 TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_ipv4)
181 ret = tle_tcp_stream_listen(stream);
184 ret = tle_tcp_stream_close(stream);
188 TEST_F(test_tle_tcp_stream_ops, tcp_stream_listen_ipv6)
190 ret = tle_tcp_stream_listen(stream6);
193 ret = tle_tcp_stream_close(stream6);