summaryrefslogtreecommitdiff
path: root/libgo/go/runtime/crash_gccgo_test.go
blob: d4a826e24e5ed8a8e7208717c0ac5e87d86d3635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2018 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.

// +build cgo,gccgo

package runtime_test

import (
	"bytes"
	"fmt"
	"internal/testenv"
	"os"
	"os/exec"
	"strings"
	"testing"
)

func TestGccgoCrashTraceback(t *testing.T) {
	t.Parallel()
	got := runTestProg(t, "testprogcgo", "CrashTracebackGccgo")
	ok := true
	for i := 1; i <= 3; i++ {
		if !strings.Contains(got, fmt.Sprintf("CFunction%d", i)) {
			t.Errorf("missing C function CFunction%d", i)
			ok = false
		}
	}
	if !ok {
		t.Log(got)
	}
}

func TestGccgoCrashTracebackNodebug(t *testing.T) {
	testenv.MustHaveGoBuild(t)
	if os.Getenv("CC") == "" {
		t.Skip("no compiler in environment")
	}

	cc := strings.Fields(os.Getenv("CC"))
	cc = append(cc, "-o", os.DevNull, "-x", "c++", "-")
	out, _ := testenv.CleanCmdEnv(exec.Command(cc[0], cc[1:]...)).CombinedOutput()
	if bytes.Contains(out, []byte("error trying to exec 'cc1plus'")) {
		t.Skip("no C++ compiler")
	}
	os.Setenv("CXX", os.Getenv("CC"))

	got := runTestProg(t, "testprogcxx", "CrashTracebackNodebug")
	ok := true
	for i := 1; i <= 3; i++ {
		if !strings.Contains(got, fmt.Sprintf("cxxFunction%d", i)) {
			t.Errorf("missing C++ function cxxFunction%d", i)
			ok = false
		}
	}
	if !ok {
		t.Log(got)
	}
}