forked from Open-CAS/open-cas-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf_framework
95 lines (75 loc) · 1.76 KB
/
conf_framework
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
#!/bin/bash
#
# Copyright(c) 2012-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
SCRIPTPATH=`dirname $0`
SCRIPTPATH=`realpath $SCRIPTPATH`
KERNEL_DIR="${KERNEL_DIR:-/lib/modules/$(uname -r)/build/}"
KERNEL_VER="$(cd $KERNEL_DIR; make M=$SCRIPTPATH kernelversion)"
NPROC=`nproc`
DEFINE_FILE=$SCRIPTPATH/modules/generated_defines.h
add_define() {
printf "#define %s\n" $1 >> $DEFINE_FILE
}
add_function() {
printf "%s\n" $1 >> $DEFINE_FILE
}
compile_module(){
if [ $# -gt 2 ]
then
i=3
while [ "$i" -le "$#" ]; do
INCLUDE+=$(echo -e "\n#include <${!i}>\\n")
i=$((i + 1))
done
else
INCLUDE=""
fi
config_file=$1
test_module_dir=$SCRIPTPATH/configure.d/${config_file}_dir
test_module_log=$SCRIPTPATH/configure.d/.${config_file}.log
test_module_file=$test_module_dir/test_mod.c
test_module_obj=$test_module_dir/test_mod.o
mkdir -p $test_module_dir
cp -f $SCRIPTPATH/configure.d/Makefile $test_module_dir
############# TEST MODULE #############
cat > $test_module_file <<- EOF
#include <linux/module.h>
#include <linux/kernel.h>
$INCLUDE
int init_module(void) {
$2;
return 0;
}
void cleanup_module(void) {};
MODULE_LICENSE("GPL");
EOF
#######################################
echo "### $2 ###" >> $test_module_log
make -C $test_module_dir KERNEL_DIR=${KERNEL_DIR} &>> $test_module_log
local ret=$?
rm -Rf $test_module_dir
if [ $ret -eq 0 ]
then
rm -f $test_module_log
fi
return $ret
}
kernel_not_supp_fail() {
echo "Current kernel is not supported!"
rm $DEFINE_FILE
exit 1
}
# $1 - name of function to be called
# $2 - path to file with valid configs
# $3 - name of processed template file
conf_run() {
local OLD_IFS=$IFS
IFS='?'
case "$1" in
"check") check $2 $3;;
"apply") apply $2 ;;
esac
IFS=$OLD_IFS
}