2014-04-23 11:26:21 +08:00
|
|
|
package gopsutil
|
|
|
|
|
|
|
|
import (
|
2014-04-23 16:57:47 +08:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2014-04-25 15:38:23 +08:00
|
|
|
"os"
|
2014-04-24 00:07:15 +08:00
|
|
|
"runtime"
|
2014-04-23 11:26:21 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-04-23 12:24:07 +08:00
|
|
|
func Test_Pids(t *testing.T) {
|
|
|
|
ret, err := Pids()
|
2014-04-23 11:26:21 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2014-04-23 12:24:07 +08:00
|
|
|
if len(ret) == 0 {
|
|
|
|
t.Errorf("could not get pids %v", ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Pid_exists(t *testing.T) {
|
2014-04-24 00:07:15 +08:00
|
|
|
check_pid := 1
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
check_pid = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
ret, err := Pid_exists(int32(check_pid))
|
2014-04-23 12:24:07 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ret == false {
|
|
|
|
t.Errorf("could not get init process %v", ret)
|
|
|
|
}
|
2014-04-23 16:57:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func Test_NewProcess(t *testing.T) {
|
2014-04-25 15:38:23 +08:00
|
|
|
check_pid := 1
|
2014-04-24 00:07:15 +08:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
check_pid = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
ret, err := NewProcess(int32(check_pid))
|
2014-04-23 16:57:47 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("error %v", err)
|
|
|
|
}
|
2014-04-23 12:24:07 +08:00
|
|
|
|
2014-04-23 16:57:47 +08:00
|
|
|
d, _ := json.Marshal(ret)
|
|
|
|
fmt.Println(string(d))
|
2014-04-23 11:26:21 +08:00
|
|
|
}
|
2014-04-25 15:29:15 +08:00
|
|
|
|
|
|
|
func Test_Process_memory_maps(t *testing.T) {
|
2014-04-25 15:34:32 +08:00
|
|
|
check_pid := os.Getpid()
|
2014-04-25 15:29:15 +08:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
check_pid = 0
|
|
|
|
}
|
|
|
|
ret, err := NewProcess(int32(check_pid))
|
|
|
|
|
|
|
|
mmaps, err := ret.Memory_Maps()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("memory map get error %v", err)
|
|
|
|
}
|
|
|
|
for _, m := range *mmaps {
|
|
|
|
fmt.Println(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|