File: run_dib_library_tests.sh

package info (click to toggle)
python-diskimage-builder 3.37.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,572 kB
  • sloc: sh: 7,380; python: 6,444; makefile: 37
file content (58 lines) | stat: -rwxr-xr-x 1,405 bytes parent folder | download | duplicates (5)
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
#!/bin/bash

# unit testing for some of the common-functions
#
# This is fairly invasive and *may* leave behind mounts, etc, that
# need a human in the loop.  Thus it's mostly useful for developers
# during testing, but not so great for CI

source ../diskimage_builder/lib/common-functions

#
# Directory mounting and unmounting
#

# make mount points
TMP_DIR=$(mktemp -d)
cd $TMP_DIR
mkdir mnt
mkdir mnt/proc mnt/dev mnt/dev/pts mnt/sysfs mnt/sys

# for extra complexity, simulate the path being behind a symlink
ln -s mnt mnt-symlink
TMP_MOUNT_PATH=$TMP_DIR/mnt-symlink

# mount devices
mount_proc_dev_sys

if [ $(grep "$TMP_DIR" /proc/mounts | wc -l) -ne 4 ]; then
    echo "*** FAILED to mount all directories"
    # we might be in an unclean state here, but something is broken...
    # we don't want to delete mounted system directories
    return 1
else
    echo "*** PASS : mounted all directories"
fi

# umount devices
unmount_dir $TMP_MOUNT_PATH

if grep -q "$TMP_DIR" /proc/mounts; then
    echo "*** FAILED due to mounts being left behind"
    return 1
else
    echo "*** PASS all directories unmounted"
fi

# unmount missing dir
if unmount_dir /this/path/does/not/exist/but/this/should/not/fail; then
    echo "*** PASS unmount_dir ignored a missing path"
else
    echo "*** FAILED unmount_dir should ignore missing paths"
    return 1
fi

# cleanup
rm -rf $TMP_DIR

### TODO more tests here