From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context
Date: Tue, 20 Aug 2024 12:31:58 +0200 [thread overview]
Message-ID: <c267034e-f016-4ac6-adff-e1b634be4c95@intel.com> (raw)
In-Reply-To: <ejgtxc727guqh6dl4tfjdqsjlhlbs5nfzvkmsxbtnpaxnu2uvx@rroc2e4sjm7r>
On 19.08.2024 23:52, Lucas De Marchi wrote:
> On Fri, Aug 09, 2024 at 06:51:54PM GMT, Michal Wajdeczko wrote:
>> The KUNIT_STATIC_STUB_REDIRECT() allows to redirect function call but
>> will
>> work only if the caller is in a KUnit context. To allow implementation of
>> the more complex test cases, add helpers that allow calling stubs also
>> out
>> of a KUnit context.
>>
>> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>> Cc: Lucas De Marchi <lucas.demarchi@intel.com>
>> ---
>> drivers/gpu/drm/xe/tests/xe_test.h | 74 ++++++++++++++++++++++++++++++
>> 1 file changed, 74 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/xe/tests/xe_test.h
>> b/drivers/gpu/drm/xe/tests/xe_test.h
>> index b8fa409ce2b1..ffa8fa6c96f0 100644
>> --- a/drivers/gpu/drm/xe/tests/xe_test.h
>> +++ b/drivers/gpu/drm/xe/tests/xe_test.h
>> @@ -54,11 +54,85 @@ xe_cur_kunit_priv(enum xe_test_priv_id id)
>> return priv->id == id ? priv : NULL;
>> }
>>
>> +/**
>> + * XE_TEST_REDIRECT() - Call a function stub if one exists.
>> + * @stub: The pointer to the function stub
>> + * @args: All of the arguments passed to this stub
>> + *
>> + * This is a function prologue which is used to allow calls to the
>> current
>> + * function to be redirected if a KUnit is running. If the stub is
>> NULL or
>> + * the KUnit is not running the function will continue execution as
>> normal.
>> + *
>> + * Unlikely the KUNIT_STATIC_STUB_REDIRECT(), this redirection will work
>> + * even if the caller is not in a KUnit context (like a worker thread).
>> + *
>> + * Example:
>> + *
>> + * .. code-block:: c
>> + *
>> + * int (*stub)(int n);
>> + *
>> + * int real_func(int n)
>> + * {
>> + * XE_TEST_REDIRECT(stub, n);
>> + * return n + 1;
>> + * }
>> + *
>> + * int replacement_func(int n)
>> + * {
>> + * return n + 100;
>> + * }
>> + *
>> + * void example_test(struct kunit *test)
>> + * {
>> + * stub = replacement_func;
>> + * KUNIT_EXPECT_EQ(test, real_func(1), 101);
>> + * KUNIT_EXPECT_EQ(test, real_func(1), 101);
>> + * }
>> + */
>> +#define XE_TEST_REDIRECT(stub, args...) \
>
> this seems another one that should rather be in the kunit layer, not in
> xe
will try to prepare generic kunit patch, but I was just hoping that we
can have/use something sooner without waiting until it will accepted there
>
>> +do { \
>> + typeof(stub) replacement = (stub); \
>> + if (XE_TEST_RUNNING()) { \
>> + if (unlikely(replacement)) { \
>> + pr_info(KUNIT_SUBTEST_INDENT "# %s: calling stub
>> %ps\n", \
>> + __func__, replacement); \
>
> KUNIT_STATIC_STUB_REDIRECT() silently calls the stub without pr_info().
> Why does this version need to be extra-verbose?
KUNIT_STATIC_STUB_REDIRECT() only works in kunit context so likely your
test is almost directly exercise that redirection, while here
replacement function will used for any code that executes during the
test, so this will help identify any unexpected redirections
and this extra-verbose 'noise' will not be seen unless your test fails
(unless you will use --raw_output)
>
> Lucas De Marchi
>
>
>> + return replacement(args); \
>> + } \
>> + } \
>> +} while (0)
>> +
>> +static inline void __nullify_pointer(void *data)
>> +{
>> + void **ptr = data;
>> +
>> + *ptr = NULL;
>> +}
>> +
>> +/**
>> + * XE_TEST_ACTIVATE_STUB() - Setup a function stub.
>> + * @test: Test case that wants to setup a function stub
>> + * @stub: The function stub pointer
>> + * @replacement: The replacement function
>> + *
>> + * This helper setups a function stub with the replacement function.
>> + * It will also automatically restore stub to NULL at the test end.
>> + */
>> +#define XE_TEST_ACTIVATE_STUB(test, stub, replacement)
>> ({ \
>> + typeof(test) __test = (test); \
>> + typeof(stub) *__ptr = &(stub); \
>> + typecheck_pointer(*__ptr); \
>> + *__ptr = (replacement); \
>> + kunit_info(__test, "activated stub %s with %ps\n",
>> __stringify(stub), *__ptr); \
>> + kunit_add_action_or_reset(__test, __nullify_pointer,
>> __ptr); \
>> +})
>> +
>> #else /* if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) */
>>
>> #define XE_TEST_DECLARE(x)
>> #define XE_TEST_ONLY(x) 0
>> #define XE_TEST_RUNNING() false
>> +#define XE_TEST_REDIRECT(...) do { } while (0)
>>
>> #define xe_cur_kunit_priv(_id) NULL
>>
>> --
>> 2.43.0
>>
next prev parent reply other threads:[~2024-08-20 10:32 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-09 16:51 [PATCH 00/12] PF: Improve VF control Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 01/12] drm/xe/pf: Add function to sanitize VF resources Michal Wajdeczko
2024-08-16 12:58 ` Piotr Piórkowski
2024-08-19 20:47 ` Lucas De Marchi
2024-08-20 9:38 ` Michal Wajdeczko
2024-08-20 13:16 ` Lucas De Marchi
2024-09-05 18:07 ` Rodrigo Vivi
2024-08-09 16:51 ` [PATCH 02/12] drm/xe/pf: Fix documentation formatting Michal Wajdeczko
2024-08-16 12:59 ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 03/12] drm/xe/pf: Drop GuC notifications for non-existing VF Michal Wajdeczko
2024-08-16 13:01 ` Piotr Piórkowski
2024-08-19 17:51 ` Michal Wajdeczko
2024-08-22 10:48 ` Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 04/12] drm/xe/pf: Improve VF control Michal Wajdeczko
2024-08-16 13:06 ` Piotr Piórkowski
2024-08-19 17:52 ` Michal Wajdeczko
2024-08-20 7:56 ` Piotr Piórkowski
2024-08-20 10:04 ` Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 05/12] drm/xe/tests: Allow deferred function call during KUnit test Michal Wajdeczko
2024-08-19 21:38 ` Lucas De Marchi
2024-08-20 10:23 ` Michal Wajdeczko
2024-08-20 13:21 ` Lucas De Marchi
2024-08-20 13:27 ` Lucas De Marchi
2024-08-09 16:51 ` [PATCH 06/12] drm/xe/tests: Add helper macro to detect if KUnit is running Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 07/12] drm/xe/tests: Add helpers to call stubs out of KUnit context Michal Wajdeczko
2024-08-19 21:52 ` Lucas De Marchi
2024-08-20 10:31 ` Michal Wajdeczko [this message]
2024-08-09 16:51 ` [PATCH 08/12] drm/xe/guc: Define stub for xe_guc_ct_send_recv() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 09/12] drm/xe/pf: Define stub for pf_sanitize_vf_resources() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 10/12] drm/xe/pf: Define stub for pf_send_vf_control_cmd() Michal Wajdeczko
2024-08-09 16:51 ` [PATCH 11/12] drm/xe/tests: Add KUnit tests for VF control state machines Michal Wajdeczko
2024-08-09 17:23 ` [PATCH v2 " Michal Wajdeczko
2024-08-22 10:51 ` Piotr Piórkowski
2024-08-22 10:47 ` [PATCH " Piotr Piórkowski
2024-08-09 16:51 ` [PATCH 12/12] drm/xe/tests: Add KUnit tests for VF control GuC messages Michal Wajdeczko
2024-08-23 13:18 ` Piotr Piórkowski
2024-08-09 16:57 ` ✓ CI.Patch_applied: success for PF: Improve VF control Patchwork
2024-08-09 16:58 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 16:58 ` ✗ CI.KUnit: failure " Patchwork
2024-08-09 17:28 ` ✓ CI.Patch_applied: success for PF: Improve VF control (rev2) Patchwork
2024-08-09 17:29 ` ✗ CI.checkpatch: warning " Patchwork
2024-08-09 17:30 ` ✓ CI.KUnit: success " Patchwork
2024-08-09 17:42 ` ✓ CI.Build: " Patchwork
2024-08-09 17:44 ` ✗ CI.Hooks: failure " Patchwork
2024-08-09 17:46 ` ✓ CI.checksparse: success " Patchwork
2024-08-09 18:06 ` ✓ CI.BAT: " Patchwork
2024-08-09 20:35 ` ✗ CI.FULL: failure " 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=c267034e-f016-4ac6-adff-e1b634be4c95@intel.com \
--to=michal.wajdeczko@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=lucas.demarchi@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