1// Copyright 2018 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
5// +build cgo,gccgo
6
7package runtime_test
8
9import (
10	"bytes"
11	"fmt"
12	"internal/testenv"
13	"os"
14	"os/exec"
15	"strings"
16	"testing"
17)
18
19func TestGccgoCrashTraceback(t *testing.T) {
20	t.Parallel()
21	got := runTestProg(t, "testprogcgo", "CrashTracebackGccgo")
22	ok := true
23	for i := 1; i <= 3; i++ {
24		if !strings.Contains(got, fmt.Sprintf("CFunction%d", i)) {
25			t.Errorf("missing C function CFunction%d", i)
26			ok = false
27		}
28	}
29	if !ok {
30		t.Log(got)
31	}
32}
33
34func TestGccgoCrashTracebackNodebug(t *testing.T) {
35	testenv.MustHaveGoBuild(t)
36	if os.Getenv("CC") == "" {
37		t.Skip("no compiler in environment")
38	}
39
40	cc := strings.Fields(os.Getenv("CC"))
41	cc = append(cc, "-o", os.DevNull, "-x", "c++", "-")
42	out, _ := testenv.CleanCmdEnv(exec.Command(cc[0], cc[1:]...)).CombinedOutput()
43	if bytes.Contains(out, []byte("error trying to exec 'cc1plus'")) {
44		t.Skip("no C++ compiler")
45	}
46	os.Setenv("CXX", os.Getenv("CC"))
47
48	got := runTestProg(t, "testprogcxx", "CrashTracebackNodebug")
49	ok := true
50	for i := 1; i <= 3; i++ {
51		if !strings.Contains(got, fmt.Sprintf("cxxFunction%d", i)) {
52			t.Errorf("missing C++ function cxxFunction%d", i)
53			ok = false
54		}
55	}
56	if !ok {
57		t.Log(got)
58	}
59}
60