xref: /openbmc/qemu/tests/qemu-iotests/131 (revision e3820d5f13188cd7e63109ca70ab47916f18ca6e)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
3ca9c4e06SDenis V. Lunev#
4ca9c4e06SDenis V. Lunev# parallels format validation tests (created by QEMU)
5ca9c4e06SDenis V. Lunev#
6ca9c4e06SDenis V. Lunev# Copyright (C) 2014 Denis V. Lunev <den@openvz.org>
7ca9c4e06SDenis V. Lunev#
8ca9c4e06SDenis V. Lunev# This program is free software; you can redistribute it and/or modify
9ca9c4e06SDenis V. Lunev# it under the terms of the GNU General Public License as published by
10ca9c4e06SDenis V. Lunev# the Free Software Foundation; either version 2 of the License, or
11ca9c4e06SDenis V. Lunev# (at your option) any later version.
12ca9c4e06SDenis V. Lunev#
13ca9c4e06SDenis V. Lunev# This program is distributed in the hope that it will be useful,
14ca9c4e06SDenis V. Lunev# but WITHOUT ANY WARRANTY; without even the implied warranty of
15ca9c4e06SDenis V. Lunev# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16ca9c4e06SDenis V. Lunev# GNU General Public License for more details.
17ca9c4e06SDenis V. Lunev#
18ca9c4e06SDenis V. Lunev# You should have received a copy of the GNU General Public License
19ca9c4e06SDenis V. Lunev# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20ca9c4e06SDenis V. Lunev#
21ca9c4e06SDenis V. Lunev
22ca9c4e06SDenis V. Lunev# creator
23ca9c4e06SDenis V. Lunevowner=den@openvz.org
24ca9c4e06SDenis V. Lunev
25ca9c4e06SDenis V. Lunevseq=`basename $0`
26ca9c4e06SDenis V. Lunevecho "QA output created by $seq"
27ca9c4e06SDenis V. Lunev
28ca9c4e06SDenis V. Lunevstatus=1	# failure is the default!
29ca9c4e06SDenis V. Lunev
30ca9c4e06SDenis V. Lunev_cleanup()
31ca9c4e06SDenis V. Lunev{
32ca9c4e06SDenis V. Lunev    _cleanup_test_img
33ca9c4e06SDenis V. Lunev}
34ca9c4e06SDenis V. Lunevtrap "_cleanup; exit \$status" 0 1 2 3 15
35ca9c4e06SDenis V. Lunev
36ca9c4e06SDenis V. Lunev# get standard environment, filters and checks
37ca9c4e06SDenis V. Lunev. ./common.rc
38ca9c4e06SDenis V. Lunev. ./common.filter
39ca9c4e06SDenis V. Lunev
40ca9c4e06SDenis V. Lunev_supported_fmt parallels
41ca9c4e06SDenis V. Lunev_supported_proto file
42ca9c4e06SDenis V. Lunev_supported_os Linux
43ca9c4e06SDenis V. Lunev
44a6be831eSDenis V. Lunevinuse_offset=$((0x2c))
45a6be831eSDenis V. Lunev
460c2cb382SHanna Reitzsize=$((64 * 1024 * 1024))
47ca9c4e06SDenis V. LunevIMGFMT=parallels
48ca9c4e06SDenis V. Lunev_make_test_img $size
49ca9c4e06SDenis V. Lunev
508e10861bSAlexander Ivanov# get cluster size in sectors from "tracks" header field
518e10861bSAlexander IvanovCLUSTER_SIZE_OFFSET=28
528e10861bSAlexander IvanovCLUSTER_SIZE=$(peek_file_le $TEST_IMG $CLUSTER_SIZE_OFFSET 4)
538e10861bSAlexander IvanovCLUSTER_SIZE=$((CLUSTER_SIZE * 512))
54dbfc5560SAlexander IvanovCLUSTER_HALF_SIZE=$((CLUSTER_SIZE / 2))
55dbfc5560SAlexander IvanovCLUSTER_DBL_SIZE=$((CLUSTER_SIZE * 2))
56dbfc5560SAlexander Ivanov
57ca9c4e06SDenis V. Lunevecho == read empty image ==
58dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0 $CLUSTER_HALF_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
59ca9c4e06SDenis V. Lunevecho == write more than 1 block in a row ==
60dbfc5560SAlexander Ivanov{ $QEMU_IO -c "write -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_DBL_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
61ca9c4e06SDenis V. Lunevecho == read less than block ==
62dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
63ca9c4e06SDenis V. Lunevecho == read exactly 1 block ==
64dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
65ca9c4e06SDenis V. Lunevecho == read more than 1 block ==
66dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_DBL_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
67ca9c4e06SDenis V. Lunevecho == check that there is no trash after written ==
68dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0 $((CLUSTER_HALF_SIZE + CLUSTER_DBL_SIZE)) $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
69ca9c4e06SDenis V. Lunevecho == check that there is no trash before written ==
70dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0 0 $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
71ca9c4e06SDenis V. Lunev
72*e3820d5fSAlexander Ivanovecho "== corrupt image =="
73a6be831eSDenis V. Lunevpoke_file "$TEST_IMG" "$inuse_offset" "\x59\x6e\x6f\x74"
74*e3820d5fSAlexander Ivanovecho "== read corrupted image with repairing =="
75dbfc5560SAlexander Ivanov{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir
76a6be831eSDenis V. Lunev
770c2cb382SHanna Reitzecho "== allocate with backing =="
780c2cb382SHanna Reitz# Verify that allocating clusters works fine even when there is a backing image.
790c2cb382SHanna Reitz# Regression test for a bug where we would pass a buffer read from the backing
800c2cb382SHanna Reitz# node as a QEMUIOVector object, which could cause anything from I/O errors over
810c2cb382SHanna Reitz# assertion failures to invalid reads from memory.
820c2cb382SHanna Reitz
830c2cb382SHanna Reitz# Clear image
840c2cb382SHanna Reitz_make_test_img $size
850c2cb382SHanna Reitz# Create base image
860c2cb382SHanna ReitzTEST_IMG="$TEST_IMG.base" _make_test_img $size
870c2cb382SHanna Reitz
880c2cb382SHanna Reitz# Write some data to the base image (which would trigger an assertion failure if
890c2cb382SHanna Reitz# interpreted as a QEMUIOVector)
90dbfc5560SAlexander Ivanov$QEMU_IO -c "write -P 42 0 $CLUSTER_SIZE" "$TEST_IMG.base" | _filter_qemu_io
910c2cb382SHanna Reitz
920c2cb382SHanna Reitz# Parallels does not seem to support storing a backing filename in the image
930c2cb382SHanna Reitz# itself, so we need to build our backing chain on the command line
940c2cb382SHanna Reitzimgopts="driver=$IMGFMT,file.driver=$IMGPROTO,file.filename=$TEST_IMG"
950c2cb382SHanna Reitzimgopts+=",backing.driver=$IMGFMT"
960c2cb382SHanna Reitzimgopts+=",backing.file.driver=$IMGPROTO,backing.file.filename=$TEST_IMG.base"
970c2cb382SHanna Reitz
980c2cb382SHanna Reitz# Cause allocation in the top image
990c2cb382SHanna ReitzQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \
1000c2cb382SHanna Reitz    $QEMU_IO --image-opts "$imgopts" -c 'write -P 1 0 64' | _filter_qemu_io
1010c2cb382SHanna Reitz
1020c2cb382SHanna Reitz# Verify
1030c2cb382SHanna ReitzQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \
1040c2cb382SHanna Reitz    $QEMU_IO --image-opts "$imgopts" \
1050c2cb382SHanna Reitz    -c 'read -P 1 0 64' \
106dbfc5560SAlexander Ivanov    -c "read -P 42 64 $((CLUSTER_SIZE - 64))" \
107dbfc5560SAlexander Ivanov    -c "read -P 0 $CLUSTER_SIZE $((size - CLUSTER_SIZE))" \
1080c2cb382SHanna Reitz    | _filter_qemu_io
1090c2cb382SHanna Reitz
110ca9c4e06SDenis V. Lunev# success, all done
111ca9c4e06SDenis V. Lunevecho "*** done"
112ca9c4e06SDenis V. Lunevrm -f $seq.full
113ca9c4e06SDenis V. Lunevstatus=0
114