Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Michal Wajdeczko" <michal.wajdeczko@intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>
Subject: [PATCH v2 08/13] drm/xe/tests: Add GuC KLV helpers basic tests
Date: Wed,  8 Jul 2026 00:08:10 +0200	[thread overview]
Message-ID: <20260707220816.677-9-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20260707220816.677-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>
Reviewed-by: Michał Winiarski <michal.winiarski@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 9225a9066b8a..f0ad5adc6699 100644
--- a/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
+++ b/drivers/gpu/drm/xe/xe_guc_klv_helpers.c
@@ -369,3 +369,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


  parent reply	other threads:[~2026-07-07 22:08 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 22:08 [PATCH v2 00/13] drm/xe: Add and use more KLV helpers Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 01/13] drm/xe/guc: Allow to print single KLV Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 02/13] drm/xe/guc: Prepare to print group KLVs Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 03/13] drm/xe/guc: Add basic KLV encoding helpers Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 04/13] drm/xe/guc: Add string KLV encoding helper Michal Wajdeczko
2026-07-09 12:51   ` Michał Winiarski
2026-07-07 22:08 ` [PATCH v2 05/13] drm/xe/guc: Add object " Michal Wajdeczko
2026-07-09 12:53   ` Michał Winiarski
2026-07-07 22:08 ` [PATCH v2 06/13] drm/xe/guc: Add KLV parsing helper Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 07/13] drm/xe/guc: Formalize Reserved KLVs Michal Wajdeczko
2026-07-10 17:25   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` Michal Wajdeczko [this message]
2026-07-07 22:08 ` [PATCH v2 09/13] drm/xe/tests: Add string encoding helper test Michal Wajdeczko
2026-07-08 18:07   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 10/13] drm/xe/tests: Add object " Michal Wajdeczko
2026-07-10 19:59   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 11/13] drm/xe/tests: Add GuC KLV printer test Michal Wajdeczko
2026-07-11  7:36   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 12/13] drm/xe/tests: Add migration packet test Michal Wajdeczko
2026-07-08 18:09   ` [PATCH v3 " Michal Wajdeczko
2026-07-07 22:08 ` [PATCH v2 13/13] drm/xe/pf: Handle migration descriptor using KLV helpers Michal Wajdeczko
2026-07-07 22:16 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev2) Patchwork
2026-07-07 22:18 ` ✓ CI.KUnit: success " Patchwork
2026-07-07 23:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-08  0:20 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-08 19:04 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev4) Patchwork
2026-07-08 19:05 ` ✓ CI.KUnit: success " Patchwork
2026-07-08 19:55 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-08 23:56 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-10 17:31 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev5) Patchwork
2026-07-10 17:32 ` ✓ CI.KUnit: success " Patchwork
2026-07-10 18:22 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-11  4:04 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-11  7:42 ` ✗ CI.checkpatch: warning for drm/xe: Add and use more KLV helpers (rev7) Patchwork
2026-07-11  7:43 ` ✓ CI.KUnit: success " Patchwork
2026-07-11  8:18 ` ✓ Xe.CI.BAT: " Patchwork
2026-07-11 11:12 ` ✓ 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=20260707220816.677-9-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.winiarski@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox