• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/logging.h>
21 #include <base/strings/string_piece.h>
22 #include <base/strings/string_util.h>
23 #include <gtest/gtest.h>
24 
25 #include <string>
26 
27 #include "bt_trace.h"
28 
29 // Override LogMsg method so that we can output log via VLOG(1)
LogMsg(uint32_t trace_set_mask,const char * fmt_str,...)30 void LogMsg(uint32_t trace_set_mask, const char* fmt_str, ...) {
31   char buffer[256];
32   va_list args;
33   va_start(args, fmt_str);
34   vsnprintf(buffer, 256, fmt_str, args);
35   VLOG(1) << buffer;
36   va_end(args);
37 }
38 
main(int argc,char ** argv)39 int main(int argc, char** argv) {
40   ::testing::InitGoogleTest(&argc, argv);
41 
42   if (base::CommandLine::InitializedForCurrentProcess()) {
43     LOG(FATAL) << "base::CommandLine::Init should not be called twice";
44     return 1;
45   }
46 
47   const char* log_level_arg = nullptr;
48   for (int i = 0; i < argc; ++i) {
49     if (base::StartsWith(base::StringPiece(argv[i]), base::StringPiece("--v="),
50                          base::CompareCase::INSENSITIVE_ASCII)) {
51       log_level_arg = argv[i];
52     }
53   }
54   if (log_level_arg == nullptr) {
55     log_level_arg = "--v=0";
56   }
57   const char* logging_argv[] = {"bt_stack", log_level_arg};
58   // Init command line object with logging switches
59   if (!base::CommandLine::Init(2, logging_argv)) {
60     LOG(FATAL) << "base::CommandLine::Init failed, arg0=" << logging_argv[0]
61                << ", arg1=" << logging_argv[1];
62     return 1;
63   }
64 
65   logging::LoggingSettings log_settings;
66   if (!logging::InitLogging(log_settings)) {
67     LOG(ERROR) << "Failed to set up logging";
68   }
69 
70   // Android already logs thread_id, proc_id, timestamp, so disable those.
71   logging::SetLogItems(false, false, false, false);
72 
73   return RUN_ALL_TESTS();
74 }