From fce1548ed866c9e39ed8e29bec19c9eac6c903d4 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Wed, 15 Jan 2020 17:09:24 +0000 Subject: [PATCH] tests/capture-libs: Tolerate path to ld.so not being fully resolved --resolve-ld.so would ideally be the equivalent of realpath or readlink -f, but in fact it only has special handling for symlinks in the last position in the pathname (like AT_SYMLINK_NOFOLLOW and O_NOFOLLOW), leading to different results on at least Arch Linux. The pressure-vessel utility for which this option was added does not actually use it any more, so fixing this is not a high priority right now. Signed-off-by: Simon McVittie <smcv@collabora.com> --- tests/capture-libs.pl | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/tests/capture-libs.pl b/tests/capture-libs.pl index ac4c84cb0..facc65048 100755 --- a/tests/capture-libs.pl +++ b/tests/capture-libs.pl @@ -297,14 +297,52 @@ SKIP: { diag "ld.so is $ld_so"; run_ok([$CAPSULE_CAPTURE_LIBS_TOOL, '--resolve-ld.so=/'], '>', \$stdout); + my $resolved = $stdout; + chomp $resolved; + + is(abs_path($resolved), abs_path($ld_so), + '--resolve-ld.so=/ should print a path to '.abs_path($ld_so)); + ok(! -l $resolved, + '--resolve-ld.so=/ should not print a symlink'); + + # Autotools considers an unexpected pass to be a test failure, so we + # have to second-guess whether this is going to work. + if ($stdout eq abs_path($ld_so)."\n") { + is($stdout, abs_path($ld_so)."\n", + '--resolve-ld.so=/ should print '.abs_path($ld_so)); + } + else { + TODO: { + local $TODO = 'symlinks before the last component are not resolved, ' + .'e.g. /lib64 -> usr/lib on Arch Linux'; + is($stdout, abs_path($ld_so)."\n", + '--resolve-ld.so=/ should print '.abs_path($ld_so)); + } + } - is($stdout, abs_path($ld_so)."\n", - '--resolve-ld.so=/ should print '.abs_path($ld_so)); run_ok([qw(bwrap --ro-bind / / --ro-bind /), $host, $CAPSULE_CAPTURE_LIBS_TOOL, "--resolve-ld.so=$host"], '>', \$stdout); - is($stdout, abs_path($ld_so)."\n", - "--resolve-ld.so=$host should print ".abs_path($ld_so)); + $resolved = $stdout; + chomp $resolved; + + is(abs_path($resolved), abs_path($ld_so), + "--resolve-ld.so=$host should print a path to ".abs_path($ld_so)); + ok(! -l $resolved, + "--resolve-ld.so=$host should not print a symlink"); + + if ($stdout eq abs_path($ld_so)."\n") { + is($stdout, abs_path($ld_so)."\n", + "--resolve-ld.so=$host should print ".abs_path($ld_so)); + } + else { + TODO: { + local $TODO = 'symlinks before the last component are not resolved, ' + .'e.g. /lib64 -> usr/lib on Arch Linux'; + is($stdout, abs_path($ld_so)."\n", + "--resolve-ld.so=$host should print ".abs_path($ld_so)); + } + } }; SKIP: { -- GitLab