Skip to contentSkip to conversation

Subject: Implement and test ASN.1 BER visitors

PATCH Superseded Stefan Berger 2 participants 14 messages Mar 21, 2013 – Mar 22, 2013

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Subject: Implement and test ASN.1 BER visitors

This patch series implements ASN.1 BER visitors for encoding and decoding of data into byte streams.

Stefan Berger (9):
Move some contents of savevm.c to qemu-file.c 3 new file wrappers
QEMUSizedBuffer
QAPI: add type_sized_buffer
ASN.1 output visitor
ASN.1 input visitor
Extend test-visitor-serialization with ASN.1 visitor(s) Update MAINTAINERS
ASN.1 specific test cases

 MAINTAINERS                        |    8 +
 configure                          |    2 +-
 include/migration/qemu-file.h      |   22 +
 include/qapi/ber-input-visitor.h   |   30 +
 include/qapi/ber-output-visitor.h  |   28 +
 include/qapi/ber.h                 |  107 ++++
 include/qapi/visitor-impl.h        |    3 +
 include/qapi/visitor.h             |    3 +
 include/qemu-common.h              |   14 +
 qapi/Makefile.objs                 |    1 +
 qapi/ber-common.c                  |   86 +++
 qapi/ber-common.h                  |   29 +
 qapi/ber-input-visitor.c           | 1141 +++++++++++++++++++++++++++++++++
 qapi/ber-output-visitor.c          |  673 ++++++++++++++++++++
 qapi/qapi-visit-core.c             |    8 +
 savevm.c                           |  690 --------------------
 tests/Makefile                     |   11 +-
 tests/test-ber-visitor.c           |  746 ++++++++++++++++++++++
 tests/test-visitor-serialization.c |   73 +++
 util/Makefile.objs                 |    1 +
 util/qemu-file.c                   | 1214 ++++++++++++++++++++++++++++++++++++
 21 files changed, 4198 insertions(+), 692 deletions(-)
 create mode 100644 include/qapi/ber-input-visitor.h
 create mode 100644 include/qapi/ber-output-visitor.h
 create mode 100644 include/qapi/ber.h
 create mode 100644 qapi/ber-common.c
 create mode 100644 qapi/ber-common.h
 create mode 100644 qapi/ber-input-visitor.c
 create mode 100644 qapi/ber-output-visitor.c
 create mode 100644 tests/test-ber-visitor.c
 create mode 100644 util/qemu-file.c
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v4 1/9 Move some contents of savevm.c to qemu-file.c

This patch reorganizes qemu file operations to be in their own source file instead of being lumped in savevm.c. Besides being more logical for maintenance it also makes it easier for future users of the file functions to add tests.

---
 include/migration/qemu-file.h |   6 +
 savevm.c                      | 690 ----------------------------------------
 util/Makefile.objs            |   1 +
 util/qemu-file.c              | 715 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 722 insertions(+), 690 deletions(-)
 create mode 100644 util/qemu-file.c
include/migration/qemu-file.h +6 -0
index df81261..7194b84 100644
@@ -98,6 +98,12 @@ void qemu_file_reset_rate_limit(QEMUFile *f);
 void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_get_error(QEMUFile *f);
+void qemu_file_set_error(QEMUFile *f, int ret);
+QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable);
+int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset);
+int qemu_peek_byte(QEMUFile *f, int offset);
+void qemu_file_skip(QEMUFile *f, int size);
+void qemu_fflush(QEMUFile *f);
 
 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
 {
savevm.c +0 -690

696 lines not on this page · raw message

util/Makefile.objs +1 -0
index 557bda7..df02fba 100644
@@ -10,3 +10,4 @@ util-obj-$(CONFIG_POSIX) += compatfd.o
 util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o
 util-obj-y += qemu-option.o qemu-progress.o
 util-obj-y += hexdump.o
+util-obj-y += qemu-file.o
util/qemu-file.c new file +715 -0

715 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v4 2/9 3 new file wrappers

In reply to Stefan Berger

Add 3 very short file wrapper functions to make code that follows more readable.

---
 include/migration/qemu-file.h |  3 +++
 util/qemu-file.c              | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
include/migration/qemu-file.h +3 -0
index 7194b84..728b6e2 100644
@@ -68,6 +68,9 @@ int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
 void qemu_put_byte(QEMUFile *f, int v);
+int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size);
+int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset);
+int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size);
 
 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
 {
util/qemu-file.c +30 -0
index 4fed6d5..f8a54e7 100644
@@ -713,3 +713,33 @@ uint64_t qemu_get_be64(QEMUFile *f)
     return v;
 }
 
