msan_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2017 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package sanitizers_test
  5. import (
  6. "strings"
  7. "testing"
  8. )
  9. func TestMSAN(t *testing.T) {
  10. goos, err := goEnv("GOOS")
  11. if err != nil {
  12. t.Fatal(err)
  13. }
  14. goarch, err := goEnv("GOARCH")
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. // The msan tests require support for the -msan option.
  19. if !mSanSupported(goos, goarch) {
  20. t.Skipf("skipping on %s/%s; -msan option is not supported.", goos, goarch)
  21. }
  22. t.Parallel()
  23. requireOvercommit(t)
  24. config := configure("memory")
  25. config.skipIfCSanitizerBroken(t)
  26. mustRun(t, config.goCmd("build", "std"))
  27. cases := []struct {
  28. src string
  29. wantErr bool
  30. }{
  31. {src: "msan.go"},
  32. {src: "msan2.go"},
  33. {src: "msan2_cmsan.go"},
  34. {src: "msan3.go"},
  35. {src: "msan4.go"},
  36. {src: "msan5.go"},
  37. {src: "msan6.go"},
  38. {src: "msan7.go"},
  39. {src: "msan8.go"},
  40. {src: "msan_fail.go", wantErr: true},
  41. }
  42. for _, tc := range cases {
  43. tc := tc
  44. name := strings.TrimSuffix(tc.src, ".go")
  45. t.Run(name, func(t *testing.T) {
  46. t.Parallel()
  47. dir := newTempDir(t)
  48. defer dir.RemoveAll(t)
  49. outPath := dir.Join(name)
  50. mustRun(t, config.goCmd("build", "-o", outPath, srcPath(tc.src)))
  51. cmd := hangProneCmd(outPath)
  52. if tc.wantErr {
  53. out, err := cmd.CombinedOutput()
  54. if err != nil {
  55. return
  56. }
  57. t.Fatalf("%#q exited without error; want MSAN failure\n%s", strings.Join(cmd.Args, " "), out)
  58. }
  59. mustRun(t, cmd)
  60. })
  61. }
  62. }