]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
meson: src: add check*protocol tests
authorPavel Hrdina <phrdina@redhat.com>
Tue, 28 Jul 2020 11:50:04 +0000 (13:50 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 3 Aug 2020 07:27:05 +0000 (09:27 +0200)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
meson.build
scripts/check-remote-protocol.py
src/Makefile.am
src/admin/meson.build
src/locking/meson.build
src/lxc/meson.build
src/meson.build
src/remote/meson.build
src/rpc/meson.build

index 71a465806d0577f2bbff3e76bdfa1b60aeed63c4..ee98505b45aa1e6e31d5af15b7a83621bf04fd78 100644 (file)
@@ -933,6 +933,7 @@ optional_programs = [
   'mm-ctl',
   'modprobe',
   'ovs-vsctl',
+  'pdwtags',
   'radvd',
   'rmmod',
   'scrub',
index e28fb80cdd1cdb644d34b95e069ebc1eaa52df3f..0a6135376e6f900e485500a6ac3434d5e983bc99 100644 (file)
@@ -31,55 +31,46 @@ import re
 import subprocess
 import sys
 
-cc = sys.argv[1]
-proto_lo = sys.argv[2]
-expected = sys.argv[3]
+name = sys.argv[1]
+targetname = sys.argv[2]
+libpath = sys.argv[3]
+pdwtags = sys.argv[4]
+expected = sys.argv[5]
 
-proto_lo = proto_lo.replace("/", "/.libs/")
+builddir = os.path.dirname(libpath)
+libname = os.path.basename(libpath)
 
-ccargv = cc.split(" ")
-ccargv.append("-v")
-ccproc = subprocess.Popen(ccargv, stdout=subprocess.PIPE,
-                          stderr=subprocess.STDOUT)
-out, err = ccproc.communicate()
-out = out.decode("utf-8")
-if out.find("clang") != -1:
-    print("WARNING: skipping pdwtags test with Clang", file=sys.stderr)
-    sys.exit(0)
 
+def get_subdir(dirname, subdir):
+    objectdir = ""
+    reg = re.compile(subdir)
+    for d in os.listdir(path=dirname):
+        if reg.match(d):
+            objectdir = d
+            break
 
-def which(program):
-    def is_exe(fpath):
-        return (os.path.isfile(fpath) and
-                os.access(fpath, os.X_OK))
+    if objectdir == "":
+        raise Exception("Failed to find '{0}' in '{1}'".format(subdir, dirname))
 
-    fpath, fname = os.path.split(program)
-    if fpath:
-        if is_exe(program):
-            return program
-    else:
-        for path in os.environ["PATH"].split(os.pathsep):
-            exe_file = os.path.join(path, program)
-            if is_exe(exe_file):
-                return exe_file
+    return os.path.join(dirname, objectdir)
 
-    return None
 
+# Figure out where is the meson target private directory that contains
+# generated object files.
+# With meson version < 0.55.0 the directory pattern is:
+#
+#   `hash_string@@target_name@bin_type` for example `25a6634@@vir_net_rpc@sta`
+#
+# but this was changed in meson 0.55.0 to a new pattern:
+#
+#   `output_file_name.p` for example `libvirt_net_rpc.a.p`
+objectdir = get_subdir(
+    builddir,
+    r'(.*@{0}@.*|{1}\.p)'.format(targetname, re.escape(libname)))
 
-pdwtags = which("pdwtags")
-if pdwtags is None:
-    print("WARNING: you lack pdwtags; skipping the protocol test",
-          file=sys.stderr)
-    print("WARNING: install the dwarves package to get pdwtags",
-          file=sys.stderr)
-    sys.exit(0)
-
-proto_o = proto_lo.replace(".lo", ".o")
-
-if not os.path.exists(proto_o):
-    raise Exception("Missing %s", proto_o)
+proto_o = get_subdir(objectdir, r'.*{0}\.c\.o'.format(name))
 
-pdwtagsproc = subprocess.Popen(["pdwtags", "--verbose", proto_o],
+pdwtagsproc = subprocess.Popen([pdwtags, "--verbose", proto_o],
                                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 out, err = pdwtagsproc.communicate()
 out = out.decode("utf-8")
index 7289f247362038a1498fcf6455bda9c404f7b4e9..33e325065258fbf9a647583bc0f9f575a276836f 100644 (file)
 # here. List them against the individual XXX_la_CFLAGS targets
 # that actually use them.
 
-RPC_PROBE_FILES =
-
 include admin/Makefile.inc.am
-
-
-# Keep this list synced with RPC_PROBE_FILES
-PROTOCOL_STRUCTS = \
-       $(srcdir)/remote_protocol-structs \
-       $(srcdir)/lxc_protocol-structs \
-       $(srcdir)/qemu_protocol-structs \
-       $(srcdir)/virnetprotocol-structs \
-       $(srcdir)/virkeepaliveprotocol-structs \
-       $(srcdir)/lxc_monitor_protocol-structs \
-       $(srcdir)/lock_protocol-structs \
-       $(srcdir)/admin_protocol-structs \
-       $(NULL)
-
-if WITH_REMOTE
-check-protocol: $(PROTOCOL_STRUCTS) $(PROTOCOL_STRUCTS:structs=struct)
-
-# Ensure that we don't change the struct or member names or member ordering
-# in remote_protocol.x  The check-remote-protocol.py script post-processes
-# output to extract the bits we want.
-
-CHECK_REMOTE_PROTOCOL = $(top_srcdir)/scripts/check-remote-protocol.py
-
-# The .o file that pdwtags parses is created as a side effect of running
-# libtool; but from make's perspective we depend on the .lo file.
-$(srcdir)/remote_protocol-struct \
-       $(srcdir)/qemu_protocol-struct \
-       $(srcdir)/lxc_protocol-struct: \
-               $(srcdir)/%-struct: remote/libvirt_driver_remote_la-%.lo
-       $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(CHECK_REMOTE_PROTOCOL) \
-               "$(CC)" $< $(@)s
-$(srcdir)/virnetprotocol-struct $(srcdir)/virkeepaliveprotocol-struct: \
-               $(srcdir)/%-struct: rpc/libvirt_net_rpc_la-%.lo
-       $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(CHECK_REMOTE_PROTOCOL) \
-               "$(CC)" $< $(@)s
-if WITH_LXC
-$(srcdir)/lxc_monitor_protocol-struct: \
-               $(srcdir)/%-struct: lxc/libvirt_driver_lxc_impl_la-%.lo
-       $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(CHECK_REMOTE_PROTOCOL) \
-               "$(CC)" $< $(@)s
-endif WITH_LXC
-$(srcdir)/lock_protocol-struct: \
-               $(srcdir)/%-struct: locking/lockd_la-%.lo
-       $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(CHECK_REMOTE_PROTOCOL) \
-               "$(CC)" $< $(@)s
-$(srcdir)/admin_protocol-struct: \
-               $(srcdir)/%-struct: admin/libvirt_admin_la-%.lo
-       $(AM_V_GEN)$(RUNUTF8) $(PYTHON) $(CHECK_REMOTE_PROTOCOL) \
-               "$(CC)" $< $(@)s
-
-else !WITH_REMOTE
-# The $(PROTOCOL_STRUCTS) files must live in git, because they cannot be
-# re-generated when configured --without-remote.
-check-protocol:
-endif !WITH_REMOTE
-
-check-local: check-protocol \
-       check-admin
-.PHONY: check-protocol $(PROTOCOL_STRUCTS:structs=struct)
index 419a5c528a239b447605d995cb4593b411b8262a..fe72cb326c5bc1c0965c59ed506d0531f52baa40 100644 (file)
@@ -97,6 +97,11 @@ admin_driver_lib = static_library(
   ],
 )
 
+check_protocols += {
+  'name': 'admin_protocol',
+  'lib': admin_driver_lib,
+}
+
 virt_conf_files += files('libvirt-admin.conf')
 
 admin_inc_dir = include_directories('.')
index 5c49bc641f84a9b9fc2a6e363e7f63a8abd356eb..a67a41298b1c03a28829cf0008b48fe7e381351b 100644 (file)
@@ -90,6 +90,11 @@ if conf.has('WITH_LIBVIRTD')
     ],
   )
 
+  check_protocols += {
+    'name': 'lock_protocol',
+    'lib': lockd_lib_impl,
+  }
+
   lockdriver_dir = libdir / 'libvirt' / 'lock-driver'
 
   virt_modules += {
index 07ae9230b32e94889a4bb9fcc23fe7656ba332b7..11526b637b2ce4d383ac7821da0091cccbdbbc1e 100644 (file)
@@ -99,6 +99,11 @@ if conf.has('WITH_LXC')
     ],
   )
 
