From dc8102185dbd93dae10630f4dd67fd155af65899 Mon Sep 17 00:00:00 2001 From: WAKAYAMA shirou Date: Sun, 29 Jan 2017 01:43:24 +0900 Subject: [PATCH] separate freebsd specific test code. --- cpu/cpu_freebsd_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ cpu/cpu_test.go | 34 ---------------------------------- 2 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 cpu/cpu_freebsd_test.go diff --git a/cpu/cpu_freebsd_test.go b/cpu/cpu_freebsd_test.go new file mode 100644 index 0000000..bd20211 --- /dev/null +++ b/cpu/cpu_freebsd_test.go @@ -0,0 +1,40 @@ +package cpu + +import ( + "path/filepath" + "runtime" + "testing" + + "github.com/shirou/gopsutil/internal/common" +) + +func TestParseDmesgBoot(t *testing.T) { + if runtime.GOOS != "freebsd" { + t.SkipNow() + } + + var cpuTests = []struct { + 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 { + v, num, err := parseDmesgBoot(filepath.Join("expected/freebsd/", tt.file)) + 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) + } + } +} diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index 3b9f471..6082ffc 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -3,12 +3,9 @@ package cpu import ( "fmt" "os" - "path/filepath" "runtime" "testing" "time" - - "github.com/shirou/gopsutil/internal/common" ) func TestCpu_times(t *testing.T) { @@ -65,37 +62,6 @@ func TestCpuInfo(t *testing.T) { } } -func TestParseDmesgBoot(t *testing.T) { - if runtime.GOOS != "freebsd" { - t.SkipNow() - } - - var cpuTests = []struct { - 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 { - v, num, err := parseDmesgBoot(filepath.Join("expected/freebsd/", tt.file)) - 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) - } - } -} - func testCPUPercent(t *testing.T, percpu bool) { numcpu := runtime.NumCPU() testCount := 3