]> git.sur5r.net Git - i3/i3/blob - testcases/t/229-cleanup-tmpdir.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 229-cleanup-tmpdir.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Makes sure i3 deletes its temporary directory when exiting.
18 # Ticket: #1253
19 # Bug still in: 4.7.2-186-g617afc6
20 use i3test i3_autostart => 0;
21 use File::Basename;
22 use File::Temp qw(tempfile tempdir);
23 use X11::XCB qw(:all);
24
25 my $config = <<EOT;
26 # i3 config file (v4)
27 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
28 EOT
29
30 # ensure XDG_RUNTIME_DIR is not set
31 delete $ENV{XDG_RUNTIME_DIR};
32
33 my $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
34 my $socketpath = get_socket_path(0);
35 my $tmpdir = dirname($socketpath);
36
37 ok(-d $tmpdir, "tmpdir $tmpdir exists");
38
39 # Clear the error logfile. The testsuite runs in an environment where RandR is
40 # not supported, so there always is a message about xinerama in the error
41 # logfile.
42 my @errorlogfiles = <$tmpdir/errorlog.*>;
43 for my $fn (@errorlogfiles) {
44     open(my $fh, '>', $fn);
45     close($fh);
46 }
47
48 exit_gracefully($pid);
49
50 ok(! -d $tmpdir, "tmpdir $tmpdir was cleaned up");
51 if (-d $tmpdir) {
52     diag('contents = ' . Dumper(<$tmpdir/*>));
53 }
54
55 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
56 $socketpath = get_socket_path(0);
57 $tmpdir = dirname($socketpath);
58
59 ok(-d $tmpdir, "tmpdir $tmpdir exists");
60
61 # Clear the error logfile. The testsuite runs in an environment where RandR is
62 # not supported, so there always is a message about xinerama in the error
63 # logfile.
64 @errorlogfiles = <$tmpdir/errorlog.*>;
65 for my $fn (@errorlogfiles) {
66     open(my $fh, '>', $fn);
67     close($fh);
68 }
69
70 diag('socket path before restarting is ' . $socketpath);
71
72 cmd 'restart';
73
74 # The socket path will be different, and we use that for checking whether i3 has restarted yet.
75 while (get_socket_path(0) eq $socketpath) {
76     sleep 0.1;
77 }
78
79 my $new_tmpdir = dirname(get_socket_path());
80
81 does_i3_live;
82
83 # Clear the error logfile. The testsuite runs in an environment where RandR is
84 # not supported, so there always is a message about xinerama in the error
85 # logfile.
86 @errorlogfiles = <$new_tmpdir/errorlog.*>;
87 for my $fn (@errorlogfiles) {
88     open(my $fh, '>', $fn);
89     close($fh);
90 }
91
92 exit_gracefully($pid);
93
94 ok(! -d $tmpdir, "old tmpdir $tmpdir was cleaned up");
95 if (-d $tmpdir) {
96     diag('contents = ' . Dumper(<$tmpdir/*>));
97 }
98
99 ok(! -d $new_tmpdir, "new tmpdir $new_tmpdir was cleaned up");
100 if (-d $new_tmpdir) {
101     diag('contents = ' . Dumper(<$new_tmpdir/*>));
102 }
103
104 ################################################################################
105 # Regression: with a socket path outside of tmpdir, i3 would delete the tmpdir
106 # prematurely and could not use it for storing the restart layout.
107 ################################################################################
108
109 # Set XDG_RUNTIME_DIR to a temp directory so that i3 will create its directory
110 # in there and we’ll be able to find it. Necessary because we cannot deduce the
111 # temp directory from the socket path (which we explicitly set).
112 $ENV{XDG_RUNTIME_DIR} = tempdir(CLEANUP => 1);
113
114 my ($outfh, $outname) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
115 $config = <<EOT;
116 # i3 config file (v4)
117 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
118
119 ipc-socket $outname
120 EOT
121
122 $pid = launch_with_config($config, dont_add_socket_path => 1, dont_create_temp_dir => 1);
123 $socketpath = get_socket_path(0);
124
125 sub get_config_path {
126     my $atom = $x->atom(name => 'I3_CONFIG_PATH');
127     my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256);
128     my $reply = $x->get_property_reply($cookie->{sequence});
129     return $reply->{value};
130 }
131
132 my ($outfh2, $outname2) = tempfile('/tmp/i3-socket.XXXXXX', UNLINK => 1);
133 my $config_path = get_config_path();
134 open(my $configfh, '>', $config_path);
135 say $configfh <<EOT;
136 # i3 config file (v4)
137 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
138 ipc-socket $outname2
139 EOT
140 close($configfh);
141 $tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
142
143 ok(-d $tmpdir, "tmpdir $tmpdir exists");
144
145 # Clear the error logfile. The testsuite runs in an environment where RandR is
146 # not supported, so there always is a message about xinerama in the error
147 # logfile.
148 @errorlogfiles = <$tmpdir/errorlog.*>;
149 for my $fn (@errorlogfiles) {
150     open(my $fh, '>', $fn);
151     close($fh);
152 }
153
154 my $tmp = fresh_workspace;
155 my $win = open_window;
156 cmd 'border none';
157 my ($nodes, $focus) = get_ws_content($tmp);
158 is($nodes->[0]->{border}, 'none', 'border is none');
159
160 cmd 'restart';
161
162 # The socket path will be different, and we use that for checking whether i3 has restarted yet.
163 while (get_socket_path(0) eq $socketpath) {
164     sleep 0.1;
165 }
166
167 $new_tmpdir = $ENV{XDG_RUNTIME_DIR} . '/i3';
168
169 does_i3_live;
170
171 ($nodes, $focus) = get_ws_content($tmp);
172 is($nodes->[0]->{border}, 'none', 'border still none after restart');
173
174 exit_gracefully($pid);
175
176 close($outfh);
177 close($outfh2);
178
179 done_testing;