Skip to contentSkip to conversation

interconnect: Add kunit tests for core functionality

PATCH Superseded Kuan-Wei Chiu 2 participants 3 messages Dec 10, 2025 – Jan 10

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kuan-Wei Chiu

author maintainer
#0 lore raw

PATCH 1/1 interconnect: Add kunit tests for core functionality

The interconnect framework currently lacks in-tree unit tests to verify the core logic in isolation. This makes it difficult to validate regression stability when modifying the provider/consumer APIs or aggregation logic.

Introduce a kunit test suite that verifies the fundamental behavior of the subsystem. The tests cover:
- Provider API (node creation, linking, topology construction).
- Consumer API (path enabling/disabling, bandwidth requests).
- Standard aggregation logic (accumulating bandwidth across links).
- Bulk operations for setting bandwidth on multiple paths.

The suite simulates a simple SoC topology with multiple masters and a shared bus to validate traffic aggregation behavior in a controlled software environment, without requiring specific hardware or Device Tree support.

---
Build and kunit tests passed

 drivers/interconnect/Kconfig     |  14 ++
 drivers/interconnect/Makefile    |   2 +
 drivers/interconnect/icc-kunit.c | 315 +++++++++++++++++++++++++++++++
 3 files changed, 331 insertions(+)
 create mode 100644 drivers/interconnect/icc-kunit.c
drivers/interconnect/Kconfig +14 -0
index f2e49bd97d31..882dcb0b4a5b 100644
@@ -22,4 +22,18 @@ config INTERCONNECT_CLK
 	help
 	  Support for wrapping clocks into the interconnect nodes.
 
+config INTERCONNECT_KUNIT_TEST
+	tristate "KUnit tests for Interconnect framework"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the KUnit test suite for the generic system interconnect
+	  framework.
+
+	  The tests cover the core functionality of the interconnect subsystem,
+	  including provider/consumer APIs, topology management, and bandwidth
+	  aggregation logic.
+
+	  If unsure, say N.
+
 endif
drivers/interconnect/Makefile +2 -0
index b0a9a6753b9d..dc4c7b657c9d 100644
@@ -10,3 +10,5 @@ obj-$(CONFIG_INTERCONNECT_QCOM)		+= qcom/
 obj-$(CONFIG_INTERCONNECT_SAMSUNG)	+= samsung/
 
 obj-$(CONFIG_INTERCONNECT_CLK)		+= icc-clk.o
+
+obj-$(CONFIG_INTERCONNECT_KUNIT_TEST) += icc-kunit.o
drivers/interconnect/icc-kunit.c new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
maintainer
#1 lore raw
Quoted 110 lines · Kuan-Wei Chiu

The interconnect framework currently lacks in-tree unit tests to verify the core logic in isolation. This makes it difficult to validate regression stability when modifying the provider/consumer APIs or aggregation logic.

Introduce a kunit test suite that verifies the fundamental behavior of the subsystem. The tests cover:
- Provider API (node creation, linking, topology construction).
- Consumer API (path enabling/disabling, bandwidth requests).
- Standard aggregation logic (accumulating bandwidth across links).
- Bulk operations for setting bandwidth on multiple paths.

The suite simulates a simple SoC topology with multiple masters and a shared bus to validate traffic aggregation behavior in a controlled software environment, without requiring specific hardware or Device Tree support.

---
Build and kunit tests passed

  drivers/interconnect/Kconfig     |  14 ++
  drivers/interconnect/Makefile    |   2 +
  drivers/interconnect/icc-kunit.c | 315 +++++++++++++++++++++++++++++++
  3 files changed, 331 insertions(+)

create mode 100644 drivers/interconnect/icc-kunit.c

drivers/interconnect/Kconfig +14 -0
index f2e49bd97d31..882dcb0b4a5b 100644
@@ -22,4 +22,18 @@ config INTERCONNECT_CLK
  	help
  	  Support for wrapping clocks into the interconnect nodes.
 
+config INTERCONNECT_KUNIT_TEST
+	tristate "KUnit tests for Interconnect framework"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the KUnit test suite for the generic system interconnect
+	  framework.
+
+	  The tests cover the core functionality of the interconnect subsystem,
+	  including provider/consumer APIs, topology management, and bandwidth
+	  aggregation logic.
+
+	  If unsure, say N.
+
  endif
