bin/benchmark-generator

filter: Statementstmt 88.6% 39 / 44 Branchbran 75.0% 9 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 82.3% 56 / 68 CC 1 SCAR 0.0
CC
1
Cov
83%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« /usr/local/bin/prove ↑ Summary bin/deploy-workflows »
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
BranchTrueFalseTotal
&GetOptions("input|i=s", \$infile, "output|o=s", \$outfile, "run|r", \$run, "help|h", \$help, "version|V", \$version) or pod2usage(2) 8 0 8
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
BranchTrueFalseTotal
if $help 1 7 8
73  
74 7 ▶if($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 1 6 7
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
l!l&&r!l&&!r
600
MC/DC0%0/2
$infile //= shift @ARGV
$infile shift @ARGV
Truth table33%1/3
A //= B
A= $infileB= shift @ARGV
ABresult
1X1
011
000
80 6 ▶pod2usage(-message => 'ERROR: no input schema given', -exitval => 2)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $infile 0 6 6
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
BranchTrueFalseTotal
if ($outfile) { } 2 3 5
elsif ($run) { } 0 3 3
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 }
« /usr/local/bin/prove ↑ Summary bin/deploy-workflows »