...
1 package cpu
2
3 import (
4 "path/filepath"
5 "runtime"
6 "testing"
7
8 "github.com/shirou/gopsutil/internal/common"
9 )
10
11 func TestParseDmesgBoot(t *testing.T) {
12 if runtime.GOOS != "freebsd" {
13 t.SkipNow()
14 }
15
16 var cpuTests = []struct {
17 file string
18 cpuNum int
19 cores int32
20 }{
21 {"1cpu_2core.txt", 1, 2},
22 {"1cpu_4core.txt", 1, 4},
23 {"2cpu_4core.txt", 2, 4},
24 }
25 for _, tt := range cpuTests {
26 v, num, err := parseDmesgBoot(filepath.Join("testdata", "freebsd", tt.file))
27 if err != nil {
28 t.Errorf("parseDmesgBoot failed(%s), %v", tt.file, err)
29 }
30 if num != tt.cpuNum {
31 t.Errorf("parseDmesgBoot wrong length(%s), %v", tt.file, err)
32 }
33 if v.Cores != tt.cores {
34 t.Errorf("parseDmesgBoot wrong core(%s), %v", tt.file, err)
35 }
36 if !common.StringsContains(v.Flags, "fpu") {
37 t.Errorf("parseDmesgBoot fail to parse features(%s), %v", tt.file, err)
38 }
39 }
40 }
41
View as plain text