+int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+    return qemu_get_buffer(f, buf, size);
+}
+
+int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+    return qemu_peek_buffer(f, buf, size, offset);
+}
+
+int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+
+    qemu_put_buffer(f, buf, size);
+
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+
+    return size;
+}
Signature · 1 line
1.7.11.7
#3 lore raw

PATCH v4 3/9 QEMUSizedBuffer

In reply to Stefan Berger

Using the QEMUFile interface, this patch adds support functions for operating on in-memory sized buffers that can be written to or read from.

---
 include/migration/qemu-file.h |  13 ++
 include/qemu-common.h         |  12 ++
 util/qemu-file.c              | 411 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 436 insertions(+)
include/migration/qemu-file.h +13 -0
index 728b6e2..0a297fc 100644
@@ -24,6 +24,8 @@
 #ifndef QEMU_FILE_H
 #define QEMU_FILE_H 1
 
+#include <stdint.h>
+
 /* This function writes a chunk of data to a file at the given position.
  * The pos argument can be ignored if the file is only being used for
  * streaming.  The handler should try to write all of the data it can.
@@ -58,6 +60,15 @@ typedef struct QEMUFileOps {
     QEMUFileGetFD *get_fd;
 } QEMUFileOps;
 
+struct QEMUSizedBuffer {
+    struct iovec *iov;
+    size_t n_iov;
+    size_t size; /* total allocated size in all iov's */
+    size_t used; /* number of used bytes */
+};
+
+typedef struct QEMUSizedBuffer QEMUSizedBuffer;
+
 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
 QEMUFile *qemu_fopen(const char *filename, const char *mode);
 QEMUFile *qemu_fdopen(int fd, const char *mode);
@@ -71,6 +82,8 @@ void qemu_put_byte(QEMUFile *f, int v);
 int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size);
 int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset);
 int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size);
+QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input);
+const QEMUSizedBuffer *qemu_buf_get(QEMUFile *f);
 
 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
 {
include/qemu-common.h +12 -0
index 7754ee2..7794fa7 100644
@@ -448,4 +448,16 @@ int uleb128_decode_small(const uint8_t *in, uint32_t *n);
 
 void hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
 
+/* QEMU Sized Buffer */
+#include "include/migration/qemu-file.h"
+QEMUSizedBuffer *qsb_create(const uint8_t *buffer, size_t len);
+QEMUSizedBuffer *qsb_clone(const QEMUSizedBuffer *);
+void qsb_free(QEMUSizedBuffer *);
+size_t qsb_set_length(QEMUSizedBuffer *qsb, size_t length);
+size_t qsb_get_length(const QEMUSizedBuffer *qsb);
+ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count,
+                       uint8_t **buf);
+ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *buf,
+                     off_t pos, size_t count);
+
 #endif
util/qemu-file.c +411 -0

414 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#4 lore raw

PATCH v4 4/9 QAPI: add type_sized_buffer

In reply to Stefan Berger

Add a sized buffer interface to qapi for serializing and deserializing of u8[], u16[], u32[] and u64[] with proper handling of endianess.

---
 include/qapi/visitor-impl.h | 3 +++
 include/qapi/visitor.h      | 3 +++
 qapi/qapi-visit-core.c      | 8 ++++++++
 3 files changed, 14 insertions(+)
include/qapi/visitor-impl.h +3 -0
index 5159964..be4e5ab 100644
@@ -34,6 +34,9 @@ struct Visitor
     void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
     void (*type_number)(Visitor *v, double *obj, const char *name,
                         Error **errp);
