255 lines
8.7 KiB
Diff
255 lines
8.7 KiB
Diff
From e9c972bc03d42d6fe7f11cd076a5500d39976a61 Mon Sep 17 00:00:00 2001
|
|
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
Date: Sat, 29 Mar 2025 10:01:05 +0000
|
|
Subject: [PATCH] tests: Add tests of file plugin cache=none
|
|
|
|
These are based on the tests which were done in the commit message
|
|
when the feature was first added in commit aa5a2183a6, but cleaned up
|
|
and modernised a little.
|
|
|
|
It is likely that these tests would fail under memory pressure (since
|
|
they test that the page cache is used vs not used). Making them more
|
|
robust left as an exercise for the future.
|
|
|
|
(cherry picked from commit 6017ba21aeeb3d7ad85925e78dba85a005194dee)
|
|
---
|
|
README.md | 1 +
|
|
tests/Makefile.am | 4 ++
|
|
tests/test-file-cache-none-read.sh | 90 ++++++++++++++++++++++++++++
|
|
tests/test-file-cache-none-write.sh | 92 +++++++++++++++++++++++++++++
|
|
4 files changed, 187 insertions(+)
|
|
create mode 100755 tests/test-file-cache-none-read.sh
|
|
create mode 100755 tests/test-file-cache-none-write.sh
|
|
|
|
diff --git a/README.md b/README.md
|
|
index fbe403da..86ac6c57 100644
|
|
--- a/README.md
|
|
+++ b/README.md
|
|
@@ -174,6 +174,7 @@ To test for memory leaks (`make check-valgrind`):
|
|
|
|
For non-essential enhancements to the test suite:
|
|
|
|
+* cachedel, cachestats (from https://github.com/Feh/nocache)
|
|
* expect
|
|
* fdisk, sfdisk (from util-linux)
|
|
* flake8
|
|
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
index 0aa36846..4340cc38 100644
|
|
--- a/tests/Makefile.am
|
|
+++ b/tests/Makefile.am
|
|
@@ -846,6 +846,8 @@ TESTS += \
|
|
test-file-extents.sh \
|
|
test-file-dir.sh \
|
|
test-file-dirfd.sh \
|
|
+ test-file-cache-none-read.sh \
|
|
+ test-file-cache-none-write.sh \
|
|
$(NULL)
|
|
EXTRA_DIST += \
|
|
test-file.sh \
|
|
@@ -855,6 +857,8 @@ EXTRA_DIST += \
|
|
test-file-extents.sh \
|
|
test-file-dir.sh \
|
|
test-file-dirfd.sh \
|
|
+ test-file-cache-none-read.sh \
|
|
+ test-file-cache-none-write.sh \
|
|
$(NULL)
|
|
LIBGUESTFS_TESTS += test-file-block
|
|
|
|
diff --git a/tests/test-file-cache-none-read.sh b/tests/test-file-cache-none-read.sh
|
|
new file mode 100755
|
|
index 00000000..c9831b43
|
|
--- /dev/null
|
|
+++ b/tests/test-file-cache-none-read.sh
|
|
@@ -0,0 +1,90 @@
|
|
+#!/usr/bin/env bash
|
|
+# nbdkit
|
|
+# Copyright Red Hat
|
|
+#
|
|
+# Redistribution and use in source and binary forms, with or without
|
|
+# modification, are permitted provided that the following conditions are
|
|
+# met:
|
|
+#
|
|
+# * Redistributions of source code must retain the above copyright
|
|
+# notice, this list of conditions and the following disclaimer.
|
|
+#
|
|
+# * Redistributions in binary form must reproduce the above copyright
|
|
+# notice, this list of conditions and the following disclaimer in the
|
|
+# documentation and/or other materials provided with the distribution.
|
|
+#
|
|
+# * Neither the name of Red Hat nor the names of its contributors may be
|
|
+# used to endorse or promote products derived from this software without
|
|
+# specific prior written permission.
|
|
+#
|
|
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
|
|
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
|
|
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
+# SUCH DAMAGE.
|
|
+
|
|
+# Test the file plugin, reading with cache=none.
|
|
+
|
|
+source ./functions.sh
|
|
+set -e
|
|
+set -x
|
|
+
|
|
+# Makes no sense to run this test under valgrind.
|
|
+skip_if_valgrind
|
|
+
|
|
+requires_plugin file
|
|
+requires_run
|
|
+requires_nbdcopy
|
|
+requires $TRUNCATE --version
|
|
+requires test -r /dev/urandom
|
|
+requires dd --version
|
|
+requires $SED --version
|
|
+
|
|
+# Requires the cachestats tool from https://github.com/Feh/nocache
|
|
+# It doesn't support --version or --help, so use 'type' instead.
|
|
+requires type cachestats
|
|
+requires type cachedel
|
|
+
|
|
+inp=file-cache-none-read.in
|
|
+stats1=file-cache-none-read.s1
|
|
+stats2=file-cache-none-read.s2
|
|
+rm -f $inp $stats1 $stats2
|
|
+cleanup_fn rm -f $inp $stats1 $stats2
|
|
+
|
|
+# Create a large random file as input.
|
|
+dd if=/dev/urandom of=$inp bs=1024k count=1024
|
|
+
|
|
+# Drop the input file from the page cache and read it out with nbdkit.
|
|
+# We expect to see the input file mostly or completely in cache after.
|
|
+cachedel $inp
|
|
+nbdkit file $inp --run 'nbdcopy "$uri" null:'
|
|
+cachestats $inp > $stats1
|
|
+cat $stats1
|
|
+
|
|
+# The same, with cache=none.
|
|
+# We expect to see the input file not cached after.
|
|
+cachedel $inp
|
|
+nbdkit file $inp --run 'nbdcopy "$uri" null:' cache=none
|
|
+cachestats $inp > $stats2
|
|
+cat $stats2
|
|
+
|
|
+# The output of cachestats looks like this:
|
|
+# pages in cache: 262144/262144 (100.0%) [filesize=1048576.0K, pagesize=4K]
|
|
+# We want to check that % pages in cache using cache=none is much
|
|
+# lower than the default case.
|
|
+pic1="$($SED 's,pages in cache: [0-9/]* (\([0-9]*\)\.[0-9]*%).*,\1,' \
|
|
+ < $stats1)"
|
|
+pic2="$($SED 's,pages in cache: [0-9/]* (\([0-9]*\)\.[0-9]*%).*,\1,' \
|
|
+ < $stats2)"
|
|
+
|
|
+# Test before is > 10%
|
|
+test "$pic1" -gt 10
|
|
+# Test after is < 10%
|
|
+test "$pic2" -lt 10
|
|
diff --git a/tests/test-file-cache-none-write.sh b/tests/test-file-cache-none-write.sh
|
|
new file mode 100755
|
|
index 00000000..2041a5cd
|
|
--- /dev/null
|
|
+++ b/tests/test-file-cache-none-write.sh
|
|
@@ -0,0 +1,92 @@
|
|
+#!/usr/bin/env bash
|
|
+# nbdkit
|
|
+# Copyright Red Hat
|
|
+#
|
|
+# Redistribution and use in source and binary forms, with or without
|
|
+# modification, are permitted provided that the following conditions are
|
|
+# met:
|
|
+#
|
|
+# * Redistributions of source code must retain the above copyright
|
|
+# notice, this list of conditions and the following disclaimer.
|
|
+#
|
|
+# * Redistributions in binary form must reproduce the above copyright
|
|
+# notice, this list of conditions and the following disclaimer in the
|
|
+# documentation and/or other materials provided with the distribution.
|
|
+#
|
|
+# * Neither the name of Red Hat nor the names of its contributors may be
|
|
+# used to endorse or promote products derived from this software without
|
|
+# specific prior written permission.
|
|
+#
|
|
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
|
|
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
|
|
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
+# SUCH DAMAGE.
|
|
+
|
|
+# Test the file plugin, writing with cache=none.
|
|
+
|
|
+source ./functions.sh
|
|
+set -e
|
|
+set -x
|
|
+
|
|
+# Makes no sense to run this test under valgrind.
|
|
+skip_if_valgrind
|
|
+
|
|
+requires_plugin file
|
|
+requires_run
|
|
+requires_nbdcopy
|
|
+requires $TRUNCATE --version
|
|
+requires test -r /dev/urandom
|
|
+requires dd --version
|
|
+requires $SED --version
|
|
+
|
|
+# Requires the cachestats tool from https://github.com/Feh/nocache
|
|
+# It doesn't support --version or --help, so use 'type' instead.
|
|
+requires type cachestats
|
|
+
|
|
+inp=file-cache-none-write.in
|
|
+out=file-cache-none-write.out
|
|
+stats1=file-cache-none-write.s1
|
|
+stats2=file-cache-none-write.s2
|
|
+rm -f $inp $out $stats1 $stats2
|
|
+cleanup_fn rm -f $inp $out $stats1 $stats2
|
|
+
|
|
+# Create a large random file as input.
|
|
+dd if=/dev/urandom of=$inp bs=1024k count=1024
|
|
+
|
|
+# Copy to output using cache=default and collect the stats.
|
|
+# We expect to see the output file mostly or completely in cache after.
|
|
+rm -f $out; truncate -r $inp $out
|
|
+export inp
|
|
+nbdkit file $out --run 'nbdcopy $inp "$uri"' cache=default
|
|
+cachestats $out > $stats1
|
|
+cat $stats1
|
|
+
|
|
+# The same, with cache=none.
|
|
+# We expect to see the output file not cached after.
|
|
+rm -f $out; truncate -r $inp $out
|
|
+export inp
|
|
+nbdkit file $out --run 'nbdcopy $inp "$uri"' cache=none
|
|
+cachestats $out > $stats2
|
|
+cat $stats2
|
|
+
|
|
+# The output of cachestats looks like this:
|
|
+# pages in cache: 262144/262144 (100.0%) [filesize=1048576.0K, pagesize=4K]
|
|
+# We want to check that % pages in cache using cache=none is much
|
|
+# lower than the default case.
|
|
+pic1="$($SED 's,pages in cache: [0-9/]* (\([0-9]*\)\.[0-9]*%).*,\1,' \
|
|
+ < $stats1)"
|
|
+pic2="$($SED 's,pages in cache: [0-9/]* (\([0-9]*\)\.[0-9]*%).*,\1,' \
|
|
+ < $stats2)"
|
|
+
|
|
+# Test before is > 10%
|
|
+test "$pic1" -gt 10
|
|
+# Test after is < 10%
|
|
+test "$pic2" -lt 10
|
|
--
|
|
2.47.1
|
|
|