-
Notifications
You must be signed in to change notification settings - Fork 6
/
exec_test.go
65 lines (51 loc) · 1.35 KB
/
exec_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
package perf_test
import (
"os/exec"
"testing"
"acln.ro/perf"
)
func TestCommand(t *testing.T) {
requires(t, paranoid(2), hardwarePMU)
cmd := exec.Command("echo", "hello world")
fa := &perf.Attr{
CountFormat: perf.CountFormat{
Running: true,
ID: true,
},
}
perf.Instructions.Configure(fa)
fa.Options.ExcludeKernel = true
fa.Options.ExcludeHypervisor = true
count, err := perf.Command(fa, cmd, perf.AnyCPU, nil)
if err != nil {
t.Fatal(err)
}
t.Logf("count = %v", count.Value)
// A primitive test to ensure the counter measured something, since we
// don't know the "correct" value.
if count.Value < 1000 {
t.Fatal("counter read less than 1000 - should be > 1M")
}
}
func TestCommandGroup(t *testing.T) {
requires(t, paranoid(2), hardwarePMU)
cmd := exec.Command("echo", "hello world")
var g perf.Group
g.CountFormat = perf.CountFormat{
Running: true,
ID: true,
}
g.Options.ExcludeKernel = true
g.Options.ExcludeHypervisor = true
g.Add(perf.Instructions, perf.CPUCycles)
counts, err := g.Command(cmd, perf.AnyCPU)
if err != nil {
t.Fatal(err)
}
t.Log("counts:", counts)
// A primitive test to ensure the counter measured something, since we
// don't know the "correct" value.
if counts.Values[0].Value < 1000 || counts.Values[1].Value < 1000 {
t.Fatal("counter read less than 1000 - should be > 1M")
}
}