mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-03-22 07:27:12 +08:00
This disallows KUNIT=m and RISCV_KPROBES_KUNIT=y, which produces these
relocs_check.sh warnings when RELOCATABLE=y:
WARNING: 3 bad relocations
ffffffff81e24118 R_RISCV_64 kunit_unary_assert_format
ffffffff81e24a60 R_RISCV_64 kunit_binary_assert_format
ffffffff81e269d0 R_RISCV_JUMP_SLOT __kunit_do_failed_assertion
This fixes allmodconfig build.
Reported-by: Inochi Amaoto <inochiama@gmail.com>
Fixes: f2fab61282 ("riscv: Add kprobes KUnit test")
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Tested-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Nam Cao <namcao@linutronix.de>
Link: https://lore.kernel.org/r/20251020-riscv-kunit-kconfig-fix-6-18-v1-2-d773b5d5ce48@iscas.ac.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/kprobes.h>
|
|
#include <kunit/test.h>
|
|
#include "test-kprobes.h"
|
|
|
|
static int kprobe_dummy_handler(struct kprobe *kp, struct pt_regs *regs)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static void test_kprobe_riscv(struct kunit *test)
|
|
{
|
|
unsigned int num_kprobe = 0;
|
|
long (*func)(void);
|
|
struct kprobe *kp;
|
|
int i;
|
|
|
|
while (test_kprobes_addresses[num_kprobe])
|
|
num_kprobe++;
|
|
|
|
kp = kcalloc(num_kprobe, sizeof(*kp), GFP_KERNEL);
|
|
KUNIT_EXPECT_TRUE(test, kp);
|
|
if (!kp)
|
|
return;
|
|
|
|
for (i = 0; i < num_kprobe; ++i) {
|
|
kp[i].addr = test_kprobes_addresses[i];
|
|
kp[i].pre_handler = kprobe_dummy_handler;
|
|
KUNIT_EXPECT_EQ(test, 0, register_kprobe(&kp[i]));
|
|
}
|
|
|
|
for (i = 0;; ++i) {
|
|
func = test_kprobes_functions[i];
|
|
if (!func)
|
|
break;
|
|
KUNIT_EXPECT_EQ_MSG(test, KPROBE_TEST_MAGIC, func(), "function %d broken", i);
|
|
}
|
|
|
|
for (i = 0; i < num_kprobe; ++i)
|
|
unregister_kprobe(&kp[i]);
|
|
kfree(kp);
|
|
}
|
|
|
|
static struct kunit_case kprobes_testcases[] = {
|
|
KUNIT_CASE(test_kprobe_riscv),
|
|
{}
|
|
};
|
|
|
|
static struct kunit_suite kprobes_test_suite = {
|
|
.name = "kprobes_riscv",
|
|
.test_cases = kprobes_testcases,
|
|
};
|
|
|
|
kunit_test_suites(&kprobes_test_suite);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("KUnit test for riscv kprobes");
|