init.sh 3.2 KB

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