141 lines · bash
1# SPDX-License-Identifier: GPL-2.02#3# init.sh4# Author: Michael Petlan <mpetlan@redhat.com>5#6# Description:7#8# This file should be used for initialization of basic functions9# for checking, reporting results etc.10#11#12 13 14. ../common/settings.sh15. ../common/patterns.sh16 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"; shift27 CHECK_RETVAL="$1"; shift28 FAILURE_REASON=""29 TASK_COMMENT="$*"30 if [ $PERF_RETVAL -eq 0 ] && [ $CHECK_RETVAL -eq 0 ]; then31 _echo "$MPASS-- [ PASS ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT"32 return 033 else34 if [ $PERF_RETVAL -ne 0 ]; then35 FAILURE_REASON="command exitcode"36 fi37 if [ $CHECK_RETVAL -ne 0 ]; then38 test -n "$FAILURE_REASON" && FAILURE_REASON="$FAILURE_REASON + "39 FAILURE_REASON="$FAILURE_REASON""output regexp parsing"40 fi41 _echo "$MFAIL-- [ FAIL ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT ($FAILURE_REASON)"42 return 143 fi44}45 46print_overall_results()47{48 RETVAL="$1"; shift49 if [ $RETVAL -eq 0 ]; then50 _echo "$MALLPASS## [ PASS ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY"51 else52 _echo "$MALLFAIL## [ FAIL ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME SUMMARY :: $RETVAL failures found"53 fi54 return $RETVAL55}56 57print_testcase_skipped()58{59 TASK_COMMENT="$*"60 _echo "$MSKIP-- [ SKIP ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $TASK_COMMENT :: testcase skipped"61 return 062}63 64print_overall_skipped()65{66 _echo "$MSKIP## [ SKIP ] ##$MEND $TEST_NAME :: $THIS_TEST_NAME :: testcase skipped"67 return 068}69 70print_warning()71{72 WARN_COMMENT="$*"73 _echo "$MWARN-- [ WARN ] --$MEND $TEST_NAME :: $THIS_TEST_NAME :: $WARN_COMMENT"74 return 075}76 77# this function should skip a testcase if the testsuite is not run in78# a runmode that fits the testcase --> if the suite runs in BASIC mode79# all STANDARD and EXPERIMENTAL testcases will be skipped; if the suite80# runs in STANDARD mode, all EXPERIMENTAL testcases will be skipped and81# if the suite runs in EXPERIMENTAL mode, nothing is skipped82consider_skipping()83{84 TESTCASE_RUNMODE="$1"85 # the runmode of a testcase needs to be at least the current suite's runmode86 if [ $PERFTOOL_TESTSUITE_RUNMODE -lt $TESTCASE_RUNMODE ]; then87 print_overall_skipped88 exit 089 fi90}91 92detect_baremetal()93{94 # return values:95 # 0 = bare metal96 # 1 = virtualization detected97 # 2 = unknown state98 VIRT=`systemd-detect-virt 2>/dev/null`99 test $? -eq 127 && return 2100 test "$VIRT" = "none"101}102 103detect_intel()104{105 # return values:106 # 0 = is Intel107 # 1 = is not Intel or unknown108 grep "vendor_id" < /proc/cpuinfo | grep -q "GenuineIntel"109}110 111detect_amd()112{113 # return values:114 # 0 = is AMD115 # 1 = is not AMD or unknown116 grep "vendor_id" < /proc/cpuinfo | grep -q "AMD"117}118 119# base probe utility120check_kprobes_available()121{122 test -e /sys/kernel/debug/tracing/kprobe_events123}124 125check_uprobes_available()126{127 test -e /sys/kernel/debug/tracing/uprobe_events128}129 130clear_all_probes()131{132 echo 0 > /sys/kernel/debug/tracing/events/enable133 check_kprobes_available && echo > /sys/kernel/debug/tracing/kprobe_events134 check_uprobes_available && echo > /sys/kernel/debug/tracing/uprobe_events135}136 137check_sdt_support()138{139 $CMD_PERF list sdt | grep sdt > /dev/null 2> /dev/null140}141