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);
23 my $i3 = i3(get_socket_path());
26 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
27 my ($outfh, $outname) = tempfile('/tmp/i3-ls-output.XXXXXX', UNLINK => 1);
29 cmd qq|exec ls -l /proc/self/fd >$outname && echo done >$tmp|;
31 open(my $fh, '<', $tmp);
32 # Block on the FIFO, this will return exactly when the command is done.
37 # Get the ls /proc/self/fd output
45 # Split lines, keep only those which are symlinks.
46 my @lines = grep { /->/ } split("\n", $output);
48 my %fds = map { /([0-9]+) -> (.+)$/; ($1, $2) } @lines;
50 # Filter out 0, 1, 2 (stdin, stdout, stderr).
55 # Filter out the fd which is caused by ls calling readdir().
56 for my $fd (keys %fds) {
57 delete $fds{$fd} if $fds{$fd} =~ m,^/proc/\d+/fd$,;
60 is(scalar keys %fds, 0, 'No file descriptors leaked');