Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0
2#
3# init.sh
4# Author: Michael Petlan <mpetlan@redhat.com>
5#
6# Description:
7#
8# This file should be used for initialization of basic functions
9# for checking, reporting results etc.
10#
11#
12
13
14. "$(dirname $0)/../common/settings.sh"
15. "$(dirname $0)/../common/patterns.sh"
16
17THIS_TEST_NAME=`basename $0 .sh`
18
19_echo()
20{
21 test "$TESTLOG_VERBOSITY" -ne 0 && echo -e "$@"
22}
23
24print_results()
25{
26 PERF_RETVAL="$1"; shift
27 CHECK_RETVAL="$1"; shift
28 FAILURE_REASON=""
29 TASK_COMMENT="$*"
30 if [ $PERF_RETVAL -eq 0 ] && [ $CHECK_RETVAL -eq 0 ]; then
31 _echo "$MPASS-- [ PASS ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT"
32 return 0
33 else
34 if [ $PERF_RETVAL -ne 0 ]; then
35 FAILURE_REASON="command exitcode"
36 fi
37 if [ $CHECK_RETVAL -ne 0 ]; then
38 test -n "$FAILURE_REASON" && FAILURE_REASON="$FAILURE_REASON + "
39 FAILURE_REASON="$FAILURE_REASON""output regexp parsing"
40 fi
41 _echo "$MFAIL-- [ FAIL ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT ($FAILURE_REASON)"
42 return 1
43 fi
44}
45
46print_overall_results()
47{
48 RETVAL="$1"; shift
49 TASK_COMMENT="$*"
50 test -n "$TASK_COMMENT" && TASK_COMMENT=":: $TASK_COMMENT"
51
52 if [ $RETVAL -eq 0 ]; then
53 _echo "$MALLPASS## [ PASS ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY"
54 else
55 _echo "$MALLFAIL## [ FAIL ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY :: $RETVAL failures found $TASK_COMMENT"
56 fi
57 return $RETVAL
58}
59
60print_testcase_skipped()
61{
62 TASK_COMMENT="$*"
63 _echo "$MSKIP-- [ SKIP ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT :: testcase skipped"
64 return 0
65}
66
67print_overall_skipped()
68{
69 _echo "$MSKIP## [ SKIP ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME :: testcase skipped"
70 return 0
71}
72
73print_warning()
74{
75 WARN_COMMENT="$*"
76 _echo "$MWARN-- [ WARN ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $WARN_COMMENT"
77 return 0
78}
79
80# this function should skip a testcase if the testsuite is not run in
81# a runmode that fits the testcase --> if the suite runs in BASIC mode
82# all STANDARD and EXPERIMENTAL testcases will be skipped; if the suite
83# runs in STANDARD mode, all EXPERIMENTAL testcases will be skipped and
84# if the suite runs in EXPERIMENTAL mode, nothing is skipped
85consider_skipping()
86{
87 TESTCASE_RUNMODE="$1"
88 # the runmode of a testcase needs to be at least the current suite's runmode
89 if [ $PERFTOOL_TESTSUITE_RUNMODE -lt $TESTCASE_RUNMODE ]; then
90 print_overall_skipped
91 exit 2
92 fi
93}
94
95detect_baremetal()
96{
97 # return values:
98 # 0 = bare metal
99 # 1 = virtualization detected
100 # 2 = unknown state
101 VIRT=`systemd-detect-virt 2>/dev/null`
102 test $? -eq 127 && return 2
103 test "$VIRT" = "none"
104}
105
106detect_intel()
107{
108 # return values:
109 # 0 = is Intel
110 # 1 = is not Intel or unknown
111 grep "vendor_id" < /proc/cpuinfo | grep -q "GenuineIntel"
112}
113
114detect_amd()
115{
116 # return values:
117 # 0 = is AMD
118 # 1 = is not AMD or unknown
119 grep "vendor_id" < /proc/cpuinfo | grep -q "AMD"
120}
121
122# base probe utility
123check_kprobes_available()
124{
125 test -e /sys/kernel/debug/tracing/kprobe_events
126}
127
128check_uprobes_available()
129{
130 test -e /sys/kernel/debug/tracing/uprobe_events
131}
132
133clear_all_probes()
134{
135 echo 0 > /sys/kernel/debug/tracing/events/enable
136 check_kprobes_available && echo > /sys/kernel/debug/tracing/kprobe_events
137 check_uprobes_available && echo > /sys/kernel/debug/tracing/uprobe_events
138}
139
140check_sdt_support()
141{
142 $CMD_PERF list sdt | grep sdt > /dev/null 2> /dev/null
143}