test_tle_udp_dev.cpp revision a152c68e
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_udp_dev.h"
17
18TEST_F(udp_dev, udp_dev_add_null_ctx)
19{
20	dev = tle_udp_add_dev(NULL, &dev_prm);
21	EXPECT_EQ(dev, (void *) NULL);
22	EXPECT_EQ(rte_errno, EINVAL);
23}
24
25TEST_F(udp_dev, udp_dev_add_null_dev_prm)
26{
27	dev = tle_udp_add_dev(ctx, NULL);
28	EXPECT_EQ(dev, (void *) NULL);
29	EXPECT_EQ(rte_errno, EINVAL);
30}
31
32TEST_F(udp_dev, udp_dev_add_no_addr)
33{
34	memset(&(dev_prm).local_addr4, 0, sizeof(struct in_addr));
35	memset(&(dev_prm).local_addr6, 0, sizeof(struct in6_addr));
36	dev = tle_udp_add_dev(ctx, &dev_prm);
37	EXPECT_EQ(dev, (void *) NULL);
38	EXPECT_EQ(rte_errno, EINVAL);
39}
40
41TEST_F(udp_dev, udp_dev_add_anyaddr)
42{
43	inet_pton(AF_INET, "0.0.0.0", &(dev_prm).local_addr4);
44	inet_pton(AF_INET6, "::0", &(dev_prm).local_addr6);
45	dev = tle_udp_add_dev(ctx, &dev_prm);
46	EXPECT_EQ(dev, (void *) NULL);
47	EXPECT_EQ(rte_errno, EINVAL);
48}
49
50TEST_F(udp_dev, udp_dev_add_only_ipv4)
51{
52	memset(&(dev_prm).local_addr6, 0, sizeof(struct in6_addr));
53	dev = tle_udp_add_dev(ctx, &dev_prm);
54	ASSERT_NE(dev, (void *) NULL);
55	EXPECT_EQ(rte_errno, 0);
56}
57
58TEST_F(udp_dev, udp_dev_add_only_ipv6)
59{
60	memset(&(dev_prm).local_addr4, 0, sizeof(struct in_addr));
61	dev = tle_udp_add_dev(ctx, &dev_prm);
62	ASSERT_NE(dev, (void *) NULL);
63	EXPECT_EQ(rte_errno, 0);
64}
65
66TEST_F(udp_dev, udp_dev_add_nonexist_ipv4)
67{
68	memset(&(dev_prm).local_addr4, 0, sizeof(struct in_addr));
69	inet_pton(AF_INET, "10.0.0.1", &(dev_prm).local_addr4);
70	dev = tle_udp_add_dev(ctx, &dev_prm);
71	ASSERT_NE(dev, (void *) NULL);
72	EXPECT_EQ(rte_errno, 0);
73}
74
75TEST_F(udp_dev, udp_dev_add_positive)
76{
77	dev = tle_udp_add_dev(ctx, &dev_prm);
78	ASSERT_NE(dev, (void *) NULL);
79	EXPECT_EQ(rte_errno, 0);
80	dev = tle_udp_add_dev(ctx, &dev_prm);
81	ASSERT_NE(dev, (void *) NULL);
82	EXPECT_EQ(rte_errno, 0);
83}
84
85TEST_F(udp_dev, udp_dev_del_positive)
86{
87	dev = tle_udp_add_dev(ctx, &dev_prm);
88	ASSERT_NE(dev, (void *) NULL);
89	EXPECT_EQ(rte_errno, 0);
90	ASSERT_EQ(tle_udp_del_dev(dev), 0);
91	EXPECT_EQ(rte_errno, 0);
92}
93