From 7fe0c586ab0009af5ebb1536a824b390c807936f Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Tue, 28 Jul 2020 13:50:04 +0200 Subject: [PATCH] meson: src: add check*protocol tests Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa Reviewed-by: Neal Gompa --- meson.build | 1 + scripts/check-remote-protocol.py | 71 ++++++++++++++------------------ src/Makefile.am | 61 --------------------------- src/admin/meson.build | 5 +++ src/locking/meson.build | 5 +++ src/lxc/meson.build | 5 +++ src/meson.build | 26 ++++++++++++ src/remote/meson.build | 15 +++++++ src/rpc/meson.build | 10 +++++ 9 files changed, 98 insertions(+), 101 deletions(-) diff --git a/meson.build b/meson.build index 71a465806d..ee98505b45 100644 --- a/meson.build +++ b/meson.build @@ -933,6 +933,7 @@ optional_programs = [ 'mm-ctl', 'modprobe', 'ovs-vsctl', + 'pdwtags', 'radvd', 'rmmod', 'scrub', diff --git a/scripts/check-remote-protocol.py b/scripts/check-remote-protocol.py index e28fb80cdd..0a6135376e 100644 --- a/scripts/check-remote-protocol.py +++ b/scripts/check-remote-protocol.py @@ -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/") - -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) +builddir = os.path.dirname(libpath) +libname = os.path.basename(libpath) -def which(program): - def is_exe(fpath): - return (os.path.isfile(fpath) and - os.access(fpath, os.X_OK)) +def get_subdir(dirname, subdir): + objectdir = "" + reg = re.compile(subdir) + for d in os.listdir(path=dirname): + if reg.match(d): + objectdir = d + break - 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 + if objectdir == "": + raise Exception("Failed to find '{0}' in '{1}'".format(subdir, dirname)) - return None + return os.path.join(dirname, objectdir) -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) +# 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))) -proto_o = proto_lo.replace(".lo", ".o") +proto_o = get_subdir(objectdir, r'.*{0}\.c\.o'.format(name)) -if not os.path.exists(proto_o): - raise Exception("Missing %s", proto_o) - -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") diff --git a/src/Makefile.am b/src/Makefile.am index 7289f24736..33e3250652 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,65 +20,4 @@ # 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) diff --git a/src/admin/meson.build b/src/admin/meson.build index 419a5c528a..fe72cb326c 100644 --- a/src/admin/meson.build +++ b/src/admin/meson.build @@ -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('.') diff --git a/src/locking/meson.build b/src/locking/meson.build index 5c49bc641f..a67a41298b 100644 --- a/src/locking/meson.build +++ b/src/locking/meson.build @@ -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 += { diff --git a/src/lxc/meson.build b/src/lxc/meson.build index 07ae9230b3..11526b637b 100644 --- a/src/lxc/meson.build +++ b/src/lxc/meson.build @@ -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': [ diff --git a/src/meson.build b/src/meson.build index 850a910089..50975cb55c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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 diff --git a/src/remote/meson.build b/src/remote/meson.build index ffd1fb14f3..25712c943b 100644 --- a/src/remote/meson.build +++ b/src/remote/meson.build @@ -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') diff --git a/src/rpc/meson.build b/src/rpc/meson.build index d759fa21ae..e249b9d534 100644 --- a/src/rpc/meson.build +++ b/src/rpc/meson.build @@ -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', [