]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo/internal/testsanitizers: fix TSAN tests using setarch
authorqmuntal <quimmuntal@gmail.com>
Wed, 20 Nov 2024 15:02:03 +0000 (16:02 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Wed, 20 Nov 2024 20:11:21 +0000 (20:11 +0000)
Some systems don't have permissions to run setarch, for example
when running in a docker container without the --privileged flag.

This change makes the tests skip the setarch command if it fails.

Fixes #70463

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-asan-clang15
Change-Id: I02fbd423ba809f5229b8639c9abe6fd275f32558
Reviewed-on: https://go-review.googlesource.com/c/go/+/630096
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/cgo/internal/testsanitizers/cshared_test.go
src/cmd/cgo/internal/testsanitizers/tsan_test.go

index 15409d0fca04fddc315eb3f1f6e208a68c19df4c..0cf094ead79e668968e098837f0bb340e55b27e0 100644 (file)
@@ -93,12 +93,19 @@ func TestShared(t *testing.T) {
 
                        cmdArgs := []string{dstBin}
                        if tc.sanitizer == "thread" && GOOS == "linux" {
-                               // Disable ASLR for TSAN. See #59418.
-                               arch, err := exec.Command("uname", "-m").Output()
+                               // Disable ASLR for TSAN. See https://go.dev/issue/59418.
+                               out, err := exec.Command("uname", "-m").Output()
                                if err != nil {
                                        t.Fatalf("failed to run `uname -m`: %v", err)
                                }
-                               cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", dstBin}
+                               arch := strings.TrimSpace(string(out))
+                               if _, err := exec.Command("setarch", arch, "-R", "true").Output(); err != nil {
+                                       // Some systems don't have permission to run `setarch`.
+                                       // See https://go.dev/issue/70463.
+                                       t.Logf("failed to run `setarch %s -R true`: %v", arch, err)
+                               } else {
+                                       cmdArgs = []string{"setarch", arch, "-R", dstBin}
+                               }
                        }
                        cmd = hangProneCmd(cmdArgs[0], cmdArgs[1:]...)
                        replaceEnv(cmd, "LD_LIBRARY_PATH", ".")
index 9a1924968c9434df8cf105e4f37e96ae641ef71c..265c5e3605275571e44f538c5ae55c3d1a98e45b 100644 (file)
@@ -71,12 +71,19 @@ func TestTSAN(t *testing.T) {
 
                        cmdArgs := []string{outPath}
                        if goos == "linux" {
-                               // Disable ASLR. See #59418.
-                               arch, err := exec.Command("uname", "-m").Output()
+                               // Disable ASLR for TSAN. See https://go.dev/issue/59418.
+                               out, err := exec.Command("uname", "-m").Output()
                                if err != nil {
                                        t.Fatalf("failed to run `uname -m`: %v", err)
                                }
-                               cmdArgs = []string{"setarch", strings.TrimSpace(string(arch)), "-R", outPath}
+                               arch := strings.TrimSpace(string(out))
+                               if _, err := exec.Command("setarch", arch, "-R", "true").Output(); err != nil {
+                                       // Some systems don't have permission to run `setarch`.
+                                       // See https://go.dev/issue/70463.
+                                       t.Logf("failed to run `setarch %s -R true`: %v", arch, err)
+                               } else {
+                                       cmdArgs = []string{"setarch", arch, "-R", outPath}
+                               }
                        }
                        cmd := hangProneCmd(cmdArgs[0], cmdArgs[1:]...)
                        if tc.needsRuntime {