2 # SPDX-License-Identifier: GPL-2.0
4 # Copyright (c) 2023 Collabora Ltd
6 # Based on Frank Rowand's dt_stat script.
8 # This script tests for devices that were declared on the Devicetree and are
9 # expected to bind to a driver, but didn't.
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
16 DIR="$(dirname $(readlink -f "$0"))"
18 source "${DIR}"/ktap_helpers.sh
20 PDT=/proc/device-tree/
21 COMPAT_LIST="${DIR}"/compatible_list
22 IGNORE_LIST="${DIR}"/compatible_ignore_list
30 if [[ ! -d "${PDT}" ]]; then
31 ktap_skip_all "${PDT} doesn't exist."
36 for node_compat in $(find ${PDT} -name compatible); do
37 node=$(dirname "${node_compat}")
38 # Check if node is available
39 if [[ -e "${node}"/status ]]; then
40 status=$(tr -d '\000' < "${node}"/status)
41 [[ "${status}" != "okay" && "${status}" != "ok" ]] && continue
43 echo "${node}" | sed -e 's|\/proc\/device-tree||'
49 for uevent in $(find /sys/devices -name uevent); do
50 if [[ -d "$(dirname "${uevent}")"/driver ]]; then
51 grep '^OF_FULLNAME=' "${uevent}" | sed -e 's|OF_FULLNAME=||'
56 num_tests=$(echo ${nodes_compatible} | wc -w)
57 ktap_set_plan "${num_tests}"
60 for node in ${nodes_compatible}; do
61 if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)"; then
62 compatibles=$(tr '\000' '\n' < "${PDT}"/"${node}"/compatible)
64 for compatible in ${compatibles}; do
65 if grep -x -q "${compatible}" "${IGNORE_LIST}"; then
69 if grep -x -q "${compatible}" "${COMPAT_LIST}"; then
70 ktap_test_fail "${node}"
75 ktap_test_skip "${node}"
77 ktap_test_pass "${node}"