#!/usr/bin/perl # test_marker.pl - Don Yang (uguu.org) # # 03/15/04 use strict; my ($i, $o, $s, $l, $r, $l0, $r0, @c); my ($alpha, $digit, $alnum, $space); my ($notalpha, $notdigit, $notalnum, $notspace); my ($cmd, $prefix); local (*FILE); $ARGV[0] && (srand $ARGV[0]); $cmd = ($ARGV[1] || "./yume"); $prefix = ($ARGV[2] || "test_marker.test$$"); @c = ( "asdiASDI01////((((((", "asdiASDI011//((((", "asdiASDI011//((", "1234//(", "123456789/" ); $alpha = join('', ('a' .. 'z', 'A' .. 'Z')); $digit = join('', ('0' .. '9')); $alnum = $alpha . $digit; $space = " \t"; $notalpha = ":" . $digit . $space; $notdigit = ":" . $alpha . $space; $notalnum = ":" . $space; $notspace = ":" . $alnum; sub GenExpr { my ($depth) = @_; my ($r, $i, $j, $k); $r = ''; $k = int(rand 4) + 1; for($i = 0; $i < $k; $i++) { $j = substr($c[$depth], int(rand(length $c[$depth])), 1); if( $j eq '(' ) { $r .= '(' . GenExpr($depth + 1) . ')' . int(rand 6); } elsif( $j eq '/' ) { $r .= '/' . ('a' .. 'z', 'A' .. 'Z')[int(rand 52)]; } else { $r .= $j; } } return $r; } sub ExpandExpr { my ($e, $dir) = @_; my ($r, $d, $c, $i); while( $e =~ s/\( ([^()]*) \) (\d+)/#####/x ) { ($c = $2) > 0 || ($c = 1); $d = $dir . $d if( ($d = $1) =~ /^\d+/ ); $r = $d x $c; $i = index($e, "#####"); substr($e, $i, 5) = $r; } return $e; } sub RandString { my ($set, $length) = @_; my ($i, $r); $r = ''; for($i = 0; $i < $length; $i++) { $r .= substr($set, int(rand(length $set)), 1); } return $r; } sub CreateString { my ($e) = @_; my ($r, $c, $opcode, $lastsearch); $r = $lastsearch = ''; while( length($e) > 0 ) { if( $e =~ s/^(\d+)(.*)$/$2/ ) { # Skip $c = $1; if( $c > 0 ) { $r .= RandString($space . $notspace, $c - 1) . '='; } $lastsearch = undef; } elsif( $e =~ s/^\/(.)(.*)$/$2/ ) { # Search fixed $opcode = $1; unless( length($r) > 0 && substr($r, length($r) - 1) eq $opcode && $lastsearch ne "/$opcode" ) { # Current position does not match, or repeated search $r .= RandString($digit . $space, int(rand 4)) . $opcode; } $lastsearch = "/$opcode"; } elsif( $e =~ s/^(.)(.*)$/$2/ ) { $opcode = $1; if( $opcode ne '+' && $opcode ne '-' ) { # Search character class if( $opcode eq 'a' ) { if( $r !~ /[[:alpha:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($notalpha, int(rand 4)) . RandString($alpha, 1); } } elsif( $opcode eq 's' ) { if( $r !~ /[[:space:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($notspace, int(rand 4)) . RandString($space, 1); } } elsif( $opcode eq 'd' ) { if( $r !~ /[[:digit:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($notdigit, int(rand 4)) . RandString($digit, 1); } } elsif( $opcode eq 'i' ) { if( $r !~ /[[:alnum:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($notalnum, int(rand 4)) . RandString($alnum, 1); } } elsif( $opcode eq 'A' ) { if( $r !~ /[^[:alpha:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($alpha, int(rand 4)) . RandString($notalpha, 1); } } elsif( $opcode eq 'S' ) { if( $r !~ /[^[:space:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($space, int(rand 4)) . RandString($notspace, 1); } } elsif( $opcode eq 'D' ) { if( $r !~ /[^[:digit:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($digit, int(rand 4)) . RandString($notdigit, 1); } } elsif( $opcode eq 'I' ) { if( $r !~ /[^[:alnum:]]$/ || $lastsearch eq $opcode ) { $r .= RandString($alnum, int(rand 4)) . RandString($notalnum, 1); } } $lastsearch = $opcode; } } } return $r; } sub ReverseStr { return pack "C*", reverse(unpack "C*", $_[0]); } print "Creating $prefix.sh\n" unless( $ARGV[2] ); do { $l = GenExpr(0) . '/_'; $l0 = ExpandExpr($l, "+"); print "\tL = $l (", length($l), " / ", length($l0), " characters)\n" unless( $ARGV[2] ); } while( length($l0) > 1024 ); do { $r = GenExpr(0) . '/_'; $r0 = ExpandExpr($r, "-"); print "\tR = $r (", length($r), " / ", length($r0), " characters)\n" unless( $ARGV[2] ); } while( length($r0) > 1024 ); open FILE, "> $prefix.l" or die; print FILE $l, "\n"; close FILE; open FILE, "> $prefix.r" or die; print FILE $r, "\n"; close FILE; open FILE, "> $prefix.l0" or die; print FILE $l0, "\n"; close FILE; open FILE, "> $prefix.r0" or die; print FILE $r0, "\n"; close FILE; unless( $ARGV[2] ) { open FILE, "> $prefix.sh" or die; print FILE <<"EOT"; #!/bin/sh $cmd -c -l `cat $prefix.l` -r `cat $prefix.r` $prefix.in $prefix.out1 $cmd -c -l `cat $prefix.l0` -r `cat $prefix.r0` $prefix.in $prefix.out2 wc $prefix.out1 $prefix.out2 diff -s -q $prefix.out1 $prefix.out2 EOT close FILE; chmod 0755, "$prefix.sh"; } print "Creating $prefix.in\n" unless( $ARGV[2] ); open FILE, "> $prefix.in" or die; for($i = $o = 0; ($i < 3) || ($o < 1000000); $i++) { $s = CreateString($l0) . "Shiipon" . ReverseStr(CreateString($r0)) . "\n"; print FILE $s; $o += length($s); } close FILE; print "\tdata = $i lines / $o bytes\n" unless( $ARGV[2] );