From: Cam Hutchison <camh@xdna.net>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 1/6] support/scripts: add script to test a package
Date: Wed, 08 Feb 2017 22:00:03 -0000 [thread overview]
Message-ID: <70e8.589b94e3.db816@xdna.net> (raw)
In-Reply-To: 085941ea3e9e9f34405ac10780d5c8aa2a6317aa.1486584734.git.yann.morin.1998@free.fr
"Yann E. MORIN" <yann.morin.1998@free.fr> writes:
>This script helps in testing that a package builds fine on a wide range
>of architectures and toolchains: BE/LE, 32/64-bit, musl/glibc/uclibc...
>Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
>[yann.morin.1998 at free.fr:
> - completely rewrite the script from Thomas, with help from Luca
>]
>Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
>Cc: Luca Ceresoli <luca@lucaceresoli.net>
>Cc: Thomas De Schampheleire <patrickdepinguin@gmail.com>
>Acked-by: Luca Ceresoli <luca@lucaceresoli.net>
>Reviewed-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
>---
>Changes v2 -> v3:
> - grammar (Luca)
>---
> support/scripts/test-pkg | 168 +++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 168 insertions(+)
> create mode 100755 support/scripts/test-pkg
>diff --git a/support/scripts/test-pkg b/support/scripts/test-pkg
>new file mode 100755
>index 0000000..008b32c
>--- /dev/null
>+++ b/support/scripts/test-pkg
>@@ -0,0 +1,168 @@
>+#!/bin/bash
>+set -e
>+
>+TOOLCHAINS_URL='http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'
>+
>+main() {
>+ local o O opts
>+ local cfg dir pkg toolchain
>+ local -a toolchains
>+
>+ o='hc:d:p:'
>+ O='help,config-snippet:build-dir:package:'
>+ opts="$( getopt -n "${my_name}" -o "${o}" -l "${O}" -- "${@}" )"
>+ eval set -- "${opts}"
>+
>+ while [ ${#} -gt 0 ]; do
>+ case "${1}" in
>+ (-h|--help)
>+ help; exit 0
>+ ;;
>+ (-c|--config-snippet)
>+ cfg="${2}"; shift 2
>+ ;;
>+ (-d|--build-dir)
>+ dir="${2}"; shift 2
>+ ;;
>+ (-p|--package)
>+ pkg="${2}"; shift 2
>+ ;;
>+ (--)
>+ shift; break
>+ ;;
>+ esac
>+ done
>+ if [ -z "${cfg}" ]; then
>+ printf "error: no config snippet specified\n" >&2; exit 1
>+ fi
>+ if [ -z "${dir}" ]; then
>+ dir="${HOME}/br-test-pkg"
>+ fi
>+
>+ # Extract the URLs of the toolchains; drop internal toolchains
>+ # E.g.: http://server/path/to/name.config,arch,libc
>+ # --> http://server/path/to/name.config
>+ toolchains=( $( curl -s "${TOOLCHAINS_URL}" \
>+ |sed -r -e 's/,.*//; /internal/d;'
>+ )
>+ )
>+
>+ if [ ${#toolchains[@]} -eq 0 ]; then
>+ printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
The format string should be in single quotes as it contains a glob char.
I usually put all printf format strings in single quotes since printf is
doing the substitutions, not the shell.
>+ fi
>+
>+ for toolchain in "${toolchains[@]}"; do
>+ build_one "${dir}" "${toolchain}" "${cfg}" "${pkg}"
>+ done
>+}
>+
>+build_one() {
>+ local dir="${1}"
>+ local url="${2}"
>+ local cfg="${3}"
>+ local pkg="${4}"
>+ local toolchain line
>+
>+ # Using basename(1) on a URL works nicely
>+ toolchain="$( basename "${url}" .config )"
>+
>+ printf "%40s: " "${toolchain}"
>+
>+ dir="${dir}/${toolchain}"
>+ mkdir -p "${dir}"
>+
>+ printf "download config"
>+ if ! curl -s "${url}" >"${dir}/.config"; then
>+ printf ": FAILED\n"
>+ return
>+ fi
>+
>+ cat >>"${dir}/.config" <<-_EOF_
>+ BR2_INIT_NONE=y
>+ BR2_SYSTEM_BIN_SH_NONE=y
>+ # BR2_PACKAGE_BUSYBOX is not set
>+ # BR2_TARGET_ROOTFS_TAR is not set
>+ _EOF_
>+ cat "${cfg}" >>"${dir}/.config"
>+
>+ printf ", olddefconfig"
>+ if ! make O="${dir}" olddefconfig >/dev/null 2>&1; then
>+ printf ": FAILED\n"
>+ return
>+ fi
>+ # We want all the options from the snippet to be present as-is (set
>+ # or not set) in the actual .config; if one of them is not, it means
>+ # some dependency from the toolchain or arch is not available, in
>+ # which case this config is untestable and we skip it.
>+ while read line; do
>+ if ! grep "^${line}\$" "${dir}/.config" >/dev/null 2>&1; then
You should use grep -Fx here since ${line} might contains regex chars:
if ! grep -Fx "${line}" "${dir}/.config" >/dev/null 2>&1; then
....
>+ printf ", SKIPPED\n"
>+ return
>+ fi
>+ done <"${cfg}"
.... but I'd get rid of the loop altogether and use comm(1); something like:
if [ -n "$( comm -23 <(sort "${cfg}") <(sort "${dir/.config}") )" ]; then
printf ", SKIPPED\n"
return
fi
>+
>+ if [ -n "${pkg}" ]; then
>+ printf ", dirclean"
>+ if ! make O="${dir}" "${pkg}-dirclean" >> "${dir}/logfile" 2>&1; then
>+ printf ": FAILED\n"
>+ return
>+ fi
>+ fi
>+
>+ printf ", build"
>+ # shellcheck disable=SC2086
>+ if ! make O="${dir}" ${pkg} >> "${dir}/logfile" 2>&1; then
>+ printf ": FAILED\n"
>+ return
>+ fi
>+
>+ printf ": OK\n"
>+}
>+
>+help() {
>+ cat <<_EOF_
>+test-pkg: test-build a package against various toolchains and architectures
>+
>+The supplied config snippet is appended to each toolchain config, the
>+resulting configuration is checked to ensure it still contains all options
>+specified in the snippet; if any is missing, the build is skipped, on the
>+assumption that the package under test requires a toolchain or architecture
>+feature that is missing.
>+
>+In case failures are noticed, you can fix the package and just re-run the
>+same command again; it will re-run the test where it failed. If you did
>+specify a package (with -p), the package build dir will be removed first.
>+
>+The list of toolchains is retrieved from the Buildroot autobuilders, available
>+at ${TOOLCHAINS_URL}.
>+
>+Options:
>+
>+ -h, --help
>+ Print this help.
>+
>+ -c CFG, --config-snippet CFG
>+ Use the CFG file as the source for the config snippet. This file
>+ should contain all the config options required to build a package.
>+
>+ -d DIR, --build-dir DIR
>+ Do the builds in directory DIR, one sub-dir per toolchain.
>+
>+ -p PKG, --package PKG
>+ Test-build the package PKG, by running 'make PKG'; if not specified,
>+ just runs 'make'.
>+
>+Example:
>+
>+ Testing libcec would require a config snippet that contains:
>+ BR2_PACKAGE_LIBCEC=y
>+
>+ Testing libcurl with openSSL support would require a snippet such as:
>+ BR2_PACKAGE_OPENSSL=y
>+ BR2_PACKAGE_LIBCURL=y
>+
>+_EOF_
>+}
>+
>+my_name="${0##*/}"
>+main "${@}"
>--
>2.7.4
>_______________________________________________
>buildroot mailing list
>buildroot at busybox.net
>http://lists.busybox.net/mailman/listinfo/buildroot
next prev parent reply other threads:[~2017-02-08 22:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-08 20:15 [Buildroot] [PATCH 0/6 v3] support: script to build-test packages Yann E. MORIN
2017-02-08 20:15 ` [Buildroot] [PATCH 1/6] support/scripts: add script to test a package Yann E. MORIN
2017-02-08 22:00 ` Cam Hutchison [this message]
2017-02-08 22:39 ` Cam Hutchison
2017-02-11 16:08 ` Yann E. MORIN
2017-02-11 21:19 ` Thomas De Schampheleire
2017-02-11 22:28 ` Yann E. MORIN
2017-02-09 13:41 ` Luca Ceresoli
2017-02-09 21:50 ` Thomas Petazzoni
2017-02-09 22:00 ` Yann E. MORIN
2017-02-09 21:51 ` Thomas Petazzoni
2017-02-08 20:15 ` [Buildroot] [PATCH 2/6] support/test-pkg: store lines missing from resulting configuraiton Yann E. MORIN
2017-02-09 17:07 ` Luca Ceresoli
2017-02-09 21:58 ` Thomas Petazzoni
2017-02-08 20:15 ` [Buildroot] [PATCH 3/6] support/test-pkg: report number and types of failures Yann E. MORIN
2017-02-09 17:09 ` Luca Ceresoli
2017-02-09 21:59 ` Thomas Petazzoni
2017-02-11 19:48 ` Thomas De Schampheleire
2017-02-11 22:21 ` Yann E. MORIN
2017-02-08 20:15 ` [Buildroot] [PATCH 4/6] supprt/test-pkg: add option to limit the number of tests Yann E. MORIN
2017-02-09 22:13 ` Thomas Petazzoni
2017-02-08 20:15 ` [Buildroot] [PATCH 5/6] support/test-pkg: add option to use an alternate list of toolchains Yann E. MORIN
2017-02-11 19:53 ` Thomas De Schampheleire
2017-02-11 22:24 ` Yann E. MORIN
2017-02-08 20:15 ` [Buildroot] [PATCH 6/6] support/test-pkg: print number of toolchain and progress Yann E. MORIN
2017-02-11 20:09 ` Thomas De Schampheleire
2017-02-11 22:25 ` Yann E. MORIN
2017-02-12 6:40 ` Thomas De Schampheleire
2017-02-12 9:33 ` Yann E. MORIN
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=70e8.589b94e3.db816@xdna.net \
--to=camh@xdna.net \
--cc=buildroot@busybox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox