summaryrefslogtreecommitdiffstats
path: root/tests/ts/libmount/context-py
blob: 53a211cf913d025a168183b19894e4cb6dcde042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash

# Copyright (C) 2010 Karel Zak <kzak@redhat.com>

TS_TOPDIR="${0%/*}/../.."
TS_DESC="context-py"

. "$TS_TOPDIR"/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_FDISK"
ts_check_test_command "$TS_CMD_FINDMNT"
ts_check_test_command "$TS_CMD_MOUNT"
ts_check_test_command "$TS_CMD_UMOUNT"
ts_check_test_command "$TS_CMD_UUIDGEN"

ts_skip_nonroot
ts_check_prog "mkfs.ext2"
ts_check_prog "mkfs.ext4"

ts_init_py libmount

if [ "$TS_ENABLE_ASAN" == "yes" -o "$TS_ENABLE_UBSAN" == "yes" ]; then
	TS_KNOWN_FAIL="yes"
fi

TESTPROG="$TS_HELPER_PYLIBMOUNT_CONTEXT"
[ -x $TESTPROG ] || ts_die "test script missing"

PYDBG="$PYTHON -m pdb"
LABEL=libmount-test
UUID=$($TS_CMD_UUIDGEN)
MOUNTPOINT="$TS_MOUNTPOINT"
TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex"
[ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST

ts_log "Init device"
$TS_CMD_UMOUNT $MOUNTPOINT &> /dev/null

# set global variable TS_DEVICE
ts_scsi_debug_init dev_size_mb=100
DEVNAME=$(basename $TS_DEVICE)

ts_log "Create partitions"
$TS_CMD_FDISK --noauto-pt ${TS_DEVICE} &> /dev/null <<EOF
o
n
p
1


w
q
EOF

DEVICE="${TS_DEVICE}1"

udevadm settle

grep -q " $DEVNAME\$" /proc/partitions
if [ $? -ne 0 ]; then
	ts_skip "no partition!"
fi

ts_log "Create filesystem"
mkfs.ext4 -L "$LABEL" -U "$UUID" $DEVICE &> /dev/null

ts_log "Do tests..."

function is_mounted {
	ts_is_mounted "$1"
	return $?
}


udevadm settle
ts_device_has "TYPE" "ext4" $DEVICE || ts_die "Cannot find ext2 on $DEVICE"


ts_init_subtest "mount-by-devname"
mkdir -p $MOUNTPOINT &>  /dev/null
$PYTHON $TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE || echo "$DEVICE not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "umount-by-devname"
$PYTHON $TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "mount-by-label"
mkdir -p $MOUNTPOINT &>  /dev/null
$PYTHON $TESTPROG --mount LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE || echo "$DEVICE not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "umount-by-mountpoint"
$PYTHON $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "mount-by-uuid"
mkdir -p $MOUNTPOINT &> /dev/null
$PYTHON $TESTPROG --mount UUID="$UUID" $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE || echo "$DEVICE not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
$PYTHON $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "mount-flags"
mkdir -p $MOUNTPOINT &> /dev/null
$PYTHON $TESTPROG --mount -o ro,noexec,nosuid,strictatime $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
$TS_CMD_FINDMNT --kernel $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE || echo "$DEVICE not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG

$PYTHON $TESTPROG --mount -o remount,rw $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
$TS_CMD_FINDMNT --kernel $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>> $TS_ERRLOG

$PYTHON $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $DEVICE && echo "$DEVICE still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest


ts_init_subtest "mount-loopdev"
mkdir -p $MOUNTPOINT &> /dev/null
img=$(ts_image_init)
mkfs.ext2 -F $img &> /dev/null
udevadm settle

$PYTHON $TESTPROG --mount -o loop $img $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $MOUNTPOINT || echo "$MOUNTPOINT not mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
udevadm settle
$PYTHON $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
is_mounted $MOUNTPOINT && echo "$MOUNTPOINT still mounted" >> $TS_OUTPUT 2>> $TS_ERRLOG
ts_finalize_subtest

ts_init_subtest "x-mount.mkdir"
$TS_CMD_MOUNT -o x-mount.mkdir --bind $MOUNTPOINT $TS_NOEXIST >> $TS_OUTPUT 2>> $TS_ERRLOG &&
  echo "successfully mounted" >> $TS_OUTPUT
ts_finalize_subtest


$TS_CMD_UMOUNT $TS_NOEXIST
rmdir $TS_NOEXIST

ts_log "...done."
ts_finalize