[LTP] [PATCH v2 3/4] shell: add kconfig parse api

Petr Vorel pvorel@suse.cz
Thu Jan 6 11:40:56 CET 2022


Hi Xu,

> +tst_require_kconfigs()
> +{
> +	[ $# -eq 0 ] && return 0
> +
> +	local kconfigs
> +	local kconfig_i
> +	local kconfig_max
> +
> +	kconfigs=$@

> +	[ -z "$kconfigs" ] && return 0
> +
> +	tst_check_cmds cut tr wc
> +	kconfig_max=$(( $(echo "$kconfigs" | tr -cd "$TST_NEEDS_KCONFIGS_IFS" | wc -c) +1))
> +	if [ $kconfig_max -gt 10 ]; then
> +		tst_brk TCONF "The max number of kconfig is 10!"
> +	fi
> +
> +	for kconfig_i in $(seq $kconfig_max); do
> +		eval "local kconfig$kconfig_i"
> +		eval "kconfig$kconfig_i='$(echo "$kconfigs" | cut -d"$TST_NEEDS_KCONFIGS_IFS" -f$kconfig_i)'"
Well, we use 2x eval and cut in order to have easy C code. How about move
splitting string to C (using e.g. strtok_r()? Although using this code is
probably safe for any shell (we use similar cut like delimiter in tst_test.sh),
I've had enough of fixing obscure shell bugs. And C code with strtok_r() is more
portable across libc than any shell code.

> +	done
> +
> +	tst_check_kconfigs $kconfig1 $kconfig2 $kconfig3 $kconfig4 $kconfig5 $kconfig6\
> +			$kconfig7 $kconfig8 $kconfig9 $kconfig10
Now I see the need for the need to limit. First, you need to quote parameters:

	tst_check_kconfigs "$kconfig1" "$kconfig2" "$kconfig3" "$kconfig4" "$kconfig5" "$kconfig6" \
			"$kconfig7" "$kconfig8" "$kconfig9" "$kconfig10"

Because there might be config value with space. I found only one which is not
going to be used:
CONFIG_CC_VERSION_TEXT="gcc (SUSE Linux) 11.2.1 20211124 [revision 7510c23c1ec53aa4a62705f0384079661342ff7b]"
but we cannot rely on that.

Kind regards,
Petr

> +	if [ $? -ne 0 ]; then
> +		tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
> +	fi
> +
> +	return 0
> +}


More information about the ltp mailing list