xref: /linux/kernel/trace/rv/monitors/sssw/sssw_kunit.c (revision 55ee4b931a7ffedc886175d265dd6e6d08fd4151)
1*8da2a883SGabriele Monaco // SPDX-License-Identifier: GPL-2.0
2*8da2a883SGabriele Monaco #include <linux/kernel.h>
3*8da2a883SGabriele Monaco #include <linux/rv.h>
4*8da2a883SGabriele Monaco #include <rv/kunit.h>
5*8da2a883SGabriele Monaco #include <trace/events/sched.h>
6*8da2a883SGabriele Monaco #include "sssw_kunit.h"
7*8da2a883SGabriele Monaco 
8*8da2a883SGabriele Monaco #if IS_REACHABLE(CONFIG_RV_MON_SSSW)
9*8da2a883SGabriele Monaco 
10*8da2a883SGabriele Monaco static void rv_test_sssw(struct kunit *test)
11*8da2a883SGabriele Monaco {
12*8da2a883SGabriele Monaco 	struct task_struct *target = rv_kunit_alloc_mock_task(test);
13*8da2a883SGabriele Monaco 	struct task_struct *other = rv_kunit_alloc_mock_task(test);
14*8da2a883SGabriele Monaco 	struct rv_kunit_ctx *ctx = test->priv;
15*8da2a883SGabriele Monaco 
16*8da2a883SGabriele Monaco 	prepare_test(test, &rv_sssw_ops.mon);
17*8da2a883SGabriele Monaco 
18*8da2a883SGabriele Monaco 	/* Suspend without setting to sleepable */
19*8da2a883SGabriele Monaco 	rv_sssw_ops.handle_sched_set_state(NULL, target, TASK_RUNNING);
20*8da2a883SGabriele Monaco 	RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
21*8da2a883SGabriele Monaco 		rv_sssw_ops.handle_sched_switch(NULL, 0, target, other, TASK_INTERRUPTIBLE);
22*8da2a883SGabriele Monaco 
23*8da2a883SGabriele Monaco 	/* Switch in after suspension without wakeup */
24*8da2a883SGabriele Monaco 	rv_sssw_ops.handle_sched_wakeup(NULL, target);
25*8da2a883SGabriele Monaco 	rv_sssw_ops.handle_sched_set_state(NULL, target, TASK_INTERRUPTIBLE);
26*8da2a883SGabriele Monaco 	rv_sssw_ops.handle_sched_switch(NULL, 0, target, other, TASK_INTERRUPTIBLE);
27*8da2a883SGabriele Monaco 	RV_KUNIT_EXPECT_REACTION_HERE(test, ctx)
28*8da2a883SGabriele Monaco 		rv_sssw_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
29*8da2a883SGabriele Monaco }
30*8da2a883SGabriele Monaco 
31*8da2a883SGabriele Monaco #else
32*8da2a883SGabriele Monaco #define rv_test_sssw rv_test_stub
33*8da2a883SGabriele Monaco #endif
34