2
2
package cpu
3
3
4
4
import (
5
- "errors"
6
5
"fmt"
7
6
"os"
8
7
"runtime"
@@ -15,15 +14,9 @@ import (
15
14
"github.com/shirou/gopsutil/v4/internal/common"
16
15
)
17
16
18
- func skipIfNotImplementedErr (t * testing.T , err error ) {
19
- if errors .Is (err , common .ErrNotImplementedError ) {
20
- t .Skip ("not implemented" )
21
- }
22
- }
23
-
24
17
func TestTimes (t * testing.T ) {
25
18
v , err := Times (false )
26
- skipIfNotImplementedErr (t , err )
19
+ common . SkipIfNotImplementedErr (t , err )
27
20
require .NoError (t , err )
28
21
assert .NotEmptyf (t , v , "could not get CPUs: %s" , err )
29
22
empty := TimesStat {}
@@ -33,11 +26,11 @@ func TestTimes(t *testing.T) {
33
26
34
27
// test sum of per cpu stats is within margin of error for cpu total stats
35
28
cpuTotal , err := Times (false )
36
- skipIfNotImplementedErr (t , err )
29
+ common . SkipIfNotImplementedErr (t , err )
37
30
require .NoError (t , err )
38
31
assert .NotEmptyf (t , cpuTotal , "could not get CPUs: %s" , err )
39
32
perCPU , err := Times (true )
40
- skipIfNotImplementedErr (t , err )
33
+ common . SkipIfNotImplementedErr (t , err )
41
34
require .NoError (t , err )
42
35
assert .NotEmptyf (t , perCPU , "could not get CPUs: %s" , err )
43
36
var perCPUUserTimeSum float64
@@ -67,12 +60,12 @@ func TestTimes(t *testing.T) {
67
60
68
61
func TestCounts (t * testing.T ) {
69
62
v , err := Counts (true )
70
- skipIfNotImplementedErr (t , err )
63
+ common . SkipIfNotImplementedErr (t , err )
71
64
require .NoError (t , err )
72
65
assert .NotZerof (t , v , "could not get logical CPU counts: %v" , v )
73
66
t .Logf ("logical cores: %d" , v )
74
67
v , err = Counts (false )
75
- skipIfNotImplementedErr (t , err )
68
+ common . SkipIfNotImplementedErr (t , err )
76
69
require .NoError (t , err )
77
70
assert .NotZerof (t , v , "could not get physical CPU counts: %v" , v )
78
71
t .Logf ("physical cores: %d" , v )
@@ -91,7 +84,7 @@ func TestTimeStat_String(t *testing.T) {
91
84
92
85
func TestInfo (t * testing.T ) {
93
86
v , err := Info ()
94
- skipIfNotImplementedErr (t , err )
87
+ common . SkipIfNotImplementedErr (t , err )
95
88
require .NoError (t , err )
96
89
assert .NotEmptyf (t , v , "could not get CPU Info" )
97
90
for _ , vv := range v {
@@ -100,13 +93,14 @@ func TestInfo(t *testing.T) {
100
93
}
101
94
102
95
func testPercent (t * testing.T , percpu bool ) {
96
+ t .Helper ()
103
97
numcpu := runtime .NumCPU ()
104
98
testCount := 3
105
99
106
100
if runtime .GOOS != "windows" {
107
101
testCount = 100
108
102
v , err := Percent (time .Millisecond , percpu )
109
- skipIfNotImplementedErr (t , err )
103
+ common . SkipIfNotImplementedErr (t , err )
110
104
require .NoError (t , err )
111
105
// Skip CI which CPU num is different
112
106
if os .Getenv ("CI" ) != "true" {
@@ -118,7 +112,7 @@ func testPercent(t *testing.T, percpu bool) {
118
112
for i := 0 ; i < testCount ; i ++ {
119
113
duration := time .Duration (10 ) * time .Microsecond
120
114
v , err := Percent (duration , percpu )
121
- skipIfNotImplementedErr (t , err )
115
+ common . SkipIfNotImplementedErr (t , err )
122
116
require .NoError (t , err )
123
117
for _ , percent := range v {
124
118
// Check for slightly greater then 100% to account for any rounding issues.
@@ -130,13 +124,14 @@ func testPercent(t *testing.T, percpu bool) {
130
124
}
131
125
132
126
func testPercentLastUsed (t * testing.T , percpu bool ) {
127
+ t .Helper ()
133
128
numcpu := runtime .NumCPU ()
134
129
testCount := 10
135
130
136
131
if runtime .GOOS != "windows" {
137
132
testCount = 2
138
133
v , err := Percent (time .Millisecond , percpu )
139
- skipIfNotImplementedErr (t , err )
134
+ common . SkipIfNotImplementedErr (t , err )
140
135
require .NoError (t , err )
141
136
// Skip CI which CPU num is different
142
137
if os .Getenv ("CI" ) != "true" {
@@ -147,7 +142,7 @@ func testPercentLastUsed(t *testing.T, percpu bool) {
147
142
}
148
143
for i := 0 ; i < testCount ; i ++ {
149
144
v , err := Percent (0 , percpu )
150
- skipIfNotImplementedErr (t , err )
145
+ common . SkipIfNotImplementedErr (t , err )
151
146
require .NoError (t , err )
152
147
time .Sleep (1 * time .Millisecond )
153
148
for _ , percent := range v {
0 commit comments