init.sh 3.3 KB

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