* [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
@ 2013-05-10 22:45 Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 01/11] qapi: qapi-types.py, native list support Michael Roth
` (13 more replies)
0 siblings, 14 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:45 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
These patches apply on top of qemu.git master, and can also be obtained from:
git://github.com/mdroth/qemu.git qapi-native-lists
Sending this now since a number of series have popped up in the past that
wanted this, and Amos has some pending patches (query-mac-tables) that rely
on this as well.
These patches add support for specifying lists of native qapi types
(int/bool/str/number/int8/uint8/etc) like so:
{ 'type': 'foo',
'data': { 'bar': ['int'] }}
for a 'bar' field that is a list of type 'int',
{ 'type': 'foo2',
'data': { 'bar2': ['str'] }}
for a 'bar2' field that is a list of type 'str', and so on.
This uses linked list types for the native C representations, just as we do
for complex schema-defined types. In the future we may add schema annotations
of some sort to specify a more natural/efficient array type for the C
representations, but this should serve the majority of uses-cases for now.
v2->v3:
* added native list support for fixed-width integer types (Amos)
* added fixed-width integer list coverage to serialization,
QMPOutputVisitor, and QmpInputVisitor unit tests
* added unit test to QmpInputVisitor to test new overflow handling when
integers types are expected (Eric)
* clarified terminology/documentation in json parser fix (Laszlo)
* fixed whitespace/newlines in code generator output (Luiz)
v1->v2:
* fixed do-nothing float tests in pre-existing code and updated new
unit tests accordingly (Laszlo)
* added a fix for a bug in json parser that was exposed by above change
* fixed misuse of string format parameters for float testing (Laszlo)
* fixed extra characters in comment (Laszlo)
* removed unused variant from UserDefNativeListUnion QAPI type
Makefile | 6 +-
qapi-schema-test.json | 15 ++
qobject/json-parser.c | 26 +-
scripts/qapi-types.py | 45 +++-
scripts/qapi-visit.py | 36 ++-
scripts/qapi.py | 23 ++
tests/test-qmp-input-visitor.c | 358 ++++++++++++++++++++++++++
tests/test-qmp-output-visitor.c | 332 ++++++++++++++++++++++++
tests/test-visitor-serialization.c | 485 +++++++++++++++++++++++++++++++++---
9 files changed, 1274 insertions(+), 52 deletions(-)
^ permalink raw reply [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 01/11] qapi: qapi-types.py, native list support
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 02/11] qapi: qapi-visit.py, fix list handling for union types Michael Roth
` (12 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Teach type generators about native types so they can generate the
appropriate linked list types.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
scripts/qapi-types.py | 45 ++++++++++++++++++++++++++++++++++++++++++---
scripts/qapi.py | 23 +++++++++++++++++++++++
2 files changed, 65 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9e19920..fd42d71 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -16,8 +16,21 @@ import os
import getopt
import errno
-def generate_fwd_struct(name, members):
+def generate_fwd_struct(name, members, builtin_type=False):
+ if builtin_type:
+ return mcgen('''
+
+typedef struct %(name)sList
+{
+ %(type)s value;
+ struct %(name)sList *next;
+} %(name)sList;
+''',
+ type=c_type(name),
+ name=name)
+
return mcgen('''
+
typedef struct %(name)s %(name)s;
typedef struct %(name)sList
@@ -164,6 +177,7 @@ void qapi_free_%(type)s(%(c_type)s obj);
def generate_type_cleanup(name):
ret = mcgen('''
+
void qapi_free_%(type)s(%(c_type)s obj)
{
QapiDeallocVisitor *md;
@@ -184,8 +198,9 @@ void qapi_free_%(type)s(%(c_type)s obj)
try:
- opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
- ["source", "header", "prefix=", "output-dir="])
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
+ ["source", "header", "builtins",
+ "prefix=", "output-dir="])
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
@@ -197,6 +212,7 @@ h_file = 'qapi-types.h'
do_c = False
do_h = False
+do_builtins = False
for o, a in opts:
if o in ("-p", "--prefix"):
@@ -207,6 +223,8 @@ for o, a in opts:
do_c = True
elif o in ("-h", "--header"):
do_h = True
+ elif o in ("-b", "--builtins"):
+ do_builtins = True
if not do_c and not do_h:
do_c = True
@@ -282,6 +300,11 @@ fdecl.write(mcgen('''
exprs = parse_schema(sys.stdin)
exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
+fdecl.write(guardstart("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
+for typename in builtin_types:
+ fdecl.write(generate_fwd_struct(typename, None, builtin_type=True))
+fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
+
for expr in exprs:
ret = "\n"
if expr.has_key('type'):
@@ -298,6 +321,22 @@ for expr in exprs:
continue
fdecl.write(ret)
+# to avoid header dependency hell, we always generate declarations
+# for built-in types in our header files and simply guard them
+fdecl.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DECL"))
+for typename in builtin_types:
+ fdecl.write(generate_type_cleanup_decl(typename + "List"))
+fdecl.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DECL"))
+
+# ...this doesn't work for cases where we link in multiple objects that
+# have the functions defined, so we use -b option to provide control
+# over these cases
+if do_builtins:
+ fdef.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
+ for typename in builtin_types:
+ fdef.write(generate_type_cleanup(typename + "List"))
+ fdef.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
+
for expr in exprs:
ret = "\n"
if expr.has_key('type'):
diff --git a/scripts/qapi.py b/scripts/qapi.py
index afc5f32..02ad668 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -11,6 +11,12 @@
from ordereddict import OrderedDict
+builtin_types = [
+ 'str', 'int', 'number', 'bool',
+ 'int8', 'int16', 'int32', 'int64',
+ 'uint8', 'uint16', 'uint32', 'uint64'
+]
+
def tokenize(data):
while len(data):
ch = data[0]
@@ -242,3 +248,20 @@ def guardname(filename):
for substr in [".", " ", "-"]:
guard = guard.replace(substr, "_")
return guard.upper() + '_H'
+
+def guardstart(name):
+ return mcgen('''
+
+#ifndef %(name)s
+#define %(name)s
+
+''',
+ name=guardname(name))
+
+def guardend(name):
+ return mcgen('''
+
+#endif /* %(name)s */
+
+''',
+ name=guardname(name))
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 02/11] qapi: qapi-visit.py, fix list handling for union types
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 01/11] qapi: qapi-types.py, native list support Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 03/11] qapi: qapi-visit.py, native list support Michael Roth
` (11 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Currently we assume non-list types when generating visitor routines for
union types. This is broken, since values like ['Type'] need to mapped
to 'TypeList'.
We already have a type_name() function to handle this that we use for
generating struct visitors, so use that here as well.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
scripts/qapi-visit.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a276540..4c4de4b 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -174,7 +174,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
''',
abbrev = de_camel_case(name).upper(),
enum = c_fun(de_camel_case(key),False).upper(),
- c_type=members[key],
+ c_type=type_name(members[key]),
c_name=c_fun(key))
ret += mcgen('''
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 03/11] qapi: qapi-visit.py, native list support
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 01/11] qapi: qapi-types.py, native list support Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 02/11] qapi: qapi-visit.py, fix list handling for union types Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 04/11] qapi: enable generation of native list code Michael Roth
` (10 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Teach visitor generators about native types so they can generate the
appropriate visitor routines.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
scripts/qapi-visit.py | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 4c4de4b..6cac05a 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -202,12 +202,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
return ret
-def generate_declaration(name, members, genlist=True):
- ret = mcgen('''
+def generate_declaration(name, members, genlist=True, builtin_type=False):
+ ret = ""
+ if not builtin_type:
+ ret += mcgen('''
void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
''',
- name=name)
+ name=name)
if genlist:
ret += mcgen('''
@@ -235,8 +237,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **e
name=name)
try:
- opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
- ["source", "header", "prefix=", "output-dir="])
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
+ ["source", "header", "builtins", "prefix=",
+ "output-dir="])
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
@@ -248,6 +251,7 @@ h_file = 'qapi-visit.h'
do_c = False
do_h = False
+do_builtins = False
for o, a in opts:
if o in ("-p", "--prefix"):
@@ -258,6 +262,8 @@ for o, a in opts:
do_c = True
elif o in ("-h", "--header"):
do_h = True
+ elif o in ("-b", "--builtins"):
+ do_builtins = True
if not do_c and not do_h:
do_c = True
@@ -324,11 +330,29 @@ fdecl.write(mcgen('''
#include "qapi/visitor.h"
#include "%(prefix)sqapi-types.h"
+
''',
prefix=prefix, guard=guardname(h_file)))
exprs = parse_schema(sys.stdin)
+# to avoid header dependency hell, we always generate declarations
+# for built-in types in our header files and simply guard them
+fdecl.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
+for typename in builtin_types:
+ fdecl.write(generate_declaration(typename, None, genlist=True,
+ builtin_type=True))
+fdecl.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
+
+# ...this doesn't work for cases where we link in multiple objects that
+# have the functions defined, so we use -b option to provide control
+# over these cases
+if do_builtins:
+ fdef.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
+ for typename in builtin_types:
+ fdef.write(generate_visit_list(typename, None))
+ fdef.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
+
for expr in exprs:
if expr.has_key('type'):
ret = generate_visit_struct(expr['type'], expr['data'])
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 04/11] qapi: enable generation of native list code
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (2 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 03/11] qapi: qapi-visit.py, native list support Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 05/11] qapi: fix leak in unit tests Michael Roth
` (9 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Also, fix a dependency issue with libqemuutil: qemu-sockets.c needs
qapi-types.c/qapi-visit.c
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 7dc0204..9695c9d 100644
--- a/Makefile
+++ b/Makefile
@@ -178,7 +178,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
# Build libraries
libqemustub.a: $(stub-obj-y)
-libqemuutil.a: $(util-obj-y)
+libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
######################################################################
@@ -215,10 +215,10 @@ $(SRC_PATH)/qga/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
qapi-types.c qapi-types.h :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
- $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "." < $<, " GEN $@")
+ $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py $(gen-out-type) -o "." -b < $<, " GEN $@")
qapi-visit.c qapi-visit.h :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
- $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "." < $<, " GEN $@")
+ $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py $(gen-out-type) -o "." -b < $<, " GEN $@")
qmp-commands.h qmp-marshal.c :\
$(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py $(gen-out-type) -m -o "." < $<, " GEN $@")
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 05/11] qapi: fix leak in unit tests
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (3 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 04/11] qapi: enable generation of native list code Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 06/11] json-parser: fix handling of large whole number values Michael Roth
` (8 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
qmp_output_get_qobject() increments the qobject's reference count. Since
we currently pass this straight into qobject_to_json() so we can feed
the data into a QMP input visitor, we never actually free the underlying
qobject when qmp_output_visitor_cleanup() is called. This causes leaks
on all of the QMP serialization tests.
Fix this by holding a pointer to the qobject and decref'ing it before
returning from qmp_deserialize().
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
tests/test-visitor-serialization.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index e84926f..8c8adac 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -657,11 +657,16 @@ static void qmp_deserialize(void **native_out, void *datap,
VisitorFunc visit, Error **errp)
{
QmpSerializeData *d = datap;
- QString *output_json = qobject_to_json(qmp_output_get_qobject(d->qov));
- QObject *obj = qobject_from_json(qstring_get_str(output_json));
+ QString *output_json;
+ QObject *obj_orig, *obj;
+
+ obj_orig = qmp_output_get_qobject(d->qov);
+ output_json = qobject_to_json(obj_orig);
+ obj = qobject_from_json(qstring_get_str(output_json));
QDECREF(output_json);
d->qiv = qmp_input_visitor_new(obj);
+ qobject_decref(obj_orig);
qobject_decref(obj);
visit(qmp_input_get_visitor(d->qiv), native_out, errp);
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 06/11] json-parser: fix handling of large whole number values
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (4 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 05/11] qapi: fix leak in unit tests Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 07/11] qapi: add QMP input test for large integers Michael Roth
` (7 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Currently our JSON parser assumes that numbers lacking a fractional
value are integers and attempts to store them as QInt/int64 values. This
breaks in the case where the number overflows/underflows int64 values (which
is still valid JSON)
Fix this by detecting such cases and using a QFloat to store the value
instead.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
qobject/json-parser.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 05279c1..e7947b3 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -640,9 +640,29 @@ static QObject *parse_literal(JSONParserContext *ctxt)
case JSON_STRING:
obj = QOBJECT(qstring_from_escaped_str(ctxt, token));
break;
- case JSON_INTEGER:
- obj = QOBJECT(qint_from_int(strtoll(token_get_value(token), NULL, 10)));
- break;
+ case JSON_INTEGER: {
+ /* A possibility exists that this is a whole-valued float where the
+ * fractional part was left out due to being 0 (.0). It's not a big
+ * deal to treat these as ints in the parser, so long as users of the
+ * resulting QObject know to expect a QInt in place of a QFloat in
+ * cases like these.
+ *
+ * However, in some cases these values will overflow/underflow a
+ * QInt/int64 container, thus we should assume these are to be handled
+ * as QFloats/doubles rather than silently changing their values.
+ *
+ * strtoll() indicates these instances by setting errno to ERANGE
+ */
+ int64_t value;
+
+ errno = 0; /* strtoll doesn't set errno on success */
+ value = strtoll(token_get_value(token), NULL, 10);
+ if (errno != ERANGE) {
+ obj = QOBJECT(qint_from_int(value));
+ break;
+ }
+ /* fall through to JSON_FLOAT */
+ }
case JSON_FLOAT:
/* FIXME dependent on locale */
obj = QOBJECT(qfloat_from_double(strtod(token_get_value(token), NULL)));
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 07/11] qapi: add QMP input test for large integers
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (5 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 06/11] json-parser: fix handling of large whole number values Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 08/11] qapi: fix visitor serialization tests for numbers/doubles Michael Roth
` (6 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Large integers previously got capped to LLONG_MAX/LLONG_MIN so we could
store them as int64_t. This could lead to silent errors occuring.
Now, we use a double to handle these cases.
Add a test to confirm that QMPInputVisitor handles this as expected if
we're expected an integer value: errors for out of range integer values
that got promoted to doubles in this fashion.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
tests/test-qmp-input-visitor.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c
index 955a4c0..b308cf9 100644
--- a/tests/test-qmp-input-visitor.c
+++ b/tests/test-qmp-input-visitor.c
@@ -75,6 +75,24 @@ static void test_visitor_in_int(TestInputVisitorData *data,
g_assert_cmpint(res, ==, value);
}
+static void test_visitor_in_int_overflow(TestInputVisitorData *data,
+ const void *unused)
+{
+ int64_t res = 0;
+ Error *errp = NULL;
+ Visitor *v;
+
+ /* this will overflow a Qint/int64, so should be deserialized into
+ * a QFloat/double field instead, leading to an error if we pass it
+ * to visit_type_int. confirm this.
+ */
+ v = visitor_input_test_init(data, "%f", DBL_MAX);
+
+ visit_type_int(v, &res, NULL, &errp);
+ g_assert(error_is_set(&errp));
+ error_free(errp);
+}
+
static void test_visitor_in_bool(TestInputVisitorData *data,
const void *unused)
{
@@ -292,6 +310,8 @@ int main(int argc, char **argv)
input_visitor_test_add("/visitor/input/int",
&in_visitor_data, test_visitor_in_int);
+ input_visitor_test_add("/visitor/input/int_overflow",
+ &in_visitor_data, test_visitor_in_int_overflow);
input_visitor_test_add("/visitor/input/bool",
&in_visitor_data, test_visitor_in_bool);
input_visitor_test_add("/visitor/input/number",
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 08/11] qapi: fix visitor serialization tests for numbers/doubles
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (6 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 07/11] qapi: add QMP input test for large integers Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 09/11] qapi: add native list coverage for visitor serialization tests Michael Roth
` (5 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
We never actually stored the stringified double values into the strings
before we did the comparisons. This left number/double values completely
uncovered in test-visitor-serialization tests.
Fixing this exposed a bug in our handling of large whole number values
in QEMU's JSON parser which is now fixed.
Simplify the code while we're at it by dropping the
calc_float_string_storage() craziness in favor of GStrings.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
tests/test-visitor-serialization.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index 8c8adac..fed6810 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -229,17 +229,6 @@ typedef struct TestArgs {
void *test_data;
} TestArgs;
-#define FLOAT_STRING_PRECISION 6 /* corresponding to n in %.nf formatting */
-static gsize calc_float_string_storage(double value)
-{
- int whole_value = value;
- gsize i = 0;
- do {
- i++;
- } while (whole_value /= 10);
- return i + 2 + FLOAT_STRING_PRECISION;
-}
-
static void test_primitives(gconstpointer opaque)
{
TestArgs *args = (TestArgs *) opaque;
@@ -248,7 +237,6 @@ static void test_primitives(gconstpointer opaque)
PrimitiveType *pt_copy = g_malloc0(sizeof(*pt_copy));
Error *err = NULL;
void *serialize_data;
- char *double1, *double2;
pt_copy->type = pt->type;
ops->serialize(pt, &serialize_data, visit_primitive_type, &err);
@@ -260,14 +248,17 @@ static void test_primitives(gconstpointer opaque)
g_assert_cmpstr(pt->value.string, ==, pt_copy->value.string);
g_free((char *)pt_copy->value.string);
} else if (pt->type == PTYPE_NUMBER) {
+ GString *double_expected = g_string_new("");
+ GString *double_actual = g_string_new("");
/* we serialize with %f for our reference visitors, so rather than fuzzy
* floating math to test "equality", just compare the formatted values
*/
- double1 = g_malloc0(calc_float_string_storage(pt->value.number));
- double2 = g_malloc0(calc_float_string_storage(pt_copy->value.number));
- g_assert_cmpstr(double1, ==, double2);
- g_free(double1);
- g_free(double2);
+ g_string_printf(double_expected, "%.6f", pt->value.number);
+ g_string_printf(double_actual, "%.6f", pt_copy->value.number);
+ g_assert_cmpstr(double_actual->str, ==, double_expected->str);
+
+ g_string_free(double_expected, true);
+ g_string_free(double_actual, true);
} else if (pt->type == PTYPE_BOOLEAN) {
g_assert_cmpint(!!pt->value.max, ==, !!pt->value.max);
} else {
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 09/11] qapi: add native list coverage for visitor serialization tests
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (7 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 08/11] qapi: fix visitor serialization tests for numbers/doubles Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 10/11] qapi: add native list coverage for QMP output visitor tests Michael Roth
` (4 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
tests/test-visitor-serialization.c | 451 ++++++++++++++++++++++++++++++++++--
1 file changed, 433 insertions(+), 18 deletions(-)
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index fed6810..ee7916b 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -23,6 +23,25 @@
#include "qapi/qmp-output-visitor.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
+#include "qapi-types.h"
+#include "qapi-visit.h"
+#include "qapi/dealloc-visitor.h"
+
+enum PrimitiveTypeKind {
+ PTYPE_STRING = 0,
+ PTYPE_BOOLEAN,
+ PTYPE_NUMBER,
+ PTYPE_INTEGER,
+ PTYPE_U8,
+ PTYPE_U16,
+ PTYPE_U32,
+ PTYPE_U64,
+ PTYPE_S8,
+ PTYPE_S16,
+ PTYPE_S32,
+ PTYPE_S64,
+ PTYPE_EOL,
+};
typedef struct PrimitiveType {
union {
@@ -40,26 +59,42 @@ typedef struct PrimitiveType {
int64_t s64;
intmax_t max;
} value;
- enum {
- PTYPE_STRING = 0,
- PTYPE_BOOLEAN,
- PTYPE_NUMBER,
- PTYPE_INTEGER,
- PTYPE_U8,
- PTYPE_U16,
- PTYPE_U32,
- PTYPE_U64,
- PTYPE_S8,
- PTYPE_S16,
- PTYPE_S32,
- PTYPE_S64,
- PTYPE_EOL,
- } type;
+ enum PrimitiveTypeKind type;
const char *description;
} PrimitiveType;
+typedef struct PrimitiveList {
+ union {
+ strList *strings;
+ boolList *booleans;
+ numberList *numbers;
+ intList *integers;
+ int8List *s8_integers;
+ int16List *s16_integers;
+ int32List *s32_integers;
+ int64List *s64_integers;
+ uint8List *u8_integers;
+ uint16List *u16_integers;
+ uint32List *u32_integers;
+ uint64List *u64_integers;
+ } value;
+ enum PrimitiveTypeKind type;
+ const char *description;
+} PrimitiveList;
+
/* test helpers */
+typedef void (*VisitorFunc)(Visitor *v, void **native, Error **errp);
+
+static void dealloc_helper(void *native_in, VisitorFunc visit, Error **errp)
+{
+ QapiDeallocVisitor *qdv = qapi_dealloc_visitor_new();
+
+ visit(qapi_dealloc_get_visitor(qdv), &native_in, errp);
+
+ qapi_dealloc_visitor_cleanup(qdv);
+}
+
static void visit_primitive_type(Visitor *v, void **native, Error **errp)
{
PrimitiveType *pt = *native;
@@ -105,6 +140,51 @@ static void visit_primitive_type(Visitor *v, void **native, Error **errp)
}
}
+static void visit_primitive_list(Visitor *v, void **native, Error **errp)
+{
+ PrimitiveList *pl = *native;
+ switch (pl->type) {
+ case PTYPE_STRING:
+ visit_type_strList(v, &pl->value.strings, NULL, errp);
+ break;
+ case PTYPE_BOOLEAN:
+ visit_type_boolList(v, &pl->value.booleans, NULL, errp);
+ break;
+ case PTYPE_NUMBER:
+ visit_type_numberList(v, &pl->value.numbers, NULL, errp);
+ break;
+ case PTYPE_INTEGER:
+ visit_type_intList(v, &pl->value.integers, NULL, errp);
+ break;
+ case PTYPE_S8:
+ visit_type_int8List(v, &pl->value.s8_integers, NULL, errp);
+ break;
+ case PTYPE_S16:
+ visit_type_int16List(v, &pl->value.s16_integers, NULL, errp);
+ break;
+ case PTYPE_S32:
+ visit_type_int32List(v, &pl->value.s32_integers, NULL, errp);
+ break;
+ case PTYPE_S64:
+ visit_type_int64List(v, &pl->value.s64_integers, NULL, errp);
+ break;
+ case PTYPE_U8:
+ visit_type_uint8List(v, &pl->value.u8_integers, NULL, errp);
+ break;
+ case PTYPE_U16:
+ visit_type_uint16List(v, &pl->value.u16_integers, NULL, errp);
+ break;
+ case PTYPE_U32:
+ visit_type_uint32List(v, &pl->value.u32_integers, NULL, errp);
+ break;
+ case PTYPE_U64:
+ visit_type_uint64List(v, &pl->value.u64_integers, NULL, errp);
+ break;
+ default:
+ g_assert(false);
+ }
+}
+
typedef struct TestStruct
{
int64_t integer;
@@ -206,12 +286,11 @@ static void visit_nested_struct_list(Visitor *v, void **native, Error **errp)
/* test cases */
-typedef void (*VisitorFunc)(Visitor *v, void **native, Error **errp);
-
typedef enum VisitorCapabilities {
VCAP_PRIMITIVES = 1,
VCAP_STRUCTURES = 2,
VCAP_LISTS = 4,
+ VCAP_PRIMITIVE_LISTS = 8,
} VisitorCapabilities;
typedef struct SerializeOps {
@@ -270,6 +349,328 @@ static void test_primitives(gconstpointer opaque)
g_free(pt_copy);
}
+static void test_primitive_lists(gconstpointer opaque)
+{
+ TestArgs *args = (TestArgs *) opaque;
+ const SerializeOps *ops = args->ops;
+ PrimitiveType *pt = args->test_data;
+ PrimitiveList pl = { .value = { 0 } };
+ PrimitiveList pl_copy = { .value = { 0 } };
+ PrimitiveList *pl_copy_ptr = &pl_copy;
+ Error *err = NULL;
+ void *serialize_data;
+ void *cur_head = NULL;
+ int i;
+
+ pl.type = pl_copy.type = pt->type;
+
+ /* build up our list of primitive types */
+ for (i = 0; i < 32; i++) {
+ switch (pl.type) {
+ case PTYPE_STRING: {
+ strList *tmp = g_new0(strList, 1);
+ tmp->value = g_strdup(pt->value.string);
+ if (pl.value.strings == NULL) {
+ pl.value.strings = tmp;
+ } else {
+ tmp->next = pl.value.strings;
+ pl.value.strings = tmp;
+ }
+ break;
+ }
+ case PTYPE_INTEGER: {
+ intList *tmp = g_new0(intList, 1);
+ tmp->value = pt->value.integer;
+ if (pl.value.integers == NULL) {
+ pl.value.integers = tmp;
+ } else {
+ tmp->next = pl.value.integers;
+ pl.value.integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_S8: {
+ int8List *tmp = g_new0(int8List, 1);
+ tmp->value = pt->value.s8;
+ if (pl.value.s8_integers == NULL) {
+ pl.value.s8_integers = tmp;
+ } else {
+ tmp->next = pl.value.s8_integers;
+ pl.value.s8_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_S16: {
+ int16List *tmp = g_new0(int16List, 1);
+ tmp->value = pt->value.s16;
+ if (pl.value.s16_integers == NULL) {
+ pl.value.s16_integers = tmp;
+ } else {
+ tmp->next = pl.value.s16_integers;
+ pl.value.s16_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_S32: {
+ int32List *tmp = g_new0(int32List, 1);
+ tmp->value = pt->value.s32;
+ if (pl.value.s32_integers == NULL) {
+ pl.value.s32_integers = tmp;
+ } else {
+ tmp->next = pl.value.s32_integers;
+ pl.value.s32_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_S64: {
+ int64List *tmp = g_new0(int64List, 1);
+ tmp->value = pt->value.s64;
+ if (pl.value.s64_integers == NULL) {
+ pl.value.s64_integers = tmp;
+ } else {
+ tmp->next = pl.value.s64_integers;
+ pl.value.s64_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_U8: {
+ uint8List *tmp = g_new0(uint8List, 1);
+ tmp->value = pt->value.u8;
+ if (pl.value.u8_integers == NULL) {
+ pl.value.u8_integers = tmp;
+ } else {
+ tmp->next = pl.value.u8_integers;
+ pl.value.u8_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_U16: {
+ uint16List *tmp = g_new0(uint16List, 1);
+ tmp->value = pt->value.u16;
+ if (pl.value.u16_integers == NULL) {
+ pl.value.u16_integers = tmp;
+ } else {
+ tmp->next = pl.value.u16_integers;
+ pl.value.u16_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_U32: {
+ uint32List *tmp = g_new0(uint32List, 1);
+ tmp->value = pt->value.u32;
+ if (pl.value.u32_integers == NULL) {
+ pl.value.u32_integers = tmp;
+ } else {
+ tmp->next = pl.value.u32_integers;
+ pl.value.u32_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_U64: {
+ uint64List *tmp = g_new0(uint64List, 1);
+ tmp->value = pt->value.u64;
+ if (pl.value.u64_integers == NULL) {
+ pl.value.u64_integers = tmp;
+ } else {
+ tmp->next = pl.value.u64_integers;
+ pl.value.u64_integers = tmp;
+ }
+ break;
+ }
+ case PTYPE_NUMBER: {
+ numberList *tmp = g_new0(numberList, 1);
+ tmp->value = pt->value.number;
+ if (pl.value.numbers == NULL) {
+ pl.value.numbers = tmp;
+ } else {
+ tmp->next = pl.value.numbers;
+ pl.value.numbers = tmp;
+ }
+ break;
+ }
+ case PTYPE_BOOLEAN: {
+ boolList *tmp = g_new0(boolList, 1);
+ tmp->value = pt->value.boolean;
+ if (pl.value.booleans == NULL) {
+ pl.value.booleans = tmp;
+ } else {
+ tmp->next = pl.value.booleans;
+ pl.value.booleans = tmp;
+ }
+ break;
+ }
+ default:
+ g_assert(0);
+ }
+ }
+
+ ops->serialize((void **)&pl, &serialize_data, visit_primitive_list, &err);
+ ops->deserialize((void **)&pl_copy_ptr, serialize_data, visit_primitive_list, &err);
+
+ g_assert(err == NULL);
+ i = 0;
+
+ /* compare our deserialized list of primitives to the original */
+ do {
+ switch (pl_copy.type) {
+ case PTYPE_STRING: {
+ strList *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.strings;
+ }
+ g_assert_cmpstr(pt->value.string, ==, ptr->value);
+ break;
+ }
+ case PTYPE_INTEGER: {
+ intList *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.integers;
+ }
+ g_assert_cmpint(pt->value.integer, ==, ptr->value);
+ break;
+ }
+ case PTYPE_S8: {
+ int8List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.s8_integers;
+ }
+ g_assert_cmpint(pt->value.s8, ==, ptr->value);
+ break;
+ }
+ case PTYPE_S16: {
+ int16List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.s16_integers;
+ }
+ g_assert_cmpint(pt->value.s16, ==, ptr->value);
+ break;
+ }
+ case PTYPE_S32: {
+ int32List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.s32_integers;
+ }
+ g_assert_cmpint(pt->value.s32, ==, ptr->value);
+ break;
+ }
+ case PTYPE_S64: {
+ int64List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.s64_integers;
+ }
+ g_assert_cmpint(pt->value.s64, ==, ptr->value);
+ break;
+ }
+ case PTYPE_U8: {
+ uint8List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.u8_integers;
+ }
+ g_assert_cmpint(pt->value.u8, ==, ptr->value);
+ break;
+ }
+ case PTYPE_U16: {
+ uint16List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.u16_integers;
+ }
+ g_assert_cmpint(pt->value.u16, ==, ptr->value);
+ break;
+ }
+ case PTYPE_U32: {
+ uint32List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.u32_integers;
+ }
+ g_assert_cmpint(pt->value.u32, ==, ptr->value);
+ break;
+ }
+ case PTYPE_U64: {
+ uint64List *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.u64_integers;
+ }
+ g_assert_cmpint(pt->value.u64, ==, ptr->value);
+ break;
+ }
+ case PTYPE_NUMBER: {
+ numberList *ptr;
+ GString *double_expected = g_string_new("");
+ GString *double_actual = g_string_new("");
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.numbers;
+ }
+ /* we serialize with %f for our reference visitors, so rather than
+ * fuzzy floating math to test "equality", just compare the
+ * formatted values
+ */
+ g_string_printf(double_expected, "%.6f", pt->value.number);
+ g_string_printf(double_actual, "%.6f", ptr->value);
+ g_assert_cmpstr(double_actual->str, ==, double_expected->str);
+ g_string_free(double_expected, true);
+ g_string_free(double_actual, true);
+ break;
+ }
+ case PTYPE_BOOLEAN: {
+ boolList *ptr;
+ if (cur_head) {
+ ptr = cur_head;
+ cur_head = ptr->next;
+ } else {
+ cur_head = ptr = pl_copy.value.booleans;
+ }
+ g_assert_cmpint(!!pt->value.boolean, ==, !!ptr->value);
+ break;
+ }
+ default:
+ g_assert(0);
+ }
+ i++;
+ } while (cur_head);
+
+ g_assert_cmpint(i, ==, 33);
+
+ ops->cleanup(serialize_data);
+ dealloc_helper(&pl, visit_primitive_list, &err);
+ g_assert(!err);
+ dealloc_helper(&pl_copy, visit_primitive_list, &err);
+ g_assert(!err);
+ g_free(args);
+}
+
static void test_struct(gconstpointer opaque)
{
TestArgs *args = (TestArgs *) opaque;
@@ -719,7 +1120,8 @@ static const SerializeOps visitors[] = {
.serialize = qmp_serialize,
.deserialize = qmp_deserialize,
.cleanup = qmp_cleanup,
- .caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS
+ .caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS |
+ VCAP_PRIMITIVE_LISTS
},
{
.type = "String",
@@ -773,6 +1175,19 @@ static void add_visitor_type(const SerializeOps *ops)
args->test_data = NULL;
g_test_add_data_func(testname, args, test_nested_struct_list);
}
+
+ if (ops->caps & VCAP_PRIMITIVE_LISTS) {
+ i = 0;
+ while (pt_values[i].type != PTYPE_EOL) {
+ sprintf(testname, "%s/primitive_list/%s", testname_prefix,
+ pt_values[i].description);
+ args = g_malloc0(sizeof(*args));
+ args->ops = ops;
+ args->test_data = &pt_values[i];
+ g_test_add_data_func(testname, args, test_primitive_lists);
+ i++;
+ }
+ }
}
int main(int argc, char **argv)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 10/11] qapi: add native list coverage for QMP output visitor tests
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (8 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 09/11] qapi: add native list coverage for visitor serialization tests Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 11/11] qapi: add native list coverage for QMP input " Michael Roth
` (3 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
This exercises schema-generated visitors for native list types and does
some sanity checking on validity of serialized data.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
qapi-schema-test.json | 15 ++
tests/test-qmp-output-visitor.c | 332 +++++++++++++++++++++++++++++++++++++++
2 files changed, 347 insertions(+)
diff --git a/qapi-schema-test.json b/qapi-schema-test.json
index 9eae350..4434fa3 100644
--- a/qapi-schema-test.json
+++ b/qapi-schema-test.json
@@ -32,6 +32,21 @@
{ 'union': 'UserDefUnion',
'data': { 'a' : 'UserDefA', 'b' : 'UserDefB' } }
+# for testing native lists
+{ 'union': 'UserDefNativeListUnion',
+ 'data': { 'integer': ['int'],
+ 's8': ['int8'],
+ 's16': ['int16'],
+ 's32': ['int32'],
+ 's64': ['int64'],
+ 'u8': ['uint8'],
+ 'u16': ['uint16'],
+ 'u32': ['uint32'],
+ 'u64': ['uint64'],
+ 'number': ['number'],
+ 'boolean': ['bool'],
+ 'string': ['str'] } }
+
# testing commands
{ 'command': 'user_def_cmd', 'data': {} }
{ 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 71367e6..0942a41 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -431,6 +431,314 @@ static void test_visitor_out_union(TestOutputVisitorData *data,
QDECREF(qdict);
}
+static void init_native_list(UserDefNativeListUnion *cvalue)
+{
+ int i;
+ switch (cvalue->kind) {
+ case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
+ intList **list = &cvalue->integer;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(intList, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S8: {
+ int8List **list = &cvalue->s8;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(int8List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S16: {
+ int16List **list = &cvalue->s16;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(int16List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S32: {
+ int32List **list = &cvalue->s32;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(int32List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S64: {
+ int64List **list = &cvalue->s64;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(int64List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U8: {
+ uint8List **list = &cvalue->u8;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(uint8List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U16: {
+ uint16List **list = &cvalue->u16;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(uint16List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U32: {
+ uint32List **list = &cvalue->u32;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(uint32List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U64: {
+ uint64List **list = &cvalue->u64;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(uint64List, 1);
+ (*list)->value = i;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN: {
+ boolList **list = &cvalue->boolean;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(boolList, 1);
+ (*list)->value = (i % 3 == 0);
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_STRING: {
+ strList **list = &cvalue->string;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(strList, 1);
+ (*list)->value = g_strdup_printf("%d", i);
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER: {
+ numberList **list = &cvalue->number;
+ for (i = 0; i < 32; i++) {
+ *list = g_new0(numberList, 1);
+ (*list)->value = (double)i / 3;
+ (*list)->next = NULL;
+ list = &(*list)->next;
+ }
+ break;
+ }
+ default:
+ g_assert(false);
+ }
+}
+
+static void check_native_list(QObject *qobj,
+ UserDefNativeListUnionKind kind)
+{
+ QDict *qdict;
+ QList *qlist;
+ int i;
+
+ g_assert(qobj);
+ g_assert(qobject_type(qobj) == QTYPE_QDICT);
+ qdict = qobject_to_qdict(qobj);
+ g_assert(qdict);
+ g_assert(qdict_haskey(qdict, "data"));
+ qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
+
+ switch (kind) {
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U8:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U16:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U32:
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U64:
+ /* all integer elements in JSON arrays get stored into QInts when
+ * we convert to QObjects, so we can check them all in the same
+ * fashion, so simply fall through here
+ */
+ case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QInt *qvalue;
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qint(tmp);
+ g_assert_cmpint(qint_get_int(qvalue), ==, i);
+ qobject_decref(qlist_pop(qlist));
+ }
+ break;
+ case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QBool *qvalue;
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qbool(tmp);
+ g_assert_cmpint(qbool_get_int(qvalue), ==, (i % 3 == 0) ? 1 : 0);
+ qobject_decref(qlist_pop(qlist));
+ }
+ break;
+ case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QString *qvalue;
+ gchar str[8];
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qstring(tmp);
+ sprintf(str, "%d", i);
+ g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
+ qobject_decref(qlist_pop(qlist));
+ }
+ break;
+ case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
+ for (i = 0; i < 32; i++) {
+ QObject *tmp;
+ QFloat *qvalue;
+ GString *double_expected = g_string_new("");
+ GString *double_actual = g_string_new("");
+
+ tmp = qlist_peek(qlist);
+ g_assert(tmp);
+ qvalue = qobject_to_qfloat(tmp);
+ g_string_printf(double_expected, "%.6f", (double)i / 3);
+ g_string_printf(double_actual, "%.6f", qfloat_get_double(qvalue));
+ g_assert_cmpstr(double_actual->str, ==, double_expected->str);
+
+ qobject_decref(qlist_pop(qlist));
+ g_string_free(double_expected, true);
+ g_string_free(double_actual, true);
+ }
+ break;
+ default:
+ g_assert(false);
+ }
+ QDECREF(qlist);
+}
+
+static void test_native_list(TestOutputVisitorData *data,
+ const void *unused,
+ UserDefNativeListUnionKind kind)
+{
+ UserDefNativeListUnion *cvalue = g_new0(UserDefNativeListUnion, 1);
+ Error *err = NULL;
+ QObject *obj;
+
+ cvalue->kind = kind;
+ init_native_list(cvalue);
+
+ visit_type_UserDefNativeListUnion(data->ov, &cvalue, NULL, &err);
+ g_assert(err == NULL);
+
+ obj = qmp_output_get_qobject(data->qov);
+ check_native_list(obj, cvalue->kind);
+ qapi_free_UserDefNativeListUnion(cvalue);
+ qobject_decref(obj);
+}
+
+static void test_visitor_out_native_list_int(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
+}
+
+static void test_visitor_out_native_list_int8(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S8);
+}
+
+static void test_visitor_out_native_list_int16(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S16);
+}
+
+static void test_visitor_out_native_list_int32(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S32);
+}
+
+static void test_visitor_out_native_list_int64(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S64);
+}
+
+static void test_visitor_out_native_list_uint8(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U8);
+}
+
+static void test_visitor_out_native_list_uint16(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U16);
+}
+
+static void test_visitor_out_native_list_uint32(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U32);
+}
+
+static void test_visitor_out_native_list_uint64(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U64);
+}
+
+static void test_visitor_out_native_list_bool(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
+}
+
+static void test_visitor_out_native_list_str(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
+}
+
+static void test_visitor_out_native_list_number(TestOutputVisitorData *data,
+ const void *unused)
+{
+ test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);
+}
+
static void output_visitor_test_add(const char *testpath,
TestOutputVisitorData *data,
void (*test_func)(TestOutputVisitorData *data, const void *user_data))
@@ -471,6 +779,30 @@ int main(int argc, char **argv)
&out_visitor_data, test_visitor_out_list_qapi_free);
output_visitor_test_add("/visitor/output/union",
&out_visitor_data, test_visitor_out_union);
+ output_visitor_test_add("/visitor/output/native_list/int",
+ &out_visitor_data, test_visitor_out_native_list_int);
+ output_visitor_test_add("/visitor/output/native_list/int8",
+ &out_visitor_data, test_visitor_out_native_list_int8);
+ output_visitor_test_add("/visitor/output/native_list/int16",
+ &out_visitor_data, test_visitor_out_native_list_int16);
+ output_visitor_test_add("/visitor/output/native_list/int32",
+ &out_visitor_data, test_visitor_out_native_list_int32);
+ output_visitor_test_add("/visitor/output/native_list/int64",
+ &out_visitor_data, test_visitor_out_native_list_int64);
+ output_visitor_test_add("/visitor/output/native_list/uint8",
+ &out_visitor_data, test_visitor_out_native_list_uint8);
+ output_visitor_test_add("/visitor/output/native_list/uint16",
+ &out_visitor_data, test_visitor_out_native_list_uint16);
+ output_visitor_test_add("/visitor/output/native_list/uint32",
+ &out_visitor_data, test_visitor_out_native_list_uint32);
+ output_visitor_test_add("/visitor/output/native_list/uint64",
+ &out_visitor_data, test_visitor_out_native_list_uint64);
+ output_visitor_test_add("/visitor/output/native_list/bool",
+ &out_visitor_data, test_visitor_out_native_list_bool);
+ output_visitor_test_add("/visitor/output/native_list/string",
+ &out_visitor_data, test_visitor_out_native_list_str);
+ output_visitor_test_add("/visitor/output/native_list/number",
+ &out_visitor_data, test_visitor_out_native_list_number);
g_test_run();
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [Qemu-devel] [PATCH 11/11] qapi: add native list coverage for QMP input visitor tests
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (9 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 10/11] qapi: add native list coverage for QMP output visitor tests Michael Roth
@ 2013-05-10 22:46 ` Michael Roth
2013-05-13 6:54 ` [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Laszlo Ersek
` (2 subsequent siblings)
13 siblings, 0 replies; 23+ messages in thread
From: Michael Roth @ 2013-05-10 22:46 UTC (permalink / raw)
To: qemu-devel; +Cc: akong, lersek, lcapitulino
This exercises schema-generated visitors for native list types and does
some sanity checking on validity of deserialized data.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
tests/test-qmp-input-visitor.c | 338 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 338 insertions(+)
diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c
index b308cf9..2741eef 100644
--- a/tests/test-qmp-input-visitor.c
+++ b/tests/test-qmp-input-visitor.c
@@ -61,6 +61,31 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,
return v;
}
+/* similar to visitor_input_test_init(), but does not expect a string
+ * literal/format json_string argument and so can be used for
+ * programatically generated strings (and we can't pass in programatically
+ * generated strings via %s format parameters since qobject_from_jsonv()
+ * will wrap those in double-quotes and treat the entire object as a
+ * string)
+ */
+static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data,
+ const char *json_string)
+{
+ Visitor *v;
+
+ data->obj = qobject_from_json(json_string);
+
+ g_assert(data->obj != NULL);
+
+ data->qiv = qmp_input_visitor_new(data->obj);
+ g_assert(data->qiv != NULL);
+
+ v = qmp_input_get_visitor(data->qiv);
+ g_assert(v != NULL);
+
+ return v;
+}
+
static void test_visitor_in_int(TestInputVisitorData *data,
const void *unused)
{
@@ -277,6 +302,287 @@ static void test_visitor_in_union(TestInputVisitorData *data,
qapi_free_UserDefUnion(tmp);
}
+static void test_native_list_integer_helper(TestInputVisitorData *data,
+ const void *unused,
+ UserDefNativeListUnionKind kind)
+{
+ UserDefNativeListUnion *cvalue = NULL;
+ Error *err = NULL;
+ Visitor *v;
+ GString *gstr_list = g_string_new("");
+ GString *gstr_union = g_string_new("");
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(gstr_list, "%d", i);
+ if (i != 31) {
+ g_string_append(gstr_list, ", ");
+ }
+ }
+ g_string_append_printf(gstr_union, "{ 'type': '%s', 'data': [ %s ] }",
+ UserDefNativeListUnionKind_lookup[kind],
+ gstr_list->str);
+ v = visitor_input_test_init_raw(data, gstr_union->str);
+
+ visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+ g_assert(err == NULL);
+ g_assert(cvalue != NULL);
+ g_assert_cmpint(cvalue->kind, ==, kind);
+
+ switch (kind) {
+ case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
+ intList *elem = NULL;
+ for (i = 0, elem = cvalue->integer; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S8: {
+ int8List *elem = NULL;
+ for (i = 0, elem = cvalue->s8; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S16: {
+ int16List *elem = NULL;
+ for (i = 0, elem = cvalue->s16; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S32: {
+ int32List *elem = NULL;
+ for (i = 0, elem = cvalue->s32; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_S64: {
+ int64List *elem = NULL;
+ for (i = 0, elem = cvalue->s64; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U8: {
+ uint8List *elem = NULL;
+ for (i = 0, elem = cvalue->u8; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U16: {
+ uint16List *elem = NULL;
+ for (i = 0, elem = cvalue->u16; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U32: {
+ uint32List *elem = NULL;
+ for (i = 0, elem = cvalue->u32; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ case USER_DEF_NATIVE_LIST_UNION_KIND_U64: {
+ uint64List *elem = NULL;
+ for (i = 0, elem = cvalue->u64; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, i);
+ }
+ break;
+ }
+ default:
+ g_assert(false);
+ }
+
+ g_string_free(gstr_union, true);
+ g_string_free(gstr_list, true);
+ qapi_free_UserDefNativeListUnion(cvalue);
+}
+
+static void test_visitor_in_native_list_int(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
+}
+
+static void test_visitor_in_native_list_int8(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_S8);
+}
+
+static void test_visitor_in_native_list_int16(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_S16);
+}
+
+static void test_visitor_in_native_list_int32(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_S32);
+}
+
+static void test_visitor_in_native_list_int64(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_S64);
+}
+
+static void test_visitor_in_native_list_uint8(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_U8);
+}
+
+static void test_visitor_in_native_list_uint16(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_U16);
+}
+
+static void test_visitor_in_native_list_uint32(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_U32);
+}
+
+static void test_visitor_in_native_list_uint64(TestInputVisitorData *data,
+ const void *unused)
+{
+ test_native_list_integer_helper(data, unused,
+ USER_DEF_NATIVE_LIST_UNION_KIND_U64);
+}
+
+static void test_visitor_in_native_list_bool(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefNativeListUnion *cvalue = NULL;
+ boolList *elem = NULL;
+ Error *err = NULL;
+ Visitor *v;
+ GString *gstr_list = g_string_new("");
+ GString *gstr_union = g_string_new("");
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(gstr_list, "%s",
+ (i % 3 == 0) ? "true" : "false");
+ if (i != 31) {
+ g_string_append(gstr_list, ", ");
+ }
+ }
+ g_string_append_printf(gstr_union, "{ 'type': 'boolean', 'data': [ %s ] }",
+ gstr_list->str);
+ v = visitor_input_test_init_raw(data, gstr_union->str);
+
+ visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+ g_assert(err == NULL);
+ g_assert(cvalue != NULL);
+ g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
+
+ for (i = 0, elem = cvalue->boolean; elem; elem = elem->next, i++) {
+ g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0);
+ }
+
+ g_string_free(gstr_union, true);
+ g_string_free(gstr_list, true);
+ qapi_free_UserDefNativeListUnion(cvalue);
+}
+
+static void test_visitor_in_native_list_string(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefNativeListUnion *cvalue = NULL;
+ strList *elem = NULL;
+ Error *err = NULL;
+ Visitor *v;
+ GString *gstr_list = g_string_new("");
+ GString *gstr_union = g_string_new("");
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(gstr_list, "'%d'", i);
+ if (i != 31) {
+ g_string_append(gstr_list, ", ");
+ }
+ }
+ g_string_append_printf(gstr_union, "{ 'type': 'string', 'data': [ %s ] }",
+ gstr_list->str);
+ v = visitor_input_test_init_raw(data, gstr_union->str);
+
+ visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+ g_assert(err == NULL);
+ g_assert(cvalue != NULL);
+ g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
+
+ for (i = 0, elem = cvalue->string; elem; elem = elem->next, i++) {
+ gchar str[8];
+ sprintf(str, "%d", i);
+ g_assert_cmpstr(elem->value, ==, str);
+ }
+
+ g_string_free(gstr_union, true);
+ g_string_free(gstr_list, true);
+ qapi_free_UserDefNativeListUnion(cvalue);
+}
+
+#define DOUBLE_STR_MAX 16
+
+static void test_visitor_in_native_list_number(TestInputVisitorData *data,
+ const void *unused)
+{
+ UserDefNativeListUnion *cvalue = NULL;
+ numberList *elem = NULL;
+ Error *err = NULL;
+ Visitor *v;
+ GString *gstr_list = g_string_new("");
+ GString *gstr_union = g_string_new("");
+ int i;
+
+ for (i = 0; i < 32; i++) {
+ g_string_append_printf(gstr_list, "%f", (double)i / 3);
+ if (i != 31) {
+ g_string_append(gstr_list, ", ");
+ }
+ }
+ g_string_append_printf(gstr_union, "{ 'type': 'number', 'data': [ %s ] }",
+ gstr_list->str);
+ v = visitor_input_test_init_raw(data, gstr_union->str);
+
+ visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+ g_assert(err == NULL);
+ g_assert(cvalue != NULL);
+ g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);
+
+ for (i = 0, elem = cvalue->number; elem; elem = elem->next, i++) {
+ GString *double_expected = g_string_new("");
+ GString *double_actual = g_string_new("");
+
+ g_string_printf(double_expected, "%.6f", (double)i / 3);
+ g_string_printf(double_actual, "%.6f", elem->value);
+ g_assert_cmpstr(double_expected->str, ==, double_actual->str);
+
+ g_string_free(double_expected, true);
+ g_string_free(double_actual, true);
+ }
+
+ g_string_free(gstr_union, true);
+ g_string_free(gstr_list, true);
+ qapi_free_UserDefNativeListUnion(cvalue);
+}
+
static void input_visitor_test_add(const char *testpath,
TestInputVisitorData *data,
void (*test_func)(TestInputVisitorData *data, const void *user_data))
@@ -330,6 +636,38 @@ int main(int argc, char **argv)
&in_visitor_data, test_visitor_in_union);
input_visitor_test_add("/visitor/input/errors",
&in_visitor_data, test_visitor_in_errors);
+ input_visitor_test_add("/visitor/input/native_list/int",
+ &in_visitor_data,
+ test_visitor_in_native_list_int);
+ input_visitor_test_add("/visitor/input/native_list/int8",
+ &in_visitor_data,
+ test_visitor_in_native_list_int8);
+ input_visitor_test_add("/visitor/input/native_list/int16",
+ &in_visitor_data,
+ test_visitor_in_native_list_int16);
+ input_visitor_test_add("/visitor/input/native_list/int32",
+ &in_visitor_data,
+ test_visitor_in_native_list_int32);
+ input_visitor_test_add("/visitor/input/native_list/int64",
+ &in_visitor_data,
+ test_visitor_in_native_list_int64);
+ input_visitor_test_add("/visitor/input/native_list/uint8",
+ &in_visitor_data,
+ test_visitor_in_native_list_uint8);
+ input_visitor_test_add("/visitor/input/native_list/uint16",
+ &in_visitor_data,
+ test_visitor_in_native_list_uint16);
+ input_visitor_test_add("/visitor/input/native_list/uint32",
+ &in_visitor_data,
+ test_visitor_in_native_list_uint32);
+ input_visitor_test_add("/visitor/input/native_list/uint64",
+ &in_visitor_data, test_visitor_in_native_list_uint64);
+ input_visitor_test_add("/visitor/input/native_list/bool",
+ &in_visitor_data, test_visitor_in_native_list_bool);
+ input_visitor_test_add("/visitor/input/native_list/str",
+ &in_visitor_data, test_visitor_in_native_list_string);
+ input_visitor_test_add("/visitor/input/native_list/number",
+ &in_visitor_data, test_visitor_in_native_list_number);
g_test_run();
--
1.7.9.5
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (10 preceding siblings ...)
2013-05-10 22:46 ` [Qemu-devel] [PATCH 11/11] qapi: add native list coverage for QMP input " Michael Roth
@ 2013-05-13 6:54 ` Laszlo Ersek
2013-05-13 13:52 ` Amos Kong
2013-05-15 13:17 ` Luiz Capitulino
13 siblings, 0 replies; 23+ messages in thread
From: Laszlo Ersek @ 2013-05-13 6:54 UTC (permalink / raw)
To: Michael Roth; +Cc: akong, qemu-devel, lcapitulino
On 05/11/13 00:45, Michael Roth wrote:
> These patches apply on top of qemu.git master, and can also be obtained from:
> git://github.com/mdroth/qemu.git qapi-native-lists
>
> Sending this now since a number of series have popped up in the past that
> wanted this, and Amos has some pending patches (query-mac-tables) that rely
> on this as well.
>
> These patches add support for specifying lists of native qapi types
> (int/bool/str/number/int8/uint8/etc) like so:
>
> { 'type': 'foo',
> 'data': { 'bar': ['int'] }}
>
> for a 'bar' field that is a list of type 'int',
>
> { 'type': 'foo2',
> 'data': { 'bar2': ['str'] }}
>
> for a 'bar2' field that is a list of type 'str', and so on.
>
> This uses linked list types for the native C representations, just as we do
> for complex schema-defined types. In the future we may add schema annotations
> of some sort to specify a more natural/efficient array type for the C
> representations, but this should serve the majority of uses-cases for now.
>
> v2->v3:
> * added native list support for fixed-width integer types (Amos)
> * added fixed-width integer list coverage to serialization,
> QMPOutputVisitor, and QmpInputVisitor unit tests
> * added unit test to QmpInputVisitor to test new overflow handling when
> integers types are expected (Eric)
> * clarified terminology/documentation in json parser fix (Laszlo)
> * fixed whitespace/newlines in code generator output (Luiz)
>
> v1->v2:
> * fixed do-nothing float tests in pre-existing code and updated new
> unit tests accordingly (Laszlo)
> * added a fix for a bug in json parser that was exposed by above change
> * fixed misuse of string format parameters for float testing (Laszlo)
> * fixed extra characters in comment (Laszlo)
> * removed unused variant from UserDefNativeListUnion QAPI type
>
> Makefile | 6 +-
> qapi-schema-test.json | 15 ++
> qobject/json-parser.c | 26 +-
> scripts/qapi-types.py | 45 +++-
> scripts/qapi-visit.py | 36 ++-
> scripts/qapi.py | 23 ++
> tests/test-qmp-input-visitor.c | 358 ++++++++++++++++++++++++++
> tests/test-qmp-output-visitor.c | 332 ++++++++++++++++++++++++
> tests/test-visitor-serialization.c | 485 +++++++++++++++++++++++++++++++++---
> 9 files changed, 1274 insertions(+), 52 deletions(-)
>
I compared the patches with their v2 counterparts, and read the new patch.
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (11 preceding siblings ...)
2013-05-13 6:54 ` [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Laszlo Ersek
@ 2013-05-13 13:52 ` Amos Kong
2013-05-15 13:17 ` Luiz Capitulino
13 siblings, 0 replies; 23+ messages in thread
From: Amos Kong @ 2013-05-13 13:52 UTC (permalink / raw)
To: Michael Roth; +Cc: lersek, qemu-devel, lcapitulino
On Fri, May 10, 2013 at 05:45:59PM -0500, Michael Roth wrote:
> These patches apply on top of qemu.git master, and can also be obtained from:
> git://github.com/mdroth/qemu.git qapi-native-lists
>
> Sending this now since a number of series have popped up in the past that
> wanted this, and Amos has some pending patches (query-mac-tables) that rely
> on this as well.
>
> These patches add support for specifying lists of native qapi types
> (int/bool/str/number/int8/uint8/etc) like so:
>
> { 'type': 'foo',
> 'data': { 'bar': ['int'] }}
>
> for a 'bar' field that is a list of type 'int',
>
> { 'type': 'foo2',
> 'data': { 'bar2': ['str'] }}
>
> for a 'bar2' field that is a list of type 'str', and so on.
>
> This uses linked list types for the native C representations, just as we do
> for complex schema-defined types. In the future we may add schema annotations
> of some sort to specify a more natural/efficient array type for the C
> representations, but this should serve the majority of uses-cases for now.
Looks good to me, thanks!
Reviewed-by: Amos Kong <akong@redhat.com>
> v2->v3:
> * added native list support for fixed-width integer types (Amos)
> * added fixed-width integer list coverage to serialization,
> QMPOutputVisitor, and QmpInputVisitor unit tests
> * added unit test to QmpInputVisitor to test new overflow handling when
> integers types are expected (Eric)
> * clarified terminology/documentation in json parser fix (Laszlo)
> * fixed whitespace/newlines in code generator output (Luiz)
>
> v1->v2:
> * fixed do-nothing float tests in pre-existing code and updated new
> unit tests accordingly (Laszlo)
> * added a fix for a bug in json parser that was exposed by above change
> * fixed misuse of string format parameters for float testing (Laszlo)
> * fixed extra characters in comment (Laszlo)
> * removed unused variant from UserDefNativeListUnion QAPI type
>
> Makefile | 6 +-
> qapi-schema-test.json | 15 ++
> qobject/json-parser.c | 26 +-
> scripts/qapi-types.py | 45 +++-
> scripts/qapi-visit.py | 36 ++-
> scripts/qapi.py | 23 ++
> tests/test-qmp-input-visitor.c | 358 ++++++++++++++++++++++++++
> tests/test-qmp-output-visitor.c | 332 ++++++++++++++++++++++++
> tests/test-visitor-serialization.c | 485 +++++++++++++++++++++++++++++++++---
> 9 files changed, 1274 insertions(+), 52 deletions(-)
--
Amos.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
` (12 preceding siblings ...)
2013-05-13 13:52 ` Amos Kong
@ 2013-05-15 13:17 ` Luiz Capitulino
2013-05-15 14:32 ` mdroth
13 siblings, 1 reply; 23+ messages in thread
From: Luiz Capitulino @ 2013-05-15 13:17 UTC (permalink / raw)
To: Michael Roth; +Cc: akong, lersek, qemu-devel
On Fri, 10 May 2013 17:45:59 -0500
Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> These patches apply on top of qemu.git master, and can also be obtained from:
> git://github.com/mdroth/qemu.git qapi-native-lists
>
> Sending this now since a number of series have popped up in the past that
> wanted this, and Amos has some pending patches (query-mac-tables) that rely
> on this as well.
>
> These patches add support for specifying lists of native qapi types
> (int/bool/str/number/int8/uint8/etc) like so:
>
> { 'type': 'foo',
> 'data': { 'bar': ['int'] }}
>
> for a 'bar' field that is a list of type 'int',
>
> { 'type': 'foo2',
> 'data': { 'bar2': ['str'] }}
>
> for a 'bar2' field that is a list of type 'str', and so on.
>
> This uses linked list types for the native C representations, just as we do
> for complex schema-defined types. In the future we may add schema annotations
> of some sort to specify a more natural/efficient array type for the C
> representations, but this should serve the majority of uses-cases for now.
I'm getting a build breakage when building all targets:
In file included from /home/lcapitulino/work/src/upstream/qmp-unstable/target-i386/cpu.c:34:0:
../qapi-visit.h:30:38: error: unknown type name ‘int8List’
../qapi-visit.h:31:39: error: unknown type name ‘int16List’
../qapi-visit.h:32:39: error: unknown type name ‘int32List’
../qapi-visit.h:33:39: error: unknown type name ‘int64List’
../qapi-visit.h:34:39: error: unknown type name ‘uint8List’
../qapi-visit.h:35:40: error: unknown type name ‘uint16List’
../qapi-visit.h:36:40: error: unknown type name ‘uint32List’
../qapi-visit.h:37:40: error: unknown type name ‘uint64List’
make[1]: *** [target-i386/cpu.o] Error 1
make: *** [subdir-i386-softmmu] Error 2
make: *** Waiting for unfinished jobs....
In file included from /home/lcapitulino/work/src/upstream/qmp-unstable/target-i386/cpu.c:34:0:
../qapi-visit.h:30:38: error: unknown type name ‘int8List’
../qapi-visit.h:31:39: error: unknown type name ‘int16List’
../qapi-visit.h:32:39: error: unknown type name ‘int32List’
../qapi-visit.h:33:39: error: unknown type name ‘int64List’
../qapi-visit.h:34:39: error: unknown type name ‘uint8List’
../qapi-visit.h:35:40: error: unknown type name ‘uint16List’
../qapi-visit.h:36:40: error: unknown type name ‘uint32List’
../qapi-visit.h:37:40: error: unknown type name ‘uint64List’
make[1]: *** [target-i386/cpu.o] Error 1
make: *** [subdir-x86_64-softmmu] Error 2
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 13:17 ` Luiz Capitulino
@ 2013-05-15 14:32 ` mdroth
2013-05-15 15:04 ` Luiz Capitulino
0 siblings, 1 reply; 23+ messages in thread
From: mdroth @ 2013-05-15 14:32 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: akong, lersek, qemu-devel
On Wed, May 15, 2013 at 09:17:46AM -0400, Luiz Capitulino wrote:
> On Fri, 10 May 2013 17:45:59 -0500
> Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
>
> > These patches apply on top of qemu.git master, and can also be obtained from:
> > git://github.com/mdroth/qemu.git qapi-native-lists
> >
> > Sending this now since a number of series have popped up in the past that
> > wanted this, and Amos has some pending patches (query-mac-tables) that rely
> > on this as well.
> >
> > These patches add support for specifying lists of native qapi types
> > (int/bool/str/number/int8/uint8/etc) like so:
> >
> > { 'type': 'foo',
> > 'data': { 'bar': ['int'] }}
> >
> > for a 'bar' field that is a list of type 'int',
> >
> > { 'type': 'foo2',
> > 'data': { 'bar2': ['str'] }}
> >
> > for a 'bar2' field that is a list of type 'str', and so on.
> >
> > This uses linked list types for the native C representations, just as we do
> > for complex schema-defined types. In the future we may add schema annotations
> > of some sort to specify a more natural/efficient array type for the C
> > representations, but this should serve the majority of uses-cases for now.
>
> I'm getting a build breakage when building all targets:
Hmm, tested all target builds and didn't/don't see any issues. Is this a
clean build? Can you confirm whether or not int8List/etc are declared in
qapi-types.h in your current build dir?
If they're not in there the file is stale and not being regenerated for some
reason. Which would be weird since qapi-visit.h seems to be getting
regenerated.
If they *are* there might be some kind of race in the QAPI build system,
because I think we rely on qapi-types.h/qapi-visit.h coming from
GENERATED_HEADERS, but otherwise being treated as parallelizable. Really,
qapi-types.h should be a dependancy of all qapi-visit.h users, and I don't
see that reflected in the Makefile unless I'm missing something.
>
> In file included from /home/lcapitulino/work/src/upstream/qmp-unstable/target-i386/cpu.c:34:0:
> ../qapi-visit.h:30:38: error: unknown type name ‘int8List’
> ../qapi-visit.h:31:39: error: unknown type name ‘int16List’
> ../qapi-visit.h:32:39: error: unknown type name ‘int32List’
> ../qapi-visit.h:33:39: error: unknown type name ‘int64List’
> ../qapi-visit.h:34:39: error: unknown type name ‘uint8List’
> ../qapi-visit.h:35:40: error: unknown type name ‘uint16List’
> ../qapi-visit.h:36:40: error: unknown type name ‘uint32List’
> ../qapi-visit.h:37:40: error: unknown type name ‘uint64List’
> make[1]: *** [target-i386/cpu.o] Error 1
> make: *** [subdir-i386-softmmu] Error 2
> make: *** Waiting for unfinished jobs....
> In file included from /home/lcapitulino/work/src/upstream/qmp-unstable/target-i386/cpu.c:34:0:
> ../qapi-visit.h:30:38: error: unknown type name ‘int8List’
> ../qapi-visit.h:31:39: error: unknown type name ‘int16List’
> ../qapi-visit.h:32:39: error: unknown type name ‘int32List’
> ../qapi-visit.h:33:39: error: unknown type name ‘int64List’
> ../qapi-visit.h:34:39: error: unknown type name ‘uint8List’
> ../qapi-visit.h:35:40: error: unknown type name ‘uint16List’
> ../qapi-visit.h:36:40: error: unknown type name ‘uint32List’
> ../qapi-visit.h:37:40: error: unknown type name ‘uint64List’
> make[1]: *** [target-i386/cpu.o] Error 1
> make: *** [subdir-x86_64-softmmu] Error 2
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 14:32 ` mdroth
@ 2013-05-15 15:04 ` Luiz Capitulino
2013-05-15 17:42 ` mdroth
0 siblings, 1 reply; 23+ messages in thread
From: Luiz Capitulino @ 2013-05-15 15:04 UTC (permalink / raw)
To: mdroth; +Cc: akong, lersek, qemu-devel
On Wed, 15 May 2013 09:32:37 -0500
mdroth <mdroth@linux.vnet.ibm.com> wrote:
> On Wed, May 15, 2013 at 09:17:46AM -0400, Luiz Capitulino wrote:
> > On Fri, 10 May 2013 17:45:59 -0500
> > Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> >
> > > These patches apply on top of qemu.git master, and can also be obtained from:
> > > git://github.com/mdroth/qemu.git qapi-native-lists
> > >
> > > Sending this now since a number of series have popped up in the past that
> > > wanted this, and Amos has some pending patches (query-mac-tables) that rely
> > > on this as well.
> > >
> > > These patches add support for specifying lists of native qapi types
> > > (int/bool/str/number/int8/uint8/etc) like so:
> > >
> > > { 'type': 'foo',
> > > 'data': { 'bar': ['int'] }}
> > >
> > > for a 'bar' field that is a list of type 'int',
> > >
> > > { 'type': 'foo2',
> > > 'data': { 'bar2': ['str'] }}
> > >
> > > for a 'bar2' field that is a list of type 'str', and so on.
> > >
> > > This uses linked list types for the native C representations, just as we do
> > > for complex schema-defined types. In the future we may add schema annotations
> > > of some sort to specify a more natural/efficient array type for the C
> > > representations, but this should serve the majority of uses-cases for now.
> >
> > I'm getting a build breakage when building all targets:
>
> Hmm, tested all target builds and didn't/don't see any issues. Is this a
> clean build? Can you confirm whether or not int8List/etc are declared in
> qapi-types.h in your current build dir?
Yes, it's a clean build and yes, the int?List declarations are being generated.
Tested a little bit more and this also happens with make -j1 and when
building only one target (x86_64 in my case).
I don't remember this happening with v1 btw, but I also don't remember if I
fully built it.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 15:04 ` Luiz Capitulino
@ 2013-05-15 17:42 ` mdroth
2013-05-15 18:05 ` Luiz Capitulino
0 siblings, 1 reply; 23+ messages in thread
From: mdroth @ 2013-05-15 17:42 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: akong, lersek, qemu-devel
On Wed, May 15, 2013 at 11:04:27AM -0400, Luiz Capitulino wrote:
> On Wed, 15 May 2013 09:32:37 -0500
> mdroth <mdroth@linux.vnet.ibm.com> wrote:
>
> > On Wed, May 15, 2013 at 09:17:46AM -0400, Luiz Capitulino wrote:
> > > On Fri, 10 May 2013 17:45:59 -0500
> > > Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> > >
> > > > These patches apply on top of qemu.git master, and can also be obtained from:
> > > > git://github.com/mdroth/qemu.git qapi-native-lists
> > > >
> > > > Sending this now since a number of series have popped up in the past that
> > > > wanted this, and Amos has some pending patches (query-mac-tables) that rely
> > > > on this as well.
> > > >
> > > > These patches add support for specifying lists of native qapi types
> > > > (int/bool/str/number/int8/uint8/etc) like so:
> > > >
> > > > { 'type': 'foo',
> > > > 'data': { 'bar': ['int'] }}
> > > >
> > > > for a 'bar' field that is a list of type 'int',
> > > >
> > > > { 'type': 'foo2',
> > > > 'data': { 'bar2': ['str'] }}
> > > >
> > > > for a 'bar2' field that is a list of type 'str', and so on.
> > > >
> > > > This uses linked list types for the native C representations, just as we do
> > > > for complex schema-defined types. In the future we may add schema annotations
> > > > of some sort to specify a more natural/efficient array type for the C
> > > > representations, but this should serve the majority of uses-cases for now.
> > >
> > > I'm getting a build breakage when building all targets:
> >
> > Hmm, tested all target builds and didn't/don't see any issues. Is this a
> > clean build? Can you confirm whether or not int8List/etc are declared in
> > qapi-types.h in your current build dir?
>
> Yes, it's a clean build and yes, the int?List declarations are being generated.
> Tested a little bit more and this also happens with make -j1 and when
> building only one target (x86_64 in my case).
The only way I've managed to reproduce this is by having a stale
qapi-types.h hanging around in $SRC_DIR while i'm building in a
different $BUILD_DIR. Can you confirm that's not what's happening here?
This is a real headscratcher otherwise. `make clean` wipes out
qapi-types.h, yet the file is present at the time of the build failure,
and appears in tact. So all I can imagine occuring here is the file
having only been partially generated at the time it was read, but I'm
not sure how that could happen with -j1
>
> I don't remember this happening with v1 btw, but I also don't remember if I
> fully built it.
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 17:42 ` mdroth
@ 2013-05-15 18:05 ` Luiz Capitulino
2013-05-15 19:13 ` mdroth
0 siblings, 1 reply; 23+ messages in thread
From: Luiz Capitulino @ 2013-05-15 18:05 UTC (permalink / raw)
To: mdroth; +Cc: akong, lersek, qemu-devel
On Wed, 15 May 2013 12:42:24 -0500
mdroth <mdroth@linux.vnet.ibm.com> wrote:
> On Wed, May 15, 2013 at 11:04:27AM -0400, Luiz Capitulino wrote:
> > On Wed, 15 May 2013 09:32:37 -0500
> > mdroth <mdroth@linux.vnet.ibm.com> wrote:
> >
> > > On Wed, May 15, 2013 at 09:17:46AM -0400, Luiz Capitulino wrote:
> > > > On Fri, 10 May 2013 17:45:59 -0500
> > > > Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> > > >
> > > > > These patches apply on top of qemu.git master, and can also be obtained from:
> > > > > git://github.com/mdroth/qemu.git qapi-native-lists
> > > > >
> > > > > Sending this now since a number of series have popped up in the past that
> > > > > wanted this, and Amos has some pending patches (query-mac-tables) that rely
> > > > > on this as well.
> > > > >
> > > > > These patches add support for specifying lists of native qapi types
> > > > > (int/bool/str/number/int8/uint8/etc) like so:
> > > > >
> > > > > { 'type': 'foo',
> > > > > 'data': { 'bar': ['int'] }}
> > > > >
> > > > > for a 'bar' field that is a list of type 'int',
> > > > >
> > > > > { 'type': 'foo2',
> > > > > 'data': { 'bar2': ['str'] }}
> > > > >
> > > > > for a 'bar2' field that is a list of type 'str', and so on.
> > > > >
> > > > > This uses linked list types for the native C representations, just as we do
> > > > > for complex schema-defined types. In the future we may add schema annotations
> > > > > of some sort to specify a more natural/efficient array type for the C
> > > > > representations, but this should serve the majority of uses-cases for now.
> > > >
> > > > I'm getting a build breakage when building all targets:
> > >
> > > Hmm, tested all target builds and didn't/don't see any issues. Is this a
> > > clean build? Can you confirm whether or not int8List/etc are declared in
> > > qapi-types.h in your current build dir?
> >
> > Yes, it's a clean build and yes, the int?List declarations are being generated.
> > Tested a little bit more and this also happens with make -j1 and when
> > building only one target (x86_64 in my case).
>
> The only way I've managed to reproduce this is by having a stale
> qapi-types.h hanging around in $SRC_DIR while i'm building in a
> different $BUILD_DIR. Can you confirm that's not what's happening here?
Yes, it was :( I had an old qapi-types.h in $SRC_DIR, but was building
in a different $BUILD_DIR. I am really sorry for having wasted your time
on this.
I've applied this series to qmp-next branch, but I have no idea how I ended
up with a qapi-types.h file in $SRC_DIR. I have an alias to build qemu that
I use for several months now...
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 18:05 ` Luiz Capitulino
@ 2013-05-15 19:13 ` mdroth
2013-05-16 10:38 ` Laszlo Ersek
0 siblings, 1 reply; 23+ messages in thread
From: mdroth @ 2013-05-15 19:13 UTC (permalink / raw)
To: Luiz Capitulino; +Cc: akong, lersek, qemu-devel
On Wed, May 15, 2013 at 02:05:58PM -0400, Luiz Capitulino wrote:
> On Wed, 15 May 2013 12:42:24 -0500
> mdroth <mdroth@linux.vnet.ibm.com> wrote:
>
> > On Wed, May 15, 2013 at 11:04:27AM -0400, Luiz Capitulino wrote:
> > > On Wed, 15 May 2013 09:32:37 -0500
> > > mdroth <mdroth@linux.vnet.ibm.com> wrote:
> > >
> > > > On Wed, May 15, 2013 at 09:17:46AM -0400, Luiz Capitulino wrote:
> > > > > On Fri, 10 May 2013 17:45:59 -0500
> > > > > Michael Roth <mdroth@linux.vnet.ibm.com> wrote:
> > > > >
> > > > > > These patches apply on top of qemu.git master, and can also be obtained from:
> > > > > > git://github.com/mdroth/qemu.git qapi-native-lists
> > > > > >
> > > > > > Sending this now since a number of series have popped up in the past that
> > > > > > wanted this, and Amos has some pending patches (query-mac-tables) that rely
> > > > > > on this as well.
> > > > > >
> > > > > > These patches add support for specifying lists of native qapi types
> > > > > > (int/bool/str/number/int8/uint8/etc) like so:
> > > > > >
> > > > > > { 'type': 'foo',
> > > > > > 'data': { 'bar': ['int'] }}
> > > > > >
> > > > > > for a 'bar' field that is a list of type 'int',
> > > > > >
> > > > > > { 'type': 'foo2',
> > > > > > 'data': { 'bar2': ['str'] }}
> > > > > >
> > > > > > for a 'bar2' field that is a list of type 'str', and so on.
> > > > > >
> > > > > > This uses linked list types for the native C representations, just as we do
> > > > > > for complex schema-defined types. In the future we may add schema annotations
> > > > > > of some sort to specify a more natural/efficient array type for the C
> > > > > > representations, but this should serve the majority of uses-cases for now.
> > > > >
> > > > > I'm getting a build breakage when building all targets:
> > > >
> > > > Hmm, tested all target builds and didn't/don't see any issues. Is this a
> > > > clean build? Can you confirm whether or not int8List/etc are declared in
> > > > qapi-types.h in your current build dir?
> > >
> > > Yes, it's a clean build and yes, the int?List declarations are being generated.
> > > Tested a little bit more and this also happens with make -j1 and when
> > > building only one target (x86_64 in my case).
> >
> > The only way I've managed to reproduce this is by having a stale
> > qapi-types.h hanging around in $SRC_DIR while i'm building in a
> > different $BUILD_DIR. Can you confirm that's not what's happening here?
>
> Yes, it was :( I had an old qapi-types.h in $SRC_DIR, but was building
> in a different $BUILD_DIR. I am really sorry for having wasted your time
> on this.
>
> I've applied this series to qmp-next branch, but I have no idea how I ended
> up with a qapi-types.h file in $SRC_DIR. I have an alias to build qemu that
> I use for several months now...
>
No problem, only thought to check that scenario because it happens to me
all the time :)
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-15 19:13 ` mdroth
@ 2013-05-16 10:38 ` Laszlo Ersek
2013-05-16 10:45 ` Peter Maydell
2013-05-17 20:06 ` mdroth
0 siblings, 2 replies; 23+ messages in thread
From: Laszlo Ersek @ 2013-05-16 10:38 UTC (permalink / raw)
To: mdroth; +Cc: akong, qemu-devel, Luiz Capitulino
On 05/15/13 21:13, mdroth wrote:
> On Wed, May 15, 2013 at 02:05:58PM -0400, Luiz Capitulino wrote:
>> On Wed, 15 May 2013 12:42:24 -0500
>> mdroth <mdroth@linux.vnet.ibm.com> wrote:
>>> The only way I've managed to reproduce this is by having a stale
>>> qapi-types.h hanging around in $SRC_DIR while i'm building in a
>>> different $BUILD_DIR. Can you confirm that's not what's happening here?
>>
>> Yes, it was :( I had an old qapi-types.h in $SRC_DIR, but was building
>> in a different $BUILD_DIR. I am really sorry for having wasted your time
>> on this.
>>
>> I've applied this series to qmp-next branch, but I have no idea how I ended
>> up with a qapi-types.h file in $SRC_DIR. I have an alias to build qemu that
>> I use for several months now...
>>
>
> No problem, only thought to check that scenario because it happens to me
> all the time :)
Side question: what's a common use case for a separate $BUILD_DIR? I
just use "git clean -fdx" in $SRC_DIR instead of "make clean". The need
to reconfigure (and to regenerate my tags file from scratch) is a small
price to pay for the peace of mind.
Thanks
Laszlo
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-16 10:38 ` Laszlo Ersek
@ 2013-05-16 10:45 ` Peter Maydell
2013-05-17 20:06 ` mdroth
1 sibling, 0 replies; 23+ messages in thread
From: Peter Maydell @ 2013-05-16 10:45 UTC (permalink / raw)
To: Laszlo Ersek; +Cc: Luiz Capitulino, akong, mdroth, qemu-devel
On 16 May 2013 11:38, Laszlo Ersek <lersek@redhat.com> wrote:
> Side question: what's a common use case for a separate $BUILD_DIR? I
> just use "git clean -fdx" in $SRC_DIR instead of "make clean". The need
> to reconfigure (and to regenerate my tags file from scratch) is a small
> price to pay for the peace of mind.
If you're in the habit of building for more than one config
(eg "native x86" plus "cross-compiled for ARM" it's nice
not to have to blow away the first set of object files to
build the second.
-- PMM
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types
2013-05-16 10:38 ` Laszlo Ersek
2013-05-16 10:45 ` Peter Maydell
@ 2013-05-17 20:06 ` mdroth
1 sibling, 0 replies; 23+ messages in thread
From: mdroth @ 2013-05-17 20:06 UTC (permalink / raw)
To: Laszlo Ersek; +Cc: akong, qemu-devel, Luiz Capitulino
On Thu, May 16, 2013 at 12:38:30PM +0200, Laszlo Ersek wrote:
> On 05/15/13 21:13, mdroth wrote:
> > On Wed, May 15, 2013 at 02:05:58PM -0400, Luiz Capitulino wrote:
> >> On Wed, 15 May 2013 12:42:24 -0500
> >> mdroth <mdroth@linux.vnet.ibm.com> wrote:
>
> >>> The only way I've managed to reproduce this is by having a stale
> >>> qapi-types.h hanging around in $SRC_DIR while i'm building in a
> >>> different $BUILD_DIR. Can you confirm that's not what's happening here?
> >>
> >> Yes, it was :( I had an old qapi-types.h in $SRC_DIR, but was building
> >> in a different $BUILD_DIR. I am really sorry for having wasted your time
> >> on this.
> >>
> >> I've applied this series to qmp-next branch, but I have no idea how I ended
> >> up with a qapi-types.h file in $SRC_DIR. I have an alias to build qemu that
> >> I use for several months now...
> >>
> >
> > No problem, only thought to check that scenario because it happens to me
> > all the time :)
>
> Side question: what's a common use case for a separate $BUILD_DIR? I
> just use "git clean -fdx" in $SRC_DIR instead of "make clean". The need
> to reconfigure (and to regenerate my tags file from scratch) is a small
> price to pay for the peace of mind.
I also do it for peace of mind, but I'm not particularly disciplined about
logging all my changes/new files into git as i go, so it's nice to be able to
do a clean build even when my $SRC_DIR is littered with abandoned
code/files/etc by simply wiping out the build dir.
I also have a number of situations where the resulting builds need to
be kept around for a while. For example I have build directories for
v1.1->v1.5 that I keep around for migration testing, other builds
for general usage, and a multitude of temp builds i might create to
compare upstream against a test/stable/development build. I could
use `make install` with an install prefix for this but for me it's quicker
to just use the binaries within the build directory.
Wasn't aware of `git clean` though, always just tried to make
due with `git reset --hard` + rm but that can get tedious at times.
>
> Thanks
> Laszlo
>
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2013-05-17 20:06 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-10 22:45 [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 01/11] qapi: qapi-types.py, native list support Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 02/11] qapi: qapi-visit.py, fix list handling for union types Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 03/11] qapi: qapi-visit.py, native list support Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 04/11] qapi: enable generation of native list code Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 05/11] qapi: fix leak in unit tests Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 06/11] json-parser: fix handling of large whole number values Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 07/11] qapi: add QMP input test for large integers Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 08/11] qapi: fix visitor serialization tests for numbers/doubles Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 09/11] qapi: add native list coverage for visitor serialization tests Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 10/11] qapi: add native list coverage for QMP output visitor tests Michael Roth
2013-05-10 22:46 ` [Qemu-devel] [PATCH 11/11] qapi: add native list coverage for QMP input " Michael Roth
2013-05-13 6:54 ` [Qemu-devel] [PATCH v3 00/11] qapi: add support for lists of native types Laszlo Ersek
2013-05-13 13:52 ` Amos Kong
2013-05-15 13:17 ` Luiz Capitulino
2013-05-15 14:32 ` mdroth
2013-05-15 15:04 ` Luiz Capitulino
2013-05-15 17:42 ` mdroth
2013-05-15 18:05 ` Luiz Capitulino
2013-05-15 19:13 ` mdroth
2013-05-16 10:38 ` Laszlo Ersek
2013-05-16 10:45 ` Peter Maydell
2013-05-17 20:06 ` mdroth
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).