From 7a2499fbfb519477148d40c5dbb52be9fcf390e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 4 Sep 2026 12:15:45 -0300 Subject: [PATCH] test(xCAT-test): cover the resolver libraries the netboot image takes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build a root filesystem for each architecture and run genimage's selection over it, so the riscv64 libraries are taken from their own directory and the other architectures keep the files they take today. Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- .../unit/ubuntu_genimage_resolver_libs.t | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 xCAT-test/unit/ubuntu_genimage_resolver_libs.t diff --git a/xCAT-test/unit/ubuntu_genimage_resolver_libs.t b/xCAT-test/unit/ubuntu_genimage_resolver_libs.t new file mode 100644 index 000000000..d14460fa1 --- /dev/null +++ b/xCAT-test/unit/ubuntu_genimage_resolver_libs.t @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use File::Path qw(make_path); +use File::Spec; +use File::Temp qw(tempdir); +use FindBin; +use Test::More; + +# A netboot image resolves names with the libnss libraries of its own architecture, and +# Ubuntu keeps them in a per-architecture directory. Build a root filesystem for each +# architecture and run genimage's selection over it. + +my $repo_root = File::Spec->rel2abs(File::Spec->catdir($FindBin::Bin, '..', '..')); +my $genimage = File::Spec->catfile( + $repo_root, 'xCAT-server', 'share', 'xcat', 'netboot', 'ubuntu', 'genimage'); +plan skip_all => "genimage not found at $genimage" unless -f $genimage; + +my $src = do { local $/; open my $fh, '<', $genimage or die $!; <$fh> }; +my ($selection) = + $src =~ /^(\s*if \(\$arch =~ \/x86_64\/\) \{.*?\n\s*\} else \{.*?\n\s*\}\n)/ms; +ok(defined $selection, 'found the resolver library selection in genimage') + or do { done_testing(); exit }; + +sub selected { + my ($arch, @present) = @_; + my $rootimg_dir = tempdir(CLEANUP => 1); + foreach my $file (@present) { + my $full = "$rootimg_dir/$file"; + ($full =~ m{^(.*)/[^/]+$}) and make_path($1); + open(my $fh, '>', $full) or die $!; + close($fh); + } + my @filestoadd; + eval "$selection 1" or die $@; ## no critic (BuiltinFunctions::ProhibitStringyEval) + return join(',', sort @filestoadd); +} + +is( + selected('riscv64', 'lib/riscv64-linux-gnu/libnss_files.so.2', + 'lib/riscv64-linux-gnu/libnss_dns.so.2'), + 'lib/riscv64-linux-gnu/libnss_dns.so.2,lib/riscv64-linux-gnu/libnss_files.so.2', + 'a riscv64 image takes the riscv64 resolver libraries', +); +is( + selected('riscv64', 'lib/libnss_dns.so.2'), + '', + 'riscv64 does not fall back to the path that holds no riscv64 library', +); +is( + selected('x86_64', 'lib/x86_64-linux-gnu/libnss_dns.so.2'), + 'lib/x86_64-linux-gnu/libnss_dns.so.2', + 'x86_64 selection is unchanged', +); +is( + selected('ppc64el', 'lib/powerpc64le-linux-gnu/libnss_files.so.2'), + 'lib/powerpc64le-linux-gnu/libnss_files.so.2', + 'ppc64el selection is unchanged', +); +is( + selected('s390x', 'lib/libnss_dns.so.2'), + 'lib/libnss_dns.so.2', + 'an architecture with no branch keeps the generic library', +); + +done_testing();