lib/Rex/GPU/AMD/Setup.pm

filter: Statementstmt 90.0% 235 / 261 Branchbran 86.2% 88 / 102 Conditioncond 73.3% 55 / 75 MC/DCmcdc 52.5% 21 / 40 Subroutinesub 75.8% 47 / 62 Podpod 100% 49 / 49 totaltotal 84.0% 495 / 589 CC 90 SCAR 17.1
CC
90
Cov
86%
plan_inbox
12.0
preflight
11.1
resolve_plan
9.0
CRAP 5.5
« lib/Rex/GPU/NVIDIA/Setup/Ubuntu.pm ↑ Summary lib/Rex/GPU/NVIDIA/VGPU.pm »
1 # ABSTRACT: Base class of the AMD driver setups: preflight, install flow, signing keys, repository files (experimental)
2  
3 package Rex::GPU::AMD::Setup;
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  
10 40 has amd => ( is => 'ro', required => 1 );
11 80 ▶has gpus => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
12 40 has state => ( is => 'ro' );
13 40 has os_release => ( is => 'lazy' );
14 40 has kernel => ( is => 'lazy' );
15 40 has arch => ( is => 'lazy' );
16  
17 0 ▶sub _build_os_release { $_[0]->amd->read_os_release }
Subroutine _build_os_release: not called CC=1 SCAR=6.9
18 250 ▶sub _build_kernel { _trim($_[0]->run_cmd('uname -r')) }
Subroutine _build_kernel: called CC=1 SCAR=0.0
19 35 ▶sub _build_arch { _trim($_[0]->run_cmd('uname -m')) }
Subroutine _build_arch: called CC=1 SCAR=0.0
20  
21  
22 4466 ▶sub run_cmd {
Subroutine run_cmd: called CC=1 SCAR=0.0
Pod documented
23 4466 my ( $self, $command, %opt ) = @_;
24 4466 return $self->amd->host_run($command, %opt);
25 }
26  
27 561 ▶sub os_version { $_[0]->os_release->{VERSION_ID} // '' }
Subroutine os_version: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[0]->os_release->{"VERSION_ID"} // ""
l!l
5601
MC/DC100%1/1
$_[0]->os_release->{"VERSION_ID"} // ""
$_[0]->os_release->{"VERSION_ID"}
Truth table100%2/2
A
A= $_[0]->os_release->{"VERSION_ID"}
Aresult
11
00
28  
29 59 ▶sub os_label {
Subroutine os_label: called CC=3 SCAR=12.5
Pod documented
30 59 my ( $self ) = @_;
31 59 my $os = $self->os_release;
32 0 ▶ return $os->{PRETTY_NAME} // join(' ', grep { defined } $os->{ID}, $os->{VERSION_ID}) || 'unknown OS';
Condition50%2/4
($os->{'PRETTY_NAME'} // join(' ', grep({defined $_;} $os->{'ID'}, $os->{'VERSION_ID'}))) || 'unknown OS'
l!l
590
$os->{"PRETTY_NAME"} // join(" ", grep({defined $_;} $os->{"ID"}, $os->{"VERSION_ID"}))
l!l
590
MC/DC0%0/1
($os->{'PRETTY_NAME'} // join(' ', grep({defined $_;} $os->{'ID'}, $os->{'VERSION_ID'}))) || 'unknown OS'
$os->{"PRETTY_NAME"}
Truth table50%1/2
A
A= $os->{"PRETTY_NAME"}
Aresult
11
00
33 }
34  
35 #### The flow #################################################################
36  
37  
38 198 ▶sub install {
Subroutine install: called CC=3 SCAR=11.0
Pod documented
39 198 my ( $self, $method ) = @_;
40 198 ▶ my $plan = $method eq 'dkms' ? $self->plan_dkms : $self->plan_inbox;
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'dkms' ? : 162 36 198
41 151 ▶ return 0 unless $plan->{needed};
Branch: 1 branch
BranchTrueFalseTotal
unless $plan->{"needed"} 4 147 151
42 147 $self->prepare_host($plan);
43 147 $self->prepare_source($plan);
44 145 $self->resolve_plan($plan);
45 128 $self->install_packages($plan);
46 128 $self->verify_packages($plan);
47 74 $self->post_install($plan);
48 42 return 1;
49 }
50  
51  
52 36 ▶sub plan_inbox {
Subroutine plan_inbox: called CC=12 SCAR=24.9
Pod documented
53 36 my ( $self ) = @_;
54 36 ▶ if (my $why = $self->host_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = $self->host_unsupported) 7 29 36
55 7 die 'install_driver: '.$why.". Nothing was changed on the host\n";
56 }
57 29 $self->preflight;
58 29 $self->check_radeon;
59 24 ▶ my @only = grep { ( $_->{driver} // '' ) eq 'inbox' } @{ $self->gpus };
Condition50%1/2
$_->{"driver"} // ""
l!l
240
MC/DC0%0/1
$_->{"driver"} // ""
$_->{"driver"}
Truth table50%1/2
A
A= $_->{"driver"}
Aresult
11
00
60 24 ▶ if (@only and my $why = $self->inbox_only_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (@only and my $why = $self->inbox_only_unsupported) 2 22 24
Condition100%3/3
@only and my $why = $self->inbox_only_unsupported
!ll&&!rl&&r
1752
MC/DC100%2/2
@only and my $why = $self->inbox_only_unsupported
@only my $why = $self->inbox_only_unsupported
Truth table100%3/3
A and B
A= @onlyB= my $why = $self->inbox_only_unsupported
ABresult
0X0
100
111
61 2 die 'install_driver: '.$self->_labels(@only).': '.$why.". Nothing was changed on the host\n";
62 }
63 22 ▶ if (my $why = $self->inbox_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = $self->inbox_unsupported) 4 18 22
64 4 die 'install_driver: '.$why.". Nothing was changed on the host\n";
65 }
66 18 my $plan = { method => 'inbox', packages => [], optional => [] };
67 18 ▶ unless (defined $self->amd->module_source(kernel => $self->kernel)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->amd->module_source("kernel", $self->kernel)) 5 13 18
68 5 my @packages = $self->inbox_module_packages;
69 5 ▶ die 'install_driver: kernel '.$self->kernel.' has no amdgpu module, and no package for it '
Branch: 1 branch
BranchTrueFalseTotal
unless @packages 1 4 5
70 .'is known on '.$self->os_label.". Nothing was changed on the host\n"
71 unless @packages;
72 4 $plan->{required} = \@packages;
73 }
74 17 my @firmware = $self->firmware_packages;
75 $plan->{firmware} = \@firmware
76 17 ▶ if @firmware && !grep { $self->package_installed($_) } @firmware;
Branch: 1 branch
BranchTrueFalseTotal
if @firmware and not grep({$self->package_installed($_);} @firmware) 9 8 17
Condition66%2/3
@firmware and not grep({$self->package_installed($_);} @firmware)
!ll&&!rl&&r
089
MC/DC50%1/2
@firmware and not grep({$self->package_installed($_);} @firmware)
@firmware not grep({$self->package_installed($_);} @firmware)
Truth table66%2/3
A and not(B)
A= @firmwareB= not grep({$self->package_installed($_);} @firmware)
ABresult
0X0
100
111
77 17 ▶ $plan->{needed} = $plan->{required} || $plan->{firmware} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$plan->{'required'} || $plan->{'firmware'} ? : 13 4 17
Condition100%3/3
$plan->{"required"} or $plan->{"firmware"}
l!l&&r!l&&!r
494
MC/DC100%2/2
$plan->{"required"} or $plan->{"firmware"}
$plan->{"required"} $plan->{"firmware"}
Truth table100%3/3
A or B
A= $plan->{"required"}B= $plan->{"firmware"}
ABresult
1X1
011
000
78 17 return $plan;
79 }
80  
81 162 ▶sub plan_dkms {
Subroutine plan_dkms: called CC=8 SCAR=20.9
Pod documented
82 162 my ( $self ) = @_;
83 162 ▶ if (my $why = $self->host_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = $self->host_unsupported) 6 156 162
84 6 die 'install_driver: '.$why.". Nothing was changed on the host\n";
85 }
86 156 $self->preflight;
87 151 $self->check_radeon;
88 143 ▶ die 'install_driver: amdgpu-dkms is built for '.$self->supported_arch.' only; this host is '
Branch: 1 branch
BranchTrueFalseTotal
unless $self->arch eq $self->supported_arch 2 141 143
89 .$self->arch.". Nothing was changed on the host\n"
90 unless $self->arch eq $self->supported_arch;
91 141 ▶ if (my $why = $self->dkms_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $why = $self->dkms_unsupported) 4 137 141
92 4 die 'install_driver: '.$why.". Nothing was changed on the host\n";
93 }
94 137 ▶ die "install_driver: Secure Boot is enabled -- the amdgpu-dkms module would be signed with a "
Branch: 1 branch
BranchTrueFalseTotal
if $self->secure_boot_enabled 1 136 137
95 ."machine owner key (MOK) that has to be enrolled at the console before it loads. Disable "
96 ."Secure Boot or use the inbox driver. Nothing was changed on the host\n"
97 if $self->secure_boot_enabled;
98 136 my $repo = $self->dkms_repo;
99 136 my $current = $self->file_content($repo->{file});
100 136 ▶ if (length $current) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $current) 2 134 136
101 die 'install_driver: '.$repo->{file}.' exists with other content than amdgpu '.$self->amdgpu_release
102 .' needs; install_driver does not replace a repository it did not write. Nothing was changed '
103 ."on the host\n"
104 2 ▶ unless _trim($current) eq _trim($repo->{content});
Branch: 1 branch
BranchTrueFalseTotal
unless _trim($current) eq _trim($repo->{"content"}) 2 0 2
105 0 $repo->{present} = 1;
106 }
107 134 my @headers = $self->kernel_header_packages;
108 return {
109 134 ▶ method => 'dkms',
Branch: 1 branch
BranchTrueFalseTotal
$self->dkms_built ? : 0 134 134
110 needed => $self->dkms_built ? 0 : 1,
111 packages => [],
112 required => [ @headers, 'amdgpu-dkms' ],
113 headers => \@headers,
114 optional => [ $self->optional_packages ],
115 repo => $repo,
116 };
117 }
118  
119  
120 185 ▶sub preflight {
Subroutine preflight: called CC=11 SCAR=24.0
Pod documented
121 185 my ( $self ) = @_;
122 185 ▶ my $cmdline = $self->run_cmd('cat /proc/cmdline 2>/dev/null') // '';
Condition50%1/2
$self->run_cmd("cat /proc/cmdline 2>/dev/null") // ""
l!l
1850
MC/DC0%0/1
$self->run_cmd("cat /proc/cmdline 2>/dev/null") // ""
$self->run_cmd("cat /proc/cmdline 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("cat /proc/cmdline 2>/dev/null")
Aresult
11
00
123 185 for my $word (split ' ', $cmdline) {
124 my $blocks = $word eq 'nomodeset' || $word eq 'amdgpu.modeset=0'
125 || ( $word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/
126 737 ▶ && grep { $_ eq 'amdgpu' } split /,/, $1 );
Condition88%8/9
$word eq 'nomodeset' || $word eq 'amdgpu.modeset=0' || $word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/ && grep({$_ eq 'amdgpu';} split(/,/, $1, 0))
l!l&&r!l&&!r
21734
$word eq "nomodeset" or $word eq "amdgpu.modeset=0"
l!l&&r!l&&!r
11735
$word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/ and grep {$_ eq "amdgpu";} split(/,/, $1, 0)
!ll&&!rl&&r
73401
MC/DC75%3/4
$word eq 'nomodeset' || $word eq 'amdgpu.modeset=0' || $word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/ && grep({$_ eq 'amdgpu';} split(/,/, $1, 0))
$word eq "nomodeset" $word eq "amdgpu.modeset=0" $word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/ grep {$_ eq "amdgpu";} split(/,/, $1, 0)
Truth table80%4/5
A or B || C and D
A= $word eq "nomodeset"B= $word eq "amdgpu.modeset=0"C= $word =~ /\A(?:modprobe\.blacklist|module_blacklist)=(.*)\z/D= grep {$_ eq "amdgpu";} split(/,/, $1, 0)
ABCDresult
1XXX1
01XX1
00111
000X0
00100
127 737 ▶ die "install_driver: the kernel command line has $word, which keeps amdgpu from loading; "
Branch: 1 branch
BranchTrueFalseTotal
if $blocks 3 734 737
128 ."remove it from the boot loader configuration first. Nothing was changed on the host\n"
129 if $blocks;
130 }
131 182 ▶ my $blacklist = $self->run_cmd(q{grep -rsHE --include='*.conf' }
Condition50%1/2
$self->run_cmd("grep -rsHE --include='*.conf' '^[[:space:]]*(blacklist[[:space:]]+amdgpu|install[[:space:]]+amdgpu[[:space:]]+(/usr)?/bin/(false|true))([[:space:]]|\$)' /etc/modprobe.d /run/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d 2>/dev/null") // ""
l!l
1820
MC/DC0%0/1
$self->run_cmd("grep -rsHE --include='*.conf' '^[[:space:]]*(blacklist[[:space:]]+amdgpu|install[[:space:]]+amdgpu[[:space:]]+(/usr)?/bin/(false|true))([[:space:]]|\$)' /etc/modprobe.d /run/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d 2>/dev/null") // ""
$self->run_cmd("grep -rsHE --include='*.conf' '^[[:space:]]*(blacklist[[:space:]]+amdgpu|install[[:space:]]+amdgpu[[:space:]]+(/usr)?/bin/(false|true))([[:space:]]|\$)' /etc/modprobe.d /run/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("grep -rsHE --include='*.conf' '^[[:space:]]*(blacklist[[:space:]]+amdgpu|install[[:space:]]+amdgpu[[:space:]]+(/usr)?/bin/(false|true))([[:space:]]|\$)' /etc/modprobe.d /run/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d 2>/dev/null")
Aresult
11
00
132 .q{'^[[:space:]]*(blacklist[[:space:]]+amdgpu|install[[:space:]]+amdgpu[[:space:]]+(/usr)?/bin/(false|true))([[:space:]]|$)' }
133 .q{/etc/modprobe.d /run/modprobe.d /usr/lib/modprobe.d /lib/modprobe.d 2>/dev/null}) // '';
134 182 my @lines = grep { /\S/ } split /\r?\n/, $blacklist;
135 182 ▶ die 'install_driver: amdgpu is blacklisted ('.join('; ', @lines).'); remove that first. '
Branch: 1 branch
BranchTrueFalseTotal
if @lines 1 181 182
136 ."Nothing was changed on the host\n"
137 if @lines;
138 181 ▶ for my $gpu (grep { defined $_->{bound_driver} && $_->{bound_driver} ne 'amdgpu' } @{ $self->gpus }) {
Condition100%3/3
defined $_->{'bound_driver'} && $_->{'bound_driver'} ne 'amdgpu'
!ll&&!rl&&r
17941
MC/DC100%2/2
defined $_->{'bound_driver'} && $_->{'bound_driver'} ne 'amdgpu'
defined $_->{'bound_driver'} $_->{'bound_driver'} ne 'amdgpu'
Truth table100%3/3
A && B
A= defined $_->{'bound_driver'}B= $_->{'bound_driver'} ne 'amdgpu'
ABresult
0X0
100
111
139 die 'install_driver: '.$self->amd->gpu_label($gpu).' is bound to '.$gpu->{bound_driver}
140 1 ."; install_driver does not unbind it. Nothing was changed on the host\n";
141 }
142 180 return;
143 }
144  
145  
146 200 ▶sub check_radeon {
Subroutine check_radeon: called CC=4 SCAR=13.9
Pod documented
147 200 my ( $self ) = @_;
148 200 ▶ my @radeon = grep { ( $_->{matrix} // '' ) eq 'radeon' } @{ $self->gpus };
Condition100%2/2
$_->{"matrix"} // ""
l!l
2212
MC/DC100%1/1
$_->{"matrix"} // ""
$_->{"matrix"}
Truth table100%2/2
A
A= $_->{"matrix"}
Aresult
11
00
149 200 ▶ if (@radeon and my $why = $self->radeon_unsupported) {
Branch: 1 branch
BranchTrueFalseTotal
if (@radeon and my $why = $self->radeon_unsupported) 14 186 200
Condition100%3/3
@radeon and my $why = $self->radeon_unsupported
!ll&&!rl&&r
179714
MC/DC100%2/2
@radeon and my $why = $self->radeon_unsupported
@radeon my $why = $self->radeon_unsupported
Truth table100%3/3
A and B
A= @radeonB= my $why = $self->radeon_unsupported
ABresult
0X0
100
111
150 14 die 'install_driver: '.$self->_labels(@radeon).': '.$why.". Nothing was changed on the host\n";
151 }
152 186 return;
153 }
154  
155  
156 # k91: AMD's matrix binds ROCm as it binds the driver (k82), in the order of
157 # plan_inbox and plan_dkms: the Radeon check first, then the Ryzen APUs'.
158 65 ▶sub check_rocm_matrix {
Subroutine check_rocm_matrix: called CC=7 SCAR=19.5
Pod documented
159 65 my ( $self, $targets ) = @_;
160 65 my $hardware = $self->amd->hardware_class;
161 65 my %table;
162 65 for my $gfx (@$targets) {
163 74 ▶ my $row = $hardware->target($gfx) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $row = $hardware->target($gfx) or next 73 1 74
164 73 ▶ push @{ $table{ $row->{matrix} } }, $gfx if defined $row->{matrix};
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->{"matrix"} 71 2 73
165 }
166 65 for my $check ([ radeon => 'radeon_unsupported' ], [ ryzen => 'inbox_only_unsupported' ]) {
167 123 my ( $matrix, $unsupported ) = @$check;
168 123 ▶ my $gfx = $table{$matrix} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $gfx = $table{$matrix} or next 55 68 123
169 55 ▶ my $why = $self->$unsupported // next;
Condition100%2/2
$self->$unsupported // (next)
l!l
2332
MC/DC100%1/1
$self->$unsupported // (next)
$self->$unsupported
Truth table100%2/2
A
A= $self->$unsupported
Aresult
11
00
170 23 die "install_rocm: AMD's ROCm compatibility matrix does not list ".join(', ', @$gfx)
171 .' for this OS and kernel: '.$why.". Nothing was changed on the host\n";
172 }
173 42 return;
174 }
175  
176  
177 1 ▶sub fallback_method {
Subroutine fallback_method: called CC=3 SCAR=12.0
Pod documented
178 1 my ( $self ) = @_;
179 1 ▶ return 'inbox' if defined $self->amd->module_source(kernel => $self->kernel);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->amd->module_source("kernel", $self->kernel) 0 1 1
180 0 ▶ return 'inbox' if grep { $self->has_candidate($_) } $self->inbox_module_packages;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$self->has_candidate($_);} $self->inbox_module_packages 0 1 1
181 1 return 'dkms';
182 }
183  
184  
185 33 ▶sub prepare_host { }
Subroutine prepare_host: called CC=1 SCAR=0.0
Pod documented
186  
187 147 ▶sub prepare_source {
Subroutine prepare_source: called CC=3 SCAR=11.0
Pod documented
188 147 my ( $self, $plan ) = @_;
189 147 ▶ if (my $repo = $plan->{repo}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $repo = $plan->{"repo"}) 134 13 147
190 134 $self->install_helpers;
191 134 $self->install_key(%{ $repo->{key} });
192 132 ▶ $self->write_file($repo->{file}, $repo->{content}) unless $repo->{present};
Branch: 1 branch
BranchTrueFalseTotal
unless $repo->{"present"} 132 0 132
193 }
194 145 $self->refresh_index;
195 145 return;
196 }
197  
198 145 ▶sub resolve_plan {
Subroutine resolve_plan: called CC=9 SCAR=22.0
Pod documented
199 145 my ( $self, $plan ) = @_;
200 145 ▶ my %header = map { $_ => 1 } @{ $plan->{headers} || [] };
Condition100%2/2
$plan->{'headers'} || []
l!l
13213
MC/DC100%1/1
$plan->{'headers'} || []
$plan->{'headers'}
Truth table100%2/2
A
A= $plan->{'headers'}
Aresult
11
00
201 145 ▶ for my $package (@{ $plan->{required} || [] }) {
Condition100%2/2
$plan->{'required'} || []
l!l
1369
MC/DC100%1/1
$plan->{'required'} || []
$plan->{'required'}
Truth table100%2/2
A
A= $plan->{'required'}
Aresult
11
00
202 314 ▶ unless ($self->has_candidate($package)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_candidate($package)) 11 299 310
203 die 'install_driver: '.$package.', a header package of the running kernel '.$self->kernel
204 ." that amdgpu-dkms is built against, cannot be installed from the host's package sources "
205 ."(no candidate): they do not (or no longer) carry this kernel's headers, usually because "
206 .'they have moved on to a newer kernel the host was not upgraded to or rebooted into. '
207 .'Upgrade the kernel, reboot into it and run install_driver again. '
208 .$self->_unresolved_note($plan)."\n"
209 11 ▶ if $header{$package};
Branch: 1 branch
BranchTrueFalseTotal
if $header{$package} 3 8 11
210 8 die "install_driver: $package cannot be installed from the host's package sources (no "
211 .'candidate). '.$self->_unresolved_note($plan)."\n";
212 }
213 299 push @{ $plan->{packages} }, $package;
214 }
215 130 ▶ push @{ $plan->{packages} }, grep { $self->has_candidate($_) } @{ $plan->{optional} || [] };
Condition50%1/2
$plan->{'optional'} || []
l!l
1300
MC/DC0%0/1
$plan->{'optional'} || []
$plan->{'optional'}
Truth table50%1/2
A
A= $plan->{'optional'}
Aresult
11
00
216 130 ▶ if (my $firmware = $plan->{firmware}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $firmware = $plan->{"firmware"}) 9 121 130
217 9 my ( $package ) = grep { $self->has_candidate($_) } @$firmware;
218 9 ▶ die 'install_driver: none of the amdgpu firmware packages ('.join(', ', @$firmware)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 2 7 9
219 .") can be installed from the host's package sources. ".$self->_unresolved_note($plan)."\n"
220 unless defined $package;
221 7 push @{ $plan->{packages} }, $package;
222 }
223 128 return;
224 }
225  
226 # What resolve_plan leaves behind when it dies: prepare_source has already
227 # written the repository file and the key (dkms), but no package went in.
228 13 ▶sub _unresolved_note {
Subroutine _unresolved_note: called CC=2 SCAR=6.9
229 13 my ( $self, $plan ) = @_;
230 13 ▶ my $repo = $plan->{repo} or return 'Nothing was installed';
Branch: 1 branch
BranchTrueFalseTotal
my $repo = $plan->{"repo"} or return "Nothing was installed" 8 5 13
231 return 'No driver package was installed; the amdgpu repository '.$repo->{file}
232 8 .' and its signing key '.$repo->{key}{path}.' are in place, and a re-run accepts them';
233 }
234  
235  
236 74 ▶sub post_install {
Subroutine post_install: called CC=8 SCAR=20.9
Pod documented
237 74 my ( $self, $plan ) = @_;
238 74 my $kernel = $self->kernel;
239 74 ▶ my $source = $self->amd->module_source(kernel => $kernel) // '';
Condition100%2/2
$self->amd->module_source("kernel", $kernel) // ""
l!l
4430
MC/DC100%1/1
$self->amd->module_source("kernel", $kernel) // ""
$self->amd->module_source("kernel", $kernel)
Truth table100%2/2
A
A= $self->amd->module_source("kernel", $kernel)
Aresult
11
00
240 74 ▶ if ($plan->{method} eq 'dkms') {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{'method'} eq 'dkms') { } 68 6 74
241 68 ▶ unless ($self->dkms_built) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dkms_built) 31 37 68
242 # k95: the package manager leaves a held amdgpu-dkms as it is (apt:
243 # or aborts the whole install), so the hold goes first in the message
244 31 my $hold = $self->hold_note($plan);
245 31 ▶ die "install_driver: amdgpu-dkms is installed, but dkms reports no amdgpu module built and "
Branch: 1 branch
BranchTrueFalseTotal
length $hold ? : 19 12 31
246 ."installed for kernel $kernel; ".( length $hold ? "$hold; if the module is still missing then, " : '' )
247 ."see /var/lib/dkms/amdgpu/*/build/make.log\n";
248 }
249 37 ▶ die "install_driver: amdgpu-dkms is built for kernel $kernel, but modinfo still resolves "
Branch: 2 branches
BranchTrueFalseTotal
unless $source eq "dkms" 1 36 37
length $source ? : 1 0 1
250 ."amdgpu to ".( length $source ? "the $source module" : 'no module' )."\n"
251 unless $source eq 'dkms';
252 }
253 else {
254 die "install_driver: no amdgpu module for kernel $kernel after installing "
255 0 ▶ .join(', ', @{ $plan->{packages} })."\n"
Branch: 1 branch
BranchTrueFalseTotal
unless length $source 0 6 6
256 unless length $source;
257 }
258 42 return;
259 }
260  
261 #### Host facts and helpers ###################################################
262  
263  
264 202 ▶sub dkms_built {
Subroutine dkms_built: called CC=4 SCAR=14.5
Pod documented
265 202 my ( $self ) = @_;
266 202 my $kernel = $self->kernel;
267 202 ▶ my $out = $self->run_cmd("dkms status -m amdgpu -k $kernel 2>&1") // '';
Condition50%1/2
$self->run_cmd("dkms status -m amdgpu -k $kernel 2>&1") // ""
l!l
2020
MC/DC0%0/1
$self->run_cmd("dkms status -m amdgpu -k $kernel 2>&1") // ""
$self->run_cmd("dkms status -m amdgpu -k $kernel 2>&1")
Truth table50%1/2
A
A= $self->run_cmd("dkms status -m amdgpu -k $kernel 2>&1")
Aresult
11
00
268 202 ▶ return ( grep { /\Q$kernel\E/ && /:\s*installed\b/ } split /\r?\n/, $out ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({/\Q$kernel\E/ and /:\s*installed\b/;} split(/\r?\n/, $out, 0)) ? : 37 165 202
Condition33%1/3
/\Q$kernel\E/ && /:\s*installed\b/
!ll&&!rl&&r
0037
MC/DC0%0/2
/\Q$kernel\E/ && /:\s*installed\b/
/\Q$kernel\E/ /:\s*installed\b/
Truth table33%1/3
A && B
A= /\Q$kernel\E/B= /:\s*installed\b/
ABresult
0X0
100
111
269 }
270  
271 137 ▶sub secure_boot_enabled {
Subroutine secure_boot_enabled: called CC=3 SCAR=11.1
Pod documented
272 137 my ( $self ) = @_;
273 137 ▶ my $out = $self->run_cmd('od -An -tu1 -j4 -N1 '
Condition50%1/2
$self->run_cmd("od -An -tu1 -j4 -N1 /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c 2>/dev/null") // ""
l!l
1370
MC/DC0%0/1
$self->run_cmd("od -An -tu1 -j4 -N1 /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c 2>/dev/null") // ""
$self->run_cmd("od -An -tu1 -j4 -N1 /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("od -An -tu1 -j4 -N1 /sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c 2>/dev/null")
Aresult
11
00
274 .'/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c 2>/dev/null') // '';
275 137 ▶ return $out =~ /\A\s*1\s*\z/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$out =~ /\A\s*1\s*\z/ ? : 1 136 137
276 }
277  
278 178 ▶sub file_content {
Subroutine file_content: called CC=2 SCAR=7.2
Pod documented
279 178 my ( $self, $path ) = @_;
280 178 ▶ return $self->run_cmd("cat $path 2>/dev/null") // '';
Condition50%1/2
$self->run_cmd("cat $path 2>/dev/null") // ""
l!l
1780
MC/DC0%0/1
$self->run_cmd("cat $path 2>/dev/null") // ""
$self->run_cmd("cat $path 2>/dev/null")
Truth table50%1/2
A
A= $self->run_cmd("cat $path 2>/dev/null")
Aresult
11
00
281 }
282  
283 172 ▶sub write_file {
Subroutine write_file: called CC=2 SCAR=7.6
Pod documented
284 172 my ( $self, $path, $content ) = @_;
285 172 ( my $quoted = $content ) =~ s/'/'\\''/g;
286 172 $self->run_cmd("printf '%s' '$quoted' > $path.tmp && chmod 0644 $path.tmp && mv -f $path.tmp $path");
287 172 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 172 172
288 0 $self->run_cmd("rm -f $path.tmp");
289 0 die "Could not write $path on the host\n";
290 }
291 172 return;
292 }
293  
294 175 ▶sub install_key {
Subroutine install_key: called CC=7 SCAR=20.2
Pod documented
295 175 my ( $self, %key ) = @_;
296 175 my ( $url, $fingerprint, $path ) = @key{qw( url fingerprint path )};
297 175 my $dir = "$path.tmp.d";
298 175 ( my $parent = $path ) =~ s{/[^/]+\z}{};
299 175 $self->run_cmd("mkdir -p -m 0755 $parent && rm -rf $dir && mkdir -m 0700 $dir "
300 ."&& curl -fsSL --proto =https $url -o $dir/key.asc");
301 175 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 175 175
302 0 $self->run_cmd("rm -rf $dir");
303 0 die "Could not download the AMD signing key ($url); $path was not changed\n";
304 }
305 175 my $listing = $self->run_cmd("GNUPGHOME=$dir gpg --batch --with-colons --show-keys $dir/key.asc 2>/dev/null");
306 175 my @primary = $self->_primary_fingerprints($listing);
307 175 ▶ unless (@primary == 1 && $primary[0] eq uc $fingerprint) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@primary == 1 and $primary[0] eq uc $fingerprint) 3 172 175
Condition66%2/3
@primary == 1 and $primary[0] eq uc $fingerprint
!ll&&!rl&&r
03172
MC/DC50%1/2
@primary == 1 and $primary[0] eq uc $fingerprint
@primary == 1 $primary[0] eq uc $fingerprint
Truth table66%2/3
A and B
A= @primary == 1B= $primary[0] eq uc $fingerprint
ABresult
0X0
100
111
308 3 $self->run_cmd("rm -rf $dir");
309 3 ▶ die "The key from $url is not the AMD signing key expected (fingerprint $fingerprint; got "
Condition50%1/2
join(', ', @primary) || 'none'
l!l
30
MC/DC0%0/1
join(', ', @primary) || 'none'
join(', ', @primary)
Truth table50%1/2
A
A= join(', ', @primary)
Aresult
11
00
310 .( join(', ', @primary) || 'none' )."); $path was not changed\n";
311 }
312 172 my $ok = $self->place_key($dir, $path);
313 172 $self->run_cmd("rm -rf $dir");
314 172 ▶ die "Could not install the AMD signing key into $path\n" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 172 172
315 172 $self->run_cmd("test -s $path");
316 172 ▶ die "AMD signing key $path is missing or empty\n" if $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 0 172 172
317 172 return;
318 }
319  
320 0 ▶sub place_key { die ref($_[0])." has no place_key\n" }
Subroutine place_key: not called CC=1 SCAR=6.9
Pod documented
321  
322 # gpg --with-colons: the fpr record that follows each pub record.
323 175 ▶sub _primary_fingerprints {
Subroutine _primary_fingerprints: called CC=8 SCAR=21.1
324 175 my ( $self, $listing ) = @_;
325 175 my ( @fingerprints, $after_pub );
326 175 ▶ for my $line (split /\r?\n/, $listing // '') {
Condition50%1/2
$listing // ""
l!l
1750
MC/DC0%0/1
$listing // ""
$listing
Truth table50%1/2
A
A= $listing
Aresult
11
00
327 525 my @field = split /:/, $line;
328 525 ▶ next unless @field;
Branch: 1 branch
BranchTrueFalseTotal
unless @field 0 525 525
329 525 ▶ if ($field[0] eq 'pub') { $after_pub = 1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($field[0] eq "pub") 175 350 525
330 350 ▶ if ($field[0] eq 'fpr' && $after_pub) { push @fingerprints, uc( $field[9] // '' ); $after_pub = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($field[0] eq "fpr" and $after_pub) 175 175 350
Condition60%3/5
$field[0] eq "fpr" and $after_pub
!ll&&!rl&&r
1750175
$field[9] // ""
l!l
1750
MC/DC50%1/2
$field[0] eq "fpr" and $after_pub
$field[0] eq "fpr" $after_pub
MC/DC0%0/1
$field[9] // ""
$field[9]
Truth table66%2/3
A and B
A= $field[0] eq "fpr"B= $after_pub
ABresult
0X0
100
111
Truth table50%1/2
A
A= $field[9]
Aresult
11
00
331 }
332 175 return @fingerprints;
333 }
334  
335 #### Packaging layer (Apt, RHEL) ##############################################
336  
337  
338 36 ▶sub supported_arch { 'x86_64' }
Subroutine supported_arch: called CC=1 SCAR=0.0
Pod documented
339 32 ▶sub refresh_index { }
Subroutine refresh_index: called CC=1 SCAR=0.0
Pod documented
340 0 ▶sub has_candidate { 1 }
Subroutine has_candidate: not called CC=1 SCAR=6.9
Pod documented
341 0 ▶sub package_installed { 0 }
Subroutine package_installed: not called CC=1 SCAR=6.9
Pod documented
342 0 ▶sub package_held { 0 }
Subroutine package_held: not called CC=1 SCAR=6.9
Pod documented
343 0 ▶sub install_helpers { }
Subroutine install_helpers: not called CC=1 SCAR=0.0
Pod documented
344 0 ▶sub install_packages { die ref($_[0])." has no install_packages\n" }
Subroutine install_packages: not called CC=1 SCAR=6.9
Pod documented
345 0 ▶sub verify_packages { die ref($_[0])." has no verify_packages\n" }
Subroutine verify_packages: not called CC=1 SCAR=6.9
Pod documented
346  
347 # k108: amdgpu-dkms 31.60 Depends (noble Packages) and Requires (el9
348 # primary.xml) amdgpu-dkms-firmware, without a version; read 2026-11-26.
349 75 ▶sub dkms_dependencies { qw( amdgpu-dkms-firmware ) }
Subroutine dkms_dependencies: called CC=1 SCAR=0.0
Pod documented
350  
351 0 ▶sub blocking_holds {
Subroutine blocking_holds: not called CC=1 SCAR=6.9
Pod documented
352 0 my ( $self, $plan ) = @_;
353 0 return grep { $self->package_held($_) } $self->_hold_packages($plan);
354 }
355  
356 # k108: one wording for post_install and every verify_packages; only a dkms
357 # plan is asked (amdgpu-dkms in it), as since k95/k101.
358 89 ▶sub hold_note {
Subroutine hold_note: called CC=4 SCAR=13.9
Pod documented
359 89 my ( $self, $plan ) = @_;
360 89 ▶ return '' unless ( $plan->{method} // '' ) eq 'dkms';
Branch: 1 branch
BranchTrueFalseTotal
unless ($plan->{"method"} // "") eq "dkms" 6 83 89
Condition100%2/2
$plan->{"method"} // ""
l!l
854
MC/DC100%1/1
$plan->{"method"} // ""
$plan->{"method"}
Truth table100%2/2
A
A= $plan->{"method"}
Aresult
11
00
361 83 ▶ my @held = $self->blocking_holds($plan) or return '';
Branch: 1 branch
BranchTrueFalseTotal
my(@held) = $self->blocking_holds($plan) or return "" 48 35 83
362 48 return $self->hold_advice(@held);
363 }
364  
365 0 ▶sub hold_advice {
Subroutine hold_advice: not called CC=2 SCAR=17.9
Pod documented
366 0 my ( $self, @held ) = @_;
367 0 ▶ return $self->_and_list(@held).( @held > 1 ? ' are' : ' is' ).' on hold, and the package manager '
Branch: 1 branch
BranchTrueFalseTotal
@held > 1 ? : 0 0 0
368 .'does not change a held package. Release the hold and run install_driver again';
369 }
370  
371 # The plan's packages, then the dkms_dependencies it does not list itself.
372 75 ▶sub _hold_packages {
Subroutine _hold_packages: called CC=2 SCAR=7.0
373 75 my ( $self, $plan ) = @_;
374 75 my %seen;
375 75 ▶ return grep { !$seen{$_}++ } @{ $plan->{packages} || [] }, $self->dkms_dependencies;
Condition50%1/2
$plan->{'packages'} || []
l!l
750
MC/DC0%0/1
$plan->{'packages'} || []
$plan->{'packages'}
Truth table50%1/2
A
A= $plan->{'packages'}
Aresult
11
00
376 }
377  
378 48 ▶sub _and_list {
Subroutine _and_list: called CC=2 SCAR=6.9
379 48 my ( $self, @items ) = @_;
380 48 ▶ return @items > 1 ? join(', ', @items[0 .. $#items - 1]).' and '.$items[-1] : $items[0];
Branch: 1 branch
BranchTrueFalseTotal
@items > 1 ? : 7 41 48
381 }
382  
383 #### Per-OS data ##############################################################
384  
385  
386 211 ▶sub amdgpu_release { '31.60' }
Subroutine amdgpu_release: called CC=1 SCAR=0.0
Pod documented
387 103 ▶sub amdgpu_key_path { '/etc/apt/keyrings/rocm.gpg' }
Subroutine amdgpu_key_path: called CC=1 SCAR=0.0
Pod documented
388  
389 136 ▶sub amdgpu_key {
Subroutine amdgpu_key: called CC=1 SCAR=0.0
Pod documented
390 136 my ( $self ) = @_;
391 return {
392 136 url => 'https://repo.radeon.com/rocm/rocm.gpg.key',
393 fingerprint => 'CA8BB4727A47B4D09B4EE8969386B48A1A693C5C',
394 path => $self->amdgpu_key_path,
395 };
396 }
397  
398 0 ▶sub dkms_repo { die ref($_[0])." has no dkms_repo\n" }
Subroutine dkms_repo: not called CC=1 SCAR=6.9
Pod documented
399  
400 149 ▶sub host_unsupported { return }
Subroutine host_unsupported: called CC=1 SCAR=0.0
Pod documented
401  
402 0 ▶sub dkms_unsupported {
Subroutine dkms_unsupported: not called CC=1 SCAR=6.9
Pod documented
403 0 my ( $self ) = @_;
404 0 return 'amdgpu-dkms is not supported on '.$self->os_label;
405 }
406  
407 16 ▶sub inbox_unsupported { return }
Subroutine inbox_unsupported: called CC=1 SCAR=0.0
Pod documented
408  
409 27 ▶sub inbox_only_supported {
Subroutine inbox_only_supported: called CC=1 SCAR=0.0
Pod documented
410 27 'Ubuntu 26.04 (GA kernel 7.0) and Ubuntu 24.04 (HWE kernel 7.0), per the ROCm 10.1 compatibility matrix'
411 }
412  
413 22 ▶sub inbox_only_unsupported {
Subroutine inbox_only_unsupported: called CC=1 SCAR=0.0
Pod documented
414 22 my ( $self ) = @_;
415 22 return 'AMD supports them with the inbox driver only on '.$self->inbox_only_supported
416 .'; this host runs '.$self->os_label.' with kernel '.$self->kernel;
417 }
418  
419 19 ▶sub radeon_supported {
Subroutine radeon_supported: called CC=1 SCAR=0.0
Pod documented
420 19 'Ubuntu 26.04 (GA kernel 7.0), Ubuntu 24.04 (HWE kernel 7.0), Ubuntu 22.04 (HWE kernel 6.8), '
421 .'RHEL 10.2 (kernel 6.12.0-211) and RHEL 9.8 (kernel 5.14.0-687), per the ROCm 10.1 '
422 .'compatibility matrix'
423 }
424  
425 10 ▶sub radeon_unsupported {
Subroutine radeon_unsupported: called CC=1 SCAR=0.0
Pod documented
426 10 my ( $self ) = @_;
427 10 return 'AMD supports Radeon GPUs only on '.$self->radeon_supported
428 .'; this host runs '.$self->os_label.' with kernel '.$self->kernel;
429 }
430  
431 0 ▶sub kernel_header_packages { () }
Subroutine kernel_header_packages: not called CC=1 SCAR=6.9
Pod documented
432 67 ▶sub optional_packages { () }
Subroutine optional_packages: called CC=1 SCAR=0.0
Pod documented
433 0 ▶sub firmware_packages { () }
Subroutine firmware_packages: not called CC=1 SCAR=6.9
Pod documented
434 2 ▶sub inbox_module_packages { () }
Subroutine inbox_module_packages: called CC=1 SCAR=0.0
Pod documented
435 0 ▶sub rocm_repo_dir { return }
Subroutine rocm_repo_dir: not called CC=1 SCAR=6.9
Pod documented
436  
437 1 ▶sub install_rocm {
Subroutine install_rocm: called CC=1 SCAR=0.0
Pod documented
438 1 my ( $self ) = @_;
439 1 die 'install_rocm: supported on apt hosts only (Ubuntu 22.04, 24.04, 26.04; Debian 12, 13), not '
440 .$self->os_label.". Nothing was changed on the host\n";
441 }
442  
443 16 ▶sub _labels {
Subroutine _labels: called CC=1 SCAR=0.0
444 16 my ( $self, @gpus ) = @_;
445 16 return join ', ', map { $self->amd->gpu_label($_) } @gpus;
446 }
447  
448 289 ▶sub _trim {
Subroutine _trim: called CC=2 SCAR=7.0
449 289 my ( $text ) = @_;
450 289 ▶ $text //= '';
Condition50%1/2
$text //= ""
l!l
2890
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
Aresult
11
00
451 289 $text =~ s/\A\s+|\s+\z//g;
452 289 return $text;
453 }
454  
455 40 1;
456  
457 __END__
« lib/Rex/GPU/NVIDIA/Setup/Ubuntu.pm ↑ Summary lib/Rex/GPU/NVIDIA/VGPU.pm »