xref: /openbmc/qemu/tests/qemu-iotests/075 (revision 0e324626)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick
305560fceSStefan Hajnoczi#
405560fceSStefan Hajnoczi# cloop format input validation tests
505560fceSStefan Hajnoczi#
605560fceSStefan Hajnoczi# Copyright (C) 2013 Red Hat, Inc.
705560fceSStefan Hajnoczi#
805560fceSStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
905560fceSStefan Hajnoczi# it under the terms of the GNU General Public License as published by
1005560fceSStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
1105560fceSStefan Hajnoczi# (at your option) any later version.
1205560fceSStefan Hajnoczi#
1305560fceSStefan Hajnoczi# This program is distributed in the hope that it will be useful,
1405560fceSStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
1505560fceSStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1605560fceSStefan Hajnoczi# GNU General Public License for more details.
1705560fceSStefan Hajnoczi#
1805560fceSStefan Hajnoczi# You should have received a copy of the GNU General Public License
1905560fceSStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2005560fceSStefan Hajnoczi#
2105560fceSStefan Hajnoczi
2205560fceSStefan Hajnoczi# creator
2305560fceSStefan Hajnocziowner=stefanha@redhat.com
2405560fceSStefan Hajnoczi
2505560fceSStefan Hajnocziseq=`basename $0`
2605560fceSStefan Hajnocziecho "QA output created by $seq"
2705560fceSStefan Hajnoczi
2805560fceSStefan Hajnoczistatus=1	# failure is the default!
2905560fceSStefan Hajnoczi
3005560fceSStefan Hajnoczi_cleanup()
3105560fceSStefan Hajnoczi{
3205560fceSStefan Hajnoczi	_cleanup_test_img
3305560fceSStefan Hajnoczi}
3405560fceSStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
3505560fceSStefan Hajnoczi
3605560fceSStefan Hajnoczi# get standard environment, filters and checks
3705560fceSStefan Hajnoczi. ./common.rc
3805560fceSStefan Hajnoczi. ./common.filter
3905560fceSStefan Hajnoczi
4005560fceSStefan Hajnoczi_supported_fmt cloop
41c5f7c0afSPeter Lieven_supported_proto file
4205560fceSStefan Hajnoczi_supported_os Linux
4305560fceSStefan Hajnoczi
44d65f97a8SStefan Hajnocziblock_size_offset=128
45509a41baSStefan Hajnoczin_blocks_offset=132
46f56b9bc3SStefan Hajnoczioffsets_offset=136
47d65f97a8SStefan Hajnoczi
4805560fceSStefan Hajnocziecho
4905560fceSStefan Hajnocziecho "== check that the first sector can be read =="
5005560fceSStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
5145f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
5205560fceSStefan Hajnoczi
53d65f97a8SStefan Hajnocziecho
5442d43d35SStefan Hajnocziecho "== check that the last sector can be read =="
5542d43d35SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
5645f1882aSJohn Snow$QEMU_IO -r -c "read $((1024 * 1024 - 512)) 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
5742d43d35SStefan Hajnoczi
5842d43d35SStefan Hajnocziecho
59d65f97a8SStefan Hajnocziecho "== block_size must be a multiple of 512 =="
60d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
61d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\x00\x00\x02\x01"
6245f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
63d65f97a8SStefan Hajnoczi
64d65f97a8SStefan Hajnocziecho
65d65f97a8SStefan Hajnocziecho "== block_size cannot be zero =="
66d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
67d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\x00\x00\x00\x00"
6845f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
69d65f97a8SStefan Hajnoczi
70d65f97a8SStefan Hajnocziecho
71d65f97a8SStefan Hajnocziecho "== huge block_size ==="
72d65f97a8SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
73d65f97a8SStefan Hajnoczipoke_file "$TEST_IMG" "$block_size_offset" "\xff\xff\xfe\x00"
7445f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
75d65f97a8SStefan Hajnoczi
76509a41baSStefan Hajnocziecho
77509a41baSStefan Hajnocziecho "== offsets_size overflow ==="
78509a41baSStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
79509a41baSStefan Hajnoczipoke_file "$TEST_IMG" "$n_blocks_offset" "\xff\xff\xff\xff"
8045f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
81509a41baSStefan Hajnoczi
827b103b36SStefan Hajnocziecho
837b103b36SStefan Hajnocziecho "== refuse images that require too many offsets ==="
847b103b36SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
857b103b36SStefan Hajnoczipoke_file "$TEST_IMG" "$n_blocks_offset" "\x04\x00\x00\x01"
8645f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
877b103b36SStefan Hajnoczi
88f56b9bc3SStefan Hajnocziecho
89f56b9bc3SStefan Hajnocziecho "== refuse images with non-monotonically increasing offsets =="
90f56b9bc3SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
91f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" "$offsets_offset" "\x00\x00\x00\x00\xff\xff\xff\xff"
92f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" $((offsets_offset + 8)) "\x00\x00\x00\x00\xff\xfe\x00\x00"
9345f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
94f56b9bc3SStefan Hajnoczi
95f56b9bc3SStefan Hajnocziecho
96f56b9bc3SStefan Hajnocziecho "== refuse images with invalid compressed block size =="
97f56b9bc3SStefan Hajnoczi_use_sample_img simple-pattern.cloop.bz2
98f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" "$offsets_offset" "\x00\x00\x00\x00\x00\x00\x00\x00"
99f56b9bc3SStefan Hajnoczipoke_file "$TEST_IMG" $((offsets_offset + 8)) "\xff\xff\xff\xff\xff\xff\xff\xff"
10045f1882aSJohn Snow$QEMU_IO -r -c "read 0 512" $TEST_IMG 2>&1 | _filter_qemu_io | _filter_testdir
101f56b9bc3SStefan Hajnoczi
10205560fceSStefan Hajnoczi# success, all done
10305560fceSStefan Hajnocziecho "*** done"
10405560fceSStefan Hajnoczirm -f $seq.full
10505560fceSStefan Hajnoczistatus=0
106