Path: blob/master/tools/testing/selftests/dt/test_unprobed_devices.sh
26285 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# Copyright (c) 2023 Collabora Ltd4#5# Based on Frank Rowand's dt_stat script.6#7# This script tests for devices that were declared on the Devicetree and are8# expected to bind to a driver, but didn't.9#10# To achieve this, two lists are used:11# * a list of the compatibles that can be matched by a Devicetree node12# * a list of compatibles that should be ignored13#1415DIR="$(dirname $(readlink -f "$0"))"1617source "${DIR}"/../kselftest/ktap_helpers.sh1819PDT=/proc/device-tree/20COMPAT_LIST="${DIR}"/compatible_list21IGNORE_LIST="${DIR}"/compatible_ignore_list2223ktap_print_header2425if [[ ! -d "${PDT}" ]]; then26ktap_skip_all "${PDT} doesn't exist."27exit "${KSFT_SKIP}"28fi2930nodes_compatible=$(31for node in $(find ${PDT} -type d); do32[ ! -f "${node}"/compatible ] && continue33# Check if node is available34if [[ -e "${node}"/status ]]; then35status=$(tr -d '\000' < "${node}"/status)36if [[ "${status}" != "okay" && "${status}" != "ok" ]]; then37if [ -n "${disabled_nodes_regex}" ]; then38disabled_nodes_regex="${disabled_nodes_regex}|${node}"39else40disabled_nodes_regex="${node}"41fi42continue43fi44fi4546# Ignore this node if one of its ancestors was disabled47if [ -n "${disabled_nodes_regex}" ]; then48echo "${node}" | grep -q -E "${disabled_nodes_regex}" && continue49fi5051echo "${node}" | sed -e 's|\/proc\/device-tree||'52done | sort53)5455nodes_dev_bound=$(56IFS=$'\n'57for dev_dir in $(find /sys/devices -type d); do58[ ! -f "${dev_dir}"/uevent ] && continue59[ ! -d "${dev_dir}"/driver ] && continue6061grep '^OF_FULLNAME=' "${dev_dir}"/uevent | sed -e 's|OF_FULLNAME=||'62done63)6465num_tests=$(echo ${nodes_compatible} | wc -w)66ktap_set_plan "${num_tests}"6768retval="${KSFT_PASS}"69for node in ${nodes_compatible}; do70if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)"; then71compatibles=$(tr '\000' '\n' < "${PDT}"/"${node}"/compatible)7273for compatible in ${compatibles}; do74if grep -x -q "${compatible}" "${IGNORE_LIST}"; then75continue76fi7778if grep -x -q "${compatible}" "${COMPAT_LIST}"; then79ktap_test_fail "${node}"80retval="${KSFT_FAIL}"81continue 282fi83done84ktap_test_skip "${node}"85else86ktap_test_pass "${node}"87fi8889done9091ktap_print_totals92exit "${retval}"939495