github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/internal/procfs/procfs_linux_test.go (about) 1 package procfs 2 3 import ( 4 "os" 5 "path/filepath" 6 "regexp" 7 "runtime" 8 "testing" 9 10 "gotest.tools/assert" 11 ) 12 13 func TestPidOf(t *testing.T) { 14 pids, err := PidOf(filepath.Base(os.Args[0])) 15 assert.NilError(t, err) 16 assert.Check(t, len(pids) == 1) 17 assert.DeepEqual(t, pids[0], os.Getpid()) 18 } 19 20 func BenchmarkGetPids(b *testing.B) { 21 if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { 22 b.Skipf("not supported on GOOS=%s", runtime.GOOS) 23 } 24 25 re, err := regexp.Compile("(^|/)" + filepath.Base(os.Args[0]) + "$") 26 assert.Check(b, err == nil) 27 28 for i := 0; i < b.N; i++ { 29 pids := getPids(re) 30 31 b.StopTimer() 32 assert.Check(b, len(pids) > 0) 33 assert.Check(b, pids[0] == os.Getpid()) 34 b.StartTimer() 35 } 36 }