github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/go/src/runtime/norace_linux_test.go (about)

     1  // Copyright 2015 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  // The file contains tests that cannot run under race detector for some reason.
     6  // +build !race
     7  
     8  package runtime_test
     9  
    10  import (
    11  	"runtime"
    12  	"testing"
    13  	"time"
    14  	"unsafe"
    15  )
    16  
    17  var newOSProcDone bool
    18  
    19  //go:nosplit
    20  func newOSProcCreated() {
    21  	newOSProcDone = true
    22  }
    23  
    24  // Can't be run with -race because it inserts calls into newOSProcCreated()
    25  // that require a valid G/M.
    26  func TestNewOSProc0(t *testing.T) {
    27  	runtime.NewOSProc0(0x800000, unsafe.Pointer(runtime.FuncPC(newOSProcCreated)))
    28  	check := time.NewTicker(100 * time.Millisecond)
    29  	defer check.Stop()
    30  	end := time.After(5 * time.Second)
    31  	for {
    32  		select {
    33  		case <-check.C:
    34  			if newOSProcDone {
    35  				return
    36  			}
    37  		case <-end:
    38  			t.Fatalf("couldn't create new OS process")
    39  		}
    40  	}
    41  }