2019-09-23 11:12:35 +00:00
|
|
|
#include "CppUTest/TestHarness.h"
|
|
|
|
#include "CppUTest/CommandLineTestRunner.h"
|
|
|
|
|
|
|
|
#include "hal_cpu.h"
|
2021-12-05 18:48:26 +00:00
|
|
|
#include "hal_time_ms.h"
|
2019-09-23 11:12:35 +00:00
|
|
|
|
2020-10-30 13:22:37 +00:00
|
|
|
#include "btstack_run_loop.h"
|
|
|
|
#include "btstack_run_loop_embedded.h"
|
|
|
|
#include "btstack_memory.h"
|
2021-02-01 15:19:02 +00:00
|
|
|
|
2019-09-23 11:12:35 +00:00
|
|
|
// quick mock
|
|
|
|
|
|
|
|
// hal_cpu
|
|
|
|
void hal_cpu_disable_irqs(void){}
|
|
|
|
void hal_cpu_enable_irqs(void){}
|
|
|
|
void hal_cpu_enable_irqs_and_sleep(void){}
|
|
|
|
|
2021-12-05 18:48:26 +00:00
|
|
|
// hal_time_ms_h
|
|
|
|
uint32_t hal_time_ms(void){
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-30 13:22:37 +00:00
|
|
|
|
|
|
|
#define HEARTBEAT_PERIOD_MS 1000
|
|
|
|
|
2021-01-28 17:20:33 +00:00
|
|
|
static btstack_timer_source_t timer_1;
|
2021-01-28 14:52:10 +00:00
|
|
|
static btstack_data_source_t data_source;
|
2021-01-28 17:20:33 +00:00
|
|
|
static bool data_source_called;
|
|
|
|
static bool timer_called;
|
|
|
|
|
2021-01-28 14:52:10 +00:00
|
|
|
static void heartbeat_timeout_handler(btstack_timer_source_t * ts){
|
|
|
|
UNUSED(ts);
|
2021-01-28 17:20:33 +00:00
|
|
|
timer_called = true;
|
2021-01-28 14:52:10 +00:00
|
|
|
}
|
|
|
|
static void data_source_handler(btstack_data_source_t * ds, btstack_data_source_callback_type_t callback_type){
|
|
|
|
UNUSED(ds);
|
|
|
|
UNUSED(callback_type);
|
2021-01-28 17:20:33 +00:00
|
|
|
data_source_called = true;
|
2020-10-30 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 18:48:26 +00:00
|
|
|
static void data_source_handler_trigger_exit(btstack_data_source_t * ds, btstack_data_source_callback_type_t callback_type){
|
|
|
|
UNUSED(ds);
|
|
|
|
UNUSED(callback_type);
|
|
|
|
btstack_run_loop_trigger_exit();
|
|
|
|
}
|
|
|
|
|
2019-09-23 11:12:35 +00:00
|
|
|
TEST_GROUP(Embedded){
|
2020-10-30 13:22:37 +00:00
|
|
|
|
2019-09-23 11:12:35 +00:00
|
|
|
void setup(void){
|
2020-10-30 13:22:37 +00:00
|
|
|
// start with BTstack init - especially configure HCI Transport
|
|
|
|
btstack_memory_init();
|
|
|
|
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
|
2021-01-28 17:20:33 +00:00
|
|
|
btstack_run_loop_set_timer_handler(&timer_1, heartbeat_timeout_handler);
|
2019-09-23 11:12:35 +00:00
|
|
|
}
|
2021-01-28 14:52:10 +00:00
|
|
|
void teardown(void){
|
|
|
|
btstack_run_loop_deinit();
|
|
|
|
btstack_memory_deinit();
|
|
|
|
}
|
2019-09-23 11:12:35 +00:00
|
|
|
};
|
|
|
|
|
2020-10-30 13:22:37 +00:00
|
|
|
TEST(Embedded, Init){
|
2021-01-28 17:20:33 +00:00
|
|
|
btstack_run_loop_set_timer(&timer_1, HEARTBEAT_PERIOD_MS);
|
|
|
|
btstack_run_loop_add_timer(&timer_1);
|
2020-10-30 13:22:37 +00:00
|
|
|
|
|
|
|
btstack_run_loop_embedded_execute_once();
|
|
|
|
btstack_run_loop_embedded_trigger();
|
|
|
|
btstack_run_loop_embedded_execute_once();
|
|
|
|
btstack_run_loop_get_time_ms();
|
2021-01-28 14:52:10 +00:00
|
|
|
btstack_run_loop_timer_dump();
|
2021-01-28 17:20:33 +00:00
|
|
|
btstack_run_loop_remove_timer(&timer_1);
|
|
|
|
(void) btstack_run_loop_get_timer_context(&timer_1);
|
2021-12-05 18:48:26 +00:00
|
|
|
static btstack_context_callback_registration_t callback_registration;
|
|
|
|
btstack_run_loop_execute_on_main_thread(&callback_registration);
|
2021-01-28 14:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Embedded, DataSource){
|
|
|
|
btstack_run_loop_set_data_source_handler(&data_source, &data_source_handler);
|
|
|
|
btstack_run_loop_set_data_source_fd(&data_source, 0);
|
|
|
|
btstack_run_loop_set_data_source_handle(&data_source, NULL);
|
|
|
|
btstack_run_loop_enable_data_source_callbacks(&data_source, DATA_SOURCE_CALLBACK_POLL);
|
|
|
|
btstack_run_loop_disable_data_source_callbacks(&data_source, DATA_SOURCE_CALLBACK_POLL);
|
|
|
|
btstack_run_loop_add_data_source(&data_source);
|
|
|
|
btstack_run_loop_remove_data_source(&data_source);
|
2020-10-30 13:22:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 18:48:26 +00:00
|
|
|
TEST(Embedded, ExitRunLoop){
|
|
|
|
btstack_run_loop_set_data_source_handler(&data_source, &data_source_handler_trigger_exit);
|
|
|
|
btstack_run_loop_set_data_source_fd(&data_source, 0);
|
|
|
|
btstack_run_loop_set_data_source_handle(&data_source, NULL);
|
|
|
|
btstack_run_loop_enable_data_source_callbacks(&data_source, DATA_SOURCE_CALLBACK_POLL);
|
|
|
|
btstack_run_loop_add_data_source(&data_source);
|
|
|
|
btstack_run_loop_execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-23 11:12:35 +00:00
|
|
|
int main (int argc, const char * argv[]){
|
|
|
|
return CommandLineTestRunner::RunAllTests(argc, argv);
|
|
|
|
}
|