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

Commit 72423722 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

Make BTIF a static library; add unit test framework

Moving BTIF to a static library allows it to be loaded for unit tests.
The framework has been put in place to add unit tests to
'net_test_btif'.

Change-Id: Ie7e0984e90f11f6e3df5c0f34c77cc976627f1d2
parent 73f865ef
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ LOCAL_SRC_FILES:= \
    ./jv/bta_jv_main.c \
    ./jv/bta_jv_api.c

LOCAL_MODULE := libbt-brcm_bta
LOCAL_MODULE := libbt-bta
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := libcutils libc

system/btif/Android.mk

0 → 100644
+137 −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)

# Common variables
# ========================================================

# HAL layer
btifCommonSrc := \
  src/bluetooth.c

# BTIF implementation
btifCommonSrc += \
  src/btif_av.c \
  src/btif_avrcp_audio_track.cpp \
  src/btif_config.c \
  src/btif_config_transcode.cpp \
  src/btif_core.c \
  src/btif_debug.c \
  src/btif_debug_btsnoop.c \
  src/btif_debug_conn.c \
  src/btif_dm.c \
  src/btif_gatt.c \
  src/btif_gatt_client.c \
  src/btif_gatt_multi_adv_util.c \
  src/btif_gatt_server.c \
  src/btif_gatt_test.c \
  src/btif_gatt_util.c \
  src/btif_hf.c \
  src/btif_hf_client.c \
  src/btif_hh.c \
  src/btif_hl.c \
  src/btif_sdp.c \
  src/btif_media_task.c \
  src/btif_pan.c \
  src/btif_profile_queue.c \
  src/btif_rc.c \
  src/btif_sm.c \
  src/btif_sock.c \
  src/btif_sock_rfc.c \
  src/btif_sock_l2cap.c \
  src/btif_sock_sco.c \
  src/btif_sock_sdp.c \
  src/btif_sock_thread.c \
  src/btif_sdp_server.c \
  src/btif_sock_util.c \
  src/btif_storage.c \
  src/btif_uid.c \
  src/btif_util.c \
  src/stack_manager.c

# Callouts
btifCommonSrc += \
  co/bta_ag_co.c \
  co/bta_dm_co.c \
  co/bta_av_co.c \
  co/bta_hh_co.c \
  co/bta_hl_co.c \
  co/bta_pan_co.c \
  co/bta_gattc_co.c \
  co/bta_gatts_co.c

# Tests
btifTestSrc := \
  test/btif_storage_test.cpp

# Includes
btifCommonIncludes := \
  $(LOCAL_PATH)/../ \
  $(LOCAL_PATH)/../bta/include \
  $(LOCAL_PATH)/../bta/sys \
  $(LOCAL_PATH)/../bta/dm \
  $(LOCAL_PATH)/../btcore/include \
  $(LOCAL_PATH)/../include \
  $(LOCAL_PATH)/../stack/include \
  $(LOCAL_PATH)/../stack/l2cap \
  $(LOCAL_PATH)/../stack/a2dp \
  $(LOCAL_PATH)/../stack/btm \
  $(LOCAL_PATH)/../stack/avdt \
  $(LOCAL_PATH)/../hcis \
  $(LOCAL_PATH)/../hcis/include \
  $(LOCAL_PATH)/../hcis/patchram \
  $(LOCAL_PATH)/../udrv/include \
  $(LOCAL_PATH)/../btif/include \
  $(LOCAL_PATH)/../btif/co \
  $(LOCAL_PATH)/../hci/include\
  $(LOCAL_PATH)/../vnd/include \
  $(LOCAL_PATH)/../brcm/include \
  $(LOCAL_PATH)/../embdrv/sbc/encoder/include \
  $(LOCAL_PATH)/../embdrv/sbc/decoder/include \
  $(LOCAL_PATH)/../audio_a2dp_hw \
  $(LOCAL_PATH)/../utils/include \
  $(bdroid_C_INCLUDES) \
  external/tinyxml2 \
  external/zlib

btifCommonCFlags += -DBUILDCFG $(bdroid_CFLAGS) -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=unused-parameter

# libbtif static library for target
# ========================================================
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(btifCommonIncludes)
LOCAL_SRC_FILES := $(btifCommonSrc)
LOCAL_CFLAGS := $(btifCommonCFlags)
# Many .h files have redefined typedefs
LOCAL_CLANG_CFLAGS += -Wno-error=typedef-redefinition
LOCAL_SHARED_LIBRARIES := libc liblog
LOCAL_MODULE_CLASS := STATIC_LIBRARIES
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libbtif
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(btifCommonIncludes)
LOCAL_SRC_FILES := $(btifTestSrc)
LOCAL_CFLAGS := $(btifCommonCFlags)
LOCAL_SHARED_LIBRARIES += liblog libhardware libhardware_legacy libcutils
LOCAL_STATIC_LIBRARIES += libbtcore libbtif libosi
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := net_test_btif
include $(BUILD_NATIVE_TEST)
+2 −2
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ void uint2devclass(UINT32 dev, DEV_CLASS dev_class);
void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128);

void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
void string_to_uuid(char *str, bt_uuid_t *p_uuid);
int ascii_2_hex (char *p_ascii, int len, UINT8 *p_hex);
void string_to_uuid(const char *str, bt_uuid_t *p_uuid);
int ascii_2_hex (const char *p_ascii, int len, UINT8 *p_hex);

#endif /* BTIF_UTIL_H */
+2 −2
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t* uuid128)
    memcpy(uuid128->uu + 2, &uuid16_bo, sizeof(uint16_t));
}

void string_to_uuid(char *str, bt_uuid_t *p_uuid)
void string_to_uuid(const char *str, bt_uuid_t *p_uuid)
{
    uint32_t uuid0, uuid4;
    uint16_t uuid1, uuid2, uuid3, uuid5;
@@ -163,7 +163,7 @@ void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)
**
**  Returns         the number of hex bytes filled.
*/
int ascii_2_hex (char *p_ascii, int len, UINT8 *p_hex)
int ascii_2_hex (const char *p_ascii, int len, UINT8 *p_hex)
{
    int     x;
    UINT8   c;
+37 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 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 <gtest/gtest.h>

extern "C" {
#include "btif/include/btif_util.h"
}

TEST(BtifStorageTest, test_string_to_uuid) {
  const char *s1 = "e39c6285-867f-4b1d-9db0-35fbd9aebf22";
  const uint8_t o1[] = {0xe3, 0x9c, 0x62, 0x85, 0x86, 0x7f, 0x4b, 0x1d,
                     0x9d, 0xb0, 0x35, 0xfb, 0xd9, 0xae, 0xbf, 0x22};

  bt_uuid_t uuid;
  memset(&uuid, 0, sizeof(uuid));
  EXPECT_FALSE(memcmp(&uuid, o1, sizeof(o1)) == 0);

  string_to_uuid(s1, &uuid);
  EXPECT_TRUE(memcmp(&uuid, o1, sizeof(o1)) == 0);
}
Loading