[PULL 11/34] iotests: Add _filter_json_filename

Maintainers: Alberto Garcia <berto@igalia.com>, Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>, John Snow <jsnow@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Max Reitz <mreitz@redhat.com>, Kevin Wolf <kwolf@redhat.com>
There is a newer version of this series
[PULL 11/34] iotests: Add _filter_json_filename
Posted by Max Reitz 5 years, 3 months ago
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Message-id: 20191107163708.833192-5-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/common.filter | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.filter
index 5367deea39..116cc8a840 100644
--- a/tests/qemu-iotests/common.filter
+++ b/tests/qemu-iotests/common.filter
@@ -232,5 +232,29 @@ _filter_qmp_empty_return()
     grep -v '{"return": {}}'
 }
 
+_filter_json_filename()
+{
+    $PYTHON -c 'import sys
+result, *fnames = sys.stdin.read().split("json:{")
+depth = 0
+for fname in fnames:
+    depth += 1 # For the opening brace in the split separator
+    for chr_i, chr in enumerate(fname):
+        if chr == "{":
+            depth += 1
+        elif chr == "}":
+            depth -= 1
+            if depth == 0:
+                break
+
+    # json:{} filenames may be nested; filter out everything from
+    # inside the outermost one
+    if depth == 0:
+        chr_i += 1 # First character past the filename
+        result += "json:{ /* filtered */ }" + fname[chr_i:]
+
+sys.stdout.write(result)'
+}
+
 # make sure this script returns success
 true
-- 
2.24.1