aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtavio Salvador <otavio@ossystems.com.br>2017-09-13 14:54:08 -0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-09-13 22:12:19 +0100
commit2343cd90b9706589b33510c560ed83a9648fb133 (patch)
treea398f87444435be82a6ef29cda174515ac98d85d
parent6699e668413c10704ffa8094b3dca67a9b88422a (diff)
downloadopenembedded-core-2343cd90b9706589b33510c560ed83a9648fb133.zip
openembedded-core-2343cd90b9706589b33510c560ed83a9648fb133.tar.gz
openembedded-core-2343cd90b9706589b33510c560ed83a9648fb133.tar.bz2
go.bbclass: Add ptest support
This adds ptest support for Go packages so its unittest content is packaged and integrated onto the test framework. Signed-off-by: Otavio Salvador <otavio@ossystems.com.br> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/go.bbclass62
1 files changed, 60 insertions, 2 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass
index 4af148e..33502bf 100644
--- a/meta/classes/go.bbclass
+++ b/meta/classes/go.bbclass
@@ -1,4 +1,4 @@
-inherit goarch
+inherit goarch ptest
def get_go_parallel_make(d):
pm = (d.getVar('PARALLEL_MAKE') or '').split()
@@ -39,6 +39,8 @@ GO_RPATH_LINK_class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pk
GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"'
export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}"
+export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
+export GOPTESTFLAGS ?= "-test.v"
GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} "
export GO = "${HOST_PREFIX}go"
@@ -81,6 +83,13 @@ go_list_packages() {
egrep -v '${GO_INSTALL_FILTEROUT}'
}
+go_list_package_tests() {
+ ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
+ grep -v '\[\]$' | \
+ egrep -v '${GO_INSTALL_FILTEROUT}' | \
+ awk '{ print $1 }'
+}
+
go_do_configure() {
ln -snf ${S}/src ${B}/
}
@@ -93,9 +102,19 @@ go_do_compile() {
}
do_compile[cleandirs] = "${B}/bin ${B}/pkg"
+do_compile_ptest() {
+ rm -f ${B}/.go_compiled_tests.list
+ go_list_package_tests | while read pkg; do
+ cd ${B}/src/$pkg
+ ${GO} test ${GOPTESTBUILDFLAGS} $pkg
+ find . -mindepth 1 -maxdepth 1 -type f -name '*.test' -exec echo $pkg/{} \; | \
+ sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list
+ done
+}
+
go_do_install() {
install -d ${D}${libdir}/go/src/${GO_IMPORT}
- tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs . | \
+ tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' . | \
tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf -
tar -C ${B} -cf - pkg | tar -C ${D}${libdir}/go --no-same-owner -xf -
@@ -105,9 +124,48 @@ go_do_install() {
fi
}
+do_install_ptest_base() {
+set -x
+ test -f "${B}/.go_compiled_tests.list" || exit 0
+ tests=""
+ while read test; do
+ tests="$tests${tests:+ }${test%.test}"
+ testdir=`dirname $test`
+ install -d ${D}${PTEST_PATH}/$testdir
+ install -m 0755 ${B}/src/$test ${D}${PTEST_PATH}/$test
+ if [ -d "${B}/src/$testdir/testdata" ]; then
+ cp --preserve=mode,timestamps -R "${B}/src/$testdir/testdata" ${D}${PTEST_PATH}/$testdir
+ fi
+ done < ${B}/.go_compiled_tests.list
+ if [ -n "$tests" ]; then
+ install -d ${D}${PTEST_PATH}
+ cat >${D}${PTEST_PATH}/run-ptest <<EOF
+#!/bin/sh
+ANYFAILED=0
+for t in $tests; do
+ testdir=\`dirname \$t.test\`
+ if ( cd "${PTEST_PATH}/\$testdir"; "${PTEST_PATH}/\$t.test" ${GOPTESTFLAGS} | tee /dev/fd/9 | grep -q "^FAIL" ) 9>&1; then
+ ANYFAILED=1
+ fi
+done
+if [ \$ANYFAILED -ne 0 ]; then
+ echo "FAIL: ${PN}"
+ exit 1
+fi
+echo "PASS: ${PN}"
+exit 0
+EOF
+ chmod +x ${D}${PTEST_PATH}/run-ptest
+ else
+ rm -rf ${D}${PTEST_PATH}
+ fi
+set +x
+}
+
EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install
FILES_${PN}-dev = "${libdir}/go/src"
FILES_${PN}-staticdev = "${libdir}/go/pkg"
INSANE_SKIP_${PN} += "ldflags"
+INSANE_SKIP_${PN}-ptest += "ldflags"