1 /******************************************************************************
2 *
3 * Copyright 2018 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #include <base/command_line.h>
20 #include <base/strings/string_piece.h>
21 #include <base/strings/string_util.h>
22 #include <bluetooth/log.h>
23 #include <gtest/gtest.h>
24
25 using namespace bluetooth;
26
main(int argc,char ** argv)27 int main(int argc, char** argv) {
28 ::testing::InitGoogleTest(&argc, argv);
29
30 if (base::CommandLine::InitializedForCurrentProcess()) {
31 log::fatal("base::CommandLine::Init should not be called twice");
32 return 1;
33 }
34
35 const char* log_level_arg = nullptr;
36 for (int i = 0; i < argc; ++i) {
37 if (base::StartsWith(base::StringPiece(argv[i]), base::StringPiece("--v="),
38 base::CompareCase::INSENSITIVE_ASCII)) {
39 log_level_arg = argv[i];
40 }
41 }
42 if (log_level_arg == nullptr) {
43 log_level_arg = "--v=0";
44 }
45 const char* logging_argv[] = {"bt_stack", log_level_arg};
46 // Init command line object with logging switches
47 if (!base::CommandLine::Init(2, logging_argv)) {
48 log::fatal("base::CommandLine::Init failed, arg0={}, arg1={}",
49 logging_argv[0], logging_argv[1]);
50 return 1;
51 }
52
53 logging::LoggingSettings log_settings;
54 if (!logging::InitLogging(log_settings)) {
55 log::error("Failed to set up logging");
56 }
57
58 // Android already logs thread_id, proc_id, timestamp, so disable those.
59 logging::SetLogItems(false, false, false, false);
60
61 return RUN_ALL_TESTS();
62 }
63