| 1 | package Tapper::Cmd::Init; | ||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Tapper - Backend functions for initially setting up Tapper | ||||||||||||||||||||||||||||
| 4 | 1 | $Tapper::Cmd::Init::VERSION = '5.0.14'; | |||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Tapper::Cmd::DbDeploy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Tapper::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Tapper::Model 'model'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::ShareDir 'module_file', 'module_dir'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Copy::Recursive 'dircopy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use File::Slurp 'slurp'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | extends 'Tapper::Cmd'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub mint_file { | ||||||||||||||||||||||||||
|
Subroutine
mint_file: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($init_dir, $basename, $force) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $HOME = $ENV{HOME}; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $USER = $ENV{USER} || 'nobody'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{'USER'} || 'nobody'
MC/DC0%0/1
$ENV{'USER'} || 'nobody'
$ENV{'USER'}
Truth table0%0/2
A
A= $ENV{'USER'}
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $file = "$init_dir/$basename"; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if (-e $file and !$force) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $file and not $force
MC/DC0%0/2
-e $file and not $force
-e $file
not $force
Truth table0%0/3
A and not(B)
A= -e $fileB= not $force
| |||||||||||||||||||||||||||||
| 30 | 0 | say "SKIP $file - already exists"; | |||||||||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||||||||
| 32 | # set write permissions when $force is set | ||||||||||||||||||||||||||||
| 33 | 0 | my $content; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (-e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $content = slurp $file; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | open my $INITCFG, "<", $file or die "Can not read file $file.\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | my $perm = (stat $INITCFG)[2] & 07777; | |||||||||||||||||||||||||||
| 39 | 0 | chmod ($perm|0600, $INITCFG); | |||||||||||||||||||||||||||
| 40 | 0 | close $INITCFG; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | print "UPDATED "; | |||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||
| 44 | 0 | $content = slurp module_file('Tapper::Cmd::Init', $basename); | |||||||||||||||||||||||||||
| 45 | 0 | print "CREATED "; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | $content =~ s/__HOME__/$HOME/g; | |||||||||||||||||||||||||||
| 49 | 0 | $content =~ s/__USER__/$USER/g; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # actually patch file | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | open my $INITCFG, ">", $file or die "Can not create file $file.\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | print $INITCFG $content; | |||||||||||||||||||||||||||
| 54 | 0 | close $INITCFG; | |||||||||||||||||||||||||||
| 55 | 0 | say $file; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub copy_subdir { | ||||||||||||||||||||||||||
|
Subroutine
copy_subdir: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my ($init_dir, $dirname) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my $dir = "$init_dir/$dirname"; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (-d $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | say "SKIP $dir/ - already exists"; | |||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||
| 67 | 0 | dircopy(module_dir('Tapper::Cmd::Init')."/$dirname", $dir); | |||||||||||||||||||||||||||
| 68 | 0 | say "CREATED $dir/"; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub make_subdir { | ||||||||||||||||||||||||||
|
Subroutine
make_subdir: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($dir) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (-d $dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | say "SKIP $dir/ - already exists"; | |||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | mkdir $dir or die "Can not create $dir\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | say "CREATED $dir/"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub dbdeploy | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
dbdeploy: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | Tapper::Config::_switch_context; # reload config | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $dsn = Tapper::Config->subconfig->{database}{TestrunDB}{dsn}; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | my ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn($dsn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | or die "Can't parse DBI DSN '$dsn'"; | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($driver eq "SQLite") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | my ($dbname) = $driver_dsn =~ /dbname=(.*)/; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (! -e $dbname) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | my $cmd = Tapper::Cmd::DbDeploy->new; | |||||||||||||||||||||||||||
| 95 | 0 | $cmd->dbdeploy('TestrunDB'); | |||||||||||||||||||||||||||
| 96 | 0 | $cmd->insert_initial_values('TestrunDB', ); | |||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 0 | say "SKIP $dbname - already exists"; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||
| 101 | 0 | my $cmd = Tapper::Cmd::DbDeploy->new; | |||||||||||||||||||||||||||
| 102 | 0 | $cmd->dbdeploy('TestrunDB'); | |||||||||||||||||||||||||||
| 103 | 0 | $cmd->insert_initial_values('TestrunDB', ); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub benchmarkdeploy | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
benchmarkdeploy: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 0 | Tapper::Config::_switch_context; # reload config | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $HOME = $ENV{HOME}; | |||||||||||||||||||||||||||
| 113 | 0 | my $dsn = Tapper::Config->subconfig->{benchmarkanything}{storage}{backend}{sql}{dsn}; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | my ($scheme, $driver, $attr_string, $attr_hash, $driver_dsn) = DBI->parse_dsn($dsn) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | or die "Can't parse DBI DSN '$dsn'"; | ||||||||||||||||||||||||||||
| 116 | 0 | $ENV{BENCHMARKANYTHING_CONFIGFILE} = "$HOME/.tapper/tapper.cfg"; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | system ("benchmarkanything-storage createdb") and die "Could not initialize BenchmarkAnything subsystem"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub init | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | my ($self, $options) = @_; | |||||||||||||||||||||||||||
| 124 | 0 | my $db = $options->{db}; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $HOME = $ENV{HOME}; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | die "No home directory found.\n" unless $HOME && -d $HOME; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$HOME and -d $HOME
MC/DC0%0/2
$HOME and -d $HOME
$HOME
-d $HOME
Truth table0%0/3
A and B
A= $HOMEB= -d $HOME
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | make_subdir my $init_dir = "$HOME/.tapper"; | |||||||||||||||||||||||||||
| 130 | 0 | make_subdir my $run_dir = "$HOME/.tapper/run"; | |||||||||||||||||||||||||||
| 131 | 0 | make_subdir my $log_dir = "$HOME/.tapper/logs"; | |||||||||||||||||||||||||||
| 132 | 0 | make_subdir my $out_dir = "$HOME/.tapper/output"; | |||||||||||||||||||||||||||
| 133 | 0 | make_subdir my $repo_dir = "$HOME/.tapper/repository"; | |||||||||||||||||||||||||||
| 134 | 0 | make_subdir my $img_dir = "$HOME/.tapper/repository/images"; | |||||||||||||||||||||||||||
| 135 | 0 | make_subdir my $pkg_dir = "$HOME/.tapper/repository/packages"; | |||||||||||||||||||||||||||
| 136 | 0 | make_subdir my $prg_dir = "$HOME/.tapper/testprogram"; | |||||||||||||||||||||||||||
| 137 | 0 | make_subdir my $producer_dir = "$HOME/.tapper/producers"; | |||||||||||||||||||||||||||
| 138 | 0 | make_subdir my $precond_dir = "$HOME/.tapper/macropreconditions"; | |||||||||||||||||||||||||||
| 139 | 0 | make_subdir my $localdata_dir = "$HOME/.tapper/localdata"; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | copy_subdir ($init_dir, "hello-world"); | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | mint_file ($init_dir, "tapper.cfg"); | |||||||||||||||||||||||||||
| 144 | 0 | mint_file ($init_dir, "log4perl.cfg"); | |||||||||||||||||||||||||||
| 145 | 0 | mint_file ($init_dir, "log4perl_webgui.cfg"); | |||||||||||||||||||||||||||
| 146 | 0 | mint_file ($init_dir, "tapper-mcp-messagereceiver.conf"); | |||||||||||||||||||||||||||
| 147 | 0 | mint_file ($init_dir, "testprogram/tapper-selftest.sh"); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # Allow more fine-grained updates for testplans and macropreconditions, | ||||||||||||||||||||||||||||
| 150 | # as we expect the user to have his own stuff in there. | ||||||||||||||||||||||||||||
| 151 | 0 | mint_file ($init_dir, $_) foreach qw(macropreconditions/tapper-selftest.mpc); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | make_subdir my $tplan_dir = "$HOME/.tapper/testplans"; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | make_subdir "$tplan_dir/$_" foreach qw(topic | |||||||||||||||||||||||||||
| 156 | topic/xen | ||||||||||||||||||||||||||||
| 157 | topic/xen/generic | ||||||||||||||||||||||||||||
| 158 | topic/any | ||||||||||||||||||||||||||||
| 159 | topic/any/generic | ||||||||||||||||||||||||||||
| 160 | topic/kernel | ||||||||||||||||||||||||||||
| 161 | topic/kernel/generic | ||||||||||||||||||||||||||||
| 162 | topic/helloworld | ||||||||||||||||||||||||||||
| 163 | topic/tapper | ||||||||||||||||||||||||||||
| 164 | include | ||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||
| 166 | 0 | mint_file ($init_dir, $_) foreach qw(testplans/topic/xen/generic/upload-xen-dmesg.sh | |||||||||||||||||||||||||||
| 167 | testplans/topic/xen/generic/test | ||||||||||||||||||||||||||||
| 168 | testplans/topic/xen/generic/guest-template.svm | ||||||||||||||||||||||||||||
| 169 | testplans/topic/xen/generic/guest-start-template.sh | ||||||||||||||||||||||||||||
| 170 | testplans/topic/any/generic/local | ||||||||||||||||||||||||||||
| 171 | testplans/topic/kernel/generic/test | ||||||||||||||||||||||||||||
| 172 | testplans/topic/helloworld/example01 | ||||||||||||||||||||||||||||
| 173 | testplans/topic/helloworld/example02 | ||||||||||||||||||||||||||||
| 174 | testplans/topic/helloworld/example03-builder | ||||||||||||||||||||||||||||
| 175 | testplans/topic/tapper/tapper-selftest | ||||||||||||||||||||||||||||
| 176 | testplans/include/distrodetails | ||||||||||||||||||||||||||||
| 177 | testplans/include/defaults | ||||||||||||||||||||||||||||
| 178 | testplans/include/defaultbenchmarks | ||||||||||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # force __HOME__ replacement for BenchmarkAnything config file | ||||||||||||||||||||||||||||
| 182 | 0 | mint_file ($init_dir, $_, 1) foreach qw(hello-world/00-set-environment/local-tapper-env.inc); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | dbdeploy; | |||||||||||||||||||||||||||
| 185 | 0 | benchmarkdeploy; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1 | 1; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||||||||||