blob: d59b2e6a3c268dd18e220b164b73b70a27b87eab [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4green='\e[0;32m'
5red='\e[0;31m'
6eol='\e[0m'
7
8function print_usage(){
9 echo -e "${green}Script for auto test all config on/off/mod \
10to ensure kernel build${eol}"
11 echo ""
12 echo -e "${red}Command for local test kernel build:${eol}"
13 echo "[kernel_dir] [arch] [defconfig] mode=t\
14./scripts/bvt/mediatek_bvt.sh"
15 echo ""
16 echo -e "${green}Description:${eol}"
17 echo "[kernel_dir]: kernel directory position"
18 echo "[arch]: arm/arm64, position of defconfig"
19 echo "[defconfig]: mediatek_debug_defconfig for all config on test"
20 echo " mediatek_config_off_defconfig \
21for all config off test"
22 echo " mediatek_module_defconfig for all\
23config module test"
24 echo ""
25 echo -e "${green}Example:${eol} ${red}kernel_dir=\$(pwd) arch=arm64 \
26defconfig=mediatek_debug_defconfig mode=t \
27./scripts/bvt/mediatek_bvt.sh${eol}"
28 echo ""
29 echo -e "${red}Command for add and check config list:${eol}"
30 echo "[commit] [kernel_dir] mode=a ./scripts/bvt/mediatek_bvt.sh"
31 echo ""
32 echo -e "${green}Description:${eol}"
33 echo "[kernel_dir]: kernel directory position"
34 echo ""
35 echo -e "${green}Example:${eol} ${red}kernel_dir=\$(pwd) \
36 mode=a ./scripts/bvt/mediatek_bvt.sh${eol}"
37}
38
39if [[ "$1" == "h" ]] || [[ "$1" == "help" ]] || [ -z "mode" ]
40then
41 print_usage
42fi
43
44if [ "$mode" == "a" ]
45then
46 IFS="+"
47 if [ -z "$commit" ]
48 then
49 bypass=$(git log --name-only -1 | grep mediatek_bvt.sh)
50 log_cached=$(git show -p | grep "+CONFIG_" \
51 | grep "=y" | sed '/^$/d' | sed 's/y//g' \
52 | sed 's/\+//g' | tr '\n' '+')
53 log_noncached=$(git diff | grep "+CONFIG_" \
54 | grep "=y" | sed '/^$/d' | sed 's/y//g' \
55 | sed 's/\+//g' | tr '\n' '+')
56 if [ -z "$bypass" ]
57 then
58 for conf in ${log_cached[@]}; do
59 result=\
60$(grep $conf $kernel_dir/scripts/bvt/config_list )
61 if [ -z "$result" ]
62 then
63 echo ""$conf"y" >> \
64 $kernel_dir/scripts/bvt/config_list
65 fi
66 done
67 fi
68 for conf in ${log_noncached[@]}; do
69 result=\
70$(grep $conf $kernel_dir/scripts/bvt/config_list )
71 if [ -z "$result" ]
72 then
73 echo ""$conf"y" >> \
74 $kernel_dir/scripts/bvt/config_list
75 fi
76 done
77 sort $kernel_dir/scripts/bvt/config_list \
78 -o $kernel_dir/scripts/bvt/config_list
79 check_return=$(git status | grep config_list)
80 if [ "$check_return" == "" ]
81 then
82 exit 0
83 fi
84 exit -1
85 else
86 new_con=$(git log "$commit"..HEAD -p | grep "+CONFIG_" \
87 | grep "=y" | sed '/^$/d' | sed 's/y//g' \
88 | sed 's/\+//g' | tr '\n' '+')
89 for conf in ${new_con[@]}; do
90 result=\
91$(grep $conf $kernel_dir/scripts/bvt/config_list )
92 if [ -z "$result" ]
93 then
94 echo ""$conf"y" >> \
95 $kernel_dir/scripts/bvt/config_list
96 fi
97 done
98 sort $kernel_dir/scripts/bvt/config_list \
99 -o $kernel_dir/scripts/bvt/config_list
100 fi
101fi
102
103opt=""
104if [[ "$defconfig" == mediatek_config_on* ]]
105then
106 opt="-e"
107fi
108if [[ "$defconfig" == mediatek_config_off* ]]
109then
110 opt="-d"
111fi
112if [[ "$defconfig" == mediatek_module* ]]
113then
114 opt="-m"
115fi
116
117if [ -z "$arch" ]
118then
119 arch=arm64
120
121 def_arch=$(echo $defconfig | tail -c 13)
122 echo $def_arch
123 if [[ "$def_arch" == "32_defconfig" ]]
124 then
125 arch=arm
126 fi
127fi
128
129if [ "$mode" == "t" ]
130then
131 if [[ "$defconfig" != "mediatek_debug_defconfig" ]] && \
132 [[ "$arch" == "arm64" ]]
133 then
134 if [ ! -f "$kernel_dir/arch/$arch/configs/$defconfig" ]
135 then
136 cp $kernel_dir/arch/$arch/configs/mediatek_debug_defconfig \
137 $kernel_dir/arch/$arch/configs/$defconfig
138 fi
139 fi
140 if [[ "$defconfig" != "mediatek_debug_32_defconfig" ]] && \
141 [[ "$arch" == "arm" ]]
142 then
143 if [ ! -f "$kernel_dir/arch/$arch/configs/$defconfig" ]
144 then
145 cp $kernel_dir/arch/$arch/configs/mediatek_debug_32_defconfig \
146 $kernel_dir/arch/$arch/configs/$defconfig
147 fi
148 fi
149 exec < $kernel_dir/scripts/bvt/config_list
150
151 IFS="="
152 while read config test
153 do
154 echo $config $test $opt $arch
155 if [[ "$test" == "y" ]] && [[ -n "$opt" ]]
156 then
157 sh $kernel_dir/scripts/config --file \
158 $kernel_dir/arch/$arch/configs/$defconfig \
159 $opt $config
160 fi
161 done
162fi