From nobody Sat Feb 7 17:20:53 2026 Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C33228C037 for ; Sat, 10 Jan 2026 20:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768077006; cv=none; b=ubTJcI+pnYeiZEwOslUaQRRKOQeItSUNp3pSDD7Ro6HkMJvT8c2lNX60kf1I5HPueeb8mqZnGLV6iZHDfVeUbntuzKb543WRr0/njdynLVO7QqYsee2QPd0ugvRzOFQuX+S0hs1V+GMid+GnvbR+JL4OJv1WUZ4Dd+wtjUoF5n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768077006; c=relaxed/simple; bh=a4HmEfh9BqR7pTBiKgNox5hkDeetZuvGFpwNpPQK9TA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CQ47bVouioqHJ02sdFPW5D2vV9m1UpNBdGqjEoOq19MBhLb950wikbzSiQZ96Uwse1frfE4zxHtbNIjLPPnJyqEyBeCM8XTGir1ScSYFEAOyjSo2ySuNq6Wlrh24E0zUE3BxA0c1kS1NfYgisCMW7gqB26YRSJDLXbuohbL23Io= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cwksx1RE; arc=none smtp.client-ip=209.85.222.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cwksx1RE" Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-93f5729f159so3396718241.0 for ; Sat, 10 Jan 2026 12:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768077003; x=1768681803; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Y2QgzlraiAQ3LvbrUcID54KuJyrj3432Mgk/LsLaWtE=; b=cwksx1REuZEAFY2w/XwVINIb9aJuqbnjSjX2k5SzUzih/pGE2YapMho2bDEgYpcbrw AaKomhe0ByEZhK9t3w+JIVPD2ONQwD5criIsm3Qf9uoDWFiZm88LG4zC0rLXNlSy5Dp0 IGMIwnQnk1AqCq3WG0vHXEHd6FsceCDy7S/nGH0gkFDPHpFKQgcKDZ4ix6DH4vsU4IMf +/R6RLvAutFBBSdJIXrhdl2YP3ndbaZfqaAFHAuXPajGcDj80n8AkjEi11Y5BRqLBMpe 3jp5sIoqGy5eg+aZXiou2aKqrJJXRG4U1gVbE3F7VOSoiO3hn3AuKbw9RXsjy9p161Sk lCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768077003; x=1768681803; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Y2QgzlraiAQ3LvbrUcID54KuJyrj3432Mgk/LsLaWtE=; b=Cu97i7k9KzyAqmqsvJanlb/E+jmOSa7j87Ijg56WYErT8E6Oj0vGG+m/IdbBvtmGZ3 wGgzfaUHtMy0hrl9aiK52Im5fM0Uvq7/g1P9mL2pftKmBlTlZ6kkmVCWvoX+vs8Xk3ae EhgTKQmkwA2+QwQjpqQ/znW8wIjFYlPsDXAc0iH1p14w79DJHtDuh1NVNqjwEOcIa+s2 o+M0FEmU/urxF57yyoY0UdYxBFKsyl983VR5BCiorWqH2aVN2h6KMgCuKkK3IFiWhjoC Sbrby5/V4XLkHjbPxvUUKEqZJM8AwLuIlct4uWLdLmsno4ilSOziGwwxbbaXMnp3VBAW 4PKA== X-Forwarded-Encrypted: i=1; AJvYcCUiIfRY7MtF5f0vmvpYI23P+eWzqRS5/FiLBsBnEGuv+hG+6DEnsrNOZ0yHHOtuZmpgwnBaFpGejnyudBk=@vger.kernel.org X-Gm-Message-State: AOJu0YwK51YSsIQyoX8DmZlHnyRlGVJCrKdBbkp7zBlTtdcrzhrTHrNr cvW3EkxtUvmB4/3XkB53c4IiK3QBDC0VS7IFK9sMq1nJlkTKpqn+uEpzR5NqHw== X-Gm-Gg: AY/fxX5qLZR9iuzHrBYqco1monSVBaG35otyy91SG82rOiKcwNZk29dOdXr7GPEShlp oteiRDvcEbgBNAae/TD+hmvnGYFQMSvPjvCB0o5UklsTko+kVPaYi2a0OqGYmNkM6Qg5EsHc8pB Aa22gctAwv8UlJAu0fXbgzeBKs/UU+JsP48wBYj2+lWx7mDsy9sx/BUJnIqsKdQOaYlvDWX/ayk 95nGGaGC+ReoloWbTdFS0/6iefzckvUhVv78J3ZGfxe/6DHz2XfxczqnDNqJFIu/Ra417R/qNEo b8xu9X4PBFTwlPR/JUZmHmXuASYvjIY/HRovVGbZvojWPd72e0FN78czZ+jMPCzVqf9s3Kb3lGS C6bIeOGWv2neJhVRiY1oPOTN9FUCXMBKy4G5ygVoFA78lRkS/PZA34P4EsVSjE1HAgZFSlhz+7n KpmYSJF+cMjWoTdw28k/LLu7dpMm/OIW+YHAOX4SeXJQbfLuSRGxUFxb73KDv1ttmOk6RZvq47S a/BW1lbRq0Qrttu4s2+zEZ5nOtTIswR X-Google-Smtp-Source: AGHT+IHJyW9uEXWCJiI83QcTAYmX1GcC5s0mRQdqyVrWqtgcrZ+wGI7/QW2fOBYzChEaW0ufq8KGjQ== X-Received: by 2002:a17:903:2b05:b0:29f:1738:348e with SMTP id d9443c01a7336-2a3ee433c46mr132033055ad.15.1768070603633; Sat, 10 Jan 2026 10:43:23 -0800 (PST) Received: from visitorckw-work01.c.googlers.com.com (25.118.81.34.bc.googleusercontent.com. [34.81.118.25]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3c5ce06sm132349985ad.44.2026.01.10.10.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 10:43:23 -0800 (PST) From: Kuan-Wei Chiu To: djakov@kernel.org Cc: jserv@ccns.ncku.edu.tw, marscheng@google.com, wllee@google.com, aarontian@google.com, hsuanting@google.com, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Kuan-Wei Chiu Subject: [PATCH v2] interconnect: Add kunit tests for core functionality Date: Sat, 10 Jan 2026 18:43:09 +0000 Message-ID: <20260110184309.906735-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Kuan-Wei Chiu --- Changes in v2: - Switch to 0-based node IDs to avoid sparse array usage. - Implement .get_bw callback to ensure zero initial bandwidth. drivers/interconnect/Kconfig | 14 ++ drivers/interconnect/Makefile | 2 + drivers/interconnect/icc-kunit.c | 324 +++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+) create mode 100644 drivers/interconnect/icc-kunit.c diff --git a/drivers/interconnect/Kconfig b/drivers/interconnect/Kconfig index f2e49bd97d31..882dcb0b4a5b 100644 --- a/drivers/interconnect/Kconfig +++ b/drivers/interconnect/Kconfig @@ -22,4 +22,18 @@ config INTERCONNECT_CLK help Support for wrapping clocks into the interconnect nodes. =20 +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 diff --git a/drivers/interconnect/Makefile b/drivers/interconnect/Makefile index b0a9a6753b9d..dc4c7b657c9d 100644 --- a/drivers/interconnect/Makefile +++ b/drivers/interconnect/Makefile @@ -10,3 +10,5 @@ obj-$(CONFIG_INTERCONNECT_QCOM) +=3D qcom/ obj-$(CONFIG_INTERCONNECT_SAMSUNG) +=3D samsung/ =20 obj-$(CONFIG_INTERCONNECT_CLK) +=3D icc-clk.o + +obj-$(CONFIG_INTERCONNECT_KUNIT_TEST) +=3D icc-kunit.o diff --git a/drivers/interconnect/icc-kunit.c b/drivers/interconnect/icc-ku= nit.c new file mode 100644 index 000000000000..bad2b583737b --- /dev/null +++ b/drivers/interconnect/icc-kunit.c @@ -0,0 +1,324 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit tests for the Interconnect framework. + * + * Copyright (c) 2025 Kuan-Wei Chiu + * + * This suite verifies the behavior of the interconnect core, including + * topology construction, bandwidth aggregation, and path lifecycle. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "internal.h" + +enum { + NODE_CPU, + 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[] =3D { + { 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]; +}; + +static struct icc_node *get_node(struct icc_test_priv *priv, int id) +{ + int idx =3D id - NODE_CPU; + + if (idx < 0 || idx >=3D ARRAY_SIZE(test_topology)) + return NULL; + return priv->nodes[idx]; +} + +static int icc_test_set(struct icc_node *src, struct icc_node *dst) +{ + return 0; +} + +static int icc_test_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, + u32 peak_bw, u32 *agg_avg, u32 *agg_peak) +{ + return icc_std_aggregate(node, tag, avg_bw, peak_bw, agg_avg, agg_peak); +} + +static struct icc_node *icc_test_xlate(const struct of_phandle_args *spec,= void *data) +{ + return NULL; +} + +static int icc_test_get_bw(struct icc_node *node, u32 *avg, u32 *peak) +{ + *avg =3D 0; + *peak =3D 0; + + return 0; +} + +static int icc_test_init(struct kunit *test) +{ + struct icc_test_priv *priv; + struct icc_node *node; + int i, j, ret; + + priv =3D kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); + test->priv =3D priv; + + priv->pdev =3D kunit_platform_device_alloc(test, "icc-test-dev", -1); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv->pdev); + KUNIT_ASSERT_EQ(test, kunit_platform_device_add(test, priv->pdev), 0); + + priv->provider.set =3D icc_test_set; + priv->provider.aggregate =3D icc_test_aggregate; + priv->provider.xlate =3D icc_test_xlate; + priv->provider.get_bw =3D icc_test_get_bw; + priv->provider.dev =3D &priv->pdev->dev; + priv->provider.data =3D priv; + INIT_LIST_HEAD(&priv->provider.nodes); + + ret =3D icc_provider_register(&priv->provider); + KUNIT_ASSERT_EQ(test, ret, 0); + + for (i =3D 0; i < ARRAY_SIZE(test_topology); i++) { + const struct test_node_data *data =3D &test_topology[i]; + + node =3D icc_node_create(data->id); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node); + + node->name =3D data->name; + icc_node_add(node, &priv->provider); + priv->nodes[i] =3D node; + } + + for (i =3D 0; i < ARRAY_SIZE(test_topology); i++) { + const struct test_node_data *data =3D &test_topology[i]; + struct icc_node *src =3D get_node(priv, data->id); + + for (j =3D 0; j < data->num_links; j++) { + ret =3D icc_link_create(src, data->links[j]); + KUNIT_ASSERT_EQ_MSG(test, ret, 0, "Failed to link %s->%d", + src->name, data->links[j]); + } + } + + icc_sync_state(&priv->pdev->dev); + + return 0; +} + +static void icc_test_exit(struct kunit *test) +{ + struct icc_test_priv *priv =3D test->priv; + + icc_nodes_remove(&priv->provider); + icc_provider_deregister(&priv->provider); +} + +/* + * Helper to construct a mock path. + * + * Because we are bypassing icc_get(), we must manually link the requests + * to the nodes' req_list so that icc_std_aggregate() can discover them. + */ +static struct icc_path *icc_test_create_path(struct kunit *test, + struct icc_node **nodes, int num) +{ + struct icc_path *path; + int i; + + path =3D kunit_kzalloc(test, struct_size(path, reqs, num), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, path); + + path->num_nodes =3D num; + for (i =3D 0; i < num; i++) { + path->reqs[i].node =3D nodes[i]; + hlist_add_head(&path->reqs[i].req_node, &nodes[i]->req_list); + } + path->name =3D "mock-path"; + + return path; +} + +static void icc_test_destroy_path(struct kunit *test, struct icc_path *pat= h) +{ + int i; + + for (i =3D 0; i < path->num_nodes; i++) + hlist_del(&path->reqs[i].req_node); + + kunit_kfree(test, path); +} + +static void icc_test_topology_integrity(struct kunit *test) +{ + struct icc_test_priv *priv =3D test->priv; + struct icc_node *cpu =3D get_node(priv, NODE_CPU); + struct icc_node *bus =3D get_node(priv, NODE_BUS); + + KUNIT_EXPECT_EQ(test, cpu->num_links, 1); + KUNIT_EXPECT_PTR_EQ(test, cpu->links[0], bus); + KUNIT_EXPECT_PTR_EQ(test, cpu->provider, &priv->provider); +} + +static void icc_test_set_bw(struct kunit *test) +{ + struct icc_test_priv *priv =3D test->priv; + struct icc_path *path; + struct icc_node *path_nodes[3]; + int ret; + + /* Path: CPU -> BUS -> DDR */ + path_nodes[0] =3D get_node(priv, NODE_CPU); + path_nodes[1] =3D get_node(priv, NODE_BUS); + path_nodes[2] =3D get_node(priv, NODE_DDR); + + path =3D icc_test_create_path(test, path_nodes, 3); + + ret =3D icc_enable(path); + KUNIT_ASSERT_EQ(test, ret, 0); + + ret =3D 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); + + 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); +} + +static void icc_test_aggregation(struct kunit *test) +{ + struct icc_test_priv *priv =3D test->priv; + struct icc_path *path_cpu, *path_gpu; + struct icc_node *nodes_cpu[3], *nodes_gpu[2]; + struct icc_node *bus =3D get_node(priv, NODE_BUS); + int ret; + + nodes_cpu[0] =3D get_node(priv, NODE_CPU); + nodes_cpu[1] =3D bus; + nodes_cpu[2] =3D get_node(priv, NODE_DDR); + path_cpu =3D icc_test_create_path(test, nodes_cpu, 3); + + nodes_gpu[0] =3D get_node(priv, NODE_GPU); + nodes_gpu[1] =3D bus; + path_gpu =3D icc_test_create_path(test, nodes_gpu, 2); + + icc_enable(path_cpu); + icc_enable(path_gpu); + + ret =3D icc_set_bw(path_cpu, 1000, 1000); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, bus->avg_bw, 1000); + + ret =3D icc_set_bw(path_gpu, 2000, 2000); + KUNIT_EXPECT_EQ(test, ret, 0); + + /* Bus aggregates: CPU(1000) + GPU(2000) */ + KUNIT_EXPECT_EQ(test, bus->avg_bw, 3000); + /* Peak aggregates: max(CPU, GPU) */ + KUNIT_EXPECT_EQ(test, bus->peak_bw, 2000); + + icc_test_destroy_path(test, path_cpu); + icc_test_destroy_path(test, path_gpu); +} + +static void icc_test_bulk_ops(struct kunit *test) +{ + struct icc_test_priv *priv =3D test->priv; + struct icc_node *nodes_cpu[3], *nodes_gpu[2]; + struct icc_bulk_data bulk[2]; + int ret; + + nodes_cpu[0] =3D get_node(priv, NODE_CPU); + nodes_cpu[1] =3D get_node(priv, NODE_BUS); + nodes_cpu[2] =3D get_node(priv, NODE_DDR); + + nodes_gpu[0] =3D get_node(priv, NODE_GPU); + nodes_gpu[1] =3D get_node(priv, NODE_BUS); + + bulk[0].path =3D icc_test_create_path(test, nodes_cpu, 3); + bulk[0].avg_bw =3D 500; + bulk[0].peak_bw =3D 500; + + bulk[1].path =3D icc_test_create_path(test, nodes_gpu, 2); + bulk[1].avg_bw =3D 600; + bulk[1].peak_bw =3D 600; + + ret =3D icc_bulk_set_bw(2, bulk); + KUNIT_EXPECT_EQ(test, ret, 0); + /* Paths disabled, bandwidth should be 0 */ + KUNIT_EXPECT_EQ(test, get_node(priv, NODE_BUS)->avg_bw, 0); + + ret =3D icc_bulk_enable(2, bulk); + KUNIT_EXPECT_EQ(test, ret, 0); + /* Paths enabled, aggregation applies */ + KUNIT_EXPECT_EQ(test, get_node(priv, NODE_BUS)->avg_bw, 1100); + + icc_bulk_disable(2, bulk); + KUNIT_EXPECT_EQ(test, get_node(priv, NODE_BUS)->avg_bw, 0); + + icc_test_destroy_path(test, bulk[0].path); + icc_test_destroy_path(test, bulk[1].path); +} + +static struct kunit_case icc_test_cases[] =3D { + KUNIT_CASE(icc_test_topology_integrity), + KUNIT_CASE(icc_test_set_bw), + KUNIT_CASE(icc_test_aggregation), + KUNIT_CASE(icc_test_bulk_ops), + {} +}; + +static struct kunit_suite icc_test_suite =3D { + .name =3D "interconnect", + .init =3D icc_test_init, + .exit =3D icc_test_exit, + .test_cases =3D icc_test_cases, +}; + +kunit_test_suite(icc_test_suite); + +MODULE_AUTHOR("Kuan-Wei Chiu "); +MODULE_DESCRIPTION("KUnit tests for the Interconnect framework"); +MODULE_LICENSE("GPL"); --=20 2.52.0.457.g6b5491de43-goog