168 lines
4.9 KiB
Diff
168 lines
4.9 KiB
Diff
From fdbd0ef69f0c222d0cdc35d3c48297aff549abce Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Fri, 13 Dec 2019 15:38:09 +0000
|
|
Subject: [PATCH 1/2] tests: Reduce excessive time taken by some tests.
|
|
|
|
For context see:
|
|
https://www.redhat.com/archives/libguestfs/2019-December/msg00074.html
|
|
|
|
This is mainly about changing tests to use libnbd/nbdsh instead of
|
|
libguestfs where libguestfs isn't really necessary for the test.
|
|
---
|
|
tests/test-cache-on-read.sh | 37 ++++++++++++++++---------------------
|
|
tests/test-cache.sh | 37 ++++++++++++++++++++-----------------
|
|
tests/test-cow.sh | 9 ++++++---
|
|
3 files changed, 42 insertions(+), 41 deletions(-)
|
|
|
|
diff --git a/tests/test-cache-on-read.sh b/tests/test-cache-on-read.sh
|
|
index 4ecf3af..6196373 100755
|
|
--- a/tests/test-cache-on-read.sh
|
|
+++ b/tests/test-cache-on-read.sh
|
|
@@ -30,15 +30,11 @@
|
|
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
# SUCH DAMAGE.
|
|
|
|
-# XXX Suggestion to improve this test: Use the delay filter below the
|
|
-# cache filter, and time reads to prove that the second read is faster
|
|
-# because it isn't going through the delay filter and plugin.
|
|
-
|
|
source ./functions.sh
|
|
set -e
|
|
set -x
|
|
|
|
-requires guestfish --version
|
|
+requires nbdsh --version
|
|
|
|
sock=`mktemp -u`
|
|
files="cache-on-read.img $sock cache-on-read.pid"
|
|
@@ -46,7 +42,7 @@ rm -f $files
|
|
cleanup_fn rm -f $files
|
|
|
|
# Create an empty base image.
|
|
-truncate -s 1G cache-on-read.img
|
|
+truncate -s 128K cache-on-read.img
|
|
|
|
# Run nbdkit with the caching filter and cache-on-read set.
|
|
start_nbdkit -P cache-on-read.pid -U $sock \
|
|
@@ -54,19 +50,18 @@ start_nbdkit -P cache-on-read.pid -U $sock \
|
|
file cache-on-read.img \
|
|
cache-on-read=true
|
|
|
|
-# Open the overlay and perform some operations.
|
|
-guestfish --format=raw -a "nbd://?socket=$sock" <<'EOF'
|
|
- run
|
|
- part-disk /dev/sda gpt
|
|
- mkfs ext4 /dev/sda1
|
|
- mount /dev/sda1 /
|
|
- fill-dir / 10000
|
|
- fill-pattern "abcde" 5M /large
|
|
- write /hello "hello, world"
|
|
-EOF
|
|
+nbdsh --connect "nbd+unix://?socket=$sock" \
|
|
+ -c '
|
|
+# Write some pattern data to the overlay and check it reads back OK.
|
|
+buf = b"abcd" * 16384
|
|
+h.pwrite (buf, 32768)
|
|
+zero = h.pread (32768, 0)
|
|
+assert zero == bytearray (32768)
|
|
+buf2 = h.pread (65536, 32768)
|
|
+assert buf == buf2
|
|
|
|
-# Check the last files we created exist.
|
|
-guestfish --ro -a cache-on-read.img -m /dev/sda1 <<'EOF'
|
|
- cat /hello
|
|
- cat /large | cat >/dev/null
|
|
-EOF
|
|
+# XXX Suggestion to improve this test: Use the delay filter below the
|
|
+# cache filter, and time reads to prove that the second read is faster
|
|
+# because it is not going through the delay filter and plugin.
|
|
+# XXX second h.pread here ...
|
|
+'
|
|
diff --git a/tests/test-cache.sh b/tests/test-cache.sh
|
|
index bafada2..eead7c8 100755
|
|
--- a/tests/test-cache.sh
|
|
+++ b/tests/test-cache.sh
|
|
@@ -34,7 +34,7 @@ source ./functions.sh
|
|
set -e
|
|
set -x
|
|
|
|
-requires guestfish --version
|
|
+requires nbdsh --version
|
|
|
|
sock=`mktemp -u`
|
|
files="cache.img $sock cache.pid"
|
|
@@ -42,24 +42,27 @@ rm -f $files
|
|
cleanup_fn rm -f $files
|
|
|
|
# Create an empty base image.
|
|
-truncate -s 1G cache.img
|
|
+truncate -s 128K cache.img
|
|
|
|
# Run nbdkit with the caching filter.
|
|
start_nbdkit -P cache.pid -U $sock --filter=cache file cache.img
|
|
|
|
-# Open the overlay and perform some operations.
|
|
-guestfish --format=raw -a "nbd://?socket=$sock" <<'EOF'
|
|
- run
|
|
- part-disk /dev/sda gpt
|
|
- mkfs ext4 /dev/sda1
|
|
- mount /dev/sda1 /
|
|
- fill-dir / 10000
|
|
- fill-pattern "abcde" 5M /large
|
|
- write /hello "hello, world"
|
|
-EOF
|
|
+nbdsh --connect "nbd+unix://?socket=$sock" \
|
|
+ -c '
|
|
+# Write some pattern data to the overlay and check it reads back OK.
|
|
+buf = b"abcd" * 16384
|
|
+h.pwrite (buf, 32768)
|
|
+zero = h.pread (32768, 0)
|
|
+assert zero == bytearray (32768)
|
|
+buf2 = h.pread (65536, 32768)
|
|
+assert buf == buf2
|
|
|
|
-# Check the last files we created exist.
|
|
-guestfish --ro -a cache.img -m /dev/sda1 <<'EOF'
|
|
- cat /hello
|
|
- cat /large | cat >/dev/null
|
|
-EOF
|
|
+# Flushing should write through to the underlying file.
|
|
+h.flush ()
|
|
+
|
|
+with open ("cache.img", "rb") as file:
|
|
+ zero = file.read (32768)
|
|
+ assert zero == bytearray (32768)
|
|
+ buf2 = file.read (65536)
|
|
+ assert buf == buf2
|
|
+'
|
|
diff --git a/tests/test-cow.sh b/tests/test-cow.sh
|
|
index 5567b77..dea518c 100755
|
|
--- a/tests/test-cow.sh
|
|
+++ b/tests/test-cow.sh
|
|
@@ -42,7 +42,11 @@ rm -f $files
|
|
cleanup_fn rm -f $files
|
|
|
|
# Create a base image which is partitioned with an empty filesystem.
|
|
-guestfish -N cow-base.img=fs exit
|
|
+rm -rf cow.d
|
|
+mkdir cow.d
|
|
+cleanup_fn rm -rf cow.d
|
|
+nbdkit -fv -U - linuxdisk cow.d size=100M \
|
|
+ --run 'qemu-img convert $nbd cow-base.img'
|
|
lastmod="$(stat -c "%y" cow-base.img)"
|
|
|
|
# Run nbdkit with a COW overlay.
|
|
@@ -50,8 +54,7 @@ start_nbdkit -P cow.pid -U $sock --filter=cow file cow-base.img
|
|
|
|
# Write some data into the overlay.
|
|
guestfish --format=raw -a "nbd://?socket=$sock" -m /dev/sda1 <<EOF
|
|
- fill-dir / 10000
|
|
- fill-pattern "abcde" 5M /large
|
|
+ fill-pattern "abcde" 128K /large
|
|
write /hello "hello, world"
|
|
EOF
|
|
|
|
--
|
|
2.23.0
|
|
|