Source file src/runtime/norace_linux_test.go

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

View as plain text