| 1 | # ABSTRACT: apt/dpkg packaging layer of the AMD driver setups, and the ROCm install (experimental) | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package Rex::GPU::AMD::Setup::Apt; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 40 | our $VERSION = '0.006'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Rex::Logger (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | extends 'Rex::GPU::AMD::Setup'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | has apt_lock_timeout => ( is => 'ro', default => 120 ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 186 | ▶ | sub _build_arch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_arch: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 186 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 186 | ▶ | my $arch = $self->run_cmd('dpkg --print-architecture') // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->run_cmd("dpkg --print-architecture") // ""
MC/DC0%0/1
$self->run_cmd("dpkg --print-architecture") // ""
$self->run_cmd("dpkg --print-architecture")
Truth table50%1/2
A
A= $self->run_cmd("dpkg --print-architecture")
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 186 | $arch =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 186 | return $arch; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 109 | ▶ | sub supported_arch { 'amd64' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_arch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 297 | ▶ | sub apt_get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apt_get: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 297 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 297 | return 'apt-get -o DPkg::Lock::Timeout='.$self->apt_lock_timeout; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 155 | ▶ | sub prepare_host { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare_host: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 155 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 155 | $self->run_cmd('systemctl stop unattended-upgrades apt-daily.service apt-daily-upgrade.service 2>/dev/null || true'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 155 | return; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 154 | ▶ | sub refresh_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
refresh_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 154 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 154 | $self->run_cmd($self->apt_get.' update -q'); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 154 | return; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 271 | ▶ | sub has_candidate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_candidate: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 271 | my ( $self, $package ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 271 | ▶ | my $out = $self->run_cmd("LC_ALL=C apt-cache policy $package 2>/dev/null") // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->run_cmd("LC_ALL=C apt-cache policy $package 2>/dev/null") // ""
MC/DC0%0/1
$self->run_cmd("LC_ALL=C apt-cache policy $package 2>/dev/null") // ""
$self->run_cmd("LC_ALL=C apt-cache policy $package 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("LC_ALL=C apt-cache policy $package 2>/dev/null")
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 271 | ▶ | return $out =~ /^\s*Candidate:\s*(\S+)/m && $1 ne '(none)' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$out =~ /^\s*Candidate:\s*(\S+)/m and $1 ne "(none)"
MC/DC50%1/2
$out =~ /^\s*Candidate:\s*(\S+)/m and $1 ne "(none)"
$out =~ /^\s*Candidate:\s*(\S+)/m
$1 ne "(none)"
Truth table66%2/3
A and B
A= $out =~ /^\s*Candidate:\s*(\S+)/mB= $1 ne "(none)"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 361 | ▶ | sub package_installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_installed: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 361 | my ( $self, $package ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 361 | $self->run_cmd("dpkg -l $package 2>/dev/null | grep -q '^[hi]i'"); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 361 | ▶ | return $? == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # ${Status} is "WANT EFLAG STATUS" (hold ok installed, install reinstreq | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # half-installed, ...); a package dpkg never had prints nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 71 | ▶ | sub package_on_disk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_on_disk: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 71 | my ( $self, $package ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 71 | ▶ | my $out = $self->run_cmd(q{dpkg-query -W -f='${Status}\n' }.$package.' 2>/dev/null') // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->run_cmd(q[dpkg-query -W -f='${Status}\\n' ] . $package . ' 2>/dev/null') // ""
MC/DC0%0/1
$self->run_cmd(q[dpkg-query -W -f='${Status}\\n' ] . $package . ' 2>/dev/null') // ""
$self->run_cmd(q[dpkg-query -W -f='${Status}\\n' ] . $package . ' 2>/dev/null')
Truth table50%1/2
A
A= $self->run_cmd(q[dpkg-query -W -f='${Status}\\n' ] . $package . ' 2>/dev/null')
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 71 | ▶ | return ( grep { /\A\S+ \S+ (\S+)\s*\z/ && $1 ne 'not-installed' && $1 ne 'config-files' } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
/\A\S+ \S+ (\S+)\s*\z/ && $1 ne 'not-installed' && $1 ne 'config-files'
/\A\S+ \S+ (\S+)\s*\z/ and $1 ne "not-installed"
MC/DC66%2/3
/\A\S+ \S+ (\S+)\s*\z/ && $1 ne 'not-installed' && $1 ne 'config-files'
/\A\S+ \S+ (\S+)\s*\z/
$1 ne "not-installed"
$1 ne 'config-files'
Truth table75%3/4
A and B && C
A= /\A\S+ \S+ (\S+)\s*\z/B= $1 ne "not-installed"C= $1 ne 'config-files'
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | split /\r?\n/, $out ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # k95: WANT of "WANT EFLAG STATUS" (hold ok installed, hold ok not-installed) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub package_held { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
package_held: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my ( $self, $package ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $s = $self->_dpkg_status($package)->{$package}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $s && $s->{status} =~ /\Ahold / ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$s and $s->{"status"} =~ /\Ahold /
MC/DC0%0/2
$s and $s->{"status"} =~ /\Ahold /
$s
$s->{"status"} =~ /\Ahold /
Truth table0%0/3
A and B
A= $sB= $s->{"status"} =~ /\Ahold /
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 143 | ▶ | sub install_helpers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_helpers: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 143 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 143 | my @missing; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 143 | for my $helper ([ curl => 'curl' ], [ gpg => 'gnupg' ]) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 286 | $self->run_cmd("command -v $helper->[0] >/dev/null 2>&1"); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 286 | ▶ | push @missing, $helper->[1] if $? != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 143 | ▶ | return unless @missing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $self->refresh_index; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $self->run_cmd('DEBIAN_FRONTEND=noninteractive '.$self->apt_get.' install -y --no-upgrade ' | |||||||||||||||||||||||||||||||||||||||||
| 79 | .join(' ', @missing)); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $self->verify_packages({ packages => \@missing }); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 142 | ▶ | sub install_packages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_packages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 142 | my ( $self, $plan ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 142 | Rex::Logger::info(' Installing: '.join(', ', @{ $plan->{packages} })); | |||||||||||||||||||||||||||||||||||||||||
| 87 | $self->run_cmd('DEBIAN_FRONTEND=noninteractive '.$self->apt_get.' install -y ' | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 142 | .join(' ', @{ $plan->{packages} })); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 142 | return; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # k101: a hold in the way makes apt-get install -y abort the whole install, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # so whichever package of a dkms plan is checked first is the one missing: | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # the holds are named for any of them, in post_install's words (k95, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # hold_note). Asked only once a package is missing, and only for a dkms plan | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # (not inbox, ROCm or the helpers). | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 143 | ▶ | sub verify_packages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_packages: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 143 | my ( $self, $plan ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 143 | for my $package (@{ $plan->{packages} }) { | |||||||||||||||||||||||||||||||||||||||||
| 100 | 338 | ▶ | next if $self->package_installed($package); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 49 | my $build = 'a failed DKMS build leaves it half-configured (/var/lib/dkms/amdgpu/*/build/make.log)'; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 49 | ▶ | my $note = $package eq 'amdgpu-dkms' ? "; $build" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 49 | ▶ | if (length( my $hold = $self->hold_note($plan) )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 25 | ▶ | $note = "; $hold".( length $note ? "; if it is still not installed then, $build" : '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 49 | die "$package not installed after apt-get install -- check the apt output$note\n"; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 94 | return; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # k108: a hold is in the way only where apt would have to change the package | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # (k101: held packages changed, or a held dependency it may not install), not | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # where it is at its candidate already. The policy is asked only for the | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # plan's held packages that are installed: a not installed one is always in | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # the way, a dependency only while not installed (no version required). | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 64 | ▶ | sub blocking_holds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blocking_holds: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 64 | my ( $self, $plan ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 64 | ▶ | my %asked = map { $_ => 1 } @{ $plan->{packages} || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$plan->{'packages'} || []
MC/DC0%0/1
$plan->{'packages'} || []
$plan->{'packages'}
Truth table50%1/2
A
A= $plan->{'packages'}
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 64 | my @packages = $self->_hold_packages($plan); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 64 | my $status = $self->_dpkg_status(@packages); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 64 | ▶ | my @held = grep { $status->{$_} && $status->{$_}{status} =~ /\Ahold / } @packages; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$status->{$_} && $status->{$_}{'status'} =~ /\Ahold /
MC/DC100%2/2
$status->{$_} && $status->{$_}{'status'} =~ /\Ahold /
$status->{$_}
$status->{$_}{'status'} =~ /\Ahold /
Truth table100%3/3
A && B
A= $status->{$_}B= $status->{$_}{'status'} =~ /\Ahold /
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 64 | ▶ | my @installed = grep { $asked{$_} && _on_disk($status->{$_}) } @held; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$asked{$_} && _on_disk($status->{$_})
MC/DC100%2/2
$asked{$_} && _on_disk($status->{$_})
$asked{$_}
_on_disk($status->{$_})
Truth table100%3/3
A && B
A= $asked{$_}B= _on_disk($status->{$_})
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 64 | ▶ | my $policy = @installed ? $self->_apt_policy(@installed) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | return grep { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 64 | !_on_disk($status->{$_}) ? 1 | |||||||||||||||||||||||||||||||||||||||||
| 126 | : !$asked{$_} ? 0 | ||||||||||||||||||||||||||||||||||||||||||
| 127 | : !$policy->{$_} ? 1 # no answer: in the way, as before k108 | ||||||||||||||||||||||||||||||||||||||||||
| 128 | : $policy->{$_}{installed} ne $policy->{$_}{candidate} | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 54 | ▶ | } @held; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 41 | ▶ | sub hold_advice { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hold_advice: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 41 | my ( $self, @held ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 41 | ▶ | return $self->_and_list(@held).( @held > 1 ? ' are' : ' is' ).' on hold, and apt-get install -y ' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | .'does not change a held package (where it would have to, it aborts the install). Run apt-mark ' | ||||||||||||||||||||||||||||||||||||||||||
| 136 | .'unhold '.join(' ', @held).' and install_driver again'; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # { package => { installed => ..., candidate => ... } } from one | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # `LC_ALL=C apt-cache policy` of @packages: a block per package, "NAME:" (a | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # foreign architecture "NAME:ARCH:", whose block is skipped), then its | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # "Installed:" and "Candidate:" lines. A package without both is left out. | ||||||||||||||||||||||||||||||||||||||||||
| 143 | # Read-only. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 27 | ▶ | sub _apt_policy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apt_policy: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 27 | my ( $self, @packages ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 27 | ▶ | my $out = $self->run_cmd('LC_ALL=C apt-cache policy '.join(' ', @packages).' 2>/dev/null') // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->run_cmd('LC_ALL=C apt-cache policy ' . join(" ", @packages) . ' 2>/dev/null') // ""
MC/DC0%0/1
$self->run_cmd('LC_ALL=C apt-cache policy ' . join(" ", @packages) . ' 2>/dev/null') // ""
$self->run_cmd('LC_ALL=C apt-cache policy ' . join(" ", @packages) . ' 2>/dev/null')
Truth table50%1/2
A
A= $self->run_cmd('LC_ALL=C apt-cache policy ' . join(" ", @packages) . ' 2>/dev/null')
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 27 | my ( %policy, $package ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 27 | for my $line (split /\r?\n/, $out) { | |||||||||||||||||||||||||||||||||||||||||
| 149 | 86 | ▶ | if ($line =~ /\A([^\s:]+)(:[^\s:]+)?:\s*\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 21 | ▶ | $package = !defined $2 && !$policy{$1} ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $2 || $policy{$1}
MC/DC50%1/2
defined $2 || $policy{$1}
defined $2
$policy{$1}
Truth table66%2/3
A || B
A= defined $2B= $policy{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 21 | ▶ | $policy{$package} = {} if defined $package; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 21 | next; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 65 | ▶ | $policy{$package}{lc $1} = $2 if defined $package && $line =~ /\A\s+(Installed|Candidate):\s*(\S+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $package and $line =~ /\A\s+(Installed|Candidate):\s*(\S+)/
MC/DC100%2/2
defined $package and $line =~ /\A\s+(Installed|Candidate):\s*(\S+)/
defined $package
$line =~ /\A\s+(Installed|Candidate):\s*(\S+)/
Truth table100%3/3
A and B
A= defined $packageB= $line =~ /\A\s+(Installed|Candidate):\s*(\S+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 19 | return { map { $_ => $policy{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 157 | 27 | ▶ | grep { defined $policy{$_}{installed} && defined $policy{$_}{candidate} } keys %policy }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $policy{$_}{'installed'} && defined $policy{$_}{'candidate'}
MC/DC0%0/2
defined $policy{$_}{'installed'} && defined $policy{$_}{'candidate'}
defined $policy{$_}{'installed'}
defined $policy{$_}{'candidate'}
Truth table33%1/3
A && B
A= defined $policy{$_}{'installed'}B= defined $policy{$_}{'candidate'}
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub dkms_suite { return } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dkms_suite: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 103 | ▶ | sub dkms_repo { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dkms_repo: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 103 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 103 | my $key = $self->amdgpu_key; | |||||||||||||||||||||||||||||||||||||||||
| 166 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | file => '/etc/apt/sources.list.d/amdgpu.list', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 103 | ▶ | content => 'deb [arch=amd64 signed-by='.$key->{path}.'] https://repo.radeon.com/amdgpu/' | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->dkms_suite // "unknown"
MC/DC0%0/1
$self->dkms_suite // "unknown"
$self->dkms_suite
Truth table50%1/2
A
A= $self->dkms_suite
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | .$self->amdgpu_release.'/ubuntu '.( $self->dkms_suite // 'unknown' )." main\n", | ||||||||||||||||||||||||||||||||||||||||||
| 170 | key => $key, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 141 | ▶ | sub place_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_key: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 141 | my ( $self, $dir, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 141 | $self->run_cmd("GNUPGHOME=$dir gpg --batch --yes --dearmor -o $dir/key.gpg $dir/key.asc " | |||||||||||||||||||||||||||||||||||||||||
| 178 | ."&& test -s $dir/key.gpg && chmod 0644 $dir/key.gpg && mv -f $dir/key.gpg $path"); | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 141 | ▶ | return $? == 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 79 | ▶ | sub install_rocm { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
install_rocm: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 79 | my ( $self, $rocm, $targets ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 79 | my $release = $rocm->{release}; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 79 | ▶ | my $dir = $self->rocm_repo_dir | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | or die "install_rocm: AMD has no ROCm $release repository for ".$self->os_label | ||||||||||||||||||||||||||||||||||||||||||
| 188 | .". Nothing was changed on the host\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 78 | ▶ | die "install_rocm: ROCm $release is built for amd64 only; this host is ".$self->arch | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | .". Nothing was changed on the host\n" | ||||||||||||||||||||||||||||||||||||||||||
| 191 | unless $self->arch eq 'amd64'; | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 77 | my @packages = map { $rocm->{package_prefix}.$_ } @$targets; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 77 | my $status = $self->_dpkg_status('rocm-core', @packages); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 77 | my $old = $status->{'rocm-core'}; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 77 | ▶ | if (_on_disk($old)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | ▶ | die "install_rocm: ROCm ".( $old->{version} // 'of unknown version' )." (rocm-core) is " | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$old->{"version"} // "of unknown version"
MC/DC0%0/1
$old->{"version"} // "of unknown version"
$old->{"version"}
Truth table50%1/2
A
A= $old->{"version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | ."$old->{state}; AMD requires removing ROCm 7.2.4 or older before installing ROCm $release, " | ||||||||||||||||||||||||||||||||||||||||||
| 198 | ."and install_rocm does not uninstall. Nothing was changed on the host\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 69 | ▶ | my $at_release = sub { my ( $s ) = @_; _installed($s) && index($s->{version}, "$release.") == 0 }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 69 | ▶ | unless (grep { !$at_release->($status->{$_}) } @packages) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | Rex::Logger::info("ROCm $release already installed: ".join(', ', @packages)); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | return 'present'; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # k91: after present (an install at the release is never refused), before | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # any change. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 65 | $self->check_rocm_matrix($targets); | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | my $key = { url => $rocm->{key_url}, fingerprint => $rocm->{key_fingerprint}, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 42 | path => '/etc/apt/keyrings/amdrocm.gpg' }; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 42 | my $file = '/etc/apt/sources.list.d/amdrocm-stable.sources'; | |||||||||||||||||||||||||||||||||||||||||
| 212 | my $content = join "\n", | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 'X-Repo-Id: amdrocm-stable', | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 'Types: deb', | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 'URIs: '.$rocm->{repo_url}.$dir.'/', | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 'Suites: stable', | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 'Components: main', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 'Architectures: amd64', | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 'Signed-By: '.$key->{path}, | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 42 | 'Enabled: yes', ''; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 42 | my $current = $self->file_content($file); | |||||||||||||||||||||||||||||||||||||||||
| 222 | 42 | ▶ | die "install_rocm: $file exists with other content than ROCm $release needs; install_rocm " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $current and _trim($current) ne _trim($content)
MC/DC50%1/2
length $current and _trim($current) ne _trim($content)
length $current
_trim($current) ne _trim($content)
Truth table66%2/3
A and B
A= length $currentB= _trim($current) ne _trim($content)
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | ."does not replace a repository it did not write. Nothing was changed on the host\n" | ||||||||||||||||||||||||||||||||||||||||||
| 224 | if length $current && _trim($current) ne _trim($content); | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 41 | $self->prepare_host; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 41 | $self->install_helpers; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 41 | $self->install_key(%$key); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 40 | ▶ | $self->write_file($file, $content) unless length $current; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 40 | $self->refresh_index; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 40 | ▶ | my $plan = { packages => [ @{ $rocm->{extra_packages} || [] }, @packages ] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$rocm->{'extra_packages'} || []
MC/DC0%0/1
$rocm->{'extra_packages'} || []
$rocm->{'extra_packages'}
Truth table50%1/2
A
A= $rocm->{'extra_packages'}
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 40 | $self->install_packages($plan); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 40 | $self->verify_packages($plan); | |||||||||||||||||||||||||||||||||||||||||
| 234 | 36 | $status = $self->_dpkg_status(@packages); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 36 | for my $package (@packages) { | |||||||||||||||||||||||||||||||||||||||||
| 236 | die "install_rocm: $package is installed at ".( $status->{$package}{version} // 'no version' ) | ||||||||||||||||||||||||||||||||||||||||||
| 237 | .", not ROCm $release\n" | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 39 | ▶ | unless $at_release->($status->{$package}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$status->{$package}{"version"} // "no version"
MC/DC0%0/1
$status->{$package}{"version"} // "no version"
$status->{$package}{"version"}
Truth table50%1/2
A
A= $status->{$package}{"version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 35 | Rex::Logger::info("ROCm $release installed for ".join(', ', @$targets)); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 35 | return 'installed'; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # { package => { status => 'WANT EFLAG STATE', state => STATE, version => ... } } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # for every one of @packages dpkg has a record of, in any state (k89: the | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # rocm-core check and the present check count them differently); version is | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # undef for not-installed. Read-only. | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 177 | ▶ | sub _dpkg_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dpkg_status: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 177 | my ( $self, @packages ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 177 | ▶ | my $out = $self->run_cmd(q{dpkg-query -W -f='${Package} ${Status} ${Version}\n' } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->run_cmd(q[dpkg-query -W -f='${Package} ${Status} ${Version}\\n' ] . join(" ", @packages) . ' 2>/dev/null') // ""
MC/DC0%0/1
$self->run_cmd(q[dpkg-query -W -f='${Package} ${Status} ${Version}\\n' ] . join(" ", @packages) . ' 2>/dev/null') // ""
$self->run_cmd(q[dpkg-query -W -f='${Package} ${Status} ${Version}\\n' ] . join(" ", @packages) . ' 2>/dev/null')
Truth table50%1/2
A
A= $self->run_cmd(q[dpkg-query -W -f='${Package} ${Status} ${Version}\\n' ] . join(" ", @packages) . ' 2>/dev/null')
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | .join(' ', @packages).' 2>/dev/null') // ''; | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 177 | my %status; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 177 | for my $line (split /\r?\n/, $out) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 152 | ▶ | next unless $line =~ /\A(\S+) (\S+ \S+ (\S+))(?: (\S+))?\s*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | # one line per architecture dpkg has a record for: a record on disk is | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # never replaced by one that is not | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 152 | ▶ | next if _on_disk($status{$1}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 152 | $status{$1} = { status => $2, state => $3, version => $4 }; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 177 | return \%status; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | # On disk in any state but not-installed and config-files, as package_on_disk | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # counts (k89). | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 320 | ▶ | sub _on_disk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_disk: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 320 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 320 | ▶ | return $s && $s->{state} ne 'not-installed' && $s->{state} ne 'config-files' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$s and $s->{"state"} ne "not-installed" and $s->{"state"} ne "config-files"
$s and $s->{"state"} ne "not-installed"
MC/DC100%3/3
$s and $s->{"state"} ne "not-installed" and $s->{"state"} ne "config-files"
$s
$s->{"state"} ne "not-installed"
$s->{"state"} ne "config-files"
Truth table100%4/4
A and B and C
A= $sB= $s->{"state"} ne "not-installed"C= $s->{"state"} ne "config-files"
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # Installed and configured, held or not (k89). | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 118 | ▶ | sub _installed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_installed: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 118 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 118 | ▶ | return $s && $s->{status} =~ /\A(?:install|hold) ok installed\z/ ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$s and $s->{"status"} =~ /\A(?:install|hold) ok installed\z/
MC/DC100%2/2
$s and $s->{"status"} =~ /\A(?:install|hold) ok installed\z/
$s
$s->{"status"} =~ /\A(?:install|hold) ok installed\z/
Truth table100%3/3
A and B
A= $sB= $s->{"status"} =~ /\A(?:install|hold) ok installed\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | ▶ | sub _trim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | my ( $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | ▶ | $text //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$text //= ""
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | $text =~ s/\A\s+|\s+\z//g; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | __END__ | ||||||||||||||||||||||||||||||||||||||||||