go-ptest.bbclass 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. inherit go ptest
  2. do_compile_ptest_base() {
  3. export TMPDIR="${GOTMPDIR}"
  4. rm -f ${B}/.go_compiled_tests.list
  5. go_list_package_tests | while read pkg; do
  6. cd ${B}/src/$pkg
  7. ${GO} test ${GOPTESTBUILDFLAGS} $pkg
  8. find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \
  9. sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list
  10. done
  11. do_compile_ptest
  12. }
  13. do_compile_ptest_base[dirs] =+ "${GOTMPDIR}"
  14. go_make_ptest_wrapper() {
  15. cat >${D}${PTEST_PATH}/run-ptest <<EOF
  16. #!/bin/sh
  17. RC=0
  18. run_test() (
  19. cd "\$1"
  20. ((((./\$2 ${GOPTESTFLAGS}; echo \$? >&3) | sed -r -e"s,^(PASS|SKIP|FAIL)\$,\\1: \$1/\$2," >&4) 3>&1) | (read rc; exit \$rc)) 4>&1
  21. exit \$?)
  22. EOF
  23. }
  24. do_install_ptest_base() {
  25. test -f "${B}/.go_compiled_tests.list" || exit 0
  26. install -d ${D}${PTEST_PATH}
  27. go_stage_testdata
  28. go_make_ptest_wrapper
  29. havetests=""
  30. while read test; do
  31. testdir=`dirname $test`
  32. testprog=`basename $test`
  33. install -d ${D}${PTEST_PATH}/$testdir
  34. install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test
  35. echo "run_test $testdir $testprog || RC=1" >> ${D}${PTEST_PATH}/run-ptest
  36. havetests="yes"
  37. done < ${B}/.go_compiled_tests.list
  38. if [ -n "$havetests" ]; then
  39. echo "exit \$RC" >> ${D}${PTEST_PATH}/run-ptest
  40. chmod +x ${D}${PTEST_PATH}/run-ptest
  41. else
  42. rm -rf ${D}${PTEST_PATH}
  43. fi
  44. do_install_ptest
  45. chown -R root:root ${D}${PTEST_PATH}
  46. }
  47. INSANE_SKIP_${PN}-ptest += "ldflags"