xref: /linux/drivers/hwtracing/coresight/coresight-kunit-tests.c (revision c26f4fbd58375bd6ef74f95eb73d61762ad97c59)
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 
coresight_test_device(struct device * dev)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 
test_default_sink(struct kunit * test)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 <james.clark@linaro.org>");
74 MODULE_DESCRIPTION("Arm CoreSight KUnit tests");
75