[Buildroot] [PATCH] support/scripts: add script to test a package

Yann E. MORIN yann.morin.1998 at free.fr
Mon Feb 6 18:02:53 UTC 2017


This script helps in testing that a pacakge 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 at 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 at free.fr>
Cc: Luca Ceresoli <luca at lucaceresoli.net>
---
 support/scripts/test-pkg | 158 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 158 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..40b373e
--- /dev/null
+++ b/support/scripts/test-pkg
@@ -0,0 +1,158 @@
+#!/bin/bash
+set -e
+
+TOOLCHAINS_BASE_URL='http://autobuild.buildroot.org/toolchains/configs'
+
+main() {
+    local o O opts
+    local cfg dir pkg toolchain out
+    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>&1; exit 1
+    fi
+    if [ -z "${dir}" ]; then
+        dir="${HOME}/br-test-pkg"
+    fi
+
+    # Extract the toolchains names
+    toolchains=( $( curl -s "${TOOLCHAINS_BASE_URL}/toolchain-configs.csv" \
+                    |sed -r -e 's/,.*//; s:.*/(.*)\.config:\1:; /internal/d;'
+                  )
+               )
+
+    if [ ${#toolchains[@]} -eq 0 ]; then
+        printf "error: no toolchain found (networking issue?)\n" 2>&1; exit 1
+    fi
+
+    for toolchain in "${toolchains[@]}"; do
+        build_one "${dir}" "${toolchain}" "${cfg}" "${pkg}"
+    done
+}
+
+build_one() {
+    local dir="${1}"
+    local tc="${2}"
+    local cfg="${3}"
+    local pkg="${4}"
+    local line
+
+    printf "%40s: " "${tc}"
+
+    dir="${dir}/${tc}"
+    mkdir -p "${dir}"
+
+    printf "download config"
+    if ! curl -s "${TOOLCHAINS_BASE_URL}/${toolchain}.config" >"${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
+    while read line; do
+        if ! grep "^${line}\$" "${dir}/.config" >/dev/null 2>&1; then
+            printf ", SKIPPED\n"
+            return
+        fi
+    done <"${cfg}"
+
+    printf ", source"
+    if ! make O=${dir} source >> ${dir}/logfile 2>&1; then
+        printf ": FAILED\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"
+    if ! make O=${dir} ${pkg} >> ${dir}/logfile 2>&1; then
+        printf ": FAILED\n"
+        return
+    fi
+
+    printf ": OK\n"
+}
+
+help() {
+    cat <<_EOF_
+${my_name}: test that a package builds with various toolchains and archs
+
+${my_name} will test-build a package (as specified in a .config snippet)
+against various toolchains on different architectures.
+
+The list of toolchains is retrieved from Buidlroot autobuilders.
+
+In case failures are noticed, you have the opportunity to fix the issue
+and relaunch the test.
+
+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.
+
+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



More information about the buildroot mailing list