From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] tests: add test for json-streamer.c error recovery
Date: Thu, 23 Apr 2026 08:55:54 +0200 [thread overview]
Message-ID: <87cxzqrwqt.fsf@pond.sub.org> (raw)
In-Reply-To: <20260331095950.512326-1-pbonzini@redhat.com> (Paolo Bonzini's message of "Tue, 31 Mar 2026 11:59:50 +0200")
One more thing...
Paolo Bonzini <pbonzini@redhat.com> writes:
> Before rewriting the error recovery code to work in a push parsing
> setup, make sure that we have tests for it.
>
> Cover various cases of invalid JSON, to check that structural
> recovery based on balanced brackets and braces works; and
> lexer-based recovery which documents "\f" as a sure fire
> way to reset the lexer.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/unit/check-json-parser.c | 145 +++++++++++++++++++++++++++++++++
> tests/unit/meson.build | 1 +
> 2 files changed, 146 insertions(+)
> create mode 100644 tests/unit/check-json-parser.c
>
> diff --git a/tests/unit/check-json-parser.c b/tests/unit/check-json-parser.c
> new file mode 100644
> index 00000000000..ca2d5f41097
> --- /dev/null
> +++ b/tests/unit/check-json-parser.c
> @@ -0,0 +1,145 @@
> +/*
> + * Unit tests for JSON Parser error recovery
> + *
> + * Copyright 2026 Red Hat
> + * Author: Paolo Bonzini <pbonzini@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +
> +#include "qapi/error.h"
> +#include "qobject/qbool.h"
> +#include "qobject/json-parser.h"
> +
> +typedef struct ParseResult {
> + int errors;
> + QObject *result;
> +} ParseResult;
> +
> +static void parse_emit(void *opaque, QObject *json, Error *err)
> +{
> + ParseResult *r = opaque;
> +
> + if (err) {
> + r->errors++;
> + error_free(err);
> + } else {
> + qobject_unref(r->result);
Unexpected calls to parse_emit() won't be detected as long as the last
one yields the expected expression. Worth detecting? I'm not quite
sure. As far as I can tell, this is not reached at the moment.
The stupidest way to detect is to assert r->result is still null.
Can't do that if we want to cover parsing multiple JSON expressions in
sequence. Collect all the results in an array?
Leave for later, with a short comment?
Up to you.
> + r->result = json;
> + }
> +}
[...]
next prev parent reply other threads:[~2026-04-23 6:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 9:59 [PATCH] tests: add test for json-streamer.c error recovery Paolo Bonzini
2026-04-20 11:53 ` Markus Armbruster
2026-04-20 12:00 ` Paolo Bonzini
2026-04-21 11:18 ` Markus Armbruster
2026-04-21 11:29 ` Markus Armbruster
2026-04-21 22:39 ` Paolo Bonzini
2026-04-23 6:57 ` Markus Armbruster
2026-04-23 6:55 ` Markus Armbruster [this message]
2026-04-23 16:24 ` Paolo Bonzini
2026-04-23 17:30 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cxzqrwqt.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.