Skip to content

Commit 632f55f

Browse files
q2venPaolo Abeni
authored andcommitted
selftest: af_unix: Add tests for -ECONNRESET.
A new function resetpair() calls close() for the receiver and checks the return value from recv() on the initial sender side. Now resetpair() is added to each test case and some additional test cases. Note that TCP sets -ECONNRESET to the consumed OOB, but we have decided not to touch TCP MSG_OOB code in the past. Before: # RUN msg_oob.no_peek.ex_oob_ex_oob ... # msg_oob.c:236:ex_oob_ex_oob:AF_UNIX :Connection reset by peer # msg_oob.c:237:ex_oob_ex_oob:Expected: # msg_oob.c:239:ex_oob_ex_oob:Expected ret[0] (-1) == expected_len (0) # ex_oob_ex_oob: Test terminated by assertion # FAIL msg_oob.no_peek.ex_oob_ex_oob not ok 14 msg_oob.no_peek.ex_oob_ex_oob ... # FAILED: 36 / 48 tests passed. # Totals: pass:36 fail:12 xfail:0 xpass:0 skip:0 error:0 After: # RUN msg_oob.no_peek.ex_oob_ex_oob ... # msg_oob.c:244:ex_oob_ex_oob:AF_UNIX : # msg_oob.c:245:ex_oob_ex_oob:TCP :Connection reset by peer # OK msg_oob.no_peek.ex_oob_ex_oob ok 14 msg_oob.no_peek.ex_oob_ex_oob ... # PASSED: 48 / 48 tests passed. # Totals: pass:48 fail:0 xfail:0 xpass:0 skip:0 error:0 Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 2a5a484 commit 632f55f

File tree

1 file changed

+115
-4
lines changed

1 file changed

+115
-4
lines changed

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

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void __sendpair(struct __test_metadata *_metadata,
210210
static void __recvpair(struct __test_metadata *_metadata,
211211
FIXTURE_DATA(msg_oob) *self,
212212
const char *expected_buf, int expected_len,
213-
int buf_len, int flags)
213+
int buf_len, int flags, bool is_sender)
214214
{
215215
int i, ret[2], recv_errno[2], expected_errno = 0;
216216
char recv_buf[2][BUF_SZ] = {};
@@ -221,7 +221,9 @@ static void __recvpair(struct __test_metadata *_metadata,
221221
errno = 0;
222222

223223
for (i = 0; i < 2; i++) {
224-
ret[i] = recv(self->fd[i * 2 + 1], recv_buf[i], buf_len, flags);
224+
int index = is_sender ? i * 2 : i * 2 + 1;
225+
226+
ret[i] = recv(self->fd[index], recv_buf[i], buf_len, flags);
225227
recv_errno[i] = errno;
226228
}
227229

@@ -308,6 +310,20 @@ static void __siocatmarkpair(struct __test_metadata *_metadata,
308310
ASSERT_EQ(answ[0], answ[1]);
309311
}
310312

313+
static void __resetpair(struct __test_metadata *_metadata,
314+
FIXTURE_DATA(msg_oob) *self,
315+
const FIXTURE_VARIANT(msg_oob) *variant,
316+
bool reset)
317+
{
318+
int i;
319+
320+
for (i = 0; i < 2; i++)
321+
close(self->fd[i * 2 + 1]);
322+
323+
__recvpair(_metadata, self, "", reset ? -ECONNRESET : 0, 1,
324+
variant->peek ? MSG_PEEK : 0, true);
325+
}
326+
311327
#define sendpair(buf, len, flags) \
312328
__sendpair(_metadata, self, buf, len, flags)
313329

@@ -316,9 +332,10 @@ static void __siocatmarkpair(struct __test_metadata *_metadata,
316332
if (variant->peek) \
317333
__recvpair(_metadata, self, \
318334
expected_buf, expected_len, \
319-
buf_len, (flags) | MSG_PEEK); \
335+
buf_len, (flags) | MSG_PEEK, false); \
320336
__recvpair(_metadata, self, \
321-
expected_buf, expected_len, buf_len, flags); \
337+
expected_buf, expected_len, \
338+
buf_len, flags, false); \
322339
} while (0)
323340

