Unverified Commit 15a5e753 authored by Ken A. Redergård's avatar Ken A. Redergård Committed by GitHub
Browse files

Move reusable test functionality into separate file (#119)

The baud rate and ble_address_to_string_convert is reusable across different tests. Moving functionality to use default platform baudrate and converting BLE address to a header file where it can be reused.
parent b4bd96d4
......@@ -52,16 +52,6 @@
#include <iostream>
#include <sstream>
#ifdef _WIN32
#define BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define BAUD_RATE 115200 /**< Baud rate 1M is not supported on MacOS. */
#endif
#ifdef __linux__
#define BAUD_RATE 1000000
#endif
#define SCAN_INTERVAL 0x00A0 /**< Determines scan interval in units of 0.625 milliseconds. */
#define SCAN_WINDOW 0x0050 /**< Determines scan window in units of 0.625 milliseconds. */
#define SCAN_TIMEOUT 0x0 /**< Scan timeout between 0x01 and 0xFFFF in seconds, 0x0 disables timeout. */
......@@ -95,7 +85,6 @@ static const ble_gap_scan_params_t m_scan_param =
/* Local function forward declarations */
static uint32_t ble_stack_init();
static std::string ble_address_to_string_convert(ble_gap_addr_t address);
static bool error = false;
static void status_handler(adapter_t * adapter, sd_rpc_app_status_t code, const char * message)
......@@ -128,7 +117,7 @@ static void log_handler(adapter_t * adapter, sd_rpc_log_severity_t severity, con
static void on_adv_report(const ble_gap_evt_t * const p_ble_gap_evt)
{
// Log the Bluetooth device address of advertisement packet received.
auto address = ble_address_to_string_convert(p_ble_gap_evt->params.adv_report.peer_addr);
auto address = testutil::ble_address_to_string_convert(p_ble_gap_evt->params.adv_report.peer_addr);
NRF_LOG("Received advertisement report with device address: " << address);
}
......@@ -159,18 +148,6 @@ static adapter_t * adapter_init(const char * serial_port, uint32_t baud_rate)
return sd_rpc_adapter_create(transport_layer);
}
static std::string ble_address_to_string_convert(ble_gap_addr_t address)
{
std::stringstream retval;
for (int i = sizeof(address.addr) - 1; i >= 0; --i)
{
retval << std::hex << static_cast<unsigned int>(address.addr[i]);
}
return retval.str();
}
static uint32_t ble_stack_init()
{
uint32_t err_code;
......@@ -275,16 +252,14 @@ static void ble_evt_dispatch(adapter_t * adapter, ble_evt_t * p_ble_evt)
TEST_CASE("test_pc_ble_driver_open_close")
{
uint32_t baudRate = BAUD_RATE;
auto env = ::test::getEnvironment();
REQUIRE(env.serialPorts.size() > 0);
REQUIRE(!env.serialPorts.empty());
auto serialPort = env.serialPorts.at(0);
auto numberOfIterations = env.numberOfIterations;
const auto numberOfIterations = env.numberOfIterations;
SECTION("open_close_open_iterations")
{
baudRate = serialPort.baudRate;
const auto baudRate = serialPort.baudRate;
INFO("Serial port used: " << serialPort.port);
INFO("Baud rate used: " << baudRate);
......
......@@ -52,6 +52,17 @@
#include <condition_variable>
#include <iostream>
#ifdef _WIN32
#define DEFAULT_BAUD_RATE 1000000 /**< The baud rate to be used for serial communication with nRF5 device. */
#endif
#ifdef __APPLE__
#define DEFAULT_BAUD_RATE 115200 /**< Baud rate 1M is not supported on MacOS. */
#endif
#ifdef __linux__
#define DEFAULT_BAUD_RATE 1000000
#endif
namespace test
{
struct SerialPort
......@@ -74,7 +85,7 @@ namespace test
{
Environment env;
auto baudRate = 1000000;
auto baudRate = DEFAULT_BAUD_RATE;
auto envBaudRate = std::getenv("BLE_DRIVER_TEST_BAUD_RATE");
if (envBaudRate != nullptr)
......
......@@ -3,7 +3,7 @@
namespace testutil
{
std::string convertToString(const std::vector<uint8_t> &data) {
static std::string convertToString(const std::vector<uint8_t> &data) {
std::stringstream ss;
ss << std::hex << std::setfill('0');
......@@ -14,6 +14,19 @@ namespace testutil
return ss.str();
}
static std::string ble_address_to_string_convert(ble_gap_addr_t address)
{
const int address_length = 6;
std::stringstream retval;
for (int i = sizeof(address.addr) - 1; i >= 0; --i)
{
retval << std::hex << static_cast<unsigned int>(address.addr[i]);
}
return retval.str();
}
}
#endif // TEST_UTIL_H__
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment