]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/libmount/context-utab
tests: fix grep expressions for devices
[thirdparty/util-linux.git] / tests / ts / libmount / context-utab
CommitLineData
2676f3c9
KZ
1#!/bin/bash
2
3# Copyright (C) 2010 Karel Zak <kzak@redhat.com>
4
e130ce53 5TS_TOPDIR="${0%/*}/../.."
2676f3c9
KZ
6TS_DESC="context (utab)"
7
8. $TS_TOPDIR/functions.sh
9ts_init "$*"
2f791546
SK
10
11ts_check_test_command "$TS_CMD_FDISK"
eff2c9a4 12#ts_check_test_command "$TS_CMD_FINDMNT"
0693589b
RM
13ts_check_test_command "$TS_CMD_MOUNT"
14ts_check_test_command "$TS_CMD_UMOUNT"
2f791546 15ts_check_test_command "$TS_CMD_WIPEFS"
0eb90ba2 16ts_check_test_command "$TS_CMD_UUIDGEN"
ee6c0ca6 17
2676f3c9 18ts_skip_nonroot
ee6c0ca6 19ts_check_prog "mkfs.ext4"
2676f3c9
KZ
20
21TESTPROG="$TS_HELPER_LIBMOUNT_CONTEXT"
22LABEL=libmount-test
0eb90ba2 23UUID=$($TS_CMD_UUIDGEN)
2676f3c9
KZ
24MOUNTPOINT="$TS_MOUNTPOINT"
25
6c2bbad1
KZ
26[ -x $TESTPROG ] || ts_skip "test not compiled"
27
f45df374 28# set global variable TS_DEVICE
131e5437 29ts_scsi_debug_init dev_size_mb=257
f45df374 30DEVNAME=$(basename $TS_DEVICE)
2676f3c9
KZ
31
32ts_log "Create partitions"
f45df374 33$TS_CMD_FDISK ${TS_DEVICE} &> /dev/null <<EOF
2676f3c9
KZ
34n
35p
361
37
38
39w
40q
41EOF
42
f45df374 43DEVICE="${TS_DEVICE}1"
2676f3c9 44
188d9656 45udevadm settle
2676f3c9 46
ec182d8b 47grep -q " $DEVNAME\$" /proc/partitions
618ec053 48if [ $? -ne 0 ]; then
618ec053
KZ
49 ts_skip "no partition!"
50fi
51
2676f3c9
KZ
52ts_log "Create filesystem"
53mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null
54
55ts_log "Do tests..."
56
57export LIBMOUNT_MTAB=$TS_OUTPUT.mtab
58rm -f $LIBMOUNT_MTAB
59ln -s /proc/mounts $LIBMOUNT_MTAB
60
61export LIBMOUNT_UTAB=$TS_OUTPUT.utab
62rm -f $LIBMOUNT_UTAB
63> $LIBMOUNT_UTAB
64
188d9656 65udevadm settle
2676f3c9
KZ
66
67ts_init_subtest "mount-by-devname"
68mkdir -p $MOUNTPOINT &> /dev/null
02ae505f 69ts_run $TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1
ec182d8b 70ts_is_mounted "$DEVICE" || \
19f411cb 71 echo "(by device) cannot find $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1
2676f3c9
KZ
72ts_finalize_subtest
73
fc6b8791 74
2676f3c9 75ts_init_subtest "umount-by-devname"
02ae505f 76ts_run $TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>&1
ec182d8b 77ts_is_mounted "$DEVICE" &&
2676f3c9
KZ
78 echo "umount (device) failed: found $DEVICE in /proc/mounts" >> $TS_OUTPUT 2>&1
79ts_finalize_subtest
80
81
82ts_init_subtest "mount-uhelper"
83mkdir -p $MOUNTPOINT &> /dev/null
02ae505f 84ts_run $TESTPROG --mount -o uhelper=foo,rw LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>&1
ec182d8b 85grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \
19f411cb 86 echo "(by label) cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1
2676f3c9
KZ
87ts_finalize_subtest
88
fc6b8791 89
2676f3c9 90ts_init_subtest "umount"
02ae505f 91ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
ec182d8b 92grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" && \
2676f3c9
KZ
93 echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1
94ts_finalize_subtest
95
ef2c9e3f 96
131e5437
RM
97if type "mkfs.btrfs" &>/dev/null && mkfs.btrfs --version &>/dev/null; then
98 $TS_CMD_WIPEFS -a $DEVICE &> /dev/null
99 #ts_log "Create filesystem [btrfs]"
100 mkfs.btrfs -L "$LABEL" $DEVICE &> /dev/null
101 udevadm settle
102
0693589b 103 $TS_CMD_MOUNT -t btrfs $DEVICE $MOUNTPOINT &> /dev/null
131e5437 104 btrfs subvolume create $MOUNTPOINT/sub &> /dev/null
0693589b 105 $TS_CMD_UMOUNT $MOUNTPOINT &> /dev/null
131e5437
RM
106
107 udevadm settle
108
109 ts_init_subtest "mount-uhelper-subvol"
110 mkdir -p $MOUNTPOINT &> /dev/null
02ae505f 111 ts_run $TESTPROG --mount -o uhelper=foo,rw,subvol=sub $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1
ec182d8b 112 grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" || \
131e5437
RM
113 echo "cannot find $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1
114 ts_finalize_subtest
115
116 # Don't temporary write btrfs mount options to the test output,
117 # the options depend on kernel version (since 4.2 it contains
118 # subvol= and subvolid=).
119 #
120 #ts_log "All mount options (btrfs subvolume + utab) ---"
eff2c9a4 121 #$TS_CMD_FINDMNT --mtab --mountpoint $MOUNTPOINT -o OPTIONS -n >> $TS_OUTPUT 2>&1
131e5437
RM
122 #ts_log "---"
123
124 ts_init_subtest "umount-subvol"
02ae505f 125 ts_run $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
ec182d8b 126 grep -q "SRC=$DEVICE\b" "$LIBMOUNT_UTAB" && \
131e5437
RM
127 echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_UTAB" >> $TS_OUTPUT 2>&1
128 ts_finalize_subtest
129fi
2676f3c9
KZ
130
131ts_log "...done."
2676f3c9 132ts_finalize