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