12c7a05da1
The gitlab-ci support in test-pkg allows to parallelize the test-pkg work into several gitlab jobs. It's much faster than local serialized testing. To trigger this, a developer will have to add, in the latest commit of their branch, a token on its own line, followed by a configuration fragment, e.g.: test-pkg config: SOME_OPTION=y # OTHER_OPTION is not set SOME_VARIABLE="some value" This configuration fragment is used as input to test-pkg. To be able to generate one job per test to run, we need the list of tests in the parent pipeline, and the individual .config files (one per test) in the child pipeline. We use the newly-introduced --prepare-only mode to test-pkg, and collect all the generated .config files as artefacts; those are inherited in the child pipeline via the "needs::pipeline" and "needs::job" directives. This is a bit tricky, and is best described by the Gitlab-CI documentation [0]. We also list those .config files to generate the actual list of jobs to run in the child pipeline. Notes: - if the user provides an empty fragment, this is considered an error: indeed, without a fragment (and the package name), there is no way to know what to test; - if that fragment yields an empty list of tests, then there is nothing to test either, so that is also considered an error. [0] https://docs.gitlab.com/ee/ci/yaml/README.html#artifact-downloads-to-child-pipelines Signed-off-by: Romain Naour <romain.naour@gmail.com> Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be> [yann.morin.1998@free.fr: - split the change to test-pkg to its own patch - generate the actual yml snippet in support/scripts/generate-gitlab-ci-yml, listing the .config files created by test-pkg - some code-style-candies... ] Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr> Signed-off-by: Romain Naour <romain.naour@gmail.com> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
132 lines
3.5 KiB
Bash
Executable File
132 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
set -o pipefail
|
|
|
|
main() {
|
|
local template="${1}"
|
|
|
|
preamble "${template}"
|
|
gen_tests
|
|
}
|
|
|
|
preamble() {
|
|
local template="${1}"
|
|
|
|
cat - "${template}" <<-_EOF_
|
|
# This file is generated; do not edit!
|
|
# Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines
|
|
|
|
image: ${CI_JOB_IMAGE}
|
|
|
|
_EOF_
|
|
}
|
|
|
|
gen_tests() {
|
|
local -a basics defconfigs runtimes
|
|
local do_basics do_defconfigs do_runtime do_testpkg
|
|
local defconfigs_ext cfg tst
|
|
|
|
basics=( DEVELOPERS flake8 package )
|
|
|
|
defconfigs=( $(cd configs; LC_ALL=C ls -1 *_defconfig) )
|
|
|
|
runtimes=( $(./support/testing/run-tests -l 2>&1 \
|
|
| sed -r -e '/^test_run \((.*)\).*/!d; s//\1/' \
|
|
| LC_ALL=C sort)
|
|
)
|
|
|
|
if [ -n "${CI_COMMIT_TAG}" ]; then
|
|
do_basics=true
|
|
do_defconfigs=base
|
|
do_runtime=true
|
|
elif [ "${CI_PIPELINE_SOURCE}" = "trigger" ]; then
|
|
case "${BR_SCHEDULE_JOBS}" in
|
|
(basic)
|
|
do_basics=true
|
|
do_defconfigs=check
|
|
defconfigs_ext=_check
|
|
;;
|
|
(defconfig)
|
|
do_defconfigs=base
|
|
;;
|
|
(runtime)
|
|
do_runtime=true
|
|
;;
|
|
esac
|
|
else
|
|
case "${CI_COMMIT_REF_NAME}" in
|
|
(*-basics)
|
|
do_basics=true
|
|
do_defconfigs=check
|
|
defconfigs_ext=_check
|
|
;;
|
|
(*-defconfigs)
|
|
do_defconfigs=base
|
|
;;
|
|
(*-*_defconfig)
|
|
defconfigs=( "${CI_COMMIT_REF_NAME##*-}" )
|
|
do_defconfigs=base
|
|
;;
|
|
(*-runtime-tests)
|
|
do_runtime=true
|
|
;;
|
|
(*-tests.*)
|
|
runtimes=( "${CI_COMMIT_REF_NAME##*-}" )
|
|
do_runtime=true
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Retrieve defconfig for test-pkg from the git commit message (if any)
|
|
if grep -q -E '^test-pkg config:$' <<<"${CI_COMMIT_DESCRIPTION}"; then
|
|
sed -r -n -e '/^test-pkg config:$/{:a;n;p;ba;}' \
|
|
<<<"${CI_COMMIT_DESCRIPTION}" \
|
|
>defconfig.frag
|
|
if [ ! -s defconfig.frag ]; then
|
|
printf "Empty configuration fragment.\n" >&2; exit 1
|
|
fi
|
|
# Use --all since we expect the user having already pre-tested the
|
|
# new package with the default subset of toolchains.
|
|
./utils/test-pkg \
|
|
--all --prepare-only \
|
|
--config-snippet defconfig.frag \
|
|
--build-dir br-test-pkg >&2
|
|
do_testpkg=( $(ls -1 br-test-pkg/*/.config 2>/dev/null |xargs -r dirname ) )
|
|
if [ "${#do_testpkg[@]}" -eq 0 ]; then
|
|
printf "Configuration fragment enables no test.\n" >&2; exit 1
|
|
fi
|
|
fi
|
|
|
|
# If nothing else, at least do the basics to generate a valid pipeline
|
|
if [ -z "${do_defconfigs}" \
|
|
-a -z "${do_runtime}" \
|
|
-a -z "${do_testpkg}" \
|
|
]
|
|
then
|
|
do_basics=true
|
|
fi
|
|
|
|
if ${do_basics:-false}; then
|
|
for tst in "${basics[@]}"; do
|
|
printf 'check-%s: { extends: .check-%s_base }\n' "${tst}" "${tst}"
|
|
done
|
|
fi
|
|
|
|
if [ -n "${do_defconfigs}" ]; then
|
|
for cfg in "${defconfigs[@]}"; do
|
|
printf '%s%s: { extends: .defconfig_%s }\n' \
|
|
"${cfg}" "${defconfigs_ext}" "${do_defconfigs}"
|
|
done
|
|
fi
|
|
|
|
if ${do_runtime:-false}; then
|
|
printf '%s: { extends: .runtime_test_base }\n' "${runtimes[@]}"
|
|
fi
|
|
|
|
if [ -n "${do_testpkg}" ]; then
|
|
printf '%s: { extends: .test_pkg }\n' "${do_testpkg[@]}"
|
|
fi
|
|
}
|
|
|
|
main "${@}"
|