OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // This is a small program that tries to connect to the X server. It | 5 // This is a small program that tries to connect to the X server. It |
6 // continually retries until it connects or 5 seconds pass. If it fails | 6 // continually retries until it connects or 5 seconds pass. If it fails |
7 // to connect to the X server after 5 seconds, it returns an error code | 7 // to connect to the X server after 5 seconds, it returns an error code |
8 // of -1. | 8 // of -1. |
9 // | 9 // |
10 // This is to help verify that the X server is available before we start | 10 // This is to help verify that the X server is available before we start |
11 // start running tests on the build bots. | 11 // start running tests on the build bots. |
12 | 12 |
13 #include <errno.h> | 13 #include <errno.h> |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include <time.h> | 15 #include <time.h> |
16 #include <X11/Xlib.h> | 16 #include <X11/Xlib.h> |
17 #include <X11/extensions/XInput2.h> | |
Peter Mayo
2011/10/20 20:58:28
Does this not want to be wrapped in if defined() t
tony
2011/10/20 21:19:49
If the package is pulled in by install-build-deps.
sadrul
2011/10/20 21:42:38
I think it does. But added the check anyway to be
| |
17 | 18 |
18 void Sleep(int duration_ms) { | 19 void Sleep(int duration_ms) { |
19 struct timespec sleep_time, remaining; | 20 struct timespec sleep_time, remaining; |
20 | 21 |
21 // Contains the portion of duration_ms >= 1 sec. | 22 // Contains the portion of duration_ms >= 1 sec. |
22 sleep_time.tv_sec = duration_ms / 1000; | 23 sleep_time.tv_sec = duration_ms / 1000; |
23 duration_ms -= sleep_time.tv_sec * 1000; | 24 duration_ms -= sleep_time.tv_sec * 1000; |
24 | 25 |
25 // Contains the portion of duration_ms < 1 sec. | 26 // Contains the portion of duration_ms < 1 sec. |
26 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. | 27 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. |
27 | 28 |
28 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) | 29 while (nanosleep(&sleep_time, &remaining) == -1 && errno == EINTR) |
29 sleep_time = remaining; | 30 sleep_time = remaining; |
30 } | 31 } |
31 | 32 |
32 int main(int argc, char* argv[]) { | 33 int main(int argc, char* argv[]) { |
33 int kNumTries = 50; | 34 int kNumTries = 50; |
35 Display* display = NULL; | |
34 for (int i = 0; i < kNumTries; ++i) { | 36 for (int i = 0; i < kNumTries; ++i) { |
35 Display* display = XOpenDisplay(NULL); | 37 display = XOpenDisplay(NULL); |
36 if (display) | 38 if (display) |
37 return 0; | 39 break; |
38 Sleep(100); | 40 Sleep(100); |
39 } | 41 } |
40 | 42 |
41 printf("Failed to connect to %s\n", XDisplayName(NULL)); | 43 if (!display) { |
42 return -1; | 44 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); |
45 return -1; | |
46 } | |
47 | |
48 #if defined(TOUCH_UI) || defined(USE_AURA) | |
49 // Check for XInput2 | |
50 int opcode, event, err; | |
51 if (!XQueryExtension(display, "XInputExtension", &opcode, &event, &err)) { | |
52 fprintf(stderr, | |
53 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL)); | |
54 return -1; | |
55 } | |
56 | |
57 int major = 2, minor = 0; | |
58 if (XIQueryVersion(display, &major, &minor) == BadRequest) { | |
59 fprintf(stderr, | |
60 "Server does not have XInput2 on %s.\n", XDisplayName(NULL)); | |
61 return -1; | |
62 } | |
63 | |
64 // Ask for the list of devices. This can cause some Xvfb to crash. | |
65 int count = 0; | |
66 XIDeviceInfo* devices = XIQueryDevice(display, XIAllDevices, &count); | |
67 if (devices) | |
68 XIFreeDeviceInfo(devices); | |
69 #endif | |
70 | |
71 return 0; | |
43 } | 72 } |
OLD | NEW |