From: Michael Stapelberg Date: Mon, 25 Jul 2011 11:35:56 +0000 (+0200) Subject: tests: get the socket path from the X11 atom I3_SOCKET_PATH X-Git-Tag: 4.0~14^2~48 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=49ea8059052d74d09ca4fb11e889340349813072;p=i3%2Fi3 tests: get the socket path from the X11 atom I3_SOCKET_PATH The hard-coded socket paths are not useful when running the test suite in parallel. --- diff --git a/testcases/i3-test.config b/testcases/i3-test.config index ae9c0a98..4f59205e 100644 --- a/testcases/i3-test.config +++ b/testcases/i3-test.config @@ -8,9 +8,6 @@ font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 # Use Mouse+Mod1 to drag floating windows to their wanted position floating_modifier Mod1 -# temporary path during development -ipc-socket /tmp/nestedcons - # Open empty container bindsym Mod1+Shift+Return open diff --git a/testcases/t/02-fullscreen.t b/testcases/t/02-fullscreen.t index 258eec99..34e5364e 100644 --- a/testcases/t/02-fullscreen.t +++ b/testcases/t/02-fullscreen.t @@ -5,7 +5,7 @@ use i3test; use X11::XCB qw(:all); use List::Util qw(first); -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/06-focus.t b/testcases/t/06-focus.t index 826588d5..d357c8a9 100644 --- a/testcases/t/06-focus.t +++ b/testcases/t/06-focus.t @@ -10,7 +10,7 @@ BEGIN { my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; ##################################################################### diff --git a/testcases/t/08-focus-stack.t b/testcases/t/08-focus-stack.t index 8a408267..f8143979 100644 --- a/testcases/t/08-focus-stack.t +++ b/testcases/t/08-focus-stack.t @@ -12,7 +12,7 @@ BEGIN { my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); fresh_workspace; cmd 'split h'; diff --git a/testcases/t/10-dock.t b/testcases/t/10-dock.t index 5fa35e1a..d4da8245 100644 --- a/testcases/t/10-dock.t +++ b/testcases/t/10-dock.t @@ -10,7 +10,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); ##################################################################### # verify that there is no dock window yet diff --git a/testcases/t/11-goto.t b/testcases/t/11-goto.t index ed8c4358..542dc828 100644 --- a/testcases/t/11-goto.t +++ b/testcases/t/11-goto.t @@ -11,7 +11,7 @@ BEGIN { my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; cmd 'split h'; diff --git a/testcases/t/14-client-leader.t b/testcases/t/14-client-leader.t index d5675e46..98978eb3 100644 --- a/testcases/t/14-client-leader.t +++ b/testcases/t/14-client-leader.t @@ -9,7 +9,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/15-ipc-workspaces.t b/testcases/t/15-ipc-workspaces.t index 0b4f819a..085163b2 100644 --- a/testcases/t/15-ipc-workspaces.t +++ b/testcases/t/15-ipc-workspaces.t @@ -4,7 +4,7 @@ use i3test; use List::MoreUtils qw(all); -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); #################### # Request workspaces diff --git a/testcases/t/16-nestedcons.t b/testcases/t/16-nestedcons.t index 7763ce79..f9d27262 100644 --- a/testcases/t/16-nestedcons.t +++ b/testcases/t/16-nestedcons.t @@ -5,7 +5,7 @@ use i3test; use List::MoreUtils qw(all none); use List::Util qw(first); -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); #################### # Request tree diff --git a/testcases/t/24-move.t b/testcases/t/24-move.t index b007d5b1..4df3a2a1 100644 --- a/testcases/t/24-move.t +++ b/testcases/t/24-move.t @@ -9,7 +9,7 @@ # use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/28-open-order.t b/testcases/t/28-open-order.t index f6b26b04..b638e708 100644 --- a/testcases/t/28-open-order.t +++ b/testcases/t/28-open-order.t @@ -6,7 +6,7 @@ use List::Util qw(first); use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t index fa9d86b5..ac029eb1 100644 --- a/testcases/t/29-focus-after-close.t +++ b/testcases/t/29-focus-after-close.t @@ -9,7 +9,7 @@ use List::Util qw(first); my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/30-close-empty-split.t b/testcases/t/30-close-empty-split.t index 9ed0ae95..57855cd5 100644 --- a/testcases/t/30-close-empty-split.t +++ b/testcases/t/30-close-empty-split.t @@ -5,7 +5,7 @@ # use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/31-stacking-order.t b/testcases/t/31-stacking-order.t index ea42596c..9c1e74ca 100644 --- a/testcases/t/31-stacking-order.t +++ b/testcases/t/31-stacking-order.t @@ -7,7 +7,7 @@ # use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/32-move-workspace.t b/testcases/t/32-move-workspace.t index 8730cdfb..3b50e39b 100644 --- a/testcases/t/32-move-workspace.t +++ b/testcases/t/32-move-workspace.t @@ -5,7 +5,7 @@ # use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); # We move the pointer out of our way to avoid a bug where the focus will # be set to the window under the cursor diff --git a/testcases/t/33-size-hints.t b/testcases/t/33-size-hints.t index a1464884..05897c88 100644 --- a/testcases/t/33-size-hints.t +++ b/testcases/t/33-size-hints.t @@ -5,7 +5,7 @@ # use i3test; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $x = X11::XCB::Connection->new; diff --git a/testcases/t/36-floating-ws-empty.t b/testcases/t/36-floating-ws-empty.t index 67986251..f33d04db 100644 --- a/testcases/t/36-floating-ws-empty.t +++ b/testcases/t/36-floating-ws-empty.t @@ -9,7 +9,7 @@ BEGIN { use_ok('X11::XCB::Window'); } -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/37-floating-unmap.t b/testcases/t/37-floating-unmap.t index bf596ada..3ae4b12d 100644 --- a/testcases/t/37-floating-unmap.t +++ b/testcases/t/37-floating-unmap.t @@ -10,7 +10,7 @@ BEGIN { use_ok('X11::XCB::Window'); } -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/38-floating-attach.t b/testcases/t/38-floating-attach.t index 9e5d7829..31bddafd 100644 --- a/testcases/t/38-floating-attach.t +++ b/testcases/t/38-floating-attach.t @@ -11,7 +11,7 @@ BEGIN { use_ok('X11::XCB::Window'); } -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/39-ws-numbers.t b/testcases/t/39-ws-numbers.t index bb688be3..3afd281b 100644 --- a/testcases/t/39-ws-numbers.t +++ b/testcases/t/39-ws-numbers.t @@ -9,7 +9,7 @@ BEGIN { use_ok('X11::XCB::Window'); } -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $x = X11::XCB::Connection->new; sub check_order { diff --git a/testcases/t/40-focus-lost.t b/testcases/t/40-focus-lost.t index a39d74ca..9df220d1 100644 --- a/testcases/t/40-focus-lost.t +++ b/testcases/t/40-focus-lost.t @@ -10,7 +10,7 @@ BEGIN { use_ok('X11::XCB::Window'); } -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $x = X11::XCB::Connection->new; sub check_order { diff --git a/testcases/t/50-regress-dock-restart.t b/testcases/t/50-regress-dock-restart.t index 6d78e939..a4f7bebc 100644 --- a/testcases/t/50-regress-dock-restart.t +++ b/testcases/t/50-regress-dock-restart.t @@ -11,7 +11,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/54-regress-multiple-dock.t b/testcases/t/54-regress-multiple-dock.t index 61e953f3..36070db1 100644 --- a/testcases/t/54-regress-multiple-dock.t +++ b/testcases/t/54-regress-multiple-dock.t @@ -11,7 +11,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/55-floating-split-size.t b/testcases/t/55-floating-split-size.t index c6f42b97..ecffbb12 100644 --- a/testcases/t/55-floating-split-size.t +++ b/testcases/t/55-floating-split-size.t @@ -12,7 +12,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/56-fullscreen-focus.t b/testcases/t/56-fullscreen-focus.t index 2027cbe0..ee60dc7a 100644 --- a/testcases/t/56-fullscreen-focus.t +++ b/testcases/t/56-fullscreen-focus.t @@ -12,7 +12,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/57-regress-fullscreen-level-up.t b/testcases/t/57-regress-fullscreen-level-up.t index 6b8c7be0..3e0b2fe1 100644 --- a/testcases/t/57-regress-fullscreen-level-up.t +++ b/testcases/t/57-regress-fullscreen-level-up.t @@ -11,7 +11,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/58-wm_take_focus.t b/testcases/t/58-wm_take_focus.t index eca3cef2..04c785ae 100644 --- a/testcases/t/58-wm_take_focus.t +++ b/testcases/t/58-wm_take_focus.t @@ -17,7 +17,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); subtest 'Window without WM_TAKE_FOCUS', sub { diff --git a/testcases/t/61-regress-borders-restart.t b/testcases/t/61-regress-borders-restart.t index 25a73b5d..1acf6c66 100644 --- a/testcases/t/61-regress-borders-restart.t +++ b/testcases/t/61-regress-borders-restart.t @@ -10,7 +10,7 @@ use List::Util qw(first); use i3test; my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; my $window = open_standard_window($x); diff --git a/testcases/t/62-regress-dock-urgent.t b/testcases/t/62-regress-dock-urgent.t index 78bf3e80..8d188738 100644 --- a/testcases/t/62-regress-dock-urgent.t +++ b/testcases/t/62-regress-dock-urgent.t @@ -12,7 +12,7 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3("/tmp/nestedcons"); +my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; diff --git a/testcases/t/66-assign.t b/testcases/t/66-assign.t index 06b4bf2b..8e701277 100644 --- a/testcases/t/66-assign.t +++ b/testcases/t/66-assign.t @@ -41,10 +41,12 @@ sub set_wm_class { # start a window and see that it does not get assigned with an empty config ##################################################################### +my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-'); + my ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; close($fh); diag("Starting i3"); @@ -52,6 +54,9 @@ my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c my $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); my $tmp = fresh_workspace; @@ -86,7 +91,7 @@ sleep 0.25; ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; say $fh q|assign "special" → targetws|; close($fh); @@ -95,6 +100,9 @@ $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $t $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); $tmp = fresh_workspace; @@ -134,6 +142,9 @@ $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $t $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); # initialize the target workspace, then go to a fresh one @@ -172,7 +183,7 @@ exit_gracefully($process->pid); ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; say $fh q|assign "special" → ~|; close($fh); @@ -181,6 +192,9 @@ $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $t $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); $tmp = fresh_workspace; diff --git a/testcases/t/67-workspace_layout.t b/testcases/t/67-workspace_layout.t index b9f697dc..cfe8bf64 100644 --- a/testcases/t/67-workspace_layout.t +++ b/testcases/t/67-workspace_layout.t @@ -22,10 +22,12 @@ my $i3_path = abs_path("../i3"); # other and no split containers are created ##################################################################### +my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-'); + my ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; close($fh); diag("Starting i3"); @@ -33,6 +35,9 @@ my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c my $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); my $tmp = fresh_workspace; @@ -57,7 +62,7 @@ exit_gracefully($process->pid); ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; say $fh "workspace_layout stacked"; close($fh); @@ -66,6 +71,9 @@ $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $t $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); $tmp = fresh_workspace; diff --git a/testcases/t/70-force_focus_wrapping.t b/testcases/t/70-force_focus_wrapping.t index 5bd68c79..020a3603 100644 --- a/testcases/t/70-force_focus_wrapping.t +++ b/testcases/t/70-force_focus_wrapping.t @@ -15,6 +15,7 @@ my $x = X11::XCB::Connection->new; # assuming we are run by complete-run.pl my $i3_path = abs_path("../i3"); +my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-'); ##################################################################### # 1: test the wrapping behaviour without force_focus_wrapping @@ -23,7 +24,7 @@ my $i3_path = abs_path("../i3"); my ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; close($fh); diag("Starting i3"); @@ -31,6 +32,9 @@ my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c my $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); my $tmp = fresh_workspace; @@ -69,7 +73,7 @@ exit_gracefully($process->pid); ($fh, $tmpfile) = tempfile(); say $fh "# i3 config file (v4)"; say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; -say $fh "ipc-socket /tmp/nestedcons"; +say $fh "ipc-socket $socketpath"; say $fh "force_focus_wrapping true"; close($fh); @@ -78,6 +82,9 @@ $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $t $process = Proc::Background->new($i3cmd); sleep 1; +# force update of the cached socket path in lib/i3test +get_socket_path(0); + diag("pid = " . $process->pid); $tmp = fresh_workspace; diff --git a/testcases/t/lib/i3test.pm b/testcases/t/lib/i3test.pm index 7bfad56a..bd40f565 100644 --- a/testcases/t/lib/i3test.pm +++ b/testcases/t/lib/i3test.pm @@ -14,9 +14,10 @@ use Try::Tiny; use v5.10; use Exporter (); -our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully workspace_exists focused_ws); +our @EXPORT = qw(get_workspace_names get_unused_workspace fresh_workspace get_ws_content get_ws get_focused open_empty_con open_standard_window get_dock_clients cmd does_i3_live exit_gracefully workspace_exists focused_ws get_socket_path); my $tester = Test::Builder->new(); +my $_cached_socket_path = undef; BEGIN { my $window_count = 0; @@ -69,7 +70,7 @@ sub open_empty_con { } sub get_workspace_names { - my $i3 = i3("/tmp/nestedcons"); + my $i3 = i3(get_socket_path()); my $tree = $i3->get_tree->recv; my @outputs = @{$tree->{nodes}}; my @cons; @@ -96,7 +97,7 @@ sub fresh_workspace { sub get_ws { my ($name) = @_; - my $i3 = i3("/tmp/nestedcons"); + my $i3 = i3(get_socket_path()); my $tree = $i3->get_tree->recv; my @outputs = @{$tree->{nodes}}; @@ -143,7 +144,7 @@ sub get_focused { sub get_dock_clients { my $which = shift; - my $tree = i3("/tmp/nestedcons")->get_tree->recv; + my $tree = i3(get_socket_path())->get_tree->recv; my @outputs = @{$tree->{nodes}}; # Children of all dockareas my @docked; @@ -164,7 +165,7 @@ sub get_dock_clients { } sub cmd { - i3("/tmp/nestedcons")->command(@_)->recv + i3(get_socket_path())->command(@_)->recv } sub workspace_exists { @@ -173,7 +174,7 @@ sub workspace_exists { } sub focused_ws { - my $i3 = i3("/tmp/nestedcons"); + my $i3 = i3(get_socket_path()); my $tree = $i3->get_tree->recv; my @outputs = @{$tree->{nodes}}; my @cons; @@ -186,7 +187,7 @@ sub focused_ws { } sub does_i3_live { - my $tree = i3('/tmp/nestedcons')->get_tree->recv; + my $tree = i3(get_socket_path())->get_tree->recv; my @nodes = @{$tree->{nodes}}; my $ok = (@nodes > 0); $tester->ok($ok, 'i3 still lives'); @@ -196,7 +197,7 @@ sub does_i3_live { # Tries to exit i3 gracefully (with the 'exit' cmd) or kills the PID if that fails sub exit_gracefully { my ($pid, $socketpath) = @_; - $socketpath ||= '/tmp/nestedcons'; + $socketpath ||= get_socket_path(); my $exited = 0; try { @@ -210,4 +211,22 @@ sub exit_gracefully { } } +# Gets the socket path from the I3_SOCKET_PATH atom stored on the X11 root window +sub get_socket_path { + my ($cache) = @_; + $cache ||= 1; + + if ($cache && defined($_cached_socket_path)) { + return $_cached_socket_path; + } + + my $x = X11::XCB::Connection->new; + my $atom = $x->atom(name => 'I3_SOCKET_PATH'); + my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256); + my $reply = $x->get_property_reply($cookie->{sequence}); + my $socketpath = $reply->{value}; + $_cached_socket_path = $socketpath; + return $socketpath; +} + 1