Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/aker_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,29 @@ static mac_block_period_t* build_periods_for_mac(
}

current = events;
timeline_event_t *prev_event = NULL;
/* Tracks the timestamp of the last absolute event seen so ALL weekly events
* tied to that same timestamp are skipped, not just the one immediately
* following it (schedule wrap-around can duplicate a weekly event at the
* same tie point, breaking a prev_event-only check). */
time_t last_absolute_time = 0;
bool has_last_absolute_time = false;
while (current) {
bool mac_in_current_list = false;

/* Skip weekly events if there was an absolute event at the same time (absolute takes precedence) */
if (!current->is_absolute && prev_event &&
prev_event->event_time == current->event_time && prev_event->is_absolute) {
if (!current->is_absolute && has_last_absolute_time &&
last_absolute_time == current->event_time) {
debug_print("build_periods_for_mac: MAC %u - Skipping weekly event at %ld, absolute event already processed\n",
mac_index, current->event_time);
prev_event = current;
current = current->next;
continue;
}

if (current->is_absolute) {
last_absolute_time = current->event_time;
has_last_absolute_time = true;
}

/* Check if this MAC is in the current event's block list */
if (current->mac_count == 0) {
/* Empty list = unblock all, so MAC is NOT in block list */
Expand Down Expand Up @@ -647,7 +656,6 @@ static mac_block_period_t* build_periods_for_mac(
currently_blocked = false;
}

prev_event = current;
current = current->next;
}

Expand Down
23 changes: 23 additions & 0 deletions src/aker_rbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ static bool g_rbus_initialized = false;
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
#ifdef UNIT_TESTING
/* Not static: exposed (non-public, not in aker_rbus.h) so unit tests can call
* them directly without a live RBUS broker. Only compiled this way for test
* builds; production keeps these fully static/encapsulated. */
rbusError_t notification_count_get_handler(
rbusHandle_t handle,
rbusProperty_t property,
rbusGetHandlerOptions_t* opts);

rbusError_t notification_count_set_handler(
rbusHandle_t handle,
rbusProperty_t property,
rbusSetHandlerOptions_t* opts);
#else
static rbusError_t notification_count_get_handler(
rbusHandle_t handle,
rbusProperty_t property,
Expand All @@ -46,6 +60,7 @@ static rbusError_t notification_count_set_handler(
rbusHandle_t handle,
rbusProperty_t property,
rbusSetHandlerOptions_t* opts);
#endif

/*----------------------------------------------------------------------------*/
/* Internal Functions */
Expand All @@ -54,7 +69,11 @@ static rbusError_t notification_count_set_handler(
/**
* @brief RBUS GET handler for NotificationCount property
*/
#ifdef UNIT_TESTING
rbusError_t notification_count_get_handler(
#else
static rbusError_t notification_count_get_handler(
#endif
rbusHandle_t handle,
rbusProperty_t property,
rbusGetHandlerOptions_t* opts)
Expand Down Expand Up @@ -83,7 +102,11 @@ static rbusError_t notification_count_get_handler(
*
* Note: Setting is only allowed for reset to 0 (administrative purposes)
*/
#ifdef UNIT_TESTING
rbusError_t notification_count_set_handler(
#else
static rbusError_t notification_count_set_handler(
#endif
rbusHandle_t handle,
rbusProperty_t property,
rbusSetHandlerOptions_t* opts)
Expand Down
9 changes: 9 additions & 0 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ static pthread_mutex_t schedule_lock;
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
static int report_metrics_to_log = 0;
static mac_timeline_collection_t *notification_timeline = NULL;
#ifdef UNIT_TESTING
/* Counts successful 10-day-stale auto-rebuilds; only compiled into test
* builds so unit tests can observe the branch fired without waiting 10 real
* days. Never present in the production aker/aker-cli binaries. */
int g_timeline_auto_rebuild_count = 0;
#endif

/*----------------------------------------------------------------------------*/
/* External functions */
Expand Down Expand Up @@ -329,6 +335,9 @@ void *scheduler_thread(void *args)

if( notification_timeline ) {
debug_info("scheduler_thread(): Timeline auto-rebuilt successfully\n");
#ifdef UNIT_TESTING
g_timeline_auto_rebuild_count++;
#endif
} else {
debug_error("scheduler_thread(): Failed to auto-rebuild timeline\n");
}
Expand Down
34 changes: 33 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ add_executable(test_scheduler test_scheduler.c ../src/schedule_print.c
mem_wrapper.c common_test_stubs.c
libparodus_mock.c)
target_link_libraries (test_scheduler ${AKER_COMMON_LIBS})
target_compile_definitions(test_scheduler PUBLIC UNIT_TESTING)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (test_scheduler ${AKER_LINUX_LIBS})
endif()
Expand Down Expand Up @@ -212,6 +213,33 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (test_aker_metrics ${AKER_LINUX_LIBS})
endif()

#-------------------------------------------------------------------------------
# test_aker_notification
#-------------------------------------------------------------------------------
add_test(NAME test_aker_notification COMMAND ${MEMORY_CHECK} ./test_aker_notification)
add_executable(test_aker_notification test_aker_notification.c ../src/schedule_print.c
../src/schedule.c ../src/decode.c ../src/process_data.c
../src/aker_md5.c ../src/md5.c ../src/aker_msgpack.c
../src/scheduler.c ../src/aker_notification.c
${AKER_RBUS_SRC}
mem_wrapper.c common_test_stubs.c
../src/aker_metrics.c libparodus_mock.c)
target_link_libraries (test_aker_notification ${AKER_COMMON_LIBS})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (test_aker_notification ${AKER_LINUX_LIBS})
endif()

#-------------------------------------------------------------------------------
# test_aker_rbus
#-------------------------------------------------------------------------------
add_test(NAME test_aker_rbus COMMAND ${MEMORY_CHECK} ./test_aker_rbus)
add_executable(test_aker_rbus test_aker_rbus.c ../src/aker_rbus.c)
target_link_libraries (test_aker_rbus ${AKER_COMMON_LIBS})
target_compile_definitions(test_aker_rbus PUBLIC UNIT_TESTING)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (test_aker_rbus ${AKER_LINUX_LIBS})
endif()

add_custom_target(coverage
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_time.dir/__/src --output-file time.info
Expand All @@ -237,10 +265,14 @@ COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_aker_msgpack.dir/__/src --output-file aker_msgpack.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_aker_metrics.dir --output-file aker_metrics.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_aker_notification.dir/__/src --output-file aker_notification.info
COMMAND lcov -q --capture --directory
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/test_aker_rbus.dir/__/src --output-file aker_rbus.info

COMMAND lcov -a md5.info -a decode.info -a process_now.info -a process_is_create_ok.info
-a schedule.info -a process.info -a time.info -a scheduler.info -a reporter.info
-a wrp.info -a aker_msgpack.info --output-file coverage.info
-a wrp.info -a aker_msgpack.info -a aker_notification.info -a aker_rbus.info --output-file coverage.info

COMMAND genhtml coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
Loading
Loading