mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
0fc52ca6dd
Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
36 lines
707 B
Go
36 lines
707 B
Go
package procfs
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"gotest.tools/assert"
|
|
)
|
|
|
|
func TestPidOf(t *testing.T) {
|
|
pids, err := PidOf(filepath.Base(os.Args[0]))
|
|
assert.NilError(t, err)
|
|
assert.Check(t, len(pids) == 1)
|
|
assert.DeepEqual(t, pids[0], os.Getpid())
|
|
}
|
|
|
|
func BenchmarkGetPids(b *testing.B) {
|
|
if runtime.GOOS == "darwin" || runtime.GOOS == "windows" {
|
|
b.Skipf("not supported on GOOS=%s", runtime.GOOS)
|
|
}
|
|
|
|
re, err := regexp.Compile("(^|/)" + filepath.Base(os.Args[0]) + "$")
|
|
assert.Check(b, err == nil)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pids := getPids(re)
|
|
|
|
b.StopTimer()
|
|
assert.Check(b, len(pids) > 0)
|
|
assert.Check(b, pids[0] == os.Getpid())
|
|
b.StartTimer()
|
|
}
|
|
}
|