blob: 31fe4ed63de83e768dff23878f6269ad55a38334 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/usr/bin/env bash
TARGET=$(basename $1)
DIR=lib/tests/module
TARGET="$DIR/$TARGET"
NUM_SYMS=$2
SCALE_FACTOR=$3
TEST_TYPE=$(echo $TARGET | sed -e 's|lib/tests/module/test_kallsyms_||g')
TEST_TYPE=$(echo $TEST_TYPE | sed -e 's|.c||g')
FIRST_B_LOOKUP=1
if [[ $NUM_SYMS -gt 2 ]]; then
FIRST_B_LOOKUP=$((NUM_SYMS/2))
fi
gen_template_module_header()
{
cat <<____END_MODULE
// SPDX-License-Identifier: GPL-2.0-or-later OR copyleft-next-0.3.1
/*
* Copyright (C) 2023 Luis Chamberlain <mcgrof@kernel.org>
*
* Automatically generated code for testing, do not edit manually.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
____END_MODULE
}
gen_num_syms()
{
PREFIX=$1
NUM=$2
for i in $(seq 1 $NUM); do
printf "int auto_test_%s_%010d = 0;\n" $PREFIX $i
printf "EXPORT_SYMBOL_GPL(auto_test_%s_%010d);\n" $PREFIX $i
done
echo
}
gen_template_module_data_a()
{
gen_num_syms a $1
cat <<____END_MODULE
static int auto_runtime_test(void)
{
return 0;
}
____END_MODULE
}
gen_template_module_data_b()
{
printf "\nextern int auto_test_a_%010d;\n\n" $FIRST_B_LOOKUP
echo "static int auto_runtime_test(void)"
echo "{"
printf "\nreturn auto_test_a_%010d;\n" $FIRST_B_LOOKUP
echo "}"
}
gen_template_module_data_c()
{
gen_num_syms c $1
cat <<____END_MODULE
static int auto_runtime_test(void)
{
return 0;
}
____END_MODULE
}
gen_template_module_data_d()
{
gen_num_syms d $1
cat <<____END_MODULE
static int auto_runtime_test(void)
{
return 0;
}
____END_MODULE
}
gen_template_module_exit()
{
cat <<____END_MODULE
static int __init auto_test_module_init(void)
{
return auto_runtime_test();
}
module_init(auto_test_module_init);
static void __exit auto_test_module_exit(void)
{
}
module_exit(auto_test_module_exit);
MODULE_AUTHOR("Luis Chamberlain <mcgrof@kernel.org>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Test module for kallsyms");
____END_MODULE
}
case $TEST_TYPE in
a)
gen_template_module_header > $TARGET
gen_template_module_data_a $NUM_SYMS >> $TARGET
gen_template_module_exit >> $TARGET
;;
b)
gen_template_module_header > $TARGET
gen_template_module_data_b >> $TARGET
gen_template_module_exit >> $TARGET
;;
c)
gen_template_module_header > $TARGET
gen_template_module_data_c $((NUM_SYMS * SCALE_FACTOR)) >> $TARGET
gen_template_module_exit >> $TARGET
;;
d)
gen_template_module_header > $TARGET
gen_template_module_data_d $((NUM_SYMS * SCALE_FACTOR * 2)) >> $TARGET
gen_template_module_exit >> $TARGET
;;
*)
;;
esac
|