Skip to content

Commit

Permalink
Support valgrind and cleanup options some
Browse files Browse the repository at this point in the history
  • Loading branch information
awick committed Jun 10, 2014
1 parent 96e8a4c commit cbe7fb3
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions tests/tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ sub doTests {
my $savedData = do { local $/; <$fh> };
my $savedJson = from_json($savedData, {relaxed => 1});

my $cmd = "../capture/moloch-capture --tests -c config.test.ini -n test -r $filename.pcap 2>&1 1>/dev/null | ./tests.pl --fix";

if ($main::valgrind) {
$cmd = "G_SLICE=allows-malloc valgrind --leak-check=full --log-file=$filename.val " . $cmd;
}

if ($main::debug) {
print "../capture/moloch-capture --tests -c config.test.ini -n test -r $filename.pcap 2>&1 1>/dev/null | ./tests.pl --fix\n";
print "$cmd\n";
}

my $testData = `../capture/moloch-capture --tests -c config.test.ini -n test -r $filename.pcap 2>&1 1>/dev/null | ./tests.pl --fix`;
my $testData = `$cmd`;
my $testJson = from_json($testData, {relaxed => 1});

eq_or_diff($testJson, $savedJson, "$filename", { context => 3 });
Expand Down Expand Up @@ -178,6 +184,7 @@ sub doViewer {
$cmd = "G_SLICE=allows-malloc valgrind --leak-check=full --log-file=moloch.val " . $cmd;
}

print "$cmd\n" if ($main::debug);
system($cmd);

print ("Starting viewer\n");
Expand Down Expand Up @@ -687,32 +694,45 @@ sub doViewer {
}
################################################################################
$main::debug = 0;
if ($ARGV[0] eq "--debug") {
$main::debug = 1;
shift @ARGV;
}
if ($ARGV[0] eq "--valgrind") {
$main::valgrind = 1;
shift @ARGV;
$main::valgrind = 0;
$main::cmd = "--capture";

while (scalar (@ARGV) > 0) {
if ($ARGV[0] eq "--debug") {
$main::debug = 1;
shift @ARGV;
} elsif ($ARGV[0] eq "--valgrind") {
$main::valgrind = 1;
shift @ARGV;
} elsif ($ARGV[0] =~ /^--(viewer|fix|make|capture|viewerfast|help)$/) {
$main::cmd = $ARGV[0];
shift @ARGV;
} elsif ($ARGV[0] =~ /^-/) {
print "Unknown option $ARGV[0]\n";
$main::cmd = "--help";
last;
} else {
last;
}
}
$main::cmd = $ARGV[0];

if ($ARGV[0] eq "--fix") {
shift @ARGV;
if ($main::cmd eq "--fix") {
doFix();
} elsif ($ARGV[0] eq "--make") {
shift @ARGV;
} elsif ($main::cmd eq "--make") {
doMake();
} elsif ($ARGV[0] eq "--help") {
print "$ARGV[0] [-debug] [COMMAND] <pcap> files\n";
} elsif ($main::cmd eq "--help") {
print "$ARGV[0] [OPTIONS] [COMMAND] <pcap> files\n";
print "Options:\n";
print " --debug Turn on debuggin\n";
print " --valgrind Use valgrind on capture\n";
print "\n";
print "Commands:\n";
print " --help This help\n";
print " --make Create a .test file for each .pcap file on command line\n";
print " --viewer viewer tests\n";
print " This will init local ES, import data, start a viewer, run tests\n";
print " [default] Run each .pcap file thru ../capture/moloch-capture and compare to .test file\n";
} elsif ($ARGV[0] =~ "^--viewer") {
shift @ARGV;
} elsif ($main::cmd =~ "^--viewer") {
doGeo();
setpgrp $$, 0;
doViewer($main::cmd);
Expand Down

0 comments on commit cbe7fb3

Please sign in to comment.