From 59cafec0a43809d540a8202b769a8de428287d5e Mon Sep 17 00:00:00 2001
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 27 Jul 2020 11:43:11 +0200
Subject: [PATCH] meson: tests: add test scripts

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
---
 tests/Makefile.am         | 34 ----------------------------------
 tests/meson.build         | 37 +++++++++++++++++++++++++++++++++++++
 tests/virt-aa-helper-test |  4 ++--
 3 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index e691919c99..24ae515a39 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -16,38 +16,6 @@
 ## License along with this library.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-test_scripts =
-libvirtd_test_scripts = \
-	libvirtd-fail \
-	libvirtd-pool \
-	virsh-auth \
-	virsh-cpuset \
-	virsh-define-dev-segfault \
-	virsh-int-overflow \
-	virsh-optparse \
-	virsh-read-bufsiz \
-	virsh-read-non-seekable \
-	virsh-schedinfo \
-	virsh-self-test \
-	virt-admin-self-test \
-	virsh-checkpoint \
-	virsh-snapshot \
-	virsh-start \
-	virsh-undefine \
-	virsh-uriprecedence \
-	virsh-vcpupin \
-	$(NULL)
-
-if WITH_LIBVIRTD
-test_scripts += $(libvirtd_test_scripts)
-endif WITH_LIBVIRTD
-
-if WITH_SECDRIVER_APPARMOR
-if WITH_LIBVIRTD
-test_scripts += virt-aa-helper-test
-endif WITH_LIBVIRTD
-endif WITH_SECDRIVER_APPARMOR
-
 if WITH_LINUX
 check-access: file-access-clean
 	VIR_TEST_FILE_ACCESS=1 $(MAKE) $(AM_MAKEFLAGS) check
@@ -59,8 +27,6 @@ file-access-clean:
 	> test_file_access.txt
 endif WITH_LINUX
 
-TESTS = $(test_scripts)
-
 VALGRIND = valgrind --quiet --leak-check=full --trace-children=yes \
 	--trace-children-skip="*/tools/virsh","*/tests/commandhelper","/usr/bin/*" \
 	--suppressions=$(abs_srcdir)/.valgrind.supp
diff --git a/tests/meson.build b/tests/meson.build
index cd59730d21..03ec061ac8 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -641,3 +641,40 @@ foreach data : helpers
     export_dynamic: true,
   )
 endforeach
+
+
+# test_scripts:
+#   list of test scripts to run
+test_scripts = []
+
+if conf.has('WITH_LIBVIRTD')
+  test_scripts += [
+    'libvirtd-fail',
+    'libvirtd-pool',
+    'virsh-auth',
+    'virsh-checkpoint',
+    'virsh-cpuset',
+    'virsh-define-dev-segfault',
+    'virsh-int-overflow',
+    'virsh-optparse',
+    'virsh-read-bufsiz',
+    'virsh-read-non-seekable',
+    'virsh-schedinfo',
+    'virsh-self-test',
+    'virsh-snapshot',
+    'virsh-start',
+    'virsh-undefine',
+    'virsh-uriprecedence',
+    'virsh-vcpupin',
+    'virt-admin-self-test',
+  ]
+
+  if conf.has('WITH_SECDRIVER_APPARMOR')
+    test_scripts += 'virt-aa-helper-test'
+  endif
+endif
+
+foreach name : test_scripts
+  script = find_program(name)
+  test(name, script, env: tests_env)
+endforeach
diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test
index 8dbe82a6b9..83f53acef6 100755
--- a/tests/virt-aa-helper-test
+++ b/tests/virt-aa-helper-test
@@ -15,13 +15,13 @@ fi
 
 output="/dev/null"
 use_valgrind=""
-ld_library_path="../src/"
+ld_library_path="$abs_top_builddir/src/"
 if [ ! -z "$1" ] && [ "$1" = "-d" ]; then
     output="/dev/stdout"
     shift
 fi
 
-exe="../src/virt-aa-helper"
+exe="$abs_top_builddir/src/virt-aa-helper"
 if [ ! -z "$1" ]; then
     if [ "$1" = "-v" ]; then
         use_valgrind="yes"