Files
cubelinux-kernel/arch/s390/lib/test_kprobes.c
T
Greg Kroah-Hartman 598cf27219 Linux 6.19.3
Link: https://lore.kernel.org/r/20260217200002.683975158@linuxfoundation.org
Tested-by: Florian Fainelli <florian.fainelli@broadcom.com>
Tested-by: Takeshi Ogasawara <takeshi.ogasawara@futuring-girl.com>
Tested-by: Peter Schneider <pschneider1968@googlemail.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Tested-by: Brett A C Sheffield <bacs@librecast.net>
Tested-by: Mark Brown <broonie@kernel.org>
Tested-by: Luna Jernberg <droidbittin@gmail.com>
Tested-by: Ronald Warsow <rwarsow@gmx.de>
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
Tested-by: Ron Economos <re@w6rz.net>
Tested-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-02-19 16:33:27 +01:00

77 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0+
#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <linux/random.h>
#include <kunit/test.h>
#include "test_kprobes.h"
static struct kprobe kp;
static void setup_kprobe(struct kunit *test, struct kprobe *kp,
const char *symbol, int offset)
{
kp->offset = offset;
kp->addr = NULL;
kp->symbol_name = symbol;
}
static void test_kprobe_offset(struct kunit *test, struct kprobe *kp,
const char *target, int offset)
{
int ret;
setup_kprobe(test, kp, target, 0);
ret = register_kprobe(kp);
if (!ret)
unregister_kprobe(kp);
KUNIT_EXPECT_EQ(test, 0, ret);
setup_kprobe(test, kp, target, offset);
ret = register_kprobe(kp);
KUNIT_EXPECT_EQ(test, -EINVAL, ret);
if (!ret)
unregister_kprobe(kp);
}
static void test_kprobe_odd(struct kunit *test)
{
test_kprobe_offset(test, &kp, "kprobes_target_odd",
kprobes_target_odd_offs);
}
static void test_kprobe_in_insn4(struct kunit *test)
{
test_kprobe_offset(test, &kp, "kprobes_target_in_insn4",
kprobes_target_in_insn4_offs);
}
static void test_kprobe_in_insn6_lo(struct kunit *test)
{
test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_lo",
kprobes_target_in_insn6_lo_offs);
}
static void test_kprobe_in_insn6_hi(struct kunit *test)
{
test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_hi",
kprobes_target_in_insn6_hi_offs);
}
static struct kunit_case kprobes_testcases[] = {
KUNIT_CASE(test_kprobe_odd),
KUNIT_CASE(test_kprobe_in_insn4),
KUNIT_CASE(test_kprobe_in_insn6_lo),
KUNIT_CASE(test_kprobe_in_insn6_hi),
{}
};
static struct kunit_suite kprobes_test_suite = {
.name = "kprobes_test_s390",
.test_cases = kprobes_testcases,
};
kunit_test_suites(&kprobes_test_suite);
MODULE_DESCRIPTION("KUnit tests for kprobes");
MODULE_LICENSE("GPL");