X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fcmd_ipc.t;h=cd76d5e896d160a015e19a9f9e119bfa0ffaa188;hb=115d59641bda19405a3ed82dc72e129f9196fad5;hp=84f8fb4d2ca20f492d98592ae65c6f78e5f31835;hpb=509c88ddfe0bb3bf4f00ff119eb2d847512df90c;p=public-inbox.git
diff --git a/t/cmd_ipc.t b/t/cmd_ipc.t
index 84f8fb4d..cd76d5e8 100644
--- a/t/cmd_ipc.t
+++ b/t/cmd_ipc.t
@@ -1,5 +1,5 @@
#!perl -w
-# Copyright (C) 2021 all contributors
+# Copyright (C) all contributors
# License: AGPL-3.0+
use strict;
use v5.10.1;
@@ -10,7 +10,6 @@ pipe(my ($r, $w)) or BAIL_OUT;
my ($send, $recv);
require_ok 'PublicInbox::Spawn';
my $SOCK_SEQPACKET = eval { Socket::SOCK_SEQPACKET() } // undef;
-use Time::HiRes qw(alarm);
my $do_test = sub { SKIP: {
my ($type, $flag, $desc) = @_;
@@ -53,13 +52,25 @@ my $do_test = sub { SKIP: {
is_deeply(\@fds, [ undef ], "EAGAIN $desc");
$s2->blocking(1);
- my $alrm = 0;
- local $SIG{ALRM} = sub { $alrm++ };
- alarm(0.001);
- @fds = $recv->($s2, $buf, length($src) + 1);
- ok($!{EINTR}, "EINTR set by ($desc)");
- is_deeply(\@fds, [ undef ], "EINTR $desc");
- is($alrm, 1, 'SIGALRM hit');
+ if ($ENV{TEST_ALRM}) {
+ my $alrm = 0;
+ local $SIG{ALRM} = sub { $alrm++ };
+ my $tgt = $$;
+ my $pid = fork // xbail "fork: $!";
+ if ($pid == 0) {
+ # need to loop since Perl signals are racy
+ # (the interpreter doesn't self-pipe)
+ while (tick(0.01)) {
+ kill 'ALRM', $tgt;
+ }
+ }
+ @fds = $recv->($s2, $buf, length($src) + 1);
+ ok($!{EINTR}, "EINTR set by ($desc)");
+ kill('KILL', $pid);
+ waitpid($pid, 0);
+ is_deeply(\@fds, [ undef ], "EINTR $desc");
+ ok($alrm, 'SIGALRM hit');
+ }
close $s1;
@fds = $recv->($s2, $buf, length($src) + 1);
@@ -73,7 +84,9 @@ my $do_test = sub { SKIP: {
$nsent += $n;
fail "sent 0 bytes" if $n == 0;
}
- ok($!{EAGAIN}, "hit EAGAIN on send $desc");
+ ok($!{EAGAIN} || $!{ETOOMANYREFS},
+ "hit EAGAIN || ETOOMANYREFS on send $desc") or
+ diag "send failed with: $!";
ok($nsent > 0, 'sent some bytes');
socketpair($s1, $s2, AF_UNIX, $type, 0) or BAIL_OUT $!;
@@ -93,8 +106,9 @@ my $do_test = sub { SKIP: {
diag "sent $nr, retrying with more";
$nr += 2 * 1024 * 1024;
} else {
- ok($!{EMSGSIZE}, 'got EMSGSIZE');
- # diag "$nr bytes hits EMSGSIZE";
+ ok($!{EMSGSIZE} || $!{ENOBUFS},
+ 'got EMSGSIZE or ENOBUFS') or
+ diag "$nr bytes fails with: $!";
last;
}
}
@@ -127,4 +141,15 @@ SKIP: {
}
}
+SKIP: {
+ skip 'not Linux', 1 if $^O ne 'linux';
+ require_ok 'PublicInbox::Syscall';
+ $send = PublicInbox::Syscall->can('send_cmd4') or
+ skip 'send_cmd4 not defined for arch';
+ $recv = PublicInbox::Syscall->can('recv_cmd4') or
+ skip 'recv_cmd4 not defined for arch';
+ $do_test->(SOCK_STREAM, 0, 'PP Linux stream');
+ $do_test->($SOCK_SEQPACKET, MSG_EOR, 'PP Linux seqpacket');
+}
+
done_testing;