common.filter 5.0 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# 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
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 18 19 20 21 22 23 24 25 26
#
#
# standard filters
#

# ctime(3) dates
#
_filter_date()
{
    sed \
K
Kevin Wolf 已提交
27
        -e 's/[A-Z][a-z][a-z] [A-z][a-z][a-z]  *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] [0-9][0-9][0-9][0-9]$/DATE/'
28 29
}

J
Jeff Cody 已提交
30 31 32 33 34
_filter_generated_node_ids()
{
     sed -re 's/\#block[0-9]{3,}/NODE_NAME/'
}

35
# replace occurrences of the actual TEST_DIR value with TEST_DIR
36 37
_filter_testdir()
{
38
    sed -e "s#$TEST_DIR/#TEST_DIR/#g"
39 40
}

41 42 43 44 45 46
# replace occurrences of the actual IMGFMT value with IMGFMT
_filter_imgfmt()
{
    sed -e "s#$IMGFMT#IMGFMT#g"
}

R
Reda Sallahi 已提交
47 48 49 50 51 52 53 54 55
# 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'
}

56 57 58 59 60 61
# Removes \r from messages
_filter_win32()
{
    sed -e 's/\r//g'
}

62 63 64
# sanitize qemu-io output
_filter_qemu_io()
{
65
    _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)/" \
66
        -e "s/: line [0-9][0-9]*:  *[0-9][0-9]*\( Aborted\| Killed\)/:\1/" \
67
        -e "s/qemu-io> //g"
68 69
}

70 71 72
# replace occurrences of QEMU_PROG with "qemu"
_filter_qemu()
{
73
    sed -e "s#\\(^\\|(qemu) \\)$(basename $QEMU_PROG):#\1QEMU_PROG:#" \
74
        -e 's#^QEMU [0-9]\+\.[0-9]\+\.[0-9]\+ monitor#QEMU X.Y.Z monitor#' \
75
        -e '/main-loop: WARNING: I\/O thread spun for [0-9]\+ iterations/d' \
76
        -e $'s#\r##' # QEMU monitor uses \r\n line endings
77 78
}

79 80 81 82 83
# replace problematic QMP output like timestamps
_filter_qmp()
{
    _filter_win32 | \
    sed -e 's#\("\(micro\)\?seconds": \)[0-9]\+#\1 TIMESTAMP#g' \
84 85 86
        -e 's#^{"QMP":.*}$#QMP_VERSION#' \
        -e '/^    "QMP": {\s*$/, /^    }\s*$/ c\' \
        -e '    QMP_VERSION'
87 88
}

V
Vladimir Sementsov-Ogievskiy 已提交
89 90 91 92 93 94
# replace block job offset
_filter_block_job_offset()
{
    sed -e 's/, "offset": [0-9]\+,/, "offset": OFFSET,/'
}

95 96 97 98 99 100 101 102 103
# replace driver-specific options in the "Formatting..." line
_filter_img_create()
{
    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
        -e "s#$TEST_DIR#TEST_DIR#g" \
        -e "s#$IMGFMT#IMGFMT#g" \
        -e "s# encryption=off##g" \
        -e "s# cluster_size=[0-9]\\+##g" \
        -e "s# table_size=[0-9]\\+##g" \
104
        -e "s# compat=[^ ]*##g" \
105 106 107 108 109
        -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" \
110
        -e "s# hwversion=[^ ]*##g" \
111 112 113 114
        -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" \
115 116
        -e "s# refcount_bits=[0-9]\\+##g" \
        -e "s# key-secret=[a-zA-Z0-9]\\+##g"
117 118
}

119 120 121 122 123
_filter_img_info()
{
    sed -e "s#$IMGPROTO:$TEST_DIR#TEST_DIR#g" \
        -e "s#$TEST_DIR#TEST_DIR#g" \
        -e "s#$IMGFMT#IMGFMT#g" \
M
Max Reitz 已提交
124
        -e 's#nbd://127.0.0.1:10810$#TEST_DIR/t.IMGFMT#g' \
125 126 127 128 129 130 131 132 133
        -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 "/static: \\(on\\|off\\)/d" \
        -e "/zeroed_grain: \\(on\\|off\\)/d" \
        -e "/subformat: '[^']*'/d" \
        -e "/adapter_type: '[^']*'/d" \
134
        -e "/hwversion: '[^']*'/d" \
135 136 137
        -e "/lazy_refcounts: \\(on\\|off\\)/d" \
        -e "/block_size: [0-9]\\+/d" \
        -e "/block_state_zero: \\(on\\|off\\)/d" \
138
        -e "/log_size: [0-9]\\+/d"
139 140
}

M
Max Reitz 已提交
141 142 143 144 145 146 147
# filter out offsets and file names from qemu-img map
_filter_qemu_img_map()
{
    sed -e 's/\([0-9a-fx]* *[0-9a-fx]* *\)[0-9a-fx]* */\1/g' \
        -e 's/Mapped to *//' | _filter_testdir | _filter_imgfmt
}

148 149 150 151 152 153 154
_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.
155
    sed -e '/nbd\/.*\.c:/d' \
156 157
        -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \
        -e "s#?socket=$TEST_DIR#?socket=TEST_DIR#g" \
158 159 160
        -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#'
}

161
# make sure this script returns success
162
true