Merge lp:~compiz-team/compiz/compiz.fix_1178514 into lp:compiz/0.9.10

Proposed by Sam Spilsbury
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 3693
Merged at revision: 3694
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1178514
Merge into: lp:compiz/0.9.10
Diff against target: 234 lines (+161/-10)
5 files modified
plugins/decor/src/pixmap-requests/tests/integration/xorg-gtest/CMakeLists.txt (+1/-1)
tests/acceptance-tests/xorg-gtest/tests/CMakeLists.txt (+1/-1)
tests/system/xorg-gtest/tests/CMakeLists.txt (+1/-1)
tests/xorg-gtest/CMakeLists.txt (+4/-7)
tests/xorg-gtest/src/compiz_xorg_gtest_main.cpp (+154/-0)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1178514
Reviewer Review Type Date Requested Status
Sam Spilsbury Approve
PS Jenkins bot (community) continuous-integration Approve
MC Return Approve
Review via email: mp+163257@code.launchpad.net

Commit message

Try to launch tests on another server if there's tests running in parallel.

Provide our own compiz_xorg_gtest_main and subclass xorg::testing::Environment
to try and launch tests on another display if there's tests running on
one already.

This isn't by any means perfect - there are still race conditions
surrounding XOpenDisplay and parallel test runs but it makes a more smaller
time gap for conditions such as:
 1. Client has a server grab on the display we're checking
    and won't let go.
 2. Two servers get launched on one port and one set of tests
    interfere with the other.

It also means that we're now unable to configure the display port,
log file and config file on the command line. But we weren't using that
anyways.

Finally, the logs now point to /tmp/Compiz.Xorg.GTest.displaynum.log

