aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/perf/tests/shell/common/init.sh
blob: aadeaf782e03a6626997ea2d47723a53d596ffc6 (plain) (blame)
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
# SPDX-License-Identifier: GPL-2.0
#
#	init.sh
#	Author: Michael Petlan <mpetlan@redhat.com>
#
#	Description:
#
#		This file should be used for initialization of basic functions
#	for checking, reporting results etc.
#
#


. ../common/settings.sh
. ../common/patterns.sh

THIS_TEST_NAME=`basename $0 .sh`

_echo()
{
	test "$TESTLOG_VERBOSITY" -ne 0 && echo -e "$@"
}

print_results()
{
	PERF_RETVAL="$1"; shift
	CHECK_RETVAL="$1"; shift
	FAILURE_REASON=""
	TASK_COMMENT="$@"
	if [ $PERF_RETVAL -eq 0 -a $CHECK_RETVAL -eq 0 ]; then
		_echo "$MPASS-- [ PASS ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT"
		return 0
	else
		if [ $PERF_RETVAL -ne 0 ]; then
			FAILURE_REASON="command exitcode"
		fi
		if [ $CHECK_RETVAL -ne 0 ]; then
			test -n "$FAILURE_REASON" && FAILURE_REASON="$FAILURE_REASON + "
			FAILURE_REASON="$FAILURE_REASON""output regexp parsing"
		fi
		_echo "$MFAIL-- [ FAIL ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT ($FAILURE_REASON)"
		return 1
	fi
}

print_overall_results()
{
	RETVAL="$1"; shift
	if [ $RETVAL -eq 0 ]; then
		_echo "$MALLPASS## [ PASS ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY"
	else
		_echo "$MALLFAIL## [ FAIL ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY :: $RETVAL failures found"
	fi
	return $RETVAL
}

print_testcase_skipped()
{
	TASK_COMMENT="$@"
	_echo "$MSKIP-- [ SKIP ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT :: testcase skipped"
	return 0
}

print_overall_skipped()
{
	_echo "$MSKIP## [ SKIP ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME :: testcase skipped"
	return 0
}

print_warning()
{
	WARN_COMMENT="$@"
	_echo "$MWARN-- [ WARN ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $WARN_COMMENT"
	return 0
}

# this function should skip a testcase if the testsuite is not run in
# a runmode that fits the testcase --> if the suite runs in BASIC mode
# all STANDARD and EXPERIMENTAL testcases will be skipped; if the suite
# runs in STANDARD mode, all EXPERIMENTAL testcases will be skipped and
# if the suite runs in EXPERIMENTAL mode, nothing is skipped
consider_skipping()
{
	TESTCASE_RUNMODE="$1"
	# the runmode of a testcase needs to be at least the current suite's runmode
	if [ $PERFTOOL_TESTSUITE_RUNMODE -lt $TESTCASE_RUNMODE ]; then
		print_overall_skipped
		exit 0
	fi
}

detect_baremetal()
{
	# return values:
	# 0 = bare metal
	# 1 = virtualization detected
	# 2 = unknown state
	VIRT=`systemd-detect-virt 2>/dev/null`
	test $? -eq 127 && return 2
	test "$VIRT" = "none"
}

detect_intel()
{
	# return values:
	# 0 = is Intel
	# 1 = is not Intel or unknown
	grep "vendor_id" < /proc/cpuinfo | grep -q "GenuineIntel"
}

detect_amd()
{
	# return values:
	# 0 = is AMD
	# 1 = is not AMD or unknown
	grep "vendor_id" < /proc/cpuinfo | grep -q "AMD"
}