Loading...
Note: File does not exist in v6.8.
1#!/bin/bash
2
3TARGET=$(basename $1)
4DIR=lib/tests/module
5TARGET="$DIR/$TARGET"
6NUM_SYMS=$2
7SCALE_FACTOR=$3
8TEST_TYPE=$(echo $TARGET | sed -e 's|lib/tests/module/test_kallsyms_||g')
9TEST_TYPE=$(echo $TEST_TYPE | sed -e 's|.c||g')
10FIRST_B_LOOKUP=1
11
12if [[ $NUM_SYMS -gt 2 ]]; then
13 FIRST_B_LOOKUP=$((NUM_SYMS/2))
14fi
15
16gen_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 <mcgrof@kernel.org>
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
35gen_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
46gen_template_module_data_a()
47{
48 gen_num_syms a $1
49 cat <<____END_MODULE
50static int auto_runtime_test(void)
51{
52 return 0;
53}
54
55____END_MODULE
56}
57
58gen_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
67gen_template_module_data_c()
68{
69 gen_num_syms c $1
70 cat <<____END_MODULE
71static int auto_runtime_test(void)
72{
73 return 0;
74}
75
76____END_MODULE
77}
78
79gen_template_module_data_d()
80{
81 gen_num_syms d $1
82 cat <<____END_MODULE
83static int auto_runtime_test(void)
84{
85 return 0;
86}
87
88____END_MODULE
89}
90
91gen_template_module_exit()
92{
93 cat <<____END_MODULE
94static int __init auto_test_module_init(void)
95{
96 return auto_runtime_test();
97}
98module_init(auto_test_module_init);
99
100static void __exit auto_test_module_exit(void)
101{
102}
103module_exit(auto_test_module_exit);
104
105MODULE_AUTHOR("Luis Chamberlain <mcgrof@kernel.org>");
106MODULE_LICENSE("GPL");
107MODULE_DESCRIPTION("Test module for kallsyms");
108____END_MODULE
109}
110
111case $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 ;;
134esac