#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use Pod::Usage;

my $cryptalg = 3;
my $format = 0;
my $cache = 2;
my $verbose = 0;

GetOptions("verbose" => \$verbose,
	   "cryptalg=i" => \$cryptalg,
	   "format=i" => \$format,
	   "cache=i" => \$cache,
	   "help|?" => sub {pod2usage(1)})
    or pod2usage(1);

if (@ARGV) {
    pod2usage(1);
}
sub run {
    my $command = shift();
    if ($verbose) {print("$command\n");}
    system($command);
}

run("rm -f *.out >/dev/null 2>&1");

run("../pkt_dump -b$cache -e$cryptalg -z$format -V vkey -T tkey -o c.out"
       ." -s s.out -t t.out -c clear.out test.in"
       .($verbose ? "" : " >/dev/null"));
if (-f "gmon.out") {
    run("mv gmon.out pkt_dump.gmon");
}

run("../../decrypt/decrypt -o decrypt.out -c c.out -s s.out -t t.out"
       ." -V vkey -T tkey"
       .($verbose ? "" : " >/dev/null"));
if (-f "gmon.out") {
    run("mv gmon.out decrypt.gmon");
}

run("cmp clear.out decrypt.out");

=head1 NAME

runtests - test pkt_dump and decrypt

=head1 SYNOPSIS

runtests [options]

 Options:
   --verbose
   --cryptalg
   --format
   --cache        0=linked list, 1=btree, 2=hash
   --help

=cut
