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