]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
meson: src/util/virfile: rewrite virFileActivateDirOverrideForProg
authorPavel Hrdina <phrdina@redhat.com>
Fri, 10 Jul 2020 10:07:16 +0000 (12:07 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 3 Aug 2020 07:26:36 +0000 (09:26 +0200)
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>
src/util/virfile.c
tests/virsh-optparse
tests/virsh-schedinfo

index af150421e726f4b287874cd7cf30289b48aad34e..c6f4a18a7a8827775a03eb793543192a0d1b28fd 100644 (file)
@@ -1782,21 +1782,22 @@ virFileFindResource(const char *filename,
  * virFileActivateDirOverrideForProg:
  * @argv0: argv[0] of the calling program
  *
- * Look at @argv0 and try to detect if running from
- * a build directory, by looking for a 'lt-' prefix
- * on the binary name, or '/.libs/' in the path
+ * Canonicalize current process path from argv0 and check if abs_top_builddir
+ * matches as prefix in the path.
  */
 void
 virFileActivateDirOverrideForProg(const char *argv0)
 {
-    char *file = strrchr(argv0, '/');
-    if (!file || file[1] == '\0')
+    g_autofree char *path = virFileCanonicalizePath(argv0);
+
+    if (!path) {
+        VIR_DEBUG("Failed to get canonicalized path errno=%d", errno);
         return;
-    file++;
-    if (STRPREFIX(file, "lt-") ||
-        strstr(argv0, "/.libs/")) {
+    }
+
+    if (STRPREFIX(path, abs_top_builddir)) {
         useDirOverride = true;
-        VIR_DEBUG("Activating build dir override for %s", argv0);
+        VIR_DEBUG("Activating build dir override for %s", path);
     }
 }
 
index d9c8f3c731b3ef93b47a2877fab7b34b8270a098..fed71a8509ef5f824a0c77b10d65f863f0200190 100755 (executable)
 
 test_expensive
 
-# If $abs_top_builddir/tools is not early in $PATH, put it there,
-# 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
+VIRSH=$abs_top_builddir/tools/virsh
 
 if test "$VERBOSE" = yes; then
   set -x
-  virsh --version
+  $VIRSH --version
 fi
 
 cat <<\EOF > exp-out || framework_failure
@@ -63,7 +57,7 @@ for args in \
     '--count 2 test' \
     '--count=2 test' \
 ; 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
 done
 
@@ -81,7 +75,7 @@ cat <<\EOF > exp-out || framework_failure
 </domainsnapshot>
 
 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 vdb --memspec file=d,,e >out 2>>err || fail=1
 compare exp-out out || fail=1
@@ -96,7 +90,7 @@ cat <<\EOF > exp-out || framework_failure
 </domainsnapshot>
 
 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
 compare exp-out out || fail=1
 
@@ -120,7 +114,7 @@ for args in \
     '--description desc --name name --domain test vda vdb' \
     '--description desc --diskspec vda --name name --domain test vdb' \
 ; 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
   compare exp-out out || fail=1
 done
@@ -131,7 +125,7 @@ test -s err && fail=1
 cat <<\EOF > exp-err || framework_failure
 error: this function is not supported by the connection driver: virDomainQemuMonitorCommand
 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
 compare exp-err err || fail=1
 
@@ -141,7 +135,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value 'abc' for <start> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -149,7 +143,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '42WB' for <start> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -158,7 +152,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '42MB' for <start> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -166,7 +160,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '2147483648' for <start> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -175,7 +169,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Invalid value for start CPU
 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
 compare exp-err err || fail=1
 
@@ -185,7 +179,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Scaled numeric value 'abc' for <size> option is malformed or out of range
 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
 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: invalid argument: unknown suffix 'WB'
 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
 compare exp-err err || fail=1
 
 # 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 err && fail=1
 
 # Numeric value bigger than INT_MAX. No failure here because
 # 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 err && fail=1
 
@@ -213,7 +207,7 @@ test -s err && fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Scaled numeric value '-1' for <size> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -223,12 +217,12 @@ cat <<\EOF > exp-err || framework_failure
 error: Unable to change MaxMemorySize
 error: memory in virDomainSetMaxMemory must not be zero
 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
 compare exp-err err || fail=1
 
 # 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 err && fail=1
 
@@ -238,7 +232,7 @@ test -s err && fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value 'abc' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -247,7 +241,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '2147484' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -255,7 +249,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '42WB' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -264,7 +258,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '42MB' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -272,7 +266,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '-1' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -281,7 +275,7 @@ compare exp-err err || fail=1
 cat <<\EOF > exp-err || framework_failure
 error: Numeric value '0' for <timeout> option is malformed or out of range
 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
 compare exp-err err || fail=1
 
@@ -291,7 +285,7 @@ cat <<\EOF > exp-out || framework_failure
 event loop timed out
 events received: 0
 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
 compare exp-out out || fail=1
 
index d6d9ac2d59ed32f18ad55b73a007b1ed3e3984f9..e4e2509f76280f00e24a6cbe770cc3b222346324 100755 (executable)
 
 . "$(dirname $0)/test-lib.sh"
 
-# If $abs_top_builddir/tools is not early in $PATH, put it there,
-# 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
+VIRSH=$abs_top_builddir/tools/virsh
 
 if test "$VERBOSE" = yes; then
   set -x
-  virsh --version
+  $VIRSH --version
 fi
 
 printf 'Scheduler      : fair\n\n' > exp-out || framework_failure
@@ -39,7 +33,7 @@ fail=0
 
 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-err err || fail=1