Brad Fitzpatrick | 5194744 | 2016-03-01 22:57:46 +0000 | [diff] [blame] | 1 | // Copyright 2015 The Go Authors. All rights reserved. |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Josh Bleecher Snyder | e43c74a | 2016-01-27 12:49:13 -0800 | [diff] [blame] | 5 | // The file contains tests that cannot run under race detector for some reason. |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 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 | |
Srdjan Petrovic | 1f65c9c | 2015-04-22 11:44:46 -0700 | [diff] [blame] | 24 | // Can't be run with -race because it inserts calls into newOSProcCreated() |
| 25 | // that require a valid G/M. |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 26 | func TestNewOSProc0(t *testing.T) { |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 27 | runtime.NewOSProc0(0x800000, unsafe.Pointer(runtime.FuncPC(newOSProcCreated))) |
Shenghou Ma | 4d1ab2d | 2015-04-29 02:42:43 -0400 | [diff] [blame] | 28 | check := time.NewTicker(100 * time.Millisecond) |
Srdjan Petrovic | 1f65c9c | 2015-04-22 11:44:46 -0700 | [diff] [blame] | 29 | defer check.Stop() |
| 30 | end := time.After(5 * time.Second) |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 31 | for { |
| 32 | select { |
Srdjan Petrovic | 1f65c9c | 2015-04-22 11:44:46 -0700 | [diff] [blame] | 33 | case <-check.C: |
Srdjan Petrovic | ca9128f | 2015-04-17 17:27:07 -0700 | [diff] [blame] | 34 | if newOSProcDone { |
| 35 | return |
| 36 | } |
| 37 | case <-end: |
| 38 | t.Fatalf("couldn't create new OS process") |
| 39 | } |
| 40 | } |
| 41 | } |