MCPcopy Create free account
hub / github.com/apache/impala / TEST

Function TEST

be/src/kudu/util/net/socket-test.cc:56–95  ·  view source on GitHub ↗

A test scenario to make sure Sockaddr::HashCode() works as expected for addresses which are logically the same. In essence, the implementation of the Sockaddr class should zero out the zero padding field sockaddr_in::sin_zero to avoid issues related to not-initialized and former contents of the memory backing the zero padding field.

Source from the content-addressed store, hash-verified

54// sockaddr_in::sin_zero to avoid issues related to not-initialized and former
55// contents of the memory backing the zero padding field.
56TEST(SockaddrHashTest, ZeroPadding) {
57 constexpr const char* const kIpAddr = "127.0.0.1";
58 constexpr const char* const kPath = "/tmp/some/long/enough/path/to.sock";
59 constexpr uint16_t kPort = 5678;
60
61 Sockaddr s_in;
62 ASSERT_OK(s_in.ParseString(kIpAddr, kPort));
63
64 Sockaddr s_un;
65 ASSERT_OK(s_un.ParseUnixDomainPath(kPath));
66
67 // Make 's_un' to be logically the same object as 's_in', but reusing the
68 // Sockaddr::storage_ field from its prior incarnation.
69 ASSERT_OK(s_un.ParseString(kIpAddr, kPort));
70
71 // The hash should be the same since 's_in' and 's_un' represent the same
72 // logical entity.
73 ASSERT_EQ(s_in.HashCode(), s_un.HashCode());
74 ASSERT_EQ(s_in, s_un);
75
76 Sockaddr s_in_0(s_in);
77 ASSERT_EQ(s_in.HashCode(), s_in_0.HashCode());
78 ASSERT_EQ(s_in, s_in_0);
79
80 Sockaddr s_in_1(s_un);
81 ASSERT_EQ(s_in.HashCode(), s_in_1.HashCode());
82 ASSERT_EQ(s_in, s_in_1);
83
84 Sockaddr s_un_0;
85 ASSERT_OK(s_un.ParseUnixDomainPath(kPath));
86 s_un_0 = s_in_0;
87 ASSERT_EQ(s_in.HashCode(), s_un_0.HashCode());
88 ASSERT_EQ(s_in_0, s_un_0);
89
90 Sockaddr s_un_1;
91 ASSERT_OK(s_un_1.ParseUnixDomainPath(kPath));
92 s_un_1 = s_in.ipv4_addr();
93 ASSERT_EQ(s_in.HashCode(), s_un_1.HashCode());
94 ASSERT_EQ(s_in, s_un_1);
95}
96
97class SocketTest : public KuduTest {
98 protected:

Callers

nothing calls this directly

Calls 3

ParseUnixDomainPathMethod · 0.80
ParseStringMethod · 0.45
HashCodeMethod · 0.45

Tested by

no test coverage detected