aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/perl-xs/t/testutl.pl
blob: add6f6a45cd9e48292c8208210495040fb61bdbe (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
#!/usr/bin/perl 

sub random_message_ok
{
    my ($pipe, $iter, $chunkmax) = @_;
    $iter = 100 unless defined $iter;
    $chunkmax = 300 unless defined $chunkmax;
    eval {
	my $input = '';
	$pipe->start_msg();
	for(my $i = 0; $i < $iter; $i++)
	{
	    my $chunk = '';
	    my $chunklen = int(rand($chunkmax));
	    $chunk .= pack("C", int(rand(256))) while $chunklen--;
	    $input .= $chunk;
	    $pipe->write($chunk);
	}
	$pipe->end_msg();
	my $msg_num = $pipe->message_count() -1;
	my $output = $pipe->read(0xFFFFFFFF, $msg_num);
	return $input eq $output;
    };
}

1;