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

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

Add headless dumpsys and gd init flags options am: a05e3d34 am: c6e266c9

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1539043

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ifde8d0679b71e31287f5096610a8eba645c46ad9
parents c264f0ff c6e266c9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ cc_test {
        "headless.cc",
        "main.cc",
        "pairing/pairing.cc",
        "dumpsys/dumpsys.cc",
        "sdp/sdp.cc",
        "sdp/sdp_db.cc",
        "nop/nop.cc",
@@ -16,6 +17,7 @@ cc_test {
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    whole_static_libs: [
@@ -63,4 +65,7 @@ cc_test {
        "libutils",
    ],
    ldflags: ["-rdynamic"],
    sanitize: {
      cfi: false,
    },
}
+9 −3
Original line number Diff line number Diff line
@@ -20,9 +20,14 @@
#include <map>
#include <string>

#include "base/logging.h"     // LOG() stdout and android log
#include "osi/include/log.h"  // android log only
#include "stack/include/btm_api.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/hci_error_code.h"
#include "stack/include/l2cap_acl_interface.h"
#include "test/headless/connect/connect.h"
#include "test/headless/get_options.h"
#include "test/headless/headless.h"
#include "test/headless/interface.h"
#include "types/raw_address.h"
@@ -50,7 +55,7 @@ void callback_interface(interface_data_t data) {

namespace {

int do_mode(unsigned int num_loops, const RawAddress& bd_addr) {
int do_connect(unsigned int num_loops, const RawAddress& bd_addr) {
  headless_add_callback("acl_state_changed", callback_interface);

  acl_state_changed_promise = std::promise<acl_state_changed_params_t>();
@@ -77,6 +82,7 @@ int do_mode(unsigned int num_loops, const RawAddress& bd_addr) {
}  // namespace

int bluetooth::test::headless::Mode::Run() {
  return RunOnHeadlessStack<int>(
      [this]() { return do_mode(options_.loop_, options_.device_.front()); });
  return RunOnHeadlessStack<int>([this]() {
    return do_connect(options_.loop_, options_.device_.front());
  });
}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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_sdp"

#include <future>

#include "base/logging.h"     // LOG() stdout and android log
#include "osi/include/log.h"  // android log only
#include "stack/include/btm_api.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/hci_error_code.h"
#include "test/headless/dumpsys/dumpsys.h"
#include "test/headless/get_options.h"
#include "test/headless/headless.h"
#include "types/raw_address.h"

extern bt_interface_t bluetoothInterface;

int bluetooth::test::headless::Dumpsys::Run() {
  return RunOnHeadlessStack<int>([this]() {
    fprintf(stdout, "Dumpsys loop:%lu \n", loop_);
    bluetoothInterface.dump(1, nullptr);
    return 0;
  });
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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 Dumpsys : public HeadlessTest<int> {
 public:
  Dumpsys(const bluetooth::test::headless::GetOpt& options)
      : HeadlessTest<int>(options) {}
  int Run() override;
};

}  // namespace headless
}  // namespace test
}  // namespace bluetooth
+41 −5
Original line number Diff line number Diff line
@@ -22,21 +22,27 @@
#include <unistd.h>
#include <list>
#include <string>
#include "gd/os/log.h"

namespace {
constexpr struct option long_options[] = {
    {"device", required_argument, 0, 0}, {"loop", required_argument, 0, 0},
    {"uuid", required_argument, 0, 0},   {"msleep", required_argument, 0, 0},
    {"stderr", no_argument, 0, 0},       {0, 0, 0, 0}};

enum OptionType {
  kOptionDevice = 0,
  kOptionLoop = 1,
  kOptionUuid = 2,
  kOptionMsleep = 3,
  kOptionStdErr = 4,
  kOptionFlags = 5,
};

constexpr struct option long_options[] = {
    {"device", required_argument, 0, 0},  // kOptionDevice
    {"loop", required_argument, 0, 0},    // kOptionLoop/
    {"uuid", required_argument, 0, 0},    // kOptionUuid
    {"msleep", required_argument, 0, 0},  // kOptionMsleep
    {"stderr", no_argument, 0, 0},        // kOptionStdErr
    {"flags", required_argument, 0, 0},   // kOptionFlags
    {0, 0, 0, 0}};

}  // namespace

void bluetooth::test::headless::GetOpt::Usage() const {
@@ -44,6 +50,9 @@ void bluetooth::test::headless::GetOpt::Usage() const {
  fprintf(stdout,
          "%s  --device=<device,>  Comma separated list of remote devices\n",
          name_);
  fprintf(stdout,
          "%s  --flags=<flags,>  Comma separated list of gd init flags\n",
          name_);
  fprintf(stdout, "%s  --uuid=<uuid,>      Comma separated list of uuids\n",
          name_);
  fprintf(stdout, "%s  --loop=<loop>       Number of loops\n", name_);
@@ -103,6 +112,13 @@ void bluetooth::test::headless::GetOpt::ProcessOption(int option_index,
    case kOptionStdErr:
      close_stderr_ = false;
      break;
    case kOptionFlags:
      if (!optarg) return;
      ParseValue(optarg, string_list);
      for (auto& flag : string_list) {
        init_flags_.push_back(flag);
      }
      break;
    default:
      fflush(nullptr);
      valid_ = false;
@@ -111,6 +127,22 @@ void bluetooth::test::headless::GetOpt::ProcessOption(int option_index,
  }
}

void bluetooth::test::headless::GetOpt::ParseStackInitFlags() {
  if (init_flags_.size() == 0) return;

  ASSERT(stack_init_flags_ == nullptr);

  unsigned idx = 0;
  stack_init_flags_ = (const char**)calloc(sizeof(char*), init_flags_.size());
  for (const std::string& flag : init_flags_)
    stack_init_flags_[idx++] = flag.c_str();
  stack_init_flags_[idx] = nullptr;
}

const char** bluetooth::test::headless::GetOpt::StackInitFlags() const {
  return stack_init_flags_;
}

bluetooth::test::headless::GetOpt::GetOpt(int argc, char** argv)
    : name_(argv[0]) {
  while (1) {
@@ -134,6 +166,10 @@ bluetooth::test::headless::GetOpt::GetOpt(int argc, char** argv)
  while (optind < argc) {
    non_options_.push_back(argv[optind++]);
  }

  ParseStackInitFlags();

  fflush(nullptr);
}

bluetooth::test::headless::GetOpt::~GetOpt() { free(stack_init_flags_); }
Loading