]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/testsanitizers: add test case for #66427
authorCherry Mui <cherryyz@google.com>
Fri, 26 Apr 2024 19:39:14 +0000 (15:39 -0400)
committerCherry Mui <cherryyz@google.com>
Mon, 6 May 2024 21:14:49 +0000 (21:14 +0000)
The added program fails consistently with "signal handler spoils
errno" error under TSAN.

For #66427.

Change-Id: Id57b9e62aa30b273a1c793aecd86ec1f211062fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/581722
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/cgo/internal/testsanitizers/testdata/tsan15.go [new file with mode: 0644]
src/cmd/cgo/internal/testsanitizers/tsan_test.go

diff --git a/src/cmd/cgo/internal/testsanitizers/testdata/tsan15.go b/src/cmd/cgo/internal/testsanitizers/testdata/tsan15.go
new file mode 100644 (file)
index 0000000..994db52
--- /dev/null
@@ -0,0 +1,60 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+// Test case for issue 66427.
+// Running under TSAN, this fails with "signal handler
+// spoils errno".
+
+/*
+#include <pthread.h>
+#include <signal.h>
+#include <stdlib.h>
+
+void go_callback();
+
+static void *thr(void *arg) {
+       int i;
+       for (i = 0; i < 10; i++)
+               go_callback();
+       return 0;
+}
+
+static void *sendthr(void *arg) {
+       pthread_t th = *(pthread_t*)arg;
+       while (1) {
+               int r = pthread_kill(th, SIGWINCH);
+               if (r < 0)
+                       break;
+       }
+       return 0;
+}
+
+static void foo() {
+       pthread_t *th = malloc(sizeof(pthread_t));
+       pthread_t th2;
+       pthread_create(th, 0, thr, 0);
+       pthread_create(&th2, 0, sendthr, th);
+       pthread_join(*th, 0);
+}
+*/
+import "C"
+
+import (
+       "time"
+)
+
+//export go_callback
+func go_callback() {}
+
+func main() {
+       go func() {
+               for {
+                       C.foo()
+               }
+       }()
+
+       time.Sleep(1000 * time.Millisecond)
+}
index 8e758e6ea7c85819131ebb99aa3309a35e08c0df..94c00ef7f4804bc19794c13f99a4da1572b85fdd 100644 (file)
@@ -54,6 +54,7 @@ func TestTSAN(t *testing.T) {
                {src: "tsan12.go", needsRuntime: true},
                {src: "tsan13.go", needsRuntime: true},
                {src: "tsan14.go", needsRuntime: true},
+               {src: "tsan15.go", needsRuntime: true},
        }
        for _, tc := range cases {
                tc := tc