tracetool: add test suite to improve reviewability
Subsystems (2)
v3 cover tracetool: add test suite to improve reviewability
To repeat the start of the commit message in patch 5....
When reviewing tracetool patches it is often very unclear what the expected output will be for the generated backends. Compounding this is that a default build will only enable the 'log' trace backend, so developers won't see generated code for other backends without making a special effort. Some backends are also platform specific, so can't be enabled in QEMU builds, even though tracetool could generate the code.
To address this, introduce a test suite for tracetool which is conceptually similar to the qapi-schema test. It is a simple python program that runs tracetool and compares the actual output to historical reference output kept in git.
This was inspired by noticing the now pointless "__nocheck__" method wrapping in the inline probe functions.
Changed in v3:
- Also modify the QAPI schema test to use QEMU_TEST_REGENERATE=1 env & document / hint this
- Make tracetool accept '-' as shorthand for stdout to avoid relative paths in the reference output
Changed in v2:
- Add tracetool info to docs/devel/testing.rst
Daniel P. Berrangé (8):
checkpatch: cull trailing '*/' in SPDX check
tracetool: eliminate trailing whitespace in C format
tracetool: avoid space after "*" in arg types
tracetool: include SPDX-License-Identifier in generated files
tracetool: support "-" as a shorthand for stdout
tracetool: add test suite for tracetool with reference output
tracetool: drop the probe "__nocheck__" wrapping
qapi: switch to use QEMU_TEST_REGENERATE env var
MAINTAINERS | 1 + docs/devel/testing/main.rst | 40 +++++++++ scripts/checkpatch.pl | 3 + scripts/tracetool/__init__.py | 17 +++- scripts/tracetool/format/c.py | 3 +- scripts/tracetool/format/d.py | 3 +- scripts/tracetool/format/h.py | 17 +--- scripts/tracetool/format/log_stap.py | 1 + scripts/tracetool/format/simpletrace_stap.py | 1 + scripts/tracetool/format/stap.py | 1 + scripts/tracetool/format/ust_events_c.py | 1 + scripts/tracetool/format/ust_events_h.py | 1 + tests/Makefile.include | 1 + tests/meson.build | 1 + tests/qapi-schema/test-qapi.py | 7 +- tests/tracetool/dtrace.c | 32 +++++++ tests/tracetool/dtrace.d | 10 +++ tests/tracetool/dtrace.h | 45 ++++++++++ tests/tracetool/dtrace.log-stap | 15 ++++ tests/tracetool/dtrace.simpletrace-stap | 16 ++++ tests/tracetool/dtrace.stap | 14 +++ tests/tracetool/ftrace.c | 32 +++++++ tests/tracetool/ftrace.h | 59 +++++++++++++ tests/tracetool/log.c | 32 +++++++ tests/tracetool/log.h | 43 +++++++++ tests/tracetool/meson.build | 25 ++++++ tests/tracetool/simple.c | 61 +++++++++++++ tests/tracetool/simple.h | 40 +++++++++ tests/tracetool/syslog.c | 32 +++++++ tests/tracetool/syslog.h | 43 +++++++++ tests/tracetool/trace-events | 5 ++ tests/tracetool/tracetool-test.py | 91 ++++++++++++++++++++ tests/tracetool/ust.c | 32 +++++++ tests/tracetool/ust.h | 41 +++++++++ tests/tracetool/ust.ust-events-c | 14 +++ tests/tracetool/ust.ust-events-h | 56 ++++++++++++ 36 files changed, 813 insertions(+), 23 deletions(-) create mode 100644 tests/tracetool/dtrace.c create mode 100644 tests/tracetool/dtrace.d create mode 100644 tests/tracetool/dtrace.h create mode 100644 tests/tracetool/dtrace.log-stap create mode 100644 tests/tracetool/dtrace.simpletrace-stap create mode 100644 tests/tracetool/dtrace.stap create mode 100644 tests/tracetool/ftrace.c create mode 100644 tests/tracetool/ftrace.h create mode 100644 tests/tracetool/log.c create mode 100644 tests/tracetool/log.h create mode 100644 tests/tracetool/meson.build create mode 100644 tests/tracetool/simple.c create mode 100644 tests/tracetool/simple.h create mode 100644 tests/tracetool/syslog.c create mode 100644 tests/tracetool/syslog.h create mode 100644 tests/tracetool/trace-events create mode 100755 tests/tracetool/tracetool-test.py create mode 100644 tests/tracetool/ust.c create mode 100644 tests/tracetool/ust.h create mode 100644 tests/tracetool/ust.ust-events-c create mode 100644 tests/tracetool/ust.ust-events-h
Signature · 1 line
2.50.1
PATCH v3 3/8 tracetool: avoid space after "*" in arg types
QEMU code style is to have no whitespace between "*" and the arg name. Since generated trace code will soon be added to git, make it comply with code style.
--- scripts/tracetool/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/tracetool/__init__.py +7 -1
@@ -170,10 +170,16 @@ def __len__(self): def __str__(self): """String suitable for declaring function arguments.""" + def onearg(t, n): + if t[-1] == '*': + return "".join([t, n]) + else: + return " ".join([t, n]) + if len(self._args) == 0: return "void" else: - return ", ".join([ " ".join([t, n]) for t,n in self._args ]) + return ", ".join([ onearg(t, n) for t,n in self._args ]) def __repr__(self): """Evaluable string representation for this object."""
Signature · 1 line
2.50.1
PATCH v3 4/8 tracetool: include SPDX-License-Identifier in generated files
In reply to Daniel P. BerrangéWhile these files are auto-generated, a later commit will add reference output to git, so having SPDX-License-Identifier is desirable.
--- scripts/tracetool/format/c.py | 1 + scripts/tracetool/format/d.py | 3 ++- scripts/tracetool/format/h.py | 1 + scripts/tracetool/format/log_stap.py | 1 + scripts/tracetool/format/simpletrace_stap.py | 1 + scripts/tracetool/format/stap.py | 1 + scripts/tracetool/format/ust_events_c.py | 1 + scripts/tracetool/format/ust_events_h.py | 1 + 8 files changed, 9 insertions(+), 1 deletion(-)
scripts/tracetool/format/c.py +1 -0
@@ -22,6 +22,7 @@ def generate(events, backend, group): header = "trace-" + group + ".h" out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '', '#include "qemu/osdep.h"', '#include "qemu/module.h"',
scripts/tracetool/format/d.py +2 -1
@@ -39,7 +39,8 @@ def generate(events, backend, group): if not events and platform != "darwin": return - out('/* This file is autogenerated by tracetool, do not edit. */' + out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '', 'provider qemu {')
scripts/tracetool/format/h.py +1 -0
@@ -19,6 +19,7 @@ def generate(events, backend, group): header = "trace/control.h" out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '', '#ifndef TRACE_%s_GENERATED_TRACERS_H' % group.upper(), '#define TRACE_%s_GENERATED_TRACERS_H' % group.upper(),
scripts/tracetool/format/log_stap.py +1 -0
@@ -88,6 +88,7 @@ def c_fmt_to_stap(fmt): def generate(events, backend, group): out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '') for event_id, e in enumerate(events):
scripts/tracetool/format/simpletrace_stap.py +1 -0
@@ -22,6 +22,7 @@ def global_var_name(name): def generate(events, backend, group): out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '') for event_id, e in enumerate(events):
scripts/tracetool/format/stap.py +1 -0
@@ -38,6 +38,7 @@ def generate(events, backend, group): if "disable" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '') for e in events:
scripts/tracetool/format/ust_events_c.py +1 -0
@@ -20,6 +20,7 @@ def generate(events, backend, group): if "disabled" not in e.properties] out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '', '#include "qemu/osdep.h"', '',
scripts/tracetool/format/ust_events_h.py +1 -0
@@ -25,6 +25,7 @@ def generate(events, backend, group): include = "trace-ust.h" out('/* This file is autogenerated by tracetool, do not edit. */', + '/* SPDX-License-Identifier: GPL-2.0-or-later */', '', '#undef TRACEPOINT_PROVIDER', '#define TRACEPOINT_PROVIDER qemu',
Signature · 1 line
2.50.1
PATCH v3 8/8 qapi: switch to use QEMU_TEST_REGENERATE env var
In reply to Daniel P. BerrangéThe QAPI_TEST_UPDATE env var can be set when running the QAPI schema tests to regenerate the reference output. For consistent naming with the tracetool test, change the env var name to QEMU_TEST_REGENERATE.
The test is modified to provide a hint about use of the new
env var and it is also added to the developer documentation.document its usage.
--- docs/devel/testing/main.rst | 12 ++++++++++++ tests/qapi-schema/test-qapi.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-)
docs/devel/testing/main.rst +12 -0
@@ -178,6 +178,18 @@ parser (either fixing a bug or extending/modifying the syntax). To do this: ``qapi-schema += foo.json`` +The reference output can be automatically updated to match the latest QAPI +code generator by running the tests with the QEMU_TEST_REGENERATE environment +variable set. + +.. code:: + + QEMU_TEST_REGENERATE=1 make check-qapi-schema + +The resulting changes must be reviewed by the author to ensure they match +the intended results, before adding the updated reference output to the +same commit that alters the generator code. + .. _tracetool-tests: Tracetool tests
tests/qapi-schema/test-qapi.py +5 -2
@@ -165,7 +165,7 @@ def test_and_diff(test_name, dir_name, update): if actual_out == expected_out and actual_err == expected_err: return 0 - print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'), + print("%s: %s" % (test_name, 'UPDATE' if update else 'FAIL'), file=sys.stderr) out_diff = difflib.unified_diff(expected_out, actual_out, outfp.name) err_diff = difflib.unified_diff(expected_err, actual_err, errfp.name)
@@ -173,6 +173,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.writelines(err_diff) if not update: + print(("\n%s: set QEMU_TEST_REGENERATE=1 to recreate reference output" + + "if the QAPI schema generator was intentionally changed") % test_name, + file=sys.stderr) return 1 try:
@@ -197,7 +200,7 @@ def main(argv): parser.add_argument('-d', '--dir', action='store', default='', help="directory containing tests") parser.add_argument('-u', '--update', action='store_true', - default='QAPI_TEST_UPDATE' in os.environ, + default='QEMU_TEST_REGENERATE' in os.environ, help="update expected test results") parser.add_argument('tests', nargs='*', metavar='TEST', action='store') args = parser.parse_args()
Signature · 1 line
2.50.1
PATCH v3 7/8 tracetool: drop the probe "__nocheck__" wrapping
In reply to Daniel P. BerrangéEvery generated inline probe function is wrapped with a trivial caller that has a hard-coded condition test:
static inline void _nocheck__trace_test_wibble(void * context, int value)
{
tracepoint(qemu, test_wibble, context, value);
}
static inline void trace_test_wibble(void * context, int value)
{
if (true) {
_nocheck__trace_test_wibble(context, value);
}
}This was introduced for TCG probes back in
864a2178: trace: [tcg] Do not generate TCG code to trace dynamically-disabled events
but is obsolete since
126d4123 tracing: excise the tcg related from tracetool
This commit removes the wrapping such that we have
static inline void trace_test_wibble(void * context, int value)
{
tracepoint(qemu, test_wibble, context, value);
}The default build of qemu-system-x86_64 on Fedora with the 'log' backend, has its size reduced by 1 MB
--- scripts/tracetool/__init__.py | 1 - scripts/tracetool/format/h.py | 16 +--------------- tests/tracetool/dtrace.h | 18 ++---------------- tests/tracetool/ftrace.h | 20 +++----------------- tests/tracetool/log.h | 20 +++----------------- tests/tracetool/simple.h | 18 ++---------------- tests/tracetool/syslog.h | 20 +++----------------- tests/tracetool/ust.h | 18 ++---------------- 8 files changed, 16 insertions(+), 115 deletions(-)
scripts/tracetool/__init__.py +0 -1
@@ -342,7 +342,6 @@ def formats(self): return self._FMT.findall(self.fmt) QEMU_TRACE = "trace_%(name)s" - QEMU_TRACE_NOCHECK = "_nocheck__" + QEMU_TRACE QEMU_TRACE_TCG = QEMU_TRACE + "_tcg" QEMU_DSTATE = "_TRACE_%(NAME)s_DSTATE" QEMU_BACKEND_DSTATE = "TRACE_%(NAME)s_BACKEND_DSTATE"
scripts/tracetool/format/h.py +1 -15
@@ -64,7 +64,7 @@ def generate(events, backend, group): out('', 'static inline void %(api)s(%(args)s)', '{', - api=e.api(e.QEMU_TRACE_NOCHECK), + api=e.api(), args=e.args) if "disable" not in e.properties:
@@ -72,20 +72,6 @@ def generate(events, backend, group): out('}') - cond = "true" - - out('', - 'static inline void %(api)s(%(args)s)', - '{', - ' if (%(cond)s) {', - ' %(api_nocheck)s(%(names)s);', - ' }', - '}', - api=e.api(), - api_nocheck=e.api(e.QEMU_TRACE_NOCHECK), - args=e.args, - names=", ".join(e.args.names()), - cond=cond) backend.generate_end(events, group)
tests/tracetool/dtrace.h +2 -16
@@ -29,31 +29,17 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; QEMU_TEST_BLAH_ENABLED() || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) -{ -QEMU_TEST_BLAH (context, filename); -} -static inline void trace_test_blah (void *context,const char *filename) { -if (true) { -_nocheck__trace_test_blah (context, filename); - } +QEMU_TEST_BLAH (context, filename); }#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ QEMU_TEST_WIBBLE_ENABLED() || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) -{ -QEMU_TEST_WIBBLE (context, value); -} -static inline void trace_test_wibble (void *context,int value) { -if (true) { -_nocheck__trace_test_wibble (context, value); - } +QEMU_TEST_WIBBLE (context, value); }#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
tests/tracetool/ftrace.h +3 -17
@@ -19,7 +19,7 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; trace_event_get_state_dynamic_by_id(TRACE_TEST_BLAH) || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) +static inline void trace_test_blah (void *context,const char *filename) { {char ftrace_buf[MAX_TRACE_STRLEN ];
@@ -36,18 +36,11 @@ static inline void _nocheck__trace_test_blah(void *context, const char *filename } } -static inline void trace_test_blah (void *context,const char *filename) -{ -if (true) { -_nocheck__trace_test_blah (context, filename); - } -} -#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ trace_event_get_state_dynamic_by_id(TRACE_TEST_WIBBLE) || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) +static inline void trace_test_wibble (void *context,int value) { {char ftrace_buf[MAX_TRACE_STRLEN ];
@@ -57,17 +50,10 @@ static inline void _nocheck__trace_test_wibble(void *context, int value)#line 5 "trace-events" trlen =snprintf (ftrace_buf,MAX_TRACE_STRLEN ,"test_wibble " "Wibble context=%p value=%d" "\n" , context, value); -#line 61 "[stdout]" +#line 54 "[stdout]" trlen =MIN (trlen,MAX_TRACE_STRLEN -1 ); unused = write(trace_marker_fd, ftrace_buf, trlen); } } } - -static inline void trace_test_wibble (void *context,int value) -{ -if (true) { -_nocheck__trace_test_wibble (context, value); - } -}#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
tests/tracetool/log.h +3 -17
@@ -19,7 +19,7 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; trace_event_get_state_dynamic_by_id(TRACE_TEST_BLAH) || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) +static inline void trace_test_blah (void *context,const char *filename) {if (trace_event_get_state (TRACE_TEST_BLAH ) &&qemu_loglevel_mask (LOG_TRACE )) {#line 4 "trace-events"
@@ -28,30 +28,16 @@ static inline void _nocheck__trace_test_blah(void *context, const char *filename } } -static inline void trace_test_blah (void *context,const char *filename) -{ -if (true) { -_nocheck__trace_test_blah (context, filename); - } -} -#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ trace_event_get_state_dynamic_by_id(TRACE_TEST_WIBBLE) || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) +static inline void trace_test_wibble (void *context,int value) {if (trace_event_get_state (TRACE_TEST_WIBBLE ) &&qemu_loglevel_mask (LOG_TRACE )) {#line 5 "trace-events"qemu_log ("test_wibble " "Wibble context=%p value=%d" "\n" , context, value); -#line 48 "[stdout]" - } -} - -static inline void trace_test_wibble (void *context,int value) -{ -if (true) { -_nocheck__trace_test_wibble (context, value); +#line 41 "[stdout]" } }#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
tests/tracetool/simple.h +2 -16
@@ -20,35 +20,21 @@ void _simple_trace_test_wibble(void *context, int value); trace_event_get_state_dynamic_by_id(TRACE_TEST_BLAH) || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) +static inline void trace_test_blah (void *context,const char *filename) {if (trace_event_get_state (TRACE_TEST_BLAH )) {_simple_trace_test_blah (context, filename); } } -static inline void trace_test_blah (void *context,const char *filename) -{ -if (true) { -_nocheck__trace_test_blah (context, filename); - } -} -#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ trace_event_get_state_dynamic_by_id(TRACE_TEST_WIBBLE) || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) +static inline void trace_test_wibble (void *context,int value) {if (trace_event_get_state (TRACE_TEST_WIBBLE )) {_simple_trace_test_wibble (context, value); } } - -static inline void trace_test_wibble (void *context,int value) -{ -if (true) { -_nocheck__trace_test_wibble (context, value); - } -}#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
tests/tracetool/syslog.h +3 -17
@@ -19,7 +19,7 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; trace_event_get_state_dynamic_by_id(TRACE_TEST_BLAH) || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) +static inline void trace_test_blah (void *context,const char *filename) {if (trace_event_get_state (TRACE_TEST_BLAH )) {#line 4 "trace-events"
@@ -28,30 +28,16 @@ static inline void _nocheck__trace_test_blah(void *context, const char *filename } } -static inline void trace_test_blah (void *context,const char *filename) -{ -if (true) { -_nocheck__trace_test_blah (context, filename); - } -} -#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ trace_event_get_state_dynamic_by_id(TRACE_TEST_WIBBLE) || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) +static inline void trace_test_wibble (void *context,int value) {if (trace_event_get_state (TRACE_TEST_WIBBLE )) {#line 5 "trace-events"syslog (LOG_INFO ,"test_wibble " "Wibble context=%p value=%d" , context, value); -#line 48 "[stdout]" - } -} - -static inline void trace_test_wibble (void *context,int value) -{ -if (true) { -_nocheck__trace_test_wibble (context, value); +#line 41 "[stdout]" } }#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
tests/tracetool/ust.h +2 -16
@@ -25,31 +25,17 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; tracepoint_enabled(qemu, test_blah) || \ false) -static inline void _nocheck__trace_test_blah (void *context,const char *filename) -{ -tracepoint (qemu, test_blah, context, filename); -} -static inline void trace_test_blah (void *context,const char *filename) { -if (true) { -_nocheck__trace_test_blah (context, filename); - } +tracepoint (qemu, test_blah, context, filename); }#define TRACE_TEST_WIBBLE_BACKEND_DSTATE () ( \ tracepoint_enabled(qemu, test_wibble) || \ false) -static inline void _nocheck__trace_test_wibble (void *context,int value) -{ -tracepoint (qemu, test_wibble, context, value); -} -static inline void trace_test_wibble (void *context,int value) { -if (true) { -_nocheck__trace_test_wibble (context, value); - } +tracepoint (qemu, test_wibble, context, value); }#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
Signature · 1 line
2.50.1
PATCH v3 6/8 tracetool: add test suite for tracetool with reference output
In reply to Daniel P. BerrangéWhen reviewing tracetool patches it is often very unclear what the expected output will be for the generated backends. Compounding this is that a default build will only enable the 'log' trace backend, so developers won't see generated code for other backends without making a special effort. Some backends are also platform specific, so can't be enabled in QEMU builds, even though tracetool could generate the code.
To address this, introduce a test suite for tracetool which is conceptually similar to the qapi-schema test. It is a simple python program that runs tracetool and compares the actual output to historical reference output kept in git. The test directly emits TAP format logs for ease of integration with meson.
This can be run with
make check-tracetool
to make it easier for developers changing generated output, the sample expected content can be auto-recreated
QEMU_TEST_REGENERATE=1 make check-tracetool
and the changes reviewed and added to the commit. This will also assist reviewers interpreting the change.
Developers are reminded of this in the test output on failure:
$ make check-tracetool 1/6 qemu:tracetool / dtrace OK 0.14s 2/6 qemu:tracetool / ftrace FAIL 0.06s exit status 1 ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― 1..2 ok 1 - ftrace.c # not ok 1 - ftrace.h (set QEMU_TEST_REGENERATE=1 to recreate reference output if tracetool generator was intentionally changed) ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
3/6 qemu:tracetool / log OK 0.06s 4/6 qemu:tracetool / simple OK 0.06s 5/6 qemu:tracetool / syslog OK 0.06s 6/6 qemu:tracetool / ust OK 0.11s
Summary of Failures:
2/6 qemu:tracetool / ftrace FAIL 0.06s exit status 1
--- MAINTAINERS | 1 + docs/devel/testing/main.rst | 28 ++++++++ tests/Makefile.include | 1 + tests/meson.build | 1 + tests/tracetool/dtrace.c | 32 +++++++++ tests/tracetool/dtrace.d | 10 +++ tests/tracetool/dtrace.h | 59 ++++++++++++++++ tests/tracetool/dtrace.log-stap | 15 ++++ tests/tracetool/dtrace.simpletrace-stap | 16 +++++ tests/tracetool/dtrace.stap | 14 ++++ tests/tracetool/ftrace.c | 32 +++++++++ tests/tracetool/ftrace.h | 73 ++++++++++++++++++++ tests/tracetool/log.c | 32 +++++++++ tests/tracetool/log.h | 57 ++++++++++++++++ tests/tracetool/meson.build | 25 +++++++ tests/tracetool/simple.c | 61 +++++++++++++++++ tests/tracetool/simple.h | 54 +++++++++++++++ tests/tracetool/syslog.c | 32 +++++++++ tests/tracetool/syslog.h | 57 ++++++++++++++++ tests/tracetool/trace-events | 5 ++ tests/tracetool/tracetool-test.py | 91 +++++++++++++++++++++++++ tests/tracetool/ust.c | 32 +++++++++ tests/tracetool/ust.h | 55 +++++++++++++++ tests/tracetool/ust.ust-events-c | 14 ++++ tests/tracetool/ust.ust-events-h | 56 +++++++++++++++ 25 files changed, 853 insertions(+) create mode 100644 tests/tracetool/dtrace.c create mode 100644 tests/tracetool/dtrace.d create mode 100644 tests/tracetool/dtrace.h create mode 100644 tests/tracetool/dtrace.log-stap create mode 100644 tests/tracetool/dtrace.simpletrace-stap create mode 100644 tests/tracetool/dtrace.stap create mode 100644 tests/tracetool/ftrace.c create mode 100644 tests/tracetool/ftrace.h create mode 100644 tests/tracetool/log.c create mode 100644 tests/tracetool/log.h create mode 100644 tests/tracetool/meson.build create mode 100644 tests/tracetool/simple.c create mode 100644 tests/tracetool/simple.h create mode 100644 tests/tracetool/syslog.c create mode 100644 tests/tracetool/syslog.h create mode 100644 tests/tracetool/trace-events create mode 100755 tests/tracetool/tracetool-test.py create mode 100644 tests/tracetool/ust.c create mode 100644 tests/tracetool/ust.h create mode 100644 tests/tracetool/ust.ust-events-c create mode 100644 tests/tracetool/ust.ust-events-h
MAINTAINERS +1 -0
@@ -3556,6 +3556,7 @@ F: scripts/tracetool/ F: scripts/qemu-trace-stap* F: docs/tools/qemu-trace-stap.rst F: docs/devel/tracing.rst +F: tests/tracetool/ T: git https://github.com/stefanha/qemu.git tracing Simpletrace
docs/devel/testing/main.rst +28 -0
@@ -178,6 +178,34 @@ parser (either fixing a bug or extending/modifying the syntax). To do this: ``qapi-schema += foo.json`` +.. _tracetool-tests: + +Tracetool tests +~~~~~~~~~~~~~~~ + +The tracetool tests validate the generated source files used for defining +probes for various tracing backends and source formats. The test operates +by running the tracetool program against a sample trace-events file, and +comparing the generated output against known good reference output. The +tests can be run with: + +.. code:: + + make check-tracetool + +The reference output is stored in files under tests/tracetool, and when +the tracetool backend/format output is intentionally changed, the reference +files need to be updated. This can be automated by setting the +QEMU_TEST_REGENERATE=1 environment variable: + +.. code:: + + QEMU_TEST_REGENERATE=1 make check-tracetool + +The resulting changes must be reviewed by the author to ensure they match +the intended results, before adding the updated reference output to the +same commit that alters the generator code. + check-block ~~~~~~~~~~~
tests/Makefile.include +1 -0
@@ -13,6 +13,7 @@ check-help: @echo " $(MAKE) check-functional-TARGET Run functional tests for a given target" @echo " $(MAKE) check-unit Run qobject tests" @echo " $(MAKE) check-qapi-schema Run QAPI schema tests" + @echo " $(MAKE) check-tracetool Run tracetool generator tests" @echo " $(MAKE) check-block Run block tests" ifneq ($(filter $(all-check-targets), check-softfloat),) @echo " $(MAKE) check-tcg Run TCG tests"
tests/meson.build +1 -0
@@ -88,3 +88,4 @@ subdir('qapi-schema') subdir('qtest') subdir('migration-stress') subdir('functional') +subdir('tracetool')
tests/tracetool/dtrace.c new file +32 -0
@@ -0,0 +1,32 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "trace-testsuite.h" + +uint16_t _TRACE_TEST_BLAH_DSTATE; +uint16_t _TRACE_TEST_WIBBLE_DSTATE; +TraceEvent _TRACE_TEST_BLAH_EVENT = { + .id =0 , + .name ="test_blah" , + .sstate =TRACE_TEST_BLAH_ENABLED , + .dstate = &_TRACE_TEST_BLAH_DSTATE +}; +TraceEvent _TRACE_TEST_WIBBLE_EVENT = { + .id =0 , + .name ="test_wibble" , + .sstate =TRACE_TEST_WIBBLE_ENABLED , + .dstate = &_TRACE_TEST_WIBBLE_DSTATE +}; +TraceEvent *testsuite_trace_events[] = { + &_TRACE_TEST_BLAH_EVENT, + &_TRACE_TEST_WIBBLE_EVENT, +NULL , +}; + +static void trace_testsuite_register_events (void ) +{ +trace_event_register_group (testsuite_trace_events); +} +trace_init (trace_testsuite_register_events)
tests/tracetool/dtrace.d new file +10 -0
@@ -0,0 +1,10 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +provider qemu { + +probe test_blah(void * context,const char * filename); + +probe test_wibble(void * context,int value); + +};
tests/tracetool/dtrace.h new file +59 -0
59 lines not on this page · raw message
tests/tracetool/dtrace.log-stap new file +15 -0
@@ -0,0 +1,15 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +probe qemu.log.test_blah = qemu.test_blah ? +{ + try { + argfilename_str = filename ? user_string_n(filename, 512) : "<null>" + } catch {} + printf("%d@%d test_blah Blah context=%p filename=%s\n", pid(), gettimeofday_ns(), context, argfilename_str) +} +probe qemu.log.test_wibble = qemu.test_wibble ? +{ + printf("%d@%d test_wibble Wibble context=%p value=%d\n", pid(), gettimeofday_ns(), context, value) +} +
tests/tracetool/dtrace.simpletrace-stap new file +16 -0
@@ -0,0 +1,16 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +probe qemu.simpletrace.test_blah = qemu.test_blah ? +{ + try { + argfilename_str = filename ? user_string_n(filename, 512) : "<null>" + } catch {} + argfilename_len = strlen(argfilename_str) + printf("%8b%8b%8b%4b%4b%8b%4b%.*s", 1, 0, gettimeofday_ns(), 24 + 8 + 4 + argfilename_len, pid(), context, argfilename_len, argfilename_len, argfilename_str) +} +probe qemu.simpletrace.test_wibble = qemu.test_wibble ? +{ + printf("%8b%8b%8b%4b%4b%8b%8b", 1, 1, gettimeofday_ns(), 24 + 8 + 8, pid(), context, value) +} +
tests/tracetool/dtrace.stap new file +14 -0
@@ -0,0 +1,14 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +probe qemu.test_blah = process("qemu").mark("test_blah") +{ + context = $arg1; + filename = $arg2; +} +probe qemu.test_wibble = process("qemu").mark("test_wibble") +{ + context = $arg1; + value = $arg2; +} +
tests/tracetool/ftrace.c new file +32 -0
@@ -0,0 +1,32 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "trace-testsuite.h" + +uint16_t _TRACE_TEST_BLAH_DSTATE; +uint16_t _TRACE_TEST_WIBBLE_DSTATE; +TraceEvent _TRACE_TEST_BLAH_EVENT = { + .id =0 , + .name ="test_blah" , + .sstate =TRACE_TEST_BLAH_ENABLED , + .dstate = &_TRACE_TEST_BLAH_DSTATE +}; +TraceEvent _TRACE_TEST_WIBBLE_EVENT = { + .id =0 , + .name ="test_wibble" , + .sstate =TRACE_TEST_WIBBLE_ENABLED , + .dstate = &_TRACE_TEST_WIBBLE_DSTATE +}; +TraceEvent *testsuite_trace_events[] = { + &_TRACE_TEST_BLAH_EVENT, + &_TRACE_TEST_WIBBLE_EVENT, +NULL , +}; + +static void trace_testsuite_register_events (void ) +{ +trace_event_register_group (testsuite_trace_events); +} +trace_init (trace_testsuite_register_events)
tests/tracetool/ftrace.h new file +73 -0
73 lines not on this page · raw message
tests/tracetool/log.c new file +32 -0
@@ -0,0 +1,32 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "trace-testsuite.h" + +uint16_t _TRACE_TEST_BLAH_DSTATE; +uint16_t _TRACE_TEST_WIBBLE_DSTATE; +TraceEvent _TRACE_TEST_BLAH_EVENT = { + .id =0 , + .name ="test_blah" , + .sstate =TRACE_TEST_BLAH_ENABLED , + .dstate = &_TRACE_TEST_BLAH_DSTATE +}; +TraceEvent _TRACE_TEST_WIBBLE_EVENT = { + .id =0 , + .name ="test_wibble" , + .sstate =TRACE_TEST_WIBBLE_ENABLED , + .dstate = &_TRACE_TEST_WIBBLE_DSTATE +}; +TraceEvent *testsuite_trace_events[] = { + &_TRACE_TEST_BLAH_EVENT, + &_TRACE_TEST_WIBBLE_EVENT, +NULL , +}; + +static void trace_testsuite_register_events (void ) +{ +trace_event_register_group (testsuite_trace_events); +} +trace_init (trace_testsuite_register_events)
tests/tracetool/log.h new file +57 -0
57 lines not on this page · raw message
tests/tracetool/meson.build new file +25 -0
@@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +test_env = environment() +test_env.set('PYTHONPATH', meson.project_source_root() / 'scripts') +test_env.set('PYTHONIOENCODING', 'utf-8') + +backends = [ + 'dtrace', + 'ftrace', + 'log', + 'simple', + 'syslog', + 'ust' +] + +foreach backend: backends + test(backend, + python, + args: [meson.current_source_dir() / 'tracetool-test.py', + meson.project_source_root() / 'scripts' / 'tracetool.py', + 'trace-events', + backend], + workdir: meson.current_source_dir(), + suite: ['tracetool']) +endforeach
tests/tracetool/simple.c new file +61 -0
61 lines not on this page · raw message
tests/tracetool/simple.h new file +54 -0
54 lines not on this page · raw message
tests/tracetool/syslog.c new file +32 -0
@@ -0,0 +1,32 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "trace-testsuite.h" + +uint16_t _TRACE_TEST_BLAH_DSTATE; +uint16_t _TRACE_TEST_WIBBLE_DSTATE; +TraceEvent _TRACE_TEST_BLAH_EVENT = { + .id =0 , + .name ="test_blah" , + .sstate =TRACE_TEST_BLAH_ENABLED , + .dstate = &_TRACE_TEST_BLAH_DSTATE +}; +TraceEvent _TRACE_TEST_WIBBLE_EVENT = { + .id =0 , + .name ="test_wibble" , + .sstate =TRACE_TEST_WIBBLE_ENABLED , + .dstate = &_TRACE_TEST_WIBBLE_DSTATE +}; +TraceEvent *testsuite_trace_events[] = { + &_TRACE_TEST_BLAH_EVENT, + &_TRACE_TEST_WIBBLE_EVENT, +NULL , +}; + +static void trace_testsuite_register_events (void ) +{ +trace_event_register_group (testsuite_trace_events); +} +trace_init (trace_testsuite_register_events)
tests/tracetool/syslog.h new file +57 -0
57 lines not on this page · raw message
tests/tracetool/trace-events new file +5 -0
@@ -0,0 +1,5 @@ +# See docs/devel/tracing.rst for syntax documentation. +# SPDX-License-Identifier: GPL-2.0-or-later + +test_blah(void *context, const char *filename) "Blah context=%p filename=%s" +test_wibble(void *context, int value) "Wibble context=%p value=%d"
tests/tracetool/tracetool-test.py new file +91 -0
91 lines not on this page · raw message
tests/tracetool/ust.c new file +32 -0
@@ -0,0 +1,32 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "qemu/module.h" +#include "trace-testsuite.h" + +uint16_t _TRACE_TEST_BLAH_DSTATE; +uint16_t _TRACE_TEST_WIBBLE_DSTATE; +TraceEvent _TRACE_TEST_BLAH_EVENT = { + .id =0 , + .name ="test_blah" , + .sstate =TRACE_TEST_BLAH_ENABLED , + .dstate = &_TRACE_TEST_BLAH_DSTATE +}; +TraceEvent _TRACE_TEST_WIBBLE_EVENT = { + .id =0 , + .name ="test_wibble" , + .sstate =TRACE_TEST_WIBBLE_ENABLED , + .dstate = &_TRACE_TEST_WIBBLE_DSTATE +}; +TraceEvent *testsuite_trace_events[] = { + &_TRACE_TEST_BLAH_EVENT, + &_TRACE_TEST_WIBBLE_EVENT, +NULL , +}; + +static void trace_testsuite_register_events (void ) +{ +trace_event_register_group (testsuite_trace_events); +} +trace_init (trace_testsuite_register_events)
tests/tracetool/ust.h new file +55 -0
55 lines not on this page · raw message
tests/tracetool/ust.ust-events-c new file +14 -0
@@ -0,0 +1,14 @@ +/* This file is autogenerated by tracetool, do not edit. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" + +#define TRACEPOINT_DEFINE +#define TRACEPOINT_CREATE_PROBES + +/* If gcc version 4.7 or older is used, LTTng ust gives a warning when compiling with + -Wredundant-decls. + */ +#pragma GCC diagnostic ignored "-Wredundant-decls" + +#include "trace-ust-all.h"
tests/tracetool/ust.ust-events-h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH v3 5/8 tracetool: support "-" as a shorthand for stdout
In reply to Daniel P. BerrangéThis avoids callers needing to use the UNIX-only /dev/stdout workaround.
--- scripts/tracetool/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
scripts/tracetool/__init__.py +6 -2
@@ -38,8 +38,12 @@ def error(*lines): def out_open(filename): global out_filename, out_fobj - out_filename = posix_relpath(filename) - out_fobj = open(filename, 'wt') + if filename == "-": + out_filename = "[stdout]" + out_fobj = sys.stdout + else: + out_filename = posix_relpath(filename) + out_fobj = open(filename, 'wt') def out(*lines, **kwargs): """Write a set of output lines.
Signature · 1 line
2.50.1
PATCH v3 1/8 checkpatch: cull trailing '*/' in SPDX check
In reply to Daniel P. BerrangéSometimes SPDX expressions appear inside C comments, and this confuses checkpatch.pl. Drop the closing C comment characters to avoid this.
--- scripts/checkpatch.pl | 3 +++ 1 file changed, 3 insertions(+)
scripts/checkpatch.pl +3 -0
@@ -1368,6 +1368,9 @@ sub checkspdx { $expr =~ s/^\s*//g; $expr =~ s/\s*$//g; + # Cull C comment end + $expr =~ s/\*\/.*//; + my @bits = split / +/, $expr; my $prefer = "GPL-2.0-or-later";
Signature · 1 line
2.50.1
PATCH v3 2/8 tracetool: eliminate trailing whitespace in C format
In reply to Daniel P. Berrangé--- scripts/tracetool/format/c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/tracetool/format/c.py +1 -1
@@ -36,7 +36,7 @@ def generate(events, backend, group): ' .id = 0,', ' .name = \"%(name)s\",', ' .sstate = %(sstate)s,', - ' .dstate = &%(dstate)s ', + ' .dstate = &%(dstate)s', '};', event = e.api(e.QEMU_EVENT), name = e.name,
Signature · 1 line
2.50.1
Re: [PATCH v3 5/8] tracetool: support "-" as a shorthand for stdout
In reply to Daniel P. BerrangéQuoted 13 lines · Daniel P. Berrangé
This avoids callers needing to use the UNIX-only
/dev/stdoutworkaround.Signed-off-by Daniel P. Berrangé <[email protected]>--- scripts/tracetool/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/tracetool/__init__.py +0
-0
scripts/tracetool/__init__.py def error(*lines): · line 42
Quoted 7 lines
scripts/tracetool/__init__.py +2
-2@@ -38,8 +38,12 @@ def error(*lines): def out_open(filename): global out_filename, out_fobj - out_filename = posix_relpath(filename) - out_fobj = open(filename, 'wt') + if filename == "-": + out_filename = "[stdout]"
A few lines above:
out_filename = '<none>'
out_fobj = sys.stdout
Stick to '<none>' here for consistency?
scripts/tracetool/__init__.py def error(*lines): · line 45
Quoted 3 lines
scripts/tracetool/__init__.py +3
-0+ out_fobj = sys.stdout + else: + out_filename = posix_relpath(filename)
I have CCed Oleg in case he spots any portability issues, but I think this should still work on Windows.
Quoted 7 lines
scripts/tracetool/__init__.py +1
-0+ out_fobj = open(filename, 'wt') def out(*lines, **kwargs): """Write a set of output lines.Signature · 1 line
2.50.1
Quoted 89 lines · Daniel P. Berrangé
To repeat the start of the commit message in patch 5....
When reviewing tracetool patches it is often very unclear what the expected output will be for the generated backends. Compounding this is that a default build will only enable the 'log' trace backend, so developers won't see generated code for other backends without making a special effort. Some backends are also platform specific, so can't be enabled in QEMU builds, even though tracetool could generate the code.
To address this, introduce a test suite for tracetool which is conceptually similar to the qapi-schema test. It is a simple python program that runs tracetool and compares the actual output to historical reference output kept in git.
This was inspired by noticing the now pointless "
__nocheck__" method wrapping in the inline probe functions.Changed in v3:
- Also modify the QAPI schema test to use QEMU_TEST_REGENERATE=1 env & document / hint this
- Make tracetool accept '-' as shorthand for stdout to avoid relative paths in the reference outputChanged in v2:
- Add tracetool info to
docs/devel/testing.rstDaniel P. Berrangé (8):
checkpatch: cull trailing '*/' in SPDX check
tracetool: eliminate trailing whitespace in C format
tracetool: avoid space after "*" in arg types
tracetool: include SPDX-License-Identifier in generated files
tracetool: support "-" as a shorthand for stdout
tracetool: add test suite for tracetool with reference output
tracetool: drop the probe "__nocheck__" wrapping
qapi: switch to useQEMU_TEST_REGENERATEenv varMAINTAINERS | 1 + docs/devel/testing/main.rst | 40 +++++++++ scripts/checkpatch.pl | 3 + scripts/tracetool/__init__.py | 17 +++- scripts/tracetool/format/c.py | 3 +- scripts/tracetool/format/d.py | 3 +- scripts/tracetool/format/h.py | 17 +--- scripts/tracetool/format/log_stap.py | 1 + scripts/tracetool/format/simpletrace_stap.py | 1 + scripts/tracetool/format/stap.py | 1 + scripts/tracetool/format/ust_events_c.py | 1 + scripts/tracetool/format/ust_events_h.py | 1 + tests/Makefile.include | 1 + tests/meson.build | 1 + tests/qapi-schema/test-qapi.py | 7 +- tests/tracetool/dtrace.c | 32 +++++++ tests/tracetool/dtrace.d | 10 +++ tests/tracetool/dtrace.h | 45 ++++++++++ tests/tracetool/dtrace.log-stap | 15 ++++ tests/tracetool/dtrace.simpletrace-stap | 16 ++++ tests/tracetool/dtrace.stap | 14 +++ tests/tracetool/ftrace.c | 32 +++++++ tests/tracetool/ftrace.h | 59 +++++++++++++ tests/tracetool/log.c | 32 +++++++ tests/tracetool/log.h | 43 +++++++++ tests/tracetool/meson.build | 25 ++++++ tests/tracetool/simple.c | 61 +++++++++++++ tests/tracetool/simple.h | 40 +++++++++ tests/tracetool/syslog.c | 32 +++++++ tests/tracetool/syslog.h | 43 +++++++++ tests/tracetool/trace-events | 5 ++ tests/tracetool/tracetool-test.py | 91 ++++++++++++++++++++ tests/tracetool/ust.c | 32 +++++++ tests/tracetool/ust.h | 41 +++++++++ tests/tracetool/ust.ust-events-c | 14 +++ tests/tracetool/ust.ust-events-h | 56 ++++++++++++ 36 files changed, 813 insertions(+), 23 deletions(-) create mode 100644 tests/tracetool/dtrace.c create mode 100644 tests/tracetool/dtrace.d create mode 100644 tests/tracetool/dtrace.h create mode 100644 tests/tracetool/dtrace.log-stap create mode 100644 tests/tracetool/dtrace.simpletrace-stap create mode 100644 tests/tracetool/dtrace.stap create mode 100644 tests/tracetool/ftrace.c create mode 100644 tests/tracetool/ftrace.h create mode 100644 tests/tracetool/log.c create mode 100644 tests/tracetool/log.h create mode 100644 tests/tracetool/meson.build create mode 100644 tests/tracetool/simple.c create mode 100644 tests/tracetool/simple.h
Quoted 8 lines
create mode 100644 tests/tracetool/syslog.c create mode 100644 tests/tracetool/syslog.h create mode 100644 tests/tracetool/trace-events create mode 100755 tests/tracetool/tracetool-test.py create mode 100644 tests/tracetool/ust.c create mode 100644 tests/tracetool/ust.h create mode 100644 tests/tracetool/ust.ust-events-c create mode 100644 tests/tracetool/ust.ust-events-h
Aside from the stdout filename comment I posted:
Re: [PATCH v3 8/8] qapi: switch to use QEMU_TEST_REGENERATE env var
In reply to Daniel P. BerrangéQuoted 22 lines · Daniel P. Berrangé
The
QAPI_TEST_UPDATEenv var can be set when running the QAPI schema tests to regenerate the reference output. For consistent naming with the tracetool test, change the env var name toQEMU_TEST_REGENERATE.The test is modified to provide a hint about use of the new
env var and it is also added to the developer documentation.document its usage.Signed-off-by Daniel P. Berrangé <[email protected]>--- docs/devel/testing/main.rst | 12 ++++++++++++ tests/qapi-schema/test-qapi.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-)docs/devel/testing/main.rst +0
-0@@ -178,6 +178,18 @@ parser (either fixing a bug or extending/modifying the syntax). To do this: ``qapi-schema += foo.json``
docs/devel/testing/main.rst parser (either fixing a bug or extending/modifying the syntax). To do this: · line 190
Quoted 10 lines
docs/devel/testing/main.rst +10
-0+The reference output can be automatically updated to match the latest QAPI +code generator by running the tests with the QEMU_TEST_REGENERATE environment +variable set. + +.. code:: + + QEMU_TEST_REGENERATE=1 make check-qapi-schema + +The resulting changes must be reviewed by the author to ensure they match +the intended results, before adding the updated reference output to the
Not sure about the comma. I'm not a native speaker, though.
Quoted 10 lines
docs/devel/testing/main.rst +2
-0+same commit that alters the generator code. + .. _tracetool-tests: Tracetool teststests/qapi-schema/test-qapi.py +0
-0
tests/qapi-schema/test-qapi.py def test_and_diff(test_name, dir_name, update): · line 168
Quoted 5 lines
tests/qapi-schema/test-qapi.py +1
-1@@ -165,7 +165,7 @@ def test_and_diff(test_name, dir_name, update): if actual_out == expected_out and actual_err == expected_err: return 0 - print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'), + print("%s: %s" % (test_name, 'UPDATE' if update else 'FAIL'),
Is there a need for this, or is it just drive-by polishing?
Quoted 22 lines
tests/qapi-schema/test-qapi.py +4
-1file=sys.stderr) out_diff = difflib.unified_diff(expected_out, actual_out, outfp.name) err_diff = difflib.unified_diff(expected_err, actual_err, errfp.name)@@ -173,6 +173,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.writelines(err_diff) if not update: + print(("\n%s: set QEMU_TEST_REGENERATE=1 to recreate reference output" + + "if the QAPI schema generator was intentionally changed") % test_name, + file=sys.stderr) return 1 try:@@ -197,7 +200,7 @@ def main(argv): parser.add_argument('-d', '--dir', action='store', default='', help="directory containing tests") parser.add_argument('-u', '--update', action='store_true', - default='QAPI_TEST_UPDATE' in os.environ, + default='QEMU_TEST_REGENERATE' in os.environ, help="update expected test results") parser.add_argument('tests', nargs='*', metavar='TEST', action='store') args = parser.parse_args()
Re: [PATCH v3 5/8] tracetool: support "-" as a shorthand for stdout
In reply to Stefan HajnocziQuoted 24 lines · Stefan Hajnoczi
Quoted 13 lines · Daniel P. Berrangé
This avoids callers needing to use the UNIX-only
/dev/stdoutworkaround.Signed-off-by Daniel P. Berrangé <[email protected]>--- scripts/tracetool/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/tracetool/__init__.py +0
-0scripts/tracetool/__init__.py def error(*lines): · line 42
Quoted 7 lines
scripts/tracetool/__init__.py +2
-2@@ -38,8 +38,12 @@ def error(*lines): def out_open(filename): global out_filename, out_fobj - out_filename = posix_relpath(filename) - out_fobj = open(filename, 'wt') + if filename == "-": + out_filename = "[stdout]"A few lines above:
Quoted 4 lines
out_filename= '<none>'
out_fobj= sys.stdoutStick to '<none>' here for consistency?
Curious - that suggests that it was intended to be able to write to stdout by default, but tracetool.py unconditionally calls out_open() so those default assignments are effectively dead code, unless this internal code is called by something other than the tracetool.py main entrypoint ?
I guess I'd be inclined to change the global initialization to just be 'None' to make it explicit that out_open is expected to always be called ?
Quoted 6 lines
scripts/tracetool/__init__.py def error(*lines): · line 45
Quoted 3 lines
scripts/tracetool/__init__.py +3
-0+ out_fobj = sys.stdout + else: + out_filename = posix_relpath(filename)I have CCed Oleg in case he spots any portability issues, but I think this should still work on Windows.
This use of posix_relpath() was pre-existing, so there shouldn't be any new issues from this.
Quoted 5 lines
scripts/tracetool/__init__.py def error(*lines): · line 49
Quoted 5 lines
scripts/tracetool/__init__.py +1
-0+ out_fobj = open(filename, 'wt') def out(*lines, **kwargs): """Write a set of output lines.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 8/8] qapi: switch to use QEMU_TEST_REGENERATE env var
In reply to Markus ArmbrusterQuoted 24 lines · Markus Armbruster
Quoted 22 lines · Daniel P. Berrangé
The
QAPI_TEST_UPDATEenv var can be set when running the QAPI schema tests to regenerate the reference output. For consistent naming with the tracetool test, change the env var name toQEMU_TEST_REGENERATE.The test is modified to provide a hint about use of the new
env var and it is also added to the developer documentation.document its usage.Signed-off-by Daniel P. Berrangé <[email protected]>--- docs/devel/testing/main.rst | 12 ++++++++++++ tests/qapi-schema/test-qapi.py | 7 +++++-- 2 files changed, 17 insertions(+), 2 deletions(-)docs/devel/testing/main.rst +0
-0@@ -178,6 +178,18 @@ parser (either fixing a bug or extending/modifying the syntax). To do this: ``qapi-schema += foo.json``
Quoted 12 lines
docs/devel/testing/main.rst parser (either fixing a bug or extending/modifying the syntax). To do this: · line 190
Quoted 10 lines
docs/devel/testing/main.rst +10
-0+The reference output can be automatically updated to match the latest QAPI +code generator by running the tests with the QEMU_TEST_REGENERATE environment +variable set. + +.. code:: + + QEMU_TEST_REGENERATE=1 make check-qapi-schema + +The resulting changes must be reviewed by the author to ensure they match +the intended results, before adding the updated reference output to theNot sure about the comma. I'm not a native speaker, though.
Yeah, the comma is redundant
Quoted 13 lines
Quoted 13 lines
docs/devel/testing/main.rst +2
-0+same commit that alters the generator code. + .. _tracetool-tests: Tracetool teststests/qapi-schema/test-qapi.py +0
-0@@ -165,7 +165,7 @@ def test_and_diff(test_name, dir_name, update): if actual_out == expected_out and actual_err == expected_err: return 0
Quoted 4 lines
tests/qapi-schema/test-qapi.py def test_and_diff(test_name, dir_name, update): · line 168
Quoted 2 lines
tests/qapi-schema/test-qapi.py +1
-1- print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'), + print("%s: %s" % (test_name, 'UPDATE' if update else 'FAIL'),Is there a need for this, or is it just drive-by polishing?
Just making it more consistent in style with other error print() statements we have in the file, as well as this new one I'm adding.
Quoted 13 lines
Quoted 13 lines
tests/qapi-schema/test-qapi.py +3
-0file=sys.stderr) out_diff = difflib.unified_diff(expected_out, actual_out, outfp.name) err_diff = difflib.unified_diff(expected_err, actual_err, errfp.name)@@ -173,6 +173,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.writelines(err_diff) if not update: + print(("\n%s: set QEMU_TEST_REGENERATE=1 to recreate reference output" + + "if the QAPI schema generator was intentionally changed") % test_name, + file=sys.stderr) return 1
Quoted 11 lines
tests/qapi-schema/test-qapi.py def main(argv): · line 206
Quoted 10 lines
tests/qapi-schema/test-qapi.py +1
-1try:@@ -197,7 +200,7 @@ def main(argv): parser.add_argument('-d', '--dir', action='store', default='', help="directory containing tests") parser.add_argument('-u', '--update', action='store_true', - default='QAPI_TEST_UPDATE' in os.environ, + default='QEMU_TEST_REGENERATE' in os.environ, help="update expected test results") parser.add_argument('tests', nargs='*', metavar='TEST', action='store') args = parser.parse_args()
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 5/8] tracetool: support "-" as a shorthand for stdout
In reply to Daniel P. BerrangéQuoted 36 lines · Daniel P. Berrangé
Quoted 24 lines · Stefan Hajnoczi
Quoted 13 lines · Daniel P. Berrangé
This avoids callers needing to use the UNIX-only
/dev/stdoutworkaround.Signed-off-by Daniel P. Berrangé <[email protected]>--- scripts/tracetool/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/tracetool/__init__.py +0
-0scripts/tracetool/__init__.py def error(*lines): · line 42
Quoted 7 lines
scripts/tracetool/__init__.py +2
-2@@ -38,8 +38,12 @@ def error(*lines): def out_open(filename): global out_filename, out_fobj - out_filename = posix_relpath(filename) - out_fobj = open(filename, 'wt') + if filename == "-": + out_filename = "[stdout]"A few lines above:
Quoted 4 lines
out_filename= '<none>'
out_fobj= sys.stdoutStick to '<none>' here for consistency?
Curious - that suggests that it was intended to be able to write to stdout by default, but
tracetool.pyunconditionally callsout_open()so those default assignments are effectively dead code, unless this internal code is called by something other than thetracetool.pymain entrypoint ?
Quoted 3 lines
I guess I'd be inclined to change the global initialization to just be 'None' to make it explicit that
out_openis expected to always be called ?
Originally the script wrote to stdout, but I added an explicit output filename argument in commit c05012a365c2 ("tracetool: add output filename command-line argument") because #line directives emitted by tracetool need to know the output filename.
Your next patch tests/tracetool/tracetool-test.py uses "-" as the output filename but leaves the existing meson.build files unchanged. They will still specify an output filename.
This commit doesn't break anything, at least not in how this patch series uses "-", but I see a contradiction with commit c05012a365c2 since we're now allowing the output filename to be effectively empty.
Could you avoid special casing stdout and instead pass a relative path to the output file? The relative path is important so the test reference output is portable across machines. Then you don't need this commit.
Stefan
Quoted 25 lines
Quoted 7 lines
scripts/tracetool/__init__.py def error(*lines): · line 45
Quoted 4 lines
scripts/tracetool/__init__.py +3
-0+ out_fobj = sys.stdout + else: + out_filename = posix_relpath(filename)I have CCed Oleg in case he spots any portability issues, but I think this should still work on Windows.
This use of
posix_relpath()was pre-existing, so there shouldn't be any new issues from this.Quoted 5 lines
scripts/tracetool/__init__.py def error(*lines): · line 49
Quoted 5 lines
scripts/tracetool/__init__.py +1
-0+ out_fobj = open(filename, 'wt') def out(*lines, **kwargs): """Write a set of output lines.With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 5/8] tracetool: support "-" as a shorthand for stdout
Quoted 50 lines · Stefan Hajnoczi
Quoted 36 lines · Daniel P. Berrangé
Quoted 24 lines · Stefan Hajnoczi
Quoted 13 lines · Daniel P. Berrangé
This avoids callers needing to use the UNIX-only
/dev/stdoutworkaround.Signed-off-by Daniel P. Berrangé <[email protected]>--- scripts/tracetool/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)scripts/tracetool/__init__.py +0
-0scripts/tracetool/__init__.py def error(*lines): · line 42
Quoted 7 lines
scripts/tracetool/__init__.py +2
-2@@ -38,8 +38,12 @@ def error(*lines): def out_open(filename): global out_filename, out_fobj - out_filename = posix_relpath(filename) - out_fobj = open(filename, 'wt') + if filename == "-": + out_filename = "[stdout]"A few lines above:
Quoted 4 lines
out_filename= '<none>'
out_fobj= sys.stdoutStick to '<none>' here for consistency?
Curious - that suggests that it was intended to be able to write to stdout by default, but
tracetool.pyunconditionally callsout_open()so those default assignments are effectively dead code, unless this internal code is called by something other than thetracetool.pymain entrypoint ?Quoted 3 lines
I guess I'd be inclined to change the global initialization to just be 'None' to make it explicit that
out_openis expected to always be called ?Originally the script wrote to stdout, but I added an explicit output filename argument in commit
c05012a365c2("tracetool: add output filename command-line argument") because #line directives emitted by tracetool need to know the output filename.Your next patch
tests/tracetool/tracetool-test.pyuses "-" as the output filename but leaves the existing meson.build files unchanged. They will still specify an output filename.
Quoted 7 lines
This commit doesn't break anything, at least not in how this patch series uses "-", but I see a contradiction with commit
c05012a365c2since we're now allowing the output filename to be effectively empty.Could you avoid special casing stdout and instead pass a relative path to the output file? The relative path is important so the test reference output is portable across machines. Then you don't need this commit.
If I copy the 'trace-events' file into the build-dir, then I can rely on relative files for both the input & output, and avoid need to support '-'.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v3 8/8] qapi: switch to use QEMU_TEST_REGENERATE env var
In reply to Daniel P. BerrangéQuoted 12 lines · Daniel P. Berrangé
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Daniel P. Berrangé
The
QAPI_TEST_UPDATEenv var can be set when running the QAPI schema tests to regenerate the reference output. For consistent naming with the tracetool test, change the env var name toQEMU_TEST_REGENERATE.The test is modified to provide a hint about use of the new
env var and it is also added to the developer documentation.document its usage.Signed-off-by Daniel P. Berrangé <[email protected]>
[...]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
index
4be930228c..cf7fb8a6df100755tests/qapi-schema/test-qapi.py +0
-0@@ -165,7 +165,7 @@ def test_and_diff(test_name, dir_name, update): if actual_out == expected_out and actual_err == expected_err: return 0
Quoted 8 lines
Quoted 4 lines
tests/qapi-schema/test-qapi.py def test_and_diff(test_name, dir_name, update): · line 168
Quoted 2 lines
tests/qapi-schema/test-qapi.py +1
-1- print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'), + print("%s: %s" % (test_name, 'UPDATE' if update else 'FAIL'),Is there a need for this, or is it just drive-by polishing?
Just making it more consistent in style with other error
print()statements we have in the file, as well as this new one I'm adding.
Which existing print()s do you mean?
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
tests/qapi-schema/test-qapi.py +4
-1file=sys.stderr) out_diff = difflib.unified_diff(expected_out, actual_out, outfp.name) err_diff = difflib.unified_diff(expected_err, actual_err, errfp.name)@@ -173,6 +173,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.writelines(err_diff) if not update: + print(("\n%s: set QEMU_TEST_REGENERATE=1 to recreate reference output" + + "if the QAPI schema generator was intentionally changed") % test_name, + file=sys.stderr) return 1 try:@@ -197,7 +200,7 @@ def main(argv): parser.add_argument('-d', '--dir', action='store', default='', help="directory containing tests") parser.add_argument('-u', '--update', action='store_true', - default='QAPI_TEST_UPDATE' in os.environ, + default='QEMU_TEST_REGENERATE' in os.environ, help="update expected test results") parser.add_argument('tests', nargs='*', metavar='TEST', action='store') args = parser.parse_args()
Re: [PATCH v3 8/8] qapi: switch to use QEMU_TEST_REGENERATE env var
Quoted 29 lines · Markus Armbruster
Quoted 12 lines · Daniel P. Berrangé
Quoted 11 lines · Markus Armbruster
Quoted 9 lines · Daniel P. Berrangé
The
QAPI_TEST_UPDATEenv var can be set when running the QAPI schema tests to regenerate the reference output. For consistent naming with the tracetool test, change the env var name toQEMU_TEST_REGENERATE.The test is modified to provide a hint about use of the new
env var and it is also added to the developer documentation.document its usage.Signed-off-by Daniel P. Berrangé <[email protected]>[...]
Quoted 12 lines
Quoted 11 lines
tests/qapi-schema/test-qapi.py def test_and_diff(test_name, dir_name, update): · line 168
Quoted 9 lines
index
4be930228c..cf7fb8a6df100755tests/qapi-schema/test-qapi.py +1
-1@@ -165,7 +165,7 @@ def test_and_diff(test_name, dir_name, update): if actual_out == expected_out and actual_err == expected_err: return 0 - print("%s %s" % (test_name, 'UPDATE' if update else 'FAIL'), + print("%s: %s" % (test_name, 'UPDATE' if update else 'FAIL'),Is there a need for this, or is it just drive-by polishing?
Quoted 5 lines
Quoted 3 lines
Just making it more consistent in style with other error
print()statements we have in the file, as well as this new one I'm adding.Which existing print()s do you mean?
I was referring to the ones in this method
except OSError as err:
print("%s: can't open '%s': %s"
% (sys.argv[0], err.filename, err.strerror),
file=sys.stderr)
return 2..
except OSError as err:
print("%s: can't write '%s': %s"
% (sys.argv[0], err.filename, err.strerror),
file=sys.stderr)though I notice now they are using 'sys.argv[0]' which is not the same as 'test_name', as well as using stderr. So the consistency isn't actually helped
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
file=sys.stderr)
out_diff=difflib.unified_diff(expected_out, actual_out, outfp.name)err_diff=difflib.unified_diff(expected_err, actual_err, errfp.name)tests/qapi-schema/test-qapi.py +3
-0@@ -173,6 +173,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.writelines(err_diff) if not update: + print(("\n%s: set QEMU_TEST_REGENERATE=1 to recreate reference output" + + "if the QAPI schema generator was intentionally changed") % test_name, + file=sys.stderr) return 1
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
tests/qapi-schema/test-qapi.py def main(argv): · line 206
Quoted 10 lines
tests/qapi-schema/test-qapi.py +1
-1try:@@ -197,7 +200,7 @@ def main(argv): parser.add_argument('-d', '--dir', action='store', default='', help="directory containing tests") parser.add_argument('-u', '--update', action='store_true', - default='QAPI_TEST_UPDATE' in os.environ, + default='QEMU_TEST_REGENERATE' in os.environ, help="update expected test results") parser.add_argument('tests', nargs='*', metavar='TEST', action='store') args = parser.parse_args()
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|