Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e87ea7f authored by David Duarte's avatar David Duarte Committed by Henri Chataing
Browse files

RootCanal: Replace GD logger by libbase logging

The GD logger in RootCanal wasn't working for VERBOSE and
DEBUG log levels because of the absence of InitFlags

libbase logging implements a Google-style C++ logging interface
which is easier to use in C++ than printf style specifiers

libbase is also available for the host so we use that instead
of the GD logger

To ease the migration and define a logging interface for rootcanal
a log.h header have been introduced to shim the old GD logger
style macros

The minimum log level on the host can be choosen via the
ANDROID_LOG_TAGS environement variable, for example
ANDROID_LOG_TAGS=*:v set the minimum log level to verbose

Test: Run root-canal
Change-Id: I88a33bc010b0be4724ef5956f9a664245c1d4e7e
parent 300ebb7d
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -31,11 +31,13 @@ cc_defaults {
    include_dirs: [
        "packages/modules/Bluetooth/system/gd",
    ],
    header_libs: [
        "libbase_headers",
    ],
    generated_headers: [
        "RootCanalGeneratedPackets_h",
        "RootCanalBrEdrBBGeneratedPackets_h",
        "BluetoothGeneratedPackets_h",
        "libbt_init_flags_bridge_header",
    ],
}

@@ -91,12 +93,12 @@ cc_library_static {
    export_generated_headers: [
        "BluetoothGeneratedPackets_h"
    ],
    shared_libs: [
        "liblog",
    ],
    whole_static_libs: [
        "liblmp",
    ],
    shared_libs: [
        "libbase",
    ],
    static_libs: [
        "libjsoncpp",
        "libscriptedbeaconpayload-protos-lite",
@@ -152,7 +154,7 @@ cc_test_host {
        ".",
    ],
    shared_libs: [
        "liblog",
        "libbase",
    ],
    static_libs: [
        "libbt-rootcanal",
@@ -186,7 +188,7 @@ cc_test_host {
        "packages/modules/Bluetooth/system/gd",
    ],
    shared_libs: [
        "liblog",
        "libbase",
    ],
    static_libs: [
        "libbt-rootcanal",
@@ -214,7 +216,7 @@ cc_binary_host {
        "libbluetooth_headers",
    ],
    shared_libs: [
        "liblog",
        "libbase",
        "libunwindstack",
    ],
    whole_static_libs: [
@@ -294,7 +296,9 @@ cc_library_static {
        "model/hci/h4_parser.cc",
        "model/hci/hci_protocol.cc",
    ],

    header_libs: [
        "libbase_headers",
    ],
    local_include_dirs: [
        "include",
    ],
@@ -302,9 +306,6 @@ cc_library_static {
        "include",
        ".",
    ],
    generated_headers: [
        "libbt_init_flags_bridge_header",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system/gd",
    ],
+8 −1
Original line number Diff line number Diff line
@@ -13,6 +13,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

// clang-format off
// This needs to be included before Backtrace.h to avoid a redefinition
// of DISALLOW_COPY_AND_ASSIGN
#include "log.h"
// clang-format on

#include <client/linux/handler/exception_handler.h>
#include <gflags/gflags.h>
#include <unwindstack/AndroidUnwinder.h>
@@ -23,7 +30,6 @@
#include "model/setup/async_manager.h"
#include "net/posix/posix_async_socket_connector.h"
#include "net/posix/posix_async_socket_server.h"
#include "os/log.h"
#include "test_environment.h"

using ::android::bluetooth::root_canal::TestEnvironment;
@@ -83,6 +89,7 @@ int main(int argc, char** argv) {
  eh.set_crash_handler(crash_callback);

  gflags::ParseCommandLineFlags(&argc, &argv, true);
  android::base::InitLogging(argv);

  LOG_INFO("main");
  uint16_t test_port = kTestPort;
+1 −1
Original line number Diff line number Diff line
@@ -21,13 +21,13 @@
#include <utility>      // for move
#include <vector>       // for vector

#include "log.h"  // for LOG_INFO, LOG_ERROR, LOG_WARN
#include "model/devices/baseband_sniffer.h"
#include "model/devices/link_layer_socket_device.h"  // for LinkLayerSocketDevice
#include "model/hci/hci_sniffer.h"                   // for HciSniffer
#include "model/hci/hci_socket_transport.h"          // for HciSocketTransport
#include "net/async_data_channel.h"                  // for AsyncDataChannel
#include "net/async_data_channel_connector.h"  // for AsyncDataChannelConnector
#include "os/log.h"  // for LOG_INFO, LOG_ERROR, LOG_WARN

namespace android {
namespace bluetooth {
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <android-base/format.h>
#include <android-base/logging.h>

// FIXME: remove those shims
#define LOG_DEBUG(...) LOG(DEBUG) << fmt::sprintf(__VA_ARGS__)
#define LOG_INFO(...) LOG(INFO) << fmt::sprintf(__VA_ARGS__)
#define LOG_WARN(...) LOG(WARNING) << fmt::sprintf(__VA_ARGS__)
#define LOG_ERROR(...) LOG(ERROR) << fmt::sprintf(__VA_ARGS__)
#define LOG_ALWAYS_FATAL(...) LOG(FATAL) << fmt::sprintf(__VA_ARGS__)

#define ASSERT(cond) CHECK(cond)
#define ASSERT_LOG(cond, ...) CHECK(cond) << fmt::sprintf(__VA_ARGS__)
+20 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// This header is currently needed for hci_packets.h
// FIXME: Change hci_packets.h to not depend on os/log.h
//        and remove this.
#include "include/log.h"
Loading