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

Commit d3132bc4 authored by Steve Gu's avatar Steve Gu Committed by Andre Eisenbach
Browse files

Adds BLE tests to bdtest.

Change-Id: Idcdc01339f0e8a14b6fedf27545566e7efdf53c2
parent 364c1eba
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -27,10 +27,12 @@ LOCAL_C_INCLUDES += \
LOCAL_SRC_FILES := \
LOCAL_SRC_FILES := \
    cases/adapter.c \
    cases/adapter.c \
    cases/cases.c \
    cases/cases.c \
    cases/gatt.c \
    cases/pan.c \
    cases/pan.c \
    cases/rfcomm.c \
    cases/rfcomm.c \
    support/adapter.c \
    support/adapter.c \
    support/callbacks.c \
    support/callbacks.c \
    support/gatt.c \
    support/hal.c \
    support/hal.c \
    support/pan.c \
    support/pan.c \
    support/rfcomm.c \
    support/rfcomm.c \
+1 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <string.h>
#include <string.h>


#include <hardware/bluetooth.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_gatt.h>
#include <hardware/bt_pan.h>
#include <hardware/bt_pan.h>
#include <hardware/bt_sock.h>
#include <hardware/bt_sock.h>
#include <hardware/hardware.h>
#include <hardware/hardware.h>
+7 −1
Original line number Original line Diff line number Diff line
@@ -34,10 +34,13 @@ TEST_CASE_DECL(pan_connect);
TEST_CASE_DECL(pan_disconnect);
TEST_CASE_DECL(pan_disconnect);
TEST_CASE_DECL(pan_quick_reconnect);
TEST_CASE_DECL(pan_quick_reconnect);


TEST_CASE_DECL(gatt_client_register);
TEST_CASE_DECL(gatt_client_scan);

// These are run with the Bluetooth adapter disabled.
// These are run with the Bluetooth adapter disabled.
const test_case_t sanity_suite[] = {
const test_case_t sanity_suite[] = {
  TEST_CASE(adapter_enable_disable),
  TEST_CASE(adapter_enable_disable),
  TEST_CASE(adapter_repeated_enable_disable),
  TEST_CASE(adapter_repeated_enable_disable)
};
};


// The normal test suite is run with the adapter enabled.
// The normal test suite is run with the adapter enabled.
@@ -53,6 +56,9 @@ const test_case_t test_suite[] = {
  TEST_CASE(pan_enable),
  TEST_CASE(pan_enable),
  TEST_CASE(pan_connect),
  TEST_CASE(pan_connect),
  TEST_CASE(pan_disconnect),
  TEST_CASE(pan_disconnect),

  TEST_CASE(gatt_client_register),
  TEST_CASE(gatt_client_scan)
};
};


const size_t sanity_suite_size = ARRAY_SIZE(sanity_suite);
const size_t sanity_suite_size = ARRAY_SIZE(sanity_suite);
+42 −0
Original line number Original line Diff line number Diff line
#include <stdlib.h>
#include <time.h>

#include "base.h"
#include "support/gatt.h"
#include "support/callbacks.h"

bt_uuid_t app_uuid;

static void assign_random_app_uuid(bt_uuid_t *uuid) {
  srand(time(NULL));
  for (int i = 0; i < 16; ++i) {
    uuid->uu[i] = (uint8_t) (rand() % 256);
  }
}

bool gatt_client_register() {
  TASSERT(gatt_interface != NULL, "Null GATT interface.");

  // Registers gatt client.
  assign_random_app_uuid(&app_uuid);
  gatt_interface->client->register_client(&app_uuid);
  CALL_AND_WAIT(gatt_interface->client->register_client(&app_uuid), btgattc_register_app_cb);
  TASSERT(gatt_get_status() == BT_STATUS_SUCCESS, "Error registering GATT app callback.");

  // Unregisters gatt client. No callback is expected.
  gatt_interface->client->unregister_client(gatt_get_client_interface());

  return true;
}

bool gatt_client_scan() {
  TASSERT(gatt_interface != NULL, "Null GATT interface.");

  // Starts BLE scan. NB: This test assumes there is a BLE beacon advertising nearby.
  CALL_AND_WAIT(gatt_interface->client->scan(true), btgattc_scan_result_cb);

  // Ends BLE scan. No callback is expected.
  gatt_interface->client->scan(false);

  return true;
}
+6 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@
#include "osi/include/config.h"
#include "osi/include/config.h"
#include "support/callbacks.h"
#include "support/callbacks.h"
#include "support/hal.h"
#include "support/hal.h"
#include "support/gatt.h"
#include "support/pan.h"
#include "support/pan.h"
#include "support/rfcomm.h"
#include "support/rfcomm.h"


@@ -175,6 +176,11 @@ int main(int argc, char **argv) {
    return 3;
    return 3;
  }
  }


  if (!gatt_init()) {
    printf("Unable to initialize GATT.\n");
    return 4;
  }

  watchdog_running = true;
  watchdog_running = true;
  pthread_create(&watchdog_thread, NULL, watchdog_fn, NULL);
  pthread_create(&watchdog_thread, NULL, watchdog_fn, NULL);


Loading