test-pkg 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/usr/bin/env bash
  2. set -e
  3. TOOLCHAINS_CSV='support/config-fragments/autobuild/toolchain-configs.csv'
  4. main() {
  5. local o O opts
  6. local cfg dir pkg random toolchains_dir toolchain
  7. local ret nb nb_skip nb_fail nb_legal nb_tc build_dir
  8. local -a toolchains
  9. o='hc:d:p:r:t:'
  10. O='help,config-snippet:build-dir:package:,random:,toolchains-dir:'
  11. opts="$(getopt -n "${my_name}" -o "${o}" -l "${O}" -- "${@}")"
  12. eval set -- "${opts}"
  13. random=0
  14. toolchains_csv="${TOOLCHAINS_CSV}"
  15. while [ ${#} -gt 0 ]; do
  16. case "${1}" in
  17. (-h|--help)
  18. help; exit 0
  19. ;;
  20. (-c|--config-snippet)
  21. cfg="${2}"; shift 2
  22. ;;
  23. (-d|--build-dir)
  24. dir="${2}"; shift 2
  25. ;;
  26. (-p|--package)
  27. pkg="${2}"; shift 2
  28. ;;
  29. (-r|--random)
  30. random="${2}"; shift 2
  31. ;;
  32. (-t|--toolchains-csv)
  33. toolchains_csv="${2}"; shift 2
  34. ;;
  35. (--)
  36. shift; break
  37. ;;
  38. esac
  39. done
  40. if [ -z "${cfg}" ]; then
  41. printf "error: no config snippet specified\n" >&2; exit 1
  42. fi
  43. if [ ! -e "${cfg}" ]; then
  44. printf "error: %s: no such file\n" "${cfg}" >&2; exit 1
  45. fi
  46. if [ -z "${dir}" ]; then
  47. dir="${HOME}/br-test-pkg"
  48. fi
  49. # Extract the URLs of the toolchains; drop internal toolchains
  50. # E.g.: http://server/path/to/name.config,arch,libc
  51. # --> http://server/path/to/name.config
  52. toolchains=($(sed -r -e 's/,.*//; /internal/d;' "${toolchains_csv}" \
  53. |if [ ${random} -gt 0 ]; then \
  54. sort -R |head -n ${random}
  55. else
  56. cat
  57. fi |sort
  58. )
  59. )
  60. nb_tc="${#toolchains[@]}"
  61. if [ ${nb_tc} -eq 0 ]; then
  62. printf "error: no toolchain found (networking issue?)\n" >&2; exit 1
  63. fi
  64. nb=0
  65. nb_skip=0
  66. nb_fail=0
  67. nb_legal=0
  68. for toolchainconfig in "${toolchains[@]}"; do
  69. : $((nb++))
  70. toolchain="$(basename "${toolchainconfig}" .config)"
  71. build_dir="${dir}/${toolchain}"
  72. printf "%40s [%*d/%d]: " "${toolchain}" ${#nb_tc} ${nb} ${nb_tc}
  73. build_one "${build_dir}" "${toolchainconfig}" "${cfg}" "${pkg}" && ret=0 || ret=${?}
  74. case ${ret} in
  75. (0) printf "OK\n";;
  76. (1) : $((nb_skip++)); printf "SKIPPED\n";;
  77. (2) : $((nb_fail++)); printf "FAILED\n";;
  78. (3) : $((nb_legal++)); printf "FAILED\n";;
  79. esac
  80. done
  81. printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
  82. ${nb} ${nb_skip} ${nb_fail} ${nb_legal}
  83. }
  84. build_one() {
  85. local dir="${1}"
  86. local toolchainconfig="${2}"
  87. local cfg="${3}"
  88. local pkg="${4}"
  89. mkdir -p "${dir}"
  90. support/kconfig/merge_config.sh -O "${dir}" \
  91. "${toolchainconfig}" "support/config-fragments/minimal.config" "${cfg}" \
  92. > /dev/null
  93. # We want all the options from the snippet to be present as-is (set
  94. # or not set) in the actual .config; if one of them is not, it means
  95. # some dependency from the toolchain or arch is not available, in
  96. # which case this config is untestable and we skip it.
  97. # We don't care about the locale to sort in, as long as both sort are
  98. # done in the same locale.
  99. comm -23 <(sort "${cfg}") <(sort "${dir}/.config") >"${dir}/missing.config"
  100. if [ -s "${dir}/missing.config" ]; then
  101. return 1
  102. fi
  103. # Remove file, it's empty anyway.
  104. rm -f "${dir}/missing.config"
  105. if [ -n "${pkg}" ]; then
  106. if ! make O="${dir}" "${pkg}-dirclean" >> "${dir}/logfile" 2>&1; then
  107. return 2
  108. fi
  109. fi
  110. # shellcheck disable=SC2086
  111. if ! make O="${dir}" ${pkg} >> "${dir}/logfile" 2>&1; then
  112. return 2
  113. fi
  114. # legal-info done systematically, because some packages have different
  115. # sources depending on the configuration (e.g. lua-5.2 vs. lua-5.3)
  116. if [ -n "${pkg}" ]; then
  117. if ! make O="${dir}" "${pkg}-legal-info" >> "${dir}/logfile" 2>&1; then
  118. return 3
  119. fi
  120. fi
  121. }
  122. help() {
  123. cat <<_EOF_
  124. test-pkg: test-build a package against various toolchains and architectures
  125. The supplied config snippet is appended to each toolchain config, the
  126. resulting configuration is checked to ensure it still contains all options
  127. specified in the snippet; if any is missing, the build is skipped, on the
  128. assumption that the package under test requires a toolchain or architecture
  129. feature that is missing.
  130. In case failures are noticed, you can fix the package and just re-run the
  131. same command again; it will re-run the test where it failed. If you did
  132. specify a package (with -p), the package build dir will be removed first.
  133. The list of toolchains is retrieved from ${TOOLCHAINS_CSV}.
  134. Only the external toolchains are tried, because building a Buildroot toolchain
  135. would take too long. An alternative toolchains CSV file can be specified with
  136. the -t option. This file should have lines consisting of the path to the
  137. toolchain config fragment and the required host architecture, separated by a
  138. comma. The config fragments should contain only the toolchain and architecture
  139. settings.
  140. Options:
  141. -h, --help
  142. Print this help.
  143. -c CFG, --config-snippet CFG
  144. Use the CFG file as the source for the config snippet. This file
  145. should contain all the config options required to build a package.
  146. -d DIR, --build-dir DIR
  147. Do the builds in directory DIR, one sub-dir per toolchain.
  148. -p PKG, --package PKG
  149. Test-build the package PKG, by running 'make PKG'; if not specified,
  150. just runs 'make'.
  151. -r N, --random N
  152. Limit the tests to the N randomly selected toolchains, instead of
  153. building with all toolchains.
  154. -t CSVFILE, --toolchains-csv CSVFILE
  155. CSV file containing the paths to config fragments of toolchains to
  156. try. If not specified, the toolchains in ${TOOLCHAINS_CSV} will be
  157. used.
  158. Example:
  159. Testing libcec would require a config snippet that contains:
  160. BR2_PACKAGE_LIBCEC=y
  161. Testing libcurl with openSSL support would require a snippet such as:
  162. BR2_PACKAGE_OPENSSL=y
  163. BR2_PACKAGE_LIBCURL=y
  164. _EOF_
  165. }
  166. my_name="${0##*/}"
  167. main "${@}"