From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Subject: [PATCH 08/13] drm/xe/tests: Add GuC KLV helpers basic tests
Date: Tue, 30 Jun 2026 15:26:27 +0200 [thread overview]
Message-ID: <20260630132633.32804-9-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20260630132633.32804-1-michal.wajdeczko@intel.com>
We will be making more extensive use of GuC KLV helpers. Add simple
tests to ensure the helpers are working as expected.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
.../drm/xe/tests/xe_guc_klv_helpers_kunit.c | 99 +++++++++++++++++++
drivers/gpu/drm/xe/xe_guc_klv_helpers.c | 4 +
2 files changed, 103 insertions(+)
create mode 100644 drivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c
diff --git a/drivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c b/drivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c
new file mode 100644
index 000000000000..f87189ef13d5
--- /dev/null
+++ b/drivers/gpu/drm/xe/tests/xe_guc_klv_helpers_kunit.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0 AND MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#include <kunit/test.h>
+#include <kunit/test-bug.h>
+
+#define TEST_KEY (GUC_KLV_RESERVED_RANGE_START + 0x3de)
+#define TEST_PAD 0xdeadbeef
+
+static void test_count(struct kunit *test)
+{
+ u32 value = 0x12345678;
+ u16 key = TEST_KEY;
+ u32 klvs[] = {
+ PREP_GUC_KLV(key + 0, 0),
+ PREP_GUC_KLV(key + 1, 1), value,
+ PREP_GUC_KLV(key + 2, 2), value, value,
+ PREP_GUC_KLV(key + 3, 0),
+ 0, /* padding */
+ };
+
+ KUNIT_EXPECT_EQ(test, 0, xe_guc_klv_count(klvs, 0));
+ KUNIT_EXPECT_EQ(test, 1, xe_guc_klv_count(klvs, 1));
+ KUNIT_EXPECT_GT(test, 0, xe_guc_klv_count(klvs, 2));
+ KUNIT_EXPECT_EQ(test, 2, xe_guc_klv_count(klvs, 3));
+ KUNIT_EXPECT_GT(test, 0, xe_guc_klv_count(klvs, 4));
+ KUNIT_EXPECT_GT(test, 0, xe_guc_klv_count(klvs, 5));
+ KUNIT_EXPECT_EQ(test, 3, xe_guc_klv_count(klvs, 6));
+ KUNIT_EXPECT_EQ(test, 4, xe_guc_klv_count(klvs, 7));
+
+ /* 0 is treated as reserved KLV { KEY=0, LEN=0 } */
+ KUNIT_EXPECT_EQ(test, 5, xe_guc_klv_count(klvs, 8));
+}
+
+static void test_encode_u32(struct kunit *test)
+{
+ u32 *fail = ERR_PTR(-ENOMEM);
+ u32 value = 0x12345678;
+ u16 key = TEST_KEY;
+ u32 klvs[16];
+
+ memset32(klvs, TEST_PAD, ARRAY_SIZE(klvs));
+
+ KUNIT_EXPECT_PTR_EQ(test, ERR_PTR(-ENOSPC), xe_guc_klv_encode_u32(klvs, 0, key, value));
+ KUNIT_EXPECT_PTR_EQ(test, ERR_PTR(-ENOSPC), xe_guc_klv_encode_u32(klvs, 1, key, value));
+
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe_guc_klv_encode_u32(klvs, 2, key, value));
+ KUNIT_EXPECT_EQ(test, klvs[0], PREP_GUC_KLV(key, 1));
+ KUNIT_EXPECT_EQ(test, klvs[1], value);
+ KUNIT_EXPECT_EQ(test, klvs[2], TEST_PAD);
+ KUNIT_EXPECT_PTR_EQ(test, &klvs[2], xe_guc_klv_encode_u32(klvs, 2, key, value));
+ KUNIT_EXPECT_PTR_EQ(test,
+ xe_guc_klv_encode_u32(klvs, 2, key, value),
+ xe_guc_klv_encode_u32(klvs, ARRAY_SIZE(klvs), key, value));
+
+ KUNIT_ASSERT_PTR_EQ(test, fail, xe_guc_klv_encode_u32(fail, ARRAY_SIZE(klvs), key, value));
+}
+
+static void test_encode_u64(struct kunit *test)
+{
+ u64 value = 0x123456789abcdef0;
+ u32 *fail = ERR_PTR(-ENOMEM);
+ u16 key = TEST_KEY;
+ u32 klvs[16];
+
+ memset32(klvs, TEST_PAD, ARRAY_SIZE(klvs));
+
+ KUNIT_EXPECT_PTR_EQ(test, ERR_PTR(-ENOSPC), xe_guc_klv_encode_u64(klvs, 0, key, value));
+ KUNIT_EXPECT_PTR_EQ(test, ERR_PTR(-ENOSPC), xe_guc_klv_encode_u64(klvs, 1, key, value));
+ KUNIT_EXPECT_PTR_EQ(test, ERR_PTR(-ENOSPC), xe_guc_klv_encode_u64(klvs, 2, key, value));
+
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe_guc_klv_encode_u64(klvs, 3, key, value));
+ KUNIT_EXPECT_EQ(test, klvs[0], PREP_GUC_KLV(key, 2));
+ KUNIT_EXPECT_EQ(test, klvs[1], lower_32_bits(value));
+ KUNIT_EXPECT_EQ(test, klvs[2], upper_32_bits(value));
+ KUNIT_EXPECT_EQ(test, klvs[3], TEST_PAD);
+ KUNIT_EXPECT_PTR_EQ(test, &klvs[3], xe_guc_klv_encode_u64(klvs, 3, key, value));
+ KUNIT_EXPECT_PTR_EQ(test,
+ xe_guc_klv_encode_u64(klvs, 3, key, value),
+ xe_guc_klv_encode_u64(klvs, ARRAY_SIZE(klvs), key, value));
+
+ KUNIT_ASSERT_PTR_EQ(test, fail, xe_guc_klv_encode_u64(fail, ARRAY_SIZE(klvs), key, value));
+}
+
+static struct kunit_case guc_klv_helpers_test_cases[] = {
+ KUNIT_CASE(test_count),
+ KUNIT_CASE(test_encode_u32),
+ KUNIT_CASE(test_encode_u64),
+ {}
+};
+
+static struct kunit_suite guc_klv_helpers_suite = {
+ .name = "guc_klv_helpers",
+ .test_cases = guc_klv_helpers_test_cases,
+};
+
+kunit_test_suite(guc_klv_helpers_suite);
diff --git a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
index 3f5c88e2c949..96f5cd2ab4f3 100644
--- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
+++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
@@ -362,3 +362,7 @@ int xe_guc_klv_parser(const u32 *klvs, u32 num_dwords, void *obj,
return total;
}
+
+#if IS_BUILTIN(CONFIG_DRM_XE_KUNIT_TEST)
+#include "tests/xe_guc_klv_helpers_kunit.c"
+#endif
--
2.47.1
next prev parent reply other threads:[~2026-06-30 13:26 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 13:26 [PATCH 00/13] drm/xe: Add and use more KLV helpers Michal Wajdeczko
2026-06-30 13:26 ` [PATCH 01/13] drm/xe/guc: Allow to print single KLV Michal Wajdeczko
2026-07-03 11:10 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 02/13] drm/xe/guc: Prepare to print group KLVs Michal Wajdeczko
2026-07-03 11:11 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 03/13] drm/xe/guc: Add basic KLV encoding helpers Michal Wajdeczko
2026-07-03 12:58 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 04/13] drm/xe/guc: Add string KLV encoding helper Michal Wajdeczko
2026-07-03 13:29 ` Michał Winiarski
2026-07-06 16:04 ` Michal Wajdeczko
2026-06-30 13:26 ` [PATCH 05/13] drm/xe/guc: Add object " Michal Wajdeczko
2026-07-03 14:33 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 06/13] drm/xe/guc: Add KLV parsing helper Michal Wajdeczko
2026-07-03 14:40 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 07/13] drm/xe/guc: Formalize Reserved KLVs Michal Wajdeczko
2026-07-03 13:31 ` Michał Winiarski
2026-06-30 13:26 ` Michal Wajdeczko [this message]
2026-07-03 14:17 ` [PATCH 08/13] drm/xe/tests: Add GuC KLV helpers basic tests Michał Winiarski
2026-06-30 13:26 ` [PATCH 09/13] drm/xe/tests: Add string encoding helper test Michal Wajdeczko
2026-07-03 20:40 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 10/13] drm/xe/tests: Add object " Michal Wajdeczko
2026-07-03 20:47 ` Michał Winiarski
2026-07-06 16:34 ` Michal Wajdeczko
2026-06-30 13:26 ` [PATCH 11/13] drm/xe/tests: Add GuC KLV printer test Michal Wajdeczko
2026-07-03 20:49 ` Michał Winiarski
2026-06-30 13:26 ` [PATCH 12/13] drm/xe/tests: Add migration packet test Michal Wajdeczko
2026-07-03 13:44 ` Michał Winiarski
2026-07-06 16:42 ` Michal Wajdeczko
2026-07-07 22:14 ` Michal Wajdeczko
2026-06-30 13:26 ` [PATCH 13/13] drm/xe/pf: Handle migration descriptor using KLV helpers Michal Wajdeczko
2026-07-03 20:50 ` Michał Winiarski
2026-06-30 13:47 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more " Patchwork
2026-06-30 13:49 ` ✓ CI.KUnit: success " Patchwork
2026-06-30 14:42 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-01 5:22 ` ✓ Xe.CI.FULL: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260630132633.32804-9-michal.wajdeczko@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.