File: test-lib.sh

package info (click to toggle)
composefs 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,040 kB
  • sloc: ansic: 9,004; sh: 416; python: 225; makefile: 5
file content (77 lines) | stat: -rw-r--r-- 1,738 bytes parent folder | download
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
#!/bin/bash

fatal() {
    echo $@ 1>&2; exit 1
}

# Dump ls -al + file contents to stderr, then fatal()
_fatal_print_file() {
    file="$1"
    shift
    ls -al "$file" >&2
    sed -e 's/^/# /' < "$file" >&2
    fatal "$@"
}

assert_file_has_content () {
    fpath=$1
    shift
    for re in "$@"; do
        if ! grep -q -e "$re" "$fpath"; then
            _fatal_print_file "$fpath" "File '$fpath' doesn't match regexp '$re'"
        fi
    done
}

check_whiteout () {
    tmpfile=$(mktemp --tmpdir lcfs-whiteout.XXXXXX)
    rm -f $tmpfile
    if mknod $tmpfile c 0 0 &> /dev/null; then
        echo y
    else
        echo n
    fi
    rm -f $tmpfile
}

check_fuse () {
    fusermount --version >/dev/null 2>&1 || return 1

    capsh --print | grep -q 'Bounding set.*[^a-z]cap_sys_admin' || \
        return 1

    [ -w /dev/fuse ] || return 1
    [ -e /etc/mtab ] || return 1

    return 0
}

check_erofs_fsck () {
    if which fsck.erofs &>/dev/null; then
        echo y
    else
        echo n
    fi
}

check_fsverity () {
    fsverity --version >/dev/null 2>&1 || return 1
    tmpfile=$(mktemp --tmpdir lcfs-fsverity.XXXXXX)
    echo foo > $tmpfile
    fsverity enable $tmpfile >/dev/null 2>&1  || return 1
    return 0
}

assert_streq () {
    if test "$1" != "$2"; then
        echo "assertion failed: $1 = $2" 1>&2
        return 1
    fi
}

[[ -v can_whiteout ]] || can_whiteout=$(check_whiteout)
[[ -v has_fuse ]] || has_fuse=$(if check_fuse; then echo y; else echo n; fi)
[[ -v has_fsck ]] || has_fsck=$(check_erofs_fsck)
[[ -v has_fsverity ]] || has_fsverity=$(if check_fsverity; then echo y; else echo n; fi)

echo Test options: can_whiteout=$can_whiteout has_fuse=$has_fuse has_fsck=$has_fsck has_fsverity=$has_fsverity