]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virshtest: Filter multiple occurences of string to drop in testFilterLine
authorPeter Krempa <pkrempa@redhat.com>
Wed, 20 Mar 2024 16:45:56 +0000 (17:45 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Apr 2024 12:24:30 +0000 (14:24 +0200)
Upcoming patches will require that possibly multiple occurences of the
string to drop are present in the output string thus we need to adapt
testFilterLine to handle them.

Additionally we drop the unused return value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/virshtest.c

index 4097c1d427bc6ff9aba406fe229427c6488fc042..e0b5cd31501497684d3faed84b91bae2c6650e7d 100644 (file)
@@ -90,21 +90,20 @@ device_read_bytes_sec: " SET_BLKIO_PARAMETER "\n\
 device_write_bytes_sec: " SET_BLKIO_PARAMETER "\n\
 \n";
 
-static int testFilterLine(char *buffer,
-                          const char *toRemove)
+static void testFilterLine(char *buffer,
+                           const char *toRemove)
 {
     char *start;
-    char *end;
 
-    if (!(start = strstr(buffer, toRemove)))
-      return -1;
+    while ((start = strstr(buffer, toRemove))) {
+        char *end;
 
-    if (!(end = strstr(start+1, "\n"))) {
-      *start = '\0';
-    } else {
-      memmove(start, end, strlen(end)+1);
+        if (!(end = strstr(start+1, "\n"))) {
+            *start = '\0';
+        } else {
+            memmove(start, end, strlen(end)+1);
+        }
     }
-    return 0;
 }
 
 static int
@@ -134,8 +133,8 @@ testCompareOutputLit(const char *expectFile,
         actual = g_strdup_printf("%s\n## Exit code: %d\n", tmp, exitstatus);
     }
 
-    if (filter && testFilterLine(actual, filter) < 0)
-        return -1;
+    if (filter)
+        testFilterLine(actual, filter);
 
     if (expectData) {
         if (virTestCompareToString(expectData, actual) < 0)