* [Qemu-devel] [PATCH] test-qobject-input-visitor: Cover visit_type_uint64()
@ 2017-03-21 17:44 Markus Armbruster
2017-03-21 18:11 ` Eric Blake
0 siblings, 1 reply; 2+ messages in thread
From: Markus Armbruster @ 2017-03-21 17:44 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, eblake, mdroth
The new test demonstrates known bugs: integers between INT64_MAX+1 and
UINT64_MAX rejected, and integers between INT64_MIN and -1 are
accepted modulo 2^64.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
tests/test-qobject-input-visitor.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
index 6eb48fe..f965743 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -116,6 +116,34 @@ static void test_visitor_in_int(TestInputVisitorData *data,
g_assert_cmpint(res, ==, value);
}
+static void test_visitor_in_uint(TestInputVisitorData *data,
+ const void *unused)
+{
+ Error *err = NULL;
+ uint64_t res = 0;
+ int value = 42;
+ Visitor *v;
+
+ v = visitor_input_test_init(data, "%d", value);
+
+ visit_type_uint64(v, NULL, &res, &error_abort);
+ g_assert_cmpuint(res, ==, (uint64_t)value);
+
+ /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */
+
+ v = visitor_input_test_init(data, "%d", -value);
+
+ visit_type_uint64(v, NULL, &res, &error_abort);
+ g_assert_cmpuint(res, ==, (uint64_t)-value);
+
+ /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */
+
+ v = visitor_input_test_init(data, "18446744073709551574");
+
+ visit_type_uint64(v, NULL, &res, &err);
+ error_free_or_abort(&err);
+}
+
static void test_visitor_in_int_overflow(TestInputVisitorData *data,
const void *unused)
{
@@ -1225,6 +1253,8 @@ int main(int argc, char **argv)
input_visitor_test_add("/visitor/input/int",
NULL, test_visitor_in_int);
+ input_visitor_test_add("/visitor/input/uint",
+ NULL, test_visitor_in_uint);
input_visitor_test_add("/visitor/input/int_overflow",
NULL, test_visitor_in_int_overflow);
input_visitor_test_add("/visitor/input/int_keyval",
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] test-qobject-input-visitor: Cover visit_type_uint64()
2017-03-21 17:44 [Qemu-devel] [PATCH] test-qobject-input-visitor: Cover visit_type_uint64() Markus Armbruster
@ 2017-03-21 18:11 ` Eric Blake
0 siblings, 0 replies; 2+ messages in thread
From: Eric Blake @ 2017-03-21 18:11 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: marcandre.lureau, mdroth
[-- Attachment #1: Type: text/plain, Size: 2185 bytes --]
On 03/21/2017 12:44 PM, Markus Armbruster wrote:
> The new test demonstrates known bugs: integers between INT64_MAX+1 and
> UINT64_MAX rejected, and integers between INT64_MIN and -1 are
> accepted modulo 2^64.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> tests/test-qobject-input-visitor.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/tests/test-qobject-input-visitor.c b/tests/test-qobject-input-visitor.c
> index 6eb48fe..f965743 100644
> --- a/tests/test-qobject-input-visitor.c
> +++ b/tests/test-qobject-input-visitor.c
> @@ -116,6 +116,34 @@ static void test_visitor_in_int(TestInputVisitorData *data,
> g_assert_cmpint(res, ==, value);
> }
>
> +static void test_visitor_in_uint(TestInputVisitorData *data,
> + const void *unused)
> +{
> + Error *err = NULL;
> + uint64_t res = 0;
> + int value = 42;
> + Visitor *v;
> +
> + v = visitor_input_test_init(data, "%d", value);
Another place where I have to rebase my work that gets rid of the
dynamic JSON parser, if we want to revive that patch series; but don't
let it stop you on this patch.
> +
> + visit_type_uint64(v, NULL, &res, &error_abort);
> + g_assert_cmpuint(res, ==, (uint64_t)value);
> +
> + /* BUG: value between INT64_MIN and -1 accepted modulo 2^64 */
> +
> + v = visitor_input_test_init(data, "%d", -value);
Not necessarily a bug - libvirt exploits this behavior. So even if we
fix the real bug, namely...
> +
> + visit_type_uint64(v, NULL, &res, &error_abort);
> + g_assert_cmpuint(res, ==, (uint64_t)-value);
> +
> + /* BUG: value between INT64_MAX+1 and UINT64_MAX rejected */
> +
> + v = visitor_input_test_init(data, "18446744073709551574");
...this, we may be stuck keeping the modulo 2^64 parsing around for
back-compat.
At any rate, your test is a welcome addition; and as it only touches the
testsuite, it is still 2.9 material if desired.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-21 18:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-21 17:44 [Qemu-devel] [PATCH] test-qobject-input-visitor: Cover visit_type_uint64() Markus Armbruster
2017-03-21 18:11 ` Eric Blake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).