| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 30 seconds pass. If it fails | 6 // continually retries until it connects or 30 seconds pass. If it fails |
| 7 // to connect to the X server or fails to find needed functiona, it returns | 7 // to connect to the X server or fails to find needed functiona, it returns |
| 8 // an error code of -1. | 8 // an error code of -1. |
| 9 // | 9 // |
| 10 // This is to help verify that a useful X server is available before we start | 10 // This is to help verify that a useful 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 <string.h> | 15 #include <string.h> |
| 16 #include <time.h> | 16 #include <time.h> |
| 17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
| 18 | 18 |
| 19 #if defined(USE_AURA) | |
| 20 #include <X11/extensions/XInput2.h> | |
| 21 #endif | |
| 22 | |
| 23 void Sleep(int duration_ms) { | 19 void Sleep(int duration_ms) { |
| 24 struct timespec sleep_time, remaining; | 20 struct timespec sleep_time, remaining; |
| 25 | 21 |
| 26 // Contains the portion of duration_ms >= 1 sec. | 22 // Contains the portion of duration_ms >= 1 sec. |
| 27 sleep_time.tv_sec = duration_ms / 1000; | 23 sleep_time.tv_sec = duration_ms / 1000; |
| 28 duration_ms -= sleep_time.tv_sec * 1000; | 24 duration_ms -= sleep_time.tv_sec * 1000; |
| 29 | 25 |
| 30 // Contains the portion of duration_ms < 1 sec. | 26 // Contains the portion of duration_ms < 1 sec. |
| 31 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. | 27 sleep_time.tv_nsec = duration_ms * 1000 * 1000; // nanoseconds. |
| 32 | 28 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 Sleep(10 * tries); | 66 Sleep(10 * tries); |
| 71 } | 67 } |
| 72 | 68 |
| 73 if (!scoped_display.display()) { | 69 if (!scoped_display.display()) { |
| 74 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); | 70 fprintf(stderr, "Failed to connect to %s\n", XDisplayName(NULL)); |
| 75 return -1; | 71 return -1; |
| 76 } | 72 } |
| 77 | 73 |
| 78 fprintf(stderr, "Connected after %d retries\n", tries); | 74 fprintf(stderr, "Connected after %d retries\n", tries); |
| 79 | 75 |
| 80 #if defined(USE_AURA) | |
| 81 // Check for XInput2 | |
| 82 int opcode, event, err; | |
| 83 if (!XQueryExtension(scoped_display.display(), "XInputExtension", &opcode, | |
| 84 &event, &err)) { | |
| 85 fprintf(stderr, | |
| 86 "Failed to get XInputExtension on %s.\n", XDisplayName(NULL)); | |
| 87 return -2; | |
| 88 } | |
| 89 | |
| 90 int major = 2, minor = 0; | |
| 91 if (XIQueryVersion(scoped_display.display(), &major, &minor) == BadRequest) { | |
| 92 fprintf(stderr, | |
| 93 "Server does not have XInput2 on %s.\n", XDisplayName(NULL)); | |
| 94 return -3; | |
| 95 } | |
| 96 | |
| 97 // Ask for the list of devices. This can cause some Xvfb to crash. | |
| 98 int count = 0; | |
| 99 XIDeviceInfo* devices = | |
| 100 XIQueryDevice(scoped_display.display(), XIAllDevices, &count); | |
| 101 if (devices) | |
| 102 XIFreeDeviceInfo(devices); | |
| 103 | |
| 104 fprintf(stderr, | |
| 105 "XInput2 verified initially sane on %s.\n", XDisplayName(NULL)); | |
| 106 #endif | |
| 107 return 0; | 76 return 0; |
| 108 } | 77 } |
| 109 | 78 |
| 110 #if defined(LEAK_SANITIZER) | 79 #if defined(LEAK_SANITIZER) |
| 111 // XOpenDisplay leaks memory if it takes more than one try to connect. This | 80 // XOpenDisplay leaks memory if it takes more than one try to connect. This |
| 112 // causes LSan bots to fail. We don't care about memory leaks in xdisplaycheck | 81 // causes LSan bots to fail. We don't care about memory leaks in xdisplaycheck |
| 113 // anyway, so just disable LSan completely. | 82 // anyway, so just disable LSan completely. |
| 114 // This function isn't referenced from the executable itself. Make sure it isn't | 83 // This function isn't referenced from the executable itself. Make sure it isn't |
| 115 // stripped by the linker. | 84 // stripped by the linker. |
| 116 __attribute__((used)) | 85 __attribute__((used)) |
| 117 __attribute__((visibility("default"))) | 86 __attribute__((visibility("default"))) |
| 118 extern "C" int __lsan_is_turned_off() { return 1; } | 87 extern "C" int __lsan_is_turned_off() { return 1; } |
| 119 #endif | 88 #endif |
| OLD | NEW |