drivers/interconnect/Makefile +2 -0
index b0a9a6753b9d..dc4c7b657c9d 100644
@@ -10,3 +10,5 @@ obj-$(CONFIG_INTERCONNECT_QCOM)		+= qcom/
  obj-$(CONFIG_INTERCONNECT_SAMSUNG)	+= samsung/
 
  obj-$(CONFIG_INTERCONNECT_CLK)		+= icc-clk.o
+
+obj-$(CONFIG_INTERCONNECT_KUNIT_TEST) += icc-kunit.o
drivers/interconnect/icc-kunit.c new file +44 -0
new file mode 100644
index 000000000000..2178487f9527
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for the Interconnect framework.
+ *
+ * Copyright (c) 2025 Kuan-Wei Chiu <[email protected]>
+ *
+ * This suite verifies the behavior of the interconnect core, including
+ * topology construction, bandwidth aggregation, and path lifecycle.
+ */
+
+#include <kunit/platform_device.h>
+#include <kunit/test.h>
+#include <linux/interconnect-provider.h>
+#include <linux/interconnect.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/overflow.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include "internal.h"
+
+enum {
+	NODE_CPU = 100,
+	NODE_GPU,
+	NODE_BUS,
+	NODE_DDR,
+	NODE_MAX
+};
+
+struct test_node_data {
+	int id;
+	const char *name;
+	int num_links;
+	int links[2];
+};
+
+/*
+ * Static Topology:
+ * CPU -\
+ * -> BUS -> DDR
+ * GPU -/
+ */
+static const struct test_node_data test_topology[] = {

drivers/interconnect/icc-kunit.c line 54

Quoted 10 lines
drivers/interconnect/icc-kunit.c new file +10 -0
+	{ NODE_CPU, "cpu", 1, { NODE_BUS } },
+	{ NODE_GPU, "gpu", 1, { NODE_BUS } },
+	{ NODE_BUS, "bus", 1, { NODE_DDR } },
+	{ NODE_DDR, "ddr", 0, { } },
+};
+
+struct icc_test_priv {
+	struct icc_provider provider;
+	struct platform_device *pdev;
+	struct icc_node *nodes[NODE_MAX];

So nodes[] is a 104-element array? Is this intentional?

[..]

Quoted 24 lines
drivers/interconnect/icc-kunit.c new file +24 -0
+static void icc_test_set_bw(struct kunit *test)
+{
+	struct icc_test_priv *priv = test->priv;
+	struct icc_path *path;
+	struct icc_node *path_nodes[3];
+	int ret;
+
+	/* Path: CPU -> BUS -> DDR */
+	path_nodes[0] = get_node(priv, NODE_CPU);
+	path_nodes[1] = get_node(priv, NODE_BUS);
+	path_nodes[2] = get_node(priv, NODE_DDR);
+
+	path = icc_test_create_path(test, path_nodes, 3);
+
+	ret = icc_enable(path);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
+	ret = icc_set_bw(path, 1000, 2000);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->avg_bw, 1000);
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->peak_bw, 2000);
+	KUNIT_EXPECT_EQ(test, path_nodes[1]->avg_bw, 1000);
+	KUNIT_EXPECT_EQ(test, path_nodes[1]->peak_bw, 2000);

drivers/interconnect/icc-kunit.c line 88

Quoted 10 lines
drivers/interconnect/icc-kunit.c new file +10 -0
+
+	icc_set_tag(path, 0xABC);
+	KUNIT_EXPECT_EQ(test, path->reqs[0].tag, 0xABC);
+
+	icc_disable(path);
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->avg_bw, 0);
+
+	icc_test_destroy_path(test, path);
+}
+

I also tried to run it and noticed that one of the tests is failing on my board...

KTAP version 1
1..1
KTAP version 1
# Subtest: interconnect
1..4
ok 1 icc_test_topology_integrity
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:207 Expected path_nodes[0]->avg_bw == 1000, but
path_nodes[0]->avg_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:208 Expected path_nodes[0]->peak_bw == 2000, but
path_nodes[0]->peak_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:209 Expected path_nodes[1]->avg_bw == 1000, but
path_nodes[1]->avg_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:210 Expected path_nodes[1]->peak_bw == 2000, but
path_nodes[1]->peak_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:216 Expected path_nodes[0]->avg_bw == 0, but
path_nodes[0]->avg_bw == 2147483647 (0x7fffffff)
not ok 2 icc_test_set_bw
ok 3 icc_test_aggregation
ok 4 icc_test_bulk_ops
# module: icc_kunit
# interconnect: pass:3 fail:1 skip:0 total:4
# Totals: pass:3 fail:1 skip:0 total:4
not ok 1 interconnect

...and the following diff seem to fix it:

