-
Notifications
You must be signed in to change notification settings - Fork 16
/
client_linux_integration_test.go
59 lines (46 loc) · 1.16 KB
/
client_linux_integration_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
//go:build linux
// +build linux
package taskstats_test
import (
"os"
"testing"
"github.com/mdlayher/taskstats"
)
func TestLinuxClientIntegration(t *testing.T) {
c, err := taskstats.New()
if err != nil {
t.Fatalf("failed to open client: %v", err)
}
defer c.Close()
t.Run("self", func(t *testing.T) {
testSelfStats(t, c)
})
t.Run("cgroup", func(t *testing.T) {
testCGroupStats(t, c)
})
}
func testSelfStats(t *testing.T, c *taskstats.Client) {
stats, err := c.Self()
if err != nil {
if os.IsPermission(err) {
t.Skipf("taskstats requires elevated permission: %v", err)
}
t.Fatalf("failed to retrieve self stats: %v", err)
}
if stats.BeginTime.IsZero() {
t.Fatalf("unexpected zero begin time")
}
// TODO(mdlayher): verify more fields?
}
func testCGroupStats(t *testing.T, c *taskstats.Client) {
// TODO(mdlayher): try to verify these in some meaningful way, but for now,
// no error means the structure is valid, which works.
_, err := c.CGroupStats("/sys/fs/cgroup/cpu")
if err == nil {
return
}
if os.IsNotExist(err) {
t.Skipf("did not find cgroup CPU stats: %v", err)
}
t.Fatalf("failed to retrieve cgroup stats: %v", err)
}