+    void (*type_sized_buffer)(Visitor *v, void **obj, const char *name,
+                              size_t elem_count, size_t elem_size,
+                              Error **errp);
 
     /* May be NULL */
     void (*start_optional)(Visitor *v, bool *present, const char *name,
include/qapi/visitor.h +3 -0
index 1fef18c..66ba4bf 100644
@@ -51,5 +51,8 @@ void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
+void visit_type_sized_buffer(Visitor *v, void **obj, const char *name,
+                             size_t elem_counter, size_t elem_size,
+                             Error **errp);
 
 #endif
qapi/qapi-visit-core.c +8 -0
index 401ee6e..374c0ff 100644
@@ -313,3 +313,11 @@ void input_type_enum(Visitor *v, int *obj, const char *strings[],
     g_free(enum_str);
     *obj = value;
 }
+
+void visit_type_sized_buffer(Visitor *v, void **obj, const char *name,
+                             size_t elem_count, size_t elem_size, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        v->type_sized_buffer(v, obj, name, elem_count, elem_size, errp);
+    }
+}
Signature · 1 line
1.7.11.7
#5 lore raw

PATCH v4 5/9 ASN.1 output visitor

In reply to Stefan Berger

Implement an output visitor for ASN.1 BER and CER encoding.

---
 configure                         |   2 +-
 include/qapi/ber-output-visitor.h |  28 ++
 include/qapi/ber.h                | 107 ++++++
 include/qemu-common.h             |   2 +
 qapi/Makefile.objs                |   1 +
 qapi/ber-common.c                 |  86 +++++
 qapi/ber-common.h                 |  29 ++
 qapi/ber-output-visitor.c         | 673 ++++++++++++++++++++++++++++++++++++++
 util/qemu-file.c                  |  58 ++++
 9 files changed, 985 insertions(+), 1 deletion(-)
 create mode 100644 include/qapi/ber-output-visitor.h
 create mode 100644 include/qapi/ber.h
 create mode 100644 qapi/ber-common.c
 create mode 100644 qapi/ber-common.h
 create mode 100644 qapi/ber-output-visitor.c
configure +1 -1
index 46a7594..5e1d69f 100755
@@ -2844,7 +2844,7 @@ fi
 # Do we need libm
 cat > $TMPC << EOF
 #include <math.h>
-int main(void) { return isnan(sin(0.0)); }
+int main(void) { return isnan(nan("NAN")); }
 EOF
 if compile_prog "" "" ; then
   :
include/qapi/ber-output-visitor.h new file +28 -0
new file mode 100644
index 0000000..bd7e198
@@ -0,0 +1,28 @@
+/*
+ * BER Output Visitor header
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *  Stefan Berger     <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef BER_OUTPUT_VISITOR_H
+#define BER_OUTPUT_VISITOR_H
+
+#include "qapi/visitor.h"
+#include "qapi/ber.h"
+
+typedef struct BEROutputVisitor BEROutputVisitor;
+
+BEROutputVisitor *ber_output_visitor_new(QEMUFile *, BERTypePC mode);
+void ber_output_visitor_cleanup(BEROutputVisitor *v);
+
+Visitor *ber_output_get_visitor(BEROutputVisitor *v);
+
+#endif
include/qapi/ber.h new file +107 -0

107 lines not on this page · raw message

include/qemu-common.h +2 -0
index 7794fa7..31ce759 100644
@@ -459,5 +459,7 @@ ssize_t qsb_get_buffer(const QEMUSizedBuffer *, off_t start, size_t count,
                        uint8_t **buf);
 ssize_t qsb_write_at(QEMUSizedBuffer *qsb, const uint8_t *buf,
                      off_t pos, size_t count);
+ssize_t qsb_qfile_write(const QEMUSizedBuffer *qsb, QEMUFile *file,
+                        off_t start, size_t count);
 
 #endif
qapi/Makefile.objs +1 -0
index 1f9c973..519e3ee 100644
@@ -3,3 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
 util-obj-y += string-input-visitor.o string-output-visitor.o
 
 util-obj-y += opts-visitor.o
+util-obj-y += ber-common.o ber-output-visitor.o
qapi/ber-common.c new file +86 -0

86 lines not on this page · raw message

qapi/ber-common.h new file +29 -0
new file mode 100644
index 0000000..c9fd2dd
@@ -0,0 +1,29 @@
+/*
+ * BER Visitor -- common code
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Stefan Berger     <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#ifndef __QAPI_BER_COMMON_H__
+#define __QAPI_BER_COMMON_H__
+
+#include <stdint.h>
+
+#include "qemu/compiler.h"
+
+struct ieee754_buffer {
+    uint8_t type;
+    uint8_t length;
+    uint8_t first;
+    uint16_t exponent;
+    uint32_t mant_hi;
+    uint32_t mant_lo;
+} QEMU_PACKED;
+
+#endif /* __QAPI_BER_COMMON_H__ */
qapi/ber-output-visitor.c new file +673 -0

