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

Commit 8c2d2026 authored by Chris Manton's avatar Chris Manton
Browse files

bt_headless: Add connect test

Towards testable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run

Change-Id: I91eafe7e8047638581dcda75f60527572d842ec6
parent 46c6bbdb
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

#define LOG_TAG "bt_headless_mode"

#include <inttypes.h>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <future>
#include <map>
#include <string>
@@ -71,9 +75,17 @@ int do_connect(unsigned int num_loops, const RawAddress& bd_addr) {
  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, "Disconnected from to:%s result:%u\n",
          bd_addr.ToString().c_str(), result.status);
  uint64_t disconnect = std::chrono::duration_cast<std::chrono::milliseconds>(
                            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);

  headless_remove_callback("acl_state_changed", callback_interface);
  return 0;
@@ -81,7 +93,7 @@ int do_connect(unsigned int num_loops, const RawAddress& bd_addr) {

}  // namespace

int bluetooth::test::headless::Mode::Run() {
int bluetooth::test::headless::Connect::Run() {
  return RunOnHeadlessStack<int>([this]() {
    return do_connect(options_.loop_, options_.device_.front());
  });
+2 −2
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ namespace bluetooth {
namespace test {
namespace headless {

class Mode : public HeadlessTest<int> {
class Connect : public HeadlessTest<int> {
 public:
  Mode(const bluetooth::test::headless::GetOpt& options)
  Connect(const bluetooth::test::headless::GetOpt& options)
      : HeadlessTest<int>(options) {}
  int Run() override;
};
+2 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@ class Main : public HeadlessTest<int> {
        "dumpsys",
        std::make_unique<bluetooth::test::headless::Dumpsys>(options));
    test_nodes_.emplace(
        "mode", std::make_unique<bluetooth::test::headless::Mode>(options));
        "connect",
        std::make_unique<bluetooth::test::headless::Connect>(options));
    test_nodes_.emplace(
        "nop", std::make_unique<bluetooth::test::headless::Nop>(options));
    test_nodes_.emplace(