aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/common.filter
blob: 3f8ee3e5f7d5d18fce5548ea4c35cf03e06d6c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/usr/bin/env bash
#
# Copyright (C) 2009 Red Hat, Inc.
# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# standard filters
#

_filter_date()
{
    $SED -re 's/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/yyyy-mm-dd hh:mm:ss/'
}

_filter_vmstate_size()
{
    $SED -r -e 's/[0-9. ]{5} [KMGT]iB/     SIZE/' \
            -e 's/[0-9. ]{5} B/   SIZE/'
}

_filter_generated_node_ids()
{
    $SED -re 's/\#block[0-9]{3,}/NODE_NAME/'
}

_filter_qom_path()
{
    $SED -e 's#\(Attached to: *\) /.*#\1 PATH#'
}

# replace occurrences of the actual TEST_DIR value with TEST_DIR
_filter_testdir()
{
    $SED -e "s#$TEST_DIR/#TEST_DIR/#g" \
         -e "s#$SOCK_DIR/#SOCK_DIR/#g"
}

# replace occurrences of the actual IMGFMT value with IMGFMT
_filter_imgfmt()
{
    $SED -e "s#$IMGFMT#IMGFMT#g"
}

# Replace error message when the format is not supported and delete
# the output lines after the first one
_filter_qemu_img_check()
{
    $SED -e '/allocated.*fragmented.*compressed clusters/d' \
        -e 's/qemu-img: This image format does not support checks/No errors were found on the image./' \
        -e '/Image end offset: [0-9]\+/d'
}

# Removes \r from messages
_filter_win32()
{
    $SED -e 's/\r//g'
}

# sanitize qemu-io output
_filter_qemu_io()
{
    _filter_win32 | $SED -e "s/[0-9]* ops\; [0-9/:. sec]* ([0-9/.inf]* [EPTGMKiBbytes]*\/sec and [0-9/.inf]* ops\/sec)/X ops\; XX:XX:XX.X (XXX YYY\/sec and XXX ops\/sec)/" \
        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
        -e "s/qemu-io> //g"
}

# replace occurrences of QEMU_PROG with "qemu"
_filter_qemu()
{
    $SED -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG):#\1QEMU_PROG:#" \
        -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#' \
        -e $'s#\r##' # QEMU monitor uses \r\n line endings
}

# replace problematic QMP output like timestamps
_filter_qmp()
{
    _filter_win32 | \
    $SED -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \
        -e 's#^{"QMP":.*}$#QMP_VERSION#' \
        -e '/^    "QMP": {\s*$/, /^    }\s*$/ c\' \
        -e '    QMP_VERSION'
}

# readline makes HMP command strings so long that git complains
_filter_hmp()
{
    $SED -e $'s/^\\((qemu) \\)\\?.*\e\\[D/\\1/g' \
        -e $'s/\e\\[K//g'
}

# replace block job offset
_filter_block_job_offset()
{
    $SED -e 's/, "offset": [0-9]\+,/, "offset": OFFSET,/'
}

# replace block job len
_filter_block_job_len()
{
    $SED -e 's/, "len": [0-9]\+,/, "len": LEN,/g'
}

# replace actual image size (depends on the host filesystem)
_filter_actual_image_size()
{
    $SED -s 's/\("actual-size":\s*\)[0-9]\+/\1SIZE/g'
}

# replace driver-specific options in the "Formatting..." line
_filter_img_create()
{
    data_file_filter=()
    if data_file=$(_get_data_file "$TEST_IMG"); then
        data_file_filter=(-e "s# data_file=$data_file##")
    fi

    $SED "${data_file_filter[@]}" \
        -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
        -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
        -e "s#$TEST_DIR#TEST_DIR#g" \
        -e "s#$SOCK_DIR#SOCK_DIR#g" \
        -e "s#$IMGFMT#IMGFMT#g" \
        -e 's#nbd:127.0.0.1:[0-9]\\+#TEST_DIR/t.IMGFMT#g' \
        -e 's#nbd+unix:///\??socket=SOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g' \
        -e "s# encryption=off##g" \
        -e "s# cluster_size=[0-9]\\+##g" \
        -e "s# table_size=[0-9]\\+##g" \
        -e "s# compat=[^ ]*##g" \
        -e "s# compat6=\\(on\\|off\\)##g" \
        -e "s# static=\\(on\\|off\\)##g" \
        -e "s# zeroed_grain=\\(on\\|off\\)##g" \
        -e "s# subformat=[^ ]*##g" \
        -e "s# adapter_type=[^ ]*##g" \
        -e "s# hwversion=[^ ]*##g" \
        -e "s# lazy_refcounts=\\(on\\|off\\)##g" \
        -e "s# block_size=[0-9]\\+##g" \
        -e "s# block_state_zero=\\(on\\|off\\)##g" \
        -e "s# log_size=[0-9]\\+##g" \
        -e "s# refcount_bits=[0-9]\\+##g" \
        -e "s# key-secret=[a-zA-Z0-9]\\+##g" \
        -e "s# iter-time=[0-9]\\+##g" \
        -e "s# force_size=\\(on\\|off\\)##g"
}

