Skip to contentSkip to conversation

Add virtio-blk-drive-serial test

PATCH Applied Ryan Harper 3 participants 6 messages Jan 13, 2012 – Jan 16, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add virtio-blk-drive-serial test

We can test out the virtio-blk drive serial number by generating and then reading it back via the file in sysfs.

---
 tests/virtio-blk-drive-serial.sh |   40 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
 create mode 100755 tests/virtio-blk-drive-serial.sh
tests/virtio-blk-drive-serial.sh new file +40 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
+    echo "Expected '$serial', got '$guest_serial'"
+    return 2
+    fi
+
+    return 0
+}
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi
Signature · 1 line
1.7.6
#1 lore raw
Quoted 39 lines · Ryan Harper

We can test out the virtio-blk drive serial number by generating and then reading it back via the file in sysfs.

---
 tests/virtio-blk-drive-serial.sh |   40 ++++++++++++++++++++++++++++++++++++++

 1 files changed, 40 insertions(+), 0 deletions(-)

 create mode 100755 tests/virtio-blk-drive-serial.sh

tests/virtio-blk-drive-serial.sh new file +24 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+

tests/virtio-blk-drive-serial.sh line 34

Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +10 -0
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
+    echo "Expected '$serial', got '$guest_serial'"
+    return 2
+    fi
+
+    return 0
+}

How will you make in_guest() run in that guest system?

Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +6 -1
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi
--

1.7.6

Signature · 3 lines
Regards,

Zhi Yong Wu
#2 lore raw
Quoted 69 lines · Zhi Yong Wu
Quoted 39 lines · Ryan Harper

We can test out the virtio-blk drive serial number by generating and then reading it back via the file in sysfs.

---
 tests/virtio-blk-drive-serial.sh |   40 ++++++++++++++++++++++++++++++++++++++

 1 files changed, 40 insertions(+), 0 deletions(-)

 create mode 100755 tests/virtio-blk-drive-serial.sh

tests/virtio-blk-drive-serial.sh new file +24 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+

tests/virtio-blk-drive-serial.sh line 34

Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +10 -0
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
+    echo "Expected '$serial', got '$guest_serial'"
+    return 2
+    fi
+
+    return 0
+}

How will you make in_guest() run in that guest system? From the code below, i guess that qtest framework make sure it.

Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +6 -1
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi
--

1.7.6

--
Regards,

Zhi Yong Wu

Signature · 3 lines
Regards,

Zhi Yong Wu
#3 lore raw
Quoted 45 lines · Zhi Yong Wu
Quoted 44 lines · Zhi Yong Wu
Quoted 43 lines · Ryan Harper

We can test out the virtio-blk drive serial number by generating and then reading it back via the file in sysfs.

---
  tests/virtio-blk-drive-serial.sh |   40 ++++++++++++++++++++++++++++++++++++++
  1 files changed, 40 insertions(+), 0 deletions(-)

create mode 100755 tests/virtio-blk-drive-serial.sh

tests/virtio-blk-drive-serial.sh new file +28 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
Quoted 8 lines
Quoted 8 lines

tests/virtio-blk-drive-serial.sh line 34

Quoted 6 lines
tests/virtio-blk-drive-serial.sh new file +6 -0
+    echo "Expected '$serial', got '$guest_serial'"
+    return 2
+    fi
+
+    return 0
+}

How will you make in_guest() run in that guest system? From the code below, i guess that qtest framework make sure it.

qemu-test. qtest is something different.

The script is copied into the initramfs used to run the guest. QEMU_TEST=1 only in the host so the code below invokes in_guest only in the guest.

Regards,

Anthony Liguori

Quoted 20 lines
Quoted 17 lines
Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +6 -1
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi
--

1.7.6

--
Regards,

Zhi Yong Wu

#4 lore raw
Quoted 66 lines · Anthony Liguori
Quoted 55 lines · Zhi Yong Wu
Quoted 53 lines · Zhi Yong Wu
Quoted 51 lines · Ryan Harper

We can test out the virtio-blk drive serial number by generating and then
reading it back via the file in sysfs.

---
 tests/virtio-blk-drive-serial.sh |   40
++++++++++++++++++++++++++++++++++++++

 1 files changed, 40 insertions(+), 0 deletions(-)

 create mode 100755 tests/virtio-blk-drive-serial.sh

tests/virtio-blk-drive-serial.sh new file +10 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive

file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?

tests/virtio-blk-drive-serial.sh new file +17 -0
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
+    echo "Expected '$serial', got '$guest_serial'"
Quoted 8 lines
Quoted 8 lines

tests/virtio-blk-drive-serial.sh line 34

Quoted 5 lines

+    return 2
+    fi

tests/virtio-blk-drive-serial.sh new file +3 -0
+
+    return 0
+}

How will you make in_guest() run in that guest system? From the code below, i guess that qtest framework make sure it.

Quoted 4 lines

qemu-test.  qtest is something different.

The script is copied into the initramfs used to run the guest.  QEMU_TEST=1 only in the host so the code below invokes in_guest only in the guest.

thanks.

Quoted 28 lines

Regards,

Anthony Liguori

Quoted 21 lines
Quoted 17 lines
Quoted 10 lines
tests/virtio-blk-drive-serial.sh new file +6 -1
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi
--

1.7.6

--
Regards,

Zhi Yong Wu

Signature · 3 lines
Regards,

Zhi Yong Wu
#5 lore raw
In reply to Ryan Harper
Quoted 4 lines · Ryan Harper

We can test out the virtio-blk drive serial number by generating and then reading it back via the file in sysfs.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 51 lines
---
  tests/virtio-blk-drive-serial.sh |   40 ++++++++++++++++++++++++++++++++++++++
  1 files changed, 40 insertions(+), 0 deletions(-)

create mode 100755 tests/virtio-blk-drive-serial.sh

tests/virtio-blk-drive-serial.sh new file +40 -0
new file mode 100755
index 0000000..0586f97
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+serial="0123456789abcdefghi"
+
+in_host() {
+    tmpdisk=$tmpdir/disk.img
+    qemu-img create -f qcow2 $tmpdisk 10G
+
+    qemu -nographic -enable-kvm \
+    -drive file=$tmpdisk,if=none,id=drive-virtio-disk0,format=raw,cache=none,serial=$serial \
+    -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
+    rc=$?
+
+    rm $tmpdisk
+    return $rc
+}
+
+in_guest() {
+    sysfspath=/sys/block/vda
+    if ! test -e $sysfspath; then
+    echo "Device not visible!"
+    return 1
+    fi
+
+    guest_serial=`cat $sysfspath/serial`
+
+    if test "$guest_serial" != "$serial"; then
+    echo "drive has wrong serial!"
+    echo "Expected '$serial', got '$guest_serial'"
+    return 2
+    fi
+
+    return 0
+}
+
+if test $QEMU_TEST; then
+    in_host
+else
+    in_guest
+fi