drivers/interconnect/icc-kunit.c +9 -0
index 2178487f9527..060f640818a5 100644
@@ -79,6 +79,14 @@ static struct icc_node *icc_test_xlate(const struct of_phandle_args *spec, void
 	return NULL;
 }
 
+static int icc_test_get_bw(struct icc_node *node, u32 *avg, u32 *peak)
+{
+	*avg = 0;
+	*peak = 0;
+
+	return 0;
+}
+
 static int icc_test_init(struct kunit *test)
 {
 	struct icc_test_priv *priv;
@@ -95,6 +103,7 @@ static int icc_test_init(struct kunit *test)
 
 	priv->provider.set = icc_test_set;
 	priv->provider.aggregate = icc_test_aggregate;
+	priv->provider.get_bw = icc_test_get_bw;
 	priv->provider.xlate = icc_test_xlate;
 	priv->provider.dev = &priv->pdev->dev;
 	priv->provider.data = priv;

Could you please update and re-send?

Thanks,
Georgi

author maintainer
#2 lore raw

Hi Georgi,

Thanks for the review!

Quoted 113 lines · Georgi Djakov
Quoted 112 lines · Kuan-Wei Chiu

The interconnect framework currently lacks in-tree unit tests to verify the core logic in isolation. This makes it difficult to validate regression stability when modifying the provider/consumer APIs or aggregation logic.

Introduce a kunit test suite that verifies the fundamental behavior of the subsystem. The tests cover:
- Provider API (node creation, linking, topology construction).
- Consumer API (path enabling/disabling, bandwidth requests).
- Standard aggregation logic (accumulating bandwidth across links).
- Bulk operations for setting bandwidth on multiple paths.

The suite simulates a simple SoC topology with multiple masters and a shared bus to validate traffic aggregation behavior in a controlled software environment, without requiring specific hardware or Device Tree support.

---
Build and kunit tests passed

  drivers/interconnect/Kconfig     |  14 ++
  drivers/interconnect/Makefile    |   2 +
  drivers/interconnect/icc-kunit.c | 315 +++++++++++++++++++++++++++++++
  3 files changed, 331 insertions(+)

create mode 100644 drivers/interconnect/icc-kunit.c

drivers/interconnect/Kconfig +14 -0
index f2e49bd97d31..882dcb0b4a5b 100644
@@ -22,4 +22,18 @@ config INTERCONNECT_CLK
  	help
  	  Support for wrapping clocks into the interconnect nodes.
+config INTERCONNECT_KUNIT_TEST
+	tristate "KUnit tests for Interconnect framework"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the KUnit test suite for the generic system interconnect
+	  framework.
+
+	  The tests cover the core functionality of the interconnect subsystem,
+	  including provider/consumer APIs, topology management, and bandwidth
+	  aggregation logic.
+
+	  If unsure, say N.
+
  endif
drivers/interconnect/Makefile +2 -0
index b0a9a6753b9d..dc4c7b657c9d 100644
@@ -10,3 +10,5 @@ obj-$(CONFIG_INTERCONNECT_QCOM)		+= qcom/
  obj-$(CONFIG_INTERCONNECT_SAMSUNG)	+= samsung/
  obj-$(CONFIG_INTERCONNECT_CLK)		+= icc-clk.o
+
+obj-$(CONFIG_INTERCONNECT_KUNIT_TEST) += icc-kunit.o
drivers/interconnect/icc-kunit.c new file +48 -0
new file mode 100644
index 000000000000..2178487f9527
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit tests for the Interconnect framework.
+ *
+ * Copyright (c) 2025 Kuan-Wei Chiu <[email protected]>
+ *
+ * This suite verifies the behavior of the interconnect core, including
+ * topology construction, bandwidth aggregation, and path lifecycle.
+ */
+
+#include <kunit/platform_device.h>
+#include <kunit/test.h>
+#include <linux/interconnect-provider.h>
+#include <linux/interconnect.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/overflow.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include "internal.h"
+
+enum {
+	NODE_CPU = 100,
+	NODE_GPU,
+	NODE_BUS,
+	NODE_DDR,
+	NODE_MAX
+};
+
+struct test_node_data {
+	int id;
+	const char *name;
+	int num_links;
+	int links[2];
+};
+
+/*
+ * Static Topology:
+ * CPU -\
+ * -> BUS -> DDR
+ * GPU -/
+ */
+static const struct test_node_data test_topology[] = {
+	{ NODE_CPU, "cpu", 1, { NODE_BUS } },
+	{ NODE_GPU, "gpu", 1, { NODE_BUS } },
+	{ NODE_BUS, "bus", 1, { NODE_DDR } },
+	{ NODE_DDR, "ddr", 0, { } },
Quoted 8 lines

drivers/interconnect/icc-kunit.c line 54

Quoted 6 lines
drivers/interconnect/icc-kunit.c new file +6 -0
+};
+
+struct icc_test_priv {
+	struct icc_provider provider;
+	struct platform_device *pdev;
+	struct icc_node *nodes[NODE_MAX];

So nodes[] is a 104-element array? Is this intentional?

That was indeed an oversight.
In v2, I will simplify the test by making the node id 0 based.

Quoted 99 lines

[..]

Quoted 24 lines
drivers/interconnect/icc-kunit.c new file +24 -0
+static void icc_test_set_bw(struct kunit *test)
+{
+	struct icc_test_priv *priv = test->priv;
+	struct icc_path *path;
+	struct icc_node *path_nodes[3];
+	int ret;
+
+	/* Path: CPU -> BUS -> DDR */
+	path_nodes[0] = get_node(priv, NODE_CPU);
+	path_nodes[1] = get_node(priv, NODE_BUS);
+	path_nodes[2] = get_node(priv, NODE_DDR);
+
+	path = icc_test_create_path(test, path_nodes, 3);
+
+	ret = icc_enable(path);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
+	ret = icc_set_bw(path, 1000, 2000);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->avg_bw, 1000);
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->peak_bw, 2000);
+	KUNIT_EXPECT_EQ(test, path_nodes[1]->avg_bw, 1000);
+	KUNIT_EXPECT_EQ(test, path_nodes[1]->peak_bw, 2000);

drivers/interconnect/icc-kunit.c

Quoted 10 lines
drivers/interconnect/icc-kunit.c new file +10 -0
+
+	icc_set_tag(path, 0xABC);
+	KUNIT_EXPECT_EQ(test, path->reqs[0].tag, 0xABC);
+
+	icc_disable(path);
+	KUNIT_EXPECT_EQ(test, path_nodes[0]->avg_bw, 0);
+
+	icc_test_destroy_path(test, path);
+}
+

