>From 0c4ffccc7258dcff94cc40abcf470a3c5ad788c3 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 14 Oct 2014 14:31:08 +0200 Subject: [PATCH 2/2] tests: Enable streaming test. --- plugins/streaming/streaming.c | 13 +++++++++++-- tests/Makefile.am | 17 +++++------------ tests/test-streaming.c | 16 +++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/plugins/streaming/streaming.c b/plugins/streaming/streaming.c index 2d08803..da4de63 100644 --- a/plugins/streaming/streaming.c +++ b/plugins/streaming/streaming.c @@ -35,6 +35,8 @@ #include #include +#include +#include #include #include #include @@ -232,6 +234,10 @@ streaming_pwrite (void *handle, const void *buf, return -1; } + nbdkit_debug ("pwrite: offset=%" PRIi64 " count=%" PRIu32 + " highestwrite=%" PRIu64, + offset, count, highestwrite); + /* This just makes the recursive case easier to reason about. */ if (count == 0) return 0; @@ -239,7 +245,8 @@ streaming_pwrite (void *handle, const void *buf, windowstart = highestwrite - window_size; if (offset < windowstart) { - nbdkit_error ("client seeked backwards > window size: you must increase the window size"); + nbdkit_error ("pwrite: client backwards seek > window size: you must increase the window size (highestwrite=%" PRIu64 ", window_size=%" PRIi64 ")", + highestwrite, window_size); errorstate = 1; errno = EIO; return -1; @@ -298,6 +305,7 @@ streaming_pwrite (void *handle, const void *buf, window = new_window; /* Make sure the extended window is zeroes to start with. */ memset (&window[window_size], 0, new_size - window_size); + window_size = new_size; highestwrite = new_highestwrite; /* Copy the buffer to the new window. */ memcpy (&window[offset - windowstart], buf, count); @@ -374,7 +382,8 @@ streaming_pread (void *handle, void *buf, uint32_t count, uint64_t offset) windowstart = highestwrite - window_size; if (offset < windowstart) { - nbdkit_error ("client seeked backwards > window size: you must increase the window size"); + nbdkit_error ("pread: client backwards seek > window size: you must increase the window size (highestwrite=%" PRIu64 ", window_size=%" PRIi64 ")", + highestwrite, window_size); errorstate = 1; errno = EIO; return -1; diff --git a/tests/Makefile.am b/tests/Makefile.am index a50e26b..cccd45b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -172,18 +172,11 @@ test_python_LDADD = libtest.la $(LIBGUESTFS_LIBS) endif # streaming plugin test. +check_PROGRAMS += test-streaming +TESTS += test-streaming -# This is disabled at the moment because the libguestfs appliance -# kernel tries to read from the device (eg to read the partition -# table) and the current streaming plugin cannot handle this. -# Implementing a sliding window in the plugin would fix this. (XXX) -EXTRA_DIST += test-streaming.c - -#check_PROGRAMS += test-streaming -#TESTS += test-streaming -# -#test_streaming_SOURCES = test-streaming.c test.h -#test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS) -#test_streaming_LDADD = libtest.la $(LIBGUESTFS_LIBS) +test_streaming_SOURCES = test-streaming.c test.h +test_streaming_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS) +test_streaming_LDADD = libtest.la $(LIBGUESTFS_LIBS) endif diff --git a/tests/test-streaming.c b/tests/test-streaming.c index 1631c19..4610fb9 100644 --- a/tests/test-streaming.c +++ b/tests/test-streaming.c @@ -48,7 +48,7 @@ #include "test.h" -static char data[4096]; +static char data[1024]; int main (int argc, char *argv[]) @@ -69,6 +69,8 @@ main (int argc, char *argv[]) if (test_start_nbdkit (NBDKIT_PLUGIN ("streaming"), "pipe=streaming.fifo", + "size=128k", + "window=128k", NULL) == -1) exit (EXIT_FAILURE); @@ -121,14 +123,10 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); /* Write linearly to the virtual disk. */ - for (i = 0; i < 10; ++i) { - memset (data, i+1, sizeof data); - - /* Note that we deliberately skip forwards, in order to - * exercise seeking code in the streaming plugin. - */ + memset (data, 1, sizeof data); + for (i = 0; i < 32; ++i) { guestfs_pwrite_device (g, "/dev/sda", data, sizeof data, - (2 * i) * sizeof data); + i * sizeof data); } if (guestfs_shutdown (g) == -1) @@ -148,7 +146,7 @@ main (int argc, char *argv[]) } md5[32] = '\0'; - if (strcmp (md5, "0123456789abcdef0123456789abcdef") != 0) { + if (strcmp (md5, "51ae9fa5fb90e9d51c4f1b4260285c99") != 0) { fprintf (stderr, "unexpected hash: %s\n", md5); exit (EXIT_FAILURE); } -- 2.0.4