File: _bootstrap.sh

package info (click to toggle)
snoopy 2.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,988 kB
  • sloc: ansic: 7,167; sh: 4,514; makefile: 1,095
file content (127 lines) | stat: -rwxr-xr-x 2,331 bytes parent folder | download | duplicates (2)
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
#!/bin/bash



### Configure shell
#
set -e
set -u



### Source build-based variables
#
. ../_bootstrap-paths.sh



### Get variables about current test
#
SNOOPY_CUR_TEST_PATH=`readlink -f $0`
echo "Current test path: $SNOOPY_CUR_TEST_PATH"
SNOOPY_CUR_TEST_DIR=`dirname $SNOOPY_CUR_TEST_PATH`
SNOOPY_CUR_TEST_FILENAME=`basename $SNOOPY_CUR_TEST_PATH`
SNOOPY_CUR_TEST_NAME=`echo $SNOOPY_CUR_TEST_FILENAME | sed -e 's/\.sh$//'`
SNOOPY_CUR_TEST_GROUP_PATH=`dirname $SNOOPY_CUR_TEST_PATH`
SNOOPY_CUR_TEST_GROUP_NAME=`basename $SNOOPY_CUR_TEST_GROUP_PATH`




### Configure paths
#
SNOOPY_TESTS_ROOTDIR=`dirname $SNOOPY_CUR_TEST_GROUP_PATH`
#
# Current working directory might not be the same,
# if build is being done outside of source tree.
#
# Also now there is an assumption that all tests are placed in subdirs of
# root tests/ directory.
#
# Do not use "readlink -f $THIS_FILE_PATH" - PWD differs when building outside of source dir
#
SNOOPY_CUR_TEST_WORKDIR=`pwd`
SNOOPY_TESTS_BINDIR="$SNOOPY_CUR_TEST_WORKDIR/../bin"
SNOOPY_TEST_CLI="$SNOOPY_TESTS_BINDIR/snoopy-test"
export SNOOPY_LIBSNOOPY_TEST_SO_PATH="${SNOOPY_TESTS_BINDIR}/.libs/libsnoopy-test-execve-wrapper-env-ini-path.so"



### Test run function: info output
#
snoopy_testRun_info()
{
    echo "$1"
}



### Result function: PASS
#
snoopy_testResult_pass()
{
    echo "PASS"
    if [ ! -z "${1:-}" ]; then
        echo "$1"
    fi
    exit 0
}



### Result function: PASS
#
snoopy_testResult_fail()
{
    MSG="$1"
    echo "FAIL"
    echo "$1"
    exit 1
}



### Result function: SKIP
#
snoopy_testResult_skip()
{
    MSG="$1"
    echo "SKIPPED: $MSG"
    exit 77
}



### Comparison function: PASS
#
snoopy_test_compareValues()
{
    VAL_SNOOPY="$1"
    VAL_REAL="$2"

    if [ "$VAL_SNOOPY" != "$VAL_REAL" ]; then
        snoopy_testResult_fail "Values do not match (snoopy=\"$VAL_SNOOPY\", real=\"$VAL_REAL\")"
    fi

    snoopy_testResult_pass
}



### Data retriever: from ps
#
snoopy_test_getValue_fromPs()
{
    PID="$1"
    FIELD="$2"

    COUNT=`ps -eo pid,$FIELD | grep -E "^[ ]*$PID[ ]+" -c`
    if [ "$COUNT" != "1" ]; then
        echo "ERROR: Invalid number of processes matched while looking for $FIELD"
        return 1
    fi

    VALUE=`ps -eo pid,$FIELD | grep -E "^[ ]*$PID[ ]+" | head -n1 | awk '{print $2}'`
    echo "$VALUE"
    return 0
}