[host]Windows: BootTime and Uptime are reversed on Windows.

This commit is contained in:
WAKAYAMA Shirou 2016-06-12 23:20:51 +09:00
parent e9afb36ccf
commit 53406b2832
3 changed files with 22 additions and 7 deletions

View File

@ -1,3 +1,5 @@
// +build linux
// +build ppc64le
// Created by cgo -godefs - DO NOT EDIT // Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_linux.go // cgo -godefs types_linux.go

View File

@ -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) { func TestBoot_time(t *testing.T) {
v, err := BootTime() v, err := BootTime()
if err != nil { if err != nil {
@ -24,6 +34,9 @@ func TestBoot_time(t *testing.T) {
if v == 0 { if v == 0 {
t.Errorf("Could not get boot time %v", v) 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) { func TestUsers(t *testing.T) {

View File

@ -50,7 +50,7 @@ func Info() (*InfoStat, error) {
boot, err := BootTime() boot, err := BootTime()
if err == nil { if err == nil {
ret.BootTime = boot ret.BootTime = boot
ret.Uptime = uptime(boot) ret.Uptime, _ = Uptime()
} }
procs, err := process.Pids() procs, err := process.Pids()
@ -76,7 +76,7 @@ func GetOSInfo() (Win32_OperatingSystem, error) {
return dst[0], nil return dst[0], nil
} }
func BootTime() (uint64, error) { func Uptime() (uint64, error) {
if osInfo == nil { if osInfo == nil {
_, err := GetOSInfo() _, err := GetOSInfo()
if err != nil { if err != nil {
@ -88,16 +88,16 @@ func BootTime() (uint64, error) {
return uint64(now.Sub(t).Seconds()), nil return uint64(now.Sub(t).Seconds()), nil
} }
func uptime(boot uint64) uint64 { func bootTime(up uint64) uint64 {
return uint64(time.Now().Unix()) - boot return uint64(time.Now().Unix()) - up
} }
func Uptime() (uint64, error) { func BootTime() (uint64, error) {
boot, err := BootTime() up, err := Uptime()
if err != nil { if err != nil {
return 0, err return 0, err
} }
return uptime(boot), nil return bootTime(up), nil
} }
func PlatformInformation() (platform string, family string, version string, err error) { func PlatformInformation() (platform string, family string, version string, err error) {