Skip to content

Commit 387027d

Browse files
authored
Merge pull request #6086 from pan-/gatt-client-unit-tests
BLE: Gatt client unit tests
2 parents ddf70f1 + 871ebb6 commit 387027d

22 files changed

+4020
-0
lines changed

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ cache:
2020
- $HOME/.cache/apt
2121
- $HOME/gcc-arm-none-eabi-6-2017-q2-update
2222

23+
addons:
24+
apt:
25+
sources:
26+
- ubuntu-toolchain-r-test
27+
packages:
28+
- gcc-6
29+
- g++-6
30+
- cmake
31+
2332
before_install:
2433
- bash -c "$STATUS" pending "Local $NAME testing is in progress"
2534
# Make sure pipefail
@@ -134,6 +143,25 @@ matrix:
134143
fi
135144
- bash -c "$STATUS" success "$STATUSM"
136145

146+
- env:
147+
- NAME=ble-host-tests
148+
- BLE_HOST_TESTS=$PWD/features/FEATURE_BLE/tests
149+
install:
150+
# Install dependencies
151+
- sudo apt-get install cmake
152+
# Print versions we use
153+
- gcc --version
154+
- cmake --version
155+
script:
156+
# Compile the tests
157+
- mkdir $BLE_HOST_TESTS/build
158+
- cd $BLE_HOST_TESTS/build && CC=gcc-6 CXX=g++-6 cmake .. -G "Unix Makefiles"
159+
- ls $BLE_HOST_TESTS
160+
- ls $BLE_HOST_TESTS/build
161+
- cd $BLE_HOST_TESTS/build && make
162+
# Run ble host tests
163+
- $BLE_HOST_TESTS/build/gatt-client-tests
164+
137165
- env:
138166
- NAME=littlefs
139167
- LITTLEFS=features/filesystem/littlefs
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
3+
# Make PROJECT_SOURCE_DIR, PROJECT_BINARY_DIR, and PROJECT_NAME available.
4+
set(PROJECT_NAME ble-tests)
5+
project(${PROJECT_NAME})
6+
7+
set(CMAKE_CXX_STANDARD 14)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
11+
################################
12+
# GTEST
13+
################################
14+
15+
# Download and unpack googletest at configure time
16+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
17+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
18+
RESULT_VARIABLE result
19+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
20+
if(result)
21+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
22+
endif()
23+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
24+
RESULT_VARIABLE result
25+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
26+
if(result)
27+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
28+
endif()
29+
30+
# Prevent overriding the parent project's compiler/linker
31+
# settings on Windows
32+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
33+
34+
# Add googletest directly to our build. This defines
35+
# the gtest and gtest_main targets.
36+
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
37+
${CMAKE_BINARY_DIR}/googletest-build
38+
EXCLUDE_FROM_ALL)
39+
40+
# The gtest/gtest_main targets carry header search path
41+
# dependencies automatically when using CMake 2.8.11 or
42+
# later. Otherwise we have to add them here ourselves.
43+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
44+
include_directories(BEFORE SYSTEM
45+
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
46+
else()
47+
target_include_directories(gmock_main SYSTEM BEFORE INTERFACE
48+
"${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include")
49+
endif()
50+
51+
52+
################################
53+
# Testing
54+
################################
55+
56+
enable_testing()
57+
58+
###############################
59+
# GattClient test
60+
###############################
61+
62+
add_executable(gatt-client-tests
63+
mbed_os_stub/mbed_assert.c
64+
generic/GattClient/mock/MockCallbacks.cpp
65+
generic/GattClient/mock/MockPalGattClient.cpp
66+
generic/GattClient/util/Equality.cpp
67+
generic/GattClient/TestCharacteristicDesctiptorDiscovery.cpp
68+
generic/GattClient/TestDiscoverAllServices.cpp
69+
generic/GattClient/TestNoCb.cpp
70+
generic/GattClient/TestRead.cpp
71+
generic/GattClient/TestServerEvent.cpp
72+
generic/GattClient/TestWrite.cpp
73+
${PROJECT_SOURCE_DIR}/../source/generic/GenericGattClient.cpp
74+
)
75+
76+
target_include_directories(gatt-client-tests PRIVATE
77+
"${PROJECT_SOURCE_DIR}/.."
78+
"${PROJECT_SOURCE_DIR}/../../.."
79+
"${PROJECT_SOURCE_DIR}/generic/GattClient"
80+
)
81+
82+
# Standard linking to gtest stuff.
83+
target_link_libraries(gatt-client-tests gmock_main)
84+
85+
# This is so you can do 'make gatt-client-tests' to see all your tests run, instead of
86+
# manually running the executable runUnitTests to see those specific tests.
87+
add_test(NAME AllUnitTests COMMAND gatt-client-tests)
88+
89+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
3+
project(googletest-download NONE)
4+
5+
include(ExternalProject)
6+
ExternalProject_Add(googletest
7+
GIT_REPOSITORY https://github.com/google/googletest.git
8+
GIT_TAG master
9+
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
10+
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
11+
CONFIGURE_COMMAND ""
12+
BUILD_COMMAND ""
13+
INSTALL_COMMAND ""
14+
TEST_COMMAND ""
15+
)

features/FEATURE_BLE/tests/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# mbed BLE host tests
2+
3+
This folder contains tests for mbed BLE that can be run on an x86 host.
4+
5+
## Getting started
6+
7+
Run the following instructions to build the tests:
8+
9+
```
10+
cd features/FEATURE_BLE/tests
11+
mkdir build
12+
cd build
13+
cmake ..
14+
make
15+
```
16+
17+
The various tests applications are present at the root of the test folder;
18+
execute them to run the tests. As an examples gatt client related tests can be
19+
run with:
20+
21+
```
22+
./gatt-client-tests
23+
```
24+
25+
## Requirements
26+
27+
These tests requires cmake on the host and a compliant C++14 compiler.
28+
29+
## Resources
30+
31+
These tests use extensively google test (gtest) and google mock. Please refer to
32+
the documentation of each products to get more insight:
33+
* gtest: https://github.com/google/googletest/tree/master/googletest/docs
34+
* gmock: https://github.com/google/googletest/tree/master/googlemock/docs
35+

0 commit comments

Comments
 (0)