1// Copyright 2018 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import "testing"
17
18func TestStat(t *testing.T) {
19	s, err := getProcFixtures(t).Stat()
20	if err != nil {
21		t.Fatal(err)
22	}
23
24	// cpu
25	if want, have := float64(301854)/userHZ, s.CPUTotal.User; want != have {
26		t.Errorf("want cpu/user %v, have %v", want, have)
27	}
28	if want, have := float64(31)/userHZ, s.CPU[7].SoftIRQ; want != have {
29		t.Errorf("want cpu7/softirq %v, have %v", want, have)
30	}
31
32	// intr
33	if want, have := uint64(8885917), s.IRQTotal; want != have {
34		t.Errorf("want irq/total %d, have %d", want, have)
35	}
36	if want, have := uint64(1), s.IRQ[8]; want != have {
37		t.Errorf("want irq8 %d, have %d", want, have)
38	}
39
40	// ctxt
41	if want, have := uint64(38014093), s.ContextSwitches; want != have {
42		t.Errorf("want context switches (ctxt) %d, have %d", want, have)
43	}
44
45	// btime
46	if want, have := uint64(1418183276), s.BootTime; want != have {
47		t.Errorf("want boot time (btime) %d, have %d", want, have)
48	}
49
50	// processes
51	if want, have := uint64(26442), s.ProcessCreated; want != have {
52		t.Errorf("want process created (processes) %d, have %d", want, have)
53	}
54
55	// procs_running
56	if want, have := uint64(2), s.ProcessesRunning; want != have {
57		t.Errorf("want processes running (procs_running) %d, have %d", want, have)
58	}
59
60	// procs_blocked
61	if want, have := uint64(1), s.ProcessesBlocked; want != have {
62		t.Errorf("want processes blocked (procs_blocked) %d, have %d", want, have)
63	}
64
65	// softirq
66	if want, have := uint64(5057579), s.SoftIRQTotal; want != have {
67		t.Errorf("want softirq total %d, have %d", want, have)
68	}
69
70	if want, have := uint64(508444), s.SoftIRQ.Rcu; want != have {
71		t.Errorf("want softirq RCU %d, have %d", want, have)
72	}
73
74}
75