673 lines not on this page · raw message

util/qemu-file.c +58 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#6 lore raw

PATCH v4 6/9 ASN.1 input visitor

In reply to Stefan Berger

Implement an input visitor for ASN.1 BER and CER encoding.

---
 include/qapi/ber-input-visitor.h |   30 +
 qapi/Makefile.objs               |    2 +-
 qapi/ber-input-visitor.c         | 1141 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1172 insertions(+), 1 deletion(-)
 create mode 100644 include/qapi/ber-input-visitor.h
 create mode 100644 qapi/ber-input-visitor.c
include/qapi/ber-input-visitor.h new file +30 -0
new file mode 100644
index 0000000..eaa3d0e
@@ -0,0 +1,30 @@
+/*
+ * BER Input Visitor header
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Anthony Liguori   <[email protected]>
+ *  Stefan Berger     <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef BER_INPUT_VISITOR_H
+#define BER_INPUT_VISITOR_H
+
+#include "qapi/visitor.h"
+
+typedef struct BERInputVisitor BERInputVisitor;
+
+BERInputVisitor *ber_input_visitor_new(QEMUFile *,
+                                       uint64_t max_allowd_buffer_size);
+void ber_input_visitor_cleanup(BERInputVisitor *v);
+uint64_t ber_input_get_parser_position(BERInputVisitor *v);
+uint64_t ber_input_get_largest_needed_buffer(BERInputVisitor *v);
+
+Visitor *ber_input_get_visitor(BERInputVisitor *v);
+
+#endif
qapi/Makefile.objs +1 -1
index 519e3ee..f7f080a 100644
@@ -3,4 +3,4 @@ util-obj-y += qmp-output-visitor.o qmp-registry.o qmp-dispatch.o
 util-obj-y += string-input-visitor.o string-output-visitor.o
 
 util-obj-y += opts-visitor.o
-util-obj-y += ber-common.o ber-output-visitor.o
+util-obj-y += ber-common.o ber-output-visitor.o ber-input-visitor.o
qapi/ber-input-visitor.c new file +1141 -0

1,141 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#7 lore raw

PATCH v4 7/9 Extend test-visitor-serialization with ASN.1 visitor(s)

In reply to Stefan Berger

Add BER visitor hooks to test-visitor-serialization

Cc Michael Tsirkin <[email protected]>
Cc Stefan Berger <[email protected]>
---
 tests/Makefile                     |  2 +-
 tests/test-visitor-serialization.c | 73 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
tests/Makefile +1 -1
index 567e36e..578d732 100644
@@ -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
 
tests/test-visitor-serialization.c +73 -0

97 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#8 lore raw

Re: [Qemu-devel] [PATCH v4 7/9] Extend test-visitor-serialization with ASN.1 visitor(s)

tests/test-visitor-serialization.c line 17

Quoted 13 lines · Stefan Berger

Add BER visitor hooks to test-visitor-serialization

Cc Michael Tsirkin <[email protected]>
Cc Stefan Berger <[email protected]>

---

+++ b/tests/test-visitor-serialization.c

tests/test-visitor-serialization.c +1 -0
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <float.h>
+#include <math.h>

Is this addition needed? I don't see any math functions added.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#9 lore raw

Re: [Qemu-devel] [PATCH v4 7/9] Extend test-visitor-serialization with ASN.1 visitor(s)

Quoted 9 lines · Eric Blake

tests/test-visitor-serialization.c line 17

Quoted 6 lines · Stefan Berger

+++ b/tests/test-visitor-serialization.c

tests/test-visitor-serialization.c +1 -0
@@ -14,6 +14,7 @@
  #include <stdlib.h>
  #include <stdint.h>
  #include <float.h>
+#include <math.h>

Is this addition needed? I don't see any math functions added.

Indeed. Removed.

Stefan

#10 lore raw

PATCH v4 8/9 Update MAINTAINERS

In reply to Stefan Berger

Since I'm throwing all this code out there I'm also signing up to maintain it. Send me your bug reports.

Cc Michael Tsirkin <[email protected]>
Cc Stefan Berger <[email protected]>
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 0ca7e1d..3e32ecb 100644
@@ -790,3 +790,11 @@ Stable 0.10
 L: [email protected]
 T: git git://git.qemu.org/qemu-stable-0.10.git
 S: Orphan
+
+Visitors
+---------------
+ASN.1 BER
+M: Stefan Berger <[email protected]>
+S: Maintained
+F: /qapi/ber*
+F: include/qapi/ber*
Signature · 1 line
1.7.11.7
#11 lore raw

PATCH v4 9/9 ASN.1 specific test cases

In reply to Stefan Berger

BER visitor tests give us some assurance that the BER visitor code works, and also end up by extention helping out on our code coverage of the filesystem tests.
After the output visitor invocation the resuling buffer is compared against a known byte stream -- this will lock the implementation into producing specific byte arrays.

---
 tests/Makefile           |   9 +
 tests/test-ber-visitor.c | 746 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 755 insertions(+)
 create mode 100644 tests/test-ber-visitor.c
tests/Makefile +9 -0
index 578d732..b74f90f 100644
@@ -23,6 +23,10 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
+check-unit-y += tests/test-ber-visitor$(EXESUF)
+gcov-files-test-vistor-y = qapi/ber-input-visitor.c
+
+
 check-unit-y += tests/test-coroutine$(EXESUF)
 ifeq ($(CONFIG_WIN32),y)
 gcov-files-test-coroutine-y = coroutine-win32.c
@@ -134,6 +138,11 @@ tests/fdc-test$(EXESUF): tests/fdc-test.o
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o
 
+tests/test-ber-visitor.o : QEMU_CFLAGS += -I include/qapi
+
+tests/test-ber-visitor.o: $(addprefix include/qapi/, ber.h ber-input-visitor.h ber-output-visitor.h) $(addprefix qapi/, ber-common.c ber-input-visitor.c ber-output-visitor.c)
+tests/test-ber-visitor$(EXESUF): tests/test-ber-visitor.o $(tools-obj-y) qapi/ber-output-visitor.o qapi/ber-input-visitor.o qapi/ber-common.o $(block-obj-y) libqemuutil.a libqemustub.a
+
 # QTest rules
 
 TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS)))
tests/test-ber-visitor.c new file +746 -0

746 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#12 lore raw

Re: [Qemu-devel] [PATCH v4 9/9] ASN.1 specific test cases

Quoted 2 lines · Stefan Berger

BER visitor tests give us some assurance that the BER visitor code works, and also end up by extention helping out on our

s/extention/extension/

Quoted 2 lines

code coverage of the filesystem tests.
After the output visitor invocation the resuling buffer is

s/resuling/resulting/

Quoted 12 lines

compared against a known byte stream -- this will lock the implementation into producing specific byte arrays.

---
 tests/Makefile           |   9 +
 tests/test-ber-visitor.c | 746 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 755 insertions(+)
 create mode 100644 tests/test-ber-visitor.c

tests/Makefile tests/fdc-test$(EXESUF): tests/fdc-test.o · line 144

Quoted 2 lines
tests/Makefile +2 -0
+tests/test-ber-visitor.o: $(addprefix include/qapi/, ber.h ber-input-visitor.h ber-output-visitor.h) $(addprefix qapi/, ber-common.c ber-input-visitor.c ber-output-visitor.c)
+tests/test-ber-visitor$(EXESUF): tests/test-ber-visitor.o $(tools-obj-y) qapi/ber-output-visitor.o qapi/ber-input-visitor.o qapi/ber-common.o $(block-obj-y) libqemuutil.a libqemustub.a

Long lines - worth using backslash-newline continuation?

tests/test-ber-visitor.c line 5

Quoted 7 lines

+++ b/tests/test-ber-visitor.c

tests/test-ber-visitor.c new file +5 -0
@@ -0,0 +1,746 @@
+/*
+ * BER Output Visitor unit-tests.
+ *
+ * Copyright (C) 2011 Red Hat Inc.
+ * Copyright (C) 2011 IBM Corporation

It's 2013 (probably applies to other files earlier in the series, as well).

tests/test-ber-visitor.c line 201

Quoted 4 lines
tests/test-ber-visitor.c new file +4 -0
+static void test_visitor_out_string(TestInputOutputVisitor *data,
+                                    const void *unused)
+{
+    char *string_in = (char *) "Q E M U", *string_out = NULL;

Does the fact that you have to cast here...

tests/test-ber-visitor.c line 204

Quoted 3 lines
tests/test-ber-visitor.c new file +3 -0
+    Error *errp = NULL;
+
+    visit_type_str(data->ov, &string_in, NULL, &errp);

...indicate a lack of const-correctness on visit_type_str()?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#13 lore raw

Re: [Qemu-devel] [PATCH v4 9/9] ASN.1 specific test cases

Quoted 4 lines · Eric Blake

tests/Makefile tests/fdc-test$(EXESUF): tests/fdc-test.o · line 144

Quoted 2 lines · Stefan Berger
tests/Makefile +2 -0
+tests/test-ber-visitor.o: $(addprefix include/qapi/, ber.h ber-input-visitor.h ber-output-visitor.h) $(addprefix qapi/, ber-common.c ber-input-visitor.c ber-output-visitor.c)
+tests/test-ber-visitor$(EXESUF): tests/test-ber-visitor.o $(tools-obj-y) qapi/ber-output-visitor.o qapi/ber-input-visitor.o qapi/ber-common.o $(block-obj-y) libqemuutil.a libqemustub.a

Long lines - worth using backslash-newline continuation?

Yes. Others are long but these lines are now the longest.

Quoted 16 lines

tests/test-ber-visitor.c line 5

Quoted 8 lines

+++ b/tests/test-ber-visitor.c

tests/test-ber-visitor.c new file +5 -0
@@ -0,0 +1,746 @@
+/*
+ * BER Output Visitor unit-tests.
+ *
+ * Copyright (C) 2011 Red Hat Inc.
+ * Copyright (C) 2011 IBM Corporation

It's 2013 (probably applies to other files earlier in the series, as well).

tests/test-ber-visitor.c line 201

Quoted 4 lines
tests/test-ber-visitor.c new file +4 -0
+static void test_visitor_out_string(TestInputOutputVisitor *data,
+                                    const void *unused)
+{
+    char *string_in = (char *) "Q E M U", *string_out = NULL;

Does the fact that you have to cast here...

Quoted 5 lines

tests/test-ber-visitor.c line 204

Quoted 3 lines
tests/test-ber-visitor.c new file +3 -0
+    Error *errp = NULL;
+
+    visit_type_str(data->ov, &string_in, NULL, &errp);

...indicate a lack of const-correctness on visit_type_str()?

The visitor interface is used for serialization and de-serialization. Upon de-serialization the underlying visitor can allocate memory for the string it found while decoding, so you can pass in a pointer to a NULL pointer and will get a valid pointer to the string back.

Stefan