Skip to contentSkip to conversation

qemu-iotests: Fix _filter_qemu

PATCH In review Kevin Wolf 4 participants 7 messages Apr 16, 2013

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qemu-iotests: Fix _filter_qemu

$QEMU_PROG happens to be 'qemu' in my setup, so this sed command replaces a bit too much. Restrict it to the start of the line and to when it's followed by a colon, i.e. the form used by error messages.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/common.filter +1 -1
index bc5f250..a7f889a 100644
@@ -155,7 +155,7 @@ _filter_qemu_io()
 # replace occurrences of QEMU_PROG with "qemu"
 _filter_qemu()
 {
-    sed -e "s#$(basename $QEMU_PROG)#QEMU_PROG#g"
+    sed -e "s#^$(basename $QEMU_PROG):#QEMU_PROG:#g"
 }
 
 # make sure this script returns success
Signature · 1 line
1.8.1.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Kevin Wolf

$QEMU_PROG happens to be 'qemu' in my setup, so this sed command replaces a bit too much. Restrict it to the start of the line and to when it's followed by a colon, i.e. the form used by error messages.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/common.filter +0 -0
index bc5f250..a7f889a 100644

tests/qemu-iotests/common.filter _filter_qemu_io() · line 158

Quoted 5 lines
tests/qemu-iotests/common.filter +1 -1
@@ -155,7 +155,7 @@ _filter_qemu_io()
 # replace occurrences of QEMU_PROG with "qemu"
 _filter_qemu()
 {
-    sed -e "s#$(basename $QEMU_PROG)#QEMU_PROG#g"
+    sed -e "s#^$(basename $QEMU_PROG):#QEMU_PROG:#g"

Why spawn a basename process, when you can use shell to do the same? Also, the g modifier is worthless once you have a ^ anchor, since sed can only replace one ^ per line. And you don't need sed's -e option for a single script.

The following is identical, with less typing:

_filter_qemu()

{
    sed "s#^${QEMU_PROG##*/}:#QEMU_PROG#"
}

That said, your more verbose version is still functionally correct, so you can add:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by
#2 lore raw
Quoted 10 lines · Eric Blake
Quoted 9 lines · Kevin Wolf

$QEMU_PROG happens to be 'qemu' in my setup, so this sed command replaces a bit too much. Restrict it to the start of the line and to when it's followed by a colon, i.e. the form used by error messages.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

tests/qemu-iotests/common.filter _filter_qemu_io() · line 158

Quoted 10 lines
tests/qemu-iotests/common.filter +1 -1
index bc5f250..a7f889a 100644
@@ -155,7 +155,7 @@ _filter_qemu_io()
 # replace occurrences of QEMU_PROG with "qemu"
 _filter_qemu()
 {
-    sed -e "s#$(basename $QEMU_PROG)#QEMU_PROG#g"
+    sed -e "s#^$(basename $QEMU_PROG):#QEMU_PROG:#g"

Why spawn a basename process, when you can use shell to do the same? Also, the g modifier is worthless once you have a ^ anchor, since sed can only replace one ^ per line. And you don't need sed's -e option for a single script.

sed -e is the convention in qemu-iotests.

Dropping the 'g' would be nice.

The problem with the POSIX shell string replacement is that the syntax is horrible. I can never remember what ${%}, ${%%}, ${#} and %{##} do. $(basename $QEMU_PROG) is clear (although it doesn't handle spaces in the filename!).

#3 lore raw
Quoted 8 lines · Stefan Hajnoczi
Quoted 3 lines
Quoted 1 line

+ sed -e "s#^$(basename $QEMU_PROG):#QEMU_PROG:#g"

Why spawn a basename process, when you can use shell to do the same?

The problem with the POSIX shell string replacement is that the syntax is horrible. I can never remember what ${%}, ${%%}, ${#} and %{##} do. $(basename $QEMU_PROG) is clear (although it doesn't handle spaces in the filename!).

As written, it also doesn't handle a leading '-' in the name. To be robust, it should be $(basename -- "$QEMU_PROG") - and even then, it still fails if $QEMU_PROG has a trailing newline (but no one is that perverse in how they name their program, right?). The shell variant never goofs on any of those corner cases. But I can totally understand your aversion to line noise, and as I'm doubtful that anyone will run the testsuite while trying to stress extreme corner-case $QEMU_PROG naming conventions, I can certainly live with keeping $(basename $QEMU_PROG) form for legibility.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#4 lore raw
In reply to Stefan Hajnoczi

Stefan Hajnoczi <[email protected]> writes:

[...]

Quoted 4 lines

The problem with the POSIX shell string replacement is that the syntax is horrible. I can never remember what ${%}, ${%%}, ${#} and %{##} do. $(basename $QEMU_PROG) is clear (although it doesn't handle spaces in the filename!).

Here's how I cope. # is left of % my keyboard. # matches "on the left", % "on the right". #/% are "short" and pick the shortest matching pattern. ##/%% are "long" and pick the longest matching pattern.

#5 lore raw
Quoted 11 lines · Markus Armbruster

Stefan Hajnoczi <[email protected]> writes:

[...]

Quoted 4 lines

The problem with the POSIX shell string replacement is that the syntax is horrible. I can never remember what ${%}, ${%%}, ${#} and %{##} do. $(basename $QEMU_PROG) is clear (although it doesn't handle spaces in the filename!).

Here's how I cope. # is left of % my keyboard. # matches "on the left", % "on the right". #/% are "short" and pick the shortest matching pattern. ##/%% are "long" and pick the longest matching pattern.

Nice :).

Stefan

author
#6 lore raw
In reply to Stefan Hajnoczi

Am 16.04.2013 um 15:16 hat Stefan Hajnoczi geschrieben:

Quoted 27 lines · Eric Blake
Quoted 10 lines · Kevin Wolf
Quoted 9 lines

$QEMU_PROG happens to be 'qemu' in my setup, so this sed command replaces a bit too much. Restrict it to the start of the line and to when it's followed by a colon, i.e. the form used by error messages.

---
 tests/qemu-iotests/common.filter | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

tests/qemu-iotests/common.filter _filter_qemu_io() · line 158

Quoted 10 lines
tests/qemu-iotests/common.filter +1 -1
index bc5f250..a7f889a 100644
@@ -155,7 +155,7 @@ _filter_qemu_io()
 # replace occurrences of QEMU_PROG with "qemu"
 _filter_qemu()
 {
-    sed -e "s#$(basename $QEMU_PROG)#QEMU_PROG#g"
+    sed -e "s#^$(basename $QEMU_PROG):#QEMU_PROG:#g"

Why spawn a basename process, when you can use shell to do the same? Also, the g modifier is worthless once you have a ^ anchor, since sed can only replace one ^ per line. And you don't need sed's -e option for a single script.

Quoted 3 lines

sed -e is the convention in qemu-iotests.

Dropping the 'g' would be nice.

Okay, I just updated the commit to drop the 'g'.

Quoted 4 lines

The problem with the POSIX shell string replacement is that the syntax is horrible. I can never remember what ${%}, ${%%}, ${#} and %{##} do. $(basename $QEMU_PROG) is clear (although it doesn't handle spaces in the filename!).

That's exactly my problem as well.

Kevin