2020-12-19 19:31:09 +01:00
|
|
|
package procmon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetProcPids(t *testing.T) {
|
|
|
|
pids := getProcPids("/proc")
|
|
|
|
|
|
|
|
if len(pids) == 0 {
|
|
|
|
t.Error("getProcPids() should not be 0", pids)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupPidDescriptors(t *testing.T) {
|
2021-03-19 19:05:45 +01:00
|
|
|
pidsFd := lookupPidDescriptors(fmt.Sprint("/proc/", myPid, "/fd/"), myPid)
|
2020-12-19 19:31:09 +01:00
|
|
|
if len(pidsFd) == 0 {
|
|
|
|
t.Error("getProcPids() should not be 0", pidsFd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupPidInProc(t *testing.T) {
|
|
|
|
// we expect that the inode 1 points to /dev/null
|
|
|
|
expect := "/dev/null"
|
2021-03-19 19:05:45 +01:00
|
|
|
foundPid := lookupPidInProc("/proc/", expect, "", myPid)
|
2021-02-06 15:29:24 +01:00
|
|
|
if foundPid == -1 {
|
|
|
|
t.Error("lookupPidInProc() should not return -1")
|
2020-12-19 19:31:09 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-19 19:05:45 +01:00
|
|
|
|
|
|
|
func BenchmarkGetProcs(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
getProcPids("/proc")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkLookupPidDescriptors(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
lookupPidDescriptors(fmt.Sprint("/proc/", myPid, "/fd/"), myPid)
|
|
|
|
}
|
|
|
|
}
|