1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
package procmon
import (
"os"
"testing"
)
var (
myPid = os.Getpid()
proc = NewProcess(myPid, "fakeComm")
)
func TestNewProcess(t *testing.T) {
if proc.ID != myPid {
t.Error("NewProcess PID not equal to ", myPid)
}
if proc.Comm != "fakeComm" {
t.Error("NewProcess Comm not equal to fakeComm")
}
}
func TestProcPath(t *testing.T) {
if err := proc.ReadPath(); err != nil {
t.Error("Proc path error:", err)
}
if proc.Path == "/fake/path" {
t.Error("Proc path equal to /fake/path, should be different:", proc.Path)
}
}
func TestProcCwd(t *testing.T) {
err := proc.ReadCwd()
if proc.CWD == "" {
t.Error("Proc readCwd() not read:", err)
}
}
func TestProcCmdline(t *testing.T) {
proc.ReadCmdline()
if len(proc.Args) == 0 {
t.Error("Proc Args should not be empty:", proc.Args)
}
}
func TestProcDescriptors(t *testing.T) {
proc.readDescriptors()
if len(proc.Descriptors) == 0 {
t.Error("Proc Descriptors should not be empty:", proc.Descriptors)
}
}
func TestProcEnv(t *testing.T) {
proc.ReadEnv()
if len(proc.Env) == 0 {
t.Error("Proc Env should not be empty:", proc.Env)
}
}
func TestProcIOStats(t *testing.T) {
proc.readIOStats()
if proc.IOStats.RChar == 0 {
t.Error("Proc.IOStats.RChar should not be 0:", proc.IOStats)
}
if proc.IOStats.WChar == 0 {
t.Error("Proc.IOStats.WChar should not be 0:", proc.IOStats)
}
if proc.IOStats.SyscallRead == 0 {
t.Error("Proc.IOStats.SyscallRead should not be 0:", proc.IOStats)
}
if proc.IOStats.SyscallWrite == 0 {
t.Error("Proc.IOStats.SyscallWrite should not be 0:", proc.IOStats)
}
/*if proc.IOStats.ReadBytes == 0 {
t.Error("Proc.IOStats.ReadBytes should not be 0:", proc.IOStats)
}
if proc.IOStats.WriteBytes == 0 {
t.Error("Proc.IOStats.WriteBytes should not be 0:", proc.IOStats)
}*/
}
func TestProcStatus(t *testing.T) {
proc.readStatus()
if proc.Status == "" {
t.Error("Proc Status should not be empty:", proc)
}
if proc.Stat == "" {
t.Error("Proc Stat should not be empty:", proc)
}
/*if proc.Stack == "" {
t.Error("Proc Stack should not be empty:", proc)
}*/
if proc.Maps == "" {
t.Error("Proc Maps should not be empty:", proc)
}
if proc.Statm.Size == 0 {
t.Error("Proc Statm Size should not be 0:", proc.Statm)
}
if proc.Statm.Resident == 0 {
t.Error("Proc Statm Resident should not be 0:", proc.Statm)
}
if proc.Statm.Shared == 0 {
t.Error("Proc Statm Shared should not be 0:", proc.Statm)
}
if proc.Statm.Text == 0 {
t.Error("Proc Statm Text should not be 0:", proc.Statm)
}
if proc.Statm.Lib != 0 {
t.Error("Proc Statm Lib should not be 0:", proc.Statm)
}
if proc.Statm.Data == 0 {
t.Error("Proc Statm Data should not be 0:", proc.Statm)
}
if proc.Statm.Dt != 0 {
t.Error("Proc Statm Dt should not be 0:", proc.Statm)
}
}
func TestProcCleanPath(t *testing.T) {
proc.Path = "/fake/path/binary (deleted)"
proc.CleanPath()
if proc.Path != "/fake/path/binary" {
t.Error("Proc cleanPath() not cleaned:", proc.Path)
}
}
|