1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

meson: src/util/virfile: rewrite virFileActivateDirOverrideForProg

With meson we no longer have .libs directory with the actual binary so
we have to take a different approach to detect if running from build
directory.

This is not as robust as for autotools because if you select --prefix
in the build directory it will incorrectly enable the override as well
but nobody should do that.

We have to modify some of the tests to not add current build path into
PATH variable and use the full path for virsh instead. Otherwise it
would be impossible to figure out that we are running virsh from build
directory.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
This commit is contained in:
Pavel Hrdina 2020-07-10 12:07:16 +02:00
parent 71f95ea1a4
commit 2298b42878
3 changed files with 39 additions and 50 deletions

View File

@ -1782,21 +1782,22 @@ virFileFindResource(const char *filename,
* virFileActivateDirOverrideForProg: * virFileActivateDirOverrideForProg:
* @argv0: argv[0] of the calling program * @argv0: argv[0] of the calling program
* *
* Look at @argv0 and try to detect if running from * Canonicalize current process path from argv0 and check if abs_top_builddir
* a build directory, by looking for a 'lt-' prefix * matches as prefix in the path.
* on the binary name, or '/.libs/' in the path
*/ */
void void
virFileActivateDirOverrideForProg(const char *argv0) virFileActivateDirOverrideForProg(const char *argv0)
{ {
char *file = strrchr(argv0, '/'); g_autofree char *path = virFileCanonicalizePath(argv0);
if (!file || file[1] == '\0')
if (!path) {
VIR_DEBUG("Failed to get canonicalized path errno=%d", errno);
return; return;
file++; }
if (STRPREFIX(file, "lt-") ||
strstr(argv0, "/.libs/")) { if (STRPREFIX(path, abs_top_builddir)) {
useDirOverride = true; useDirOverride = true;
VIR_DEBUG("Activating build dir override for %s", argv0); VIR_DEBUG("Activating build dir override for %s", path);
} }
} }

View File

@ -21,17 +21,11 @@
test_expensive test_expensive
# If $abs_top_builddir/tools is not early in $PATH, put it there, VIRSH=$abs_top_builddir/tools/virsh
# so that we can safely invoke "virsh" simply with its name.
case $PATH in
$abs_top_builddir/tools/src:$abs_top_builddir/tools:*) ;;
$abs_top_builddir/tools:*) ;;
*) PATH=$abs_top_builddir/tools:$PATH; export PATH ;;
esac
if test "$VERBOSE" = yes; then if test "$VERBOSE" = yes; then
set -x set -x
virsh --version $VIRSH --version
fi fi
cat <<\EOF > exp-out || framework_failure cat <<\EOF > exp-out || framework_failure
@ -63,7 +57,7 @@ for args in \
'--count 2 test' \ '--count 2 test' \
'--count=2 test' \ '--count=2 test' \
; do ; do
virsh -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=1 $VIRSH -k0 -d0 -c $test_url setvcpus $args >out 2>>err || fail=1
LC_ALL=C sort out | compare exp-out - || fail=1 LC_ALL=C sort out | compare exp-out - || fail=1
done done
@ -81,7 +75,7 @@ cat <<\EOF > exp-out || framework_failure
</domainsnapshot> </domainsnapshot>
EOF EOF
virsh -q -c $test_url snapshot-create-as --print-xml test \ $VIRSH -q -c $test_url snapshot-create-as --print-xml test \
--diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \ --diskspec 'vda,file=a&b,,c,snapshot=external' --description '1<2' \
--diskspec vdb --memspec file=d,,e >out 2>>err || fail=1 --diskspec vdb --memspec file=d,,e >out 2>>err || fail=1
compare exp-out out || fail=1 compare exp-out out || fail=1
@ -96,7 +90,7 @@ cat <<\EOF > exp-out || framework_failure
</domainsnapshot> </domainsnapshot>
EOF EOF
virsh -q -c $test_url snapshot-create-as --print-xml test name vda vdb \ $VIRSH -q -c $test_url snapshot-create-as --print-xml test name vda vdb \
>out 2>>err || fail=1 >out 2>>err || fail=1
compare exp-out out || fail=1 compare exp-out out || fail=1
@ -120,7 +114,7 @@ for args in \
'--description desc --name name --domain test vda vdb' \ '--description desc --name name --domain test vda vdb' \
'--description desc --diskspec vda --name name --domain test vdb' \ '--description desc --diskspec vda --name name --domain test vdb' \
; do ; do
virsh -q -c $test_url snapshot-create-as --print-xml $args \ $VIRSH -q -c $test_url snapshot-create-as --print-xml $args \
>out 2>>err || fail=1 >out 2>>err || fail=1
compare exp-out out || fail=1 compare exp-out out || fail=1
done done
@ -131,7 +125,7 @@ test -s err && fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: this function is not supported by the connection driver: virDomainQemuMonitorCommand error: this function is not supported by the connection driver: virDomainQemuMonitorCommand
EOF EOF
virsh -q -c $test_url qemu-monitor-command test a >out 2>err && fail=1 $VIRSH -q -c $test_url qemu-monitor-command test a >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -141,7 +135,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value 'abc' for <start> option is malformed or out of range error: Numeric value 'abc' for <start> option is malformed or out of range
EOF EOF
virsh -q -c $test_url cpu-stats test --start abc >out 2>err && fail=1 $VIRSH -q -c $test_url cpu-stats test --start abc >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -149,7 +143,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '42WB' for <start> option is malformed or out of range error: Numeric value '42WB' for <start> option is malformed or out of range
EOF EOF
virsh -q -c $test_url cpu-stats test --start 42WB >out 2>err && fail=1 $VIRSH -q -c $test_url cpu-stats test --start 42WB >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -158,7 +152,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '42MB' for <start> option is malformed or out of range error: Numeric value '42MB' for <start> option is malformed or out of range
EOF EOF
virsh -q -c $test_url cpu-stats test --start 42MB >out 2>err && fail=1 $VIRSH -q -c $test_url cpu-stats test --start 42MB >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -166,7 +160,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '2147483648' for <start> option is malformed or out of range error: Numeric value '2147483648' for <start> option is malformed or out of range
EOF EOF
virsh -q -c $test_url cpu-stats test --start 2147483648 >out 2>err && fail=1 $VIRSH -q -c $test_url cpu-stats test --start 2147483648 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -175,7 +169,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Invalid value for start CPU error: Invalid value for start CPU
EOF EOF
virsh -q -c $test_url cpu-stats test --start -1 >out 2>err && fail=1 $VIRSH -q -c $test_url cpu-stats test --start -1 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -185,7 +179,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Scaled numeric value 'abc' for <size> option is malformed or out of range error: Scaled numeric value 'abc' for <size> option is malformed or out of range
EOF EOF
virsh -q -c $test_url setmaxmem test abc >out 2>err && fail=1 $VIRSH -q -c $test_url setmaxmem test abc >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -194,18 +188,18 @@ cat <<\EOF > exp-err || framework_failure
error: Scaled numeric value '42WB' for <size> option is malformed or out of range error: Scaled numeric value '42WB' for <size> option is malformed or out of range
error: invalid argument: unknown suffix 'WB' error: invalid argument: unknown suffix 'WB'
EOF EOF
virsh -q -c $test_url setmaxmem test 42WB >out 2>err && fail=1 $VIRSH -q -c $test_url setmaxmem test 42WB >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
# Numeric value with valid suffix # Numeric value with valid suffix
virsh -q -c $test_url setmaxmem test 42MB --config >out 2>err || fail=1 $VIRSH -q -c $test_url setmaxmem test 42MB --config >out 2>err || fail=1
test -s out && fail=1 test -s out && fail=1
test -s err && fail=1 test -s err && fail=1
# Numeric value bigger than INT_MAX. No failure here because # Numeric value bigger than INT_MAX. No failure here because
# scaled numeric values are unsigned long long # scaled numeric values are unsigned long long
virsh -q -c $test_url setmaxmem test 2147483648 --config >out 2>err || fail=1 $VIRSH -q -c $test_url setmaxmem test 2147483648 --config >out 2>err || fail=1
test -s out && fail=1 test -s out && fail=1
test -s err && fail=1 test -s err && fail=1
@ -213,7 +207,7 @@ test -s err && fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Scaled numeric value '-1' for <size> option is malformed or out of range error: Scaled numeric value '-1' for <size> option is malformed or out of range
EOF EOF
virsh -q -c $test_url setmaxmem test -1 >out 2>err && fail=1 $VIRSH -q -c $test_url setmaxmem test -1 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -223,12 +217,12 @@ cat <<\EOF > exp-err || framework_failure
error: Unable to change MaxMemorySize error: Unable to change MaxMemorySize
error: memory in virDomainSetMaxMemory must not be zero error: memory in virDomainSetMaxMemory must not be zero
EOF EOF
virsh -q -c $test_url setmaxmem test 0 >out 2>err && fail=1 $VIRSH -q -c $test_url setmaxmem test 0 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
# Numeric value # Numeric value
virsh -q -c $test_url setmaxmem test 42 --config >out 2>err || fail=1 $VIRSH -q -c $test_url setmaxmem test 42 --config >out 2>err || fail=1
test -s out && fail=1 test -s out && fail=1
test -s err && fail=1 test -s err && fail=1
@ -238,7 +232,7 @@ test -s err && fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value 'abc' for <timeout> option is malformed or out of range error: Numeric value 'abc' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout abc >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout abc >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -247,7 +241,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '2147484' for <timeout> option is malformed or out of range error: Numeric value '2147484' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout 2147484 >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout 2147484 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -255,7 +249,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '42WB' for <timeout> option is malformed or out of range error: Numeric value '42WB' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout 42WB >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout 42WB >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -264,7 +258,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '42MB' for <timeout> option is malformed or out of range error: Numeric value '42MB' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout 42MB >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout 42MB >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -272,7 +266,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '-1' for <timeout> option is malformed or out of range error: Numeric value '-1' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout -1 >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout -1 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -281,7 +275,7 @@ compare exp-err err || fail=1
cat <<\EOF > exp-err || framework_failure cat <<\EOF > exp-err || framework_failure
error: Numeric value '0' for <timeout> option is malformed or out of range error: Numeric value '0' for <timeout> option is malformed or out of range
EOF EOF
virsh -q -c $test_url event --all --timeout 0 >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout 0 >out 2>err && fail=1
test -s out && fail=1 test -s out && fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1
@ -291,7 +285,7 @@ cat <<\EOF > exp-out || framework_failure
event loop timed out event loop timed out
events received: 0 events received: 0
EOF EOF
virsh -q -c $test_url event --all --timeout 1 >out 2>err && fail=1 $VIRSH -q -c $test_url event --all --timeout 1 >out 2>err && fail=1
test -s err && fail=1 test -s err && fail=1
compare exp-out out || fail=1 compare exp-out out || fail=1

View File

@ -19,17 +19,11 @@
. "$(dirname $0)/test-lib.sh" . "$(dirname $0)/test-lib.sh"
# If $abs_top_builddir/tools is not early in $PATH, put it there, VIRSH=$abs_top_builddir/tools/virsh
# so that we can safely invoke "virsh" simply with its name.
case $PATH in
$abs_top_builddir/tools/src:$abs_top_builddir/tools:*) ;;
$abs_top_builddir/tools:*) ;;
*) PATH=$abs_top_builddir/tools:$PATH; export PATH ;;
esac
if test "$VERBOSE" = yes; then if test "$VERBOSE" = yes; then
set -x set -x
virsh --version $VIRSH --version
fi fi
printf 'Scheduler : fair\n\n' > exp-out || framework_failure printf 'Scheduler : fair\n\n' > exp-out || framework_failure
@ -39,7 +33,7 @@ fail=0
test_url=test:///default test_url=test:///default
virsh -c $test_url schedinfo 1 --set j=k >out 2>err && fail=1 $VIRSH -c $test_url schedinfo 1 --set j=k >out 2>err && fail=1
compare exp-out out || fail=1 compare exp-out out || fail=1
compare exp-err err || fail=1 compare exp-err err || fail=1