linux/kernel/trace/kprobe_event_gen_test.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Test module for in-kernel kprobe event creation and generation.
 *
 * Copyright (C) 2019 Tom Zanussi <[email protected]>
 */

#include <linux/module.h>
#include <linux/trace_events.h>

/*
 * This module is a simple test of basic functionality for in-kernel
 * kprobe/kretprobe event creation.  The first test uses
 * kprobe_event_gen_cmd_start(), kprobe_event_add_fields() and
 * kprobe_event_gen_cmd_end() to create a kprobe event, which is then
 * enabled in order to generate trace output.  The second creates a
 * kretprobe event using kretprobe_event_gen_cmd_start() and
 * kretprobe_event_gen_cmd_end(), and is also then enabled.
 *
 * To test, select CONFIG_KPROBE_EVENT_GEN_TEST and build the module.
 * Then:
 *
 * # insmod kernel/trace/kprobe_event_gen_test.ko
 * # cat /sys/kernel/tracing/trace
 *
 * You should see many instances of the "gen_kprobe_test" and
 * "gen_kretprobe_test" events in the trace buffer.
 *
 * To remove the events, remove the module:
 *
 * # rmmod kprobe_event_gen_test
 *
 */

static struct trace_event_file *gen_kprobe_test;
static struct trace_event_file *gen_kretprobe_test;

#define KPROBE_GEN_TEST_FUNC

/* X86 */
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_32)
#define KPROBE_GEN_TEST_ARG0
#define KPROBE_GEN_TEST_ARG1
#define KPROBE_GEN_TEST_ARG2
#define KPROBE_GEN_TEST_ARG3

/* ARM64 */
#elif defined(CONFIG_ARM64)
#define KPROBE_GEN_TEST_ARG0
#define KPROBE_GEN_TEST_ARG1
#define KPROBE_GEN_TEST_ARG2
#define KPROBE_GEN_TEST_ARG3

/* ARM */
#elif defined(CONFIG_ARM)
#define KPROBE_GEN_TEST_ARG0
#define KPROBE_GEN_TEST_ARG1
#define KPROBE_GEN_TEST_ARG2
#define KPROBE_GEN_TEST_ARG3

/* RISCV */
#elif defined(CONFIG_RISCV)
#define KPROBE_GEN_TEST_ARG0
#define KPROBE_GEN_TEST_ARG1
#define KPROBE_GEN_TEST_ARG2
#define KPROBE_GEN_TEST_ARG3

/* others */
#else
#define KPROBE_GEN_TEST_ARG0
#define KPROBE_GEN_TEST_ARG1
#define KPROBE_GEN_TEST_ARG2
#define KPROBE_GEN_TEST_ARG3
#endif

static bool trace_event_file_is_valid(struct trace_event_file *input)
{}

/*
 * Test to make sure we can create a kprobe event, then add more
 * fields.
 */
static int __init test_gen_kprobe_cmd(void)
{}

/*
 * Test to make sure we can create a kretprobe event.
 */
static int __init test_gen_kretprobe_cmd(void)
{}

static int __init kprobe_event_gen_test_init(void)
{}

static void __exit kprobe_event_gen_test_exit(void)
{}

module_init(kprobe_event_gen_test_init)
module_exit(kprobe_event_gen_test_exit)

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();