(LP: #1178514)

Description of the change

Try to launch tests on another server if there's tests running in parallel.

Provide our own compiz_xorg_gtest_main and subclass xorg::testing::Environment
to try and launch tests on another display if there's tests running on
one already.

This isn't by any means perfect - there are still race conditions
surrounding XOpenDisplay and parallel test runs but it makes a more smaller
time gap for conditions such as:
 1. Client has a server grab on the display we're checking
    and won't let go.
 2. Two servers get launched on one port and one set of tests
    interfere with the other.

It also means that we're now unable to configure the display port,
log file and config file on the command line. But we weren't using that
anyways.

Finally, the logs now point to /tmp/Compiz.Xorg.GTest.displaynum.log

(LP: #1178514)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

Maybe a newline after:

137 + Display *check = XOpenDisplay (ss.str ().c_str ());

This looks like it is wrongly indented:

172 + if (environment)
173 + environment->Kill ();

here also:

215 + for (unsigned i = 0; i < sizeof(signals) / sizeof(signals[0]); ++i)
216 + if (sigaction(signals[i], &action, NULL))
217 + std::cerr << "Warning: Failed to set signal handler for signal "

Note: I did just check the .diff attached here -> maybe it just looks wrong...

3691. By Sam Spilsbury

Fix indentation

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

On Fri, May 10, 2013 at 3:11 PM, MC Return <email address hidden> wrote:
> Maybe a newline after:
>
> 137 + Display *check = XOpenDisplay (ss.str ().c_str ());
>
> This looks like it is wrongly indented:
>
> 172 + if (environment)
> 173 + environment->Kill ();
>
> here also:
>
> 215 + for (unsigned i = 0; i < sizeof(signals) / sizeof(signals[0]); ++i)
> 216 + if (sigaction(signals[i], &action, NULL))
> 217 + std::cerr << "Warning: Failed to set signal handler for signal "
>
> Note: I did just check the .diff attached here -> maybe it just looks wrong...

Ah, thanks for that. I've been working on a two-space project for a
few days now and didn't notice those.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

I think this change in r3691 is wrong:

55 std::stringstream ss;
 55 std::stringstream
5656 ss << ":" << displayNumber;
57 Display *check = XOpenDisplay (ss.str ().c_str ());
 57 Display *check = XOpenDisplay (ss.str ().c_

You need to initialize std::stringstream ss; seperately...

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

On Fri, May 10, 2013 at 5:36 PM, MC Return <email address hidden> wrote:
> I think this change in r3691 is wrong:
>
> 55 std::stringstream ss;
> 55 std::stringstream
> 5656 ss << ":" << displayNumber;
> 57 Display *check = XOpenDisplay (ss.str ().c_str ());
> 57 Display *check = XOpenDisplay (ss.str ().c_
>
> You need to initialize std::stringstream ss; seperately...

stringstream can only be initialized with a string buffer, or its
default constructor creates a new one. You can't put any content into
a stringstream from its constructor.

> --
> https://code.launchpad.net/~compiz-team/compiz/compiz.fix_1178514/+merge/163257
> Your team Compiz Maintainers is requested to review the proposed merge of lp:~compiz-team/compiz/compiz.fix_1178514 into lp:compiz.

--
Sam Spilsbury

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Wait, nope, scratch that, I'm an idiot. Fixed.

3692. By Sam Spilsbury

Fix accidentally removed variable

Revision history for this message
MC Return (mc-return) wrote :

> Wait, nope, scratch that, I'm an idiot. Fixed.

I ran into the same problem, when I cleaned up OpenGL (has not been proposed for merging yet), that is why I know you have to do it...

Revision history for this message
MC Return (mc-return) wrote :

LGTM now AFAICT.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
3693. By Sam Spilsbury

Fix truncated line

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/decor/src/pixmap-requests/tests/integration/xorg-gtest/CMakeLists.txt'
2--- plugins/decor/src/pixmap-requests/tests/integration/xorg-gtest/CMakeLists.txt 2013-04-22 14:30:55 +0000
3+++ plugins/decor/src/pixmap-requests/tests/integration/xorg-gtest/CMakeLists.txt 2013-05-11 01:07:32 +0000
4@@ -18,7 +18,7 @@
5
6 set (COMPIZ_DECOR_PIXMAP_PROTOCOL_XORG_INTEGRATION_TEST_LIBRARIES
7 xorg_gtest_all
8- xorg_gtest_main
9+ compiz_xorg_gtest_main
10 compiz_xorg_gtest_system_test
11 compiz_decor_pixmap_requests
12 compiz_decor_pixmap_requests_mock
13
14=== modified file 'tests/acceptance-tests/xorg-gtest/tests/CMakeLists.txt'
15--- tests/acceptance-tests/xorg-gtest/tests/CMakeLists.txt 2013-04-22 14:30:55 +0000
16+++ tests/acceptance-tests/xorg-gtest/tests/CMakeLists.txt 2013-05-11 01:07:32 +0000
17@@ -7,7 +7,7 @@
18 set (COMPIZ_XORG_ACCEPTANCE_TEST_LIBRARIES
19 compiz_xorg_gtest_system_test
20 xorg_gtest_all
21- xorg_gtest_main
22+ compiz_xorg_gtest_main
23 ${GTEST_BOTH_LIBRARIES}
24 ${XORG_SERVER_LIBRARIES}
25 ${X11_XI_LIBRARIES})
26
27=== modified file 'tests/system/xorg-gtest/tests/CMakeLists.txt'
28--- tests/system/xorg-gtest/tests/CMakeLists.txt 2013-04-22 14:30:55 +0000
29+++ tests/system/xorg-gtest/tests/CMakeLists.txt 2013-05-11 01:07:32 +0000
30@@ -31,7 +31,7 @@
31 set (COMPIZ_XORG_GTEST_LIBRARIES
32 compiz_xorg_gtest_system_test
33 xorg_gtest_all
34- xorg_gtest_main
35+ compiz_xorg_gtest_main
36 ${GTEST_BOTH_LIBRARIES}
37 ${XORG_SERVER_LIBRARIES}
38 ${X11_XI_LIBRARIES})
39
40=== modified file 'tests/xorg-gtest/CMakeLists.txt'
41--- tests/xorg-gtest/CMakeLists.txt 2013-04-22 14:30:55 +0000
42+++ tests/xorg-gtest/CMakeLists.txt 2013-05-11 01:07:32 +0000
43@@ -24,14 +24,11 @@
44 set (_xorg_gtest_all_srcs
45 ${XORG_SERVER_GTEST_SRC}/src/xorg-gtest-all.cpp)
46
47-set (_xorg_gtest_main_srcs
48- ${XORG_SERVER_GTEST_SRC}/src/xorg-gtest_main.cpp)
49-
50 add_library (xorg_gtest_all STATIC
51 ${_xorg_gtest_all_srcs})
52
53-add_library (xorg_gtest_main STATIC
54- ${_xorg_gtest_main_srcs})
55+add_library (compiz_xorg_gtest_main STATIC
56+ ${CMAKE_CURRENT_SOURCE_DIR}/src/compiz_xorg_gtest_main.cpp)
57
58 add_library (compiz_xorg_gtest_system_test STATIC
59 ${CMAKE_CURRENT_SOURCE_DIR}/src/compiz-xorg-gtest.cpp)
60@@ -43,13 +40,13 @@
61 ${GTEST_BOTH_LIBRARIES}
62 ${XORG_SERVER_GTEST_LIBRARIES})
63
64-target_link_libraries (xorg_gtest_main
65+target_link_libraries (compiz_xorg_gtest_main
66 ${GTEST_BOTH_LIBRARIES}
67 ${XORG_SERVER_GTEST_LIBRARIES})
68
69 target_link_libraries (compiz_xorg_gtest_system_test
70 xorg_gtest_all
71- xorg_gtest_main
72+ compiz_xorg_gtest_main
73 ${GTEST_BOTH_LIBRARIES}
74 ${XORG_SERVER_LIBRARIES}
75 ${COMPIZ_XORG_GTEST_COMMUNICATOR_LIBRARY}
76
77=== added file 'tests/xorg-gtest/src/compiz_xorg_gtest_main.cpp'
78--- tests/xorg-gtest/src/compiz_xorg_gtest_main.cpp 1970-01-01 00:00:00 +0000
79+++ tests/xorg-gtest/src/compiz_xorg_gtest_main.cpp 2013-05-11 01:07:32 +0000
80@@ -0,0 +1,154 @@
81+/*
82+ * Compiz XOrg GTest Decoration Pixmap Protocol Integration Tests
83+ *
84+ * Copyright (C) 2013 Sam Spilsbury.
85+ *
86+ * This library is free software; you can redistribute it and/or
87+ * modify it under the terms of the GNU Lesser General Public
88+ * License as published by the Free Software Foundation; either
89+ * version 2.1 of the License, or (at your option) any later version.
90+
91+ * This library is distributed in the hope that it will be useful,
92+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
93+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
94+ * Lesser General Public License for more details.
95+
96+ * You should have received a copy of the GNU Lesser General Public
97+ * License along with this library; if not, write to the Free Software
98+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
99+ *
100+ * Authored By:
101+ * Sam Spilsbury <smspillaz@gmail.com>
102+ */
103+
104+#include <csignal>
105+
106+#include <sstream>
107+#include <stdexcept>
108+
109+#include <gtest/gtest.h>
110+#include "xorg/gtest/xorg-gtest-environment.h"
111+
112+#include <X11/Xlib.h>
113+
114+namespace compiz
115+{
116+namespace testing
117+{
118+class XorgEnvironment :
119+ public xorg::testing::Environment
120+{
121+ public:
122+
123+ virtual void SetUp ()
124+ {
125+ /* Another hack - if the server fails
126+ * to start then just set another display
127+ * number until it does */
128+ const int MaxConnections = 255;
129+ int displayNumber = 0;
130+ bool serverRunningOnDisplay = true;
131+
132+ while (serverRunningOnDisplay &&
133+ displayNumber < MaxConnections)
134+ {
135+ std::stringstream ss;
136+ ss << ":" << displayNumber;
137+ Display *check = XOpenDisplay (ss.str ().c_str ());
138+
139+ if (!check)
140+ serverRunningOnDisplay = false;
141+ else
142+ {
143+ XCloseDisplay (check);
144+ ++displayNumber;
145+ }
146+ }
147+
148+ if (displayNumber == MaxConnections)
149+ throw std::runtime_error ("couldn't find a socket "
150+ "to launch on");
151+
152+ std::stringstream logFile;
153+ logFile << "/tmp/Compiz.Xorg.GTest." << displayNumber << ".log";
154+
155+ SetDisplayNumber (displayNumber);
156+ SetLogFile (logFile.str ());
157+ xorg::testing::Environment::SetUp ();
158+ }
159+};
160+}
161+}
162+
163+/* X testing environment - Google Test environment feat. dummy x server
164+ * Copyright (C) 2011, 2012 Canonical Ltd.
165+ */
166+compiz::testing::XorgEnvironment *environment = NULL;
167+
168+namespace
169+{
170+
171+void SignalHandler (int signum)
172+{
173+ if (environment)
174+ environment->Kill ();
175+
176+ /* This will call the default handler because we used SA_RESETHAND */
177+ raise (signum);
178+}
179+
180+void SetupSignalHandlers ()
181+{
182+ static const int signals[] =
183+ {
184+ SIGHUP,
185+ SIGTERM,
186+ SIGQUIT,
187+ SIGILL,
188+ SIGABRT,
189+ SIGFPE,
190+ SIGSEGV,
191+ SIGPIPE,
192+ SIGALRM,
193+ SIGTERM,
194+ SIGUSR1,
195+ SIGUSR2,
196+ SIGBUS,
197+ SIGPOLL,
198+ SIGPROF,
199+ SIGSYS,
200+ SIGTRAP,
201+ SIGVTALRM,
202+ SIGXCPU,
203+ SIGXFSZ,
204+ SIGIOT,
205+ SIGSTKFLT,
206+ SIGIO,
207+ SIGPWR,
208+ SIGUNUSED,
209+ };
210+
211+ struct sigaction action;
212+ action.sa_handler = SignalHandler;
213+ sigemptyset(&action.sa_mask);
214+ action.sa_flags = SA_RESETHAND;
215+
216+ for (unsigned i = 0; i < sizeof(signals) / sizeof(signals[0]); ++i)
217+ if (sigaction(signals[i], &action, NULL))
218+ std::cerr << "Warning: Failed to set signal handler for signal "
219+ << signals[i] << "\n";
220+}
221+}
222+
223+int main (int argc, char **argv)
224+{
225+ ::testing::InitGoogleTest (&argc, argv);
226+
227+ SetupSignalHandlers ();
228+
229+ environment = new compiz::testing::XorgEnvironment ();
230+ ::testing::AddGlobalTestEnvironment (environment);
231+
232+ return RUN_ALL_TESTS ();
233+}
234+

Subscribers

People subscribed via source and target branches

to all changes: