| 1 | #!/usr/bin/env perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 8 | ▶ | use autodie qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 8 | ▶ | use App::Test::Generator::BenchmarkGenerator; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 8 | ▶ | use Getopt::Long qw(GetOptions); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 8 | ▶ | use Pod::Usage; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 8 | ▶ | use YAML::XS qw(LoadFile); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | benchmark-generator - Generate Benchmark harnesses from ATG schema files | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | benchmark-generator -i schemas/my_func.yml | ||||||||||||||||||||
| 19 | benchmark-generator -i schemas/abs.yml -o benchmarks/abs.pl | ||||||||||||||||||||
| 20 | benchmark-generator -i schemas/abs.yml -r | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Reads an ATG YAML schema (the same format used by C<fuzz-harness-generator>) | ||||||||||||||||||||
| 25 | and emits a self-contained Perl benchmark script using L<Benchmark/cmpthese>. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | Each transform in the schema becomes one variant in the C<cmpthese> call. | ||||||||||||||||||||
| 28 | When no transforms are defined a single C<'default'> variant is generated. | ||||||||||||||||||||
| 29 | Representative input values are derived from each parameter's type and | ||||||||||||||||||||
| 30 | range constraints. | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 OPTIONS | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =over 4 | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =item B<--input|-i> FILE | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | The schema YAML file to read (required unless positional argument given). | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =item B<--output|-o> FILE | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Output file for the generated benchmark. Defaults to STDOUT. | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =item B<--run|-r> | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | Execute the generated benchmark with C<perl> immediately after generating it. | ||||||||||||||||||||
| 47 | Implies a temporary output file when B<--output> is not given. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =item B<--version|-V> | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | Print the L<App::Test::Generator> version and exit. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | =item B<--help|-h> | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | Show this help message and exit. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =back | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 8 | my ($infile, $outfile, $run, $help, $version); | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 8 | Getopt::Long::Configure('bundling'); | |||||||||||||||||||
| 64 | 8 | ▶ | GetOptions( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 'input|i=s' => \$infile, | ||||||||||||||||||||
| 66 | 'output|o=s' => \$outfile, | ||||||||||||||||||||
| 67 | 'run|r' => \$run, | ||||||||||||||||||||
| 68 | 'help|h' => \$help, | ||||||||||||||||||||
| 69 | 'version|V' => \$version, | ||||||||||||||||||||
| 70 | ) or pod2usage(2); | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 8 | ▶ | pod2usage(-exitval => 0, -verbose => 1) if $help; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 7 | ▶ | if($version) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 1 | print $App::Test::Generator::BenchmarkGenerator::VERSION, "\n"; | |||||||||||||||||||
| 76 | 1 | exit 0; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 6 | ▶ | $infile //= shift @ARGV; | ||||||||||||||||||
|
Condition33%1/3
$infile //= shift @ARGV
MC/DC0%0/2
$infile //= shift @ARGV
$infile
shift @ARGV
Truth table33%1/3
A //= B
A= $infileB= shift @ARGV
| |||||||||||||||||||||
| 80 | 6 | ▶ | pod2usage(-message => 'ERROR: no input schema given', -exitval => 2) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | unless defined $infile; | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 6 | my $schema = LoadFile($infile); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 5 | my $bg = App::Test::Generator::BenchmarkGenerator->new(schema => $schema); | |||||||||||||||||||
| 86 | 5 | my $source = $bg->generate(); | |||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 5 | ▶ | if($outfile) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 89 | 2 | open my $fh, '>', $outfile; | |||||||||||||||||||
| 90 | 2 | print $fh $source; | |||||||||||||||||||
| 91 | 2 | close $fh; | |||||||||||||||||||
| 92 | 2 | print "Wrote benchmark to $outfile\n"; | |||||||||||||||||||
| 93 | } elsif($run) { | ||||||||||||||||||||
| 94 | 0 | require File::Temp; | |||||||||||||||||||
| 95 | 0 | my $tmp = File::Temp->new(SUFFIX => '.pl', UNLINK => 1); | |||||||||||||||||||
| 96 | 0 | print $tmp $source; | |||||||||||||||||||
| 97 | 0 | close $tmp; | |||||||||||||||||||
| 98 | 0 | system($^X, "$tmp"); | |||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||
| 100 | 3 | print $source; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||