Skip to content

Commit b104a94

Browse files
james-c-linaroSuzuki K Poulose
authored andcommitted
coresight: Add a KUnit test for coresight_find_default_sink()
Add a test to confirm that default sink selection skips over an ETF and returns an ETR even if it's further away. This also makes it easier to add new unit tests in the future. Reviewed-by: Leo Yan <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e6e6b69 commit b104a94

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

drivers/hwtracing/coresight/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,13 @@ config CORESIGHT_DUMMY
259259

260260
To compile this driver as a module, choose M here: the module will be
261261
called coresight-dummy.
262+
263+
config CORESIGHT_KUNIT_TESTS
264+
tristate "Enable Coresight unit tests"
265+
depends on KUNIT
266+
default KUNIT_ALL_TESTS
267+
help
268+
Enable Coresight unit tests. Only useful for development and not
269+
intended for production.
270+
262271
endif

drivers/hwtracing/coresight/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ obj-$(CONFIG_ULTRASOC_SMB) += ultrasoc-smb.o
5353
obj-$(CONFIG_CORESIGHT_DUMMY) += coresight-dummy.o
5454
obj-$(CONFIG_CORESIGHT_CTCU) += coresight-ctcu.o
5555
coresight-ctcu-y := coresight-ctcu-core.o
56+
obj-$(CONFIG_CORESIGHT_KUNIT_TESTS) += coresight-kunit-tests.o

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ coresight_find_default_sink(struct coresight_device *csdev)
989989
}
990990
return csdev->def_sink;
991991
}
992+
EXPORT_SYMBOL_GPL(coresight_find_default_sink);
992993

993994
static int coresight_remove_sink_ref(struct device *dev, void *data)
994995
{
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <kunit/test.h>
4+
#include <kunit/device.h>
5+
#include <linux/coresight.h>
6+
7+
#include "coresight-priv.h"
8+
9+
static struct coresight_device *coresight_test_device(struct device *dev)
10+
{
11+
struct coresight_device *csdev = devm_kcalloc(dev, 1,
12+
sizeof(struct coresight_device),
13+
GFP_KERNEL);
14+
csdev->pdata = devm_kcalloc(dev, 1,
15+
sizeof(struct coresight_platform_data),
16+
GFP_KERNEL);
17+
return csdev;
18+
}
19+
20+
static void test_default_sink(struct kunit *test)
21+
{
22+
/*
23+
* Source -> ETF -> ETR -> CATU
24+
* ^
25+
* | default
26+
*/
27+
struct device *dev = kunit_device_register(test, "coresight_kunit");
28+
struct coresight_device *src = coresight_test_device(dev),
29+
*etf = coresight_test_device(dev),
30+
*etr = coresight_test_device(dev),
31+
*catu = coresight_test_device(dev);
32+
struct coresight_connection conn = {};
33+
34+
src->type = CORESIGHT_DEV_TYPE_SOURCE;
35+
/*
36+
* Don't use CORESIGHT_DEV_SUBTYPE_SOURCE_PROC, that would always return
37+
* a TRBE sink if one is registered.
38+
*/
39+
src->subtype.source_subtype = CORESIGHT_DEV_SUBTYPE_SOURCE_BUS;
40+
etf->type = CORESIGHT_DEV_TYPE_LINKSINK;
41+
etf->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
42+
etr->type = CORESIGHT_DEV_TYPE_SINK;
43+
etr->subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_SYSMEM;
44+
catu->type = CORESIGHT_DEV_TYPE_HELPER;
45+
46+
conn.src_dev = src;
47+
conn.dest_dev = etf;
48+
coresight_add_out_conn(dev, src->pdata, &conn);
49+
50+
conn.src_dev = etf;
51+
conn.dest_dev = etr;
52+
coresight_add_out_conn(dev, etf->pdata, &conn);
53+
54+
conn.src_dev = etr;
55+
conn.dest_dev = catu;
56+
coresight_add_out_conn(dev, etr->pdata, &conn);
57+
58+
KUNIT_ASSERT_PTR_EQ(test, coresight_find_default_sink(src), etr);
59+
}
60+
61+
static struct kunit_case coresight_testcases[] = {
62+
KUNIT_CASE(test_default_sink),
63+
{}
64+
};
65+
66+
static struct kunit_suite coresight_test_suite = {
67+
.name = "coresight_test_suite",
68+
.test_cases = coresight_testcases,
69+
};
70+
71+
kunit_test_suites(&coresight_test_suite);
72+
MODULE_LICENSE("GPL");
73+
MODULE_AUTHOR("James Clark <[email protected]>");
74+
MODULE_DESCRIPTION("Arm CoreSight KUnit tests");

0 commit comments

Comments
 (0)