From 53406b283244bfe6ebf41a1c4b38b4fac57e6201 Mon Sep 17 00:00:00 2001 From: WAKAYAMA Shirou Date: Sun, 12 Jun 2016 23:20:51 +0900 Subject: [PATCH] [host]Windows: BootTime and Uptime are reversed on Windows. --- host/host_linux_ppc64le.go | 2 ++ host/host_test.go | 13 +++++++++++++ host/host_windows.go | 14 +++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/host/host_linux_ppc64le.go b/host/host_linux_ppc64le.go index 37dbe5c..d081a08 100644 --- a/host/host_linux_ppc64le.go +++ b/host/host_linux_ppc64le.go @@ -1,3 +1,5 @@ +// +build linux +// +build ppc64le // Created by cgo -godefs - DO NOT EDIT // cgo -godefs types_linux.go diff --git a/host/host_test.go b/host/host_test.go index 2bf395c..526f0ec 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -16,6 +16,16 @@ func TestHostInfo(t *testing.T) { } } +func TestUptime(t *testing.T) { + v, err := Uptime() + if err != nil { + t.Errorf("error %v", err) + } + if v == 0 { + t.Errorf("Could not get up time %v", v) + } +} + func TestBoot_time(t *testing.T) { v, err := BootTime() if err != nil { @@ -24,6 +34,9 @@ func TestBoot_time(t *testing.T) { if v == 0 { t.Errorf("Could not get boot time %v", v) } + if v < 946652400 { + t.Errorf("Invalid Boottime, older than 2000-01-01") + } } func TestUsers(t *testing.T) { diff --git a/host/host_windows.go b/host/host_windows.go index 29f900c..18062df 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -50,7 +50,7 @@ func Info() (*InfoStat, error) { boot, err := BootTime() if err == nil { ret.BootTime = boot - ret.Uptime = uptime(boot) + ret.Uptime, _ = Uptime() } procs, err := process.Pids() @@ -76,7 +76,7 @@ func GetOSInfo() (Win32_OperatingSystem, error) { return dst[0], nil } -func BootTime() (uint64, error) { +func Uptime() (uint64, error) { if osInfo == nil { _, err := GetOSInfo() if err != nil { @@ -88,16 +88,16 @@ func BootTime() (uint64, error) { return uint64(now.Sub(t).Seconds()), nil } -func uptime(boot uint64) uint64 { - return uint64(time.Now().Unix()) - boot +func bootTime(up uint64) uint64 { + return uint64(time.Now().Unix()) - up } -func Uptime() (uint64, error) { - boot, err := BootTime() +func BootTime() (uint64, error) { + up, err := Uptime() if err != nil { return 0, err } - return uptime(boot), nil + return bootTime(up), nil } func PlatformInformation() (platform string, family string, version string, err error) {