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 16DIR="$(dirname $(readlink -f "$0"))" 17 18source "${DIR}"/ktap_helpers.sh 19 20PDT=/proc/device-tree/ 21COMPAT_LIST="${DIR}"/compatible_list 22IGNORE_LIST="${DIR}"/compatible_ignore_list 23 24KSFT_PASS=0 25KSFT_FAIL=1 26KSFT_SKIP=4 27 28ktap_print_header 29 30if [[ ! -d "${PDT}" ]]; then 31 ktap_skip_all "${PDT} doesn't exist." 32 exit "${KSFT_SKIP}" 33fi 34 35nodes_compatible=$( 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 42 fi 43 echo "${node}" | sed -e 's|\/proc\/device-tree||' 44 done | sort 45 ) 46 47nodes_dev_bound=$( 48 IFS=$'\n' 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=||' 52 fi 53 done 54 ) 55 56num_tests=$(echo ${nodes_compatible} | wc -w) 57ktap_set_plan "${num_tests}" 58 59retval="${KSFT_PASS}" 60for node in ${nodes_compatible}; do 61 if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)"; then 62 compatibles=$(tr '\000' '\n' < "${PDT}"/"${node}"/compatible) 63 64 for compatible in ${compatibles}; do 65 if grep -x -q "${compatible}" "${IGNORE_LIST}"; then 66 continue 67 fi 68 69 if grep -x -q "${compatible}" "${COMPAT_LIST}"; then 70 ktap_test_fail "${node}" 71 retval="${KSFT_FAIL}" 72 continue 2 73 fi 74 done 75 ktap_test_skip "${node}" 76 else 77 ktap_test_pass "${node}" 78 fi 79 80done 81 82ktap_print_totals 83exit "${retval}" 84