2021-12-23 05:54:41 +08:00
|
|
|
//go:build darwin
|
2015-09-18 13:52:45 +08:00
|
|
|
// +build darwin
|
|
|
|
|
|
|
|
package mem
|
|
|
|
|
|
|
|
import (
|
2016-02-22 04:43:55 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2015-09-18 13:52:45 +08:00
|
|
|
"testing"
|
2016-02-20 03:53:29 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2015-09-18 13:52:45 +08:00
|
|
|
)
|
|
|
|
|
2016-02-20 03:53:29 +08:00
|
|
|
func TestVirtualMemoryDarwin(t *testing.T) {
|
|
|
|
v, err := VirtualMemory()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2016-05-20 16:59:41 +08:00
|
|
|
outBytes, err := invoke.Command("/usr/sbin/sysctl", "hw.memsize")
|
2016-02-22 04:43:55 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
outString := string(outBytes)
|
|
|
|
outString = strings.TrimSpace(outString)
|
|
|
|
outParts := strings.Split(outString, " ")
|
|
|
|
actualTotal, err := strconv.ParseInt(outParts[1], 10, 64)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, uint64(actualTotal), v.Total)
|
2016-02-21 03:37:17 +08:00
|
|
|
|
2016-02-20 03:53:29 +08:00
|
|
|
assert.True(t, v.Available > 0)
|
2016-02-21 03:37:17 +08:00
|
|
|
assert.Equal(t, v.Available, v.Free+v.Inactive, "%v", v)
|
2016-02-20 03:53:29 +08:00
|
|
|
|
|
|
|
assert.True(t, v.Used > 0)
|
|
|
|
assert.True(t, v.Used < v.Total)
|
|
|
|
|
|
|
|
assert.True(t, v.UsedPercent > 0)
|
|
|
|
assert.True(t, v.UsedPercent < 100)
|
|
|
|
|
|
|
|
assert.True(t, v.Free > 0)
|
|
|
|
assert.True(t, v.Free < v.Available)
|
|
|
|
|
|
|
|
assert.True(t, v.Active > 0)
|
|
|
|
assert.True(t, v.Active < v.Total)
|
|
|
|
|
|
|
|
assert.True(t, v.Inactive > 0)
|
|
|
|
assert.True(t, v.Inactive < v.Total)
|
|
|
|
|
|
|
|
assert.True(t, v.Wired > 0)
|
|
|
|
assert.True(t, v.Wired < v.Total)
|
|
|
|
}
|