xref: /linux/kernel/trace/rv/monitors/nomiss/nomiss_kunit.c (revision 67f8bc848ee31831336bd478e57d2f993551902e)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/rv.h>
4 #include <rv/kunit.h>
5 #include <trace/events/sched.h>
6 #include "nomiss_kunit.h"
7 
8 #if IS_REACHABLE(CONFIG_RV_MON_NOMISS)
9 
10 static void rv_test_nomiss(struct kunit *test)
11 {
12 	struct task_struct *target = rv_kunit_alloc_mock_task(test);
13 	struct task_struct *other = rv_kunit_alloc_mock_task(test);
14 	struct rv_kunit_ctx *ctx = test->priv;
15 
16 	prepare_test(test, &rv_nomiss_ops.mon);
17 
18 	target->pid = 99;
19 	target->policy = SCHED_DEADLINE;
20 	target->dl.runtime = 10000;
21 	target->dl.dl_deadline = 20000;
22 
23 	rv_nomiss_ops.handle_newtask(NULL, target, 0);
24 
25 	/* Task gets preempted and can't terminate before deadline */
26 	rv_nomiss_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
27 	rv_nomiss_ops.handle_dl_replenish(NULL, &target->dl, 0, DL_TASK);
28 	udelay(10);
29 	rv_nomiss_ops.handle_sched_switch(NULL, 0, target, other, TASK_RUNNING);
30 	RV_KUNIT_EXPECT_REACTION_HERE(test, ctx) {
31 		udelay(15 + div_u64(*rv_nomiss_ops.deadline_thresh, 1000));
32 		rv_nomiss_ops.handle_sched_switch(NULL, 0, other, target, TASK_RUNNING);
33 	}
34 }
35 
36 #else
37 #define rv_test_nomiss rv_test_stub
38 #endif
39