Commit 2895d879 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by David S. Miller

selftest: tcp: Move expected_errno into each test case in bind_wildcard.c.

This is a preparation patch for the following patch.

Let's define expected_errno in each test case so that we can add other test
cases easily.
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0071d155
...@@ -10,37 +10,41 @@ FIXTURE(bind_wildcard) ...@@ -10,37 +10,41 @@ FIXTURE(bind_wildcard)
{ {
struct sockaddr_in addr4; struct sockaddr_in addr4;
struct sockaddr_in6 addr6; struct sockaddr_in6 addr6;
int expected_errno;
}; };
FIXTURE_VARIANT(bind_wildcard) FIXTURE_VARIANT(bind_wildcard)
{ {
const __u32 addr4_const; const __u32 addr4_const;
const struct in6_addr *addr6_const; const struct in6_addr *addr6_const;
int expected_errno;
}; };
FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_any) FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_any)
{ {
.addr4_const = INADDR_ANY, .addr4_const = INADDR_ANY,
.addr6_const = &in6addr_any, .addr6_const = &in6addr_any,
.expected_errno = EADDRINUSE,
}; };
FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_local) FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_local)
{ {
.addr4_const = INADDR_ANY, .addr4_const = INADDR_ANY,
.addr6_const = &in6addr_loopback, .addr6_const = &in6addr_loopback,
.expected_errno = 0,
}; };
FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_any) FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_any)
{ {
.addr4_const = INADDR_LOOPBACK, .addr4_const = INADDR_LOOPBACK,
.addr6_const = &in6addr_any, .addr6_const = &in6addr_any,
.expected_errno = EADDRINUSE,
}; };
FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_local) FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_local)
{ {
.addr4_const = INADDR_LOOPBACK, .addr4_const = INADDR_LOOPBACK,
.addr6_const = &in6addr_loopback, .addr6_const = &in6addr_loopback,
.expected_errno = 0,
}; };
FIXTURE_SETUP(bind_wildcard) FIXTURE_SETUP(bind_wildcard)
...@@ -52,11 +56,6 @@ FIXTURE_SETUP(bind_wildcard) ...@@ -52,11 +56,6 @@ FIXTURE_SETUP(bind_wildcard)
self->addr6.sin6_family = AF_INET6; self->addr6.sin6_family = AF_INET6;
self->addr6.sin6_port = htons(0); self->addr6.sin6_port = htons(0);
self->addr6.sin6_addr = *variant->addr6_const; self->addr6.sin6_addr = *variant->addr6_const;
if (variant->addr6_const == &in6addr_any)
self->expected_errno = EADDRINUSE;
else
self->expected_errno = 0;
} }
FIXTURE_TEARDOWN(bind_wildcard) FIXTURE_TEARDOWN(bind_wildcard)
...@@ -65,6 +64,7 @@ FIXTURE_TEARDOWN(bind_wildcard) ...@@ -65,6 +64,7 @@ FIXTURE_TEARDOWN(bind_wildcard)
void bind_sockets(struct __test_metadata *_metadata, void bind_sockets(struct __test_metadata *_metadata,
FIXTURE_DATA(bind_wildcard) *self, FIXTURE_DATA(bind_wildcard) *self,
int expected_errno,
struct sockaddr *addr1, socklen_t addrlen1, struct sockaddr *addr1, socklen_t addrlen1,
struct sockaddr *addr2, socklen_t addrlen2) struct sockaddr *addr2, socklen_t addrlen2)
{ {
...@@ -86,9 +86,9 @@ void bind_sockets(struct __test_metadata *_metadata, ...@@ -86,9 +86,9 @@ void bind_sockets(struct __test_metadata *_metadata,
ASSERT_GT(fd[1], 0); ASSERT_GT(fd[1], 0);
ret = bind(fd[1], addr2, addrlen2); ret = bind(fd[1], addr2, addrlen2);
if (self->expected_errno) { if (expected_errno) {
ASSERT_EQ(ret, -1); ASSERT_EQ(ret, -1);
ASSERT_EQ(errno, self->expected_errno); ASSERT_EQ(errno, expected_errno);
} else { } else {
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
} }
...@@ -99,14 +99,14 @@ void bind_sockets(struct __test_metadata *_metadata, ...@@ -99,14 +99,14 @@ void bind_sockets(struct __test_metadata *_metadata,
TEST_F(bind_wildcard, v4_v6) TEST_F(bind_wildcard, v4_v6)
{ {
bind_sockets(_metadata, self, bind_sockets(_metadata, self, variant->expected_errno,
(struct sockaddr *)&self->addr4, sizeof(self->addr4), (struct sockaddr *)&self->addr4, sizeof(self->addr4),
(struct sockaddr *)&self->addr6, sizeof(self->addr6)); (struct sockaddr *)&self->addr6, sizeof(self->addr6));
} }
TEST_F(bind_wildcard, v6_v4) TEST_F(bind_wildcard, v6_v4)
{ {
bind_sockets(_metadata, self, bind_sockets(_metadata, self, variant->expected_errno,
(struct sockaddr *)&self->addr6, sizeof(self->addr6), (struct sockaddr *)&self->addr6, sizeof(self->addr6),
(struct sockaddr *)&self->addr4, sizeof(self->addr4)); (struct sockaddr *)&self->addr4, sizeof(self->addr4));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment