xref: /qemu/tests/qemu-iotests/036 (revision e7be13ad3ff593608a118bfb69553037bd221563)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2d551cd50SStefan Hajnoczi#
312ac6d3dSKevin Wolf# Test qcow2 feature bits
4d551cd50SStefan Hajnoczi#
5d551cd50SStefan Hajnoczi# Copyright (C) 2011 Red Hat, Inc.
6d551cd50SStefan Hajnoczi# Copyright IBM, Corp. 2010
7d551cd50SStefan Hajnoczi#
8d551cd50SStefan Hajnoczi# Based on test 031.
9d551cd50SStefan Hajnoczi#
10d551cd50SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
11d551cd50SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
12d551cd50SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
13d551cd50SStefan Hajnoczi# (at your option) any later version.
14d551cd50SStefan Hajnoczi#
15d551cd50SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
16d551cd50SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
17d551cd50SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18d551cd50SStefan Hajnoczi# GNU General Public License for more details.
19d551cd50SStefan Hajnoczi#
20d551cd50SStefan Hajnoczi# You should have received a copy of the GNU General Public License
21d551cd50SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22d551cd50SStefan Hajnoczi#
23d551cd50SStefan Hajnoczi
24d551cd50SStefan Hajnoczi# creator
25d551cd50SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com
26d551cd50SStefan Hajnoczi
27d551cd50SStefan Hajnocziseq=`basename $0`
28d551cd50SStefan Hajnocziecho "QA output created by $seq"
29d551cd50SStefan Hajnoczi
30d551cd50SStefan Hajnoczistatus=1	# failure is the default!
31d551cd50SStefan Hajnoczi
32d551cd50SStefan Hajnoczi_cleanup()
33d551cd50SStefan Hajnoczi{
34d551cd50SStefan Hajnoczi	_cleanup_test_img
35d551cd50SStefan Hajnoczi}
36d551cd50SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
37d551cd50SStefan Hajnoczi
38d551cd50SStefan Hajnoczi# get standard environment, filters and checks
39d551cd50SStefan Hajnoczi. ./common.rc
40d551cd50SStefan Hajnoczi. ./common.filter
41d551cd50SStefan Hajnoczi. ./common.pattern
42d551cd50SStefan Hajnoczi
43d551cd50SStefan Hajnoczi# This tests qcow2-specific low-level functionality
44d551cd50SStefan Hajnoczi_supported_fmt qcow2
451f7bf7d0SPeter Lieven_supported_proto file
463be2024aSMax Reitz# Only qcow2v3 and later supports feature bits;
47*e7be13adSEric Blake# qcow2.py does not support external data files;
48*e7be13adSEric Blake# this test requires a cluster size large enough for the feature table
49*e7be13adSEric Blake_unsupported_imgopts 'compat=0.10' data_file \
50*e7be13adSEric Blake		     'cluster_size=\(512\|1024\|2048\|4096\)'
51d551cd50SStefan Hajnoczi
5212ac6d3dSKevin Wolfecho
5312ac6d3dSKevin Wolfecho === Image with unknown incompatible feature bit ===
5412ac6d3dSKevin Wolfecho
5512ac6d3dSKevin Wolf_make_test_img 64M
5612ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 63
5712ac6d3dSKevin Wolf
5812ac6d3dSKevin Wolf# Without feature table
59b527c9b3SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
607ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep features
617ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header-exts
6212ac6d3dSKevin Wolf_img_info
6312ac6d3dSKevin Wolf
6412ac6d3dSKevin Wolf# With feature table containing bit 63
6512ac6d3dSKevin Wolfprintf "\x00\x3f%s" "Test feature" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
6612ac6d3dSKevin Wolf_img_info
6712ac6d3dSKevin Wolf
6812ac6d3dSKevin Wolfecho
6912ac6d3dSKevin Wolfecho === Image with multiple incompatible feature bits ===
7012ac6d3dSKevin Wolfecho
7112ac6d3dSKevin Wolf_make_test_img 64M
7212ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 61
7312ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 62
7412ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" set-feature-bit incompatible 63
7512ac6d3dSKevin Wolf
7612ac6d3dSKevin Wolf# Without feature table
77b527c9b3SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
7812ac6d3dSKevin Wolf_img_info
7912ac6d3dSKevin Wolf
8012ac6d3dSKevin Wolf# With feature table containing bit 63
8112ac6d3dSKevin Wolfprintf "\x00\x3f%s" "Test feature" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
8212ac6d3dSKevin Wolf_img_info
8312ac6d3dSKevin Wolf
8412ac6d3dSKevin Wolf# With feature table containing bit 61
8512ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
8612ac6d3dSKevin Wolfprintf "\x00\x3d%s" "Test feature" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
8712ac6d3dSKevin Wolf_img_info
8812ac6d3dSKevin Wolf
8912ac6d3dSKevin Wolf# With feature table containing bits 61 and 62
9012ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
9112ac6d3dSKevin Wolfprintf "\x00\x3d%s\x00%40s\x00\x3e%s\x00%40s" "test1" "" "test2" "" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
9212ac6d3dSKevin Wolf_img_info
9312ac6d3dSKevin Wolf
9412ac6d3dSKevin Wolf# With feature table containing all bits
9512ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
9612ac6d3dSKevin Wolfprintf "\x00\x3d%s\x00%40s\x00\x3e%s\x00%40s\x00\x3f%s\x00%40s" "test1" "" "test2" "" "test3" "" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
9712ac6d3dSKevin Wolf_img_info
9812ac6d3dSKevin Wolf
9912ac6d3dSKevin Wolf# With feature table containing unrelated bits, including compatible/autoclear
10012ac6d3dSKevin Wolf$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0x6803f857
10112ac6d3dSKevin Wolfprintf "\x01\x3d%s\x00%40s\x00\x3e%s\x00%40s\x02\x3f%s\x00%40s\x00\x3c%s\x00%40s" "test1" "" "test2" "" "test3" "" "test4" "" | $PYTHON qcow2.py "$TEST_IMG" add-header-ext-stdio 0x6803f857
10212ac6d3dSKevin Wolf_img_info
10312ac6d3dSKevin Wolf
10412ac6d3dSKevin Wolf
105d551cd50SStefan Hajnocziecho === Create image with unknown autoclear feature bit ===
106d551cd50SStefan Hajnocziecho
107d551cd50SStefan Hajnoczi_make_test_img 64M
108ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 63
1097ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep features
1107ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header-exts
111d551cd50SStefan Hajnoczi
112d551cd50SStefan Hajnocziecho
113d551cd50SStefan Hajnocziecho === Repair image ===
114d551cd50SStefan Hajnocziecho
115c6bb9ad1SFederico Simoncelli_check_test_img -r all
116c6bb9ad1SFederico Simoncelli
1177ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header | grep features
1187ab2a258SMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header-exts
119d551cd50SStefan Hajnoczi
120d551cd50SStefan Hajnoczi# success, all done
121d551cd50SStefan Hajnocziecho "*** done"
122d551cd50SStefan Hajnoczirm -f $seq.full
123d551cd50SStefan Hajnoczistatus=0
124