henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | // |
| 11 | // A reuseable entry point for gunit tests. |
| 12 | |
| 13 | #if defined(WEBRTC_WIN) |
| 14 | #include <crtdbg.h> |
| 15 | #endif |
| 16 | |
| 17 | #include "webrtc/base/flags.h" |
| 18 | #include "webrtc/base/fileutils.h" |
| 19 | #include "webrtc/base/gunit.h" |
| 20 | #include "webrtc/base/logging.h" |
pbos@webrtc.org | 34f2a9e | 2014-09-28 11:36:45 +0000 | [diff] [blame] | 21 | #include "webrtc/base/ssladapter.h" |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 22 | #include "webrtc/test/field_trial.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 23 | |
| 24 | DEFINE_bool(help, false, "prints this message"); |
| 25 | DEFINE_string(log, "", "logging options to use"); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 26 | DEFINE_string( |
| 27 | force_fieldtrials, |
| 28 | "", |
| 29 | "Field trials control experimental feature code which can be forced. " |
| 30 | "E.g. running with --force_fieldtrials=WebRTC-FooFeature/Enable/" |
| 31 | " will assign the group Enable to field trial WebRTC-FooFeature."); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 32 | #if defined(WEBRTC_WIN) |
| 33 | DEFINE_int(crt_break_alloc, -1, "memory allocation to break on"); |
| 34 | DEFINE_bool(default_error_handlers, false, |
| 35 | "leave the default exception/dbg handler functions in place"); |
| 36 | |
| 37 | void TestInvalidParameterHandler(const wchar_t* expression, |
| 38 | const wchar_t* function, |
| 39 | const wchar_t* file, |
| 40 | unsigned int line, |
| 41 | uintptr_t pReserved) { |
| 42 | LOG(LS_ERROR) << "InvalidParameter Handler called. Exiting."; |
| 43 | LOG(LS_ERROR) << expression << std::endl << function << std::endl << file |
| 44 | << std::endl << line; |
| 45 | exit(1); |
| 46 | } |
| 47 | void TestPureCallHandler() { |
| 48 | LOG(LS_ERROR) << "Purecall Handler called. Exiting."; |
| 49 | exit(1); |
| 50 | } |
| 51 | int TestCrtReportHandler(int report_type, char* msg, int* retval) { |
| 52 | LOG(LS_ERROR) << "CrtReport Handler called..."; |
| 53 | LOG(LS_ERROR) << msg; |
| 54 | if (report_type == _CRT_ASSERT) { |
| 55 | exit(1); |
| 56 | } else { |
| 57 | *retval = 0; |
| 58 | return TRUE; |
| 59 | } |
| 60 | } |
Tommi | 0eefb4d | 2015-05-23 09:54:07 +0200 | [diff] [blame] | 61 | #endif // WEBRTC_WIN |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 62 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 63 | int main(int argc, char** argv) { |
| 64 | testing::InitGoogleTest(&argc, argv); |
henrike@webrtc.org | c50bf7c | 2014-05-14 18:24:13 +0000 | [diff] [blame] | 65 | rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 66 | if (FLAG_help) { |
henrike@webrtc.org | c50bf7c | 2014-05-14 18:24:13 +0000 | [diff] [blame] | 67 | rtc::FlagList::Print(NULL, false); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 71 | webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials); |
| 72 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 73 | #if defined(WEBRTC_WIN) |
| 74 | if (!FLAG_default_error_handlers) { |
| 75 | // Make sure any errors don't throw dialogs hanging the test run. |
| 76 | _set_invalid_parameter_handler(TestInvalidParameterHandler); |
| 77 | _set_purecall_handler(TestPureCallHandler); |
| 78 | _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, TestCrtReportHandler); |
| 79 | } |
| 80 | |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame^] | 81 | #if !defined(NDEBUG) // Turn on memory leak checking on Windows. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 82 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF |_CRTDBG_LEAK_CHECK_DF); |
| 83 | if (FLAG_crt_break_alloc >= 0) { |
| 84 | _crtBreakAlloc = FLAG_crt_break_alloc; |
| 85 | } |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame^] | 86 | #endif |
Tommi | 0eefb4d | 2015-05-23 09:54:07 +0200 | [diff] [blame] | 87 | #endif // WEBRTC_WIN |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 88 | |
| 89 | rtc::Filesystem::SetOrganizationName("google"); |
| 90 | rtc::Filesystem::SetApplicationName("unittest"); |
| 91 | |
| 92 | // By default, log timestamps. Allow overrides by used of a --log flag. |
| 93 | rtc::LogMessage::LogTimestamps(); |
| 94 | if (*FLAG_log != '\0') { |
Tommi | 0eefb4d | 2015-05-23 09:54:07 +0200 | [diff] [blame] | 95 | rtc::LogMessage::ConfigureLogging(FLAG_log); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 96 | } |
| 97 | |
pbos@webrtc.org | 34f2a9e | 2014-09-28 11:36:45 +0000 | [diff] [blame] | 98 | // Initialize SSL which are used by several tests. |
| 99 | rtc::InitializeSSL(); |
| 100 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 101 | int res = RUN_ALL_TESTS(); |
| 102 | |
pbos@webrtc.org | 34f2a9e | 2014-09-28 11:36:45 +0000 | [diff] [blame] | 103 | rtc::CleanupSSL(); |
| 104 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 105 | // clean up logging so we don't appear to leak memory. |
Tommi | 0eefb4d | 2015-05-23 09:54:07 +0200 | [diff] [blame] | 106 | rtc::LogMessage::ConfigureLogging(""); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 107 | |
| 108 | #if defined(WEBRTC_WIN) |
| 109 | // Unhook crt function so that we don't ever log after statics have been |
| 110 | // uninitialized. |
| 111 | if (!FLAG_default_error_handlers) |
| 112 | _CrtSetReportHook2(_CRT_RPTHOOK_REMOVE, TestCrtReportHandler); |
| 113 | #endif |
| 114 | |
| 115 | return res; |
| 116 | } |