Add simple tests creating an image with all kinds of extents, different
formats, different backing chain, different protocol, and different
image options. Since all images have the same guest visible content they
must have the same checksum.
To help debugging in case of failures, the output includes a json map of
every test image.
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
tests/qemu-iotests/tests/qemu-img-checksum | 149 ++++++++++++++++++
.../qemu-iotests/tests/qemu-img-checksum.out | 74 +++++++++
2 files changed, 223 insertions(+)
create mode 100755 tests/qemu-iotests/tests/qemu-img-checksum
create mode 100644 tests/qemu-iotests/tests/qemu-img-checksum.out
diff --git a/tests/qemu-iotests/tests/qemu-img-checksum
b/tests/qemu-iotests/tests/qemu-img-checksum
new file mode 100755
index 0000000000..3a85ba33f2
--- /dev/null
+++ b/tests/qemu-iotests/tests/qemu-img-checksum
@@ -0,0 +1,149 @@
+#!/usr/bin/env python3
+# group: rw auto quick
+#
+# Test cases for qemu-img checksum.
+#
+# Copyright (C) 2022 Red Hat, Inc.
+#
+# 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; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will 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
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import re
+
+import iotests
+
+from iotests import (
+ filter_testfiles,
+ qemu_img,
+ qemu_img_log,
+ qemu_io,
+ qemu_nbd_popen,
+)
+
+
+def checksum_available():
+ out = qemu_img("--help").stdout
+ return re.search(r"\bchecksum .+ filename\b", out) is not None
+
+
+if not checksum_available():
+ iotests.notrun("checksum command not available")
+
+iotests.script_initialize(
+ supported_fmts=["raw", "qcow2"],
+ supported_cache_modes=["none", "writeback"],
+ supported_protocols=["file", "nbd"],
+ required_fmts=["raw", "qcow2"],
+)
+
+print()
+print("=== Test images ===")
+print()
+
+disk_raw = iotests.file_path('raw')
+qemu_img("create", "-f", "raw", disk_raw, "10m")
+qemu_io("-f", "raw",
+ "-c", "write -P 0x1 0 2m", # data
+ "-c", "write -P 0x0 2m 2m", # data with zeroes
+ "-c", "write -z 4m 2m", # zero allocated
+ "-c", "write -z -u 6m 2m", # zero hole
+ # unallocated
+ disk_raw)
+print(filter_testfiles(disk_raw))
+qemu_img_log("map", "--output", "json", disk_raw)
+
+disk_qcow2 = iotests.file_path('qcow2')
+qemu_img("create", "-f", "qcow2", disk_qcow2, "10m")
+qemu_io("-f", "qcow2",
+ "-c", "write -P 0x1 0 2m", # data
+ "-c", "write -P 0x0 2m 2m", # data with zeroes
+ "-c", "write -z 4m 2m", # zero allocated
+ "-c", "write -z -u 6m 2m", # zero hole
+ # unallocated
+ disk_qcow2)
+print(filter_testfiles(disk_qcow2))
+qemu_img_log("map", "--output", "json", disk_qcow2)