]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/api: report error in test instead of crashing
authorRuss Cox <rsc@golang.org>
Tue, 14 Jan 2025 13:22:08 +0000 (08:22 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 14 Jan 2025 18:06:18 +0000 (10:06 -0800)
https://ci.chromium.org/ui/inv/build-8725798219051312433/test-results?sortby=&groupby=
shows a mysterious failure with this stack:

=== RUN   BenchmarkAll
BenchmarkAll
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7c497f]

goroutine 20 gp=0xc000004000 m=7 mp=0xc000182808 [running]:
panic({0x81c5e0?, 0xabc6b0?})
/home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/panic.go:806 +0x168 fp=0xc00c7ffce0 sp=0xc00c7ffc30 pc=0x4ad4c8
runtime.panicmem(...)
/home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/panic.go:262
runtime.sigpanic()
/home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/signal_unix.go:925 +0x359 fp=0xc00c7ffd40 sp=0xc00c7ffce0 pc=0x4af6d9
cmd/api.(*Walker).export(0xc000034100, 0x0)
/home/swarming/.swarming/w/ir/x/w/goroot/src/cmd/api/main_test.go:193 +0x3f fp=0xc00c7ffe08 sp=0xc00c7ffd40 pc=0x7c497f
cmd/api.BenchmarkAll(0xc000214288)
/home/swarming/.swarming/w/ir/x/w/goroot/src/cmd/api/api_test.go:205 +0x207 fp=0xc00c7ffeb0 sp=0xc00c7ffe08 pc=0x7c1c07
testing.(*B).runN(0xc000214288, 0x1)
/home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:202 +0x291 fp=0xc00c7fff78 sp=0xc00c7ffeb0 pc=0x57e611
testing.(*B).run1.func1()
/home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:224 +0x7c fp=0xc00c7fffe0 sp=0xc00c7fff78 pc=0x57f11c
runtime.goexit({})
/home/swarming/.swarming/w/ir/x/w/goroot/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc00c7fffe8 sp=0xc00c7fffe0 pc=0x4b4a61
created by testing.(*B).run1 in goroutine 1
/home/swarming/.swarming/w/ir/x/w/goroot/src/testing/benchmark.go:217 +0x173

So import_ must have returned an error, making pkg nil. Show that error.
Also do the same at the other calls to import_.

Change-Id: Ie782571c4bda3334a86b303f61969cf1cc7d3c32
Reviewed-on: https://go-review.googlesource.com/c/go/+/642438
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/cmd/api/api_test.go

index cac624af8a6530cb4285157cf3069e513fb27d7e..32da68982bce452b59f6b9aa19f1c0af77df59ff 100644 (file)
@@ -57,7 +57,10 @@ func TestGolden(t *testing.T) {
                // TODO(gri) remove extra pkg directory eventually
                goldenFile := filepath.Join("testdata", "src", "pkg", fi.Name(), "golden.txt")
                w := NewWalker(nil, "testdata/src/pkg")
-               pkg, _ := w.import_(fi.Name())
+               pkg, err := w.import_(fi.Name())
+               if err != nil {
+                       t.Fatalf("import %s: %v", fi.Name(), err)
+               }
                w.export(pkg)
 
                if *updateGolden {
@@ -205,6 +208,9 @@ func BenchmarkAll(b *testing.B) {
                                if _, nogo := err.(*build.NoGoError); nogo {
                                        continue
                                }
+                               if err != nil {
+                                       b.Fatalf("import %s (%s-%s): %v", name, context.GOOS, context.GOARCH, err)
+                               }
                                w.export(pkg)
                        }
                        w.Features()
@@ -242,8 +248,7 @@ func TestIssue21181(t *testing.T) {
                w := NewWalker(context, "testdata/src/issue21181")
                pkg, err := w.import_("p")
                if err != nil {
-                       t.Fatalf("%s: (%s-%s) %s %v", err, context.GOOS, context.GOARCH,
-                               pkg.Name(), w.imported)
+                       t.Fatalf("import %s (%s-%s): %v", "p", context.GOOS, context.GOARCH, err)
                }
                w.export(pkg)
        }