summaryrefslogtreecommitdiffstats
path: root/tools/xdisplaycheck
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 22:44:58 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-16 22:44:58 +0000
commitdbcda9bb32b1753395ebd40e0a3df9f47c0c8998 (patch)
treeca4806e9368d21fb15d60589a0d699b5ea98785d /tools/xdisplaycheck
parente942438457e9c464a758d79efc8279622e522ca5 (diff)
downloadchromium_src-dbcda9bb32b1753395ebd40e0a3df9f47c0c8998.zip
chromium_src-dbcda9bb32b1753395ebd40e0a3df9f47c0c8998.tar.gz
chromium_src-dbcda9bb32b1753395ebd40e0a3df9f47c0c8998.tar.bz2
Add a small untility for checking to see if the X server is alive.
This will be used by the buildbots after Xvfb is executated to make sure that Xvfb is alive. Review URL: http://codereview.chromium.org/126165 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/xdisplaycheck')
-rw-r--r--tools/xdisplaycheck/xdisplaycheck.cc43
-rw-r--r--tools/xdisplaycheck/xdisplaycheck.gyp21
2 files changed, 64 insertions, 0 deletions
diff --git a/tools/xdisplaycheck/xdisplaycheck.cc b/tools/xdisplaycheck/xdisplaycheck.cc
new file mode 100644
index 0000000..b7a9754
--- /dev/null
+++ b/tools/xdisplaycheck/xdisplaycheck.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// This is a small program that tries to connect to the X server. It
+// continually retries until it connects or 5 seconds pass. If it fails
+// to connect to the X server after 5 seconds, it returns an error code
+// of -1.
+//
+// This is to help verify that the X server is available before we start
+// start running tests on the build bots.
+
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <X11/Xlib.h>
+
+void Sleep(int duration_ms) {
+ struct timespec sleep_time, remaining;
+
+ // Contains the portion of duration_ms >= 1 sec.
+ sleep_time.tv_sec = duration_ms / 1000;
+ duration_ms -= sleep_time.tv_sec * 1000;
+
+ // Contains the portion of duration_ms < 1 sec.
+ sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds.
+
+ while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR)
+ sleep_time = remaining;
+}
+
+int main(int argc, char* argv[]) {
+ int kNumTries = 50;
+ for (int i = 0; i < kNumTries; ++i) {
+ Display* display = XOpenDisplay(NULL);
+ if (display)
+ return 0;
+ Sleep(100);
+ }
+
+ printf("Failed to connect to %s\n", XDisplayName(NULL));
+ return -1;
+}
diff --git a/tools/xdisplaycheck/xdisplaycheck.gyp b/tools/xdisplaycheck/xdisplaycheck.gyp
new file mode 100644
index 0000000..cb22c22
--- /dev/null
+++ b/tools/xdisplaycheck/xdisplaycheck.gyp
@@ -0,0 +1,21 @@
+# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'includes': [
+ '../../build/common.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'xdisplaycheck',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../build/linux/system.gyp:x11',
+ ],
+ 'sources': [
+ 'xdisplaycheck.cc',
+ ],
+ },
+ ],
+}