Commit 6f9bc755 authored by Kuniyuki Iwashima's avatar Kuniyuki Iwashima Committed by Jakub Kicinski

selftest: tcp: Define the reverse order bind() tests explicitly.

Currently, bind_wildcard.c calls bind() twice for two addresses and
checks the pre-defined errno against the 2nd call.  Also, the two
bind() calls are swapped to cover various patterns how bind buckets
are created.

However, only testing two addresses is insufficient to detect regression.
So, we will add more bind() calls, and then, we need to define different
errno for each bind() per test case.

As a prepartion, let's define the reverse order bind() test cases as
fixtures.

No functional changes are intended.
Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20240326204251.51301-5-kuniyu@amazon.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c48baf56
...@@ -42,6 +42,7 @@ FIXTURE_VARIANT(bind_wildcard) ...@@ -42,6 +42,7 @@ FIXTURE_VARIANT(bind_wildcard)
int expected_errno; int expected_errno;
}; };
/* (IPv4, IPv6) */
FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_any) FIXTURE_VARIANT_ADD(bind_wildcard, v4_any_v6_any)
{ {
.family = {AF_INET, AF_INET6}, .family = {AF_INET, AF_INET6},
...@@ -98,6 +99,63 @@ FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_v4mapped_local) ...@@ -98,6 +99,63 @@ FIXTURE_VARIANT_ADD(bind_wildcard, v4_local_v6_v4mapped_local)
.expected_errno = EADDRINUSE, .expected_errno = EADDRINUSE,
}; };
/* (IPv6, IPv4) */
FIXTURE_VARIANT_ADD(bind_wildcard, v6_any_v4_any)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_any, &in4addr_any},
.expected_errno = EADDRINUSE,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_any_v4_local)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_any, &in4addr_loopback},
.expected_errno = EADDRINUSE,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_local_v4_any)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_loopback, &in4addr_any},
.expected_errno = 0,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_local_v4_local)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_loopback, &in4addr_loopback},
.expected_errno = 0,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_v4mapped_any_v4_any)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_v4mapped_any, &in4addr_any},
.expected_errno = EADDRINUSE,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_v4mapped_any_v4_local)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_v4mapped_any, &in4addr_loopback},
.expected_errno = EADDRINUSE,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_v4mapped_local_v4_any)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_v4mapped_loopback, &in4addr_any},
.expected_errno = EADDRINUSE,
};
FIXTURE_VARIANT_ADD(bind_wildcard, v6_v4mapped_local_v4_local)
{
.family = {AF_INET6, AF_INET},
.addr = {&in6addr_v4mapped_loopback, &in4addr_loopback},
.expected_errno = EADDRINUSE,
};
static void setup_addr(FIXTURE_DATA(bind_wildcard) *self, int i, static void setup_addr(FIXTURE_DATA(bind_wildcard) *self, int i,
int family, const void *addr_const) int family, const void *addr_const)
{ {
...@@ -167,18 +225,11 @@ void bind_sockets(struct __test_metadata *_metadata, ...@@ -167,18 +225,11 @@ void bind_sockets(struct __test_metadata *_metadata,
close(fd[0]); close(fd[0]);
} }
TEST_F(bind_wildcard, v4_v6) TEST_F(bind_wildcard, plain)
{ {
bind_sockets(_metadata, self, variant->expected_errno, bind_sockets(_metadata, self, variant->expected_errno,
&self->addr[0].addr, self->addrlen[0], &self->addr[0].addr, self->addrlen[0],
&self->addr[1].addr, self->addrlen[1]); &self->addr[1].addr, self->addrlen[1]);
} }
TEST_F(bind_wildcard, v6_v4)
{
bind_sockets(_metadata, self, variant->expected_errno,
&self->addr[1].addr, self->addrlen[1],
&self->addr[0].addr, self->addrlen[0]);
}
TEST_HARNESS_MAIN TEST_HARNESS_MAIN
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