projects/linux·blob master · refs

73 lines · 1.4 KiB

1// SPDX-License-Identifier: GPL-2.0-only
2#include <kunit/test.h>
3#include <linux/pgtable.h>
4
5MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
6
7static void expect_not_active(struct kunit *test)
8{
9 KUNIT_EXPECT_FALSE(test, is_lazy_mmu_mode_active());
10}
11
12static void expect_active(struct kunit *test)
13{
14 KUNIT_EXPECT_TRUE(test, is_lazy_mmu_mode_active());
15}
16
17static void lazy_mmu_mode_active(struct kunit *test)
18{
19 expect_not_active(test);
20
21 lazy_mmu_mode_enable();
22 expect_active(test);
23
24 {
25 /* Nested section */
26 lazy_mmu_mode_enable();
27 expect_active(test);
28
29 lazy_mmu_mode_disable();
30 expect_active(test);
31 }
32
33 {
34 /* Paused section */
35 lazy_mmu_mode_pause();
36 expect_not_active(test);
37
38 {
39 /* No effect (paused) */
40 lazy_mmu_mode_enable();
41 expect_not_active(test);
42
43 lazy_mmu_mode_disable();
44 expect_not_active(test);
45
46 lazy_mmu_mode_pause();
47 expect_not_active(test);
48
49 lazy_mmu_mode_resume();
50 expect_not_active(test);
51 }
52
53 lazy_mmu_mode_resume();
54 expect_active(test);
55 }
56
57 lazy_mmu_mode_disable();
58 expect_not_active(test);
59}
60
61static struct kunit_case lazy_mmu_mode_test_cases[] = {
62 KUNIT_CASE(lazy_mmu_mode_active),
63 {}
64};
65
66static struct kunit_suite lazy_mmu_mode_test_suite = {
67 .name = "lazy_mmu_mode",
68 .test_cases = lazy_mmu_mode_test_cases,
69};
70kunit_test_suite(lazy_mmu_mode_test_suite);
71
72MODULE_DESCRIPTION("Tests for the lazy MMU mode");
73MODULE_LICENSE("GPL");