xref: /openbmc/qemu/tests/qemu-iotests/265 (revision 407fb56a)
1ae6ef019SMax Reitz#!/usr/bin/env bash
2ae6ef019SMax Reitz#
3ae6ef019SMax Reitz# Test reverse-ordered qcow2 writes on a sub-cluster level
4ae6ef019SMax Reitz#
5ae6ef019SMax Reitz# Copyright (C) 2019 Red Hat, Inc.
6ae6ef019SMax Reitz#
7ae6ef019SMax Reitz# This program is free software; you can redistribute it and/or modify
8ae6ef019SMax Reitz# it under the terms of the GNU General Public License as published by
9ae6ef019SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10ae6ef019SMax Reitz# (at your option) any later version.
11ae6ef019SMax Reitz#
12ae6ef019SMax Reitz# This program is distributed in the hope that it will be useful,
13ae6ef019SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14ae6ef019SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15ae6ef019SMax Reitz# GNU General Public License for more details.
16ae6ef019SMax Reitz#
17ae6ef019SMax Reitz# You should have received a copy of the GNU General Public License
18ae6ef019SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19ae6ef019SMax Reitz#
20ae6ef019SMax Reitz
21ae6ef019SMax Reitzseq=$(basename $0)
22ae6ef019SMax Reitzecho "QA output created by $seq"
23ae6ef019SMax Reitz
24ae6ef019SMax Reitzstatus=1	# failure is the default!
25ae6ef019SMax Reitz
26ae6ef019SMax Reitz_cleanup()
27ae6ef019SMax Reitz{
28ae6ef019SMax Reitz    _cleanup_test_img
29ae6ef019SMax Reitz}
30ae6ef019SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
31ae6ef019SMax Reitz
32ae6ef019SMax Reitz# get standard environment, filters and checks
33ae6ef019SMax Reitz. ./common.rc
34ae6ef019SMax Reitz. ./common.filter
35ae6ef019SMax Reitz
36ae6ef019SMax Reitz# qcow2-specific test
37ae6ef019SMax Reitz_supported_fmt qcow2
38ae6ef019SMax Reitz_supported_proto file
39ae6ef019SMax Reitz_supported_os Linux
40ae6ef019SMax Reitz
41ae6ef019SMax Reitzecho '--- Writing to the image ---'
42ae6ef019SMax Reitz
43ae6ef019SMax Reitz# Reduce cluster size so we get more and quicker I/O
44*407fb56aSMax Reitz_make_test_img -o 'cluster_size=4096' 1M
45ae6ef019SMax Reitz(for ((kb = 1024 - 4; kb >= 0; kb -= 4)); do \
46ae6ef019SMax Reitz     echo "aio_write -P 42 $((kb + 1))k 2k"; \
47ae6ef019SMax Reitz done) \
48ae6ef019SMax Reitz | $QEMU_IO "$TEST_IMG" > /dev/null
49ae6ef019SMax Reitz
50ae6ef019SMax Reitzecho '--- Verifying its content ---'
51ae6ef019SMax Reitz
52ae6ef019SMax Reitz(for ((kb = 0; kb < 1024; kb += 4)); do \
53ae6ef019SMax Reitz    echo "read -P 0 ${kb}k 1k"; \
54ae6ef019SMax Reitz    echo "read -P 42 $((kb + 1))k 2k"; \
55ae6ef019SMax Reitz    echo "read -P 0 $((kb + 3))k 1k"; \
56ae6ef019SMax Reitz done) \
57ae6ef019SMax Reitz | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | grep 'verification'
58ae6ef019SMax Reitz
59ae6ef019SMax Reitz# Status of qemu-io
60ae6ef019SMax Reitzif [ ${PIPESTATUS[1]} = 0 ]; then
61ae6ef019SMax Reitz    echo 'Content verified.'
62ae6ef019SMax Reitzfi
63ae6ef019SMax Reitz
64ae6ef019SMax Reitz# success, all done
65ae6ef019SMax Reitzecho "*** done"
66ae6ef019SMax Reitzrm -f $seq.full
67ae6ef019SMax Reitzstatus=0
68