324341
#define epollpair(oob_remaining) \
@@ -330,6 +347,9 @@ static void __siocatmarkpair(struct __test_metadata *_metadata,
330347
#define setinlinepair() \
331348
__setinlinepair(_metadata, self)
332349

350+
#define resetpair(reset) \
351+
__resetpair(_metadata, self, variant, reset)
352+
333353
#define tcp_incompliant \
334354
for (self->tcp_compliant = false; \
335355
self->tcp_compliant == false; \
@@ -344,6 +364,21 @@ TEST_F(msg_oob, non_oob)
344364
recvpair("", -EINVAL, 1, MSG_OOB);
345365
epollpair(false);
346366
siocatmarkpair(false);
367+
368+
resetpair(true);
369+
}
370+
371+
TEST_F(msg_oob, non_oob_no_reset)
372+
{
373+
sendpair("x", 1, 0);
374+
epollpair(false);
375+
siocatmarkpair(false);
376+
377+
recvpair("x", 1, 1, 0);
378+
epollpair(false);
379+
siocatmarkpair(false);
380+
381+
resetpair(false);
347382
}
348383

349384
TEST_F(msg_oob, oob)
@@ -355,6 +390,19 @@ TEST_F(msg_oob, oob)
355390
recvpair("x", 1, 1, MSG_OOB);
356391
epollpair(false);
357392
siocatmarkpair(true);
393+
394+
tcp_incompliant {
395+
resetpair(false); /* TCP sets -ECONNRESET for ex-OOB. */
396+
}
397+
}
398+
399+
TEST_F(msg_oob, oob_reset)
400+
{
401+
sendpair("x", 1, MSG_OOB);
402+
epollpair(true);
403+
siocatmarkpair(true);
404+
405+
resetpair(true);
358406
}
359407

360408
TEST_F(msg_oob, oob_drop)
@@ -370,6 +418,8 @@ TEST_F(msg_oob, oob_drop)
370418
recvpair("", -EINVAL, 1, MSG_OOB);
371419
epollpair(false);
372420
siocatmarkpair(false);
421+
422+
resetpair(false);
373423
}
374424

375425
TEST_F(msg_oob, oob_ahead)
@@ -385,6 +435,10 @@ TEST_F(msg_oob, oob_ahead)
385435
recvpair("hell", 4, 4, 0);
386436
epollpair(false);
387437
siocatmarkpair(true);
438+
439+
tcp_incompliant {
440+
resetpair(false); /* TCP sets -ECONNRESET for ex-OOB. */
441+
}
388442
}
389443

390444
TEST_F(msg_oob, oob_break)
@@ -403,6 +457,8 @@ TEST_F(msg_oob, oob_break)
403457

404458
recvpair("", -EAGAIN, 1, 0);
405459
siocatmarkpair(false);
460+
461+
resetpair(false);
406462
}
407463

408464
TEST_F(msg_oob, oob_ahead_break)
@@ -426,6 +482,8 @@ TEST_F(msg_oob, oob_ahead_break)
426482
recvpair("world", 5, 5, 0);
427483
epollpair(false);
428484
siocatmarkpair(false);
485+
486+
resetpair(false);
429487
}
430488

431489
TEST_F(msg_oob, oob_break_drop)
@@ -449,6 +507,8 @@ TEST_F(msg_oob, oob_break_drop)
449507
recvpair("", -EINVAL, 1, MSG_OOB);
450508
epollpair(false);
451509
siocatmarkpair(false);
510+
511+
resetpair(false);
452512
}
453513

454514
TEST_F(msg_oob, ex_oob_break)
@@ -476,6 +536,8 @@ TEST_F(msg_oob, ex_oob_break)
476536
recvpair("ld", 2, 2, 0);
477537
epollpair(false);
478538
siocatmarkpair(false);
539+
540+
resetpair(false);
479541
}
480542

481543
TEST_F(msg_oob, ex_oob_drop)
@@ -498,6 +560,8 @@ TEST_F(msg_oob, ex_oob_drop)
498560
epollpair(false);
499561
siocatmarkpair(true);
500562
}
563+
564+
resetpair(false);
501565
}
502566

503567
TEST_F(msg_oob, ex_oob_drop_2)
@@ -523,6 +587,8 @@ TEST_F(msg_oob, ex_oob_drop_2)
523587
epollpair(false);
524588
siocatmarkpair(true);
525589
}
590+
591+
resetpair(false);
526592
}
527593

