Skip to content

Commit 2593cd2

Browse files
author
Tzafrir Cohen
committed
kernel: draft of alternative configuration
Change-Id: I51f1660c9d7bbc97749b8b5182c942615a5251ea
1 parent dc11668 commit 2593cd2

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

kernel/config_kernel

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/sh
2+
3+
usage() {
4+
cat <<EOF
5+
$0: configure kernel
6+
Usage:
7+
$0 # Run configuration
8+
$0 CONFIG_NAME # re-test configuration for CONFIG_NAME
9+
10+
Kernel source is set by setting KSRC, KVERS or taken from uname -r
11+
EOF
12+
13+
}
14+
15+
set_ksrc() {
16+
KVERS="${KVERS:-`uname -r`}"
17+
KSRC=${KSRC:-/lib/modules/$KVERS/build}
18+
}
19+
20+
set_globals() {
21+
set_ksrc # FIXME: command-line arguments?
22+
TEST_MODULES_DIR="$PWD/test_mods"
23+
TEST_CASES_DIR="$PWD/test_cases"
24+
TEST_MOD_NAME="testmod"
25+
TEST_RUN_LOG="$TEST_MODULES_DIR/run.log"
26+
ERROR_FLAGS="-Werror-implicit-function-declaration -Wno-unused-variable -Wno-uninitialized -Werror=int-conversion -Werror=discarded-qualifiers"
27+
HEADER_FILE="xpmem_kernel.h"
28+
}
29+
30+
msg_checking() {
31+
echo -n "Checking $*: "
32+
}
33+
34+
msg_error() {
35+
echo "Error: $*"
36+
exit 1
37+
}
38+
39+
msg_result() {
40+
echo "$*"
41+
}
42+
43+
msg_notice() {
44+
echo "$*"
45+
}
46+
47+
gen_test_case() {
48+
local mod_name mod_dir
49+
50+
mod_name="$1"
51+
mod_dir="$TEST_MODULES_DIR/$mod_name"
52+
rm -rf "$mod_dir"
53+
mkdir -p "$mod_dir"
54+
cat <<EOF >"$mod_dir/$TEST_MOD_NAME.c"
55+
#include <linux/module.h>
56+
#include <linux/kernel.h>
57+
MODULE_LICENSE("GPL");
58+
`cat $TEST_CASES_DIR/$mod_name.init`
59+
static int __init test_func (void) {
60+
`cat $TEST_CASES_DIR/$mod_name.main`
61+
return 0;
62+
}
63+
module_init(test_func);
64+
EOF
65+
echo "obj-m += $TEST_MOD_NAME.o" >"$mod_dir/Makefile"
66+
echo "obj-\$(XPMEM_TEST)\$(XPMEM_TEST_$mod_name) += $mod_name/" >>$TEST_MODULES_DIR/Makefile
67+
}
68+
69+
build_test_modules() {
70+
msg_notice "Test-building kernel modules test-builds"
71+
make -s -C "$KSRC" -k -j${NJOBS:-1} EXTRA_CFLAGS="$ERROR_FLAGS" "M=$TEST_MODULES_DIR" XPMEM_TEST=m modules 2>"$TEST_RUN_LOG"
72+
echo ''
73+
}
74+
75+
check_test_results() {
76+
local mod_dir test_name rc desc
77+
78+
rm -f "$HEADER_FILE"
79+
for mod_dir in $TEST_MODULES_DIR/HAVE_*; do
80+
if test ! -d "$mod_dir"; then continue; fi
81+
test_name="${mod_dir##*/}"
82+
test ! -e "$mod_dir/$TEST_MOD_NAME.o"
83+
rc=$?
84+
desc_file="$TEST_CASES_DIR/$test_name.desc"
85+
if [ -f "$desc_file" ]; then
86+
echo "" >>"$HEADER_FILE"
87+
echo "// $test_name: `cat $desc_file`" >> "$HEADER_FILE"
88+
fi
89+
if [ "$rc" = 1 ]; then
90+
echo "#define $test_name 1" >>"$HEADER_FILE"
91+
else
92+
echo "//#undef $test_name" >>"$HEADER_FILE"
93+
fi
94+
msg_notice "$test_name=$rc"
95+
96+
97+
98+
#if test "$mlnx_rdma_mod_dir_rc" = 1; then
99+
# AC_DEFINE_UNQUOTED([$mlnx_rdma_mod_dir_name], [$mlnx_rdma_mod_dir_rc])
100+
#fi
101+
done
102+
}
103+
104+
check_build_sanity() {
105+
local rc
106+
msg_checking "that system can build kernel modules"
107+
gen_test_case KBUILD_WORKS "building a kernel module works"
108+
make -s -C "$KSRC" EXTRA_CFLAGS="$ERROR_FLAGS" "M=$TEST_MODULES_DIR" XPMEM_TEST_KBUILD_WORKS=m modules 2>"$TEST_RUN_LOG"
109+
rc=$?
110+
if test "$rc" != 0; then
111+
echo ''; cat "$TEST_RUN_LOG"
112+
msg_error "Failed to build a dummy kernel module. Check compiler, kernel headers, etc."
113+
fi
114+
msg_result "yes"
115+
}
116+
117+
get_tested_modules() {
118+
ls $TEST_CASES_DIR/HAVE_*.init | sed -r -e 's|.*/(HAVE_)|\1|' -e 's|\.init$||'
119+
}
120+
121+
create_test_modules() {
122+
local mod
123+
124+
rm -rf "${TEST_MODULES_DIR}"
125+
mkdir -p "${TEST_MODULES_DIR}"
126+
127+
check_build_sanity
128+
129+
for mod in `get_tested_modules`; do
130+
gen_test_case "$mod"
131+
done
132+
}
133+
134+
run_all() {
135+
set_globals
136+
create_test_modules
137+
build_test_modules
138+
check_test_results
139+
}
140+
141+
# re-run a single test, after it was built
142+
run_test() {
143+
set_globals
144+
make -C "$KSRC" "M=$TEST_MODULES_DIR" XPMEM_TEST_$1=m modules EXTRA_CFLAGS="$ERROR_FLAGS"
145+
}
146+
147+
case "$1" in
148+
HAVE_* | TEST_KBUILD) run_test "$1";;
149+
'') run_all;;
150+
*) usage; exit 1;;
151+
esac

kernel/test_cases/HAVE_good.init

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <linux/slab.h>

kernel/test_cases/HAVE_good.main

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int hello = 5;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A description of a test

kernel/test_cases/HAVE_syntaxerror.init

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aaa bbb

kernel/test_cases/KBUILD_WORKS.init

Whitespace-only changes.

kernel/test_cases/KBUILD_WORKS.main

Whitespace-only changes.

0 commit comments

Comments
 (0)