From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org, anthony@codemonkey.ws
Cc: jschopp@linux.vnet.ibm.com, coreyb@linux.vnet.ibm.com,
mdroth@linux.vnet.ibm.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH v5 7/8] Extend test-visitor-serialization with ASN.1 visitor(s)
Date: Thu, 28 Mar 2013 07:38:18 -0400 [thread overview]
Message-ID: <1364470699-16223-8-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1364470699-16223-1-git-send-email-stefanb@linux.vnet.ibm.com>
Add BER visitor hooks to test-visitor-serialization
Cc: Michael Tsirkin <mst@redhat.com>
Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
---
tests/Makefile | 2 +-
tests/test-visitor-serialization.c | 78 ++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/tests/Makefile b/tests/Makefile
index 567e36e..578d732 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -124,7 +124,7 @@ tests/test-qmp-output-visitor$(EXESUF): tests/test-qmp-output-visitor.o $(test-q
tests/test-qmp-input-visitor$(EXESUF): tests/test-qmp-input-visitor.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
tests/test-qmp-input-strict$(EXESUF): tests/test-qmp-input-strict.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
tests/test-qmp-commands$(EXESUF): tests/test-qmp-commands.o tests/test-qmp-marshal.o $(test-qapi-obj-y) qapi-types.o qapi-visit.o libqemuutil.a libqemustub.a
-tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) libqemuutil.a libqemustub.a
+tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) $(block-obj-y) libqemuutil.a libqemustub.a
tests/test-mul64$(EXESUF): tests/test-mul64.o libqemuutil.a
diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serialization.c
index 3c6b8df..ef3c8e8 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -23,6 +23,9 @@
#include "qapi/qmp-output-visitor.h"
#include "qapi/string-input-visitor.h"
#include "qapi/string-output-visitor.h"
+#include "qapi/ber-input-visitor.h"
+#include "qapi/ber-output-visitor.h"
+#include "migration/qemu-file.h"
typedef struct PrimitiveType {
union {
@@ -701,6 +704,66 @@ static void string_cleanup(void *datap)
string_input_visitor_cleanup(d->siv);
}
+
+typedef struct BERSerializeData {
+ BEROutputVisitor *sov;
+ QEMUFile *qoutfile;
+ BERInputVisitor *siv;
+ QEMUFile *qinfile;
+} BERSerializeData;
+
+static void ber_serialize(void *native_in, void **datap,
+ VisitorFunc visit, Error **errp,
+ BERLengthEncoding ber_length_encoding)
+{
+ BERSerializeData *d = g_malloc0(sizeof(*d));
+
+ d->qoutfile = qemu_bufopen("w", NULL);
+ d->sov = ber_output_visitor_new(d->qoutfile, ber_length_encoding);
+ visit(ber_output_get_visitor(d->sov), &native_in, errp);
+ *datap = d;
+}
+
+static void ber_definite_serialize(void *native_in, void **datap,
+ VisitorFunc visit, Error **errp)
+{
+ ber_serialize(native_in, datap, visit, errp,
+ BER_LENGTH_ENCODING_DEFINITE);
+}
+
+static void ber_indefinite_serialize(void *native_in, void **datap,
+ VisitorFunc visit, Error **errp)
+{
+ ber_serialize(native_in, datap, visit, errp,
+ BER_LENGTH_ENCODING_INDEFINITE);
+}
+
+static void ber_deserialize(void **native_out, void *datap,
+ VisitorFunc visit, Error **errp)
+{
+ BERSerializeData *d = datap;
+ const QEMUSizedBuffer *qsb = qemu_buf_get(d->qoutfile);
+ QEMUSizedBuffer *new_qsb = qsb_clone(qsb);
+ g_assert(new_qsb != NULL);
+
+ d->qinfile = qemu_bufopen("r", new_qsb);
+
+ d->siv = ber_input_visitor_new(d->qinfile, ~0);
+ visit(ber_input_get_visitor(d->siv), native_out, errp);
+}
+
+static void ber_cleanup(void *datap)
+{
+ BERSerializeData *d = datap;
+
+ ber_output_visitor_cleanup(d->sov);
+ ber_input_visitor_cleanup(d->siv);
+ qemu_fclose(d->qinfile);
+ qemu_fclose(d->qoutfile);
+ g_free(d);
+}
+
+
/* visitor registration, test harness */
/* note: to function interchangeably as a serialization mechanism your
@@ -722,6 +785,21 @@ static const SerializeOps visitors[] = {
.cleanup = string_cleanup,
.caps = VCAP_PRIMITIVES
},
+ {
+ .type = "ASN.1 BER indefinite l.e.",
+ .serialize = ber_indefinite_serialize,
+ .deserialize = ber_deserialize,
+ .cleanup = ber_cleanup,
+ .caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS
+ },
+ {
+ .type = "ASN.1 BER definite l.e.",
+ .serialize = ber_definite_serialize,
+ .deserialize = ber_deserialize,
+ .cleanup = ber_cleanup,
+ .caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS
+ },
+
{ NULL }
};
--
1.7.11.7
next prev parent reply other threads:[~2013-03-28 11:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-28 11:38 [Qemu-devel] [PATCH v5 0/8] Implement and test ASN.1 BER visitors Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 1/8] Move some contents of savevm.c to qemu-file.c Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 2/8] 3 new file wrappers Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 3/8] QEMUSizedBuffer Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 4/8] QAPI: add type_sized_buffer Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 5/8] ASN.1 output visitor Stefan Berger
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 6/8] ASN.1 input visitor Stefan Berger
2013-03-28 11:38 ` Stefan Berger [this message]
2013-03-28 11:38 ` [Qemu-devel] [PATCH v5 8/8] ASN.1 specific test cases Stefan Berger
2013-03-28 11:43 ` [Qemu-devel] [PATCH v5 0/8] Implement and test ASN.1 BER visitors Stefan Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364470699-16223-8-git-send-email-stefanb@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=anthony@codemonkey.ws \
--cc=coreyb@linux.vnet.ibm.com \
--cc=jschopp@linux.vnet.ibm.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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).