utils/test-pkg: add check that show-info is proper json

JSON parser are usually rather strict when parsing their input. Both
jq and the python json module choke on non-conformant inputs.

Commit e4c284e6b9 (package/pkg-utils: escape \ in generated legal-info)
fixed the \-escaping case, but we want to ensure that we do not have
other data that would be improperly encoded.

To more easily catch issues, also run show-info and send its output
through jq, to try and validate the output.

Reported-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
Yann E. MORIN 2021-02-07 22:21:01 +01:00 committed by Arnout Vandecappelle (Essensium/Mind)
parent 7affc7827a
commit f29239cf9b

View File

@ -13,7 +13,7 @@ do_clean() {
main() {
local o O opts
local cfg dir pkg random toolchains_csv toolchain all number mode prepare_only
local ret nb nb_skip nb_fail nb_legal nb_tc build_dir keep
local ret nb nb_skip nb_fail nb_legal nb_show nb_tc build_dir keep
local -a toolchains
local pkg_br_name
@ -126,6 +126,7 @@ main() {
nb_skip=0
nb_fail=0
nb_legal=0
nb_show=0
for toolchainconfig in "${toolchains[@]}"; do
: $((nb++))
toolchain="$(basename "${toolchainconfig}" .config)"
@ -137,11 +138,12 @@ main() {
(1) : $((nb_skip++)); printf "SKIPPED\n";;
(2) : $((nb_fail++)); printf "FAILED\n";;
(3) : $((nb_legal++)); printf "FAILED\n";;
(4) : $((nb_show++)); printf "FAILED\n";;
esac
done
printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
${nb} ${nb_skip} ${nb_fail} ${nb_legal}
printf "%d builds, %d skipped, %d build failed, %d legal-info failed, %d show-info failed\n" \
${nb} ${nb_skip} ${nb_fail} ${nb_legal} ${nb_show}
return $((nb_fail + nb_legal))
}
@ -197,6 +199,20 @@ build_one() {
return 3
fi
# Validate that we generate proper json as show-info
{ tput smso; printf '>>> Running show-info\n'; tput rmso; } >> "${dir}/logfile" 2> /dev/null;
JQ="$(which jq)"
if [ -z "${JQ}" ]; then
make O="${dir}" host-jq >> "${dir}/logfile" 2>&1
JQ="${dir}/host/bin/jq"
fi
if ! make O="${dir}" "${pkg:+${pkg}-}show-info" > "${dir}/info.json" 2>> "${dir}/logfile"; then
return 4
fi
if ! "${JQ}" . < "${dir}/info.json" >> "${dir}/logfile" 2>&1; then
return 4
fi
# If we get here, the build was successful. Clean up the build/host
# directories to save disk space, unless 'keep' was set.
if [ ${keep} -ne 1 ]; then