File: libtest.sh

package info (click to toggle)
libkcapi 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,992 kB
  • sloc: ansic: 13,808; sh: 2,422; perl: 1,949; makefile: 287
file content (152 lines) | stat: -rw-r--r-- 3,327 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#
# Copyright (C) 2017 - 2022, Stephan Mueller <smueller@chronox.de>
#
# License: see LICENSE file in root directory
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
# WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
# Common code for test cases
#

#####################################################################
# Common functions
#####################################################################

DIRNAME="$(dirname "$0")"

# Allow overriding default value:
if [ -e "$DIRNAME/test-is-local" ]; then
	KCAPI_TEST_LOCAL=${KCAPI_TEST_LOCAL:-1}
else
	KCAPI_TEST_LOCAL=${KCAPI_TEST_LOCAL:-0}
fi

if [ "$KCAPI_TEST_LOCAL" -eq 1 ]; then
	get_app_path()
	{
		echo -n "$DIRNAME/../bin/$1"
	}
	run_app()
	{
		local appname="$1"; shift

		"$(get_app_path "$appname")" "$@"
	}
	find_app_binary()
	{
		echo -n "$(dirname "$1")/.libs/$(basename "$1")"
	}
	KCAPI_TEST_BIN_DIR="$DIRNAME/../bin"
else
	get_app_path()
	{
		command -v "$1"
	}
	run_app()
	{
		"$@"
	}
	find_app_binary()
	{
		echo -n "$1"
	}
	KCAPI_TEST_BIN_DIR="$DIRNAME"
fi

failures=0
PLATFORM="unknown wordsize"
KERNVER=$(uname -r)

# color -- emit ansi color codes
color()
{
	bg=0
	echo -ne "\033[0m"
	while [[ $# -gt 0 ]]; do
		code=0
		case $1 in
			black) code=30 ;;
			red) code=31 ;;
			green) code=32 ;;
			yellow) code=33 ;;
			blue) code=34 ;;
			magenta) code=35 ;;
			cyan) code=36 ;;
			white) code=37 ;;
			background|bg) bg=10 ;;
			foreground|fg) bg=0 ;;
			reset|off|default) code=0 ;;
			bold|bright) code=1 ;;
		esac
		[[ $code == 0 ]] || echo -ne "\033[$(printf "%02d" $((code+bg)))m"
		shift
	done
}

echo_pass()
{
	echo $(color "green")[PASSED: $PLATFORM - $KERNVER]$(color off) $@
}

echo_fail()
{
	echo $(color "red")[FAILED: $PLATFORM - $KERNVER]$(color off) $@
	failures=$(($failures+1))
}

echo_deact()
{
	echo $(color "yellow")[DEACTIVATED: $PLATFORM - $KERNVER]$(color off) $@
}

find_platform()
{
	local app="$(get_app_path "$1")"
	local binlocation="$(find_app_binary $app)"
	if ! [ -x "$binlocation" ]
	then
		binlocation="$app"
	fi
	PLATFORM=$(file "$binlocation" | cut -d" " -f 3)
}

# check whether a given kernel version is present
# returns true for yes, false for no
check_min_kernelver() {
	major=$1
	minor=$2

	if [ $(uname -r | cut -d"." -f1) -gt $major ]; then
		return 0
	fi

	if [ $(uname -r | cut -d"." -f1) -eq $major ]; then
		if [ $(uname -r | cut -d"." -f2) -ge $minor ]; then
			return 0
		fi
	fi
	return 1
}

#####################################################################
# Common variables
#####################################################################

# Storage location of temp files
TMPDIR="/var/tmp"
if [ ! -d $TMPDIR ]
then
	TMPDIR="."
fi