diff options
| author | Gabriele Monaco <gmonaco@redhat.com> | 2026-07-23 09:45:30 +0200 |
|---|---|---|
| committer | Gabriele Monaco <gmonaco@redhat.com> | 2026-07-31 16:27:45 +0200 |
| commit | cf8f191c06546dff223df12010d4a21f7b631ae3 (patch) | |
| tree | 2b4270e5e15d56d46fe5124d0ad8e057118c67ce /include/rv/kunit.h | |
| parent | 8da2a88383658dac97769ed8f807ef6100a69480 (diff) | |
rv: Add KUnit mock for current
Some monitors do not only rely on tracepoint arguments but also on the
currently executing task.
This makes it more challenging to mock events in KUnit.
Define wrapper functions around current, the functionality is mocked
only during KUnit, an additional function call is avoided using a static
branch unless any (even unrelated) KUnit test is running.
Rely on a global mock_current variable that is set only by the RV KUnit
tests and cleared on teardown. Unrelated KUnit tests that happen to
trigger RV handlers would see it null and use current.
Reviewed-by: Nam Cao <namcao@linutronix.de>
Reviewed-by: Wen Yang <wen.yang@linux.dev>
Link: https://lore.kernel.org/r/20260723074534.43521-14-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Diffstat (limited to 'include/rv/kunit.h')
| -rw-r--r-- | include/rv/kunit.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/include/rv/kunit.h b/include/rv/kunit.h index ff98b5137285..31e0b93c40ea 100644 --- a/include/rv/kunit.h +++ b/include/rv/kunit.h @@ -2,7 +2,10 @@ /* * Copyright (C) 2026-2029 Red Hat, Inc. Gabriele Monaco <gmonaco@redhat.com> * - * Declaration of utilities to run KUnit tests. + * Declaration of wrappers to allow mocking core functionality, like current, + * and other testing utilities. + * Necessary only when mocking may be needed. If the RV KUnit test is + * enabled, the wrappers incur an additional function call overhead. */ #ifndef _RV_KUNIT_H @@ -57,5 +60,14 @@ void prepare_test(struct kunit *test, const struct rv_kunit_mon *mon); void teardown_test(void *arg); struct task_struct *rv_kunit_alloc_mock_task(struct kunit *test); +void rv_mock_current(struct task_struct *tsk); +struct task_struct *rv_get_mock_current(void); + +#define rv_get_current() (unlikely(kunit_get_current_test()) ? rv_get_mock_current() : current) + +#else /* !CONFIG_RV_MONITORS_KUNIT_TEST */ + +#define rv_get_current() current + #endif /* CONFIG_RV_MONITORS_KUNIT_TEST */ #endif /* _RV_KUNIT_H */ |
