Skip to content

Commit dacf1d7

Browse files
nfrapradogregkh
authored andcommitted
kselftest: Add test to verify probe of devices from discoverable buses
Add a new test to verify that a list of expected devices from discoverable buses (ie USB, PCI) have been successfully instantiated and probed by a driver. The per-platform list of expected devices is selected from the ones under the boards/ directory based on the DT compatible or the DMI IDs. Signed-off-by: "Nícolas F. R. A. Prado" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 71ba4fe commit dacf1d7

File tree

4 files changed

+413
-0
lines changed

4 files changed

+413
-0
lines changed

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ TARGETS += core
1313
TARGETS += cpufreq
1414
TARGETS += cpu-hotplug
1515
TARGETS += damon
16+
TARGETS += devices
1617
TARGETS += dmabuf-heaps
1718
TARGETS += drivers/dma-buf
1819
TARGETS += drivers/s390x/uvdevice
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
TEST_PROGS := test_discoverable_devices.py
2+
TEST_FILES := boards ksft.py
3+
4+
include ../lib.mk
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# Copyright (c) 2023 Collabora Ltd
4+
#
5+
# Kselftest helpers for outputting in KTAP format. Based on kselftest.h.
6+
#
7+
8+
import sys
9+
10+
ksft_cnt = {"pass": 0, "fail": 0, "skip": 0}
11+
ksft_num_tests = 0
12+
ksft_test_number = 1
13+
14+
KSFT_PASS = 0
15+
KSFT_FAIL = 1
16+
KSFT_SKIP = 4
17+
18+
19+
def print_header():
20+
print("TAP version 13")
21+
22+
23+
def set_plan(num_tests):
24+
global ksft_num_tests
25+
ksft_num_tests = num_tests
26+
print("1..{}".format(num_tests))
27+
28+
29+
def print_cnts():
30+
print(
31+
f"# Totals: pass:{ksft_cnt['pass']} fail:{ksft_cnt['fail']} xfail:0 xpass:0 skip:{ksft_cnt['skip']} error:0"
32+
)
33+
34+
35+
def print_msg(msg):
36+
print(f"# {msg}")
37+
38+
39+
def _test_print(result, description, directive=None):
40+
if directive:
41+
directive_str = f"# {directive}"
42+
else:
43+
directive_str = ""
44+
45+
global ksft_test_number
46+
print(f"{result} {ksft_test_number} {description} {directive_str}")
47+
ksft_test_number += 1
48+
49+
50+
def test_result_pass(description):
51+
_test_print("ok", description)
52+
ksft_cnt["pass"] += 1
53+
54+
55+
def test_result_fail(description):
56+
_test_print("not ok", description)
57+
ksft_cnt["fail"] += 1
58+
59+
60+
def test_result_skip(description):
61+
_test_print("ok", description, "SKIP")
62+
ksft_cnt["skip"] += 1
63+
64+
65+
def test_result(condition, description=""):
66+
if condition:
67+
test_result_pass(description)
68+
else:
69+
test_result_fail(description)
70+
71+
72+
def finished():
73+
if ksft_cnt["pass"] == ksft_num_tests:
74+
exit_code = KSFT_PASS
75+
else:
76+
exit_code = KSFT_FAIL
77+
78+
print_cnts()
79+
80+
sys.exit(exit_code)
81+
82+
83+
def exit_fail():
84+
print_cnts()
85+
sys.exit(KSFT_FAIL)
86+
87+
88+
def exit_pass():
89+
print_cnts()
90+
sys.exit(KSFT_PASS)

0 commit comments

Comments
 (0)