summaryrefslogblamecommitdiffstats
path: root/tests/ts/libmount/context
blob: c1c1fb74b94c86889871baccc271c396bdfff0af (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                

                                                         
 

       

                                               



                                                    
                               






                                                                              
                                                       

                        
              












                                               
              








                                                     
              


                                  
                                                                    
 
                                   
                                                                                   

                   
                                   
                                                         






                                                                                         
                                                                           
                                   
                                                                                  



                                      
                                                             






                                                                                             
                                                                         
                                   
                                                                                 
                                                             






                                                                                
                                                                                                    

                                                                         
                                                                       
 
                                                                          

                                                                         
                                                             




                                                                                



                                 

              
                                                                         

                                                                                     
              
                                                             



                                                                                    







                                                                                   


                 
#!/bin/bash

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

TS_TOPDIR="$(dirname $0)/../.."
TS_DESC="context"

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

TESTPROG="$TS_HELPER_LIBMOUNT_CONTEXT"
LABEL=libmount-test
UUID=$(uuidgen)
MOUNTPOINT="$TS_MOUNTPOINT"
TS_NOEXIST="$TS_OUTDIR/${TS_TESTNAME}-${TS_SUBNAME}-noex"
[ -d $TS_NOEXIST ] && rmdir $TS_NOEXIST

#set -x

[ -x $TESTPROG ] || ts_skip "test not compiled"

modprobe --dry-run --quiet scsi_debug
[ "$?" == 0 ] || ts_skip "missing scsi_debug module"

ts_log "Init device"
umount $MOUNTPOINT &> /dev/null
rmmod scsi_debug &> /dev/null
modprobe scsi_debug dev_size_mb=100
[ "$?" == 0 ] || ts_die "Cannot init device"

sleep 3

DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
[ "x${DEVNAME}" == "x" ] && ts_die "Cannot find device"

DEVICE="/dev/${DEVNAME}"
udevadm settle

ts_log "Create partitions"
$TS_CMD_FDISK ${DEVICE} >> /dev/null 2>&1 <<EOF
n
p
1


w
q
EOF

DEVICE="/dev/${DEVNAME}1"
udevadm settle

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

ts_log "Do tests..."

export LIBMOUNT_MTAB=$TS_OUTPUT.mtab
> $LIBMOUNT_MTAB

udevadm settle

ts_init_subtest "mount-by-devname"
mkdir -p $MOUNTPOINT &>  /dev/null
ts_valgrind $TESTPROG --mount $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1

grep -q $DEVICE $LIBMOUNT_MTAB || \
	echo "(by device) cannot find $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest

ts_init_subtest "umount-by-devname"
ts_valgrind $TESTPROG --umount $DEVICE >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB &&
	echo "umount (device) failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest


ts_init_subtest "mount-by-label"
mkdir -p $MOUNTPOINT &>  /dev/null
ts_valgrind $TESTPROG --mount LABEL="$LABEL" $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB || \
	echo "(by label) cannot find $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest


ts_init_subtest "umount-by-mountpoint"
ts_valgrind $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB && \
	echo "umount (mountpoint) failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest


ts_init_subtest "mount-by-uuid"
mkdir -p $MOUNTPOINT &> /dev/null
ts_valgrind $TESTPROG --mount UUID="$UUID" $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB || \
	echo "(by uuid) cannot find $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_valgrind $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB &&
	echo "umount failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest


ts_init_subtest "mount-flags"
mkdir -p $MOUNTPOINT &> /dev/null
ts_valgrind $TESTPROG --mount -o ro,noexec,nosuid,strictatime $DEVICE $MOUNTPOINT >> $TS_OUTPUT 2>&1
$TS_CMD_FINDMNT --kernel $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB || \
	echo "cannot find $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1

ts_valgrind $TESTPROG --mount -o remount,rw $MOUNTPOINT >> $TS_OUTPUT 2>&1
$TS_CMD_FINDMNT --kernel $MOUNTPOINT -o VFS-OPTIONS -n >> $TS_OUTPUT 2>&1

ts_valgrind $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $DEVICE $LIBMOUNT_MTAB &&
	echo "umount failed: found $DEVICE in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest


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

ts_valgrind $TESTPROG --mount -o loop $img $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $MOUNTPOINT $LIBMOUNT_MTAB || \
	echo "(loopdev) cannot find $MOUNTPOINT in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
udevadm settle
ts_valgrind $TESTPROG --umount $MOUNTPOINT >> $TS_OUTPUT 2>&1
grep -q $MOUNTPOINT $LIBMOUNT_MTAB &&
	echo "umount failed: found $MOUNTPOINT in $LIBMOUNT_MTAB" >> $TS_OUTPUT 2>&1
ts_finalize_subtest

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

$TS_CMD_UMOUNT $TS_NOEXIST
rmdir $TS_NOEXIST

ts_log "...done."
rmmod scsi_debug
ts_finalize