Esempio n. 1
0
func TestRaceSignal(t *testing.T) {
	if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
		t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
	}

	testenv.MustHaveGoRun(t)

	// This test requires building various packages with -race, so
	// it's somewhat slow.
	if testing.Short() {
		t.Skip("skipping test in -short mode")
	}

	exe, err := buildTestProg(t, "testprogcgo", "-race")
	if err != nil {
		t.Fatal(err)
	}

	got, err := testEnv(exec.Command(exe, "CgoRaceSignal")).CombinedOutput()
	if err != nil {
		t.Logf("%s\n", got)
		t.Fatal(err)
	}
	want := "OK\n"
	if string(got) != want {
		t.Errorf("expected %q got %s", want, got)
	}
}
Esempio n. 2
0
func TestImports(t *testing.T) {
	testenv.MustHaveGoRun(t)

	if err := exec.Command("go", "run", "x509_test_import.go").Run(); err != nil {
		t.Errorf("failed to run x509_test_import.go: %s", err)
	}
}
Esempio n. 3
0
func testCgoPprof(t *testing.T, buildArg, runArg string) {
	if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
		t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
	}
	testenv.MustHaveGoRun(t)

	exe, err := buildTestProg(t, "testprogcgo", buildArg)
	if err != nil {
		t.Fatal(err)
	}

	got, err := testEnv(exec.Command(exe, runArg)).CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}
	fn := strings.TrimSpace(string(got))
	defer os.Remove(fn)

	top, err := exec.Command("go", "tool", "pprof", "-top", "-nodecount=1", exe, fn).CombinedOutput()
	t.Logf("%s", top)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Contains(top, []byte("cpuHog")) {
		t.Error("missing cpuHog in pprof output")
	}
}
Esempio n. 4
0
func TestConcurrentMapIterateWrite(t *testing.T) {
	if !*concurrentMapTest {
		t.Skip("skipping without -run_concurrent_map_tests")
	}
	testenv.MustHaveGoRun(t)
	output := runTestProg(t, "testprog", "concurrentMapIterateWrite")
	want := "fatal error: concurrent map iteration and map write"
	if !strings.HasPrefix(output, want) {
		t.Fatalf("output does not start with %q:\n%s", want, output)
	}
}
Esempio n. 5
0
func TestBuiltin(t *testing.T) {
	testenv.MustHaveGoRun(t)

	old, err := ioutil.ReadFile("builtin.go")
	if err != nil {
		t.Fatal(err)
	}

	new, err := exec.Command(testenv.GoToolPath(t), "run", "mkbuiltin.go", "-stdout").Output()
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Equal(old, new) {
		t.Fatal("builtin.go out of date; run mkbuiltin.go")
	}
}
Esempio n. 6
0
func testCgoPprof(t *testing.T, buildArg, runArg string) {
	if runtime.GOOS != "linux" || runtime.GOARCH != "amd64" {
		t.Skipf("not yet supported on %s/%s", runtime.GOOS, runtime.GOARCH)
	}
	testenv.MustHaveGoRun(t)

	exe, err := buildTestProg(t, "testprogcgo", buildArg)
	if err != nil {
		t.Fatal(err)
	}

	got, err := testEnv(exec.Command(exe, runArg)).CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}

	fn := strings.TrimSpace(string(got))
	defer os.Remove(fn)

	cmd := testEnv(exec.Command(testenv.GoToolPath(t), "tool", "pprof", "-top", "-nodecount=1", "-symbolize=force", exe, fn))

	found := false
	for i, e := range cmd.Env {
		if strings.HasPrefix(e, "PPROF_TMPDIR=") {
			cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir()
			found = true
			break
		}
	}
	if !found {
		cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir())
	}

	top, err := cmd.CombinedOutput()
	t.Logf("%s", top)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Contains(top, []byte("cpuHog")) {
		t.Error("missing cpuHog in pprof output")
	}
}
Esempio n. 7
0
func TestMemPprof(t *testing.T) {
	testenv.MustHaveGoRun(t)

	exe, err := buildTestProg(t, "testprog")
	if err != nil {
		t.Fatal(err)
	}

	got, err := testEnv(exec.Command(exe, "MemProf")).CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}
	fn := strings.TrimSpace(string(got))
	defer os.Remove(fn)

	cmd := testEnv(exec.Command("go", "tool", "pprof", "-alloc_space", "-top", exe, fn))

	found := false
	for i, e := range cmd.Env {
		if strings.HasPrefix(e, "PPROF_TMPDIR=") {
			cmd.Env[i] = "PPROF_TMPDIR=" + os.TempDir()
			found = true
			break
		}
	}
	if !found {
		cmd.Env = append(cmd.Env, "PPROF_TMPDIR="+os.TempDir())
	}

	top, err := cmd.CombinedOutput()
	t.Logf("%s", top)
	if err != nil {
		t.Fatal(err)
	}

	if !bytes.Contains(top, []byte("MemProf")) {
		t.Error("missing MemProf in pprof output")
	}
}