~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/hid/vmtest.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/testing/selftests/hid/vmtest.sh (Version linux-6.12-rc7) and /tools/testing/selftests/hid/vmtest.sh (Version linux-6.6.60)


  1 #!/bin/bash                                         1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3                                                     3 
  4 set -u                                              4 set -u
  5 set -e                                              5 set -e
  6                                                     6 
  7 # This script currently only works for x86_64       7 # This script currently only works for x86_64
  8 ARCH="$(uname -m)"                                  8 ARCH="$(uname -m)"
  9 case "${ARCH}" in                                   9 case "${ARCH}" in
 10 x86_64)                                            10 x86_64)
 11         QEMU_BINARY=qemu-system-x86_64             11         QEMU_BINARY=qemu-system-x86_64
 12         BZIMAGE="arch/x86/boot/bzImage"            12         BZIMAGE="arch/x86/boot/bzImage"
 13         ;;                                         13         ;;
 14 *)                                                 14 *)
 15         echo "Unsupported architecture"            15         echo "Unsupported architecture"
 16         exit 1                                     16         exit 1
 17         ;;                                         17         ;;
 18 esac                                               18 esac
 19 SCRIPT_DIR="$(dirname $(realpath $0))"             19 SCRIPT_DIR="$(dirname $(realpath $0))"
 20 OUTPUT_DIR="$SCRIPT_DIR/results"                   20 OUTPUT_DIR="$SCRIPT_DIR/results"
 21 KCONFIG_REL_PATHS=("${SCRIPT_DIR}/config" "${S     21 KCONFIG_REL_PATHS=("${SCRIPT_DIR}/config" "${SCRIPT_DIR}/config.common" "${SCRIPT_DIR}/config.${ARCH}")
 22 B2C_URL="https://gitlab.freedesktop.org/gfx-ci !!  22 B2C_URL="https://gitlab.freedesktop.org/mupuf/boot2container/-/raw/master/vm2c.py"
 23 NUM_COMPILE_JOBS="$(nproc)"                        23 NUM_COMPILE_JOBS="$(nproc)"
 24 LOG_FILE_BASE="$(date +"hid_selftests.%Y-%m-%d     24 LOG_FILE_BASE="$(date +"hid_selftests.%Y-%m-%d_%H-%M-%S")"
 25 LOG_FILE="${LOG_FILE_BASE}.log"                    25 LOG_FILE="${LOG_FILE_BASE}.log"
 26 EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status     26 EXIT_STATUS_FILE="${LOG_FILE_BASE}.exit_status"
 27 CONTAINER_IMAGE="registry.freedesktop.org/bent !!  27 CONTAINER_IMAGE="registry.freedesktop.org/libevdev/hid-tools/fedora/37:2023-02-17.1"
 28                                                    28 
 29 TARGETS="${TARGETS:=$(basename ${SCRIPT_DIR})}     29 TARGETS="${TARGETS:=$(basename ${SCRIPT_DIR})}"
 30 DEFAULT_COMMAND="pip3 install hid-tools; make      30 DEFAULT_COMMAND="pip3 install hid-tools; make -C tools/testing/selftests TARGETS=${TARGETS} run_tests"
 31                                                    31 
 32 usage()                                            32 usage()
 33 {                                                  33 {
 34         cat <<EOF                                  34         cat <<EOF
 35 Usage: $0 [-j N] [-s] [-b] [-d <output_dir>] - !!  35 Usage: $0 [-i] [-s] [-d <output_dir>] -- [<command>]
 36                                                    36 
 37 <command> is the command you would normally ru     37 <command> is the command you would normally run when you are in
 38 the source kernel direcory. e.g:                   38 the source kernel direcory. e.g:
 39                                                    39 
 40         $0 -- ./tools/testing/selftests/hid/hi     40         $0 -- ./tools/testing/selftests/hid/hid_bpf
 41                                                    41 
 42 If no command is specified and a debug shell (     42 If no command is specified and a debug shell (-s) is not requested,
 43 "${DEFAULT_COMMAND}" will be run by default.       43 "${DEFAULT_COMMAND}" will be run by default.
 44                                                    44 
 45 If you build your kernel using KBUILD_OUTPUT=      45 If you build your kernel using KBUILD_OUTPUT= or O= options, these
 46 can be passed as environment variables to the      46 can be passed as environment variables to the script:
 47                                                    47 
 48   O=<kernel_build_path> $0 -- ./tools/testing/     48   O=<kernel_build_path> $0 -- ./tools/testing/selftests/hid/hid_bpf
 49                                                    49 
 50 or                                                 50 or
 51                                                    51 
 52   KBUILD_OUTPUT=<kernel_build_path> $0 -- ./to     52   KBUILD_OUTPUT=<kernel_build_path> $0 -- ./tools/testing/selftests/hid/hid_bpf
 53                                                    53 
 54 Options:                                           54 Options:
 55                                                    55 
 56         -u)             Update the boot2contai     56         -u)             Update the boot2container script to a newer version.
 57         -d)             Update the output dire     57         -d)             Update the output directory (default: ${OUTPUT_DIR})
 58         -b)             Run only the build ste << 
 59         -j)             Number of jobs for com     58         -j)             Number of jobs for compilation, similar to -j in make
 60                         (default: ${NUM_COMPIL     59                         (default: ${NUM_COMPILE_JOBS})
 61         -s)             Instead of powering of     60         -s)             Instead of powering off the VM, start an interactive
 62                         shell. If <command> is     61                         shell. If <command> is specified, the shell runs after
 63                         the command finishes e     62                         the command finishes executing
 64 EOF                                                63 EOF
 65 }                                                  64 }
 66                                                    65 
 67 download()                                         66 download()
 68 {                                                  67 {
 69         local file="$1"                            68         local file="$1"
 70                                                    69 
 71         echo "Downloading $file..." >&2            70         echo "Downloading $file..." >&2
 72         curl -Lsf "$file" -o "${@:2}"              71         curl -Lsf "$file" -o "${@:2}"
 73 }                                                  72 }
 74                                                    73 
 75 recompile_kernel()                                 74 recompile_kernel()
 76 {                                                  75 {
 77         local kernel_checkout="$1"                 76         local kernel_checkout="$1"
 78         local make_command="$2"                    77         local make_command="$2"
 79                                                    78 
 80         cd "${kernel_checkout}"                    79         cd "${kernel_checkout}"
 81                                                    80 
 82         ${make_command} olddefconfig               81         ${make_command} olddefconfig
 83         ${make_command} headers                    82         ${make_command} headers
 84         ${make_command}                            83         ${make_command}
 85 }                                                  84 }
 86                                                    85 
 87 update_selftests()                                 86 update_selftests()
 88 {                                                  87 {
 89         local kernel_checkout="$1"                 88         local kernel_checkout="$1"
 90         local selftests_dir="${kernel_checkout     89         local selftests_dir="${kernel_checkout}/tools/testing/selftests/hid"
 91                                                    90 
 92         cd "${selftests_dir}"                      91         cd "${selftests_dir}"
 93         ${make_command}                            92         ${make_command}
 94 }                                                  93 }
 95                                                    94 
 96 run_vm()                                           95 run_vm()
 97 {                                                  96 {
 98         local run_dir="$1"                         97         local run_dir="$1"
 99         local b2c="$2"                             98         local b2c="$2"
100         local kernel_bzimage="$3"                  99         local kernel_bzimage="$3"
101         local command="$4"                        100         local command="$4"
102         local post_command=""                     101         local post_command=""
103                                                   102 
104         cd "${run_dir}"                           103         cd "${run_dir}"
105                                                   104 
106         if ! which "${QEMU_BINARY}" &> /dev/nu    105         if ! which "${QEMU_BINARY}" &> /dev/null; then
107                 cat <<EOF                         106                 cat <<EOF
108 Could not find ${QEMU_BINARY}                     107 Could not find ${QEMU_BINARY}
109 Please install qemu or set the QEMU_BINARY env    108 Please install qemu or set the QEMU_BINARY environment variable.
110 EOF                                               109 EOF
111                 exit 1                            110                 exit 1
112         fi                                        111         fi
113                                                   112 
114         # alpine (used in post-container requi    113         # alpine (used in post-container requires the PATH to have /bin
115         export PATH=$PATH:/bin                    114         export PATH=$PATH:/bin
116                                                   115 
117         if [[ "${debug_shell}" != "yes" ]]        116         if [[ "${debug_shell}" != "yes" ]]
118         then                                      117         then
119                 touch ${OUTPUT_DIR}/${LOG_FILE    118                 touch ${OUTPUT_DIR}/${LOG_FILE}
120                 command="mount bpffs -t bpf /s    119                 command="mount bpffs -t bpf /sys/fs/bpf/; set -o pipefail ; ${command} 2>&1 | tee ${OUTPUT_DIR}/${LOG_FILE}"
121                 post_command="cat ${OUTPUT_DIR    120                 post_command="cat ${OUTPUT_DIR}/${LOG_FILE}"
122         else                                      121         else
123                 command="mount bpffs -t bpf /s    122                 command="mount bpffs -t bpf /sys/fs/bpf/; ${command}"
124         fi                                        123         fi
125                                                   124 
126         set +e                                    125         set +e
127         $b2c --command "${command}" \             126         $b2c --command "${command}" \
128              --kernel ${kernel_bzimage} \         127              --kernel ${kernel_bzimage} \
129              --workdir ${OUTPUT_DIR} \            128              --workdir ${OUTPUT_DIR} \
130              --image ${CONTAINER_IMAGE}           129              --image ${CONTAINER_IMAGE}
131                                                   130 
132         echo $? > ${OUTPUT_DIR}/${EXIT_STATUS_    131         echo $? > ${OUTPUT_DIR}/${EXIT_STATUS_FILE}
133                                                   132 
134         set -e                                    133         set -e
135                                                   134 
136         ${post_command}                           135         ${post_command}
137 }                                                 136 }
138                                                   137 
139 is_rel_path()                                     138 is_rel_path()
140 {                                                 139 {
141         local path="$1"                           140         local path="$1"
142                                                   141 
143         [[ ${path:0:1} != "/" ]]                  142         [[ ${path:0:1} != "/" ]]
144 }                                                 143 }
145                                                   144 
146 do_update_kconfig()                               145 do_update_kconfig()
147 {                                                 146 {
148         local kernel_checkout="$1"                147         local kernel_checkout="$1"
149         local kconfig_file="$2"                   148         local kconfig_file="$2"
150                                                   149 
151         rm -f "$kconfig_file" 2> /dev/null        150         rm -f "$kconfig_file" 2> /dev/null
152                                                   151 
153         for config in "${KCONFIG_REL_PATHS[@]}    152         for config in "${KCONFIG_REL_PATHS[@]}"; do
154                 local kconfig_src="${config}"     153                 local kconfig_src="${config}"
155                 cat "$kconfig_src" >> "$kconfi    154                 cat "$kconfig_src" >> "$kconfig_file"
156         done                                      155         done
157 }                                                 156 }
158                                                   157 
159 update_kconfig()                                  158 update_kconfig()
160 {                                                 159 {
161         local kernel_checkout="$1"                160         local kernel_checkout="$1"
162         local kconfig_file="$2"                   161         local kconfig_file="$2"
163                                                   162 
164         if [[ -f "${kconfig_file}" ]]; then       163         if [[ -f "${kconfig_file}" ]]; then
165                 local local_modified="$(stat -    164                 local local_modified="$(stat -c %Y "${kconfig_file}")"
166                                                   165 
167                 for config in "${KCONFIG_REL_P    166                 for config in "${KCONFIG_REL_PATHS[@]}"; do
168                         local kconfig_src="${c    167                         local kconfig_src="${config}"
169                         local src_modified="$(    168                         local src_modified="$(stat -c %Y "${kconfig_src}")"
170                         # Only update the conf    169                         # Only update the config if it has been updated after the
171                         # previously cached co    170                         # previously cached config was created. This avoids
172                         # unnecessarily compil    171                         # unnecessarily compiling the kernel and selftests.
173                         if [[ "${src_modified}    172                         if [[ "${src_modified}" -gt "${local_modified}" ]]; then
174                                 do_update_kcon    173                                 do_update_kconfig "$kernel_checkout" "$kconfig_file"
175                                 # Once we have    174                                 # Once we have found one outdated configuration
176                                 # there is no     175                                 # there is no need to check other ones.
177                                 break             176                                 break
178                         fi                        177                         fi
179                 done                              178                 done
180         else                                      179         else
181                 do_update_kconfig "$kernel_che    180                 do_update_kconfig "$kernel_checkout" "$kconfig_file"
182         fi                                        181         fi
183 }                                                 182 }
184                                                   183 
185 main()                                            184 main()
186 {                                                 185 {
187         local script_dir="$(cd -P -- "$(dirnam    186         local script_dir="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
188         local kernel_checkout=$(realpath "${sc    187         local kernel_checkout=$(realpath "${script_dir}"/../../../../)
189         # By default the script searches for t    188         # By default the script searches for the kernel in the checkout directory but
190         # it also obeys environment variables     189         # it also obeys environment variables O= and KBUILD_OUTPUT=
191         local kernel_bzimage="${kernel_checkou    190         local kernel_bzimage="${kernel_checkout}/${BZIMAGE}"
192         local command="${DEFAULT_COMMAND}"        191         local command="${DEFAULT_COMMAND}"
193         local update_b2c="no"                     192         local update_b2c="no"
194         local debug_shell="no"                    193         local debug_shell="no"
195         local build_only="no"                  << 
196                                                   194 
197         while getopts ':hsud:j:b' opt; do      !! 195         while getopts ':hsud:j:' opt; do
198                 case ${opt} in                    196                 case ${opt} in
199                 u)                                197                 u)
200                         update_b2c="yes"          198                         update_b2c="yes"
201                         ;;                        199                         ;;
202                 d)                                200                 d)
203                         OUTPUT_DIR="$OPTARG"      201                         OUTPUT_DIR="$OPTARG"
204                         ;;                        202                         ;;
205                 j)                                203                 j)
206                         NUM_COMPILE_JOBS="$OPT    204                         NUM_COMPILE_JOBS="$OPTARG"
207                         ;;                        205                         ;;
208                 s)                                206                 s)
209                         command="/bin/sh"         207                         command="/bin/sh"
210                         debug_shell="yes"         208                         debug_shell="yes"
211                         ;;                        209                         ;;
212                 b)                             << 
213                         build_only="yes"       << 
214                         ;;                     << 
215                 h)                                210                 h)
216                         usage                     211                         usage
217                         exit 0                    212                         exit 0
218                         ;;                        213                         ;;
219                 \? )                              214                 \? )
220                         echo "Invalid Option:     215                         echo "Invalid Option: -$OPTARG"
221                         usage                     216                         usage
222                         exit 1                    217                         exit 1
223                         ;;                        218                         ;;
224                 : )                               219                 : )
225                         echo "Invalid Option:     220                         echo "Invalid Option: -$OPTARG requires an argument"
226                         usage                     221                         usage
227                         exit 1                    222                         exit 1
228                         ;;                        223                         ;;
229                 esac                              224                 esac
230         done                                      225         done
231         shift $((OPTIND -1))                      226         shift $((OPTIND -1))
232                                                   227 
233         # trap 'catch "$?"' EXIT                  228         # trap 'catch "$?"' EXIT
234         if [[ "${build_only}" == "no" && "${de !! 229 
                                                   >> 230         if [[ "${debug_shell}" == "no" ]]; then
235                 if [[ $# -eq 0 ]]; then           231                 if [[ $# -eq 0 ]]; then
236                         echo "No command speci    232                         echo "No command specified, will run ${DEFAULT_COMMAND} in the vm"
237                 else                              233                 else
238                         command="$@"              234                         command="$@"
239                                                   235 
240                         if [[ "${command}" ==     236                         if [[ "${command}" == "/bin/bash" || "${command}" == "bash" ]]
241                         then                      237                         then
242                                 debug_shell="y    238                                 debug_shell="yes"
243                         fi                        239                         fi
244                 fi                                240                 fi
245         fi                                        241         fi
246                                                   242 
247         local kconfig_file="${OUTPUT_DIR}/late    243         local kconfig_file="${OUTPUT_DIR}/latest.config"
248         local make_command="make -j ${NUM_COMP    244         local make_command="make -j ${NUM_COMPILE_JOBS} KCONFIG_CONFIG=${kconfig_file}"
249                                                   245 
250         # Figure out where the kernel is being    246         # Figure out where the kernel is being built.
251         # O takes precedence over KBUILD_OUTPU    247         # O takes precedence over KBUILD_OUTPUT.
252         if [[ "${O:=""}" != "" ]]; then           248         if [[ "${O:=""}" != "" ]]; then
253                 if is_rel_path "${O}"; then       249                 if is_rel_path "${O}"; then
254                         O="$(realpath "${PWD}/    250                         O="$(realpath "${PWD}/${O}")"
255                 fi                                251                 fi
256                 kernel_bzimage="${O}/${BZIMAGE    252                 kernel_bzimage="${O}/${BZIMAGE}"
257                 make_command="${make_command}     253                 make_command="${make_command} O=${O}"
258         elif [[ "${KBUILD_OUTPUT:=""}" != "" ]    254         elif [[ "${KBUILD_OUTPUT:=""}" != "" ]]; then
259                 if is_rel_path "${KBUILD_OUTPU    255                 if is_rel_path "${KBUILD_OUTPUT}"; then
260                         KBUILD_OUTPUT="$(realp    256                         KBUILD_OUTPUT="$(realpath "${PWD}/${KBUILD_OUTPUT}")"
261                 fi                                257                 fi
262                 kernel_bzimage="${KBUILD_OUTPU    258                 kernel_bzimage="${KBUILD_OUTPUT}/${BZIMAGE}"
263                 make_command="${make_command}     259                 make_command="${make_command} KBUILD_OUTPUT=${KBUILD_OUTPUT}"
264         fi                                        260         fi
265                                                   261 
266         local b2c="${OUTPUT_DIR}/vm2c.py"         262         local b2c="${OUTPUT_DIR}/vm2c.py"
267                                                   263 
268         echo "Output directory: ${OUTPUT_DIR}"    264         echo "Output directory: ${OUTPUT_DIR}"
269                                                   265 
270         mkdir -p "${OUTPUT_DIR}"                  266         mkdir -p "${OUTPUT_DIR}"
271         update_kconfig "${kernel_checkout}" "$    267         update_kconfig "${kernel_checkout}" "${kconfig_file}"
272                                                   268 
273         recompile_kernel "${kernel_checkout}"     269         recompile_kernel "${kernel_checkout}" "${make_command}"
274         update_selftests "${kernel_checkout}"  << 
275                                                << 
276         if [[ "${build_only}" == "no" ]]; then << 
277                 if [[ "${update_b2c}" == "no"  << 
278                         echo "vm2c script not  << 
279                         update_b2c="yes"       << 
280                 fi                             << 
281                                                   270 
282                 if [[ "${update_b2c}" == "yes" !! 271         if [[ "${update_b2c}" == "no" && ! -f "${b2c}" ]]; then
283                         download $B2C_URL $b2c !! 272                 echo "vm2c script not found in ${b2c}"
284                         chmod +x $b2c          !! 273                 update_b2c="yes"
285                 fi                             !! 274         fi
286                                                   275 
287                 run_vm "${kernel_checkout}" $b !! 276         if [[ "${update_b2c}" == "yes" ]]; then
288                 if [[ "${debug_shell}" != "yes !! 277                 download $B2C_URL $b2c
289                         echo "Logs saved in ${ !! 278                 chmod +x $b2c
290                 fi                             !! 279         fi
291                                                   280 
292                 exit $(cat ${OUTPUT_DIR}/${EXI !! 281         update_selftests "${kernel_checkout}" "${make_command}"
                                                   >> 282         run_vm "${kernel_checkout}" $b2c "${kernel_bzimage}" "${command}"
                                                   >> 283         if [[ "${debug_shell}" != "yes" ]]; then
                                                   >> 284                 echo "Logs saved in ${OUTPUT_DIR}/${LOG_FILE}"
293         fi                                        285         fi
                                                   >> 286 
                                                   >> 287         exit $(cat ${OUTPUT_DIR}/${EXIT_STATUS_FILE})
294 }                                                 288 }
295                                                   289 
296 main "$@"                                         290 main "$@"
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php