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

Commit f6e72467 authored by Sharvil Nanavati's avatar Sharvil Nanavati
Browse files

Initial import of HAL-layer tests for bluedroid.

The test cases are in cases/, the support infrastructure for the
tests are in support/. Initially, as new test cases are being added
for different functional areas (e.g. BT socket) we'll need to also
write support functions to make those tests easier to write.
Over time, however, the support functions will be complete enough
that writing additional tests won't require also writing support
routines.

Change-Id: I54abb1011ca5132834a334cc256e3ff18cc20cbb
parent 315404dc
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
#
#  Copyright (C) 2014 Google, Inc.
#
#  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.
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := bdtest

LOCAL_SRC_FILES := \
	cases/adapter.c \
	cases/cases.c \
	cases/pan.c \
	support/adapter.c \
	support/callbacks.c \
	support/hal.c \
	support/pan.c \
	support/property.c \
	main.c

LOCAL_SHARED_LIBRARIES += \
	libhardware \
	libhardware_legacy

LOCAL_CFLAGS += -std=c99 -Wall -Wno-unused-parameter -Wno-missing-field-initializers -Werror

include $(BUILD_EXECUTABLE)
+36 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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 <stdio.h>
#include <stdbool.h>
#include <string.h>

#include <hardware/bluetooth.h>
#include <hardware/bt_pan.h>
#include <hardware/hardware.h>

#ifndef ARRAY_SIZE
#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif

#define TASSERT(c, ...) if (!(c)) { fprintf(stderr, "%s:%d: ", __func__, __LINE__); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); return false; }

extern const bt_interface_t *bt_interface;
extern bt_bdaddr_t bt_remote_bdaddr;
+96 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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.
 *
 ******************************************************************************/

#include "base.h"
#include "support/adapter.h"
#include "support/callbacks.h"
#include "support/property.h"

bool adapter_enable_disable() {
  int error;

  CALL_AND_WAIT(error = bt_interface->enable(), adapter_state_changed);
  TASSERT(error == BT_STATUS_SUCCESS, "Error enabling Bluetooth: %d", error);
  TASSERT(adapter_get_state() == BT_STATE_ON, "Adapter did not turn on.");

  CALL_AND_WAIT(error = bt_interface->disable(), adapter_state_changed);
  TASSERT(error == BT_STATUS_SUCCESS, "Error disabling Bluetooth: %d", error);
  TASSERT(adapter_get_state() == BT_STATE_OFF, "Adapter did not turn off.");

  return true;
}

bool adapter_repeated_enable_disable() {
  for (int i = 0; i < 10; ++i) {
    if (!adapter_enable_disable()) {
      return false;
    }
  }
  return true;
}

bool adapter_set_name() {
  int error;
  bt_property_t *name = property_new_name("set_name");

  CALL_AND_WAIT(error = bt_interface->set_adapter_property(name), adapter_properties);
  TASSERT(error == BT_STATUS_SUCCESS, "Error setting device name.");
  TASSERT(adapter_get_property_count() == 1, "Expected 1 adapter property change, found %d instead.", adapter_get_property_count());
  TASSERT(adapter_get_property(BT_PROPERTY_BDNAME), "The Bluetooth name property did not change.");
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_extract_name(adapter_get_property(BT_PROPERTY_BDNAME)));

  property_free(name);

  return true;
}

bool adapter_get_name() {
  int error;
  bt_property_t *name = property_new_name("get_name");

  CALL_AND_WAIT(bt_interface->set_adapter_property(name), adapter_properties);
  CALL_AND_WAIT(error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), adapter_properties);
  TASSERT(error == BT_STATUS_SUCCESS, "Error getting device name.");
  TASSERT(adapter_get_property_count() == 1, "Expected 1 adapter property change, found %d instead.", adapter_get_property_count());
  TASSERT(adapter_get_property(BT_PROPERTY_BDNAME), "The Bluetooth name property did not change.");
  TASSERT(property_equals(adapter_get_property(BT_PROPERTY_BDNAME), name), "Bluetooth name '%s' does not match test value", property_extract_name(adapter_get_property(BT_PROPERTY_BDNAME)));

  property_free(name);
  return true;
}

bool adapter_start_discovery() {
  int error;

  CALL_AND_WAIT(error = bt_interface->start_discovery(), discovery_state_changed);
  TASSERT(error == BT_STATUS_SUCCESS, "Error calling start_discovery: %d", error);
  TASSERT(adapter_get_discovery_state() == BT_DISCOVERY_STARTED, "Unable to start discovery.");

  return true;
}

bool adapter_cancel_discovery() {
  int error;

  CALL_AND_WAIT(bt_interface->start_discovery(), discovery_state_changed);
  CALL_AND_WAIT(error = bt_interface->cancel_discovery(), discovery_state_changed);
  TASSERT(error == BT_STATUS_SUCCESS, "Error calling cancel_discovery: %d", error);
  TASSERT(adapter_get_discovery_state() == BT_DISCOVERY_STOPPED, "Unable to stop discovery.");

  return true;
}
+53 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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.
 *
 ******************************************************************************/

#include "base.h"
#include "cases/cases.h"

TEST_CASE_DECL(adapter_enable_disable);
TEST_CASE_DECL(adapter_repeated_enable_disable);
TEST_CASE_DECL(adapter_set_name);
TEST_CASE_DECL(adapter_get_name);
TEST_CASE_DECL(adapter_start_discovery);
TEST_CASE_DECL(adapter_cancel_discovery);

TEST_CASE_DECL(pan_enable);
TEST_CASE_DECL(pan_connect);
TEST_CASE_DECL(pan_disconnect);
TEST_CASE_DECL(pan_quick_reconnect);

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

// The normal test suite is run with the adapter enabled.
const test_case_t test_suite[] = {
  TEST_CASE(adapter_set_name),
  TEST_CASE(adapter_get_name),
  TEST_CASE(adapter_start_discovery),
  TEST_CASE(adapter_cancel_discovery),

  TEST_CASE(pan_enable),
  TEST_CASE(pan_connect),
  TEST_CASE(pan_disconnect),
};

const size_t sanity_suite_size = ARRAY_SIZE(sanity_suite);
const size_t test_suite_size = ARRAY_SIZE(test_suite);
+34 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 Google, Inc.
 *
 *  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 "base.h"

#define TEST_CASE_DECL(x) bool x()
#define TEST_CASE(x) { x, #x }

typedef struct {
  bool (*function)();
  const char *function_name;
} test_case_t;

extern const test_case_t test_suite[];
extern const test_case_t sanity_suite[];
extern const size_t test_suite_size;
extern const size_t sanity_suite_size;
Loading