brintos

brintos / linux-shallow public Read only

0
0
Text · 2.2 KiB · 5e3f42e Raw
94 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Copyright (c) 2023 Collabora Ltd5#6# Based on Frank Rowand's dt_stat script.7#8# This script tests for devices that were declared on the Devicetree and are9# 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 node13# * a list of compatibles that should be ignored14#15 16DIR="$(dirname $(readlink -f "$0"))"17 18source "${DIR}"/../kselftest/ktap_helpers.sh19 20PDT=/proc/device-tree/21COMPAT_LIST="${DIR}"/compatible_list22IGNORE_LIST="${DIR}"/compatible_ignore_list23 24ktap_print_header25 26if [[ ! -d "${PDT}" ]]; then27	ktap_skip_all "${PDT} doesn't exist."28	exit "${KSFT_SKIP}"29fi30 31nodes_compatible=$(32	for node in $(find ${PDT} -type d); do33		[ ! -f "${node}"/compatible ] && continue34		# Check if node is available35		if [[ -e "${node}"/status ]]; then36			status=$(tr -d '\000' < "${node}"/status)37			if [[ "${status}" != "okay" && "${status}" != "ok" ]]; then38				if [ -n "${disabled_nodes_regex}" ]; then39					disabled_nodes_regex="${disabled_nodes_regex}|${node}"40				else41					disabled_nodes_regex="${node}"42				fi43				continue44			fi45		fi46 47		# Ignore this node if one of its ancestors was disabled48		if [ -n "${disabled_nodes_regex}" ]; then49			echo "${node}" | grep -q -E "${disabled_nodes_regex}" && continue50		fi51 52		echo "${node}" | sed -e 's|\/proc\/device-tree||'53	done | sort54	)55 56nodes_dev_bound=$(57	IFS=$'\n'58	for dev_dir in $(find /sys/devices -type d); do59		[ ! -f "${dev_dir}"/uevent ] && continue60		[ ! -d "${dev_dir}"/driver ] && continue61 62		grep '^OF_FULLNAME=' "${dev_dir}"/uevent | sed -e 's|OF_FULLNAME=||'63	done64	)65 66num_tests=$(echo ${nodes_compatible} | wc -w)67ktap_set_plan "${num_tests}"68 69retval="${KSFT_PASS}"70for node in ${nodes_compatible}; do71	if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)"; then72		compatibles=$(tr '\000' '\n' < "${PDT}"/"${node}"/compatible)73 74		for compatible in ${compatibles}; do75			if grep -x -q "${compatible}" "${IGNORE_LIST}"; then76				continue77			fi78 79			if grep -x -q "${compatible}" "${COMPAT_LIST}"; then80				ktap_test_fail "${node}"81				retval="${KSFT_FAIL}"82				continue 283			fi84		done85		ktap_test_skip "${node}"86	else87		ktap_test_pass "${node}"88	fi89 90done91 92ktap_print_totals93exit "${retval}"94