_filter_img_info()
{
    if [[ "$1" == "--format-specific" ]]; then
        local format_specific=1
        shift
    else
        local format_specific=0
    fi

    discard=0
    regex_json_spec_start='^ *"format-specific": \{'
    $SED -e "s#$REMOTE_TEST_DIR#TEST_DIR#g" \
        -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
        -e "s#$TEST_DIR#TEST_DIR#g" \
        -e "s#$SOCK_DIR#SOCK_DIR#g" \
        -e "s#$IMGFMT#IMGFMT#g" \
        -e 's#nbd://127.0.0.1:[0-9]\\+$#TEST_DIR/t.IMGFMT#g' \
        -e 's#nbd+unix:///\??socket=SOCK_DIR/nbd#TEST_DIR/t.IMGFMT#g' \
        -e 's#json.*vdisk-id.*vxhs"}}#TEST_DIR/t.IMGFMT#' \
        -e "/encrypted: yes/d" \
        -e "/cluster_size: [0-9]\\+/d" \
        -e "/table_size: [0-9]\\+/d" \
        -e "/compat: '[^']*'/d" \
        -e "/compat6: \\(on\\|off\\)/d" \
        -e "s/cid: [0-9]\+/cid: XXXXXXXXXX/" \
        -e "/static: \\(on\\|off\\)/d" \
        -e "/zeroed_grain: \\(on\\|off\\)/d" \
        -e "/subformat: '[^']*'/d" \
        -e "/adapter_type: '[^']*'/d" \
        -e "/hwversion: '[^']*'/d" \
        -e "/lazy_refcounts: \\(on\\|off\\)/d" \
        -e "/block_size: [0-9]\\+/d" \
        -e "/block_state_zero: \\(on\\|off\\)/d" \
        -e "/log_size: [0-9]\\+/d" \
        -e "s/iters: [0-9]\\+/iters: 1024/" \
        -e "s/uuid: [-a-f0-9]\\+/uuid: 00000000-0000-0000-0000-000000000000/" | \
    while IFS='' read -r line; do
        if [[ $format_specific == 1 ]]; then
            discard=0
        elif [[ $line == "Format specific information:" ]]; then
            discard=1
        elif [[ $line =~ $regex_json_spec_start ]]; then
            discard=2
            regex_json_spec_end="^${line%%[^ ]*}\\},? *$"
        fi
        if [[ $discard == 0 ]]; then
            echo "$line"
        elif [[ $discard == 1 && ! $line ]]; then
            echo
            discard=0
        elif [[ $discard == 2 && $line =~ $regex_json_spec_end ]]; then
            discard=0
        fi
    done
}

# filter out offsets and file names from qemu-img map; good for both
# human and json output
_filter_qemu_img_map()
{
    # Assuming the data_file value in $IMGOPTS contains a '$TEST_IMG',
    # create a filter that replaces the data file name by $TEST_IMG.
    # Example:
    #   In $IMGOPTS: 'data_file=$TEST_IMG.data_file'
    #   Then data_file_pattern == '\(.*\).data_file'
    #   And  data_file_filter  == -e 's#\(.*\).data_file#\1#
    data_file_filter=()
    if data_file_pattern=$(_get_data_file '\\(.*\\)'); then
        data_file_filter=(-e "s#$data_file_pattern#\\1#")
    fi

    $SED -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
        -e 's/"offset": [0-9]\+/"offset": OFFSET/g' \
        -e 's/Mapped to *//' \
        "${data_file_filter[@]}" \
        | _filter_testdir | _filter_imgfmt
}

_filter_nbd()
{
    # nbd.c error messages contain function names and line numbers that are
    # prone to change.  Message ordering depends on timing between send and
    # receive callbacks sometimes, making them unreliable.
    #
    # Filter out the TCP port number since this changes between runs.
    $SED -e '/nbd\/.*\.c:/d' \
        -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \
        -e "s#?socket=$SOCK_DIR#?socket=SOCK_DIR#g" \
        -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#'
}

_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