528594
TEST_F(msg_oob, ex_oob_oob)
@@ -546,6 +612,31 @@ TEST_F(msg_oob, ex_oob_oob)
546612
recvpair("", -EINVAL, 1, MSG_OOB);
547613
epollpair(false);
548614
siocatmarkpair(false);
615+
616+
resetpair(false);
617+
}
618+
619+
TEST_F(msg_oob, ex_oob_ex_oob)
620+
{
621+
sendpair("x", 1, MSG_OOB);
622+
epollpair(true);
623+
siocatmarkpair(true);
624+
625+
recvpair("x", 1, 1, MSG_OOB);
626+
epollpair(false);
627+
siocatmarkpair(true);
628+
629+
sendpair("y", 1, MSG_OOB);
630+
epollpair(true);
631+
siocatmarkpair(true);
632+
633+
recvpair("y", 1, 1, MSG_OOB);
634+
epollpair(false);
635+
siocatmarkpair(true);
636+
637+
tcp_incompliant {
638+
resetpair(false); /* TCP sets -ECONNRESET for ex-OOB. */
639+
}
549640
}
550641

551642
TEST_F(msg_oob, ex_oob_ex_oob_oob)
@@ -599,6 +690,10 @@ TEST_F(msg_oob, ex_oob_ahead_break)
599690
recvpair("d", 1, 1, MSG_OOB);
600691
epollpair(false);
601692
siocatmarkpair(true);
693+
694+
tcp_incompliant {
695+
resetpair(false); /* TCP sets -ECONNRESET for ex-OOB. */
696+
}
602697
}
603698

604699
TEST_F(msg_oob, ex_oob_siocatmark)
@@ -618,6 +713,8 @@ TEST_F(msg_oob, ex_oob_siocatmark)
618713
recvpair("hell", 4, 4, 0); /* Intentionally stop at ex-OOB. */
619714
epollpair(true);
620715
siocatmarkpair(false);
716+
717+
resetpair(true);
621718
}
622719

623720
TEST_F(msg_oob, inline_oob)
@@ -635,6 +732,8 @@ TEST_F(msg_oob, inline_oob)
635732
recvpair("x", 1, 1, 0);
636733
epollpair(false);
637734
siocatmarkpair(false);
735+
736+
resetpair(false);
638737
}
639738

640739
TEST_F(msg_oob, inline_oob_break)
@@ -656,6 +755,8 @@ TEST_F(msg_oob, inline_oob_break)
656755
recvpair("o", 1, 1, 0);
657756
epollpair(false);
658757
siocatmarkpair(false);
758+
759+
resetpair(false);
659760
}
660761

661762
TEST_F(msg_oob, inline_oob_ahead_break)
@@ -684,6 +785,8 @@ TEST_F(msg_oob, inline_oob_ahead_break)
684785

685786
epollpair(false);
686787
siocatmarkpair(false);
788+
789+
resetpair(false);
687790
}
688791

689792
TEST_F(msg_oob, inline_ex_oob_break)
@@ -709,6 +812,8 @@ TEST_F(msg_oob, inline_ex_oob_break)
709812
recvpair("rld", 3, 3, 0);
710813
epollpair(false);
711814
siocatmarkpair(false);
815+
816+
resetpair(false);
712817
}
713818

714819
TEST_F(msg_oob, inline_ex_oob_no_drop)
@@ -730,6 +835,8 @@ TEST_F(msg_oob, inline_ex_oob_no_drop)
730835
recvpair("y", 1, 1, 0);
731836
epollpair(false);
732837
siocatmarkpair(false);
838+
839+
resetpair(false);
733840
}
734841

735842
TEST_F(msg_oob, inline_ex_oob_drop)
@@ -754,6 +861,8 @@ TEST_F(msg_oob, inline_ex_oob_drop)
754861
epollpair(false);
755862
siocatmarkpair(false);
756863
}
864+
865+
resetpair(false);
757866
}
758867

759868
TEST_F(msg_oob, inline_ex_oob_siocatmark)
@@ -775,6 +884,8 @@ TEST_F(msg_oob, inline_ex_oob_siocatmark)
775884
recvpair("hell", 4, 4, 0); /* Intentionally stop at ex-OOB. */
776885
epollpair(true);
777886
siocatmarkpair(false);
887+
888+
resetpair(true);
778889
}
779890

780891
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)