diff options
author | John Snow <jsnow@redhat.com> | 2015-05-22 14:13:44 -0400 |
---|---|---|
committer | John Snow <jsnow@redhat.com> | 2015-05-22 15:58:22 -0400 |
commit | 7a6a740d8dcc02f5693315d7935b5de9b963bb96 (patch) | |
tree | a2e267889145f6cff4d1af159684568d19bd16a8 /tests/libqtest.c | |
parent | 332cc7e9b39ddb2feacb4c71dcd18c3e5b0c3147 (diff) |
qtest: Add base64 encoded read/write
For larger pieces of data that won't need to be debugged and
viewing the hex nibbles is unlikely to be useful, we can encode
data using base64 instead of encoding each byte as %02x, which
leads to some space savings and faster reads/writes.
For now, the default is left as hex nibbles in memwrite() and memread().
For the purposes of making qtest io easier to read and debug, some
callers may want to specify using the old encoding format for small
patches of data where the savings from base64 wouldn't be that profound.
memwrite/memread use a data encoding that takes 2x the size of the original
buffer, but base64 uses "only" (4/3)x, so for larger buffers we can save a
decent amount of time and space.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-id: 1430864578-22072-3-git-send-email-jsnow@redhat.com
Diffstat (limited to 'tests/libqtest.c')
-rw-r--r-- | tests/libqtest.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/libqtest.c b/tests/libqtest.c index a525dc532c..5f57005447 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -695,6 +695,37 @@ void qtest_add_data_func(const char *str, const void *data, void (*fn)) g_free(path); } +void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size) +{ + gchar *bdata; + + bdata = g_base64_encode(data, size); + qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); + socket_send(s->fd, bdata, strlen(bdata)); + socket_send(s->fd, "\n", 1); + qtest_rsp(s, 0); + g_free(bdata); +} + +void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size) +{ + gchar **args; + size_t len; + + qtest_sendf(s, "b64read 0x%" PRIx64 " 0x%zx\n", addr, size); + args = qtest_rsp(s, 2); + + g_base64_decode_inplace(args[1], &len); + if (size != len) { + fprintf(stderr, "bufread: asked for %zu bytes but decoded %zu\n", + size, len); + len = MIN(len, size); + } + + memcpy(data, args[1], len); + g_strfreev(args); +} + void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size) { const uint8_t *ptr = data; |