test-pkg 5.1 KB

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