Skip to content

Commit f5ea076

Browse files
q2venPaolo Abeni
authored andcommitted
selftest: af_unix: Add non-TCP-compliant test cases in msg_oob.c.
While testing, I found some weird behaviour on the TCP side as well. For example, TCP drops the preceding OOB data when queueing a new OOB data if the old OOB data is at the head of recvq. # RUN msg_oob.no_peek.ex_oob_drop ... # msg_oob.c:146:ex_oob_drop:AF_UNIX :x # msg_oob.c:147:ex_oob_drop:TCP :Resource temporarily unavailable # msg_oob.c:146:ex_oob_drop:AF_UNIX :y # msg_oob.c:147:ex_oob_drop:TCP :Invalid argument # OK msg_oob.no_peek.ex_oob_drop ok 9 msg_oob.no_peek.ex_oob_drop # RUN msg_oob.no_peek.ex_oob_drop_2 ... # msg_oob.c:146:ex_oob_drop_2:AF_UNIX :x # msg_oob.c:147:ex_oob_drop_2:TCP :Resource temporarily unavailable # OK msg_oob.no_peek.ex_oob_drop_2 ok 10 msg_oob.no_peek.ex_oob_drop_2 This patch allows AF_UNIX's MSG_OOB implementation to produce different results from TCP when operations are guarded with tcp_incompliant{}. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 93c99f2 commit f5ea076

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

tools/testing/selftests/net/af_unix/msg_oob.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FIXTURE(msg_oob)
1919
* 2: TCP sender
2020
* 3: TCP receiver
2121
*/
22+
bool tcp_compliant;
2223
};
2324

2425
FIXTURE_VARIANT(msg_oob)
@@ -88,6 +89,8 @@ FIXTURE_SETUP(msg_oob)
8889
{
8990
create_unix_socketpair(_metadata, self);
9091
create_tcp_socketpair(_metadata, self);
92+
93+
self->tcp_compliant = true;
9194
}
9295

9396
FIXTURE_TEARDOWN(msg_oob)
@@ -115,6 +118,7 @@ static void __recvpair(struct __test_metadata *_metadata,
115118
{
116119
int i, ret[2], recv_errno[2], expected_errno = 0;
117120
char recv_buf[2][BUF_SZ] = {};
121+
bool printed = false;
118122

119123
ASSERT_GE(BUF_SZ, buf_len);
120124

@@ -142,8 +146,12 @@ static void __recvpair(struct __test_metadata *_metadata,
142146
TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
143147
TH_LOG("TCP :%s", ret[1] < 0 ? strerror(recv_errno[1]) : recv_buf[1]);
144148

145-
ASSERT_EQ(ret[0], ret[1]);
146-
ASSERT_EQ(recv_errno[0], recv_errno[1]);
149+
printed = true;
150+
151+
if (self->tcp_compliant) {
152+
ASSERT_EQ(ret[0], ret[1]);
153+
ASSERT_EQ(recv_errno[0], recv_errno[1]);
154+
}
147155
}
148156

149157
if (expected_len >= 0) {
@@ -159,10 +167,13 @@ static void __recvpair(struct __test_metadata *_metadata,
159167

160168
cmp = strncmp(recv_buf[0], recv_buf[1], expected_len);
161169
if (cmp) {
162-
TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
163-
TH_LOG("TCP :%s", ret[1] < 0 ? strerror(recv_errno[1]) : recv_buf[1]);
170+
if (!printed) {
171+
TH_LOG("AF_UNIX :%s", ret[0] < 0 ? strerror(recv_errno[0]) : recv_buf[0]);
172+
TH_LOG("TCP :%s", ret[1] < 0 ? strerror(recv_errno[1]) : recv_buf[1]);
173+
}
164174

165-
ASSERT_EQ(cmp, 0);
175+
if (self->tcp_compliant)
176+
ASSERT_EQ(cmp, 0);
166177
}
167178
}
168179
}
@@ -180,6 +191,11 @@ static void __recvpair(struct __test_metadata *_metadata,
180191
expected_buf, expected_len, buf_len, flags); \
181192
} while (0)
182193

194+
#define tcp_incompliant \
195+
for (self->tcp_compliant = false; \
196+
self->tcp_compliant == false; \
197+
self->tcp_compliant = true)
198+
183199
TEST_F(msg_oob, non_oob)
184200
{
185201
sendpair("x", 1, 0);
@@ -249,4 +265,27 @@ TEST_F(msg_oob, ex_oob_break)
249265
recvpair("ld", 2, 2, 0);
250266
}
251267

268+
TEST_F(msg_oob, ex_oob_drop)
269+
{
270+
sendpair("x", 1, MSG_OOB);
271+
sendpair("y", 1, MSG_OOB); /* TCP drops "x" at this moment. */
272+
273+
tcp_incompliant {
274+
recvpair("x", 1, 1, 0); /* TCP drops "y" by passing through it. */
275+
recvpair("y", 1, 1, MSG_OOB); /* TCP returns -EINVAL. */
276+
}
277+
}
278+
279+
TEST_F(msg_oob, ex_oob_drop_2)
280+
{
281+
sendpair("x", 1, MSG_OOB);
282+
sendpair("y", 1, MSG_OOB); /* TCP drops "x" at this moment. */
283+
284+
recvpair("y", 1, 1, MSG_OOB);
285+
286+
tcp_incompliant {
287+
recvpair("x", 1, 1, 0); /* TCP returns -EAGAIN. */
288+
}
289+
}
290+
252291
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)