xref: /openbmc/qemu/tests/qemu-iotests/tests/loop-create-file (revision 872893185e958eb172ade5eb1772584cab8d8357)
1#!/usr/bin/env bash
2# group: quick
3#
4# SPDX-License-Identifier: GPL-2.0-or-later
5#
6# Copyright Red Hat, Inc.
7#
8# Test Linux loop device image creation
9#
10# This test verifies #3127 "qemu-img create fails on loop device with sector size 4096"
11# https://gitlab.com/qemu-project/qemu/-/issues/3127
12
13seq="$(basename $0)"
14echo "QA output created by $seq"
15
16status=1	# failure is the default!
17
18_cleanup() {
19    if [ -n "$loopdev" ]; then
20        sudo losetup --detach "$loopdev"
21    fi
22
23    _cleanup_test_img
24}
25
26trap "_cleanup; exit \$status" 0 1 2 3 15
27
28# get standard environment, filters and checks
29cd ..
30. ./common.rc
31. ./common.filter
32
33_supported_fmt raw
34_supported_proto file
35_supported_os Linux
36
37if ! sudo -n losetup &>/dev/null; then
38    _notrun "sudo losetup not available"
39fi
40
41echo
42echo "=== Create image on a 4 KB sector size loop device ==="
43echo
44
45_make_test_img -f $IMGFMT 1M
46
47loopdev=$(sudo losetup --sector-size 4096 --find --show "$TEST_IMG")
48if [ -z "$loopdev" ]; then
49    _fail
50fi
51
52sudo $QEMU_IMG_PROG create -f raw "$loopdev" 1M | \
53    sed -e "s#/dev/loop[0-9]\\+#LOOPDEV#g"
54
55# success, all done
56echo
57echo '*** done'
58rm -f $seq.full
59status=0
60