Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #include "test/core/util/test_config.h" |
| 35 | |
Craig Tiller | e1e2475 | 2015-01-13 17:26:27 -0800 | [diff] [blame] | 36 | #include <signal.h> |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 37 | #include <stdbool.h> |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 38 | #include <stdio.h> |
| 39 | #include <stdlib.h> |
Muxi Yan | cf6eaa7 | 2016-11-28 13:43:42 -0800 | [diff] [blame^] | 40 | #include <string.h> |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 41 | |
| 42 | #include <grpc/support/alloc.h> |
| 43 | #include <grpc/support/log.h> |
| 44 | |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 45 | #include "src/core/lib/support/env.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 46 | #include "src/core/lib/support/string.h" |
Nicolas "Pixel" Noble | 80d68c0 | 2015-01-13 20:14:43 -0800 | [diff] [blame] | 47 | |
Craig Tiller | 7b9ed35 | 2015-08-04 08:55:12 -0700 | [diff] [blame] | 48 | double g_fixture_slowdown_factor = 1.0; |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 49 | double g_poller_slowdown_factor = 1.0; |
Craig Tiller | 7b9ed35 | 2015-08-04 08:55:12 -0700 | [diff] [blame] | 50 | |
Nicolas "Pixel" Noble | 80d68c0 | 2015-01-13 20:14:43 -0800 | [diff] [blame] | 51 | #if GPR_GETPID_IN_UNISTD_H |
ctiller | b3e3317 | 2015-01-05 14:40:53 -0800 | [diff] [blame] | 52 | #include <unistd.h> |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 53 | static unsigned seed(void) { return (unsigned)getpid(); } |
Nicolas "Pixel" Noble | 80d68c0 | 2015-01-13 20:14:43 -0800 | [diff] [blame] | 54 | #endif |
| 55 | |
| 56 | #if GPR_GETPID_IN_PROCESS_H |
| 57 | #include <process.h> |
Nicolas "Pixel" Noble | c4b18a5 | 2016-04-15 04:53:54 +0200 | [diff] [blame] | 58 | static unsigned seed(void) { return (unsigned)_getpid(); } |
Nicolas "Pixel" Noble | 80d68c0 | 2015-01-13 20:14:43 -0800 | [diff] [blame] | 59 | #endif |
ctiller | b3e3317 | 2015-01-05 14:40:53 -0800 | [diff] [blame] | 60 | |
Nicolas "Pixel" Noble | 717ea0e | 2015-07-11 22:50:09 +0200 | [diff] [blame] | 61 | #if GPR_WINDOWS_CRASH_HANDLER |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 62 | #include <windows.h> |
Craig Tiller | b195792 | 2016-03-16 17:22:57 -0700 | [diff] [blame] | 63 | |
| 64 | #include <tchar.h> |
| 65 | |
Craig Tiller | 2ed1a9e | 2016-03-16 20:09:43 -0700 | [diff] [blame] | 66 | // disable warning 4091 - dbghelp.h is broken for msvc2015 |
| 67 | #pragma warning(disable : 4091) |
Craig Tiller | c9c0b8b | 2016-03-16 14:57:29 -0700 | [diff] [blame] | 68 | #define DBGHELP_TRANSLATE_TCHAR |
| 69 | #include <dbghelp.h> |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 70 | |
Craig Tiller | c9c0b8b | 2016-03-16 14:57:29 -0700 | [diff] [blame] | 71 | #ifdef _MSC_VER |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 72 | #pragma comment(lib, "dbghelp.lib") |
Craig Tiller | c9c0b8b | 2016-03-16 14:57:29 -0700 | [diff] [blame] | 73 | #endif |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 74 | |
| 75 | static void print_current_stack() { |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 76 | typedef USHORT(WINAPI * CaptureStackBackTraceType)( |
| 77 | __in ULONG, __in ULONG, __out PVOID *, __out_opt PULONG); |
Craig Tiller | adf3a9d | 2016-03-16 14:59:36 -0700 | [diff] [blame] | 78 | CaptureStackBackTraceType func = (CaptureStackBackTraceType)(GetProcAddress( |
| 79 | LoadLibrary(_T("kernel32.dll")), "RtlCaptureStackBackTrace")); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 80 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 81 | if (func == NULL) return; // WOE 29.SEP.2010 |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 82 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 83 | // Quote from Microsoft Documentation: |
| 84 | // ## Windows Server 2003 and Windows XP: |
| 85 | // ## The sum of the FramesToSkip and FramesToCapture parameters must be less |
| 86 | // than 63. |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 87 | #define MAX_CALLERS 62 |
| 88 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 89 | void *callers_stack[MAX_CALLERS]; |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 90 | unsigned short frames; |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 91 | SYMBOL_INFOW *symbol; |
| 92 | HANDLE process; |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 93 | process = GetCurrentProcess(); |
| 94 | SymInitialize(process, NULL, TRUE); |
| 95 | frames = (func)(0, MAX_CALLERS, callers_stack, NULL); |
Craig Tiller | adf3a9d | 2016-03-16 14:59:36 -0700 | [diff] [blame] | 96 | symbol = |
| 97 | (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 98 | symbol->MaxNameLen = 255; |
| 99 | symbol->SizeOfStruct = sizeof(SYMBOL_INFOW); |
| 100 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 101 | const unsigned short MAX_CALLERS_SHOWN = 32; |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 102 | frames = frames < MAX_CALLERS_SHOWN ? frames : MAX_CALLERS_SHOWN; |
| 103 | for (unsigned int i = 0; i < frames; i++) { |
| 104 | SymFromAddrW(process, (DWORD64)(callers_stack[i]), 0, symbol); |
Craig Tiller | b195792 | 2016-03-16 17:22:57 -0700 | [diff] [blame] | 105 | fwprintf(stderr, L"*** %d: %016I64X %ls - %016I64X\n", i, |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 106 | (DWORD64)callers_stack[i], symbol->Name, (DWORD64)symbol->Address); |
Craig Tiller | bb84c6a | 2016-03-17 10:42:57 -0700 | [diff] [blame] | 107 | fflush(stderr); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | free(symbol); |
| 111 | } |
| 112 | |
| 113 | static void print_stack_from_context(CONTEXT c) { |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 114 | STACKFRAME s; // in/out stackframe |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 115 | memset(&s, 0, sizeof(s)); |
| 116 | DWORD imageType; |
| 117 | #ifdef _M_IX86 |
| 118 | // normally, call ImageNtHeader() and use machine info from PE header |
| 119 | imageType = IMAGE_FILE_MACHINE_I386; |
| 120 | s.AddrPC.Offset = c.Eip; |
| 121 | s.AddrPC.Mode = AddrModeFlat; |
| 122 | s.AddrFrame.Offset = c.Ebp; |
| 123 | s.AddrFrame.Mode = AddrModeFlat; |
| 124 | s.AddrStack.Offset = c.Esp; |
| 125 | s.AddrStack.Mode = AddrModeFlat; |
| 126 | #elif _M_X64 |
| 127 | imageType = IMAGE_FILE_MACHINE_AMD64; |
| 128 | s.AddrPC.Offset = c.Rip; |
| 129 | s.AddrPC.Mode = AddrModeFlat; |
| 130 | s.AddrFrame.Offset = c.Rsp; |
| 131 | s.AddrFrame.Mode = AddrModeFlat; |
| 132 | s.AddrStack.Offset = c.Rsp; |
| 133 | s.AddrStack.Mode = AddrModeFlat; |
| 134 | #elif _M_IA64 |
| 135 | imageType = IMAGE_FILE_MACHINE_IA64; |
| 136 | s.AddrPC.Offset = c.StIIP; |
| 137 | s.AddrPC.Mode = AddrModeFlat; |
| 138 | s.AddrFrame.Offset = c.IntSp; |
| 139 | s.AddrFrame.Mode = AddrModeFlat; |
| 140 | s.AddrBStore.Offset = c.RsBSP; |
| 141 | s.AddrBStore.Mode = AddrModeFlat; |
| 142 | s.AddrStack.Offset = c.IntSp; |
| 143 | s.AddrStack.Mode = AddrModeFlat; |
| 144 | #else |
| 145 | #error "Platform not supported!" |
| 146 | #endif |
| 147 | |
| 148 | HANDLE process = GetCurrentProcess(); |
| 149 | HANDLE thread = GetCurrentThread(); |
| 150 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 151 | SYMBOL_INFOW *symbol = |
Craig Tiller | c9c0b8b | 2016-03-16 14:57:29 -0700 | [diff] [blame] | 152 | (SYMBOL_INFOW *)calloc(sizeof(SYMBOL_INFOW) + 256 * sizeof(wchar_t), 1); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 153 | symbol->MaxNameLen = 255; |
| 154 | symbol->SizeOfStruct = sizeof(SYMBOL_INFOW); |
| 155 | |
Craig Tiller | 2b45cb8 | 2016-03-16 10:44:57 -0700 | [diff] [blame] | 156 | while (StackWalk(imageType, process, thread, &s, &c, 0, |
| 157 | SymFunctionTableAccess, SymGetModuleBase, 0)) { |
| 158 | BOOL has_symbol = |
| 159 | SymFromAddrW(process, (DWORD64)(s.AddrPC.Offset), 0, symbol); |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 160 | fwprintf( |
Craig Tiller | b195792 | 2016-03-16 17:22:57 -0700 | [diff] [blame] | 161 | stderr, L"*** %016I64X %ls - %016I64X\n", (DWORD64)(s.AddrPC.Offset), |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 162 | has_symbol ? symbol->Name : L"<<no symbol>>", (DWORD64)symbol->Address); |
Craig Tiller | bb84c6a | 2016-03-17 10:42:57 -0700 | [diff] [blame] | 163 | fflush(stderr); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | free(symbol); |
| 167 | } |
| 168 | |
| 169 | static LONG crash_handler(struct _EXCEPTION_POINTERS *ex_info) { |
| 170 | fprintf(stderr, "Exception handler called, dumping information\n"); |
| 171 | bool try_to_print_stack = true; |
| 172 | PEXCEPTION_RECORD exrec = ex_info->ExceptionRecord; |
| 173 | while (exrec) { |
| 174 | DWORD code = exrec->ExceptionCode; |
| 175 | DWORD flgs = exrec->ExceptionFlags; |
| 176 | PVOID addr = exrec->ExceptionAddress; |
| 177 | if (code == EXCEPTION_STACK_OVERFLOW) try_to_print_stack = false; |
| 178 | fprintf(stderr, "code: %x - flags: %d - address: %p\n", code, flgs, addr); |
| 179 | exrec = exrec->ExceptionRecord; |
| 180 | } |
| 181 | if (try_to_print_stack) { |
| 182 | print_stack_from_context(*ex_info->ContextRecord); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 183 | } |
| 184 | if (IsDebuggerPresent()) { |
| 185 | __debugbreak(); |
| 186 | } else { |
| 187 | _exit(1); |
| 188 | } |
Nicolas "Pixel" Noble | 717ea0e | 2015-07-11 22:50:09 +0200 | [diff] [blame] | 189 | return EXCEPTION_EXECUTE_HANDLER; |
| 190 | } |
| 191 | |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 192 | static void abort_handler(int sig) { |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 193 | fprintf(stderr, "Abort handler called.\n"); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 194 | print_current_stack(NULL); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 195 | if (IsDebuggerPresent()) { |
| 196 | __debugbreak(); |
| 197 | } else { |
| 198 | _exit(1); |
| 199 | } |
Nicolas "Pixel" Noble | e1d95d6 | 2015-07-14 02:08:50 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 202 | static void install_crash_handler() { |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 203 | if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) { |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 204 | fprintf(stderr, "SymInitialize failed: %d\n", GetLastError()); |
Craig Tiller | ce2b308 | 2016-03-16 10:43:49 -0700 | [diff] [blame] | 205 | } |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 206 | SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)crash_handler); |
| 207 | _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| 208 | _set_abort_behavior(0, _CALL_REPORTFAULT); |
| 209 | signal(SIGABRT, abort_handler); |
Nicolas "Pixel" Noble | 717ea0e | 2015-07-11 22:50:09 +0200 | [diff] [blame] | 210 | } |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 211 | #elif GPR_POSIX_CRASH_HANDLER |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 212 | #include <errno.h> |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 213 | #include <execinfo.h> |
Craig Tiller | 2befb68 | 2016-03-16 17:16:02 -0700 | [diff] [blame] | 214 | #include <grpc/support/useful.h> |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 215 | #include <stdio.h> |
| 216 | #include <string.h> |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 217 | |
Craig Tiller | 1b409a0 | 2016-04-29 11:26:38 -0700 | [diff] [blame] | 218 | static char g_alt_stack[GPR_MAX(MINSIGSTKSZ, 65536)]; |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 219 | |
| 220 | #define MAX_FRAMES 32 |
| 221 | |
Craig Tiller | 4e710f5 | 2015-09-30 07:38:49 -0700 | [diff] [blame] | 222 | /* signal safe output */ |
| 223 | static void output_string(const char *string) { |
| 224 | size_t len = strlen(string); |
| 225 | ssize_t r; |
| 226 | |
| 227 | do { |
| 228 | r = write(STDERR_FILENO, string, len); |
| 229 | } while (r == -1 && errno == EINTR); |
| 230 | } |
| 231 | |
| 232 | static void output_num(long num) { |
| 233 | char buf[GPR_LTOA_MIN_BUFSIZE]; |
| 234 | gpr_ltoa(num, buf); |
| 235 | output_string(buf); |
| 236 | } |
| 237 | |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 238 | static void crash_handler(int signum, siginfo_t *info, void *data) { |
| 239 | void *addrlist[MAX_FRAMES + 1]; |
| 240 | int addrlen; |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 241 | |
Craig Tiller | 4e710f5 | 2015-09-30 07:38:49 -0700 | [diff] [blame] | 242 | output_string("\n\n\n*******************************\nCaught signal "); |
| 243 | output_num(signum); |
| 244 | output_string("\n"); |
| 245 | |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 246 | addrlen = backtrace(addrlist, GPR_ARRAY_SIZE(addrlist)); |
| 247 | |
Craig Tiller | 3a12dcf | 2015-09-30 07:47:08 -0700 | [diff] [blame] | 248 | if (addrlen == 0) { |
| 249 | output_string(" no backtrace\n"); |
| 250 | } else { |
Craig Tiller | 2c0b91d | 2015-09-30 07:49:59 -0700 | [diff] [blame] | 251 | backtrace_symbols_fd(addrlist, addrlen, STDERR_FILENO); |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 252 | } |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 253 | |
Craig Tiller | 4bf2928 | 2015-12-14 11:25:48 -0800 | [diff] [blame] | 254 | /* try to get a core dump for SIGTERM */ |
| 255 | if (signum == SIGTERM) signum = SIGQUIT; |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 256 | raise(signum); |
| 257 | } |
| 258 | |
| 259 | static void install_crash_handler() { |
| 260 | stack_t ss; |
| 261 | struct sigaction sa; |
Craig Tiller | 4e710f5 | 2015-09-30 07:38:49 -0700 | [diff] [blame] | 262 | |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 263 | memset(&ss, 0, sizeof(ss)); |
| 264 | memset(&sa, 0, sizeof(sa)); |
| 265 | ss.ss_size = sizeof(g_alt_stack); |
| 266 | ss.ss_sp = g_alt_stack; |
| 267 | GPR_ASSERT(sigaltstack(&ss, NULL) == 0); |
| 268 | sa.sa_flags = (int)(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); |
| 269 | sa.sa_sigaction = crash_handler; |
| 270 | GPR_ASSERT(sigaction(SIGILL, &sa, NULL) == 0); |
| 271 | GPR_ASSERT(sigaction(SIGABRT, &sa, NULL) == 0); |
| 272 | GPR_ASSERT(sigaction(SIGBUS, &sa, NULL) == 0); |
| 273 | GPR_ASSERT(sigaction(SIGSEGV, &sa, NULL) == 0); |
Craig Tiller | 4bf2928 | 2015-12-14 11:25:48 -0800 | [diff] [blame] | 274 | GPR_ASSERT(sigaction(SIGTERM, &sa, NULL) == 0); |
| 275 | GPR_ASSERT(sigaction(SIGQUIT, &sa, NULL) == 0); |
Craig Tiller | 2bc3729 | 2015-09-28 10:08:21 -0700 | [diff] [blame] | 276 | } |
Nicolas "Pixel" Noble | 717ea0e | 2015-07-11 22:50:09 +0200 | [diff] [blame] | 277 | #else |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 278 | static void install_crash_handler() {} |
Nicolas "Pixel" Noble | 717ea0e | 2015-07-11 22:50:09 +0200 | [diff] [blame] | 279 | #endif |
| 280 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 281 | void grpc_test_init(int argc, char **argv) { |
| 282 | install_crash_handler(); |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 283 | { /* poll-cv poll strategy runs much more slowly than anything else */ |
| 284 | char *s = gpr_getenv("GRPC_POLL_STRATEGY"); |
| 285 | if (s != NULL && 0 == strcmp(s, "poll-cv")) { |
| 286 | g_poller_slowdown_factor = 5.0; |
| 287 | } |
| 288 | gpr_free(s); |
| 289 | } |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 290 | gpr_log(GPR_DEBUG, "test slowdown: machine=%f build=%f poll=%f total=%f", |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 291 | (double)GRPC_TEST_SLOWDOWN_MACHINE_FACTOR, |
Craig Tiller | f2876ea | 2016-11-28 08:57:48 -0800 | [diff] [blame] | 292 | (double)GRPC_TEST_SLOWDOWN_BUILD_FACTOR, g_poller_slowdown_factor, |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 293 | (double)GRPC_TEST_SLOWDOWN_FACTOR); |
ctiller | b3e3317 | 2015-01-05 14:40:53 -0800 | [diff] [blame] | 294 | /* seed rng with pid, so we don't end up with the same random numbers as a |
| 295 | concurrently running test binary */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 296 | srand(seed()); |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 297 | } |