+  check_protocols += {
+    'name': 'lxc_monitor_protocol',
+    'lib': lxc_driver_impl_lib,
+  }
+
   virt_modules += {
     'name': 'virt_driver_lxc',
     'link_whole': [
index 850a910089c18d2c63bceafc63e540bb11defb91..50975cb55cc5a4dfc1042c28612e6ea9c53e55c9 100644 (file)
@@ -225,6 +225,12 @@ driver_source_files = []
 #   stateful driver source files to check
 stateful_driver_source_files = []
 
+# check_protocols:
+#   check if $name.x is in sync with $name-structs
+#   name - name of the protocol (required)
+#   lib - library that this test depends on (required)
+check_protocols = []
+
 
 # list subdirectories
 
@@ -924,3 +930,23 @@ if augparse_prog.found()
     )
   endforeach
 endif
+
+if pdwtags_prog.found() and cc.get_id() != 'clang'
+  foreach proto : check_protocols
+    lib = proto['lib']
+    test(
+      'check-@0@'.format(proto['name']),
+      python3_prog,
+      args: [
+        check_remote_protocol_prog.path(),
+        proto['name'],
+        lib.name(),
+        lib.full_path(),
+        pdwtags_prog.path(),
+        files('@0@-structs'.format(proto['name'])),
+      ],
+      env: runutf8,
+      depends: [ lib ],
+    )
+  endforeach
+endif
index ffd1fb14f33586f7fd2b91329107c397ceab9066..25712c943b75de56969ad5899864b6e9646b1d70 100644 (file)
@@ -145,6 +145,21 @@ if conf.has('WITH_REMOTE')
     ],
   )
 
+  check_protocols += {
+    'name': 'remote_protocol',
+    'lib': remote_driver_lib,
+  }
+
+  check_protocols += {
+    'name': 'qemu_protocol',
+    'lib': remote_driver_lib,
+  }
+
+  check_protocols += {
+    'name': 'lxc_protocol',
+    'lib': remote_driver_lib,
+  }
+
   libvirt_libs += remote_driver_lib
 
   if conf.has('WITH_LIBVIRTD')
index d759fa21aec6435762b0df4b046901a21820f5f3..e249b9d534b9e33f466544f93acfdae12115bc3c 100644 (file)
@@ -81,6 +81,16 @@ virt_rpc_lib = static_library(
   ],
 )
 
+check_protocols += {
+  'name': 'virnetprotocol',
+  'lib': virt_rpc_lib,
+}
+
+check_protocols += {
+  'name': 'virkeepaliveprotocol',
+  'lib': virt_rpc_lib,
+}
+
 virt_rpc_server_lib = static_library(
   'virt_net_rpc_server',
   [