kallsyms.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # perf kallsyms tests
  3. # SPDX-License-Identifier: GPL-2.0
  4. err=0
  5. test_kallsyms() {
  6. echo "Basic perf kallsyms test"
  7. # Check if /proc/kallsyms is readable
  8. if [ ! -r /proc/kallsyms ]; then
  9. echo "Basic perf kallsyms test [Skipped: /proc/kallsyms not readable]"
  10. err=2
  11. return
  12. fi
  13. # Use a symbol that is definitely a function and present in all kernels, e.g. schedule
  14. symbol="schedule"
  15. # Run perf kallsyms
  16. # It prints "address symbol_name"
  17. output=$(perf kallsyms $symbol 2>&1)
  18. ret=$?
  19. if [ $ret -ne 0 ] || [ -z "$output" ]; then
  20. # If empty or failed, it might be due to permissions (kptr_restrict)
  21. # Check if we can grep the symbol from /proc/kallsyms directly
  22. if grep -q "$symbol" /proc/kallsyms 2>/dev/null; then
  23. # If it's in /proc/kallsyms but perf kallsyms returned empty/error,
  24. # it likely means perf couldn't parse it or access it correctly (e.g. kptr_restrict=2).
  25. echo "Basic perf kallsyms test [Skipped: $symbol found in /proc/kallsyms but perf kallsyms failed (output: '$output')]"
  26. err=2
  27. return
  28. else
  29. echo "Basic perf kallsyms test [Skipped: $symbol not found in /proc/kallsyms]"
  30. err=2
  31. return
  32. fi
  33. fi
  34. if echo "$output" | grep -q "not found"; then
  35. echo "Basic perf kallsyms test [Failed: output '$output' does not contain $symbol]"
  36. err=1
  37. return
  38. fi
  39. if perf kallsyms ErlingHaaland | grep -vq "not found"; then
  40. echo "Basic perf kallsyms test [Failed: ErlingHaaland found in the output]"
  41. err=1
  42. return
  43. fi
  44. echo "Basic perf kallsyms test [Success]"
  45. }
  46. test_kallsyms
  47. exit $err