I also tried to run it and noticed that one of the tests is failing on my board...

KTAP version 1
1..1
KTAP version 1
# Subtest: interconnect
1..4
ok 1 icc_test_topology_integrity
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:207 Expected path_nodes[0]->avg_bw == 1000, but
path_nodes[0]->avg_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:208 Expected path_nodes[0]->peak_bw == 2000, but
path_nodes[0]->peak_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:209 Expected path_nodes[1]->avg_bw == 1000, but
path_nodes[1]->avg_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:210 Expected path_nodes[1]->peak_bw == 2000, but
path_nodes[1]->peak_bw == 2147483647 (0x7fffffff)
# icc_test_set_bw: EXPECTATION FAILED at drivers/interconnect/icc-kunit.c:216 Expected path_nodes[0]->avg_bw == 0, but
path_nodes[0]->avg_bw == 2147483647 (0x7fffffff)
not ok 2 icc_test_set_bw
ok 3 icc_test_aggregation
ok 4 icc_test_bulk_ops
# module: icc_kunit
# interconnect: pass:3 fail:1 skip:0 total:4
# Totals: pass:3 fail:1 skip:0 total:4
not ok 1 interconnect

...and the following diff seem to fix it:

drivers/interconnect/icc-kunit.c +9 -0
index 2178487f9527..060f640818a5 100644
@@ -79,6 +79,14 @@ static struct icc_node *icc_test_xlate(const struct of_phandle_args *spec, void
 	return NULL;
 }
 
+static int icc_test_get_bw(struct icc_node *node, u32 *avg, u32 *peak)
+{
+	*avg = 0;
+	*peak = 0;
+
+	return 0;
+}
+
 static int icc_test_init(struct kunit *test)
 {
 	struct icc_test_priv *priv;
@@ -95,6 +103,7 @@ static int icc_test_init(struct kunit *test)
 
 	priv->provider.set = icc_test_set;
 	priv->provider.aggregate = icc_test_aggregate;
+	priv->provider.get_bw = icc_test_get_bw;
 	priv->provider.xlate = icc_test_xlate;
 	priv->provider.dev = &priv->pdev->dev;
 	priv->provider.data = priv;
Quoted 1 line

Could you please update and re-send?

Thanks for pointing this out.
I will include this callback in v2.

Will send the v2 patch shortly.

Regards,
Kuan-Wei