cmd/go: test -coverprofile option causes test to panic

ttcibm8c  于 4个月前  发布在  Go
关注(0)|答案(1)|浏览(37)

你正在使用哪个版本的Go( go version )?

$ go version
go version go1.14.4 linux/amd64

同时测试了1.14.9和1.15.2,都失败了。

这个问题在最新版本中是否重现?

是的。

你正在使用什么操作系统和处理器架构( go env )?

go env 输出

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/github.com/kubeedge/kubedge/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build657190380=/tmp/go-build -gno-record-gcc-switches"

你做了什么?

为了获取coverfile,我为go test添加了一个选项,然后go test失败了:

root@70bbf38bedaf:/go/src/github.com/kubeedge/kubedge# git show
commit 791d503c74b9cdfe2c43a54ad3286fe12ff10d1e (HEAD -> master, origin/master, origin/HEAD)
Author: Xiang Dai <long0dai@foxmail.com>
Date:   Fri Sep 11 16:07:09 2020 +0800

    Generate coverprofile when test

    Signed-off-by: Xiang Dai <long0dai@foxmail.com>

diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 14d530a9..d8bcc57d 100644
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -434,5 +434,5 @@ kubeedge::golang::run_test() {
     testdirs+=("${KUBEEDGE_ALL_TESTCASES[@]}")
   fi

-  go test ${testdirs[@]}
+  go test -coverprofile=coverprofile.cov ${testdirs[@]}
 }
root@70bbf38bedaf:/go/src/github.com/kubeedge/kubedge# make test
hack/make-rules/clean.sh
hack/make-rules/test.sh
running tests cases
ok  	github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/model	0.009s	coverage: 96.3% of statements
ok  	github.com/kubeedge/kubeedge/cloud/pkg/edgecontroller/manager	0.027s	coverage: 26.4% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin	0.019s	coverage: 82.2% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dttype	0.027s	coverage: 95.4% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtmodule	0.019s	coverage: 55.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtclient	0.028s	coverage: 96.1% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcontext	0.013s	coverage: 93.8% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtmanager	51.048s	coverage: 85.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/devicetwin/dtcommon	0.014s	coverage: 100.0% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/metamanager/dao	0.011s	coverage: 100.0% of statements
PASS
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0xb75749]

goroutine 12 [running]:
github.com/kubeedge/kubeedge/edge/pkg/metamanager/dao.QueryAllMeta(0xd6e86a, 0x4, 0xd70d24, 0x9, 0x0, 0x0, 0x0)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/dao/meta.go:97 +0x49
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).syncPodStatus(0xc00003d418)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:516 +0xa9
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).processSync(...)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:511
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).process(0xc00003d418, 0xc000040e40, 0x24, 0x0, 0x0, 0x17499ee0ec9, 0x0, 0x0, 0x0, 0xd722e4, ...)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:646 +0x50b
github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).runMetaManager.func1(0xc00003d418)
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:670 +0x318
created by github.com/kubeedge/kubeedge/edge/pkg/metamanager.(*metaManager).runMetaManager
	/go/src/github.com/kubeedge/kubedge/edge/pkg/metamanager/process.go:660 +0x49
FAIL	github.com/kubeedge/kubeedge/edge/pkg/metamanager	0.009s
ok  	github.com/kubeedge/kubeedge/edge/pkg/servicebus/util	0.021s	coverage: 60.6% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/eventbus/common/util	0.019s	coverage: 65.9% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub/clients/wsclient	0.190s	coverage: 3.0% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub/common/http	0.071s	coverage: 36.7% of statements
ok  	github.com/kubeedge/kubeedge/edge/pkg/edgehub	24.017s	coverage: 60.6% of statements
ok  	github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/util	0.010s	coverage: 1.1% of statements
FAIL
make: *** [Makefile:91: test] Error 1

重现:

$ docker run -it golang:1.14 bash
$ go get github.com/daixiang0/kubeedge
$ cd /go/src/github.com/daixiang0/kubeedge
$ make test

你期望看到什么?

测试通过。

你实际上看到了什么?

测试失败。
如果恢复这个更改,测试通过。
我在做这件事的时候查阅了文档,但没有得到任何有用的信息:(

相关问题