mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Update the performance unit test generation example scripts.
This commit is contained in:
parent
6d3da8c39a
commit
c63d0ea21a
@ -276,6 +276,7 @@ AC_CONFIG_FILES([build/apxs-wrapper], [chmod +x build/apxs-wrapper])
|
||||
if test -e "$PERL"; then
|
||||
AC_CONFIG_FILES([t/run-tests.pl], [chmod +x t/run-tests.pl])
|
||||
AC_CONFIG_FILES([t/gen_rx-pm.pl], [chmod +x t/gen_rx-pm.pl])
|
||||
AC_CONFIG_FILES([t/csv_rx-pm.pl], [chmod +x t/csv_rx-pm.pl])
|
||||
|
||||
# Perl based tools
|
||||
AC_CONFIG_FILES([../tools/rules-updater.pl], [chmod +x ../tools/rules-updater.pl])
|
||||
|
21
apache2/t/csv_rx-pm.pl.in
Executable file
21
apache2/t/csv_rx-pm.pl.in
Executable file
@ -0,0 +1,21 @@
|
||||
#!@PERL@
|
||||
#
|
||||
# Example to generate CSV performance data from test results taken from
|
||||
# test generated by gen_rx-pm.pl.
|
||||
#
|
||||
use strict;
|
||||
|
||||
my %H = ();
|
||||
while (<>) {
|
||||
chomp;
|
||||
my ($op, $label, $n, $i, $value) = (m/\s*\d+\)\s+\S+\s+"([^"]*)"\s+(\S+)\s+(\d+) item\(s\): passed\s+\((\d+)\s+\@\s+([-\+\d\.E]+) msec\s.*/);
|
||||
|
||||
next unless defined($value);
|
||||
$H{$n}{$label} = $value;
|
||||
|
||||
}
|
||||
|
||||
printf "%s, %s, %s, %s\n", qw(N rx1 rx2 pm1);
|
||||
for (sort {$a <=> $b} keys %H) {
|
||||
printf "%s, %s, %s, %s\n", $_, $H{$_}{rx1}, $H{$_}{rx2}, $H{$_}{pm1}
|
||||
};
|
@ -4,92 +4,95 @@
|
||||
#
|
||||
use strict;
|
||||
use Regexp::Assemble;
|
||||
|
||||
|
||||
my $MIN = 1;
|
||||
my $MAX = 5000;
|
||||
my $INC = 250;
|
||||
srand(424242); # We want this static, so we can compare different runs
|
||||
|
||||
my $MIN = $ARGV[0] || 0;
|
||||
my $MAX = $ARGV[1] || 5000;
|
||||
my $INC = $ARGV[2] || int($MAX * .05);
|
||||
my $ITERATIONS = 10000;
|
||||
my $MINSTRLEN = 2;
|
||||
my $MAXSTRLEN = 8;
|
||||
|
||||
my $last = rndstr();
|
||||
my @param = ($last);
|
||||
my $match = join '', ('a' .. 'z');
|
||||
my @param = ();
|
||||
my $i=$MIN;
|
||||
while ($i <= $MAX) {
|
||||
my $ra = Regexp::Assemble->new;
|
||||
|
||||
while (@param < $i) {
|
||||
unshift @param, rndstr();
|
||||
}
|
||||
|
||||
$ra->add(@param);
|
||||
|
||||
printf (
|
||||
"# rx: %6d\n".
|
||||
"{\n".
|
||||
" comment => \"%6d item(s)\",\n".
|
||||
" comment => \"rx1 %6d item(s)\",\n".
|
||||
" type => \"op\",\n".
|
||||
" name => \"rx\",\n".
|
||||
" param => qr/^(?:%s)\$/,\n".
|
||||
" param => qr/%s/,\n".
|
||||
" input => \"%s\",\n".
|
||||
" ret => 1,\n".
|
||||
" ret => " . (@param ? 0 : 1) . ",".
|
||||
" iterations => %d,\n".
|
||||
"},\n",
|
||||
$i,
|
||||
$i,
|
||||
join('|', @param),
|
||||
$last,
|
||||
(@param ? '(?:' . join('|', @param) . ')' : ""),
|
||||
$match,
|
||||
$ITERATIONS,
|
||||
);
|
||||
|
||||
printf (
|
||||
"# rx-optimized: %6d\n".
|
||||
"{\n".
|
||||
" comment => \"%6d item(s)\",\n".
|
||||
" comment => \"rx2 %6d item(s)\",\n".
|
||||
" type => \"op\",\n".
|
||||
" name => \"rx\",\n".
|
||||
" param => qr/^(?:%s)\$/,\n".
|
||||
" param => qr/%s/,\n".
|
||||
" input => \"%s\",\n".
|
||||
" ret => 1,\n".
|
||||
" ret => " . (@param ? 0 : 1) . ",".
|
||||
" iterations => %d,\n".
|
||||
"},\n",
|
||||
$i,
|
||||
$i,
|
||||
$ra->as_string,
|
||||
$last,
|
||||
(@param ? $ra->as_string : ""),
|
||||
$match,
|
||||
$ITERATIONS,
|
||||
);
|
||||
|
||||
printf (
|
||||
"# pm: %6d\n".
|
||||
"{\n".
|
||||
" comment => \"%6d item(s)\",\n".
|
||||
" comment => \"pm1 %6d item(s)\",\n".
|
||||
" type => \"op\",\n".
|
||||
" name => \"pm\",\n".
|
||||
" param => \"%s\",\n".
|
||||
" input => \"%s\",\n".
|
||||
" ret => 1,\n".
|
||||
" ret => 0,".
|
||||
" iterations => %d,\n".
|
||||
"},\n",
|
||||
$i,
|
||||
$i,
|
||||
join(' ', @param),
|
||||
$last,
|
||||
join(' ', @param ? @param : ("''")),
|
||||
$match,
|
||||
$ITERATIONS,
|
||||
);
|
||||
|
||||
$i = ($i == 1) ? $INC : $i + $INC;
|
||||
$i = ($i == $MIN) ? ($i + $INC) - ($i % $INC) : $i + $INC;
|
||||
|
||||
while (@param < $i) {
|
||||
unshift @param, rndstr();
|
||||
}
|
||||
}
|
||||
|
||||
sub rndstr {
|
||||
my @c=('a'..'z','0'..'9','_');
|
||||
my @c = ('a' .. 'z');
|
||||
my $rndstr;
|
||||
my $max = int(rand($MAXSTRLEN - $MINSTRLEN)) + $MINSTRLEN;
|
||||
foreach (1 .. $max) {
|
||||
$rndstr .= $c[rand @c];
|
||||
}
|
||||
# We need a string that is not in another string for "last"
|
||||
if ($last =~ m/$rndstr/) {
|
||||
if ($match =~ m/$rndstr/) {
|
||||
$rndstr = rndstr();
|
||||
}
|
||||
return $rndstr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user