blob: 3517a5ddbe76b49121873423bc3c9a7712019058 [file] [log] [blame]
Brad Fitzpatrick51947442016-03-01 22:57:46 +00001// Copyright 2015 The Go Authors. All rights reserved.
Srdjan Petrovicca9128f2015-04-17 17:27:07 -07002// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Josh Bleecher Snydere43c74a2016-01-27 12:49:13 -08005// The file contains tests that cannot run under race detector for some reason.
Srdjan Petrovicca9128f2015-04-17 17:27:07 -07006// +build !race
7
8package runtime_test
9
10import (
11 "runtime"
12 "testing"
13 "time"
14 "unsafe"
15)
16
17var newOSProcDone bool
18
19//go:nosplit
20func newOSProcCreated() {
21 newOSProcDone = true
22}
23
Srdjan Petrovic1f65c9c2015-04-22 11:44:46 -070024// Can't be run with -race because it inserts calls into newOSProcCreated()
25// that require a valid G/M.
Srdjan Petrovicca9128f2015-04-17 17:27:07 -070026func TestNewOSProc0(t *testing.T) {
Srdjan Petrovicca9128f2015-04-17 17:27:07 -070027 runtime.NewOSProc0(0x800000, unsafe.Pointer(runtime.FuncPC(newOSProcCreated)))
Shenghou Ma4d1ab2d2015-04-29 02:42:43 -040028 check := time.NewTicker(100 * time.Millisecond)
Srdjan Petrovic1f65c9c2015-04-22 11:44:46 -070029 defer check.Stop()
30 end := time.After(5 * time.Second)
Srdjan Petrovicca9128f2015-04-17 17:27:07 -070031 for {
32 select {
Srdjan Petrovic1f65c9c2015-04-22 11:44:46 -070033 case <-check.C:
Srdjan Petrovicca9128f2015-04-17 17:27:07 -070034 if newOSProcDone {
35 return
36 }
37 case <-end:
38 t.Fatalf("couldn't create new OS process")
39 }
40 }
41}