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

Commit b63c5cba authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

bt_headless: Update and verify all test modules am: b98008c9 am: 9889b2ea

parents 300deef4 9889b2ea
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ cc_binary {
        "HeadlessBuildTimestamp",
    ],
    srcs: [
        "bt_property.cc",
        "adapter/adapter.cc",
        "bt_stack_info.cc",
        "connect/connect.cc",
        "discovery/discovery.cc",
        "dumpsys/dumpsys.cc",
@@ -51,6 +52,7 @@ cc_binary {
        "log.cc",
        "main.cc",
        "messenger.cc",
        "mode/mode.cc",
        "nop/nop.cc",
        "pairing/pairing.cc",
        "property.cc",
@@ -59,11 +61,13 @@ cc_binary {
        "scan/scan.cc",
        "sdp/sdp.cc",
        "sdp/sdp_db.cc",
        "text.cc",
        "util.cc",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    static_libs: [
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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.
 */

#define LOG_TAG "bt_headless_scan"

#include "test/headless/adapter/adapter.h"

#include "base/logging.h"  // LOG() stdout and android log
#include "gd/os/log.h"
#include "test/headless/headless.h"
#include "test/headless/interface.h"
#include "test/headless/log.h"
#include "test/headless/messenger.h"
#include "test/headless/stopwatch.h"

using namespace bluetooth::test;
using namespace std::chrono_literals;

namespace {

unsigned kTimeoutMs = 5000;

int get_adapter_info([[maybe_unused]] unsigned int num_loops) {
  LOG(INFO) << "Started Device Adapter Properties";

  ASSERT(bluetoothInterface.get_adapter_properties() == BT_STATUS_SUCCESS);
  LOG_CONSOLE("Started get adapter properties");

  headless::messenger::Context context{
      .stop_watch = Stopwatch(__func__),
      .timeout = 1s,  // Poll time
      .check_point = {},
      .callbacks = {Callback::AdapterProperties},
  };

  bool adapter_properties_found = false;
  while (context.stop_watch.LapMs() < kTimeoutMs) {
    // If we have received callback results within this timeframe...
    if (headless::messenger::await_callback(context)) {
      while (!context.callback_ready_q.empty()) {
        std::shared_ptr<callback_params_t> p = context.callback_ready_q.front();
        context.callback_ready_q.pop_front();
        switch (p->CallbackType()) {
          case Callback::AdapterProperties: {
            adapter_properties_params_t* q =
                static_cast<adapter_properties_params_t*>(p.get());
            for (const auto& p2 : q->properties()) {
              LOG_CONSOLE("  %s prop:%s", p->Name().c_str(),
                          p2->ToString().c_str());
            }
            adapter_properties_found = true;
          } break;
          default:
            LOG_CONSOLE("WARN Received callback for unasked:%s",
                        p->Name().c_str());
            break;
        }
      }
    }
    if (adapter_properties_found) break;
  }

  LOG_CONSOLE("Retrieved adapter properties");
  return 0;
}

}  // namespace

int bluetooth::test::headless::Adapter::Run() {
  if (options_.loop_ < 1) {
    LOG_CONSOLE("This test requires at least a single loop");
    options_.Usage();
    return -1;
  }
  return RunOnHeadlessStack<int>(
      [this]() { return get_adapter_info(options_.loop_); });
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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 "test/headless/get_options.h"
#include "test/headless/headless.h"

namespace bluetooth {
namespace test {
namespace headless {

class Adapter : public HeadlessTest<int> {
 public:
  Adapter(const bluetooth::test::headless::GetOpt& options)
      : HeadlessTest<int>(options) {}
  virtual ~Adapter() = default;

  int Run() override;
};

}  // namespace headless
}  // namespace test
}  // namespace bluetooth
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 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.
 */

extern "C" {
struct android_namespace_t* android_get_exported_namespace(const char*) {
  return nullptr;
}
}  // "C"
+0 −123
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.
 */

#define LOG_TAG "bt_headless_property"

#include "test/headless/bt_property.h"

#include "base/logging.h"  // LOG() stdout and android log
#include "btif/include/btif_api.h"
#include "osi/include/log.h"  // android log only
#include "stack/include/sdp_api.h"
#include "test/headless/get_options.h"
#include "test/headless/headless.h"
#include "test/headless/interface.h"
#include "test/headless/log.h"
#include "test/headless/sdp/sdp.h"
#include "test/headless/stopwatch.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

using namespace bluetooth::test::headless;
using namespace std::chrono_literals;

namespace bluetooth {
namespace test {
namespace headless {

void process_property(const RawAddress& bd_addr, const bt_property_t* prop) {
  LOG_INFO("%s bt_property type:%d len:%d val:%p",
           ADDRESS_TO_LOGGABLE_CSTR(bd_addr), prop->type,
           prop->len, prop->val);
  switch (prop->type) {
    case BT_PROPERTY_BDNAME: {
      ASSERT(prop->len >= 0);
      std::string name(static_cast<const char*>(prop->val),
                       static_cast<size_t>(prop->len));
      LOG_CONSOLE("BT_PROPERTY_BDNAME  NAME:%s", name.c_str());
    } break;
    case BT_PROPERTY_BDADDR:
      LOG_CONSOLE("BT_PROPERTY_BDADDR");
      break;
    case BT_PROPERTY_UUIDS: {
      const size_t remainder = prop->len % sizeof(bluetooth::Uuid);
      ASSERT(remainder == 0);
      bluetooth::Uuid* uuid = reinterpret_cast<bluetooth::Uuid*>(prop->val);
      for (int len = prop->len; len > 0; len -= sizeof(*uuid)) {
        LOG_CONSOLE("BT_PROPERTY_UUIDS  UUID:%s", uuid->ToString().c_str());
        uuid++;
      }
    } break;
    case BT_PROPERTY_CLASS_OF_DEVICE: {
      ASSERT(prop->len == 4);
      uint32_t cod = *(reinterpret_cast<uint32_t*>(prop->val));
      LOG_CONSOLE("BT_PROPERTY_CLASS_OF_DEVICE  0x%04x", cod);
    } break;
    case BT_PROPERTY_TYPE_OF_DEVICE: {
      ASSERT(prop->len == 4);
      uint32_t devtype = *(reinterpret_cast<uint32_t*>(prop->val));
      LOG_CONSOLE("BT_PROPERTY_TYPE_OF_DEVICE  0x%04x", devtype);
    } break;
    case BT_PROPERTY_SERVICE_RECORD:
      LOG_CONSOLE("BT_PROPERTY_SERVICE_RECORD");
      break;
    case BT_PROPERTY_ADAPTER_SCAN_MODE:
      LOG_CONSOLE("BT_PROPERTY_ADAPTER_SCAN_MODE");
      break;
    case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
      LOG_CONSOLE("BT_PROPERTY_ADAPTER_BONDED_DEVICES");
      break;
    case BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT:
      LOG_CONSOLE("BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT");
      break;
    case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
      LOG_CONSOLE("BT_PROPERTY_REMOTE_FRIENDLY_NAME");
      break;
    case BT_PROPERTY_REMOTE_RSSI:
      LOG_CONSOLE("BT_PROPERTY_REMOTE_RSSI");
      break;
    case BT_PROPERTY_REMOTE_VERSION_INFO:
      LOG_CONSOLE("BT_PROPERTY_REMOTE_VERSION_INFO");
      break;
    case BT_PROPERTY_LOCAL_LE_FEATURES:
      LOG_CONSOLE("BT_PROPERTY_LOCAL_LE_FEATURES");
      break;
    case BT_PROPERTY_LOCAL_IO_CAPS:
      LOG_CONSOLE("BT_PROPERTY_LOCAL_IO_CAPS");
      break;
    case BT_PROPERTY_DYNAMIC_AUDIO_BUFFER:
      LOG_CONSOLE("BT_PROPERTY_DYNAMIC_AUDIO_BUFFER");
      break;
    case BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER:
      LOG_CONSOLE("BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER");
      break;
    case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP:
      LOG_CONSOLE("BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER");
      break;
    default: {
      LOG_CONSOLE("Unable to find BT property bd_addr:%s type:%d ptr:%p",
                  ADDRESS_TO_LOGGABLE_CSTR(bd_addr), prop->type, prop);
      const uint8_t* p = reinterpret_cast<const uint8_t*>(prop);
      for (size_t i = 0; i < sizeof(bt_property_t); i++, p++) {
        LOG_CONSOLE("  %p:0x%02x", p, *p);
      }
    } break;
  }
}

}  // namespace headless
}  // namespace test
}  // namespace bluetooth
Loading