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