test_tle_udp_dev.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_udp_dev.h"
17
18TEST_F(udp_dev, udp_dev_add_null_ctx)
19{
20	dev = tle_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_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_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_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_add_dev(ctx, &dev_prm);
54	ASSERT_NE(dev, (void *) NULL);
55	EXPECT_EQ(rte_errno, 0);
56	devs.push_back(dev);
57}
58
59TEST_F(udp_dev, udp_dev_add_only_ipv6)
60{
61	memset(&(dev_prm).local_addr4, 0, sizeof(struct in_addr));
62	dev = tle_add_dev(ctx, &dev_prm);
63	ASSERT_NE(dev, (void *) NULL);
64	EXPECT_EQ(rte_errno, 0);
65	devs.push_back(dev);
66}
67
68TEST_F(udp_dev, udp_dev_add_nonexist_ipv4)
69{
70	memset(&(dev_prm).local_addr4, 0, sizeof(struct in_addr));
71	inet_pton(AF_INET, "10.0.0.1", &(dev_prm).local_addr4);
72	dev = tle_add_dev(ctx, &dev_prm);
73	ASSERT_NE(dev, (void *) NULL);
74	EXPECT_EQ(rte_errno, 0);
75	devs.push_back(dev);
76}
77
78TEST_F(udp_dev, udp_dev_add_positive)
79{
80	dev = tle_add_dev(ctx, &dev_prm);
81	ASSERT_NE(dev, (void *) NULL);
82	EXPECT_EQ(rte_errno, 0);
83	devs.push_back(dev);
84}
85
86TEST_F(udp_dev, udp_dev_add_max)
87{
88	int i;
89	for(i = 0; i < RTE_MAX_ETHPORTS; i++) {
90		dev = tle_add_dev(ctx, &dev_prm);
91		ASSERT_NE(dev, (void *) NULL);
92		EXPECT_EQ(rte_errno, 0);
93		devs.push_back(dev);
94	}
95	dev = tle_add_dev(ctx, &dev_prm);
96	ASSERT_EQ(dev, (void *) NULL);
97	EXPECT_EQ(rte_errno, ENODEV);
98}
99
100TEST_F(udp_dev, udp_dev_del_positive)
101{
102	dev = tle_add_dev(ctx, &dev_prm);
103	ASSERT_NE(dev, (void *) NULL);
104	EXPECT_EQ(rte_errno, 0);
105	devs.push_back(dev);
106	ASSERT_EQ(tle_del_dev(dev), 0);
107	EXPECT_EQ(rte_errno, 0);
108}
109
110TEST_F(udp_dev, udp_dev_del_null_dev)
111{
112	ASSERT_EQ(tle_del_dev(dev), -EINVAL);
113}
114