pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Artem Titov | 40a7a35 | 2018-10-15 13:25:34 | [diff] [blame] | 11 | #include <memory> |
Jeremy Leconte | c6ae33f | 2022-11-22 10:06:47 | [diff] [blame] | 12 | #include <regex> |
| 13 | #include <string> |
| 14 | #include <vector> |
Oleh Prypin | 135aad0 | 2018-09-21 11:56:26 | [diff] [blame] | 15 | |
Danil Chapovalov | 40dc98a | 2019-08-12 11:40:47 | [diff] [blame] | 16 | #include "absl/debugging/failure_signal_handler.h" |
| 17 | #include "absl/debugging/symbolize.h" |
Artem Titov | bcb42f1 | 2020-08-11 10:19:18 | [diff] [blame] | 18 | #include "absl/flags/parse.h" |
| 19 | #include "test/gmock.h" |
Artem Titov | 40a7a35 | 2018-10-15 13:25:34 | [diff] [blame] | 20 | #include "test/test_main_lib.h" |
oprypin | 9b2f20c | 2017-08-29 12:51:57 | [diff] [blame] | 21 | |
Jeremy Leconte | c6ae33f | 2022-11-22 10:06:47 | [diff] [blame] | 22 | namespace { |
| 23 | |
| 24 | std::vector<std::string> ReplaceDashesWithUnderscores(int argc, char* argv[]) { |
| 25 | std::vector<std::string> args(argv, argv + argc); |
| 26 | for (std::string& arg : args) { |
| 27 | // Only replace arguments that starts with a dash. |
| 28 | if (!arg.empty() && arg[0] == '-') { |
| 29 | // Don't replace the 2 first characters. |
| 30 | auto begin = arg.begin() + 2; |
| 31 | // Replace dashes on the left of '=' or on all the arg if no '=' is found. |
| 32 | auto end = std::find(arg.begin(), arg.end(), '='); |
| 33 | std::replace(begin, end, '-', '_'); |
| 34 | } |
| 35 | } |
| 36 | return args; |
| 37 | } |
| 38 | |
| 39 | std::vector<char*> VectorOfStringsToVectorOfPointers( |
| 40 | std::vector<std::string>& input) { |
| 41 | std::vector<char*> output(input.size()); |
| 42 | for (size_t i = 0; i < input.size(); ++i) { |
| 43 | output[i] = &(input[i][0]); |
| 44 | } |
| 45 | return output; |
| 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 | [diff] [blame] | 50 | int main(int argc, char* argv[]) { |
Danil Chapovalov | 40dc98a | 2019-08-12 11:40:47 | [diff] [blame] | 51 | // Initialize the symbolizer to get a human-readable stack trace |
Mirko Bonadei | e6e7f6a | 2020-05-15 13:01:54 | [diff] [blame] | 52 | absl::InitializeSymbolizer(argv[0]); |
Artem Titov | bcb42f1 | 2020-08-11 10:19:18 | [diff] [blame] | 53 | testing::InitGoogleMock(&argc, argv); |
Jeremy Leconte | c6ae33f | 2022-11-22 10:06:47 | [diff] [blame] | 54 | // Before parsing the arguments with the absl flag library, any internal '-' |
| 55 | // characters will be converted to '_' characters to make sure the string is a |
| 56 | // valid attribute name. |
| 57 | std::vector<std::string> new_argv = ReplaceDashesWithUnderscores(argc, argv); |
| 58 | std::vector<char*> raw_new_argv = VectorOfStringsToVectorOfPointers(new_argv); |
| 59 | absl::ParseCommandLine(argc, &raw_new_argv[0]); |
Danil Chapovalov | 40dc98a | 2019-08-12 11:40:47 | [diff] [blame] | 60 | |
Christoffer Jansson | f1fa705 | 2022-11-08 12:56:19 | [diff] [blame] | 61 | // This absl handler use unsupported features/instructions on Fuchsia |
| 62 | #if !defined(WEBRTC_FUCHSIA) |
Mirko Bonadei | e6e7f6a | 2020-05-15 13:01:54 | [diff] [blame] | 63 | absl::FailureSignalHandlerOptions options; |
| 64 | absl::InstallFailureSignalHandler(options); |
Christoffer Jansson | f1fa705 | 2022-11-08 12:56:19 | [diff] [blame] | 65 | #endif |
Danil Chapovalov | 40dc98a | 2019-08-12 11:40:47 | [diff] [blame] | 66 | |
Artem Titov | 40a7a35 | 2018-10-15 13:25:34 | [diff] [blame] | 67 | std::unique_ptr<webrtc::TestMain> main = webrtc::TestMain::Create(); |
Artem Titov | bcb42f1 | 2020-08-11 10:19:18 | [diff] [blame] | 68 | int err_code = main->Init(); |
Artem Titov | 40a7a35 | 2018-10-15 13:25:34 | [diff] [blame] | 69 | if (err_code != 0) { |
| 70 | return err_code; |
oprypin | 9b2f20c | 2017-08-29 12:51:57 | [diff] [blame] | 71 | } |
Artem Titov | 40a7a35 | 2018-10-15 13:25:34 | [diff] [blame] | 72 | return main->Run(argc, argv); |
pbos@webrtc.org | af8d5af | 2013-07-09 08:02:33 | [diff] [blame] | 73 | } |