test_unprobed_devices.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Copyright (c) 2023 Collabora Ltd
  5. #
  6. # Based on Frank Rowand's dt_stat script.
  7. #
  8. # This script tests for devices that were declared on the Devicetree and are
  9. # expected to bind to a driver, but didn't.
  10. #
  11. # To achieve this, two lists are used:
  12. # * a list of the compatibles that can be matched by a Devicetree node
  13. # * a list of compatibles that should be ignored
  14. #
  15. DIR="$(dirname $(readlink -f "$0"))"
  16. source "${DIR}"/../kselftest/ktap_helpers.sh
  17. PDT=/proc/device-tree/
  18. COMPAT_LIST="${DIR}"/compatible_list
  19. IGNORE_LIST="${DIR}"/compatible_ignore_list
  20. ktap_print_header
  21. if [[ ! -d "${PDT}" ]]; then
  22. ktap_skip_all "${PDT} doesn't exist."
  23. exit "${KSFT_SKIP}"
  24. fi
  25. nodes_compatible=$(
  26. for node in $(find ${PDT} -type d); do
  27. [ ! -f "${node}"/compatible ] && continue
  28. # Check if node is available
  29. if [[ -e "${node}"/status ]]; then
  30. status=$(tr -d '\000' < "${node}"/status)
  31. if [[ "${status}" != "okay" && "${status}" != "ok" ]]; then
  32. if [ -n "${disabled_nodes_regex}" ]; then
  33. disabled_nodes_regex="${disabled_nodes_regex}|${node}"
  34. else
  35. disabled_nodes_regex="${node}"
  36. fi
  37. continue
  38. fi
  39. fi
  40. # Ignore this node if one of its ancestors was disabled
  41. if [ -n "${disabled_nodes_regex}" ]; then
  42. echo "${node}" | grep -q -E "${disabled_nodes_regex}" && continue
  43. fi
  44. echo "${node}" | sed -e 's|\/proc\/device-tree||'
  45. done | sort
  46. )
  47. nodes_dev_bound=$(
  48. IFS=$'\n'
  49. for dev_dir in $(find /sys/devices -type d); do
  50. [ ! -f "${dev_dir}"/uevent ] && continue
  51. [ ! -d "${dev_dir}"/driver ] && continue
  52. grep '^OF_FULLNAME=' "${dev_dir}"/uevent | sed -e 's|OF_FULLNAME=||'
  53. done
  54. )
  55. num_tests=$(echo ${nodes_compatible} | wc -w)
  56. ktap_set_plan "${num_tests}"
  57. retval="${KSFT_PASS}"
  58. for node in ${nodes_compatible}; do
  59. if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)"; then
  60. compatibles=$(tr '\000' '\n' < "${PDT}"/"${node}"/compatible)
  61. for compatible in ${compatibles}; do
  62. if grep -x -q "${compatible}" "${IGNORE_LIST}"; then
  63. continue
  64. fi
  65. if grep -x -q "${compatible}" "${COMPAT_LIST}"; then
  66. ktap_test_fail "${node}"
  67. retval="${KSFT_FAIL}"
  68. continue 2
  69. fi
  70. done
  71. ktap_test_skip "${node}"
  72. else
  73. ktap_test_pass "${node}"
  74. fi
  75. done
  76. ktap_print_totals
  77. exit "${retval}"