1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
4
5. $(dirname $0)/functions.sh
6
7MOD_TEST=test_klp_shadow_vars
8
9set_dynamic_debug
10
11
12# TEST: basic shadow variable API
13# - load a module that exercises the shadow variable API
14
15echo -n "TEST: basic shadow variable API ... "
16dmesg -C
17
18load_mod $MOD_TEST
19unload_mod $MOD_TEST
20
21check_result "% modprobe $MOD_TEST
22$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1234) = PTR0
23$MOD_TEST:   got expected NULL result
24$MOD_TEST: shadow_ctor: PTR6 -> PTR1
25$MOD_TEST: klp_shadow_alloc(obj=PTR5, id=0x1234, size=8, gfp_flags=GFP_KERNEL), ctor=PTR7, ctor_data=PTR1 = PTR6
26$MOD_TEST: shadow_ctor: PTR8 -> PTR2
27$MOD_TEST: klp_shadow_alloc(obj=PTR9, id=0x1234, size=8, gfp_flags=GFP_KERNEL), ctor=PTR7, ctor_data=PTR2 = PTR8
28$MOD_TEST: shadow_ctor: PTR10 -> PTR3
29$MOD_TEST: klp_shadow_alloc(obj=PTR5, id=0x1235, size=8, gfp_flags=GFP_KERNEL), ctor=PTR7, ctor_data=PTR3 = PTR10
30$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1234) = PTR6
31$MOD_TEST:   got expected PTR6 -> PTR1 result
32$MOD_TEST: klp_shadow_get(obj=PTR9, id=0x1234) = PTR8
33$MOD_TEST:   got expected PTR8 -> PTR2 result
34$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1235) = PTR10
35$MOD_TEST:   got expected PTR10 -> PTR3 result
36$MOD_TEST: shadow_ctor: PTR11 -> PTR4
37$MOD_TEST: klp_shadow_get_or_alloc(obj=PTR12, id=0x1234, size=8, gfp_flags=GFP_KERNEL), ctor=PTR7, ctor_data=PTR4 = PTR11
38$MOD_TEST: klp_shadow_get_or_alloc(obj=PTR12, id=0x1234, size=8, gfp_flags=GFP_KERNEL), ctor=PTR7, ctor_data=PTR4 = PTR11
39$MOD_TEST:   got expected PTR11 -> PTR4 result
40$MOD_TEST: shadow_dtor(obj=PTR5, shadow_data=PTR6)
41$MOD_TEST: klp_shadow_free(obj=PTR5, id=0x1234, dtor=PTR13)
42$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1234) = PTR0
43$MOD_TEST:   got expected NULL result
44$MOD_TEST: shadow_dtor(obj=PTR9, shadow_data=PTR8)
45$MOD_TEST: klp_shadow_free(obj=PTR9, id=0x1234, dtor=PTR13)
46$MOD_TEST: klp_shadow_get(obj=PTR9, id=0x1234) = PTR0
47$MOD_TEST:   got expected NULL result
48$MOD_TEST: shadow_dtor(obj=PTR12, shadow_data=PTR11)
49$MOD_TEST: klp_shadow_free(obj=PTR12, id=0x1234, dtor=PTR13)
50$MOD_TEST: klp_shadow_get(obj=PTR12, id=0x1234) = PTR0
51$MOD_TEST:   got expected NULL result
52$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1235) = PTR10
53$MOD_TEST:   got expected PTR10 -> PTR3 result
54$MOD_TEST: shadow_dtor(obj=PTR5, shadow_data=PTR10)
55$MOD_TEST: klp_shadow_free_all(id=0x1235, dtor=PTR13)
56$MOD_TEST: klp_shadow_get(obj=PTR5, id=0x1234) = PTR0
57$MOD_TEST:   shadow_get() got expected NULL result
58% rmmod test_klp_shadow_vars"
59
60exit 0
61