Preliminary patches for subproject split
v3 cover Preliminary patches for subproject split
From: Marc-André Lureau <[email protected]>
Hi,
Here is another subset of the large "subproject(qga)" series I intend to send soon after (https://gitlab.com/marcandre.lureau/qemu/-/commits/qga).
Thanks
v3:
- use overriable qmp_dispatch_exec() stub, instead of extra callback
- qapi-gen "-i file.h" will always generate '#include "file.h"' now
- improve mtest2make.py subproject tests handling
- add r-b tags
v2:
- drop error_init() callbacks, use static library symbol override instead
- include a few patches from the rest of the series to introduce qemu-common subproject
Marc-André Lureau (16):
error-report: misc comment fix
error-report: introduce "detailed" variable
error-report: simplify print_loc()
error-report: introduce overridable error_is_detailed()
stubs: remove needless error_vprintf_unless_qmp()
qapi: move QEMU-specific dispatch code in monitor
qapi: remove QEMU-specific monitor dependency from dispatch scripts/qapi-gen: add -i option
scripts/qapi: add required system includes to visitor
util: move 256-by-128 division helpers to int128
qemu-common: introduce a common subproject
qemu-common: move scripts/qapi
qemu-common: move glib-compat.h
qemu-common: move error-report
mtest2make.py: teach suite name that are just "PROJECT"
qemu-common: add error-report test
docs/conf.py | 2 +-
meson.build | 28 +--
include/qapi/qmp/dispatch.h | 6 +-
include/qemu/host-utils.h | 3 -
include/qemu/int128.h | 3 +
.../qemu-common/include}/glib-compat.h | 4 +-
.../qemu-common/include}/qemu/error-report.h | 4 +
.../qemu-common/include}/qemu/help-texts.h | 0
monitor/qmp.c | 64 +++++++
qapi/qmp-dispatch.c | 62 +-----
softmmu/vl.c | 5 +
stubs/qmp-dispatch-exec.c | 8 +
.../qemu-common/src/error-is-detailed.c | 6 +
.../qemu-common/src}/error-report.c | 20 +-
.../qemu-common/src/error-vprintf.c | 10 +-
.../qemu-common/tests/test-error-report.c | 120 ++++++++++++
util/host-utils.c | 180 ------------------
util/int128.c | 180 ++++++++++++++++++
MAINTAINERS | 4 +-
scripts/mtest2make.py | 9 +-
stubs/meson.build | 2 +-
subprojects/libvduse/meson.build | 2 +
subprojects/libvduse/subprojects/qemu-common | 1 +
subprojects/libvhost-user/meson.build | 2 +
.../libvhost-user/subprojects/qemu-common | 1 +
subprojects/qemu-common/meson.build | 26 +++
subprojects/qemu-common/scripts/meson.build | 3 +
.../qemu-common/scripts}/qapi-gen.py | 0
.../qemu-common/scripts}/qapi/.flake8 | 0
.../qemu-common/scripts}/qapi/.isort.cfg | 0
.../qemu-common/scripts}/qapi/__init__.py | 0
.../qemu-common/scripts}/qapi/commands.py | 15 +-
.../qemu-common/scripts}/qapi/common.py | 0
.../qemu-common/scripts}/qapi/error.py | 0
.../qemu-common/scripts}/qapi/events.py | 17 +-
.../qemu-common/scripts}/qapi/expr.py | 0
.../qemu-common/scripts}/qapi/gen.py | 15 ++
.../qemu-common/scripts}/qapi/introspect.py | 11 +-
.../qemu-common/scripts}/qapi/main.py | 17 +-
.../qemu-common/scripts/qapi/meson.build | 16 ++
.../qemu-common/scripts}/qapi/mypy.ini | 0
.../qemu-common/scripts}/qapi/parser.py | 0
.../qemu-common/scripts}/qapi/pylintrc | 0
.../qemu-common/scripts}/qapi/schema.py | 0
.../qemu-common/scripts}/qapi/source.py | 0
.../qemu-common/scripts}/qapi/types.py | 17 +-
.../qemu-common/scripts}/qapi/visit.py | 19 +-
subprojects/qemu-common/src/meson.build | 5 +
subprojects/qemu-common/tests/meson.build | 12 ++
tests/qapi-schema/meson.build | 2 +-
util/meson.build | 2 +-
51 files changed, 579 insertions(+), 324 deletions(-)
rename {include => subprojects/qemu-common/include}/glib-compat.h (97%)
rename {include => subprojects/qemu-common/include}/qemu/error-report.h (97%)
rename {include => subprojects/qemu-common/include}/qemu/help-texts.h (100%)
create mode 100644 stubs/qmp-dispatch-exec.c
create mode 100644 subprojects/qemu-common/src/error-is-detailed.c
rename {util => subprojects/qemu-common/src}/error-report.c (96%)
rename stubs/error-printf.c => subprojects/qemu-common/src/error-vprintf.c (64%)
create mode 100644 subprojects/qemu-common/tests/test-error-report.c
create mode 120000 subprojects/libvduse/subprojects/qemu-common
create mode 120000 subprojects/libvhost-user/subprojects/qemu-common
create mode 100644 subprojects/qemu-common/meson.build
create mode 100644 subprojects/qemu-common/scripts/meson.build
rename {scripts => subprojects/qemu-common/scripts}/qapi-gen.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/.flake8 (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/.isort.cfg (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/__init__.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/commands.py (96%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/common.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/error.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/events.py (95%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/expr.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/gen.py (96%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/introspect.py (97%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/main.py (85%)
create mode 100644 subprojects/qemu-common/scripts/qapi/meson.build
rename {scripts => subprojects/qemu-common/scripts}/qapi/mypy.ini (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/parser.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/pylintrc (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/schema.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/source.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/types.py (96%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/visit.py (96%)
create mode 100644 subprojects/qemu-common/src/meson.build
create mode 100644 subprojects/qemu-common/tests/meson.buildSignature · 1 line
2.37.1
PATCH v3 1/16 error-report: misc comment fix
From: Marc-André Lureau <[email protected]>
Missed in commit beeb175c0d "util/qemu-error: Rename error_print_loc() to be more generic".
--- util/error-report.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/error-report.c +1 -1
@@ -390,7 +390,7 @@ void error_init(const char *argv0) {const char *p =strrchr (argv0,'/' ); -/* Set the program name for error_print_loc(). */ +/* Set the program name for print_loc(). */ g_set_prgname (p ? p +1 : argv0);/*
Signature · 1 line
2.37.1
PATCH v3 2/16 error-report: introduce "detailed" variable
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Let's use a more explicit variable "detailed" instead of calling monitor_cur() multiple times.
--- util/error-report.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
util/error-report.c +3 -2
@@ -195,16 +195,17 @@ real_time_iso8601(void)*/ static void vreport (report_type type,const char *fmt,va_list ap) { +bool detailed = !monitor_cur ();gchar *timestr; -if (message_with_timestamp && !monitor_cur ()) { +if (message_with_timestamp && detailed) { timestr =real_time_iso8601 ();error_printf ("%s " , timestr);g_free (timestr); }/* Only prepend guest name if -msg guest-name and -name guest=... are set */ -if (error_with_guestname && error_guest_name && !monitor_cur ()) { +if (error_with_guestname && error_guest_name && detailed) {error_printf ("%s " , error_guest_name); }
Signature · 1 line
2.37.1
PATCH v3 3/16 error-report: simplify print_loc()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Pass the program name as "prefix" argument to print_loc() if printing with "details". This allows to get rid of monitor_cur() call in print_loc().
--- util/error-report.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
util/error-report.c +4 -4
@@ -138,14 +138,14 @@ void loc_set_file(const char *fname, int lno)/* * Print current location to current monitor if we have one, else to stderr. */ -static void print_loc (void ) +static void print_loc (const char *prefix) {const char *sep ="" ;int i;const char *const *argp; -if (!monitor_cur () &&g_get_prgname ()) { -error_printf ("%s:" ,g_get_prgname ()); +if (prefix) { +error_printf ("%s:" , prefix); sep =" " ; }switch (cur_loc->kind) {
@@ -209,7 +209,7 @@ static void vreport(report_type type, const char *fmt, va_list ap)error_printf ("%s " , error_guest_name); } -print_loc (); +print_loc (detailed ?g_get_prgname () :NULL );switch (type) {case REPORT_TYPE_ERROR :
Signature · 1 line
2.37.1
PATCH v3 4/16 error-report: introduce overridable error_is_detailed()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Remove the direct dependency from error-report to monitor code. This will allow to move error-report to a subproject.
--- include/qemu/error-report.h | 2 ++ softmmu/vl.c | 5 +++++ stubs/error-is-detailed.c | 7 +++++++ util/error-report.c | 3 +-- stubs/meson.build | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 stubs/error-is-detailed.c
include/qemu/error-report.h +2 -0
@@ -30,6 +30,8 @@ void loc_set_none(void);void loc_set_cmdline (char **argv,int idx,int cnt);void loc_set_file (const char *fname,int lno); +bool error_is_detailed (void ); + int error_vprintf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0); int error_printf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
softmmu/vl.c +5 -0
@@ -2603,6 +2603,11 @@ void qmp_x_exit_preconfig(Error **errp) } } +bool error_is_detailed (void ) +{ +return !monitor_cur (); +} +void qemu_init (int argc,char **argv,char **envp) {QemuOpts *opts;
stubs/error-is-detailed.c new file +7 -0
@@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "qemu/error-report.h" + +bool error_is_detailed (void ) +{ +return TRUE; +}
util/error-report.c +1 -2
@@ -11,7 +11,6 @@*/ #include "qemu/osdep.h" -#include "monitor/monitor.h" #include "qemu/error-report.h" /*
@@ -195,7 +194,7 @@ real_time_iso8601(void)*/ static void vreport (report_type type,const char *fmt,va_list ap) { -bool detailed = !monitor_cur (); +bool detailed =error_is_detailed ();gchar *timestr;if (message_with_timestamp && detailed) {
stubs/meson.build +1 -0
@@ -9,6 +9,7 @@ stub_ss.add(files('cpus-get-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c')) +stub_ss.add(files('error-is-detailed.c')) stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('gdbstub.c'))
Signature · 1 line
2.37.1
PATCH v3 5/16 stubs: remove needless error_vprintf_unless_qmp()
In reply to [email protected]From: Marc-André Lureau <[email protected]>
--- stubs/error-printf.c | 5 ----- 1 file changed, 5 deletions(-)
stubs/error-printf.c +0 -5
@@ -16,8 +16,3 @@ int error_vprintf(const char *fmt, va_list ap) }return vfprintf (stderr, fmt, ap); } - -int error_vprintf_unless_qmp (const char *fmt,va_list ap) -{ -return error_vprintf (fmt, ap); -}
Signature · 1 line
2.37.1
PATCH v3 6/16 qapi: move QEMU-specific dispatch code in monitor
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Make QMP-dispatch code free from QEMU-specific OOB dispatch/async coroutine handling. This will allow to move the base code to qemu-common, and clear other users from potential mis-ususe (QGA doesn't have OOB or coroutines).
Introduce an overridable qmp_dispatch_exec() function, with a default a stub implementation, while the oob & coroutine dispatch logic is moved to monitor/qmp.c.
--- include/qapi/qmp/dispatch.h | 3 ++ monitor/qmp.c | 63 +++++++++++++++++++++++++++++++++++++ qapi/qmp-dispatch.c | 60 +---------------------------------- stubs/qmp-dispatch-exec.c | 8 +++++ stubs/meson.build | 1 + 5 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 stubs/qmp-dispatch-exec.c
include/qapi/qmp/dispatch.h +3 -0
@@ -41,6 +41,9 @@ typedef struct QmpCommand typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList; +void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,Monitor *cur_mon, +QDict *args,QObject **ret,Error **err); +void qmp_register_command (QmpCommandList *cmds,const char *name,QmpCommandFunc *fn,QmpCommandOptions options,unsigned special_features);
monitor/qmp.c +63 -0
69 lines not on this page · raw message
qapi/qmp-dispatch.c +1 -59
85 lines not on this page · raw message
stubs/qmp-dispatch-exec.c new file +8 -0
@@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "qapi/qmp/dispatch.h" + +void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,Monitor *cur_mon, +QDict *args,QObject **ret,Error **err) +{ + cmd->fn (args, ret, err); +}
stubs/meson.build +1 -0
@@ -32,6 +32,7 @@ stub_ss.add(files('monitor.c')) stub_ss.add(files('monitor-core.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('qmp_memory_device.c')) +stub_ss.add(files('qmp-dispatch-exec.c')) stub_ss.add(files('qmp-command-available.c')) stub_ss.add(files('qmp-quit.c')) stub_ss.add(files('qtest.c'))
Signature · 1 line
2.37.1
PATCH v3 7/16 qapi: remove QEMU-specific monitor dependency from dispatch
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The monitor is specific to QEMU. Instead of passing a Monitor type argument to the exec handler, use a generic void* pointer. This simplify also the unit dependency, as now the dispatching code is free from QEMU-specifics.
--- include/qapi/qmp/dispatch.h | 5 ++--- monitor/qmp.c | 3 ++- qapi/qmp-dispatch.c | 4 ++-- stubs/qmp-dispatch-exec.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
include/qapi/qmp/dispatch.h +2 -3
@@ -14,7 +14,6 @@#ifndef QAPI_QMP_DISPATCH_H #define QAPI_QMP_DISPATCH_H -#include "monitor/monitor.h" #include "qemu/queue.h" typedef void (QmpCommandFunc )(QDict *,QObject **,Error **);
@@ -41,7 +40,7 @@ typedef struct QmpCommand typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList; -void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,Monitor *cur_mon, +void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,void *exec_data,QDict *args,QObject **ret,Error **err); void qmp_register_command(QmpCommandList *cmds, const char *name,
@@ -59,7 +58,7 @@ const char *qmp_command_name(const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd);QDict *qmp_error_response (Error *err);QDict *qmp_dispatch (const QmpCommandList *cmds,QObject *request, -bool allow_oob,Monitor *cur_mon); +bool allow_oob,void *exec_data);bool qmp_is_oob (const QDict *dict);typedef void (*qmp_cmd_callback_fn )(const QmpCommand *cmd,void *opaque);
monitor/qmp.c +2 -1
@@ -156,9 +156,10 @@ static void do_qmp_dispatch_bh(void *opaque)* Runs outside of coroutine context for OOB commands, but in coroutine * context for everything else. */ -void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,Monitor *cur_mon, +void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,void *exec_data,QDict *args,QObject **ret,Error **errp) { +Monitor *cur_mon = exec_data;assert (!(oob &&qemu_in_coroutine ()));assert (monitor_cur () ==NULL );
qapi/qmp-dispatch.c +2 -2
@@ -108,7 +108,7 @@ bool qmp_is_oob(const QDict *dict) }QDict *qmp_dispatch (const QmpCommandList *cmds,QObject *request, -bool allow_oob,Monitor *cur_mon) +bool allow_oob,void *exec_data) {Error *err =NULL ;bool oob;
@@ -176,7 +176,7 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,qobject_ref (args); } -qmp_dispatch_exec (cmd, oob, cur_mon, args, &ret, &err); +qmp_dispatch_exec (cmd, oob, exec_data, args, &ret, &err);qobject_unref (args);if (err) {
stubs/qmp-dispatch-exec.c +1 -1
@@ -1,7 +1,7 @@#include "qemu/osdep.h" #include "qapi/qmp/dispatch.h" -void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,Monitor *cur_mon, +void qmp_dispatch_exec (const QmpCommand *cmd,bool oob,void *exec_data,QDict *args,QObject **ret,Error **err) { cmd->fn (args, ret, err);
Signature · 1 line
2.37.1
PATCH v3 8/16 scripts/qapi-gen: add -i option
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Replace hard-coded "qemu/osdep.h" include with a qapi-gen option to specify the headers to include. This will allow to substitute QEMU osdep.h with glib.h for example, for projects with different global headers.
For historical reasons, we can keep the default as "qemu/osdep.h".
--- scripts/qapi/commands.py | 15 ++++++++++----- scripts/qapi/events.py | 17 +++++++++++------ scripts/qapi/gen.py | 15 +++++++++++++++ scripts/qapi/introspect.py | 11 +++++++---- scripts/qapi/main.py | 17 +++++++++++------ scripts/qapi/types.py | 17 +++++++++++------ scripts/qapi/visit.py | 17 +++++++++++------ 7 files changed, 76 insertions(+), 33 deletions(-)
scripts/qapi/commands.py +10 -5
@@ -294,9 +294,9 @@ def gen_register_command(name: str, class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str, gen_tracing: bool): + def __init__(self, prefix: str, include: List[str], gen_tracing: bool): super().__init__( - prefix, 'qapi-commands', + prefix, include, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', None, __doc__, gen_tracing=gen_tracing) self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {}
@@ -308,7 +308,8 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/compat-policy.h" #include "qapi/visitor.h" #include "qapi/qmp/qdict.h"
@@ -318,6 +319,7 @@ def _begin_user_module(self, name: str) -> None: #include "%(commands)s.h" ''', + include=self.genc_include(), commands=commands, visit=visit)) if self._gen_tracing and commands != 'qapi-commands':
@@ -344,7 +346,8 @@ def visit_begin(self, schema: QAPISchema) -> None: ''', c_prefix=c_name(self._prefix, protect=False))) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-commands.h" #include "%(prefix)sqapi-init-commands.h"
@@ -353,6 +356,7 @@ def visit_begin(self, schema: QAPISchema) -> None: QTAILQ_INIT(cmds); ''', + include=self.genc_include(), prefix=self._prefix, c_prefix=c_name(self._prefix, protect=False)))
@@ -404,7 +408,8 @@ def visit_command(self, def gen_commands(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], gen_tracing: bool) -> None: - vis = QAPISchemaGenCommandVisitor(prefix, gen_tracing) + vis = QAPISchemaGenCommandVisitor(prefix, include, gen_tracing) schema.visit(vis) vis.write(output_dir)
scripts/qapi/events.py +11 -6
@@ -175,9 +175,9 @@ def gen_event_send(name: str, class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-events', + prefix, include, 'qapi-events', ' * Schema-defined QAPI/QMP events', None, __doc__) self._event_enum_name = c_name(prefix + 'QAPIEvent', protect=False) self._event_enum_members: List[QAPISchemaEnumMember] = []
@@ -188,7 +188,8 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-emit-events.h" #include "%(events)s.h" #include "%(visit)s.h"
@@ -198,6 +199,7 @@ def _begin_user_module(self, name: str) -> None: #include "qapi/qmp-event.h" ''', + include=self.genc_include(), events=events, visit=visit, prefix=self._prefix)) self._genh.add(mcgen('''
@@ -209,9 +211,11 @@ def _begin_user_module(self, name: str) -> None: def visit_end(self) -> None: self._add_module('./emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-emit-events.h" ''', + include=self.genc_include(), prefix=self._prefix)) self._genh.preamble_add(mcgen(''' #include "qapi/util.h"
@@ -246,7 +250,8 @@ def visit_event(self, def gen_events(schema: QAPISchema, output_dir: str, - prefix: str) -> None: - vis = QAPISchemaGenEventVisitor(prefix) + prefix: str, + include: List[str]) -> None: + vis = QAPISchemaGenEventVisitor(prefix, include) schema.visit(vis) vis.write(output_dir)
scripts/qapi/gen.py +15 -0
@@ -17,6 +17,7 @@ from typing import ( Dict, Iterator, + List, Optional, Sequence, Tuple,
@@ -45,6 +46,10 @@ def gen_special_features(features: Sequence[QAPISchemaFeature]) -> str: return ' | '.join(special_features) or '0' +def genc_include(include: List[str]) -> str: + return '\n'.join([f'#include "{inc}"' for inc in include]) + + class QAPIGen: def __init__(self, fname: str): self.fname = fname
@@ -228,16 +233,21 @@ def ifcontext(ifcond: QAPISchemaIfCond, *args: QAPIGenCCode) -> Iterator[None]: class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor): def __init__(self, prefix: str, + include: List[str], what: str, blurb: str, pydoc: str): self._prefix = prefix + self._include = include self._what = what self._genc = QAPIGenC(self._prefix + self._what + '.c', blurb, pydoc) self._genh = QAPIGenH(self._prefix + self._what + '.h', blurb, pydoc) + def genc_include(self) -> str: + return genc_include(self._include) + def write(self, output_dir: str) -> None: self._genc.write(output_dir) self._genh.write(output_dir)
@@ -246,12 +256,14 @@ def write(self, output_dir: str) -> None: class QAPISchemaModularCVisitor(QAPISchemaVisitor): def __init__(self, prefix: str, + include: List[str], what: str, user_blurb: str, builtin_blurb: Optional[str], pydoc: str, gen_tracing: bool = False): self._prefix = prefix + self._include = include self._what = what self._user_blurb = user_blurb self._builtin_blurb = builtin_blurb
@@ -262,6 +274,9 @@ def __init__(self, self._main_module: Optional[str] = None self._gen_tracing = gen_tracing + def genc_include(self) -> str: + return genc_include(self._include) + @property def _genc(self) -> QAPIGenC: assert self._current_module is not None
scripts/qapi/introspect.py +7 -4
@@ -170,9 +170,9 @@ def to_c_string(string: str) -> str: class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): - def __init__(self, prefix: str, unmask: bool): + def __init__(self, prefix: str, include: List[str], unmask: bool): super().__init__( - prefix, 'qapi-introspect', + prefix, include, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask = unmask self._schema: Optional[QAPISchema] = None
@@ -180,10 +180,12 @@ def __init__(self, prefix: str, unmask: bool): self._used_types: List[QAPISchemaType] = [] self._name_map: Dict[str, str] = {} self._genc.add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "%(prefix)sqapi-introspect.h" ''', + include=self.genc_include(), prefix=prefix)) def visit_begin(self, schema: QAPISchema) -> None:
@@ -384,7 +386,8 @@ def visit_event(self, name: str, info: Optional[QAPISourceInfo], def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_unmask: bool) -> None: - vis = QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) + vis = QAPISchemaGenIntrospectVisitor(prefix, include, opt_unmask) schema.visit(vis) vis.write(output_dir)
scripts/qapi/main.py +11 -6
@@ -9,7 +9,7 @@ import argparse import sys -from typing import Optional +from typing import List, Optional from .commands import gen_commands from .common import must_match
@@ -31,6 +31,7 @@ def invalid_prefix_char(prefix: str) -> Optional[str]: def generate(schema_file: str, output_dir: str, prefix: str, + include: List[str], unmask: bool = False, builtins: bool = False, gen_tracing: bool = False) -> None:
@@ -48,11 +49,11 @@ def generate(schema_file: str, assert invalid_prefix_char(prefix) is None schema = QAPISchema(schema_file) - gen_types(schema, output_dir, prefix, builtins) - gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix, gen_tracing) - gen_events(schema, output_dir, prefix) - gen_introspect(schema, output_dir, prefix, unmask) + gen_types(schema, output_dir, prefix, include, builtins) + gen_visit(schema, output_dir, prefix, include, builtins) + gen_commands(schema, output_dir, prefix, include, gen_tracing) + gen_events(schema, output_dir, prefix, include) + gen_introspect(schema, output_dir, prefix, include, unmask) def main() -> int:
@@ -75,6 +76,9 @@ def main() -> int: parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', dest='unmask', help="expose non-ABI names in introspection") + parser.add_argument('-i', '--include', nargs='*', + default=['qemu/osdep.h'], + help="top-level include headers") # Option --suppress-tracing exists so we can avoid solving build system # problems. TODO Drop it when we no longer need it.
@@ -94,6 +98,7 @@ def main() -> int: generate(args.schema, output_dir=args.output_dir, prefix=args.prefix, + include=args.include, unmask=args.unmask, builtins=args.builtins, gen_tracing=not args.suppress_tracing)
scripts/qapi/types.py +11 -6
@@ -282,18 +282,20 @@ def gen_type_cleanup(name: str) -> str: class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-types', ' * Schema-defined QAPI types', + prefix, include, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/dealloc-visitor.h" #include "qapi/qapi-builtin-types.h" #include "qapi/qapi-builtin-visit.h" -''')) +''', + include=self.genc_include())) self._genh.preamble_add(mcgen(''' #include "qapi/util.h" '''))
@@ -302,11 +304,13 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/dealloc-visitor.h" #include "%(types)s.h" #include "%(visit)s.h" ''', + include=self.genc_include(), types=types, visit=visit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-types.h"
@@ -381,7 +385,8 @@ def visit_alternate_type(self, def gen_types(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_builtins: bool) -> None: - vis = QAPISchemaGenTypeVisitor(prefix) + vis = QAPISchemaGenTypeVisitor(prefix, include) schema.visit(vis) vis.write(output_dir, opt_builtins)
scripts/qapi/visit.py +11 -6
@@ -318,17 +318,19 @@ def gen_visit_object(name: str) -> str: class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, include: List[str]): super().__init__( - prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', + prefix, include, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) def _begin_builtin_module(self) -> None: self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/error.h" #include "qapi/qapi-builtin-visit.h" -''')) +''', + include=self.genc_include())) self._genh.preamble_add(mcgen(''' #include "qapi/visitor.h" #include "qapi/qapi-builtin-types.h"
@@ -339,11 +341,13 @@ def _begin_user_module(self, name: str) -> None: types = self._module_basename('qapi-types', name) visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' -#include "qemu/osdep.h" +%(include)s + #include "qapi/error.h" #include "qapi/qmp/qerror.h" #include "%(visit)s.h" ''', + include=self.genc_include(), visit=visit)) self._genh.preamble_add(mcgen(''' #include "qapi/qapi-builtin-visit.h"
@@ -408,7 +412,8 @@ def visit_alternate_type(self, def gen_visit(schema: QAPISchema, output_dir: str, prefix: str, + include: List[str], opt_builtins: bool) -> None: - vis = QAPISchemaGenVisitVisitor(prefix) + vis = QAPISchemaGenVisitVisitor(prefix, include) schema.visit(vis) vis.write(output_dir, opt_builtins)
Signature · 1 line
2.37.1
PATCH v3 9/16 scripts/qapi: add required system includes to visitor
In reply to [email protected]From: Marc-André Lureau <[email protected]>
The generated visitor code includes abort() & assert(), we shouldn't rely on the global "-i" headers to include the necessary system headers.
--- scripts/qapi/visit.py | 2 ++ 1 file changed, 2 insertions(+)
scripts/qapi/visit.py +2 -0
@@ -342,6 +342,8 @@ def _begin_user_module(self, name: str) -> None: visit = self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' %(include)s +#include <assert.h> +#include <stdlib.h> #include "qapi/error.h" #include "qapi/qmp/qerror.h"
Signature · 1 line
2.37.1
PATCH v3 10/16 util: move 256-by-128 division helpers to int128
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Break a cyclic dependency between int128 and host-utils.
--- include/qemu/host-utils.h | 3 - include/qemu/int128.h | 3 + util/host-utils.c | 180 -------------------------------------- util/int128.c | 180 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 183 deletions(-)
include/qemu/host-utils.h +0 -3
@@ -32,7 +32,6 @@#include "qemu/compiler.h" #include "qemu/bswap.h" -#include "qemu/int128.h" #ifdef CONFIG_INT128 static inline void mulu64(uint64_t *plow, uint64_t *phigh,
@@ -784,6 +783,4 @@ static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1, #endif } -Int128 divu256 (Int128 *plow,Int128 *phigh,Int128 divisor); -Int128 divs256 (Int128 *plow,Int128 *phigh,Int128 divisor);#endif
include/qemu/int128.h +3 -0
@@ -472,4 +472,7 @@ static inline void bswap128s(Int128 *s)#define INT128_MAX int128_make128(UINT64_MAX, INT64_MAX)#define INT128_MIN int128_make128(0, INT64_MIN) +Int128 divu256 (Int128 *plow,Int128 *phigh,Int128 divisor); +Int128 divs256 (Int128 *plow,Int128 *phigh,Int128 divisor); +#endif /* INT128_H */
util/host-utils.c +0 -180
183 lines not on this page · raw message
util/int128.c +180 -0
183 lines not on this page · raw message
Signature · 1 line
2.37.1
PATCH v3 11/16 qemu-common: introduce a common subproject
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add a new meson subproject to provide common code and scripts for QEMU and tools. Initially, it will offer QAPI/QMP code generation and common utilities.
libvhost-user & libvduse will make use of the subproject to avoid having include/ links to common headers.
The other targeted user is qemu-ga, which will also be converted to a subproject (so it can be built, moved, released etc independent from QEMU).
Other projects such as qemu-storage-daemon could be built standalone eventually in the future.
Note that with meson subprojects are "global". Projects will share
subprojects (https://mesonbuild.com/Subprojects.html#subprojects-depending-on-other-subprojects).
We will add extra subprojects/ links to allow standalone subproject
compilation though.
This initial commit simply set the stage to build and link against it.
---
meson.build | 9 ++++++++-
.../qemu-common/include}/qemu/help-texts.h | 0
subprojects/libvduse/meson.build | 2 ++
subprojects/libvduse/subprojects/qemu-common | 1 +
subprojects/libvhost-user/meson.build | 2 ++
subprojects/libvhost-user/subprojects/qemu-common | 1 +
subprojects/qemu-common/meson.build | 8 ++++++++
7 files changed, 22 insertions(+), 1 deletion(-)
rename {include => subprojects/qemu-common/include}/qemu/help-texts.h (100%)
create mode 120000 subprojects/libvduse/subprojects/qemu-common
create mode 120000 subprojects/libvhost-user/subprojects/qemu-common
create mode 100644 subprojects/qemu-common/meson.buildmeson.build +8 -1
@@ -169,6 +169,10 @@ if 'dtrace' in get_option('trace_backends') endif endif +add_project_arguments('-I' + meson.current_source_dir() / 'subprojects/qemu-common/include', + language: ['c', 'cpp', 'objc'], +) + if get_option('iasl') == '' iasl = find_program('iasl', required: false) else
@@ -1583,6 +1587,9 @@ if libbpf.found() and not cc.links(''' endif endif +qemu_common = subproject('qemu-common') +qemu_common = qemu_common.get_variable('qemu_common_dep') + ################# # config-host.h # #################
@@ -3057,7 +3064,7 @@ util_ss.add_all(trace_ss) util_ss = util_ss.apply(config_all, strict: false) libqemuutil = static_library('qemuutil', sources: util_ss.sources() + stub_ss.sources() + genh, - dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman]) + dependencies: [util_ss.dependencies(), libm, threads, glib, socket, malloc, pixman, qemu_common]) qemuutil = declare_dependency(link_with: libqemuutil, sources: genh + version_res, dependencies: [event_loop_base])
subprojects/qemu-common/include/qemu/help-texts.h renamed from include/qemu/help-texts.h +0 -0
subprojects/libvduse/meson.build +2 -0
@@ -2,6 +2,8 @@ project('libvduse', 'c', license: 'GPL-2.0-or-later', default_options: ['c_std=gnu99']) +qemu_common = subproject('qemu-common') + libvduse = static_library('vduse', files('libvduse.c'), c_args: '-D_GNU_SOURCE')
subprojects/libvduse/subprojects/qemu-common new file +1 -0
@@ -0,0 +1 @@ +../../qemu-common
subprojects/libvhost-user/meson.build +2 -0
@@ -5,6 +5,8 @@ project('libvhost-user', 'c', threads = dependency('threads') glib = dependency('glib-2.0') +qemu_common = subproject('qemu-common') + vhost_user = static_library('vhost-user', files('libvhost-user.c'), dependencies: threads,
subprojects/libvhost-user/subprojects/qemu-common new file +1 -0
@@ -0,0 +1 @@ +../../qemu-common
subprojects/qemu-common/meson.build new file +8 -0
@@ -0,0 +1,8 @@ +project('qemu-common', 'c', + license: 'GPL-2.0-or-later', + default_options: ['c_std=gnu11'] +) + +qemu_common_dep = declare_dependency( + include_directories: include_directories('include'), +)
Signature · 1 line
2.37.1
PATCH v3 12/16 qemu-common: move scripts/qapi
In reply to [email protected]From: Marc-André Lureau <[email protected]>
This is just moving qapi-gen.py and related subdir to qemu-common, to ease review and proceed step by step. The following patches will move related necessary code, tests etc.
---
docs/conf.py | 2 +-
meson.build | 19 ++-----------------
MAINTAINERS | 4 ++--
subprojects/qemu-common/meson.build | 2 ++
subprojects/qemu-common/scripts/meson.build | 3 +++
.../qemu-common/scripts}/qapi-gen.py | 0
.../qemu-common/scripts}/qapi/.flake8 | 0
.../qemu-common/scripts}/qapi/.isort.cfg | 0
.../qemu-common/scripts}/qapi/__init__.py | 0
.../qemu-common/scripts}/qapi/commands.py | 0
.../qemu-common/scripts}/qapi/common.py | 0
.../qemu-common/scripts}/qapi/error.py | 0
.../qemu-common/scripts}/qapi/events.py | 0
.../qemu-common/scripts}/qapi/expr.py | 0
.../qemu-common/scripts}/qapi/gen.py | 0
.../qemu-common/scripts}/qapi/introspect.py | 0
.../qemu-common/scripts}/qapi/main.py | 0
.../qemu-common/scripts/qapi/meson.build | 16 ++++++++++++++++
.../qemu-common/scripts}/qapi/mypy.ini | 0
.../qemu-common/scripts}/qapi/parser.py | 0
.../qemu-common/scripts}/qapi/pylintrc | 0
.../qemu-common/scripts}/qapi/schema.py | 0
.../qemu-common/scripts}/qapi/source.py | 0
.../qemu-common/scripts}/qapi/types.py | 0
.../qemu-common/scripts}/qapi/visit.py | 0
tests/qapi-schema/meson.build | 2 +-
26 files changed, 27 insertions(+), 21 deletions(-)
create mode 100644 subprojects/qemu-common/scripts/meson.build
rename {scripts => subprojects/qemu-common/scripts}/qapi-gen.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/.flake8 (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/.isort.cfg (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/__init__.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/commands.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/common.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/error.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/events.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/expr.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/gen.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/introspect.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/main.py (100%)
create mode 100644 subprojects/qemu-common/scripts/qapi/meson.build
rename {scripts => subprojects/qemu-common/scripts}/qapi/mypy.ini (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/parser.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/pylintrc (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/schema.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/source.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/types.py (100%)
rename {scripts => subprojects/qemu-common/scripts}/qapi/visit.py (100%)docs/conf.py +1 -1
@@ -56,7 +56,7 @@ # Our extensions are in docs/sphinx; the qapidoc extension requires # the QAPI modules from scripts/. sys.path.insert(0, os.path.join(qemu_docdir, "sphinx")) -sys.path.insert(0, os.path.join(qemu_docdir, "../scripts")) +sys.path.insert(0, os.path.join(qemu_docdir, "../subprojects/qemu-common/scripts")) # -- General configuration ------------------------------------------------
meson.build +2 -17
@@ -1588,6 +1588,8 @@ if libbpf.found() and not cc.links(''' endif qemu_common = subproject('qemu-common') +qapi_gen = qemu_common.get_variable('qapi_gen') +qapi_gen_depends = qemu_common.get_variable('qapi_gen_depends') qemu_common = qemu_common.get_variable('qemu_common_dep') #################
@@ -2795,23 +2797,6 @@ genh += configure_file(output: 'config-host.h', configuration: config_host_data) hxtool = find_program('scripts/hxtool') shaderinclude = find_program('scripts/shaderinclude.pl') -qapi_gen = find_program('scripts/qapi-gen.py') -qapi_gen_depends = [ meson.current_source_dir() / 'scripts/qapi/__init__.py', - meson.current_source_dir() / 'scripts/qapi/commands.py', - meson.current_source_dir() / 'scripts/qapi/common.py', - meson.current_source_dir() / 'scripts/qapi/error.py', - meson.current_source_dir() / 'scripts/qapi/events.py', - meson.current_source_dir() / 'scripts/qapi/expr.py', - meson.current_source_dir() / 'scripts/qapi/gen.py', - meson.current_source_dir() / 'scripts/qapi/introspect.py', - meson.current_source_dir() / 'scripts/qapi/parser.py', - meson.current_source_dir() / 'scripts/qapi/schema.py', - meson.current_source_dir() / 'scripts/qapi/source.py', - meson.current_source_dir() / 'scripts/qapi/types.py', - meson.current_source_dir() / 'scripts/qapi/visit.py', - meson.current_source_dir() / 'scripts/qapi/common.py', - meson.current_source_dir() / 'scripts/qapi-gen.py' -] tracetool = [ python, files('scripts/tracetool.py'),
MAINTAINERS +2 -2
@@ -2848,8 +2848,8 @@ F: tests/unit/test-*-visitor.c F: tests/unit/test-qapi-*.c F: tests/unit/test-qmp-*.c F: tests/unit/test-visitor-serialization.c -F: scripts/qapi-gen.py -F: scripts/qapi/* +F: subprojects/qemu-common/scripts/qapi-gen.py +F: subprojects/qemu-common/scripts/qapi/* F: docs/sphinx/qapidoc.py F: docs/devel/qapi* T: git https://repo.or.cz/qemu/armbru.git qapi-next
subprojects/qemu-common/meson.build +2 -0
@@ -6,3 +6,5 @@ project('qemu-common', 'c', qemu_common_dep = declare_dependency( include_directories: include_directories('include'), ) + +subdir('scripts')
subprojects/qemu-common/scripts/meson.build new file +3 -0
@@ -0,0 +1,3 @@ +qapi_gen = find_program('qapi-gen.py') + +subdir('qapi')
subprojects/qemu-common/scripts/qapi-gen.py renamed from scripts/qapi-gen.py +0 -0
subprojects/qemu-common/scripts/qapi/.flake8 renamed from scripts/qapi/.flake8 +0 -0
subprojects/qemu-common/scripts/qapi/.isort.cfg renamed from scripts/qapi/.isort.cfg +0 -0
subprojects/qemu-common/scripts/qapi/__init__.py renamed from scripts/qapi/__init__.py +0 -0
subprojects/qemu-common/scripts/qapi/commands.py renamed from scripts/qapi/commands.py +0 -0
subprojects/qemu-common/scripts/qapi/common.py renamed from scripts/qapi/common.py +0 -0
subprojects/qemu-common/scripts/qapi/error.py renamed from scripts/qapi/error.py +0 -0
subprojects/qemu-common/scripts/qapi/events.py renamed from scripts/qapi/events.py +0 -0
subprojects/qemu-common/scripts/qapi/expr.py renamed from scripts/qapi/expr.py +0 -0
subprojects/qemu-common/scripts/qapi/gen.py renamed from scripts/qapi/gen.py +0 -0
subprojects/qemu-common/scripts/qapi/introspect.py renamed from scripts/qapi/introspect.py +0 -0
subprojects/qemu-common/scripts/qapi/main.py renamed from scripts/qapi/main.py +0 -0
subprojects/qemu-common/scripts/qapi/meson.build new file +16 -0
@@ -0,0 +1,16 @@ +qapi_gen_depends = files( + '__init__.py', + 'commands.py', + 'common.py', + 'error.py', + 'events.py', + 'expr.py', + 'gen.py', + 'introspect.py', + 'parser.py', + 'schema.py', + 'source.py', + 'types.py', + 'visit.py', + 'common.py', +)
subprojects/qemu-common/scripts/qapi/mypy.ini renamed from scripts/qapi/mypy.ini +0 -0
subprojects/qemu-common/scripts/qapi/parser.py renamed from scripts/qapi/parser.py +0 -0
subprojects/qemu-common/scripts/qapi/pylintrc renamed from scripts/qapi/pylintrc +0 -0
subprojects/qemu-common/scripts/qapi/schema.py renamed from scripts/qapi/schema.py +0 -0
subprojects/qemu-common/scripts/qapi/source.py renamed from scripts/qapi/source.py +0 -0
subprojects/qemu-common/scripts/qapi/types.py renamed from scripts/qapi/types.py +0 -0
subprojects/qemu-common/scripts/qapi/visit.py renamed from scripts/qapi/visit.py +0 -0
tests/qapi-schema/meson.build +1 -1
@@ -1,5 +1,5 @@ test_env = environment() -test_env.set('PYTHONPATH', meson.project_source_root() / 'scripts') +test_env.set('PYTHONPATH', meson.project_source_root() / 'subprojects/qemu-common/scripts') test_env.set('PYTHONIOENCODING', 'utf-8') schemas = [
Signature · 1 line
2.37.1
PATCH v3 13/16 qemu-common: move glib-compat.h
In reply to [email protected]From: Marc-André Lureau <[email protected]>
qemu-common will have compatible dependency requirements with QEMU.
Since qemu-common won't have a toplevel qemu/osdep.h which would include various system headers, include stdbool.h (bool is used for some declarations here).
Replace getenv() with g_getenv() to avoid extra header inclusion.
---
{include => subprojects/qemu-common/include}/glib-compat.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
rename {include => subprojects/qemu-common/include}/glib-compat.h (97%)subprojects/qemu-common/include/glib-compat.h renamed from include/glib-compat.h +3 -1
@@ -30,6 +30,8 @@#pragma GCC diagnostic ignored "-Wdeprecated-declarations"#include <glib.h> +#include <stdbool.h> +#if defined(G_OS_UNIX )#include <glib-unix.h> #include <sys/types.h>
@@ -133,7 +135,7 @@ qemu_g_test_slow(void) {static int cached =-1 ;if (cached ==-1 ) { - cached =g_test_slow () ||getenv ("G_TEST_SLOW" ) !=NULL ; + cached =g_test_slow () ||g_getenv ("G_TEST_SLOW" ) !=NULL ; }return cached; }
Signature · 1 line
2.37.1
PATCH v3 14/16 qemu-common: move error-report
In reply to [email protected]From: Marc-André Lureau <[email protected]>
---
.../qemu-common/include}/qemu/error-report.h | 2 ++
.../qemu-common/src}/error-is-detailed.c | 1 -
.../qemu-common/src}/error-report.c | 4 +++-
.../qemu-common/src/error-vprintf.c | 5 ++---
stubs/meson.build | 2 --
subprojects/qemu-common/meson.build | 20 ++++++++++++++++---
subprojects/qemu-common/src/meson.build | 5 +++++
util/meson.build | 2 +-
8 files changed, 30 insertions(+), 11 deletions(-)
rename {include => subprojects/qemu-common/include}/qemu/error-report.h (98%)
rename {stubs => subprojects/qemu-common/src}/error-is-detailed.c (77%)
rename {util => subprojects/qemu-common/src}/error-report.c (99%)
rename stubs/error-printf.c => subprojects/qemu-common/src/error-vprintf.c (78%)
create mode 100644 subprojects/qemu-common/src/meson.buildsubprojects/qemu-common/include/qemu/error-report.h renamed from include/qemu/error-report.h +2 -0
@@ -13,6 +13,8 @@ #ifndef QEMU_ERROR_REPORT_H #define QEMU_ERROR_REPORT_H +#include "glib-compat.h" + typedef struct Location { /* all members are private to qemu-error.c */ enum { LOC_NONE, LOC_CMDLINE, LOC_FILE } kind;
subprojects/qemu-common/src/error-is-detailed.c renamed from stubs/error-is-detailed.c +0 -1
@@ -1,4 +1,3 @@ -#include "qemu/osdep.h" #include "qemu/error-report.h" bool error_is_detailed (void )
subprojects/qemu-common/src/error-report.c renamed from util/error-report.c +3 -1
@@ -10,7 +10,9 @@* See the COPYING file in the top-level directory. */ -#include "qemu/osdep.h" +#include <stdio.h> +#include <assert.h> +#include "qemu/error-report.h" /*
subprojects/qemu-common/src/error-vprintf.c renamed from stubs/error-printf.c +2 -3
@@ -1,13 +1,12 @@ -#include "qemu/osdep.h" +#include <stdio.h> #include "qemu/error-report.h" -#include "monitor/monitor.h" int error_vprintf (const char *fmt,va_list ap) {int ret;if (g_test_initialized () && !g_test_subprocess () && -getenv ("QTEST_SILENT_ERRORS" )) { +g_getenv ("QTEST_SILENT_ERRORS" )) {char *msg =g_strdup_vprintf (fmt, ap);g_test_message ("%s" , msg); ret =strlen (msg);
stubs/meson.build +0 -2
@@ -9,8 +9,6 @@ stub_ss.add(files('cpus-get-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c')) -stub_ss.add(files('error-is-detailed.c')) -stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('gdbstub.c')) stub_ss.add(files('get-vm-name.c'))
subprojects/qemu-common/meson.build +17 -3
@@ -3,8 +3,22 @@ project('qemu-common', 'c', default_options: ['c_std=gnu11'] ) -qemu_common_dep = declare_dependency( - include_directories: include_directories('include'), -) +glib_dep = dependency('glib-2.0') +inc = include_directories('include') + +sources = [] subdir('scripts') +subdir('src') + +lib = static_library( + 'qemu-common', sources, + dependencies: [glib_dep], + include_directories: inc, +) + +qemu_common_dep = declare_dependency( + link_with: lib, + include_directories: inc, + dependencies: [glib_dep], +)
subprojects/qemu-common/src/meson.build new file +5 -0
@@ -0,0 +1,5 @@ +sources += files( + 'error-is-detailed.c', + 'error-report.c', + 'error-vprintf.c', +)
util/meson.build +1 -1
@@ -29,7 +29,7 @@ util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheflush.c')) -util_ss.add(files('error.c', 'error-report.c')) +util_ss.add(files('error.c')) util_ss.add(files('qemu-print.c')) util_ss.add(files('id.c')) util_ss.add(files('qemu-config.c', 'notify.c'))
Signature · 1 line
2.37.1
PATCH v3 15/16 mtest2make.py: teach suite name that are just "PROJECT"
In reply to [email protected]From: Marc-André Lureau <[email protected]>
A subproject test may be simply in the "PROJECT" suite (such as "qemu-common" with the following patches)
--- scripts/mtest2make.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
scripts/mtest2make.py +5 -4
@@ -51,10 +51,11 @@ def process_tests(test, targets, suites): test_suites = test['suite'] or ['default'] for s in test_suites: - # The suite name in the introspection info is "PROJECT:SUITE" - s = s.split(':')[1] - if s == 'slow' or s == 'thorough': - continue + # The suite name in the introspection info is "PROJECT" or "PROJECT:SUITE" + if ':' in s: + s = s.split(':')[1] + if s == 'slow' or s == 'thorough': + continue if s.endswith('-slow'): s = s[:-5] suites[s].speeds.append('slow')
Signature · 1 line
2.37.1
PATCH v3 16/16 qemu-common: add error-report test
In reply to [email protected]From: Marc-André Lureau <[email protected]>
Add new tests to check the behaviour of error reporting functions.
--- .../qemu-common/tests/test-error-report.c | 120 ++++++++++++++++++ subprojects/qemu-common/meson.build | 2 + subprojects/qemu-common/tests/meson.build | 12 ++ 3 files changed, 134 insertions(+) create mode 100644 subprojects/qemu-common/tests/test-error-report.c create mode 100644 subprojects/qemu-common/tests/meson.build
subprojects/qemu-common/tests/test-error-report.c new file +120 -0
@@ -0,0 +1,120 @@ +/* +* Error reporting test +* +* Copyright (C) 2022 Red Hat Inc. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "glib-compat.h" +#include <locale.h> + +#include "qemu/error-report.h" + +static void +test_error_report_simple (void ) +{ +if (g_test_subprocess ()) { +error_report ("%s" ,"test error" ); +warn_report ("%s" ,"test warn" ); +info_report ("%s" ,"test info" ); +return ; + } + +g_test_trap_subprocess (NULL ,0 ,0 ); +g_test_trap_assert_passed (); +g_test_trap_assert_stderr ("\ +test-error-report: test error*\ +test-error-report: warning: test warn*\ +test-error-report: info: test info*\ +" ); +} + +static void +test_error_report_loc (void ) +{ +if (g_test_subprocess ()) { +loc_set_file ("some-file.c" ,7717 ); +error_report ("%s" ,"test error1" ); +loc_set_none (); +error_report ("%s" ,"test error2" ); +return ; + } + +g_test_trap_subprocess (NULL ,0 ,0 ); +g_test_trap_assert_passed (); +g_test_trap_assert_stderr ("\ +test-error-report:some-file.c:7717: test error1*\ +test-error-report: test error2*\ +" ); +} + +static void +test_error_report_glog (void ) +{ +if (g_test_subprocess ()) { +g_message ("gmessage" ); +return ; + } + +g_test_trap_subprocess (NULL ,0 ,0 ); +g_test_trap_assert_passed (); +g_test_trap_assert_stderr ("test-error-report: info: gmessage*" ); +} + +static void +test_error_report_once (void ) +{ +int i; + +if (g_test_subprocess ()) { +for (i =0 ; i <3 ; i++) { +warn_report_once ("warn" ); +error_report_once ("err" ); + } +return ; + } + +g_test_trap_subprocess (NULL ,0 ,0 ); +g_test_trap_assert_passed (); +g_test_trap_assert_stderr ("\ +test-error-report: warning: warn*\ +test-error-report: err*\ +" ); +} + +static void +test_error_report_timestamp (void ) +{ +if (g_test_subprocess ()) { + message_with_timestamp = true; +warn_report ("warn" ); +error_report ("err" ); +return ; + } + +g_test_trap_subprocess (NULL ,0 ,0 ); +g_test_trap_assert_passed (); +g_test_trap_assert_stderr ("\ +*-*-*:*:* test-error-report: warning: warn*\ +*-*-*:*:* test-error-report: err*\ +" ); +} + +int +main (int argc,char *argv[]) +{ +setlocale (LC_ALL ,"" ); + +g_test_init (&argc, &argv,NULL ); +error_init ("test-error-report" ); + +g_test_add_func ("/error-report/simple" , test_error_report_simple); +g_test_add_func ("/error-report/loc" , test_error_report_loc); +g_test_add_func ("/error-report/glog" , test_error_report_glog); +g_test_add_func ("/error-report/once" , test_error_report_once); +g_test_add_func ("/error-report/timestamp" , test_error_report_timestamp); + +return g_test_run (); +}
subprojects/qemu-common/meson.build +2 -0
@@ -22,3 +22,5 @@ qemu_common_dep = declare_dependency( include_directories: inc, dependencies: [glib_dep], ) + +subdir('tests')
subprojects/qemu-common/tests/meson.build new file +12 -0
@@ -0,0 +1,12 @@ +env = [ + 'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()), + 'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()), +] + +test('error-report', + executable('test-error-report', + sources: files('test-error-report.c'), + dependencies: qemu_common_dep, + ), + env: env, +)
Signature · 1 line
2.37.1