[PATCH RFC 8/8] fdstreamtest: test virStreamSendOffset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/fdstreamtest.c | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)

diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c
index 5036cec..4fc88a7 100644
--- a/tests/fdstreamtest.c
+++ b/tests/fdstreamtest.c
@@ -220,9 +220,12 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
     virStreamPtr st = NULL;
     size_t i;
     virConnectPtr conn = NULL;
+    unsigned long long streamOffset;
+    unsigned long long streamLength;
     bool blocking = !(flags & VIR_STREAM_NONBLOCK);
+    bool sparse = flags & VIR_STREAM_SPARSE;
 
-    virCheckFlags(VIR_STREAM_NONBLOCK, -1);
+    virCheckFlags(VIR_STREAM_NONBLOCK | VIR_STREAM_SPARSE, -1);
 
     if (!(conn = virConnectOpen("test:///default")))
         goto cleanup;
@@ -243,8 +246,11 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
     /* Start writing 1/2 way through first pattern
      * and end 1/2 way through last pattern
      */
+    streamOffset = PATTERN_LEN / 2;
+    streamLength = sparse ? PATTERN_LEN * 8192 : PATTERN_LEN * 9;
     if (virFDStreamCreateFile(st, file,
-                              PATTERN_LEN / 2, PATTERN_LEN * 9,
+                              streamOffset,
+                              streamLength,
                               O_WRONLY, 0600) < 0)
         goto cleanup;
 
@@ -258,8 +264,11 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
 
         while (want > 0) {
             int got;
-        rewrite:
-            got = st->driver->streamSend(st, pattern + offset, want);
+         rewrite:
+            if (sparse)
+                got = st->driver->streamSendOffset(st, streamOffset, pattern + offset, want);
+            else
+                got = st->driver->streamSend(st, pattern + offset, want);
             if (got < 0) {
                 if (got == -2 && !blocking) {
                     usleep(20 * 1000);
@@ -272,6 +281,10 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
                               virGetLastErrorMessage());
                 goto cleanup;
             }
+            if (i == 0)
+                streamOffset = 8192 + PATTERN_LEN;
+            else
+                streamOffset += 8192 + PATTERN_LEN;
             offset += got;
             want -= got;
         }
@@ -286,6 +299,7 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
     if ((fd = open(file, O_RDONLY)) < 0)
         goto cleanup;
 
+    streamOffset = 0;
     for (i = 0; i < 10; i++) {
         size_t want;
         if (i == 9)
@@ -293,6 +307,12 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
         else
             want = PATTERN_LEN;
 
+        if (sparse &&
+            lseek(fd, streamOffset, SEEK_SET) < 0) {
+            virFilePrintf(stderr, "unable to seek");
+            goto cleanup;
+        }
+
         if (saferead(fd, buf, want) != want) {
             virFilePrintf(stderr, "Short read from data\n");
             goto cleanup;
@@ -321,6 +341,11 @@ static int testFDStreamWriteCommon(const char *scratchdir, const unsigned int fl
                 goto cleanup;
             }
         }
+
+        if (i == 0)
+            streamOffset = 8192 + PATTERN_LEN;
+        else
+            streamOffset += 8192 + PATTERN_LEN;
     }
 
     if (VIR_CLOSE(fd) < 0)
@@ -350,6 +375,10 @@ static int testFDStreamWriteNonblock(const void *data)
 {
     return testFDStreamWriteCommon(data, false);
 }
+static int testFDStreamSparseWriteBlock(const void *data)
+{
+    return testFDStreamWriteCommon(data, VIR_STREAM_SPARSE);
+}
 
 #define SCRATCHDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
 
@@ -374,6 +403,8 @@ mymain(void)
         ret = -1;
     if (virtTestRun("Sparse stream read blocking ", testFDStreamSparseReadBlock, scratchdir) < 0)
         ret = -1;
+    if (virtTestRun("Sparse stream write blocking ", testFDStreamSparseWriteBlock, scratchdir) < 0)
+        ret = -1;
 
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(scratchdir);
-- 
2.4.10

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]