File: common.sh

package info (click to toggle)
xrootd 5.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,956 kB
  • sloc: cpp: 244,425; sh: 2,691; python: 1,980; ansic: 1,027; perl: 814; makefile: 272
file content (88 lines) | stat: -rw-r--r-- 1,919 bytes parent folder | download | duplicates (3)
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
# Helper functions

run_test_case() {
    local test_case_dir=$1
    local idx=$(basename $test_case_dir | cut -d'-' -f1)
    . $test_case_dir/main.sh
    echo "\nRunning test case $idx: $TEST_CASE_NAME\n"
    echo "Using test workspace: $WORKSPACE"
    test_init
    test_main
    test_finalize
    echo "\nTest case $idx: SUCCESS\n"
}

start_caddy() {
    local www_root=$1
    local caddyfile=$2

    ulimit -n 8192

    echo -n "Starting Caddy... "
    $CADDY_EXEC -root $www_root -conf $caddyfile -log $WORKSPACE/caddy.log -pidfile $WORKSPACE/caddy_pid &
    sleep 1
    echo "done."
}

stop_caddy() {
    if [ -f $WORKSPACE/caddy_pid ]; then
        echo -n "Stopping Caddy... "
        kill $(cat $WORKSPACE/caddy_pid)
        rm -f $WORKSPACE/caddy_pid
        echo "done."
    fi
}

generate_random_string() {
    local length=$1
    cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $length | head -n 1
}

file_sha1() {
    echo $(sha1sum $1 | cut -d' ' -f1)
}

str_sha1() {
    echo $(echo $1 | sha1sum | cut -d' ' -f1)
}

die() {
    echo $1
    exit 1
}

create_workspace() {
    mktemp -d -p /tmp/ xrdclhttp-test-ws.XXXXXXXXXX
}

check_executable() {
    which $1 > /dev/null || die "Could not find executable: $1"
}

check_file() {
    local needle=$1
    local haystack=$2
    local res=$(find $haystack -name $needle)
    if [ x"$res" = x"" ]; then
        echo "Could not find file $needle in $haystack"
        exit 1
    fi
}

check_prefix() {
    [ ! -z $XROOTD_PREFIX ] || die "The variable XROOTD_PREFIX is needed to point to the XRootD installation"
    check_file xrootd $XROOTD_PREFIX/bin
    check_file xrdcp $XROOTD_PREFIX/bin
    check_file libXrdClHttp-4.so $XROOTD_PREFIX/lib
}

clean_up() {
    if [ x"$WORKSPACE" != x"" ] && [ -d $WORKSPACE ]; then
        stop_caddy
        echo "Cleaning up: $WORKSPACE"
        rm -r $WORKSPACE
    fi
}

trap clean_up EXIT HUP INT TERM || return $?