shirou_gopsutil/cpu/cpu_freebsd_test.go

41 lines
872 B
Go
Raw Normal View History

2017-01-29 00:43:24 +08:00
package cpu
import (
"path/filepath"
"runtime"
"testing"
"github.com/shirou/gopsutil/v3/internal/common"
2017-01-29 00:43:24 +08:00
)
func TestParseDmesgBoot(t *testing.T) {
if runtime.GOOS != "freebsd" {
t.SkipNow()
}
2021-12-23 05:54:41 +08:00
cpuTests := []struct {
2017-01-29 00:43:24 +08:00
file string
cpuNum int
cores int32
}{
{"1cpu_2core.txt", 1, 2},
{"1cpu_4core.txt", 1, 4},
{"2cpu_4core.txt", 2, 4},
}
for _, tt := range cpuTests {
2017-03-15 22:32:55 +08:00
v, num, err := parseDmesgBoot(filepath.Join("testdata", "freebsd", tt.file))
2017-01-29 00:43:24 +08:00
if err != nil {
t.Errorf("parseDmesgBoot failed(%s), %v", tt.file, err)
}
if num != tt.cpuNum {
t.Errorf("parseDmesgBoot wrong length(%s), %v", tt.file, err)
}
if v.Cores != tt.cores {
t.Errorf("parseDmesgBoot wrong core(%s), %v", tt.file, err)
}
if !common.StringsContains(v.Flags, "fpu") {
t.Errorf("parseDmesgBoot fail to parse features(%s), %v", tt.file, err)
}
}
}