Skip to content

Commit

Permalink
sql: work around lack of runtime/trace in gccgo
Browse files Browse the repository at this point in the history
Moves runtime/trace support behind a "gc" build tag to allow sql_test
to build under gccgo, which does not support runtime/trace.

See golang/go#15544.
  • Loading branch information
tamird committed Aug 14, 2016
1 parent 00354c9 commit ce6c652
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 23 deletions.
46 changes: 46 additions & 0 deletions sql/logic_gc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2016 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Author: Tamir Duberstein ([email protected])

// +build gc

package sql_test

import (
"os"
"runtime/trace"
)

func (t *logicTest) traceStart(filename string) {
if t.traceFile != nil {
t.Fatalf("tracing already active")
}
var err error
t.traceFile, err = os.Create(filename)
if err != nil {
t.Fatalf("unable to open trace output file: %s", err)
}
if err := trace.Start(t.traceFile); err != nil {
t.Fatalf("unable to start tracing: %s", err)
}
}

func (t *logicTest) traceStop() {
if t.traceFile != nil {
trace.Stop()
t.traceFile.Close()
t.traceFile = nil
}
}
23 changes: 23 additions & 0 deletions sql/logic_not_gc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2016 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// Author: Tamir Duberstein ([email protected])

// +build !gc

package sql_test

func (*logicTest) traceStart(_ string) {}

func (*logicTest) traceStop() {}
23 changes: 0 additions & 23 deletions sql/logic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime/trace"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -1020,28 +1019,6 @@ func (t *logicTest) success(file string) {
}
}

func (t *logicTest) traceStart(filename string) {
if t.traceFile != nil {
t.Fatalf("tracing already active")
}
var err error
t.traceFile, err = os.Create(filename)
if err != nil {
t.Fatalf("unable to open trace output file: %s", err)
}
if err := trace.Start(t.traceFile); err != nil {
t.Fatalf("unable to start tracing: %s", err)
}
}

func (t *logicTest) traceStop() {
if t.traceFile != nil {
trace.Stop()
t.traceFile.Close()
t.traceFile = nil
}
}

func TestLogic(t *testing.T) {
defer leaktest.AfterTest(t)()

Expand Down

0 comments on commit ce6c652

Please sign in to comment.