Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp360305rdb; Sat, 19 Aug 2023 05:00:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFS7sTVEkuitew/IRMwc3yOAMiqBQTzr4q7U/E8vrkM+fdcatYsZ7/boNOx2JxXsO1+BVds X-Received: by 2002:a17:907:3e12:b0:98f:450e:fc20 with SMTP id hp18-20020a1709073e1200b0098f450efc20mr2012686ejc.17.1692446443888; Sat, 19 Aug 2023 05:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692446443; cv=none; d=google.com; s=arc-20160816; b=aZkfukJuS9YWgW6lLxbH42RXs7IpUCOIU6uxRD6oD1LaHJuelGKaBRgDutfuaVoDKe jrKkG2oUeNCsiGijPS2eo71qin4TpAyiEqfg2fHo6xZgKBpSFbrP0cIux7CwrQE+YwUb Mlh7NDW7VzZOzUfaXUbLdLZIPuHv7k/dDWPDPT7axHgSgFGpSYM4W6DsOjQ8uyR9+j52 i6dYcvWZfFMeWQ+Y7R/XNpZEOVOQIY53A4twDexfYYG+gUAnwkuIR+LcSLjYkSixBIZ0 07sVYf4SCfh2mxiFnjQUhAIm++nv/C37x3Kt2oMQXOXwXjDXYX6zgjYqtj7SOFqljWpC X6Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=dJXGBd6MA3G+qn7ecp8udH3GCarATAJzwipNmBIm3PM=; fh=AN7hgqCdE3GF9iyPYy2UaKfAv1Ll/WSjqNQGL9SMvxE=; b=ipAsDdjXvqDVVnQgZfaUKXeIerpcXxRiq0FZi/zkO9oKc7DEyItEZ7B3BqsvZNTXlR JSJdLCmjfm2C1/2zppfZk8VjfzSN0YFQ1/I2pnDwwUsDGNLHzIP6aSoyN/efyuB5PnKa gQvoxy2FLlP7Waj+/mWAbpcUr2Qv6wahxl9ZWUZcmE6Lz1hPDclGC34ZE0zbnvpyr47P G+AQOsQKhC6b+hFDEd39clN+5EN+19l1fLwRX9rkKNNOwH4Xr8ZlGulO5MHALUK1VYKE xvc9yOPSHWhhbM2a3uycXhFksXgy+wZoixQFUUZH3WPdiiZoGYC1kvitEdijawnBOPNa b3OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Kwi2YM1Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o2-20020aa7c7c2000000b005259756c012si1437115eds.175.2023.08.19.05.00.18; Sat, 19 Aug 2023 05:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Kwi2YM1Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377943AbjHRPFc (ORCPT + 99 others); Fri, 18 Aug 2023 11:05:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377978AbjHRPFV (ORCPT ); Fri, 18 Aug 2023 11:05:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26AF9F7; Fri, 18 Aug 2023 08:05:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AB68A63239; Fri, 18 Aug 2023 15:05:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EE76C433C9; Fri, 18 Aug 2023 15:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692371115; bh=6orISlGJkrk5AwvasxRjT35F7ynLA4E1pATy72EGrCo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Kwi2YM1ZCF1Y9OK30Zx3DREaJdYbFWWuWbaXumT06EKuNrxKoEgYWRpymAR4M/QiI ZwkhSUUIOhx/Ct1fiN0+VQu60UqO5GG1DZ12mt6AnJcqltVDsWgJfO2tzsnvAwfMwD +R9390FVr45fpyEUg50QmVyzJzUZ1vd2nuNdeE7nnfwYuJSPaGT0M4Olweu1nto5dq KepEg6yt4osratSXpwqMc2Ame5n+y/3U+8bh4xe/oiPCX6jTR99HfIICVBmIylGw1a qIvmwKySPkM9Y2I3emJ9RGQdzsnnSgioWGIBU3inRBxbX6dlT0YwkRkCaMkf4jK2JN wl8UUidV+WJGw== Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2b72161c6e9so24647721fa.0; Fri, 18 Aug 2023 08:05:15 -0700 (PDT) X-Gm-Message-State: AOJu0Yxdsm+BGfX8RniXDQJ+S/y98GfWval+asxJw1oQuX4nsJyqQ0zz AaALhkm9QV89qU7nNjjUXSSiKbOYGqlqT6Q2SQ== X-Received: by 2002:a05:651c:1243:b0:2b6:fdae:903a with SMTP id h3-20020a05651c124300b002b6fdae903amr2117850ljh.5.1692371113056; Fri, 18 Aug 2023 08:05:13 -0700 (PDT) MIME-Version: 1.0 References: <20230817233635.2306377-1-nfraprado@collabora.com> <20230817233635.2306377-4-nfraprado@collabora.com> In-Reply-To: <20230817233635.2306377-4-nfraprado@collabora.com> From: Rob Herring Date: Fri, 18 Aug 2023 10:05:00 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 3/3] kselftest: Add new test for detecting unprobed Devicetree devices To: =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Cc: Frank Rowand , Shuah Khan , Mark Brown , kernelci@lists.linux.dev, Guenter Roeck , kernel@collabora.com, Bjorn Andersson , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 17, 2023 at 6:36=E2=80=AFPM N=C3=ADcolas F. R. A. Prado wrote: > > Introduce a new kselftest to detect devices that were declared in the > Devicetree, and are expected to be probed by a driver, but weren't. > > The test uses two lists: a list of compatibles that can match a > Devicetree device to a driver, and a list of compatibles that should be > ignored. The first is automatically generated by the > dt-extract-compatibles script, and is run as part of building this test. > The list of compatibles to ignore is a hand-crafted list to capture the > few exceptions of compatibles that are expected to match a driver but > not be bound to it. > > Signed-off-by: N=C3=ADcolas F. R. A. Prado > > --- > > Changes in v2: > - Switched output to be in KTAP format > - Changed Makefile to make use of the dt-extract-compatibles instead of > the Coccinelle script > - Dropped compatibles from compatible_ignore_list that are now already > filtered out by extraction script > - Added early exit if /proc/device-tree is not present > > tools/testing/selftests/Makefile | 1 + > tools/testing/selftests/dt/.gitignore | 1 + > tools/testing/selftests/dt/Makefile | 21 +++++ Please add this path to DT maintainers entry. > .../selftests/dt/compatible_ignore_list | 1 + > tools/testing/selftests/dt/ktap_helpers.sh | 57 +++++++++++++ As Mark said, looks common. > .../selftests/dt/test_unprobed_devices.sh | 79 +++++++++++++++++++ > 6 files changed, 160 insertions(+) > create mode 100644 tools/testing/selftests/dt/.gitignore > create mode 100644 tools/testing/selftests/dt/Makefile > create mode 100644 tools/testing/selftests/dt/compatible_ignore_list > create mode 100644 tools/testing/selftests/dt/ktap_helpers.sh > create mode 100755 tools/testing/selftests/dt/test_unprobed_devices.sh > > diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/M= akefile > index 42806add0114..e8823097698c 100644 > --- a/tools/testing/selftests/Makefile > +++ b/tools/testing/selftests/Makefile > @@ -18,6 +18,7 @@ TARGETS +=3D drivers/dma-buf > TARGETS +=3D drivers/s390x/uvdevice > TARGETS +=3D drivers/net/bonding > TARGETS +=3D drivers/net/team > +TARGETS +=3D dt > TARGETS +=3D efivarfs > TARGETS +=3D exec > TARGETS +=3D fchmodat2 > diff --git a/tools/testing/selftests/dt/.gitignore b/tools/testing/selfte= sts/dt/.gitignore > new file mode 100644 > index 000000000000..f6476c9f2884 > --- /dev/null > +++ b/tools/testing/selftests/dt/.gitignore > @@ -0,0 +1 @@ > +compatible_list Not sure on the selftests, but is this enough that it gets cleaned? > diff --git a/tools/testing/selftests/dt/Makefile b/tools/testing/selftest= s/dt/Makefile > new file mode 100644 > index 000000000000..62dc00ee4978 > --- /dev/null > +++ b/tools/testing/selftests/dt/Makefile > @@ -0,0 +1,21 @@ > +PY3 =3D $(shell which python3 2>/dev/null) > + > +ifneq ($(PY3),) > + > +TEST_PROGS :=3D test_unprobed_devices.sh > +TEST_GEN_FILES :=3D compatible_list > +TEST_FILES :=3D compatible_ignore_list ktap_helpers.sh > + > +include ../lib.mk > + > +$(OUTPUT)/compatible_list: > + $(top_srcdir)/scripts/dtc/dt-extract-compatibles -d $(top_srcdir)= > $@ > + > +else > + > +all: no_py3_warning > + > +no_py3_warning: > + @echo "Missing python3. This test will be skipped." > + > +endif > diff --git a/tools/testing/selftests/dt/compatible_ignore_list b/tools/te= sting/selftests/dt/compatible_ignore_list > new file mode 100644 > index 000000000000..1323903feca9 > --- /dev/null > +++ b/tools/testing/selftests/dt/compatible_ignore_list > @@ -0,0 +1 @@ > +simple-mfd > diff --git a/tools/testing/selftests/dt/ktap_helpers.sh b/tools/testing/s= elftests/dt/ktap_helpers.sh > new file mode 100644 > index 000000000000..27e89a31e602 > --- /dev/null > +++ b/tools/testing/selftests/dt/ktap_helpers.sh > @@ -0,0 +1,57 @@ > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Copyright (c) 2023 Collabora Ltd > +# > +# Helpers for outputting in KTAP format > +# > +KTAP_TESTNO=3D1 > + > +ktap_print_header() { > + echo "TAP version 13" > +} > + > +ktap_set_plan() { > + num_tests=3D"$1" > + > + echo "1..$num_tests" > +} > + > +ktap_skip_all() { > + echo -n "1..0 # SKIP " > + echo $@ > +} > + > +__ktap_test() { > + result=3D"$1" > + description=3D"$2" > + directive=3D"$3" # optional > + > + local directive_str=3D > + [[ ! -z "$directive" ]] && directive_str=3D"# $directive" > + > + echo $result $KTAP_TESTNO $description $directive_str > + > + KTAP_TESTNO=3D$((KTAP_TESTNO+1)) > +} > + > +ktap_test_pass() { > + description=3D"$1" > + > + result=3D"ok" > + __ktap_test "$result" "$description" > +} > + > +ktap_test_skip() { > + description=3D"$1" > + > + result=3D"ok" > + directive=3D"SKIP" > + __ktap_test "$result" "$description" "$directive" > +} > + > +ktap_test_fail() { > + description=3D"$1" > + > + result=3D"not ok" > + __ktap_test "$result" "$description" > +} > diff --git a/tools/testing/selftests/dt/test_unprobed_devices.sh b/tools/= testing/selftests/dt/test_unprobed_devices.sh > new file mode 100755 > index 000000000000..b523767cdbfb > --- /dev/null > +++ b/tools/testing/selftests/dt/test_unprobed_devices.sh > @@ -0,0 +1,79 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# > +# Copyright (c) 2023 Collabora Ltd > +# > +# Based on Frank Rowand's dt_stat script. > +# > +# This script tests for devices that were declared on the Devicetree and= are > +# expected to bind to a driver, but didn't. > +# > +# To achieve this, two lists are used: > +# * a list of the compatibles that can be matched by a Devicetree node > +# * a list of compatibles that should be ignored > +# > + > +DIR=3D"$(dirname $(readlink -f "$0"))" > + > +source "${DIR}"/ktap_helpers.sh > + > +PDT=3D/proc/device-tree/ This is considered the legacy path though we will probably never get rid of it. Use the sysfs path instead. > +COMPAT_LIST=3D"${DIR}"/compatible_list > +IGNORE_LIST=3D"${DIR}"/compatible_ignore_list > + > +KSFT_PASS=3D0 > +KSFT_FAIL=3D1 > +KSFT_SKIP=3D4 > + > +ktap_print_header > + > +if [[ ! -d "${PDT}" ]]; then > + ktap_skip_all "${PDT} doesn't exist." > + exit "${KSFT_SKIP}" > +fi > + > +nodes_compatible=3D$( > + for node_compat in $(find ${PDT} -name compatible); do > + node=3D$(dirname "${node_compat}") > + # Check if node is available > + [[ -e "${node}"/status && $(tr -d '\000' < "${node}"/stat= us) !=3D "okay" ]] && continue Note that "ok" is accepted by the kernel and does show up some. But for your use, probably okay as is. > + echo "${node}" | sed -e 's|\/proc\/device-tree||' > + done | sort > + ) > + > +nodes_dev_bound=3D$( > + IFS=3D$'\n' > + for uevent in $(find /sys/devices -name uevent); do > + if [[ -d "$(dirname "${uevent}")"/driver ]]; then > + grep '^OF_FULLNAME=3D' "${uevent}" | sed -e 's|OF= _FULLNAME=3D||' > + fi > + done > + ) > + > +num_tests=3D$(echo ${nodes_compatible} | wc -w) > +ktap_set_plan "${num_tests}" > + > +retval=3D"${KSFT_PASS}" > +for node in ${nodes_compatible}; do > + if ! echo "${nodes_dev_bound}" | grep -E -q "(^| )${node}( |\$)";= then > + compatibles=3D$(tr '\000' '\n' < "${PDT}"/"${node}"/compa= tible) > + > + for compatible in ${compatibles}; do > + if grep -x -q "${compatible}" "${IGNORE_LIST}"; t= hen > + continue > + fi > + > + if grep -x -q "${compatible}" "${COMPAT_LIST}"; t= hen > + ktap_test_fail "${node}" > + retval=3D"${KSFT_FAIL}" > + continue 2 > + fi > + done > + ktap_test_skip "${node}" > + else > + ktap_test_pass "${node}" > + fi > + > +done > + > +exit "${retval}" > -- > 2.41.0 >