board/csky: fixup gdb instructions in readme.txt
[buildroot-gz.git] / support / scripts / test-pkg
blob0e7779de49acd6c535b374ed9ddcee9ec611a055
1 #!/bin/bash
2 set -e
4 TOOLCHAINS_URL='http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'
6 main() {
7 local o O opts
8 local cfg dir pkg random toolchain
9 local ret nb nb_skip nb_fail
10 local -a toolchains
12 o='hc:d:p:r:'
13 O='help,config-snippet:build-dir:package:,random:'
14 opts="$(getopt -n "${my_name}" -o "${o}" -l "${O}" -- "${@}")"
15 eval set -- "${opts}"
17 random=0
18 while [ ${#} -gt 0 ]; do
19 case "${1}" in
20 (-h|--help)
21 help; exit 0
23 (-c|--config-snippet)
24 cfg="${2}"; shift 2
26 (-d|--build-dir)
27 dir="${2}"; shift 2
29 (-p|--package)
30 pkg="${2}"; shift 2
32 (-r|--random)
33 random="${2}"; shift 2
35 (--)
36 shift; break
38 esac
39 done
40 if [ -z "${cfg}" ]; then
41 printf "error: no config snippet specified\n" >&2; exit 1
43 if [ ! -e "${cfg}" ]; then
44 printf "error: %s: no such file\n" "${cfg}" >&2; exit 1
46 if [ -z "${dir}" ]; then
47 dir="${HOME}/br-test-pkg"
50 # Extract the URLs of the toolchains; drop internal toolchains
51 # E.g.: http://server/path/to/name.config,arch,libc
52 # --> http://server/path/to/name.config
53 toolchains=($(curl -s "${TOOLCHAINS_URL}" \
54 |sed -r -e 's/,.*//; /internal/d;' \
55 |if [ ${random} -gt 0 ]; then \
56 sort -R |head -n ${random}
57 else
58 cat
59 fi |sort
63 if [ ${#toolchains[@]} -eq 0 ]; then
64 printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
67 nb=0
68 nb_skip=0
69 nb_fail=0
70 for toolchain in "${toolchains[@]}"; do
71 build_one "${dir}" "${toolchain}" "${cfg}" "${pkg}" && ret=0 || ret=${?}
72 case ${ret} in
73 (0) ;;
74 (1) : $((nb_skip++));;
75 (2) : $((nb_fail++));;
76 esac
77 : $((nb++))
78 done
80 printf "%d builds, %d skipped, %d failed\n" ${nb} ${nb_skip} ${nb_fail}
83 build_one() {
84 local dir="${1}"
85 local url="${2}"
86 local cfg="${3}"
87 local pkg="${4}"
88 local toolchain
90 # Using basename(1) on a URL works nicely
91 toolchain="$(basename "${url}" .config)"
93 printf "%40s: " "${toolchain}"
95 dir="${dir}/${toolchain}"
96 mkdir -p "${dir}"
98 if ! curl -s "${url}" >"${dir}/.config"; then
99 printf "FAILED\n"
100 return 2
103 cat >>"${dir}/.config" <<-_EOF_
104 BR2_INIT_NONE=y
105 BR2_SYSTEM_BIN_SH_NONE=y
106 # BR2_PACKAGE_BUSYBOX is not set
107 # BR2_TARGET_ROOTFS_TAR is not set
108 _EOF_
109 cat "${cfg}" >>"${dir}/.config"
111 if ! make O="${dir}" olddefconfig > "${dir}/logfile" 2>&1; then
112 printf "FAILED\n"
113 return 2
115 # We want all the options from the snippet to be present as-is (set
116 # or not set) in the actual .config; if one of them is not, it means
117 # some dependency from the toolchain or arch is not available, in
118 # which case this config is untestable and we skip it.
119 # We don't care about the locale to sort in, as long as both sort are
120 # done in the same locale.
121 comm -23 <(sort "${cfg}") <(sort "${dir}/.config") >"${dir}/missing.config"
122 if [ -s "${dir}/missing.config" ]; then
123 printf "SKIPPED\n"
124 return 1
126 # Remove file, it's empty anyway.
127 rm -f "${dir}/missing.config"
129 if [ -n "${pkg}" ]; then
130 if ! make O="${dir}" "${pkg}-dirclean" >> "${dir}/logfile" 2>&1; then
131 printf "FAILED\n"
132 return 2
136 # shellcheck disable=SC2086
137 if ! make O="${dir}" ${pkg} >> "${dir}/logfile" 2>&1; then
138 printf "FAILED\n"
139 return 2
142 printf "OK\n"
145 help() {
146 cat <<_EOF_
147 test-pkg: test-build a package against various toolchains and architectures
149 The supplied config snippet is appended to each toolchain config, the
150 resulting configuration is checked to ensure it still contains all options
151 specified in the snippet; if any is missing, the build is skipped, on the
152 assumption that the package under test requires a toolchain or architecture
153 feature that is missing.
155 In case failures are noticed, you can fix the package and just re-run the
156 same command again; it will re-run the test where it failed. If you did
157 specify a package (with -p), the package build dir will be removed first.
159 The list of toolchains is retrieved from the Buildroot autobuilders, available
160 at ${TOOLCHAINS_URL}.
162 Options:
164 -h, --help
165 Print this help.
167 -c CFG, --config-snippet CFG
168 Use the CFG file as the source for the config snippet. This file
169 should contain all the config options required to build a package.
171 -d DIR, --build-dir DIR
172 Do the builds in directory DIR, one sub-dir per toolchain.
174 -p PKG, --package PKG
175 Test-build the package PKG, by running 'make PKG'; if not specified,
176 just runs 'make'.
178 -r N, --random N
179 Limit the tests to the N randomly selected toolchains, instead of
180 building with all toolchains.
182 Example:
184 Testing libcec would require a config snippet that contains:
185 BR2_PACKAGE_LIBCEC=y
187 Testing libcurl with openSSL support would require a snippet such as:
188 BR2_PACKAGE_OPENSSL=y
189 BR2_PACKAGE_LIBCURL=y
191 _EOF_
194 my_name="${0##*/}"
195 main "${@}"