Skip to content

Commit

Permalink
tests: print fd details if we find too many
Browse files Browse the repository at this point in the history
  • Loading branch information
rfjakob committed Jul 6, 2021
1 parent dea92ae commit bca302b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 1 addition & 11 deletions testsuite_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,7 @@ func TestCli(t *testing.T) {
t.Errorf("Memory usage too high! actual rss: %d, rssMax: %d", res.rss, rssMaxKiB)
pass = false
}
/*
$ ls -l /proc/42277/fd
total 0
lrwx------. 1 jakob jakob 64 Feb 22 14:36 0 -> /dev/pts/2
lrwx------. 1 jakob jakob 64 Feb 22 14:36 1 -> /dev/pts/2
lrwx------. 1 jakob jakob 64 Feb 22 14:36 2 -> /dev/pts/2
lr-x------. 1 jakob jakob 64 Feb 22 14:36 3 -> /proc/meminfo
Plus one for /proc/[pid]/stat which may possibly be open as well
*/
if res.fds > 5 {
if res.fds > openFdsMax {
t.Fatalf("High number of open file descriptors: %d", res.fds)
}
if !pass {
Expand Down
20 changes: 20 additions & 0 deletions testsuite_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func runEarlyoom(t *testing.T, args ...string) exitVals {
}
}

/*
$ ls -l /proc/$(pgrep earlyoom)/fd
total 0
lrwx------. 1 jakob jakob 64 Feb 22 14:36 0 -> /dev/pts/2
lrwx------. 1 jakob jakob 64 Feb 22 14:36 1 -> /dev/pts/2
lrwx------. 1 jakob jakob 64 Feb 22 14:36 2 -> /dev/pts/2
lr-x------. 1 jakob jakob 64 Feb 22 14:36 3 -> /proc/meminfo
Plus one for /proc/[pid]/stat which may possibly be open as well
*/
const openFdsMax = 5

func countFds(pid int) int {
dir := fmt.Sprintf("/proc/%d/fd", pid)
f, err := os.Open(dir)
Expand All @@ -105,6 +117,14 @@ func countFds(pid int) int {
if err != nil {
return -1
}
if len(names) > openFdsMax {
fmt.Printf("countFds: earlyoom has too many open fds:\n")
for _, n := range names {
linkName := fmt.Sprintf("%s/%s", dir, n)
linkTarget, err := os.Readlink(linkName)
fmt.Printf("%s -> %s, err=%v\n", linkName, linkTarget, err)
}
}
return len(names)
}

Expand Down

0 comments on commit bca302b

Please sign in to comment.