summaryrefslogtreecommitdiffstats
path: root/meta/classes/go.bbclass
diff options
context:
space:
mode:
authorMatt Madison <matt@madison.systems>2018-03-04 13:09:30 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-03-06 06:43:10 -0800
commit13fd7abbe088dba1882e158270ef44a9b0c47f8e (patch)
tree4602011b1769c1b7e8f673c5a000b2fa5051eb9b /meta/classes/go.bbclass
parent02b8eae8c7fc56c5047372e326f42500e9bbe13e (diff)
downloadpoky-13fd7abbe088dba1882e158270ef44a9b0c47f8e.tar.gz
go.bbclass: ptest cleanup and improvements
* Don't enable verbose test output (-test.v) by default, as it generates too much noise for automated results parsing * Override do_install_ptest_base in the bbclass, so recipes can provide their own modifications with do_install_ptest. * Improve the generated run-ptest script to better handle large numbers of tests, and to generate 'status: test name' output similar to Automake tests. * Install all non-vendored 'testdata' directories from the source into the ptest package, as some packages share test data among multiple tests. (From OE-Core rev: 11037462d80cefbee90a69e6a8a95895375ed6da) Signed-off-by: Matt Madison <matt@madison.systems> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/go.bbclass')
-rw-r--r--meta/classes/go.bbclass87
1 files changed, 51 insertions, 36 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass
index afd68b5951..a51ba3e9f0 100644
--- a/meta/classes/go.bbclass
+++ b/meta/classes/go.bbclass
@@ -26,7 +26,7 @@ GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} -extldflags '${GO_EXTLDFLAGS
26export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" 26export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}"
27export GOPATH_OMIT_IN_ACTIONID ?= "1" 27export GOPATH_OMIT_IN_ACTIONID ?= "1"
28export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" 28export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
29export GOPTESTFLAGS ?= "-test.v" 29export GOPTESTFLAGS ?= ""
30GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} " 30GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} "
31 31
32export GO = "${HOST_PREFIX}go" 32export GO = "${HOST_PREFIX}go"
@@ -76,7 +76,7 @@ go_list_packages() {
76} 76}
77 77
78go_list_package_tests() { 78go_list_package_tests() {
79 ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ 79 ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
80 grep -v '\[\]$' | \ 80 grep -v '\[\]$' | \
81 egrep -v '${GO_INSTALL_FILTEROUT}' | \ 81 egrep -v '${GO_INSTALL_FILTEROUT}' | \
82 awk '{ print $1 }' 82 awk '{ print $1 }'
@@ -100,15 +100,16 @@ go_do_compile() {
100do_compile[dirs] =+ "${GOTMPDIR}" 100do_compile[dirs] =+ "${GOTMPDIR}"
101do_compile[cleandirs] = "${B}/bin ${B}/pkg" 101do_compile[cleandirs] = "${B}/bin ${B}/pkg"
102 102
103do_compile_ptest() { 103do_compile_ptest_base() {
104 export TMPDIR="${GOTMPDIR}" 104 export TMPDIR="${GOTMPDIR}"
105 rm -f ${B}/.go_compiled_tests.list 105 rm -f ${B}/.go_compiled_tests.list
106 go_list_package_tests | while read pkg; do 106 go_list_package_tests | while read pkg; do
107 cd ${B}/src/$pkg 107 cd ${B}/src/$pkg
108 ${GO} test ${GOPTESTBUILDFLAGS} $pkg 108 ${GO} test ${GOPTESTBUILDFLAGS} $pkg
109 find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \ 109 find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \
110 sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list 110 sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list
111 done 111 done
112 do_compile_ptest
112} 113}
113do_compile_ptest_base[dirs] =+ "${GOTMPDIR}" 114do_compile_ptest_base[dirs] =+ "${GOTMPDIR}"
114 115
@@ -124,40 +125,54 @@ go_do_install() {
124 fi 125 fi
125} 126}
126 127
127do_install_ptest_base() { 128go_make_ptest_wrapper() {
128 test -f "${B}/.go_compiled_tests.list" || exit 0 129 cat >${D}${PTEST_PATH}/run-ptest <<EOF
129 tests=""
130 while read test; do
131 tests="$tests${tests:+ }${test%.test}"
132 testdir=`dirname $test`
133 install -d ${D}${PTEST_PATH}/$testdir
134 install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test
135 if [ -d "${B}/src/$testdir/testdata" ]; then
136 cp --preserve=mode,timestamps -R "${B}/src/$testdir/testdata" ${D}${PTEST_PATH}/$testdir
137 fi
138 done < ${B}/.go_compiled_tests.list
139 if [ -n "$tests" ]; then
140 install -d ${D}${PTEST_PATH}
141 cat >${D}${PTEST_PATH}/run-ptest <<EOF
142#!/bin/sh 130#!/bin/sh
143ANYFAILED=0 131RC=0
144for t in $tests; do 132run_test() (
145 testdir=\`dirname \$t.test\` 133 cd "\$1"
146 if ( cd "${PTEST_PATH}/\$testdir"; "${PTEST_PATH}/\$t.test" ${GOPTESTFLAGS} | tee /dev/fd/9 | grep -q "^FAIL" ) 9>&1; then 134 ((((./\$2 ${GOPTESTFLAGS}; echo \$? >&3) | sed -r -e"s,^(PASS|SKIP|FAIL)\$,\\1: \$1/\$2," >&4) 3>&1) | (read rc; exit \$rc)) 4>&1
147 ANYFAILED=1 135 exit \$?)
148 fi
149done
150if [ \$ANYFAILED -ne 0 ]; then
151 echo "FAIL: ${PN}"
152 exit 1
153fi
154echo "PASS: ${PN}"
155exit 0
156EOF 136EOF
157 chmod +x ${D}${PTEST_PATH}/run-ptest 137
158 else 138}
159 rm -rf ${D}${PTEST_PATH} 139
160 fi 140go_stage_testdata() {
141 oldwd="$PWD"
142 cd ${S}/src
143 find ${GO_IMPORT} -depth -type d -name testdata | while read d; do
144 if echo "$d" | grep -q '/vendor/'; then
145 continue
146 fi
147 parent=`dirname $d`
148 install -d ${D}${PTEST_PATH}/$parent
149 cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/
150 done
151 cd "$oldwd"
152}
153
154do_install_ptest_base() {
155 test -f "${B}/.go_compiled_tests.list" || exit 0
156 install -d ${D}${PTEST_PATH}
157 go_stage_testdata
158 go_make_ptest_wrapper
159 havetests=""
160 while read test; do
161 testdir=`dirname $test`
162 testprog=`basename $test`
163 install -d ${D}${PTEST_PATH}/$testdir
164 install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test
165 echo "run_test $testdir $testprog || RC=1" >> ${D}${PTEST_PATH}/run-ptest
166 havetests="yes"
167 done < ${B}/.go_compiled_tests.list
168 if [ -n "$havetests" ]; then
169 echo "exit \$RC" >> ${D}${PTEST_PATH}/run-ptest
170 chmod +x ${D}${PTEST_PATH}/run-ptest
171 else
172 rm -rf ${D}${PTEST_PATH}
173 fi
174 do_install_ptest
175 chown -R root:root ${D}${PTEST_PATH}
161} 176}
162 177
163EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install 178EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install