2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Verifies that i3 does not leak any file descriptors in 'exec'.
21 use File::Temp qw(:POSIX tempfile);
24 skip "Procfs not available on $^O", 1 if $^O eq 'openbsd';
26 my $i3 = i3(get_socket_path());
29 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
30 my ($outfh, $outname) = tempfile('/tmp/i3-ls-output.XXXXXX', UNLINK => 1);
32 cmd qq|exec ls -l /proc/self/fd >$outname && echo done >$tmp|;
34 open(my $fh, '<', $tmp);
35 # Block on the FIFO, this will return exactly when the command is done.
40 # Get the ls /proc/self/fd output
48 # Split lines, keep only those which are symlinks.
49 my @lines = grep { /->/ } split("\n", $output);
51 my %fds = map { /([0-9]+) -> (.+)$/; ($1, $2) } @lines;
53 # Filter out 0, 1, 2 (stdin, stdout, stderr).
58 # Filter out the fd which is caused by ls calling readdir().
59 for my $fd (keys %fds) {
60 delete $fds{$fd} if $fds{$fd} =~ m,^/proc/\d+/fd$,;
63 is(scalar keys %fds, 0, 'No file descriptors leaked');