1dd08ebf6SMatthew Brost /* SPDX-License-Identifier: GPL-2.0 AND MIT */ 2dd08ebf6SMatthew Brost /* 3dd08ebf6SMatthew Brost * Copyright © 2022 Intel Corporation 4dd08ebf6SMatthew Brost */ 5dd08ebf6SMatthew Brost 63457388fSLucas De Marchi #ifndef _XE_TEST_H_ 73457388fSLucas De Marchi #define _XE_TEST_H_ 8dd08ebf6SMatthew Brost 9dd08ebf6SMatthew Brost #include <linux/types.h> 10dd08ebf6SMatthew Brost 11dd08ebf6SMatthew Brost #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) 12dd08ebf6SMatthew Brost #include <kunit/test.h> 13*bd85e00fSMichal Wajdeczko #include <kunit/test-bug.h> 14dd08ebf6SMatthew Brost 15dd08ebf6SMatthew Brost /* 16dd08ebf6SMatthew Brost * Each test that provides a kunit private test structure, place a test id 17dd08ebf6SMatthew Brost * here and point the kunit->priv to an embedded struct xe_test_priv. 18dd08ebf6SMatthew Brost */ 19dd08ebf6SMatthew Brost enum xe_test_priv_id { 20dd08ebf6SMatthew Brost XE_TEST_LIVE_DMA_BUF, 217cba3396SThomas Hellström XE_TEST_LIVE_MIGRATE, 22dd08ebf6SMatthew Brost }; 23dd08ebf6SMatthew Brost 24dd08ebf6SMatthew Brost /** 25dd08ebf6SMatthew Brost * struct xe_test_priv - Base class for test private info 26dd08ebf6SMatthew Brost * @id: enum xe_test_priv_id to identify the subclass. 27dd08ebf6SMatthew Brost */ 28dd08ebf6SMatthew Brost struct xe_test_priv { 29dd08ebf6SMatthew Brost enum xe_test_priv_id id; 30dd08ebf6SMatthew Brost }; 31dd08ebf6SMatthew Brost 32dd08ebf6SMatthew Brost #define XE_TEST_DECLARE(x) x 33dd08ebf6SMatthew Brost #define XE_TEST_ONLY(x) unlikely(x) 34dd08ebf6SMatthew Brost 35dd08ebf6SMatthew Brost /** 36dd08ebf6SMatthew Brost * xe_cur_kunit_priv - Obtain the struct xe_test_priv pointed to by 37dd08ebf6SMatthew Brost * current->kunit->priv if it exists and is embedded in the expected subclass. 38dd08ebf6SMatthew Brost * @id: Id of the expected subclass. 39dd08ebf6SMatthew Brost * 40dd08ebf6SMatthew Brost * Return: NULL if the process is not a kunit test, and NULL if the 41dd08ebf6SMatthew Brost * current kunit->priv pointer is not pointing to an object of the expected 42dd08ebf6SMatthew Brost * subclass. A pointer to the embedded struct xe_test_priv otherwise. 43dd08ebf6SMatthew Brost */ 44dd08ebf6SMatthew Brost static inline struct xe_test_priv * 45dd08ebf6SMatthew Brost xe_cur_kunit_priv(enum xe_test_priv_id id) 46dd08ebf6SMatthew Brost { 47dd08ebf6SMatthew Brost struct xe_test_priv *priv; 48dd08ebf6SMatthew Brost 49*bd85e00fSMichal Wajdeczko if (!kunit_get_current_test()) 50dd08ebf6SMatthew Brost return NULL; 51dd08ebf6SMatthew Brost 52*bd85e00fSMichal Wajdeczko priv = kunit_get_current_test()->priv; 53dd08ebf6SMatthew Brost return priv->id == id ? priv : NULL; 54dd08ebf6SMatthew Brost } 55dd08ebf6SMatthew Brost 56dd08ebf6SMatthew Brost #else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */ 57dd08ebf6SMatthew Brost 58dd08ebf6SMatthew Brost #define XE_TEST_DECLARE(x) 59dd08ebf6SMatthew Brost #define XE_TEST_ONLY(x) 0 60dd08ebf6SMatthew Brost #define xe_cur_kunit_priv(_id) NULL 61dd08ebf6SMatthew Brost 62dd08ebf6SMatthew Brost #endif 63dd08ebf6SMatthew Brost #endif 64