Skip to content

Commit 6154fb9

Browse files
nfrapradorobherring
authored andcommitted
kselftest: dt: Stop relying on dirname to improve performance
When walking directory trees, instead of looking for specific files and running dirname to get the parent folder, traverse all folders and ignore the ones not containing the desired files. This avoids the need to call dirname inside the loop, which drastically decreases run time: Running locally on a mt8192-asurada-spherion, which reports 160 test cases, has gone from 5.5s to 2.9s, while running remotely with an nfsroot has gone from 13.5s to 5.5s. This change has a side-effect, which is that the root DT node now also shows in the output, even though it isn't expected to bind to a driver. However there shouldn't be a matching driver for the board compatible, so the end result will be just an extra skipped test: ok 1 / # SKIP Reported-by: Mark Brown <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Fixes: 14571ab ("kselftest: Add new test for detecting unprobed Devicetree devices") Tested-by: Mark Brown <[email protected]> Signed-off-by: Nícolas F. R. A. Prado <[email protected]> Link: https://lore.kernel.org/r/20240122-dt-kselftest-dirname-perf-fix-v2-1-f1630532fd38@collabora.com Signed-off-by: Rob Herring <[email protected]>
1 parent 9350242 commit 6154fb9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tools/testing/selftests/dt/test_unprobed_devices.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ if [[ ! -d "${PDT}" ]]; then
3333
fi
3434

3535
nodes_compatible=$(
36-
for node_compat in $(find ${PDT} -name compatible); do
37-
node=$(dirname "${node_compat}")
36+
for node in $(find ${PDT} -type d); do
37+
[ ! -f "${node}"/compatible ] && continue
3838
# Check if node is available
3939
if [[ -e "${node}"/status ]]; then
4040
status=$(tr -d '\000' < "${node}"/status)
@@ -46,10 +46,11 @@ nodes_compatible=$(
4646

4747
nodes_dev_bound=$(
4848
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
49+
for dev_dir in $(find /sys/devices -type d); do
50+
[ ! -f "${dev_dir}"/uevent ] && continue
51+
[ ! -d "${dev_dir}"/driver ] && continue
52+
53+
grep '^OF_FULLNAME=' "${dev_dir}"/uevent | sed -e 's|OF_FULLNAME=||'
5354
done
5455
)
5556

0 commit comments

Comments
 (0)