2
2
package cpu
3
3
4
4
import (
5
- "errors"
6
5
"fmt"
7
6
"os"
8
7
"runtime"
@@ -14,15 +13,9 @@ import (
14
13
"github.com/shirou/gopsutil/v4/internal/common"
15
14
)
16
15
17
- func skipIfNotImplementedErr (t * testing.T , err error ) {
18
- if errors .Is (err , common .ErrNotImplementedError ) {
19
- t .Skip ("not implemented" )
20
- }
21
- }
22
-
23
16
func TestTimes (t * testing.T ) {
24
17
v , err := Times (false )
25
- skipIfNotImplementedErr (t , err )
18
+ common . SkipIfNotImplementedErr (t , err )
26
19
if err != nil {
27
20
t .Errorf ("error %v" , err )
28
21
}
@@ -38,15 +31,15 @@ func TestTimes(t *testing.T) {
38
31
39
32
// test sum of per cpu stats is within margin of error for cpu total stats
40
33
cpuTotal , err := Times (false )
41
- skipIfNotImplementedErr (t , err )
34
+ common . SkipIfNotImplementedErr (t , err )
42
35
if err != nil {
43
36
t .Errorf ("error %v" , err )
44
37
}
45
38
if len (cpuTotal ) == 0 {
46
39
t .Error ("could not get CPUs" , err )
47
40
}
48
41
perCPU , err := Times (true )
49
- skipIfNotImplementedErr (t , err )
42
+ common . SkipIfNotImplementedErr (t , err )
50
43
if err != nil {
51
44
t .Errorf ("error %v" , err )
52
45
}
@@ -80,7 +73,7 @@ func TestTimes(t *testing.T) {
80
73
81
74
func TestCounts (t * testing.T ) {
82
75
v , err := Counts (true )
83
- skipIfNotImplementedErr (t , err )
76
+ common . SkipIfNotImplementedErr (t , err )
84
77
if err != nil {
85
78
t .Errorf ("error %v" , err )
86
79
}
@@ -89,7 +82,7 @@ func TestCounts(t *testing.T) {
89
82
}
90
83
t .Logf ("logical cores: %d" , v )
91
84
v , err = Counts (false )
92
- skipIfNotImplementedErr (t , err )
85
+ common . SkipIfNotImplementedErr (t , err )
93
86
if err != nil {
94
87
t .Errorf ("error %v" , err )
95
88
}
@@ -114,7 +107,7 @@ func TestTimeStat_String(t *testing.T) {
114
107
115
108
func TestInfo (t * testing.T ) {
116
109
v , err := Info ()
117
- skipIfNotImplementedErr (t , err )
110
+ common . SkipIfNotImplementedErr (t , err )
118
111
if err != nil {
119
112
t .Errorf ("error %v" , err )
120
113
}
@@ -129,13 +122,14 @@ func TestInfo(t *testing.T) {
129
122
}
130
123
131
124
func testPercent (t * testing.T , percpu bool ) {
125
+ t .Helper ()
132
126
numcpu := runtime .NumCPU ()
133
127
testCount := 3
134
128
135
129
if runtime .GOOS != "windows" {
136
130
testCount = 100
137
131
v , err := Percent (time .Millisecond , percpu )
138
- skipIfNotImplementedErr (t , err )
132
+ common . SkipIfNotImplementedErr (t , err )
139
133
if err != nil {
140
134
t .Errorf ("error %v" , err )
141
135
}
@@ -149,7 +143,7 @@ func testPercent(t *testing.T, percpu bool) {
149
143
for i := 0 ; i < testCount ; i ++ {
150
144
duration := time .Duration (10 ) * time .Microsecond
151
145
v , err := Percent (duration , percpu )
152
- skipIfNotImplementedErr (t , err )
146
+ common . SkipIfNotImplementedErr (t , err )
153
147
if err != nil {
154
148
t .Errorf ("error %v" , err )
155
149
}
@@ -163,13 +157,14 @@ func testPercent(t *testing.T, percpu bool) {
163
157
}
164
158
165
159
func testPercentLastUsed (t * testing.T , percpu bool ) {
160
+ t .Helper ()
166
161
numcpu := runtime .NumCPU ()
167
162
testCount := 10
168
163
169
164
if runtime .GOOS != "windows" {
170
165
testCount = 2
171
166
v , err := Percent (time .Millisecond , percpu )
172
- skipIfNotImplementedErr (t , err )
167
+ common . SkipIfNotImplementedErr (t , err )
173
168
if err != nil {
174
169
t .Errorf ("error %v" , err )
175
170
}
@@ -182,7 +177,7 @@ func testPercentLastUsed(t *testing.T, percpu bool) {
182
177
}
183
178
for i := 0 ; i < testCount ; i ++ {
184
179
v , err := Percent (0 , percpu )
185
- skipIfNotImplementedErr (t , err )
180
+ common . SkipIfNotImplementedErr (t , err )
186
181
if err != nil {
187
182
t .Errorf ("error %v" , err )
188
183
}
0 commit comments