Skip to contentSkip to conversation

mbuto: fix the help error message

PATCH New Sevinj Aghayeva 1 participant 4 messages Apr 17, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/4 mbuto: fix the help error message

The examples in the help error message still show -c and -t suboptions when choosing specific kselftest collections and tests. Capitalize them to match the actual suboptions.

---
 mbuto | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mbuto +2 -2
index 3a66a6e..4565a19 100755
@@ -1106,9 +1106,9 @@ usage() {
 	echo "			-T collection:test"
 	echo "				select a specific test to run"
 	echo "		Examples:"
-	echo "			-p kselftests -c net"
+	echo "			-p kselftests -C net"
 	echo "				run all the tests in net collection"
-	echo "			-p kselftests -t net:ip_defrag.sh"
+	echo "			-p kselftests -T net:ip_defrag.sh"
 	echo "				run ip_defrag.sh from net collection"
 	echo "	-s SCRIPT|-"
 	echo "		fix-up script to run before init, '-' for none"
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/4 mbuto: undo commit 6199e368

In reply to a message not in the archive

Commit 6199e368 moves argument parsing before checking fakeroot and saves the arguments in ARGS variable. Unfortunately, passing ARGS to the recursive call flattens and removes quotes, which disables passing multiple arguments to suboptions, as in -C "net proc". For now we undo this commit to enable multiple argument passing to suboptions.

---
 mbuto | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
mbuto +8 -10
index 4565a19..44b9a56 100755
@@ -1159,7 +1159,14 @@ usage() {
 ################################################################################
 
 
-ARGS=${@}
+# If we're not running as root, re-run with fakeroot
+if [ "${LD_PRELOAD}" != "libfakeroot-sysv.so" ] && [ "$(id -u)" -ne 0 ]; then
+	if ! FAKEROOT="$(command -v fakeroot)"; then
+		err "Not root and no fakeroot available, exiting"
+	fi
+	PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" "${@}"
+	exit ${?}
+fi
 
 # Parse options
 while getopts :c:df:k:m:p:s:vh __opt; do
@@ -1182,15 +1189,6 @@ done
 shift $((OPTIND - 1))
 [ -z "${PROFILE}" ] && PROFILE="base"
 
-# If we're not running as root, re-run with fakeroot
-if [ "${LD_PRELOAD}" != "libfakeroot-sysv.so" ] && [ "$(id -u)" -ne 0 ]; then
-	if ! FAKEROOT="$(command -v fakeroot)"; then
-		err "Not root and no fakeroot available, exiting"
-	fi
-	PATH="${PATH}:/sbin:/usr/sbin" "${FAKEROOT}" "${0}" ${ARGS}
-	exit ${?}
-fi
-
 # Check needed tools, exit if any is missing
 for __l in ${TOOLS}; do
 	cmd_check "${__l}"
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/4 mbuto: quote variables when calling eval

In reply to a message not in the archive

We need to pass suboptions multiple arguments as a single string, as in

SUBOPT_collection="net proc"

Without these quotes the result of eval becomes

SUBOPT_collection=net proc

which assings only the value "net" to SUBOPT_collection.

---
 mbuto | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mbuto +1 -1
index 44b9a56..f9ee6c5 100755
@@ -497,7 +497,7 @@ subopts_get_one() {
 	[ "${__profile}" != "${PROFILE}" ] 	&& return 1
 	[ "${__passed}" != "${__short}" ]	&& return 1
 
-	eval $(echo SUBOPT_${__name}="${__value}")
+	eval $(echo SUBOPT_${__name}=\"${__value}\")
 }
 
 # subopts_get() - Set sub-option values, validating against SUBOPTS
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/4 mbuto: enable passing multiple collections and tests to suboptions

In reply to a message not in the archive

The run_kselftest.sh script, which is run upon booting the image created by mbuto, allows specifying multiple collections and specific tests, as in:

run_kselftest.sh -c "net proc" -t "x86:iopl_32 timers:rtcpie"

The above command runs (1) all the tests in the net collection, (2) all the tests in the proc collection, (3) the iopl_32 test from the x86 collection, and (4) the rtcpie test from the timers collection. This patch enables the same functionality in mbuto. Now users can run mbuto as follows:

mbuto -p kselftests -C "net proc" -T "x86:iopl_32 timers:rtcpie"

and mbuto generates an image that runs the same set of tests. In addition, mbuto installs only the tests in the specified collections in the image. For example, for the above command line, mbuto will install all the tests in the net, proc, x86, and timers collections (but it will only run iopl_32 and rtcpie test from the last two). Mbuto also installs only the modules needed for running these tests and warns the user if there are missing modules.

Mbuto also warns the user if an invalid collection name is passed to the -C suboption. Due to irregular structure of Makefiles in selftest directories, it is hard to warn the user if an invalid test name is passed to the -T option. In this case the user will find out about the mistake after the kernel boots and run_kselftest.sh fails to run the test.

---
 mbuto | 47 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 15 deletions(-)
mbuto +32 -15
index f9ee6c5..49b8139 100755
@@ -203,14 +203,31 @@ profile_kselftests() {
 		exit 1
 	fi
 
-	KERNEL="$(cat include/config/kernel.release)"
+	KERNEL="$(${CAT} include/config/kernel.release)"
+
+	__testpath="./tools/testing/selftests/"
+	__makefile="${__testpath}Makefile"
+	__colls=
+	for __c in ${SUBOPT_collection}; do
+		if ! ${GREP} -q "^TARGETS += ${__c}$" ${__makefile}; then
+			notice "WARNING: collection ${__c} doesn't exist"
+			continue
+		fi
+		__colls="${__c} ${__colls}"
+	done
+
+	for __t in ${SUBOPT_test}; do
+		__colls="${__colls} $(echo ${__t} | ${AWK} -F':' '{print $1}')"
+	done
+	__colls="$(echo ${__colls} | ${TR} ' ' '\n' | ${SORT} -u)"
+
+	__pattern=$(list_join "${__colls}" '^' '$' '|')
 
-	__skip_targets=$(${AWK} '/^TARGETS/ { print $3}' \
-		tools/testing/selftests/Makefile | \
-		${GREP} -v "^${SUBOPT_collection}$" | ${TR} '\n' ' ')
+	__skip_targets=$(${AWK} '/^TARGETS/ { print $3}' ${__makefile} | \
+		${EGREP} -v "${__pattern}" | ${TR} '\n' ' ')
 
-	${MAKE} SKIP_TARGETS="${__skip_targets}" -C \
-		tools/testing/selftests/ install >/dev/null 2>&1
+	${MAKE} SKIP_TARGETS="${__skip_targets}" -C ${__testpath} install \
+								 >/dev/null 2>&1
 
 	MODDIR="$(${REALPATH} .mbuto_mods)"
 	${RM} -rf "${MODDIR}"
@@ -218,10 +235,12 @@ profile_kselftests() {
 	INSTALL_MOD_PATH="${MODDIR}" ${MAKE} modules_install -j ${THREADS} \
 								>/dev/null
 
-	__cfg="./tools/testing/selftests/${SUBOPT_collection}/config"
+	__files=$(list_join "${__colls}" "${__testpath}" '/config' ' ')
+	__cfgs="$(${CAT} ${__files} 2>/dev/null)"
+
 	KMODS=
-	if [ -f ${__cfg} ]; then
-		__mods=$(${AWK} -F'=' '/=m/ {print $1}' ${__cfg} | ${SORT} -u)
+	if [ ! -z "${__cfgs}" ]; then
+		__mods=$(echo "${__cfgs}" | ${AWK} -F'=' '/=m/ {print $1}' | ${SORT} -u)
 
 		__pattern=$(list_join "${__mods}" '^obj-\$\(' '\).*.o$' '|')
 		__result=$(${BASENAME} -a -s .o \
@@ -253,12 +272,11 @@ profile_kselftests() {
 
 	DIRS="${DIRS} /tmp /run/netns /var/run"
 
-	COPIES="${COPIES}
-		tools/testing/selftests/kselftest_install/*,"
+	COPIES="${COPIES} ${__testpath}kselftest_install/*,"
 
 	__run_args=
-	[ ! -z ${SUBOPT_collection} ] && __run_args="-c ${SUBOPT_collection}"
-	[ ! -z ${SUBOPT_test} ] && __run_args="${__run_args} -t ${SUBOPT_test}"
+	[ ! -z "${SUBOPT_collection}" ] && __run_args="-c ${SUBOPT_collection}"
+	[ ! -z "${SUBOPT_test}" ] && __run_args="${__run_args} -t ${SUBOPT_test}"
 
 	FIXUP='#!/bin/sh
 
@@ -289,8 +307,7 @@ profile_kselftests() {
 		[ "${a}" != "s" ] && ./run_kselftest.sh '"${__run_args}"'
 '
 
-	for __f in $(${FIND} tools/testing/selftests/kselftest_install/ \
-		     -executable); do
+	for __f in $(${FIND} ${__testpath}kselftest_install/ -executable); do
 		case $("${FILE}" -bi "${__f}") in
 		"application/"*) libs_copy "${__f}" ;;
 		esac
Signature · 1 line
2.25.1