LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Test stack split logic by calling functions of every frame size | 5 // Test stack split logic by calling functions of every frame size |
6 // from near 0 up to and beyond the default segment size (4k). | 6 // from near 0 up to and beyond the default segment size (4k). |
7 // Each of those functions reports its SP + stack limit, and then | 7 // Each of those functions reports its SP + stack limit, and then |
8 // the test (the caller) checks that those make sense. By not | 8 // the test (the caller) checks that those make sense. By not |
9 // doing the actual checking and reporting from the suspect functions, | 9 // doing the actual checking and reporting from the suspect functions, |
10 // we minimize the possibility of crashes during the test itself. | 10 // we minimize the possibility of crashes during the test itself. |
(...skipping 16 matching lines...) Expand all Loading... |
27 // stack_test.go:22: after runtime_test.stack3856: sp=0x7f7818d5d050 < limi
t=0x7f7818d5d080 | 27 // stack_test.go:22: after runtime_test.stack3856: sp=0x7f7818d5d050 < limi
t=0x7f7818d5d080 |
28 // stack_test.go:22: after runtime_test.stack3860: sp=0x7f7818d5d048 < limi
t=0x7f7818d5d080 | 28 // stack_test.go:22: after runtime_test.stack3860: sp=0x7f7818d5d048 < limi
t=0x7f7818d5d080 |
29 // stack_test.go:22: after runtime_test.stack3864: sp=0x7f7818d5d048 < limi
t=0x7f7818d5d080 | 29 // stack_test.go:22: after runtime_test.stack3864: sp=0x7f7818d5d048 < limi
t=0x7f7818d5d080 |
30 // FAIL | 30 // FAIL |
31 | 31 |
32 package runtime_test | 32 package runtime_test |
33 | 33 |
34 import ( | 34 import ( |
35 . "runtime" | 35 . "runtime" |
36 "testing" | 36 "testing" |
| 37 "time" |
37 "unsafe" | 38 "unsafe" |
38 ) | 39 ) |
39 | 40 |
40 // See stack.h. | 41 // See stack.h. |
41 const ( | 42 const ( |
42 StackGuard = 256 | 43 StackGuard = 256 |
43 StackLimit = 128 | 44 StackLimit = 128 |
44 ) | 45 ) |
45 | 46 |
46 func TestStackSplit(t *testing.T) { | 47 func TestStackSplit(t *testing.T) { |
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 func stack4964() (uintptr, uintptr) { var buf [4964]byte; use(buf[:]); return St
ackguard() } | 1520 func stack4964() (uintptr, uintptr) { var buf [4964]byte; use(buf[:]); return St
ackguard() } |
1520 func stack4968() (uintptr, uintptr) { var buf [4968]byte; use(buf[:]); return St
ackguard() } | 1521 func stack4968() (uintptr, uintptr) { var buf [4968]byte; use(buf[:]); return St
ackguard() } |
1521 func stack4972() (uintptr, uintptr) { var buf [4972]byte; use(buf[:]); return St
ackguard() } | 1522 func stack4972() (uintptr, uintptr) { var buf [4972]byte; use(buf[:]); return St
ackguard() } |
1522 func stack4976() (uintptr, uintptr) { var buf [4976]byte; use(buf[:]); return St
ackguard() } | 1523 func stack4976() (uintptr, uintptr) { var buf [4976]byte; use(buf[:]); return St
ackguard() } |
1523 func stack4980() (uintptr, uintptr) { var buf [4980]byte; use(buf[:]); return St
ackguard() } | 1524 func stack4980() (uintptr, uintptr) { var buf [4980]byte; use(buf[:]); return St
ackguard() } |
1524 func stack4984() (uintptr, uintptr) { var buf [4984]byte; use(buf[:]); return St
ackguard() } | 1525 func stack4984() (uintptr, uintptr) { var buf [4984]byte; use(buf[:]); return St
ackguard() } |
1525 func stack4988() (uintptr, uintptr) { var buf [4988]byte; use(buf[:]); return St
ackguard() } | 1526 func stack4988() (uintptr, uintptr) { var buf [4988]byte; use(buf[:]); return St
ackguard() } |
1526 func stack4992() (uintptr, uintptr) { var buf [4992]byte; use(buf[:]); return St
ackguard() } | 1527 func stack4992() (uintptr, uintptr) { var buf [4992]byte; use(buf[:]); return St
ackguard() } |
1527 func stack4996() (uintptr, uintptr) { var buf [4996]byte; use(buf[:]); return St
ackguard() } | 1528 func stack4996() (uintptr, uintptr) { var buf [4996]byte; use(buf[:]); return St
ackguard() } |
1528 func stack5000() (uintptr, uintptr) { var buf [5000]byte; use(buf[:]); return St
ackguard() } | 1529 func stack5000() (uintptr, uintptr) { var buf [5000]byte; use(buf[:]); return St
ackguard() } |
| 1530 |
| 1531 // TestStackMem measures per-thread stack segment cache behavior. |
| 1532 // The test consumed up to 500MB in the past. |
| 1533 func TestStackMem(t *testing.T) { |
| 1534 const ( |
| 1535 BatchSize = 32 |
| 1536 BatchCount = 512 |
| 1537 ArraySize = 1024 |
| 1538 RecursionDepth = 128 |
| 1539 ) |
| 1540 if testing.Short() { |
| 1541 return |
| 1542 } |
| 1543 defer GOMAXPROCS(GOMAXPROCS(BatchSize)) |
| 1544 s0 := new(MemStats) |
| 1545 ReadMemStats(s0) |
| 1546 for b := 0; b < BatchCount; b++ { |
| 1547 c := make(chan bool, BatchSize) |
| 1548 for i := 0; i < BatchSize; i++ { |
| 1549 go func() { |
| 1550 var f func(k int, a [ArraySize]byte) |
| 1551 f = func(k int, a [ArraySize]byte) { |
| 1552 if k == 0 { |
| 1553 time.Sleep(time.Millisecond) |
| 1554 return |
| 1555 } |
| 1556 f(k-1, a) |
| 1557 } |
| 1558 f(RecursionDepth, [ArraySize]byte{}) |
| 1559 c <- true |
| 1560 }() |
| 1561 } |
| 1562 for i := 0; i < BatchSize; i++ { |
| 1563 <-c |
| 1564 } |
| 1565 } |
| 1566 s1 := new(MemStats) |
| 1567 ReadMemStats(s1) |
| 1568 consumed := s1.StackSys - s0.StackSys |
| 1569 t.Logf("Consumed %vMB for stack mem", consumed>>20) |
| 1570 estimate := uint64(8 * BatchSize * ArraySize * RecursionDepth) // 8 is t
o reduce flakiness. |
| 1571 if consumed > estimate { |
| 1572 t.Fatalf("Stack mem: want %v, got %v", estimate, consumed) |
| 1573 } |
| 1574 } |
LEFT | RIGHT |