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

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

bt_headless: Various updates am: 47b11978 am: babdce71 am: 7711edfa

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I364b4b7a3b6041afe5b1fac970d0d1312ffc7379
parents 15335430 7711edfa
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <string>

#include "base/logging.h"  // LOG() stdout and android log
#include "btif/include/stack_manager.h"
#include "osi/include/log.h"  // android log only
#include "stack/include/btm_api.h"
#include "stack/include/btm_api_types.h"
@@ -36,6 +37,7 @@
#include "test/headless/interface.h"
#include "types/raw_address.h"

const stack_manager_t* stack_manager_get_interface();
extern bt_interface_t bluetoothInterface;

void power_mode_callback(const RawAddress& p_bda, tBTM_PM_STATUS status,
@@ -85,16 +87,19 @@ int do_connect(unsigned int num_loops, const RawAddress& bd_addr,
  acl_create_classic_connection(bd_addr, false, false);

  acl_state_changed_params_t result = future.get();
  fprintf(stdout, "Connected created to:%s result:%u\n",
          bd_addr.ToString().c_str(), result.status);
  fprintf(stdout, "Connected created to:%s result:%s[%u]\n",
          bd_addr.ToString().c_str(), bt_status_text(result.status).c_str(),
          result.status);
  acl_state_changed_promise = std::promise<acl_state_changed_params_t>();
  future = acl_state_changed_promise.get_future();

  uint64_t connect = std::chrono::duration_cast<std::chrono::milliseconds>(
                         std::chrono::system_clock::now().time_since_epoch())
                         .count();
  fprintf(stdout, "Waiting for supervision timeout\n");
  result = future.get();

  fprintf(stdout, "Just crushing stack\n");
  LOG(INFO) << "Just crushing stack";
  stack_manager_get_interface()->clean_up_stack();

  if (disconnect_wait_time == 0) {
    fprintf(stdout, "Waiting to disconnect from supervision timeout\n");
@@ -104,8 +109,9 @@ int do_connect(unsigned int num_loops, const RawAddress& bd_addr,
            std::chrono::system_clock::now().time_since_epoch())
            .count();

    fprintf(stdout, "Disconnected after:%" PRId64 "ms from:%s result:%u\n",
            disconnect - connect, bd_addr.ToString().c_str(), result.status);
    fprintf(stdout, "Disconnected after:%" PRId64 "ms from:%s result:%s[%u]\n",
            disconnect - connect, bd_addr.ToString().c_str(),
            bt_status_text(result.status).c_str(), result.status);

    headless_remove_callback("acl_state_changed", callback_interface);
  } else {
+7 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ enum OptionType {
  kOptionMsleep = 3,
  kOptionStdErr = 4,
  kOptionFlags = 5,
  kOptionClear = 6,
};

constexpr struct option long_options[] = {
@@ -41,14 +42,16 @@ constexpr struct option long_options[] = {
    {"msleep", required_argument, 0, 0},  // kOptionMsleep
    {"stderr", no_argument, 0, 0},        // kOptionStdErr
    {"flags", required_argument, 0, 0},   // kOptionFlags
    {"clear", no_argument, 0, 0},         // kOptionDevice
    {0, 0, 0, 0}};

const char* kShortArgs = "d:l:u:";
const char* kShortArgs = "cd:l:u:";

}  // namespace

void bluetooth::test::headless::GetOpt::Usage() const {
  fprintf(stdout, "%s: Usage:\n", name_);
  fprintf(stdout, "%s  -c  Clear logcat logs\n", name_);
  fprintf(stdout,
          "%s  --device=<device,>  Comma separated list of remote devices\n",
          name_);
@@ -132,6 +135,9 @@ void bluetooth::test::headless::GetOpt::ProcessOption(int option_index,
        init_flags_.push_back(flag);
      }
      break;
    case kOptionClear:
      clear_logcat_ = true;
      break;
    default:
      fflush(nullptr);
      valid_ = false;
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class GetOpt {
  unsigned long msec_{0};

  bool close_stderr_{true};
  bool clear_logcat_{false};

  mutable std::list<std::string> non_options_;

+27 −0
Original line number Diff line number Diff line
@@ -16,8 +16,12 @@

#define LOG_TAG "bt_headless"

#include <iostream>
#include <unordered_map>

#include <sys/wait.h>
#include <unistd.h>

#include "base/logging.h"     // LOG() stdout and android log
#include "osi/include/log.h"  // android log only
#include "test/headless/connect/connect.h"
@@ -33,6 +37,24 @@ using namespace bluetooth::test::headless;

namespace {

void clear_logcat() {
  int pid;
  if ((pid = fork())) {
    // parent process
    int status;
    waitpid(pid, &status, 0);  // wait for the child to exit
    ASSERT_LOG(WIFEXITED(status), "Unable to clear logcat");
  } else {
    // child process
    const char exec[] = "/system/bin/logcat";
    const char arg0[] = "-c";

    execl(exec, exec, arg0, NULL);

    ASSERT_LOG(false, "Should not return from exec process");
  }
}

class Main : public HeadlessTest<int> {
 public:
  Main(const bluetooth::test::headless::GetOpt& options)
@@ -58,6 +80,11 @@ class Main : public HeadlessTest<int> {
    if (options_.close_stderr_) {
      fclose(stderr);
    }

    if (options_.clear_logcat_) {
      clear_logcat();
    }

    return HeadlessTest<int>::Run();
  }
};