File: 900_rand.t

package info (click to toggle)
libsereal-decoder-perl 5.004%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,556 kB
  • sloc: ansic: 11,615; perl: 6,938; sh: 25; makefile: 9
file content (56 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
use strict;
use warnings;

use Test::More;
use Test::Warn;
use Sereal::Decoder qw(:all);
use Sereal::Decoder::Constants qw(:all);
use lib ( 't/lib', 'lib' );
use Sereal::TestSet qw(hobodecode);
use Devel::Peek;

my $seed= $ENV{SRAND} || ( time ^ int rand(1000000) ^ $$ );
srand($seed);
warn("Seed for this test was: $seed\n");

my $header= SRL_MAGIC_STRING . chr(1) . chr(0);
my $header_v2= SRL_MAGIC_STRING . chr(2) . chr(0);
my $header_snappy= SRL_MAGIC_STRING . chr( 1 + 16 ) . chr(0);
my $decoder= Sereal::Decoder->new;
for my $i ( 1 .. 2e9 ) {
    my $content= '';
    my $len= 200;

    #my $len = int( rand() * 200 );
    $content .= chr( int( rand() * 256 ) ) for 1 .. $len;

    foreach my $hdr (
        [ 'v1', $header ],
        [ 'v2', $header_v2 ],

        #                 ['snappy', $header_snappy] # snappy not safe to random crapola (pity)
        )
    {
        my $out;
        my $ok;
        my $data= "$hdr->[1]$content";
        while ( $len-- > 0 ) {
            if ( $ENV{DEBUG_SEREAL} ) {

                #note("'$data'");
                Dump($data);

                #hobodecode($data);
            }
            warnings_are {
                eval { $decoder->decode($data) }
            }
            [], "Alive and no warnings ($i, $len, $hdr->[0])";
            chop $data;
        }
    }
}

pass("Alive");
done_testing();