| File: | bin/benchmark-generator |
| Coverage: | 84.8% |
| line | stmt | bran | cond | sub | time | code |
|---|---|---|---|---|---|---|
| 1 | #!/usr/bin/env perl | |||||
| 2 | ||||||
| 3 | 8 8 8 | 17170 8 134 | use strict; | |||
| 4 | 8 8 8 | 10 8 158 | use warnings; | |||
| 5 | 8 8 8 | 1462 65970 14 | use autodie qw(:all); | |||
| 6 | ||||||
| 7 | 8 8 8 | 77269 9 134 | use App::Test::Generator::BenchmarkGenerator; | |||
| 8 | 8 8 8 | 2848 35373 16 | use Getopt::Long qw(GetOptions); | |||
| 9 | 8 8 8 | 2575 200625 539 | use Pod::Usage; | |||
| 10 | 8 8 8 | 1503 10043 1215 | use YAML::XS qw(LoadFile); | |||
| 11 | ||||||
| 12 - 59 | =head1 NAME benchmark-generator - Generate Benchmark harnesses from ATG schema files =head1 SYNOPSIS benchmark-generator -i schemas/my_func.yml benchmark-generator -i schemas/abs.yml -o benchmarks/abs.pl benchmark-generator -i schemas/abs.yml -r =head1 DESCRIPTION Reads an ATG YAML schema (the same format used by C<fuzz-harness-generator>) and emits a self-contained Perl benchmark script using L<Benchmark/cmpthese>. Each transform in the schema becomes one variant in the C<cmpthese> call. When no transforms are defined a single C<'default'> variant is generated. Representative input values are derived from each parameter's type and range constraints. =head1 OPTIONS =over 4 =item B<--input|-i> FILE The schema YAML file to read (required unless positional argument given). =item B<--output|-o> FILE Output file for the generated benchmark. Defaults to STDOUT. =item B<--run|-r> Execute the generated benchmark with C<perl> immediately after generating it. Implies a temporary output file when B<--output> is not given. =item B<--version|-V> Print the L<App::Test::Generator> version and exit. =item B<--help|-h> Show this help message and exit. =back =cut | |||||
| 60 | ||||||
| 61 | 8 | 543594 | my ($infile, $outfile, $run, $help, $version); | |||
| 62 | ||||||
| 63 | 8 | 38 | Getopt::Long::Configure('bundling'); | |||
| 64 | 8 | 199 | GetOptions( | |||
| 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 | 3460 | pod2usage(-exitval => 0, -verbose => 1) if $help; | |||
| 73 | ||||||
| 74 | 7 | 21 | if($version) { | |||
| 75 | 1 | 10 | print $App::Test::Generator::BenchmarkGenerator::VERSION, "\n"; | |||
| 76 | 1 | 0 | exit 0; | |||
| 77 | } | |||||
| 78 | ||||||
| 79 | 6 | 23 | $infile //= shift @ARGV; | |||
| 80 | 6 | 23 | pod2usage(-message => 'ERROR: no input schema given', -exitval => 2) | |||
| 81 | unless defined $infile; | |||||
| 82 | ||||||
| 83 | 6 | 19 | my $schema = LoadFile($infile); | |||
| 84 | ||||||
| 85 | 5 | 691 | my $bg = App::Test::Generator::BenchmarkGenerator->new(schema => $schema); | |||
| 86 | 5 | 16 | my $source = $bg->generate(); | |||
| 87 | ||||||
| 88 | 5 | 8 | if($outfile) { | |||
| 89 | 2 | 8 | open my $fh, '>', $outfile; | |||
| 90 | 2 | 1649 | print $fh $source; | |||
| 91 | 2 | 5 | close $fh; | |||
| 92 | 2 | 0 | print "Wrote benchmark to $outfile\n"; | |||
| 93 | } elsif($run) { | |||||
| 94 | 0 | 0 | require File::Temp; | |||
| 95 | 0 | 0 | my $tmp = File::Temp->new(SUFFIX => '.pl', UNLINK => 1); | |||
| 96 | 0 | 0 | print $tmp $source; | |||
| 97 | 0 | 0 | close $tmp; | |||
| 98 | 0 | 0 | system($^X, "$tmp"); | |||
| 99 | } else { | |||||
| 100 | 3 | 0 | print $source; | |||
| 101 | } | |||||