linux/kernel/trace/rv/monitors/pagefault/pagefault_kunit.c
Gabriele Monaco 51f3fe704a rv: Add KUnit tests for some LTL monitors
Validate the functionality of LTL monitors by injecting events in a
controlled environment (KUnit) and expecting reactions, just like it is
done in DA monitors.

Reviewed-by: Nam Cao <namcao@linutronix.de>
Link: https://lore.kernel.org/r/20260723074534.43521-15-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
2026-07-31 16:27:46 +02:00

35 lines
965 B
C

// SPDX-License-Identifier: GPL-2.0
#include <linux/kernel.h>
#include <linux/rv.h>
#include <rv/kunit.h>
#include <linux/sched/deadline.h>
#include <linux/sched/rt.h>
#include "pagefault_kunit.h"
#if IS_REACHABLE(CONFIG_RV_MON_PAGEFAULT)
static void rv_test_pagefault(struct kunit *test)
{
struct task_struct *target = rv_kunit_alloc_mock_task(test);
struct rv_kunit_ctx *ctx = test->priv;
prepare_test(test, &rv_pagefault_ops.mon);
/* Initial pagefault when non-RT to start the model without failure */
target->policy = SCHED_NORMAL;
target->prio = MAX_RT_PRIO + 20;
rv_pagefault_ops.handle_task_newtask(NULL, target, 0);
rv_mock_current(target);
rv_pagefault_ops.handle_page_fault(NULL, 0, NULL, 0);
/* RT task has a page fault */
target->policy = SCHED_FIFO;
target->prio = MAX_RT_PRIO - 1;
RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
rv_pagefault_ops.handle_page_fault(NULL, 0, NULL, 0);
}
#else
#define rv_test_pagefault rv_test_stub
#endif