github.com/PandaGoAdmin/utils@v0.0.0-20211208134815-d5461603a00f/os_darwin_cgo_test.go (about)

     1  // +build darwin
     2  // +build cgo
     3  
     4  package kgo
     5  
     6  import (
     7  	"github.com/stretchr/testify/assert"
     8  	"os"
     9  	"testing"
    10  )
    11  
    12  func TestOS_Darwin_Cgo_CpuUsage(t *testing.T) {
    13  	var user, idle, total uint64
    14  	user, idle, total = KOS.CpuUsage()
    15  	assert.Greater(t, int(user), 0)
    16  	assert.Greater(t, int(idle), 0)
    17  	assert.Greater(t, int(total), 0)
    18  }
    19  
    20  func BenchmarkOS_Darwin_Cgo_CpuUsage(b *testing.B) {
    21  	b.ResetTimer()
    22  	for i := 0; i < b.N; i++ {
    23  		_, _, _ = KOS.CpuUsage()
    24  	}
    25  }
    26  
    27  func TestOS_Darwin_Cgo_GetProcessExecPath(t *testing.T) {
    28  	var res string
    29  
    30  	pid := os.Getpid()
    31  	res = KOS.GetProcessExecPath(pid)
    32  	assert.NotEmpty(t, res)
    33  }
    34  
    35  func BenchmarkOS_Darwin_Cgo_GetProcessExecPath(b *testing.B) {
    36  	b.ResetTimer()
    37  	pid := os.Getpid()
    38  	for i := 0; i < b.N; i++ {
    39  		KOS.GetProcessExecPath(pid)
    40  	}
    41  }