Skip to contentSkip to conversation

mbuto: support building a minimal image for kernel selftests

PATCH In review Sevinj Aghayeva 3 participants 7 messages Apr 14, 2022 – Apr 15, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mbuto: support building a minimal image for kernel selftests

Adds suboption -c for the case of -p kselftests for choosing a test collection to run. For example, specifying "-p kselftests -c net" creates an image that contains only the tests from the net collection and only the kernel modules needed to run those tests. If there are missing modules for running the tests, a warning will be emitted showing missing modules names. The -c option is similar to the -c option of run_kselftests.sh, but unlike run_kselftest.sh's option it currently it doesn't support specifying multiple collections. This will be fixed later.

Also adds suboption -t for the case of -p kselftests for choosing a specific test. For example, specifying "-p kselftests -t net:ip_defrag.sh" creates an image that runs only the single test when booted. This option is also similar to run_kselftest.sh's -t option, but it is also lacking some functionality, which will be fixed later.

v1 -> v2: Update TOOLS, Use variable names for commands, and use capitalized versions of run_kselftests.sh options (-C and -T).

---
 mbuto | 161 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 135 insertions(+), 26 deletions(-)
mbuto +135 -26
index c643c9b..74c81eb 100755
@@ -205,7 +205,12 @@ profile_kselftests() {
 
 	KERNEL="$(cat include/config/kernel.release)"
 
-	${MAKE} -C tools/testing/selftests/ install >/dev/null 2>&1
+	__skip_targets=$(${AWK} '/^TARGETS/ { print $3}' \
+		tools/testing/selftests/Makefile | \
+		${GREP} -v "^${SUBOPT_collection}$" | ${TR} '\n' ' ')
+
+	${MAKE} SKIP_TARGETS="${__skip_targets}" -C \
+		tools/testing/selftests/ install >/dev/null 2>&1
 
 	MODDIR="$(${REALPATH} .mbuto_mods)"
 	${RM} -rf "${MODDIR}"
@@ -213,19 +218,46 @@ profile_kselftests() {
 	INSTALL_MOD_PATH="${MODDIR}" ${MAKE} modules_install -j ${THREADS} \
 								>/dev/null
 
-	__skip_dirs="drivers/gpu drivers/iio drivers/infiniband drivers/media
-		     drivers/net/ethernet drivers/net/wireless
-		     drivers/scsi drivers/usb"
-	__skip_args=
-	for __d in ${__skip_dirs}; do
-		__skip_args="${__skip_args}-path ${__d} -prune "
-	done
-	KMODS="$(${FIND} "${MODDIR}" ${__skip_args}			\
-		-o -name '*.ko' -printf "%p ")"
+	__cfg="./tools/testing/selftests/${SUBOPT_collection}/config"
+	KMODS=
+	if [ -f ${__cfg} ]; then
+		__mods=$(${AWK} -F'=' '/=m/ {print $1}' ${__cfg} | ${SORT} -u)
+
+		__egrep_pattern=""
+		for __c in ${__mods}; do
+	    		__egrep_pattern='^obj-\$\('"${__c}"'\).*.o$|'"${__egrep_pattern}"
+		done
+		__egrep_pattern=${__egrep_pattern%|}
+
+		__kmods_needed=
+		__find_pattern=
+		for __mo in $(${EGREP} -rn --include "*Makefile" ${__egrep_pattern} | \
+				${AWK} -F'+=' '/+=/ {print $2}'); do
+			__m=$(${BASENAME} -s .o ${__mo})
+			__find_pattern="-name ${__m}.ko -o ${__find_pattern}"
+			__kmods_needed="${__m} ${__kmods_needed}"
+		done
+		__find_pattern=${__find_pattern%-o }
 
-	workers kmod_strip_worker
+		KMODS=$(${FIND} "${MODDIR}" ${__find_pattern} | ${TR} '\n' ' ')
 
-	KMODS="$(basename -a -s .ko ${KMODS})"
+		workers kmod_strip_worker
+
+		KMODS="$(${BASENAME} -a -s .ko ${KMODS})"
+
+		__kmods_missing=
+		for __n in ${__kmods_needed}; do
+			__found=0
+			for __f in ${KMODS}; do
+				[ ${__n} = ${__f} ] && __found=1
+			done
+			[ ${__found} -eq 0 ] && \
+				__kmods_missing="${__n} ${__kmods_missing}"
+		done
+		if [ ! -z "${__kmods_missing}" ]; then
+			notice "WARNING: missing modules: ${__kmods_missing}"
+		fi
+	fi
 
 	LINKS="${LINKS:-
 		 bash		/init
@@ -240,6 +272,10 @@ profile_kselftests() {
 	COPIES="${COPIES}
 		tools/testing/selftests/kselftest_install/*,"
 
+	__run_args=
+	[ ! -z ${SUBOPT_collection} ] && __run_args="-c ${SUBOPT_collection}"
+	[ ! -z ${SUBOPT_test} ] && __run_args="${__run_args} -t ${SUBOPT_test}"
+
 	FIXUP='#!/bin/sh
 
 		export PATH=/bin:/usr/bin:/sbin:/usr/sbin
@@ -266,7 +302,7 @@ profile_kselftests() {
 		echo 3 > /proc/sys/kernel/printk
 		echo "Press s for shell, any other key to run selftests"
 		read a
-		[ "${a}" != "s" ] && ./run_kselftest.sh
+		[ "${a}" != "s" ] && ./run_kselftest.sh '"${__run_args}"'
 '
 
 	for __f in $(${FIND} tools/testing/selftests/kselftest_install/ \
@@ -286,9 +322,10 @@ profile_kselftests() {
 ### Helpers ####################################################################
 
 # List of tools used here, assigned to uppercase variable names
-TOOLS="basename bc cat cd chmod cp cpio depmod diff dirname du file find grep
-       gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv printf
-       readlink realpath rm rmdir seq sleep strip sync umount uname wget which"
+TOOLS="awk basename bc cat cd chmod cp cpio depmod diff dirname du file find 
+       grep egrep gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv
+       printf readlink realpath rm rmdir seq sleep sort strip sync tr umount
+       uname wget which"
 
 # err() - Print error and exit
 # $@:	Error message, optionally with printf format and arguments
@@ -392,6 +429,63 @@ workers() {
 ################################################################################
 
 
+### Suboption Parsing #########################################################
+
+SUBOPTS='
+	kselftests	C	collection	Select a collection of kernel tests
+	kselftests	T	test		Select a test from a collection
+'
+
+subopts_profile=
+subopts_usage_one() {
+	__profile="${1}"
+	__short="${2}"
+	__help="${4}"
+
+	if [ "${usage_subopts_profile}" != ${__profile} ]; then
+		usage_subopts_profile="${__profile}"
+		printf "\tSub-options for profile ${__profile}:\n"
+	fi
+
+	printf "\t\t-%s: %s\n" ${__short} "${__help}"
+}
+
+subopts_usage() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_usage_one ${__line}
+		IFS='
+'
+	done
+	unset IFS
+}
+
+subopts_get_one() {
+	__profile="${3}"
+	__short="${4}"
+	__name="${5}"
+
+	[ "${__profile}" != "${PROFILE}" ] 	&& return 1
+	[ "${1}" != "${4}" ]			&& return 1
+
+	eval $(echo SUBOPT_${__name}="${2}")
+}
+
+subopts_get() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_get_one "${1}" "${2}" ${__line} && unset IFS && return 0
+		IFS='
+'
+	done
+	unset IFS
+	return 1
+}
+
 ### CPIO #######################################################################
 
 # cpio_init() - Source existing CPIO archive, or create if needed
@@ -972,8 +1066,19 @@ usage() {
 	echo "		relative root for /lib/modules. Default: /"
 	echo "	-p PROFILE"
 	echo "		select profile for add-ons, one of:"
-	echo "			base bash kata kata_debug passt"
+	echo "			base bash kata kata_debug passt kselftests"
 	echo "		Default: base"
+	echo "          when profile is kselftests there are two suboptions"
+	echo "          that are identical to run_kselftests.sh options:"
+	echo "          -C collection"
+	echo "                 select a collection of tests to run"
+	echo "          -T collection:test"
+	echo "                 select a specific test to run"
+	echo "          For example, specifying:"
+	echo "                 -p kselftests -c net"
+	echo "          runs all the tests in net collection; specifying"
+	echo "                 -p kselftests -t net:ip_defrag.sh"
+	echo "          runs only the ip_defrag.sh test from net collection"
 	echo "	-s SCRIPT|-"
 	echo "		fix-up script to run before init, '-' for none"
 	echo "	-v: verbose"
@@ -1026,16 +1131,20 @@ usage() {
 ARGS=${@}
 
 # Parse options
-while getopts c:df:k:m:p:s:vh __opt; do
+while getopts :c:df:k:m:p:s:vh __opt; do
 	case ${__opt} in
-	c) COMPRESS="${OPTARG}"	;;
-	d) STRIP="n"		;;
-	f) OUT="${OPTARG}"	;;
-	k) KERNEL="${OPTARG}"	;;
-	m) MODDIR="${OPTARG}"	;;
-	p) PROFILE="${OPTARG}"	;;
-	s) SCRIPT="${OPTARG}"	;;
-	v) VERBOSE="y"		;;
+	c) COMPRESS="${OPTARG}"					;;
+	d) STRIP="n"						;;
+	f) OUT="${OPTARG}"					;;
+	k) KERNEL="${OPTARG}"					;;
+	m) MODDIR="${OPTARG}"					;;
+	p) PROFILE="${OPTARG}"					;;
+	s) SCRIPT="${OPTARG}"					;;
+	v) VERBOSE="y"						;;
+	?)
+		eval arg=\${$((OPTIND))}
+		OPTIND=$((OPTIND + 1))
+		subopts_get "${OPTARG}" "${arg}" || usage	;;
 	h|*) usage		;;
 	esac
 done
Signature · 1 line
2.25.1
#1 lore raw

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

Quoted 1 line · On Thu, 14 Apr 2022 19:09:23 -0400 Sevinj Aghayeva <[email protected]>…

Adds suboption -c for the case of -p kselftests for choosing a test collection

...this is now -C.

Quoted 6 lines

to run. For example, specifying "-p kselftests -c net" creates an image that contains only the tests from the net collection and only the kernel modules needed to run those tests. If there are missing modules for running the tests, a warning will be emitted showing missing modules names. The -c option is similar to the -c option of run_kselftests.sh, but unlike run_kselftest.sh's option it currently it doesn't support specifying multiple collections. This will be fixed

it ... it doesn't.

Quoted 7 lines

later.

Also adds suboption -t for the case of -p kselftests for choosing a specific test. For example, specifying "-p kselftests -t net:ip_defrag.sh" creates an image that runs only the single test when booted. This option is also similar to run_kselftest.sh's -t option, but it is also lacking some functionality, which will be fixed later.

Reformatted a bit to fit in 70 columns, using imperative verb mood consistently.

Quoted 5 lines

v1 -> v2: Update TOOLS, Use variable names for commands, and use capitalized versions of run_kselftests.sh options (-C and -T).

Moved before "Signed-off-by:". In general you should put this after the --- below, but I personally like to retain version history in the tree, and that's also the case for net and net-next kernel trees.

Quoted 33 lines
---
 mbuto | 161 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 135 insertions(+), 26 deletions(-)
mbuto +6 -8
index c643c9b..74c81eb 100755
@@ -205,7 +205,12 @@ profile_kselftests() {
 
 	KERNEL="$(cat include/config/kernel.release)"
 
-	${MAKE} -C tools/testing/selftests/ install >/dev/null 2>&1
+	__skip_targets=$(${AWK} '/^TARGETS/ { print $3}' \
+		tools/testing/selftests/Makefile | \
+		${GREP} -v "^${SUBOPT_collection}$" | ${TR} '\n' ' ')
+
+	${MAKE} SKIP_TARGETS="${__skip_targets}" -C \
+		tools/testing/selftests/ install >/dev/null 2>&1
 
 	MODDIR="$(${REALPATH} .mbuto_mods)"
 	${RM} -rf "${MODDIR}"
@@ -213,19 +218,46 @@ profile_kselftests() {
 	INSTALL_MOD_PATH="${MODDIR}" ${MAKE} modules_install -j ${THREADS} \
 								>/dev/null  
 
-	__skip_dirs="drivers/gpu drivers/iio drivers/infiniband drivers/media
-		     drivers/net/ethernet drivers/net/wireless
-		     drivers/scsi drivers/usb"
-	__skip_args=
-	for __d in ${__skip_dirs}; do
-		__skip_args="${__skip_args}-path ${__d} -prune "
-	done

mbuto profile_kselftests() { · line 228

Quoted 10 lines
mbuto +8 -2
-	KMODS="$(${FIND} "${MODDIR}" ${__skip_args}			\
-		-o -name '*.ko' -printf "%p ")"
+	__cfg="./tools/testing/selftests/${SUBOPT_collection}/config"
+	KMODS=
+	if [ -f ${__cfg} ]; then
+		__mods=$(${AWK} -F'=' '/=m/ {print $1}' ${__cfg} | ${SORT} -u)
+
+		__egrep_pattern=""
+		for __c in ${__mods}; do
+	    		__egrep_pattern='^obj-\$\('"${__c}"'\).*.o$|'"${__egrep_pattern}"

Mixed spaces and tabs in indentation. You might want to use an editor showing you that ('git am' told me, though, so I guess git in general would warn you about that and maybe that's good enough).

I personally use (also) a GUI editor (not joking), Geany, which shows whitespace in a clear but non-distracting way, as it doesn't need to use a different character or terminal colour for it.

Quoted 58 lines
mbuto +35 -3
+		done
+		__egrep_pattern=${__egrep_pattern%|}
+
+		__kmods_needed=
+		__find_pattern=
+		for __mo in $(${EGREP} -rn --include "*Makefile" ${__egrep_pattern} | \
+				${AWK} -F'+=' '/+=/ {print $2}'); do
+			__m=$(${BASENAME} -s .o ${__mo})
+			__find_pattern="-name ${__m}.ko -o ${__find_pattern}"
+			__kmods_needed="${__m} ${__kmods_needed}"
+		done
+		__find_pattern=${__find_pattern%-o }
 
-	workers kmod_strip_worker
+		KMODS=$(${FIND} "${MODDIR}" ${__find_pattern} | ${TR} '\n' ' ')
 
-	KMODS="$(basename -a -s .ko ${KMODS})"
+		workers kmod_strip_worker
+
+		KMODS="$(${BASENAME} -a -s .ko ${KMODS})"
+
+		__kmods_missing=
+		for __n in ${__kmods_needed}; do
+			__found=0
+			for __f in ${KMODS}; do
+				[ ${__n} = ${__f} ] && __found=1
+			done
+			[ ${__found} -eq 0 ] && \
+				__kmods_missing="${__n} ${__kmods_missing}"
+		done
+		if [ ! -z "${__kmods_missing}" ]; then
+			notice "WARNING: missing modules: ${__kmods_missing}"
+		fi
+	fi
 
 	LINKS="${LINKS:-
 		 bash		/init
@@ -240,6 +272,10 @@ profile_kselftests() {
 	COPIES="${COPIES}
 		tools/testing/selftests/kselftest_install/*,"
 
+	__run_args=
+	[ ! -z ${SUBOPT_collection} ] && __run_args="-c ${SUBOPT_collection}"
+	[ ! -z ${SUBOPT_test} ] && __run_args="${__run_args} -t ${SUBOPT_test}"
+
 	FIXUP='#!/bin/sh
 
 		export PATH=/bin:/usr/bin:/sbin:/usr/sbin
@@ -266,7 +302,7 @@ profile_kselftests() {
 		echo 3 > /proc/sys/kernel/printk
 		echo "Press s for shell, any other key to run selftests"
 		read a
-		[ "${a}" != "s" ] && ./run_kselftest.sh
+		[ "${a}" != "s" ] && ./run_kselftest.sh '"${__run_args}"'
 '
 
 	for __f in $(${FIND} tools/testing/selftests/kselftest_install/ \

mbuto profile_kselftests() { · line 325

Quoted 7 lines
mbuto +1 -3
@@ -286,9 +322,10 @@ profile_kselftests() {
 ### Helpers ####################################################################
 
 # List of tools used here, assigned to uppercase variable names
-TOOLS="basename bc cat cd chmod cp cpio depmod diff dirname du file find grep
-       gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv printf
-       readlink realpath rm rmdir seq sleep strip sync umount uname wget which"
+TOOLS="awk basename bc cat cd chmod cp cpio depmod diff dirname du file find 

Trailing whitespace (after 'find').

Quoted 9 lines
mbuto +3 -0
+       grep egrep gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv
+       printf readlink realpath rm rmdir seq sleep sort strip sync tr umount
+       uname wget which"
 
 # err() - Print error and exit
 # $@:	Error message, optionally with printf format and arguments
@@ -392,6 +429,63 @@ workers() {
 ################################################################################
 

mbuto workers() { · line 440

Quoted 10 lines
mbuto +9 -0
 
+### Suboption Parsing #########################################################
+
+SUBOPTS='
+	kselftests	C	collection	Select a collection of kernel tests
+	kselftests	T	test		Select a test from a collection
+'
+
+subopts_profile=
+subopts_usage_one() {

I added usage comments for this function and the ones below.

Quoted 21 lines
mbuto +21 -0
+	__profile="${1}"
+	__short="${2}"
+	__help="${4}"
+
+	if [ "${usage_subopts_profile}" != ${__profile} ]; then
+		usage_subopts_profile="${__profile}"
+		printf "\tSub-options for profile ${__profile}:\n"
+	fi
+
+	printf "\t\t-%s: %s\n" ${__short} "${__help}"
+}
+
+subopts_usage() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_usage_one ${__line}
+		IFS='
+'
+	done

mbuto workers() { · line 471

Quoted 10 lines
mbuto +10 -0
+	unset IFS
+}
+
+subopts_get_one() {
+	__profile="${3}"
+	__short="${4}"
+	__name="${5}"
+
+	[ "${__profile}" != "${PROFILE}" ] 	&& return 1
+	[ "${1}" != "${4}" ]			&& return 1

Used named variables for $1 and $4 instead.

Quoted 21 lines
mbuto +17 -0
+
+	eval $(echo SUBOPT_${__name}="${2}")
+}
+
+subopts_get() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_get_one "${1}" "${2}" ${__line} && unset IFS && return 0
+		IFS='
+'
+	done
+	unset IFS
+	return 1
+}
+
 ### CPIO #######################################################################
 
 # cpio_init() - Source existing CPIO archive, or create if needed

mbuto usage() { · line 1071

Quoted 7 lines
mbuto +2 -1
@@ -972,8 +1066,19 @@ usage() {
 	echo "		relative root for /lib/modules. Default: /"
 	echo "	-p PROFILE"
 	echo "		select profile for add-ons, one of:"
-	echo "			base bash kata kata_debug passt"
+	echo "			base bash kata kata_debug passt kselftests"
 	echo "		Default: base"
+	echo "          when profile is kselftests there are two suboptions"

From this point on: you used spaces instead of tabs, and usage of capital letters is a bit inconsistent (why "when" after we had "Default"?).

mbuto usage() { · line 1078

Quoted 7 lines
mbuto +7 -0
+	echo "          that are identical to run_kselftests.sh options:"
+	echo "          -C collection"
+	echo "                 select a collection of tests to run"
+	echo "          -T collection:test"
+	echo "                 select a specific test to run"
+	echo "          For example, specifying:"
+	echo "                 -p kselftests -c net"

-C and -T in these examples.

Quoted 24 lines
mbuto +7 -9
+	echo "          runs all the tests in net collection; specifying"
+	echo "                 -p kselftests -t net:ip_defrag.sh"
+	echo "          runs only the ip_defrag.sh test from net collection"
 	echo "	-s SCRIPT|-"
 	echo "		fix-up script to run before init, '-' for none"
 	echo "	-v: verbose"
@@ -1026,16 +1131,20 @@ usage() {
 ARGS=${@}
 
 # Parse options
-while getopts c:df:k:m:p:s:vh __opt; do
+while getopts :c:df:k:m:p:s:vh __opt; do
 	case ${__opt} in
-	c) COMPRESS="${OPTARG}"	;;
-	d) STRIP="n"		;;
-	f) OUT="${OPTARG}"	;;
-	k) KERNEL="${OPTARG}"	;;
-	m) MODDIR="${OPTARG}"	;;
-	p) PROFILE="${OPTARG}"	;;
-	s) SCRIPT="${OPTARG}"	;;
-	v) VERBOSE="y"		;;
+	c) COMPRESS="${OPTARG}"					;;
+	d) STRIP="n"						;;
+	f) OUT="${OPTARG}"					;;

mbuto usage() { · line 1148

Quoted 10 lines
mbuto +9 -0
+	k) KERNEL="${OPTARG}"					;;
+	m) MODDIR="${OPTARG}"					;;
+	p) PROFILE="${OPTARG}"					;;
+	s) SCRIPT="${OPTARG}"					;;
+	v) VERBOSE="y"						;;
+	?)
+		eval arg=\${$((OPTIND))}
+		OPTIND=$((OPTIND + 1))
+		subopts_get "${OPTARG}" "${arg}" || usage	;;
 	h|*) usage		;;

Moved ;; here too.

mbuto usage() { · line 1150

Quoted 2 lines
mbuto +0 -0
 	esac
 done

Thanks again!

Signature · 1 line
Stefano
#2 lore raw
Quoted 2 lines · Stefano Brivio

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

What repository is this in?

Quoted 303 lines
Quoted 1 line · On Thu, 14 Apr 2022 19:09:23 -0400 Sevinj Aghayeva <[email protected]>…

Adds suboption -c for the case of -p kselftests for choosing a test collection

...this is now -C.

Quoted 6 lines

to run. For example, specifying "-p kselftests -c net" creates an image that contains only the tests from the net collection and only the kernel modules needed to run those tests. If there are missing modules for running the tests, a warning will be emitted showing missing modules names. The -c option is similar to the -c option of run_kselftests.sh, but unlike run_kselftest.sh's option it currently it doesn't support specifying multiple collections. This will be fixed

it ... it doesn't.

Quoted 7 lines

later.

Also adds suboption -t for the case of -p kselftests for choosing a specific test. For example, specifying "-p kselftests -t net:ip_defrag.sh" creates an image that runs only the single test when booted. This option is also similar to run_kselftest.sh's -t option, but it is also lacking some functionality, which will be fixed later.

Reformatted a bit to fit in 70 columns, using imperative verb mood consistently.

Quoted 5 lines

v1 -> v2: Update TOOLS, Use variable names for commands, and use capitalized versions of run_kselftests.sh options (-C and -T).

Moved before "Signed-off-by:". In general you should put this after the --- below, but I personally like to retain version history in the tree, and that's also the case for net and net-next kernel trees.

Quoted 33 lines
---
 mbuto | 161 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 135 insertions(+), 26 deletions(-)
mbuto +6 -8
index c643c9b..74c81eb 100755
@@ -205,7 +205,12 @@ profile_kselftests() {
 
 	KERNEL="$(cat include/config/kernel.release)"
 
-	${MAKE} -C tools/testing/selftests/ install >/dev/null 2>&1
+	__skip_targets=$(${AWK} '/^TARGETS/ { print $3}' \
+		tools/testing/selftests/Makefile | \
+		${GREP} -v "^${SUBOPT_collection}$" | ${TR} '\n' ' ')
+
+	${MAKE} SKIP_TARGETS="${__skip_targets}" -C \
+		tools/testing/selftests/ install >/dev/null 2>&1
 
 	MODDIR="$(${REALPATH} .mbuto_mods)"
 	${RM} -rf "${MODDIR}"
@@ -213,19 +218,46 @@ profile_kselftests() {
 	INSTALL_MOD_PATH="${MODDIR}" ${MAKE} modules_install -j ${THREADS} \
 								>/dev/null  
 
-	__skip_dirs="drivers/gpu drivers/iio drivers/infiniband drivers/media
-		     drivers/net/ethernet drivers/net/wireless
-		     drivers/scsi drivers/usb"
-	__skip_args=
-	for __d in ${__skip_dirs}; do
-		__skip_args="${__skip_args}-path ${__d} -prune "
-	done

mbuto profile_kselftests() { · line 228

Quoted 10 lines
mbuto +8 -2
-	KMODS="$(${FIND} "${MODDIR}" ${__skip_args}			\
-		-o -name '*.ko' -printf "%p ")"
+	__cfg="./tools/testing/selftests/${SUBOPT_collection}/config"
+	KMODS=
+	if [ -f ${__cfg} ]; then
+		__mods=$(${AWK} -F'=' '/=m/ {print $1}' ${__cfg} | ${SORT} -u)
+
+		__egrep_pattern=""
+		for __c in ${__mods}; do
+	    		__egrep_pattern='^obj-\$\('"${__c}"'\).*.o$|'"${__egrep_pattern}"

Mixed spaces and tabs in indentation. You might want to use an editor showing you that ('git am' told me, though, so I guess git in general would warn you about that and maybe that's good enough).

I personally use (also) a GUI editor (not joking), Geany, which shows whitespace in a clear but non-distracting way, as it doesn't need to use a different character or terminal colour for it.

Quoted 58 lines
mbuto +35 -3
+		done
+		__egrep_pattern=${__egrep_pattern%|}
+
+		__kmods_needed=
+		__find_pattern=
+		for __mo in $(${EGREP} -rn --include "*Makefile" ${__egrep_pattern} | \
+				${AWK} -F'+=' '/+=/ {print $2}'); do
+			__m=$(${BASENAME} -s .o ${__mo})
+			__find_pattern="-name ${__m}.ko -o ${__find_pattern}"
+			__kmods_needed="${__m} ${__kmods_needed}"
+		done
+		__find_pattern=${__find_pattern%-o }
 
-	workers kmod_strip_worker
+		KMODS=$(${FIND} "${MODDIR}" ${__find_pattern} | ${TR} '\n' ' ')
 
-	KMODS="$(basename -a -s .ko ${KMODS})"
+		workers kmod_strip_worker
+
+		KMODS="$(${BASENAME} -a -s .ko ${KMODS})"
+
+		__kmods_missing=
+		for __n in ${__kmods_needed}; do
+			__found=0
+			for __f in ${KMODS}; do
+				[ ${__n} = ${__f} ] && __found=1
+			done
+			[ ${__found} -eq 0 ] && \
+				__kmods_missing="${__n} ${__kmods_missing}"
+		done
+		if [ ! -z "${__kmods_missing}" ]; then
+			notice "WARNING: missing modules: ${__kmods_missing}"
+		fi
+	fi
 
 	LINKS="${LINKS:-
 		 bash		/init
@@ -240,6 +272,10 @@ profile_kselftests() {
 	COPIES="${COPIES}
 		tools/testing/selftests/kselftest_install/*,"
 
+	__run_args=
+	[ ! -z ${SUBOPT_collection} ] && __run_args="-c ${SUBOPT_collection}"
+	[ ! -z ${SUBOPT_test} ] && __run_args="${__run_args} -t ${SUBOPT_test}"
+
 	FIXUP='#!/bin/sh
 
 		export PATH=/bin:/usr/bin:/sbin:/usr/sbin
@@ -266,7 +302,7 @@ profile_kselftests() {
 		echo 3 > /proc/sys/kernel/printk
 		echo "Press s for shell, any other key to run selftests"
 		read a
-		[ "${a}" != "s" ] && ./run_kselftest.sh
+		[ "${a}" != "s" ] && ./run_kselftest.sh '"${__run_args}"'
 '
 
 	for __f in $(${FIND} tools/testing/selftests/kselftest_install/ \

mbuto profile_kselftests() { · line 325

Quoted 7 lines
mbuto +1 -3
@@ -286,9 +322,10 @@ profile_kselftests() {
 ### Helpers ####################################################################
 
 # List of tools used here, assigned to uppercase variable names
-TOOLS="basename bc cat cd chmod cp cpio depmod diff dirname du file find grep
-       gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv printf
-       readlink realpath rm rmdir seq sleep strip sync umount uname wget which"
+TOOLS="awk basename bc cat cd chmod cp cpio depmod diff dirname du file find 

Trailing whitespace (after 'find').

Quoted 9 lines
mbuto +3 -0
+       grep egrep gzip ldconfig ldd ln ls make mkdir mknod mktemp modprobe mv
+       printf readlink realpath rm rmdir seq sleep sort strip sync tr umount
+       uname wget which"
 
 # err() - Print error and exit
 # $@:	Error message, optionally with printf format and arguments
@@ -392,6 +429,63 @@ workers() {
 ################################################################################
 

mbuto workers() { · line 440

Quoted 10 lines
mbuto +9 -0
 
+### Suboption Parsing #########################################################
+
+SUBOPTS='
+	kselftests	C	collection	Select a collection of kernel tests
+	kselftests	T	test		Select a test from a collection
+'
+
+subopts_profile=
+subopts_usage_one() {

I added usage comments for this function and the ones below.

Quoted 21 lines
mbuto +21 -0
+	__profile="${1}"
+	__short="${2}"
+	__help="${4}"
+
+	if [ "${usage_subopts_profile}" != ${__profile} ]; then
+		usage_subopts_profile="${__profile}"
+		printf "\tSub-options for profile ${__profile}:\n"
+	fi
+
+	printf "\t\t-%s: %s\n" ${__short} "${__help}"
+}
+
+subopts_usage() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_usage_one ${__line}
+		IFS='
+'
+	done

mbuto workers() { · line 471

Quoted 10 lines
mbuto +10 -0
+	unset IFS
+}
+
+subopts_get_one() {
+	__profile="${3}"
+	__short="${4}"
+	__name="${5}"
+
+	[ "${__profile}" != "${PROFILE}" ] 	&& return 1
+	[ "${1}" != "${4}" ]			&& return 1

Used named variables for $1 and $4 instead.

Quoted 21 lines
mbuto +17 -0
+
+	eval $(echo SUBOPT_${__name}="${2}")
+}
+
+subopts_get() {
+	IFS='
+'
+	for __line in ${SUBOPTS}; do
+		IFS='	'
+		subopts_get_one "${1}" "${2}" ${__line} && unset IFS && return 0
+		IFS='
+'
+	done
+	unset IFS
+	return 1
+}
+
 ### CPIO #######################################################################
 
 # cpio_init() - Source existing CPIO archive, or create if needed

mbuto usage() { · line 1071

Quoted 7 lines
mbuto +2 -1
@@ -972,8 +1066,19 @@ usage() {
 	echo "		relative root for /lib/modules. Default: /"
 	echo "	-p PROFILE"
 	echo "		select profile for add-ons, one of:"
-	echo "			base bash kata kata_debug passt"
+	echo "			base bash kata kata_debug passt kselftests"
 	echo "		Default: base"
+	echo "          when profile is kselftests there are two suboptions"

From this point on: you used spaces instead of tabs, and usage of capital letters is a bit inconsistent (why "when" after we had "Default"?).

mbuto usage() { · line 1078

Quoted 7 lines
mbuto +7 -0
+	echo "          that are identical to run_kselftests.sh options:"
+	echo "          -C collection"
+	echo "                 select a collection of tests to run"
+	echo "          -T collection:test"
+	echo "                 select a specific test to run"
+	echo "          For example, specifying:"
+	echo "                 -p kselftests -c net"

-C and -T in these examples.

Quoted 24 lines
mbuto +7 -9
+	echo "          runs all the tests in net collection; specifying"
+	echo "                 -p kselftests -t net:ip_defrag.sh"
+	echo "          runs only the ip_defrag.sh test from net collection"
 	echo "	-s SCRIPT|-"
 	echo "		fix-up script to run before init, '-' for none"
 	echo "	-v: verbose"
@@ -1026,16 +1131,20 @@ usage() {
 ARGS=${@}
 
 # Parse options
-while getopts c:df:k:m:p:s:vh __opt; do
+while getopts :c:df:k:m:p:s:vh __opt; do
 	case ${__opt} in
-	c) COMPRESS="${OPTARG}"	;;
-	d) STRIP="n"		;;
-	f) OUT="${OPTARG}"	;;
-	k) KERNEL="${OPTARG}"	;;
-	m) MODDIR="${OPTARG}"	;;
-	p) PROFILE="${OPTARG}"	;;
-	s) SCRIPT="${OPTARG}"	;;
-	v) VERBOSE="y"		;;
+	c) COMPRESS="${OPTARG}"					;;
+	d) STRIP="n"						;;
+	f) OUT="${OPTARG}"					;;

mbuto usage() { · line 1148

Quoted 10 lines
mbuto +9 -0
+	k) KERNEL="${OPTARG}"					;;
+	m) MODDIR="${OPTARG}"					;;
+	p) PROFILE="${OPTARG}"					;;
+	s) SCRIPT="${OPTARG}"					;;
+	v) VERBOSE="y"						;;
+	?)
+		eval arg=\${$((OPTIND))}
+		OPTIND=$((OPTIND + 1))
+		subopts_get "${OPTARG}" "${arg}" || usage	;;
 	h|*) usage		;;

Moved ;; here too.

mbuto usage() { · line 1150

Quoted 2 lines
mbuto +0 -0
 	esac
 done

Thanks again!

Signature · 1 line
Stefano
#3 lore raw
Quoted 5 lines · On Fri, 15 Apr 2022 10:05:43 -0700 Alison Schofield…
Quoted 2 lines · Stefano Brivio

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

What repository is this in?

https://mbuto.sh/mbuto -- we're tracking project-specific tasks at
https://board.net/p/Outreachy2022KernelNetworking and this is task #7 there.

Documentation is still a bit lacking (I'm working on it on and off), I hope it can become finally usable for other applicants (to run kselftests without semi-complicated VM installs) in a couple of days.

Signature · 1 line
Stefano
#4 lore raw
Quoted 7 lines · Stefano Brivio
Quoted 4 lines · On Fri, 15 Apr 2022 10:05:43 -0700 Alison Schofield…
Quoted 2 lines · Stefano Brivio

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

Quoted 8 lines
Quoted 1 line

What repository is this in?

https://mbuto.sh/mbuto -- we're tracking project-specific tasks at
https://board.net/p/Outreachy2022KernelNetworking and this is task #7 there.

Documentation is still a bit lacking (I'm working on it on and off), I hope it can become finally usable for other applicants (to run kselftests without semi-complicated VM installs) in a couple of days.

I see, thanks!

So do you think "Minimal Builder Using Terse Options" will someday land in the kernels scripts/ directory?

Wondering why this isn't in a github repository? I think you (Stefano) told me something previously about access issues that some folks have with github.

Thanks for helping me understand!
Alison

Quoted 4 lines
Signature · 2 lines
-- 
Stefano
#5 lore raw
Quoted 13 lines · On Fri, 15 Apr 2022 12:23:39 -0700 Alison Schofield…
Quoted 12 lines · Stefano Brivio
Quoted 5 lines · On Fri, 15 Apr 2022 10:05:43 -0700 Alison Schofield…
Quoted 2 lines · Stefano Brivio

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

What repository is this in?

https://mbuto.sh/mbuto -- we're tracking project-specific tasks at
https://board.net/p/Outreachy2022KernelNetworking and this is task #7 there.

Quoted 8 lines
Quoted 3 lines

Documentation is still a bit lacking (I'm working on it on and off), I hope it can become finally usable for other applicants (to run kselftests without semi-complicated VM installs) in a couple of days.

I see, thanks!

So do you think "Minimal Builder Using Terse Options" will someday land in the kernels scripts/ directory?

That might be an attempt/possibility, yes, but not necessarily: it has other use cases as well. I actually started it for a completely different reason, and right now the only automated user it has is yet another thing (tests for https://passt.top).

Quoted 3 lines

Wondering why this isn't in a github repository? I think you (Stefano) told me something previously about access issues that some folks have with github.

First off, opinions expressed here are solely my own and do not express the views or opinions of my employer. :)

Three categories of reasons:

1. GitHub is subject to US trade control laws (EAR), and access is currently excluded for at least developers residing in Cuba and Syria -- it looks like it's working fine for Iran-based developers, and I understand there's the will from GitHub to find workarounds for others:

	https://twitter.com/github/status/1346626296219099136?lang=en

...but I would still define the current situation somewhat exclusive (and only partially under control of GitHub, of course).

2. I don't like using proprietary software (especially since a. I'm volunteering and b. Outreachy is involved)

3. technical reasons: I think an email-based workflow has many advantages over "trendy" things, and for example contributing to mbuto can be "used" to get more familiar with the kernel changes workflow as well, as it's essentially the same.

There are also some tricks I couldn't do on GitHub, for example arbitrary HTML/JavaScript in web pages:
https://mbuto.sh/mbuto/tree/README.md

...and actually I have a ton of them, but I don't want to make this email overly long. :)

Quoted 1 line

Thanks for helping me understand!

You're welcome! Out of personal curiosity, and I'm mostly interested in an instinctive/first-thought answer here: why did you expect it to be on GitHub?

Signature · 1 line
Stefano
#6 lore raw
Quoted 61 lines · Stefano Brivio
Quoted 13 lines · On Fri, 15 Apr 2022 12:23:39 -0700 Alison Schofield…
Quoted 12 lines · Stefano Brivio
Quoted 5 lines · On Fri, 15 Apr 2022 10:05:43 -0700 Alison Schofield…
Quoted 2 lines · Stefano Brivio

This is really valuable work, thank you. I took the liberty of fixing up a few things, listed below, and pushed:

What repository is this in?

https://mbuto.sh/mbuto -- we're tracking project-specific tasks at
https://board.net/p/Outreachy2022KernelNetworking and this is task #7 there.

Quoted 8 lines
Quoted 3 lines

Documentation is still a bit lacking (I'm working on it on and off), I hope it can become finally usable for other applicants (to run kselftests without semi-complicated VM installs) in a couple of days.

I see, thanks!

So do you think "Minimal Builder Using Terse Options" will someday land in the kernels scripts/ directory?

That might be an attempt/possibility, yes, but not necessarily: it has other use cases as well. I actually started it for a completely different reason, and right now the only automated user it has is yet another thing (tests for https://passt.top).

Quoted 3 lines

Wondering why this isn't in a github repository? I think you (Stefano) told me something previously about access issues that some folks have with github.

First off, opinions expressed here are solely my own and do not express the views or opinions of my employer. :)

Three categories of reasons:

1. GitHub is subject to US trade control laws (EAR), and access is currently excluded for at least developers residing in Cuba and Syria -- it looks like it's working fine for Iran-based developers, and I understand there's the will from GitHub to find workarounds for others:

	https://twitter.com/github/status/1346626296219099136?lang=en

...but I would still define the current situation somewhat exclusive (and only partially under control of GitHub, of course).

2. I don't like using proprietary software (especially since a. I'm volunteering and b. Outreachy is involved)

3. technical reasons: I think an email-based workflow has many advantages over "trendy" things, and for example contributing to mbuto can be "used" to get more familiar with the kernel changes workflow as well, as it's essentially the same.

There are also some tricks I couldn't do on GitHub, for example arbitrary HTML/JavaScript in web pages:
https://mbuto.sh/mbuto/tree/README.md

Quoted 8 lines

...and actually I have a ton of them, but I don't want to make this email overly long. :)

Quoted 1 line

Thanks for helping me understand!

You're welcome! Out of personal curiosity, and I'm mostly interested in an instinctive/first-thought answer here: why did you expect it to be on GitHub?

I'm in U.S. and in my circles, github is the defacto location for sharing code.

Quoted 4 lines
Signature · 2 lines
-- 
Stefano