File: common

package info (click to toggle)
lcov 2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,464 kB
  • sloc: perl: 27,911; sh: 7,320; xml: 6,982; python: 1,152; makefile: 597; cpp: 520; ansic: 176
file content (109 lines) | stat: -rw-r--r-- 1,726 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
function elapsed_to_ms()
{
	local ELAPSED=$1
	local IFS=:.
	local MS

	set -- $ELAPSED
	if [ $# -eq 3 ] ; then
		let MS=${3#0}*10+${2#0}*1000+$1*60000
	else
		let MS=${4#0}*10+${3#0}*1000+${2#0}*60000+$1*3600000
	fi

	echo $MS
}

function t_timestamp()
{
	date +"%Y-%m-%d %H:%M:%S %z"
}

function t_marker()
{
	echo
	echo "======================================================================"
}

function t_detail()
{
	local KEY=$1
	local VALUE=$2
	local DOTS=" ............"

	printf "%-.12s: %s\n" "$KEY$DOTS" "$VALUE"
}

function t_announce()
{
	local TESTNAME="$1"
	local len=`echo "$1" | wc -c`
	local start=`expr $len - 31`
	if [[ $len > 32 ]] ; then
	   # test name too long - trim from left
	   TESTNAME="...`echo $TESTNAME | cut -c ${start}-`"
	fi

	printf "$BOLD%-.35s$RESET " "$TESTNAME .............................."
	t_marker >> "$LOGFILE"
	t_detail "DATE" "$(t_timestamp)" >> "$LOGFILE"
	t_detail "TESTNAME" "$TESTNAME" >> "$LOGFILE"
}

function t_result()
{
	local COLOR="$1"
	local TEXT="$2"

	printf "[$COLOR$TEXT$RESET]"
}

function t_pass()
{
	local TESTNAME="$1"

	t_result "$GREEN" "pass"
	echo "pass $TESTNAME" >> "$COUNTFILE"
}

function t_fail()
{
	local TESTNAME="$1"

	t_result "$RED" "fail"
	echo "fail $TESTNAME" >> "$COUNTFILE"
}

function t_kill()
{
	local TESTNAME="$1"

	t_result "$RED" "kill"
	echo "fail $TESTNAME" >> "$COUNTFILE"
}

function t_skip()
{
	local TESTNAME="$1"

	t_result "$BLUE" "skip"
	echo "skip $TESTNAME" >> "$COUNTFILE"
}

function t_indent()
{
	sed -e 's/^/  /'
}

LOGFILE="$TOPDIR/test.log"
COUNTFILE="$TOPDIR/test.counts"
TIMEFILE="$TOPDIR/test.time"

if [ -t 1 ] ; then
	RED="\e[31m"
	GREEN="\e[32m"
	BLUE="\e[34m"
	BOLD="\e[1m"
	DEFAULT="\e[39m"
	RESET="\e[0m"
fi