test-pkg 5.3 KB

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