drm/xe/tests: Add kunit tests for xe_any

Add simple sanity tests for all xe_any macros to make sure they
are working as expected.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
Link: https://patch.msgid.link/20260814171801.13347-18-michal.wajdeczko@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
This commit is contained in:
Michal Wajdeczko 2026-08-14 19:17:43 +02:00 committed by Rodrigo Vivi
parent c352c0bd4e
commit 14cd83cb77
No known key found for this signature in database
GPG Key ID: FA625F640EEB13CA
2 changed files with 214 additions and 0 deletions

View File

@ -7,6 +7,7 @@ xe_live_test-y = xe_live_test_mod.o
# Normal kunit tests
obj-$(CONFIG_DRM_XE_KUNIT_TEST) += xe_test.o
xe_test-y = xe_test_mod.o \
xe_any_kunit.o \
xe_args_test.o \
xe_pci_test.o \
xe_rtp_tables_test.o \

View File

@ -0,0 +1,213 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright © 2026 Intel Corporation
*/
#include <kunit/test.h>
#include "tests/xe_kunit_helpers.h"
#include "tests/xe_pci_test.h"
#include "xe_any.h"
#include "xe_device.h"
static void test_to_xe(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
const struct xe_device *cxe = xe;
const struct xe_tile *ctile = tile;
const struct xe_gt *cgt = gt;
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(xe));
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(tile));
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(gt));
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(drm));
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(dev));
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_to_xe(pdev));
KUNIT_EXPECT_PTR_EQ(test, cxe, xe_any_to_xe(cxe));
KUNIT_EXPECT_PTR_EQ(test, cxe, xe_any_to_xe(ctile));
KUNIT_EXPECT_PTR_EQ(test, cxe, xe_any_to_xe(cgt));
}
static void test_to_pdev(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(xe));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(tile));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(gt));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(drm));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(dev));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(pdev));
/* mimic early probe stage */
dev_set_drvdata(xe->drm.dev, NULL);
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(dev));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_to_pdev(pdev));
}
static void test_to_dev(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(xe));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(tile));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(gt));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(drm));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(dev));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(pdev));
/* mimic early probe stage */
dev_set_drvdata(xe->drm.dev, NULL);
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(dev));
KUNIT_EXPECT_PTR_EQ(test, dev, xe_any_to_dev(pdev));
}
static void test_to_drm(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(xe));
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(tile));
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(gt));
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(drm));
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(dev));
KUNIT_EXPECT_PTR_EQ(test, drm, xe_any_to_drm(pdev));
}
static void test_if_pdev(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_TRUE(test, xe && drm && tile && gt && dev && pdev);
KUNIT_EXPECT_NULL(test, xe_any_if_pdev(xe));
KUNIT_EXPECT_NULL(test, xe_any_if_pdev(tile));
KUNIT_EXPECT_NULL(test, xe_any_if_pdev(gt));
KUNIT_EXPECT_NULL(test, xe_any_if_pdev(drm));
KUNIT_EXPECT_NULL(test, xe_any_if_pdev(dev));
KUNIT_EXPECT_PTR_EQ(test, pdev, xe_any_if_pdev(pdev));
}
static void test_if_xe(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_TRUE(test, xe && drm && tile && gt && dev && pdev);
KUNIT_EXPECT_PTR_EQ(test, xe, xe_any_if_xe(xe));
KUNIT_EXPECT_NULL(test, xe_any_if_xe(tile));
KUNIT_EXPECT_NULL(test, xe_any_if_xe(gt));
KUNIT_EXPECT_NULL(test, xe_any_if_xe(drm));
KUNIT_EXPECT_NULL(test, xe_any_if_xe(dev));
KUNIT_EXPECT_NULL(test, xe_any_if_xe(pdev));
}
static void test_if_tile(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_TRUE(test, xe && drm && tile && gt && dev && pdev);
KUNIT_EXPECT_NULL(test, xe_any_if_tile(xe));
KUNIT_EXPECT_PTR_EQ(test, tile, xe_any_if_tile(tile));
KUNIT_EXPECT_NULL(test, xe_any_if_tile(gt));
KUNIT_EXPECT_NULL(test, xe_any_if_tile(drm));
KUNIT_EXPECT_NULL(test, xe_any_if_tile(dev));
KUNIT_EXPECT_NULL(test, xe_any_if_tile(pdev));
}
static void test_if_gt(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct drm_device *drm = &xe->drm;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
KUNIT_EXPECT_TRUE(test, xe && drm && tile && gt && dev && pdev);
KUNIT_EXPECT_NULL(test, xe_any_if_gt(xe));
KUNIT_EXPECT_NULL(test, xe_any_if_gt(tile));
KUNIT_EXPECT_PTR_EQ(test, gt, xe_any_if_gt(gt));
KUNIT_EXPECT_NULL(test, xe_any_if_gt(drm));
KUNIT_EXPECT_NULL(test, xe_any_if_gt(dev));
KUNIT_EXPECT_NULL(test, xe_any_if_gt(pdev));
}
static void test_to_id(struct kunit *test)
{
struct xe_device *xe = test->priv;
struct xe_tile *tile = xe_device_get_root_tile(xe);
struct xe_gt *gt = tile->primary_gt;
struct device *dev = xe->drm.dev;
struct pci_dev *pdev = to_pci_dev(dev);
const struct xe_device *cxe = xe;
const struct xe_tile *ctile = tile;
const struct xe_gt *cgt = gt;
tile->id = 1;
gt->info.id = 2;
KUNIT_EXPECT_EQ(test, 0, xe_any_id(xe));
KUNIT_EXPECT_EQ(test, 1, xe_any_id(tile));
KUNIT_EXPECT_EQ(test, 2, xe_any_id(gt));
KUNIT_EXPECT_EQ(test, 0, xe_any_id(dev));
KUNIT_EXPECT_EQ(test, 0, xe_any_id(pdev));
KUNIT_EXPECT_EQ(test, 0, xe_any_id(cxe));
KUNIT_EXPECT_EQ(test, 1, xe_any_id(ctile));
KUNIT_EXPECT_EQ(test, 2, xe_any_id(cgt));
}
static struct kunit_case xe_any_tests[] = {
KUNIT_CASE(test_to_xe),
KUNIT_CASE(test_to_dev),
KUNIT_CASE(test_to_pdev),
KUNIT_CASE(test_to_drm),
KUNIT_CASE(test_if_pdev),
KUNIT_CASE(test_if_xe),
KUNIT_CASE(test_if_tile),
KUNIT_CASE(test_if_gt),
KUNIT_CASE(test_to_id),
{}
};
static struct kunit_suite xe_any_test_suite = {
.name = "xe_any",
.test_cases = xe_any_tests,
.init = xe_kunit_helper_xe_device_test_init,
};
kunit_test_suite(xe_any_test_suite);