-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpapi_hl_test.go
114 lines (103 loc) · 3 KB
/
papi_hl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// This file tests the high-level features of the PAPI library.
package papi
import "testing"
import "time"
// Do most of the work for TestFlipFlops() by testing any of Flips(),
// Flops(), or Ipc() high-level PAPI functions in a consistent manner.
func testFlipFlopsHelper(t *testing.T, funcName string, hlFunc func() (float32, float32, int64, float32, error)) {
const sleep_usecs = 10000
const flops = 100
counterValues := make([]int64, 3)
// Test the given function().
rtime1, ptime1, other1, _, err := hlFunc()
if err != nil {
t.Fatal(err)
}
performWork(flops)
time.Sleep(sleep_usecs * 1000)
rtime2, ptime2, other2, _, err := hlFunc()
if err != nil {
t.Fatal(err)
}
if rtime2-rtime1 < sleep_usecs/1.0e6 {
t.Fatalf("%s() real time increases too slowly: %f vs. %f",
funcName, rtime2-rtime1, sleep_usecs/1.0e6)
}
if ptime1 > ptime2 {
t.Fatalf("%s() process time decreases: %f >= %f",
funcName, ptime1, ptime2)
}
if (other2 - other1) < flops {
t.Fatalf("%s() observed too few counts: %d >= %d",
other2-other1, flops)
}
if err := StopCounters(counterValues); err != nil {
t.Fatal(err)
}
}
// Ensure that the time, floating-point, and instruction counters
// return believable values.
func TestFlipFlops(t *testing.T) {
testFlipFlopsHelper(t, "Flips", Flips)
testFlipFlopsHelper(t, "Flops", Flops)
testFlipFlopsHelper(t, "Ipc", Ipc)
}
// Ensure that the high-level counters actually count something.
func TestHLCounters(t *testing.T) {
// Start counting a few events (but not more than NumCounters).
eventList := []Event{LD_INS, SR_INS, TOT_CYC, TOT_INS}
var usedEvents []Event
if len(eventList) <= NumCounters {
usedEvents = eventList
} else {
usedEvents = eventList[0 : NumCounters-1]
}
if err := StartCounters(usedEvents); err != nil {
t.Fatal(err)
}
// Read the counters right away.
counterValues := make([]int64, len(usedEvents))
if err := ReadCounters(counterValues); err != nil {
t.Fatal(err)
}
// Burn some cycles.
eventNames := make(map[Event]string)
for _, ecode := range eventList {
eventNames[ecode] = ecode.String()
}
// Ensure that at least one of our counters increased. All
// should increase, but perhaps some don't on certain hardware.
if err := AccumCounters(counterValues); err != nil {
t.Fatal(err)
}
anyChanged := false
for _, value := range counterValues {
if value != 0 {
anyChanged = true
break
}
}
if !anyChanged {
t.Fatalf("None of %v appear to count", usedEvents)
}
// Burn some more cycles.
for _, ecode := range eventList {
eventNames[ecode] = eventNames[ecode] + " event"
}
// Ensure that at least one of our counters increased. All
// should increase, but perhaps some don't on certain hardware.
counterValues = make([]int64, len(counterValues)) // Clear all counters
if err := StopCounters(counterValues); err != nil {
t.Fatal(err)
}
anyChanged = false
for _, value := range counterValues {
if value != 0 {
anyChanged = true
break
}
}
if !anyChanged {
t.Fatalf("None of %v appear to count", usedEvents)
}
}