summaryrefslogtreecommitdiff
path: root/regress/usr.sbin/syslogd/args-client-tcp-multichunks.pl
blob: 3490caed3647044e386794c6319f94087d798aea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# The syslogd listens on 127.0.0.1 TCP socket.
# The client writes a message into a 127.0.0.1 TCP socket in multiple chunks.
# The syslogd writes it into a file and through a pipe.
# The syslogd passes it via UDP to the loghost.
# The server receives the message on its UDP socket.
# Find the message in file, pipe, syslogd, server log.
# Check that the file log contains the complete message.

use strict;
use warnings;
use Socket;

my $msglen = length(get_testlog());
my $framelen = $msglen + 1;

our %args = (
    client => {
	connect => { domain => AF_INET, proto => "tcp", addr => "127.0.0.1",
	    port => 514 },
	func => sub {
	    my $self = shift;
	    local $| = 1;
	    my $n = 0;
	    foreach (get_testlog() =~ /.{1,5}/g) {
		$n += length;
		print;
		print STDERR "<<< $_\n";
		${$self->{syslogd}}->loggrep("tcp logger .* buffer $n bytes", 5)
		    or die ref($self), " syslogd did not buffer $n bytes";
	    }
	    $n++;
	    print "\n";
	    ${$self->{syslogd}}->loggrep("tcp logger .* use $n bytes", 5)
		or die ref($self), " syslogd did not use $n bytes";
	    write_shutdown($self);
	},
	loggrep => {},
    },
    syslogd => {
	options => ["-T", "127.0.0.1:514"],
	loggrep => {
	    qr/tcp logger .* buffer \d+ bytes/ => int(($msglen+4)/5),
	    qr/tcp logger .* non transparent framing, use $framelen bytes/ => 1,
	    get_testgrep() => 1,
	},
    },
);

1;