diff --git a/docs/architecture/index.md b/docs/architecture/index.md index 72812bd558..bf41bad78e 100644 --- a/docs/architecture/index.md +++ b/docs/architecture/index.md @@ -18,7 +18,8 @@ implemented under `kernel/`). The main source layers, as described on the - `src/fw/drivers` — hardware drivers (public interfaces under `include/pbl/drivers`). - `subsys/` — OS subsystems shared beyond the firmware tree; currently - logging, included via the `pbl/logging/` header path. + logging and cron, included via the `pbl/logging/` and `pbl/cron/` header + paths. Alongside these sit `src/fw/shell` (launcher/watchface UX flow), `src/fw/process_management` (app lifecycle) and `src/fw/comm` (phone diff --git a/include/pbl/cron/cron.h b/include/pbl/cron/cron.h new file mode 100644 index 0000000000..7d3a903f57 --- /dev/null +++ b/include/pbl/cron/cron.h @@ -0,0 +1,159 @@ +/* SPDX-FileCopyrightText: 2024 Google LLC */ +/* SPDX-License-Identifier: Apache-2.0 */ + +#pragma once + +#include +#include +#include + +#include "pbl/util/list.h" + +//! @file cron.h +//! Wall-clock based timer system. Designed for use in things such as alarms, calendar events, etc. +//! Properly handles DST, etc. + +struct pbl_cron_job; + +typedef void (*pbl_cron_job_cb_t)(struct pbl_cron_job *job, void *data); + +//! Matches any possible value. +#define PBL_CRON_MINUTE_ANY (-1) +#define PBL_CRON_HOUR_ANY (-1) +#define PBL_CRON_MDAY_ANY (-1) +#define PBL_CRON_MONTH_ANY (-1) + +#define PBL_CRON_WDAY_SUNDAY (1 << 0) +#define PBL_CRON_WDAY_MONDAY (1 << 1) +#define PBL_CRON_WDAY_TUESDAY (1 << 2) +#define PBL_CRON_WDAY_WEDNESDAY (1 << 3) +#define PBL_CRON_WDAY_THURSDAY (1 << 4) +#define PBL_CRON_WDAY_FRIDAY (1 << 5) +#define PBL_CRON_WDAY_SATURDAY (1 << 6) + +#define PBL_CRON_WDAY_WEEKDAYS \ + (PBL_CRON_WDAY_MONDAY | PBL_CRON_WDAY_TUESDAY | PBL_CRON_WDAY_WEDNESDAY | \ + PBL_CRON_WDAY_THURSDAY | PBL_CRON_WDAY_FRIDAY) +#define PBL_CRON_WDAY_WEEKENDS (PBL_CRON_WDAY_SUNDAY | PBL_CRON_WDAY_SATURDAY) +#define PBL_CRON_WDAY_ANY (PBL_CRON_WDAY_WEEKENDS | PBL_CRON_WDAY_WEEKDAYS) + +struct pbl_cron_job { + //! internal, no touchy + ListNode list_node; + + //! Cached execution timestamp in UTC. + //! This is set by `pbl_cron_job_schedule`, and is required to never be changed once the job has + //! been added. + time_t cached_execute_time; + + //! Callback that is called when the job fires. + pbl_cron_job_cb_t cb; + void *cb_data; + + //! Occasionally, the system gets a clock change event for various reasons: + //! - User changed time-zones or a DST transition happened + //! - User changed the time + //! - Phone sent the current time and was different from ours, so we took theirs. + //! In the first case, the cron job's execute time will always be recalculated. + //! In the other two, we see if the time difference from the old time is >= this. + //! If it is, then we'll recalculate. Otherwise, we leave the calculated time alone. + //! In this way, 0 will always recalculate, and UINT32_MAX will never recalculate. + //! + //! Recalculating would essentially mean that a job that was "skipped over" will not fire until + //! the next match. If recalculation is not done, but the job was skipped over, it will fire + //! instantly. + //! + //! This value is specified in seconds. + uint32_t clock_change_tolerance; + + int8_t minute; //!< 0-59, or PBL_CRON_MINUTE_ANY + int8_t hour; //!< 0-23, or PBL_CRON_HOUR_ANY + int8_t mday; //!< 0-30, or PBL_CRON_MDAY_ANY + int8_t month; //!< 0-11, or PBL_CRON_MONTH_ANY + + //! Seconds to offset the cron execution time applied after regular cron job time calculation. + //! For example, a cron scheduled for Monday at 0:15 with an offset of negative 30min will fire + //! on Sunday at 23:45. + int32_t offset_seconds; + + union { + uint8_t flags; + + struct { + //! This should be any combination of PBL_CRON_WDAY_*. If zero, acts like PBL_CRON_WDAY_ANY. + uint8_t wday : 7; + + //! If this flag is set, the resulting execution time may be equal to the local epoch. + //! Having it set could be used for some event that must happen at the specified time even if + //! that time is right now. + bool may_be_instant : 1; + }; + }; +}; + +//! Initialize the cron subsystem. +void pbl_cron_init(void); + +//! Adjust all cron jobs, as the wall clock has changed. +//! @param utc_time_delta seconds the UTC time moved by. +//! @param gmt_offset_delta seconds the GMT offset moved by; non-zero forces recalculation. +//! @param dst_changed whether the DST state changed; true forces recalculation. +void pbl_cron_handle_clock_change(int32_t utc_time_delta, int32_t gmt_offset_delta, + bool dst_changed); + +//! Add a cron job. This will make the subsystem hold a reference to the specified job, so it must +//! not leave scope or be destroyed until it is unscheduled. +//! The job only gets scheduled once. For re-scheduling, you can call this on the job again. +//! @param job pointer to the job to be scheduled. +//! @returns time_t for when the job is destined to go off. +time_t pbl_cron_job_schedule(struct pbl_cron_job *job); + +//! Schedule a cron job to run after another cron job. +//! This will make the subsystem hold a reference to the new job, so it must +//! not leave scope or be destroyed until it is unscheduled. +//! @param job pointer to the job after which we want our job to run. job must be scheduled. +//! @param new_job pointer to the job to be scheduled. new_job must be unscheduled. +//! @returns time_t for when the job is destined to go off. +//! @note This API makes no guarantee that the two jobs will be scheduled back to back, +//! only that new_job will have the same scheduled time as job and that it will trigger +//! strictly after job. +time_t pbl_cron_job_schedule_after(struct pbl_cron_job *job, struct pbl_cron_job *new_job); + +//! Remove a scheduled cron job. +//! @param job pointer to the job to be unscheduled. +//! @return true if the job was successfully removed (false may indicate no job was +//! scheduled at all or the cb is currently executing) +bool pbl_cron_job_unschedule(struct pbl_cron_job *job); + +//! Check if a cron job is scheduled. +//! @param job pointer to the job to be checked for being scheduled. +//! @returns true if scheduled or pending deletion, false otherwise +bool pbl_cron_job_is_scheduled(struct pbl_cron_job *job); + +//! Calculate cron job's destined execution time, from the current time. +//! @param job pointer to the job to get the execution time for. +//! @returns time_t for when the job is destined to go off. +time_t pbl_cron_job_get_execute_time(const struct pbl_cron_job *job); + +//! Calculate cron job's destined execution time if it were scheduled at the given time. +//! @param job pointer to the job to get the execution time for. +//! @param local_epoch the epoch for getting the job's execution time. +//! @returns time_t for when the job is destined to go off. +time_t pbl_cron_job_get_execute_time_from_epoch(const struct pbl_cron_job *job, time_t local_epoch); + +#if UNITTEST +//! Remove all jobs. +void pbl_cron_clear_all_jobs(void); + +//! Clean up the cron subsystem. +void pbl_cron_deinit(void); + +//! The number of registered cron jobs. +uint32_t pbl_cron_get_job_count(void); + +//! Run the cron timers if they've fired. +void pbl_cron_wakeup(void); + +//! Execute time of the earliest scheduled job, or 0 when none is scheduled. +time_t pbl_cron_get_next_execute_time(void); +#endif diff --git a/include/pbl/services/cron.h b/include/pbl/services/cron.h deleted file mode 100644 index 7aa8aba7c4..0000000000 --- a/include/pbl/services/cron.h +++ /dev/null @@ -1,38 +0,0 @@ -/* SPDX-FileCopyrightText: 2024 Google LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - -#pragma once - -#include "kernel/events.h" - -//! @file cron.h -//! Wall-clock based timer system. Designed for use in things such as alarms, calendar events, etc. -//! Properly handles DST, etc. -//! This file is for controlling the service itself. The actual job API is in - -//! Initialize the cron service. -void cron_service_init(void); - -//! Adjust all cron jobs, as the wall clock has changed. -//! This means DST and/or time zone may have changed! -void cron_service_handle_clock_change(PebbleSetTimeEvent *set_time_info); - -#if UNITTEST -// ----------------------------------------------------------------------------- -// For testing: - -//! Remove all jobs. -void cron_clear_all_jobs(void); - -//! Clean up the cron service. -void cron_service_deinit(void); - -//! The number of registered cron jobs. -uint32_t cron_service_get_job_count(void); - -//! Run the cron timers if they've fired. -void cron_service_wakeup(void); - -//! Execute time of the earliest scheduled job, or 0 when none is scheduled. -time_t cron_service_get_next_execute_time(void); -#endif diff --git a/include/pebbleos/cron.h b/include/pebbleos/cron.h deleted file mode 100644 index c0e1ce1004..0000000000 --- a/include/pebbleos/cron.h +++ /dev/null @@ -1,128 +0,0 @@ -/* SPDX-FileCopyrightText: 2024 Google LLC */ -/* SPDX-License-Identifier: Apache-2.0 */ - -#pragma once - -#include - -#include "pbl/util/list.h" - -//! @file cron.h -//! Wall-clock based timer system. Designed for use in things such as alarms, calendar events, etc. -//! Properly handles DST, etc. - -typedef struct CronJob CronJob; - -typedef void (*CronJobCallback)(CronJob *job, void *data); - -//! Matches any possible value. -#define CRON_MINUTE_ANY (-1) -#define CRON_HOUR_ANY (-1) -#define CRON_MDAY_ANY (-1) -#define CRON_MONTH_ANY (-1) - -#define WDAY_SUNDAY (1 << 0) -#define WDAY_MONDAY (1 << 1) -#define WDAY_TUESDAY (1 << 2) -#define WDAY_WEDNESDAY (1 << 3) -#define WDAY_THURSDAY (1 << 4) -#define WDAY_FRIDAY (1 << 5) -#define WDAY_SATURDAY (1 << 6) - -#define WDAY_WEEKDAYS (WDAY_MONDAY | WDAY_TUESDAY | WDAY_WEDNESDAY | WDAY_THURSDAY | WDAY_FRIDAY) -#define WDAY_WEEKENDS (WDAY_SUNDAY | WDAY_SATURDAY) -#define WDAY_ANY (WDAY_WEEKENDS | WDAY_WEEKDAYS) - -struct CronJob { - //! internal, no touchy - ListNode list_node; - - //! Cached execution timestamp in UTC. - //! This is set by `cron_job_schedule`, and is required to never be changed once the job has been - //! added. - time_t cached_execute_time; - - //! Callback that is called when the job fires. - CronJobCallback cb; - void *cb_data; - - //! Occasionally, the system gets a clock change event for various reasons: - //! - User changed time-zones or a DST transition happened - //! - User changed the time - //! - Phone sent the current time and was different from ours, so we took theirs. - //! In the first case, the cron job's execute time will always be recalculated. - //! In the other two, we see if the time difference from the old time is >= this. - //! If it is, then we'll recalculate. Otherwise, we leave the calculated time alone. - //! In this way, 0 will always recalculate, and UINT32_MAX will never recalculate. - //! - //! Recalculating would essentially mean that a job that was "skipped over" will not fire until - //! the next match. If recalculation is not done, but the job was skipped over, it will fire - //! instantly. - //! - //! This value is specified in seconds. - uint32_t clock_change_tolerance; - - int8_t minute; //!< 0-59, or CRON_MINUTE_ANY - int8_t hour; //!< 0-23, or CRON_HOUR_ANY - int8_t mday; //!< 0-30, or CRON_MDAY_ANY - int8_t month; //!< 0-11, or CRON_MONTH_ANY - - //! Seconds to offset the cron execution time applied after regular cron job time calculation. - //! For example, a cron scheduled for Monday at 0:15 with an offset of negative 30min will fire - //! on Sunday at 23:45. - int32_t offset_seconds; - - union { - uint8_t flags; - - struct { - //! This should be any combination of WDAY_*. If zero, acts like WDAY_ANY. - uint8_t wday : 7; - - //! If this flag is set, the resulting execution time may be equal to the local epoch. - //! Having it set could be used for some event that must happen at the specified time even if - //! that time is right now. - bool may_be_instant : 1; - }; - }; -}; - -//! Add a cron job. This will make the service hold a reference to the specified job, so it must -//! not leave scope or be destroyed until it is unscheduled. -//! The job only gets scheduled once. For re-scheduling, you can call this on the job again. -//! @param job pointer to the CronJob struct to be scheduled. -//! @returns time_t for when the job is destined to go off. -time_t cron_job_schedule(CronJob *job); - -//! Schedule a cron job to run after another cron job. -//! This will make the service hold a reference to the new job, so it must -//! not leave scope or be destroyed until it is unscheduled. -//! @param job pointer to the CronJob after which we want our job to run. job must be scheduled. -//! @param new_job pointer to the CronJob struct to be scheduled. new_job must be unscheduled. -//! @returns time_t for when the job is destined to go off. -//! @note This API makes no guarantee that the two jobs will be scheduled back to back, -//! only that new_job will have the same scheduled time as job and that it will trigger -//! strictly after job. -time_t cron_job_schedule_after(CronJob *new_job, CronJob *job); - -//! Remove a scheduled cron job. -//! @param job pointer to the CronJob struct to be unscheduled. -//! @return true if the job was successfully removed (false may indicate no job was -//! scheduled at all or the cb is currently executing) -bool cron_job_unschedule(CronJob *job); - -//! Check if a cron job is scheduled. -//! @param job pointer to the CronJob struct to be checked for being scheduled. -//! @returns true if scheduled or pending deletion, false otherwise -bool cron_job_is_scheduled(CronJob *job); - -//! Calculate cron job's destined execution time, from the current time. -//! @param job pointer to the CronJob struct to get the execution time for. -//! @returns time_t for when the job is destined to go off. -time_t cron_job_get_execute_time(const CronJob *job); - -//! Calculate cron job's destined execution time if it were scheduled at the given time. -//! @param job pointer to the CronJob struct to get the execution time for. -//! @param local_epoch the epoch for getting the job's execution time. -//! @returns time_t for when the job is destined to go off. -time_t cron_job_get_execute_time_from_epoch(const CronJob *job, time_t local_epoch); diff --git a/src/fw/kernel/event_loop.c b/src/fw/kernel/event_loop.c index 21e7046890..914fc2f85e 100644 --- a/src/fw/kernel/event_loop.c +++ b/src/fw/kernel/event_loop.c @@ -34,7 +34,7 @@ #include "pbl/services/battery/battery_monitor.h" #include "pbl/services/clock.h" #include "pbl/services/compositor/compositor.h" -#include "pbl/services/cron.h" +#include #include "pbl/services/debounced_connection_service.h" #include "pbl/services/ecompass.h" #include "pbl/services/event_service.h" @@ -468,7 +468,8 @@ static PBL_NOINLINE void prv_extended_event_handler(PebbleEvent *e) { ABS(set_time_info->utc_time_delta) > 15) { alarm_handle_clock_change(); wakeup_handle_significant_clock_change(); - cron_service_handle_clock_change(set_time_info); + pbl_cron_handle_clock_change(set_time_info->utc_time_delta, set_time_info->gmt_offset_delta, + set_time_info->dst_changed); } // Always reschedule wakeup timers on any time change to prevent timers from diff --git a/src/fw/popups/timeline/peek.c b/src/fw/popups/timeline/peek.c index 37c28d4d6d..26fa556e92 100644 --- a/src/fw/popups/timeline/peek.c +++ b/src/fw/popups/timeline/peek.c @@ -16,7 +16,7 @@ #include #include "pbl/util/size.h" -#include +#include #define TIMELINE_PEEK_FRAME_HIDDEN GRect(0, DISP_ROWS, DISP_COLS, TIMELINE_PEEK_HEIGHT) #define TIMELINE_PEEK_OUTER_BORDER_WIDTH PBL_IF_RECT_ELSE(2, 1) @@ -102,16 +102,16 @@ static void prv_redraw(void *PBL_UNUSED data) { layer_mark_dirty(&peek->layout_layer); } -static void prv_cron_callback(CronJob *job, void *PBL_UNUSED data) { +static void prv_cron_callback(struct pbl_cron_job *job, void *PBL_UNUSED data) { launcher_task_add_callback(prv_redraw, NULL); - cron_job_schedule(job); + pbl_cron_job_schedule(job); } -static CronJob s_timeline_peek_job = { - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, +static struct pbl_cron_job s_timeline_peek_job = { + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .cb = prv_cron_callback, }; @@ -428,9 +428,9 @@ void timeline_peek_init(void) { static void prv_set_visible(bool visible, bool animated) { TimelinePeek *peek = &s_peek; if (!peek->started && visible) { - cron_job_schedule(&s_timeline_peek_job); + pbl_cron_job_schedule(&s_timeline_peek_job); } else { - cron_job_unschedule(&s_timeline_peek_job); + pbl_cron_job_unschedule(&s_timeline_peek_job); } prv_transition_frame(peek, visible, animated); } diff --git a/src/fw/prj.conf b/src/fw/prj.conf index 411370163a..21c6ea1b6c 100644 --- a/src/fw/prj.conf +++ b/src/fw/prj.conf @@ -2,6 +2,9 @@ # Values here are applied on top of the board defconfig and below variant- # specific prj_.conf overrides. +# Subsystems. +CONFIG_CRON=y + # Common services. CONFIG_SERVICE_ACCEL_MANAGER=y CONFIG_SERVICE_ANALYTICS=y @@ -12,7 +15,6 @@ CONFIG_SERVICE_BOOT_SPLASH=y CONFIG_SERVICE_CLOCK=y CONFIG_SERVICE_COMM_SESSION=y CONFIG_SERVICE_COMPOSITOR=y -CONFIG_SERVICE_CRON=y CONFIG_SERVICE_DEBOUNCED_CONNECTION_SERVICE=y CONFIG_SERVICE_EVENT_SERVICE=y CONFIG_SERVICE_EVENTED_TIMER=y diff --git a/src/fw/services/CMakeLists.txt b/src/fw/services/CMakeLists.txt index bbf8e76c84..bd8471a0f8 100644 --- a/src/fw/services/CMakeLists.txt +++ b/src/fw/services/CMakeLists.txt @@ -22,7 +22,6 @@ pbl_add_subdirectory_ifdef(CONFIG_SERVICE_CLOCK clock) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_COMM_SESSION comm_session) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_COMPOSITOR compositor) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_CONTACTS contacts) -pbl_add_subdirectory_ifdef(CONFIG_SERVICE_CRON cron) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_DATA_LOGGING data_logging) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_DEBOUNCED_CONNECTION_SERVICE debounced_connection_service) pbl_add_subdirectory_ifdef(CONFIG_SERVICE_ECOMPASS ecompass) diff --git a/src/fw/services/Kconfig b/src/fw/services/Kconfig index 6d01ddd42f..044821b917 100644 --- a/src/fw/services/Kconfig +++ b/src/fw/services/Kconfig @@ -24,7 +24,6 @@ rsource "clock/Kconfig" rsource "comm_session/Kconfig" rsource "compositor/Kconfig" rsource "contacts/Kconfig" -rsource "cron/Kconfig" rsource "data_logging/Kconfig" rsource "debounced_connection_service/Kconfig" rsource "ecompass/Kconfig" diff --git a/src/fw/services/activity/activity.c b/src/fw/services/activity/activity.c index 29da108ffe..27f2501bd9 100644 --- a/src/fw/services/activity/activity.c +++ b/src/fw/services/activity/activity.c @@ -24,7 +24,7 @@ #include "pbl/util/math.h" #include "util/units.h" -#include +#include #include "pbl/kernel/sem.h" @@ -969,16 +969,16 @@ PBL_T_STATIC void prv_minute_system_task_cb(void *data) { // ------------------------------------------------------------------------------------------------ // Runs on the timer task. Simply register a callback for the KernelBG task from here. -static void prv_minute_cb(CronJob *job, void *data) { +static void prv_minute_cb(struct pbl_cron_job *job, void *data) { system_task_add_callback(prv_minute_system_task_cb, data); - cron_job_schedule(job); + pbl_cron_job_schedule(job); } -static CronJob s_activity_job = { - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, +static struct pbl_cron_job s_activity_job = { + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .cb = prv_minute_cb, }; @@ -1231,7 +1231,7 @@ static void prv_start_tracking_cb(void *context) { activity_algorithm_metrics_changed_notification(); // Register our minutes callback - cron_job_schedule(&s_activity_job); + pbl_cron_job_schedule(&s_activity_job); s_activity_state.started = true; PBL_LOG_INFO("Activity tracking started"); @@ -1253,7 +1253,7 @@ static void prv_stop_tracking_cb(void *context) { return; } - cron_job_unschedule(&s_activity_job); + pbl_cron_job_unschedule(&s_activity_job); if (s_activity_state.accel_session) { accel_session_data_unsubscribe(s_activity_state.accel_session); accel_session_delete(s_activity_state.accel_session); @@ -1827,7 +1827,7 @@ bool activity_test_reset(bool reset_settings, bool tracking_on, // Wait for stop_tracking KernelBG callback to run sys_psleep(1); } - cron_job_unschedule(&s_activity_job); + pbl_cron_job_unschedule(&s_activity_job); pbl_mutex_deinit(&s_activity_state.mutex); if (reset_settings) { pfs_remove(ACTIVITY_SETTINGS_FILE_NAME); diff --git a/src/fw/services/alarms/alarm.c b/src/fw/services/alarms/alarm.c index f383ec20e9..94e42db124 100644 --- a/src/fw/services/alarms/alarm.c +++ b/src/fw/services/alarms/alarm.c @@ -24,7 +24,7 @@ #include "pbl/util/string.h" #include "util/units.h" -#include +#include #include @@ -116,7 +116,7 @@ static void prv_alarm_operation(AlarmId id, AlarmOperationCallback callback, voi static bool prv_reload_alarms(SettingsFile *file); static bool prv_alarm_get_config(SettingsFile *file, AlarmId id, AlarmConfig *config_out); static void prv_alarm_set_config(SettingsFile *file, AlarmId id, const AlarmConfig *config); -static void prv_cron_callback(CronJob *job, void *data); +static void prv_cron_callback(struct pbl_cron_job *job, void *data); static void prv_snooze_alarm(int snooze_delay_s, bool user_initiated); static bool prv_set_alarm_kind_op(AlarmId id, AlarmConfig *config, void *context); static bool prv_set_alarm_custom_op(AlarmId id, AlarmConfig *config, void *context); @@ -127,7 +127,7 @@ static time_t s_next_alarm_time; //! This is only valid when s_next_alarm_time is not 0. static Alarm s_next_alarm; -static CronJob s_next_alarm_cron; +static struct pbl_cron_job s_next_alarm_cron; static AlarmId s_most_recent_alarm_id = ALARM_INVALID_ID; static AlarmConfig s_most_recent_alarm_config; static bool s_most_recent_alarm_recorded; @@ -254,8 +254,8 @@ static void prv_add_pin(AlarmId id, const AlarmConfig *config, time_t alarm_time // ---------------------------------------------------------------------------------------------- //! Pins alarm in the timeline for the next three days -static void prv_timeline_add_alarm(SettingsFile *file, const Alarm *alarm, const CronJob *cron, - const time_t current_time) { +static void prv_timeline_add_alarm(SettingsFile *file, const Alarm *alarm, + const struct pbl_cron_job *cron, const time_t current_time) { // If an alarm was updated then remove all the pins with stale information // If an alarm was added then this has no effect bool updated = prv_timeline_remove_alarm(file, alarm->id); @@ -269,7 +269,7 @@ static void prv_timeline_add_alarm(SettingsFile *file, const Alarm *alarm, const } int num_pin_adds = 0; - time_t alarm_time = prv_get_alarm_time(alarm, cron_job_get_execute_time(cron)); + time_t alarm_time = prv_get_alarm_time(alarm, pbl_cron_job_get_execute_time(cron)); time_t last_alarm = 0; for (int i = 0; alarm_time <= current_time + SECONDS_PER_DAY * 3; i++) { @@ -285,8 +285,8 @@ static void prv_timeline_add_alarm(SettingsFile *file, const Alarm *alarm, const } } } - alarm_time = prv_get_alarm_time( - alarm, cron_job_get_execute_time_from_epoch(cron, current_time + (i * SECONDS_PER_DAY))); + alarm_time = prv_get_alarm_time(alarm, pbl_cron_job_get_execute_time_from_epoch( + cron, current_time + (i * SECONDS_PER_DAY))); } AlarmStorageKey key = {.id = alarm->id, .type = ALARM_DATA_PINS}; @@ -299,15 +299,15 @@ static void prv_timeline_add_alarm(SettingsFile *file, const Alarm *alarm, const } // ---------------------------------------------------------------------------------------------- -static time_t prv_build_cron(AlarmConfig *config, CronJob *cron) { - *cron = (CronJob){ +static time_t prv_build_cron(AlarmConfig *config, struct pbl_cron_job *cron) { + *cron = (struct pbl_cron_job){ .cb = prv_cron_callback, .cb_data = (void *)0, .minute = config->minute, .hour = config->hour, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = config->is_smart ? -SMART_ALARM_RANGE_S : 0, @@ -317,16 +317,16 @@ static time_t prv_build_cron(AlarmConfig *config, CronJob *cron) { for (int i = 0; i < DAYS_PER_WEEK; i++) { cron->wday |= config->scheduled_days[i] ? (1 << i) : 0; } - return cron_job_get_execute_time(cron); + return pbl_cron_job_get_execute_time(cron); } // ---------------------------------------------------------------------------------------------- -static void prv_assign_alarm(Alarm *alarm, CronJob *cron) { - cron_job_unschedule(&s_next_alarm_cron); +static void prv_assign_alarm(Alarm *alarm, struct pbl_cron_job *cron) { + pbl_cron_job_unschedule(&s_next_alarm_cron); s_next_alarm_cron = *cron; s_next_alarm_cron.cb_data = (void *)(intptr_t)alarm->id; s_next_alarm = *alarm; - s_next_alarm_time = cron_job_schedule(&s_next_alarm_cron); + s_next_alarm_time = pbl_cron_job_schedule(&s_next_alarm_cron); PBL_LOG_INFO("Scheduling alarm %u to go off at %d:%d (%ld) (smart:%d)", alarm->id, alarm->config.hour, alarm->config.minute, s_next_alarm_time, alarm->config.is_smart); } @@ -343,7 +343,7 @@ static void prv_check_and_schedule_alarm(SettingsFile *fd, Alarm *alarm, bool re return; } - CronJob cron; + struct pbl_cron_job cron; time_t execute_time = prv_build_cron(&alarm->config, &cron); prv_timeline_add_alarm(fd, alarm, &cron, rtc_get_time()); @@ -380,7 +380,7 @@ static bool prv_reload_alarms(SettingsFile *file) { bool alarm_found = false; s_next_alarm_time = 0; - cron_job_unschedule(&s_next_alarm_cron); + pbl_cron_job_unschedule(&s_next_alarm_cron); for (int i = 0; i < MAX_CONFIGURED_ALARMS; ++i) { AlarmConfig config; @@ -513,7 +513,7 @@ PBL_T_STATIC void prv_timer_kernel_bg_callback(void *data) { prv_process_most_recent_alarm(); } -static void prv_cron_callback(CronJob *job, void *data) { +static void prv_cron_callback(struct pbl_cron_job *job, void *data) { system_task_add_callback(prv_timer_kernel_bg_callback, data); } @@ -998,7 +998,7 @@ bool alarm_get_time_until(AlarmId id, time_t *time_out) { } if (time_out) { - CronJob cron; + struct pbl_cron_job cron; *time_out = prv_build_cron(&config, &cron) - rtc_get_time(); } alarm_is_scheduled = true; diff --git a/src/fw/services/notifications/do_not_disturb.c b/src/fw/services/notifications/do_not_disturb.c index 9deca0dbd9..5ec1253415 100644 --- a/src/fw/services/notifications/do_not_disturb.c +++ b/src/fw/services/notifications/do_not_disturb.c @@ -26,7 +26,7 @@ #include "pbl/util/math.h" #include "util/time/time.h" -#include +#include #include PBL_LOG_MODULE_DECLARE(service_notifications, CONFIG_SERVICE_NOTIFICATIONS_LOG_LEVEL); @@ -41,11 +41,11 @@ static DoNotDisturbData s_data; //! Cron jobs for the schedule boundaries, and for midnight of the days on //! which the weekday/weekend schedule takes over from the other. -static CronJob s_weekday_from_job; -static CronJob s_weekday_to_job; -static CronJob s_weekend_from_job; -static CronJob s_weekend_to_job; -static CronJob s_schedule_switch_job; +static struct pbl_cron_job s_weekday_from_job; +static struct pbl_cron_job s_weekday_to_job; +static struct pbl_cron_job s_weekend_from_job; +static struct pbl_cron_job s_weekend_to_job; +static struct pbl_cron_job s_schedule_switch_job; static bool prv_is_smart_dnd_active(void); static bool prv_is_schedule_active(void); @@ -142,7 +142,7 @@ static void prv_try_update_schedule_mode_callback(bool clear_manual_override) { system_task_add_callback(prv_try_update_schedule_mode, (void *)(uintptr_t)clear_manual_override); } -static void prv_schedule_cron_callback(CronJob *job, void *data) { +static void prv_schedule_cron_callback(struct pbl_cron_job *job, void *data) { prv_try_update_schedule_mode_callback(true); } @@ -173,20 +173,20 @@ static bool prv_is_in_schedule_period(void) { return from != to && (now >= from || now < to); } -static void prv_schedule_job(CronJob *job, int hour, int minute, uint8_t wday) { - *job = (CronJob){ +static void prv_schedule_job(struct pbl_cron_job *job, int hour, int minute, uint8_t wday) { + *job = (struct pbl_cron_job){ .cb = prv_schedule_cron_callback, .minute = minute, .hour = hour, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .wday = wday, }; - cron_job_schedule(job); + pbl_cron_job_schedule(job); } -static void prv_schedule_jobs(DoNotDisturbScheduleType type, CronJob *from_job, CronJob *to_job, - uint8_t wday) { +static void prv_schedule_jobs(DoNotDisturbScheduleType type, struct pbl_cron_job *from_job, + struct pbl_cron_job *to_job, uint8_t wday) { DoNotDisturbSchedule schedule; do_not_disturb_get_schedule(type, &schedule); prv_schedule_job(from_job, schedule.from_hour, schedule.from_minute, wday); @@ -194,22 +194,24 @@ static void prv_schedule_jobs(DoNotDisturbScheduleType type, CronJob *from_job, } static void prv_update_schedule_mode(void) { - cron_job_unschedule(&s_weekday_from_job); - cron_job_unschedule(&s_weekday_to_job); - cron_job_unschedule(&s_weekend_from_job); - cron_job_unschedule(&s_weekend_to_job); - cron_job_unschedule(&s_schedule_switch_job); + pbl_cron_job_unschedule(&s_weekday_from_job); + pbl_cron_job_unschedule(&s_weekday_to_job); + pbl_cron_job_unschedule(&s_weekend_from_job); + pbl_cron_job_unschedule(&s_weekend_to_job); + pbl_cron_job_unschedule(&s_schedule_switch_job); const bool weekday_enabled = do_not_disturb_is_schedule_enabled(WeekdaySchedule); const bool weekend_enabled = do_not_disturb_is_schedule_enabled(WeekendSchedule); if (weekday_enabled) { - prv_schedule_jobs(WeekdaySchedule, &s_weekday_from_job, &s_weekday_to_job, WDAY_WEEKDAYS); + prv_schedule_jobs(WeekdaySchedule, &s_weekday_from_job, &s_weekday_to_job, + PBL_CRON_WDAY_WEEKDAYS); } if (weekend_enabled) { - prv_schedule_jobs(WeekendSchedule, &s_weekend_from_job, &s_weekend_to_job, WDAY_WEEKENDS); + prv_schedule_jobs(WeekendSchedule, &s_weekend_from_job, &s_weekend_to_job, + PBL_CRON_WDAY_WEEKENDS); } if (weekday_enabled || weekend_enabled) { - prv_schedule_job(&s_schedule_switch_job, 0, 0, WDAY_MONDAY | WDAY_SATURDAY); + prv_schedule_job(&s_schedule_switch_job, 0, 0, PBL_CRON_WDAY_MONDAY | PBL_CRON_WDAY_SATURDAY); } const bool in_period = prv_is_in_schedule_period(); diff --git a/src/fw/services/services_common/service.c b/src/fw/services/services_common/service.c index a6d050cc84..651f55c024 100644 --- a/src/fw/services/services_common/service.c +++ b/src/fw/services/services_common/service.c @@ -16,7 +16,7 @@ #include "pbl/services/comm_session/app_session_capabilities.h" #include "pbl/services/comm_session/default_kernel_sender.h" #include "pbl/services/comm_session/session.h" -#include "pbl/services/cron.h" +#include #include "pbl/services/firmware_update.h" #include "pbl/services/hrm/hrm_manager.h" #include "pbl/services/light.h" @@ -37,7 +37,7 @@ void services_common_init(void) { accel_manager_init(); light_init(); - cron_service_init(); + pbl_cron_init(); shared_prf_storage_init(); bt_persistent_storage_init(); diff --git a/subsys/CMakeLists.txt b/subsys/CMakeLists.txt index e72cce6a28..66caa075fc 100644 --- a/subsys/CMakeLists.txt +++ b/subsys/CMakeLists.txt @@ -2,4 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 pbl_include_directories(.) +pbl_add_subdirectory_ifdef(CONFIG_CRON cron) add_subdirectory(logging) diff --git a/subsys/Kconfig b/subsys/Kconfig index 28de460e07..bb4ddb1ee3 100644 --- a/subsys/Kconfig +++ b/subsys/Kconfig @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2026 Core Devices LLC # SPDX-License-Identifier: Apache-2.0 +rsource "cron/Kconfig" rsource "logging/Kconfig" diff --git a/src/fw/services/cron/CMakeLists.txt b/subsys/cron/CMakeLists.txt similarity index 76% rename from src/fw/services/cron/CMakeLists.txt rename to subsys/cron/CMakeLists.txt index 524d8b6ddb..fa03cd3f0f 100644 --- a/src/fw/services/cron/CMakeLists.txt +++ b/subsys/cron/CMakeLists.txt @@ -2,4 +2,4 @@ # SPDX-License-Identifier: Apache-2.0 pbl_library() -pbl_library_sources(service.c) +pbl_library_sources(cron.c) diff --git a/src/fw/services/cron/Kconfig b/subsys/cron/Kconfig similarity index 61% rename from src/fw/services/cron/Kconfig rename to subsys/cron/Kconfig index b896ed5ab4..28b2358449 100644 --- a/src/fw/services/cron/Kconfig +++ b/subsys/cron/Kconfig @@ -1,14 +1,15 @@ # SPDX-FileCopyrightText: 2026 Core Devices LLC # SPDX-License-Identifier: Apache-2.0 -config SERVICE_CRON +config CRON bool "Cron" help - Cron-like scheduler for periodic jobs. + Wall-clock based job scheduler that handles DST and time zone + changes. -if SERVICE_CRON +if CRON -module = SERVICE_CRON +module = CRON module-str = Cron source "subsys/logging/Kconfig.template.log_level" diff --git a/src/fw/services/cron/service.c b/subsys/cron/cron.c similarity index 86% rename from src/fw/services/cron/service.c rename to subsys/cron/cron.c index 7c17176eeb..b10a1402af 100644 --- a/src/fw/services/cron/service.c +++ b/subsys/cron/cron.c @@ -1,8 +1,7 @@ /* SPDX-FileCopyrightText: 2024 Google LLC */ /* SPDX-License-Identifier: Apache-2.0 */ -#include "pbl/services/cron.h" -#include +#include #include #include "pbl/kernel/mutex.h" @@ -11,7 +10,7 @@ #include "system/passert.h" #include "pbl/util/math.h" -PBL_LOG_MODULE_DEFINE(service_cron, CONFIG_SERVICE_CRON_LOG_LEVEL); +PBL_LOG_MODULE_DEFINE(cron, CONFIG_CRON_LOG_LEVEL); //! Don't let users modify the list while callbacks are occurring. static PBL_MUTEX_DEFINE(s_list_mutex); @@ -37,7 +36,7 @@ static void prv_arm_wakeup(void) { time_t now; uint16_t milliseconds; rtc_get_time_ms(&now, &milliseconds); - const time_t execute_time = ((CronJob *)s_scheduled_jobs)->cached_execute_time; + const time_t execute_time = ((struct pbl_cron_job *)s_scheduled_jobs)->cached_execute_time; int32_t delta_s = (execute_time > now) ? (int32_t)(execute_time - now) : 0; delta_s = MIN(delta_s, CRON_MAX_ARM_INTERVAL_S); uint32_t timeout_ms = (uint32_t)delta_s * 1000U; @@ -48,14 +47,14 @@ static void prv_arm_wakeup(void) { } // ------------------------------------------------------------------------------------------- -static bool prv_is_scheduled(CronJob *job) { +static bool prv_is_scheduled(struct pbl_cron_job *job) { // Assumes mutex lock is already taken return list_contains(s_scheduled_jobs, &job->list_node); } static int prv_sort(void *a, void *b) { - CronJob *job_a = (CronJob *)a; - CronJob *job_b = (CronJob *)b; + struct pbl_cron_job *job_a = (struct pbl_cron_job *)a; + struct pbl_cron_job *job_b = (struct pbl_cron_job *)b; return job_b->cached_execute_time - job_a->cached_execute_time; } @@ -63,8 +62,8 @@ static int prv_sort(void *a, void *b) { static void prv_timer_callback(void *data) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); while (s_scheduled_jobs != NULL && - ((CronJob *)s_scheduled_jobs)->cached_execute_time <= rtc_get_time()) { - CronJob *job = (CronJob *)s_scheduled_jobs; + ((struct pbl_cron_job *)s_scheduled_jobs)->cached_execute_time <= rtc_get_time()) { + struct pbl_cron_job *job = (struct pbl_cron_job *)s_scheduled_jobs; // Remove the job from the list, it's done. s_scheduled_jobs = list_pop_head(s_scheduled_jobs); @@ -78,21 +77,22 @@ static void prv_timer_callback(void *data) { } // -------------------------------------------------------------------------------------------- -void cron_service_handle_clock_change(PebbleSetTimeEvent *set_time_info) { +void pbl_cron_handle_clock_change(int32_t utc_time_delta, int32_t gmt_offset_delta, + bool dst_changed) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); - const bool must_recalc = set_time_info->gmt_offset_delta != 0 || set_time_info->dst_changed; + const bool must_recalc = gmt_offset_delta != 0 || dst_changed; // Because it's ABS, it'll be unsigned. This makes the compiler behave. - const uint32_t change_diff = ABS(set_time_info->utc_time_delta); + const uint32_t change_diff = ABS(utc_time_delta); // Need to re-build the list somewhere else ListNode *newlist = NULL; while (s_scheduled_jobs != NULL) { - CronJob *job = (CronJob *)s_scheduled_jobs; + struct pbl_cron_job *job = (struct pbl_cron_job *)s_scheduled_jobs; s_scheduled_jobs = list_pop_head(s_scheduled_jobs); // Re-calculate the execute time. // See the notes in the API header on how this works. if (must_recalc || change_diff >= job->clock_change_tolerance) { - job->cached_execute_time = cron_job_get_execute_time(job); + job->cached_execute_time = pbl_cron_job_get_execute_time(job); } PBL_LOG_DBG("Cron job rescheduled for %ld", job->cached_execute_time); @@ -108,7 +108,7 @@ void cron_service_handle_clock_change(PebbleSetTimeEvent *set_time_info) { } // -------------------------------------------------------------------------------------------- -void cron_service_init(void) { +void pbl_cron_init(void) { s_scheduled_jobs = NULL; if (s_wakeup_timer == TIMER_INVALID_ID) { @@ -117,12 +117,12 @@ void cron_service_init(void) { } // ------------------------------------------------------------------------------------------- -time_t cron_job_schedule(CronJob *job) { +time_t pbl_cron_job_schedule(struct pbl_cron_job *job) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); const time_t now = rtc_get_time(); // Always update the execution time. - job->cached_execute_time = cron_job_get_execute_time_from_epoch(job, now); + job->cached_execute_time = pbl_cron_job_get_execute_time_from_epoch(job, now); // If not scheduled yet, schedule it. if (!prv_is_scheduled(job)) { s_scheduled_jobs = list_sorted_add(s_scheduled_jobs, &job->list_node, prv_sort, true); @@ -137,7 +137,7 @@ time_t cron_job_schedule(CronJob *job) { } // ------------------------------------------------------------------------------------------ -time_t cron_job_schedule_after(CronJob *job, CronJob *new_job) { +time_t pbl_cron_job_schedule_after(struct pbl_cron_job *job, struct pbl_cron_job *new_job) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); // can't schedule an already scheduled job @@ -146,7 +146,7 @@ time_t cron_job_schedule_after(CronJob *job, CronJob *new_job) { PBL_ASSERTN(prv_is_scheduled(job)); // copy schedule info from existing job - CronJob temp_job = *job; + struct pbl_cron_job temp_job = *job; list_init(&temp_job.list_node); temp_job.cb = new_job->cb; temp_job.cb_data = new_job->cb_data; @@ -163,7 +163,7 @@ time_t cron_job_schedule_after(CronJob *job, CronJob *new_job) { } // ------------------------------------------------------------------------------------------ -bool cron_job_is_scheduled(CronJob *job) { +bool pbl_cron_job_is_scheduled(struct pbl_cron_job *job) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); bool rv = prv_is_scheduled(job); pbl_mutex_unlock(&s_list_mutex); @@ -172,7 +172,7 @@ bool cron_job_is_scheduled(CronJob *job) { } // ------------------------------------------------------------------------------------------ -bool cron_job_unschedule(CronJob *job) { +bool pbl_cron_job_unschedule(struct pbl_cron_job *job) { bool removed = false; pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); @@ -189,12 +189,12 @@ bool cron_job_unschedule(CronJob *job) { // --------------------------------------------------------------------------------------- // For Testing: -void cron_clear_all_jobs(void) { +void pbl_cron_clear_all_jobs(void) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); // Iterate over all the jobs to remove them all. for (ListNode *iter = s_scheduled_jobs; iter != NULL;) { - CronJob *job = (CronJob *)iter; + struct pbl_cron_job *job = (struct pbl_cron_job *)iter; iter = list_get_next(iter); // Remove the job from the list. list_remove(&job->list_node, NULL, NULL); @@ -205,13 +205,13 @@ void cron_clear_all_jobs(void) { pbl_mutex_unlock(&s_list_mutex); } -void cron_service_deinit(void) { - cron_clear_all_jobs(); +void pbl_cron_deinit(void) { + pbl_cron_clear_all_jobs(); new_timer_stop(s_wakeup_timer); } -uint32_t cron_service_get_job_count(void) { +uint32_t pbl_cron_get_job_count(void) { uint32_t count = 0; pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); count = list_count(s_scheduled_jobs); @@ -219,13 +219,14 @@ uint32_t cron_service_get_job_count(void) { return count; } -void cron_service_wakeup(void) { +void pbl_cron_wakeup(void) { prv_timer_callback(NULL); } -time_t cron_service_get_next_execute_time(void) { +time_t pbl_cron_get_next_execute_time(void) { pbl_mutex_lock(&s_list_mutex, PBL_FOREVER); - const time_t rv = s_scheduled_jobs ? ((CronJob *)s_scheduled_jobs)->cached_execute_time : 0; + const time_t rv = + s_scheduled_jobs ? ((struct pbl_cron_job *)s_scheduled_jobs)->cached_execute_time : 0; pbl_mutex_unlock(&s_list_mutex); return rv; } @@ -268,9 +269,9 @@ static int prv_future_past_direction(int **dest_arr, const int *curr_arr) { // Increase the day in `cron_tm` to fit into the wday set in `cron`. // This doesn't take mday into account because that's way too hard and we won't need it. -static bool prv_adjust_for_wday_spec(const CronJob *cron, struct tm *cron_tm) { +static bool prv_adjust_for_wday_spec(const struct pbl_cron_job *cron, struct tm *cron_tm) { // If we're allowing any wday, we're not adjusting. - if (cron->wday == WDAY_ANY || cron->wday == 0) { + if (cron->wday == PBL_CRON_WDAY_ANY || cron->wday == 0) { return false; } @@ -294,7 +295,7 @@ static bool prv_adjust_for_wday_spec(const CronJob *cron, struct tm *cron_tm) { return adjusted; } -static time_t prv_get_execute_time_from_epoch(const CronJob *job, time_t local_epoch) { +static time_t prv_get_execute_time_from_epoch(const struct pbl_cron_job *job, time_t local_epoch) { struct tm current_tm; // We work off of each element, so we need a struct tm. localtime_r(&local_epoch, ¤t_tm); @@ -436,7 +437,8 @@ static time_t prv_get_execute_time_from_epoch(const CronJob *job, time_t local_e return t; } -time_t cron_job_get_execute_time_from_epoch(const CronJob *job, time_t local_epoch) { +time_t pbl_cron_job_get_execute_time_from_epoch(const struct pbl_cron_job *job, + time_t local_epoch) { time_t t = prv_get_execute_time_from_epoch(job, local_epoch); if (job->offset_seconds != 0) { @@ -464,6 +466,6 @@ time_t cron_job_get_execute_time_from_epoch(const CronJob *job, time_t local_epo return t; } -time_t cron_job_get_execute_time(const CronJob *job) { - return cron_job_get_execute_time_from_epoch(job, rtc_get_time()); +time_t pbl_cron_job_get_execute_time(const struct pbl_cron_job *job) { + return pbl_cron_job_get_execute_time_from_epoch(job, rtc_get_time()); } diff --git a/tests/fakes/fake_cron.h b/tests/fakes/fake_cron.h index ae58bc3f77..bf85c7e0ce 100644 --- a/tests/fakes/fake_cron.h +++ b/tests/fakes/fake_cron.h @@ -3,25 +3,25 @@ #pragma once -#include +#include #include "clar_asserts.h" -static CronJob *s_job = NULL; +static struct pbl_cron_job *s_job = NULL; -time_t cron_job_schedule(CronJob *job) { +time_t pbl_cron_job_schedule(struct pbl_cron_job *job) { s_job = job; return 0; } -bool cron_job_unschedule(CronJob *job) { +bool pbl_cron_job_unschedule(struct pbl_cron_job *job) { s_job = NULL; return true; } void fake_cron_job_fire(void) { cl_assert(s_job != NULL); - CronJob *job = s_job; + struct pbl_cron_job *job = s_job; s_job = NULL; job->cb(job, job->cb_data); } diff --git a/tests/fw/CMakeLists.txt b/tests/fw/CMakeLists.txt index c9ff01d56b..c8ba970a13 100644 --- a/tests/fw/CMakeLists.txt +++ b/tests/fw/CMakeLists.txt @@ -117,7 +117,7 @@ pbl_clar_test(test_alarm src/fw/util/time/mktime.c src/fw/util/rand/rand.c third_party/tinymt/TinyMT/tinymt/tinymt32.c - src/fw/services/cron/service.c + subsys/cron/cron.c src/fw/services/filesystem/flash_translation.c src/fw/services/filesystem/pfs.c src/fw/services/blob_db/timeline_item_storage.c @@ -143,7 +143,7 @@ pbl_clar_test(test_alarm_smart src/fw/util/time/time.c src/fw/util/time/mktime.c third_party/tinymt/TinyMT/tinymt/tinymt32.c - src/fw/services/cron/service.c + subsys/cron/cron.c src/fw/services/filesystem/flash_translation.c src/fw/services/filesystem/pfs.c src/fw/services/blob_db/timeline_item_storage.c diff --git a/tests/fw/services/CMakeLists.txt b/tests/fw/services/CMakeLists.txt index 714028f7d6..8f6d833018 100644 --- a/tests/fw/services/CMakeLists.txt +++ b/tests/fw/services/CMakeLists.txt @@ -49,7 +49,7 @@ pbl_clar_test(test_put_bytes pbl_clar_test(test_cron SOURCES tests/fakes/fake_rtc.c - src/fw/services/cron/service.c + subsys/cron/cron.c src/fw/util/time/time.c src/fw/util/time/mktime.c ) @@ -418,7 +418,7 @@ pbl_clar_test(test_do_not_disturb src/fw/services/settings/settings_raw_iter.c src/fw/services/notifications/alerts_preferences.c src/fw/services/notifications/do_not_disturb.c - src/fw/services/cron/service.c + subsys/cron/cron.c src/fw/util/time/time.c src/fw/util/time/mktime.c src/fw/util/crc8.c diff --git a/tests/fw/services/test_cron.c b/tests/fw/services/test_cron.c index 77da26a0c2..30cd41d15f 100644 --- a/tests/fw/services/test_cron.c +++ b/tests/fw/services/test_cron.c @@ -3,12 +3,10 @@ #include "clar.h" -#include "pbl/services/cron.h" +#include #include "pbl/services/new_timer/new_timer.h" #include "pbl/util/size.h" -#include - #include "stubs_logging.h" #include "stubs_mutex.h" #include "stubs_passert.h" @@ -53,11 +51,11 @@ static const TimezoneInfo s_timezone_gmt = { void test_cron__initialize(void) { s_timer_timeout_ms = 0; - cron_service_init(); + pbl_cron_init(); } void test_cron__cleanup(void) { - cron_service_deinit(); + pbl_cron_deinit(); } static TimezoneInfo g_timezone; @@ -67,67 +65,62 @@ static void prv_set_rtc(time_t t, const TimezoneInfo *tz_info) { time_util_update_timezone(&g_timezone); } -static void prv_cron_callback(CronJob *job, void *data) { +static void prv_cron_callback(struct pbl_cron_job *job, void *data) { job->cb_data = (void *)((uintptr_t)data + 1); } static void prv_clock_change(int32_t time_diff, int32_t gmt_diff, bool dst_trans) { - PebbleSetTimeEvent set_time_info = { - .utc_time_delta = time_diff, - .gmt_offset_delta = gmt_diff, - .dst_changed = dst_trans, - }; rtc_set_time(rtc_get_time() + time_diff); g_timezone.tm_gmtoff += gmt_diff; time_util_update_timezone(&g_timezone); - cron_service_handle_clock_change(&set_time_info); + pbl_cron_handle_clock_change(time_diff, gmt_diff, dst_trans); } void test_cron__timer_aligned_to_execute_second(void) { - CronJob job = { + struct pbl_cron_job job = { .cb = prv_cron_callback, .minute = 45, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, }; prv_set_rtc(s_2015_nov12_123456_gmt, &s_timezone_gmt); fake_rtc_increment_time_ms(750); - const time_t execute_time = cron_job_schedule(&job); + const time_t execute_time = pbl_cron_job_schedule(&job); cl_assert_equal_i(execute_time, 1447332300); cl_assert_equal_i(s_timer_timeout_ms, 603250); - cl_assert(cron_job_unschedule(&job)); + cl_assert(pbl_cron_job_unschedule(&job)); } void test_cron__time_change_basic(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 45, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, .clock_change_tolerance = 0, }; - CronJob *job = &test_cron; + struct pbl_cron_job *job = &test_cron; time_t base = s_2015_nov12_123456_gmt; prv_set_rtc(base, &s_timezone_gmt); // 2015 Nov 12, 12:45:00 int32_t target = 1447332300; - cron_clear_all_jobs(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_clear_all_jobs(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); - cron_job_schedule(job); + pbl_cron_job_schedule(job); cl_assert_equal_i((uintptr_t)job->cb_data, 0); cl_assert_equal_i(job->cached_execute_time, target); - cl_assert_equal_i(cron_service_get_job_count(), 1); + cl_assert_equal_i(pbl_cron_get_job_count(), 1); // Mutate the execute time to see if we actually effect change. job->cached_execute_time = UINT32_MAX; @@ -171,49 +164,49 @@ void test_cron__time_change_basic(void) { prv_clock_change(INT32_MAX, 0, false); cl_assert_equal_i(job->cached_execute_time, UINT32_MAX); - cron_clear_all_jobs(); + pbl_cron_clear_all_jobs(); } void test_cron__time_change_instant(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 35, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, .clock_change_tolerance = 0, }; - CronJob *job = &test_cron; + struct pbl_cron_job *job = &test_cron; time_t base = s_2015_nov12_123456_gmt; prv_set_rtc(base, &s_timezone_gmt); // 2015 Nov 12, 12:35:00 int32_t target = 1447331700; - cron_clear_all_jobs(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_clear_all_jobs(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); - cron_job_schedule(job); + pbl_cron_job_schedule(job); cl_assert_equal_i((uintptr_t)job->cb_data, 0); cl_assert_equal_i(job->cached_execute_time, target); - cl_assert_equal_i(cron_service_get_job_count(), 1); + cl_assert_equal_i(pbl_cron_get_job_count(), 1); // Mutate the execute time to see if we actually effect change. job->clock_change_tolerance = 100; prv_clock_change(10, 0, false); cl_assert_equal_i((uintptr_t)job->cb_data, 1); cl_assert_equal_i(job->cached_execute_time, target); - cl_assert_equal_i(cron_service_get_job_count(), 0); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); - cron_clear_all_jobs(); + pbl_cron_clear_all_jobs(); } -static void prv_basic_test(const TimezoneInfo *tz_info, CronJob *job, time_t base, time_t offset, - time_t increment, int dst_type) { +static void prv_basic_test(const TimezoneInfo *tz_info, struct pbl_cron_job *job, time_t base, + time_t offset, time_t increment, int dst_type) { TimezoneInfo new_tz_info = *tz_info; switch (dst_type) { case 0: @@ -229,43 +222,43 @@ static void prv_basic_test(const TimezoneInfo *tz_info, CronJob *job, time_t bas } prv_set_rtc(base, &new_tz_info); - cron_clear_all_jobs(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_clear_all_jobs(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); job->cb_data = (void *)0; - cron_job_schedule(job); + pbl_cron_job_schedule(job); cl_assert_equal_i((uintptr_t)job->cb_data, 0); cl_assert_equal_i(job->cached_execute_time, base + offset); - cl_assert_equal_i(cron_service_get_job_count(), 1); + cl_assert_equal_i(pbl_cron_get_job_count(), 1); // Check that the timer doesn't fire early if (offset > 0) { fake_rtc_increment_time(increment - 1); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i((uintptr_t)job->cb_data, 0); cl_assert_equal_i(job->cached_execute_time, base + offset); - cl_assert_equal_i(cron_service_get_job_count(), 1); + cl_assert_equal_i(pbl_cron_get_job_count(), 1); fake_rtc_increment_time(1); } else { fake_rtc_increment_time(increment); } - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i((uintptr_t)job->cb_data, 1); cl_assert_equal_i(job->cached_execute_time, base + offset); - cl_assert_equal_i(cron_service_get_job_count(), 0); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); } void test_cron__1_basic(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }; @@ -274,15 +267,15 @@ void test_cron__1_basic(void) { } void test_cron__4_basic(void) { - CronJob test_cron[4] = { + struct pbl_cron_job test_cron[4] = { { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 45, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }, @@ -290,10 +283,10 @@ void test_cron__4_basic(void) { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, + .minute = PBL_CRON_MINUTE_ANY, .hour = 13, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }, @@ -301,10 +294,10 @@ void test_cron__4_basic(void) { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, .mday = 12, - .month = CRON_MONTH_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }, @@ -312,9 +305,9 @@ void test_cron__4_basic(void) { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, .month = 11, .may_be_instant = true, @@ -329,24 +322,24 @@ void test_cron__4_basic(void) { prv_set_rtc(s_2015_nov12_123456_gmt, &s_timezone_gmt); - cron_clear_all_jobs(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_clear_all_jobs(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); // Add the jobs in reverse order to make sure they add properly. for (int i = 0; i < 4; i++) { - CronJob *job = &test_cron[4 - i - 1]; - cron_job_schedule(job); + struct pbl_cron_job *job = &test_cron[4 - i - 1]; + pbl_cron_job_schedule(job); cl_assert_equal_i((uintptr_t)job->cb_data, 0); cl_assert_equal_i(job->cached_execute_time, timestamps[4 - i - 1]); - cl_assert_equal_i(cron_service_get_job_count(), i + 1); + cl_assert_equal_i(pbl_cron_get_job_count(), i + 1); } time_t left = s_2015_nov12_123456_gmt; for (int i = 0; i < 4; i++) { fake_rtc_increment_time(timestamps[i] - left); left = timestamps[i]; - cron_service_wakeup(); - cl_assert_equal_i(cron_service_get_job_count(), 4 - i - 1); + pbl_cron_wakeup(); + cl_assert_equal_i(pbl_cron_get_job_count(), 4 - i - 1); for (int l = 0; l < 4; l++) { cl_assert_equal_i((uintptr_t)test_cron[l].cb_data, i >= l ? 1 : 0); } @@ -354,14 +347,14 @@ void test_cron__4_basic(void) { } void test_cron__already_elapsed(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }; @@ -377,89 +370,93 @@ struct { //////// 'future' time finding // minute // 2015 Nov 12, 12:45:00 - {-1, -1, -1, 45, WDAY_ANY, 1447332300}, + {-1, -1, -1, 45, PBL_CRON_WDAY_ANY, 1447332300}, // hour // 2015 Nov 12, 13:00:00 - {-1, -1, 13, -1, WDAY_ANY, 1447333200}, + {-1, -1, 13, -1, PBL_CRON_WDAY_ANY, 1447333200}, // hour+minute // 2015 Nov 12, 13:45:00 - {-1, -1, 13, 45, WDAY_ANY, 1447335900}, + {-1, -1, 13, 45, PBL_CRON_WDAY_ANY, 1447335900}, // mday // 2015 Nov 13, 00:00:00 - {-1, 12, -1, -1, WDAY_ANY, 1447372800}, + {-1, 12, -1, -1, PBL_CRON_WDAY_ANY, 1447372800}, // mday+minute // 2015 Nov 13, 00:45:00 - {-1, 12, -1, 45, WDAY_ANY, 1447375500}, + {-1, 12, -1, 45, PBL_CRON_WDAY_ANY, 1447375500}, // mday+hour // 2015 Nov 13, 13:00:00 - {-1, 12, 13, -1, WDAY_ANY, 1447419600}, + {-1, 12, 13, -1, PBL_CRON_WDAY_ANY, 1447419600}, // mday+hour+minute // 2015 Nov 13, 13:45:00 - {-1, 12, 13, 45, WDAY_ANY, 1447422300}, + {-1, 12, 13, 45, PBL_CRON_WDAY_ANY, 1447422300}, // month // 2015 Dec 1, 00:00:00 - {11, -1, -1, -1, WDAY_ANY, 1448928000}, + {11, -1, -1, -1, PBL_CRON_WDAY_ANY, 1448928000}, // month+minute // 2015 Dec 1, 00:45:00 - {11, -1, -1, 45, WDAY_ANY, 1448930700}, + {11, -1, -1, 45, PBL_CRON_WDAY_ANY, 1448930700}, // month+hour // 2015 Dec 1, 13:00:00 - {11, -1, 13, -1, WDAY_ANY, 1448974800}, + {11, -1, 13, -1, PBL_CRON_WDAY_ANY, 1448974800}, // month+hour+minute // 2015 Dec 1, 13:45:00 - {11, -1, 13, 45, WDAY_ANY, 1448977500}, + {11, -1, 13, 45, PBL_CRON_WDAY_ANY, 1448977500}, // month+mday // 2015 Dec 13, 00:00:00 - {11, 12, -1, -1, WDAY_ANY, 1449964800}, + {11, 12, -1, -1, PBL_CRON_WDAY_ANY, 1449964800}, // month+mday+minute // 2015 Dec 13, 00:45:00 - {11, 12, -1, 45, WDAY_ANY, 1449967500}, + {11, 12, -1, 45, PBL_CRON_WDAY_ANY, 1449967500}, // month+mday+hour // 2015 Dec 13, 13:00:00 - {11, 12, 13, -1, WDAY_ANY, 1450011600}, + {11, 12, 13, -1, PBL_CRON_WDAY_ANY, 1450011600}, // month+mday+hour+minute // 2015 Dec 13, 13:45:00 - {11, 12, 13, 45, WDAY_ANY, 1450014300}, + {11, 12, 13, 45, PBL_CRON_WDAY_ANY, 1450014300}, //////// 'past' time finding // minute // 2015 Nov 12, 13:23:00 - {-1, -1, -1, 23, WDAY_ANY, 1447334580}, + {-1, -1, -1, 23, PBL_CRON_WDAY_ANY, 1447334580}, // hour // 2015 Nov 13, 11:00:00 - {-1, -1, 11, -1, WDAY_ANY, 1447412400}, + {-1, -1, 11, -1, PBL_CRON_WDAY_ANY, 1447412400}, // day // 2015 Dec 11, 00:00:00 - {-1, 10, -1, -1, WDAY_ANY, 1449792000}, + {-1, 10, -1, -1, PBL_CRON_WDAY_ANY, 1449792000}, // month // 2016 Oct 1, 00:00:00 - {9, -1, -1, -1, WDAY_ANY, 1475280000}, + {9, -1, -1, -1, PBL_CRON_WDAY_ANY, 1475280000}, // month+hour // 2016 Oct 1, 12:00:00 - {9, -1, 12, -1, WDAY_ANY, 1475323200}, + {9, -1, 12, -1, PBL_CRON_WDAY_ANY, 1475323200}, //////// wday time finding // now, -Th // 2015 Nov 13, 00:00:00 - {-1, -1, -1, -1, WDAY_ANY & ~WDAY_THURSDAY, 1447372800}, + {-1, -1, -1, -1, PBL_CRON_WDAY_ANY & ~PBL_CRON_WDAY_THURSDAY, 1447372800}, // now, -Th-Fr // 2015 Nov 14, 00:00:00 - {-1, -1, -1, -1, WDAY_ANY & ~(WDAY_THURSDAY | WDAY_FRIDAY), 1447459200}, + {-1, -1, -1, -1, PBL_CRON_WDAY_ANY & ~(PBL_CRON_WDAY_THURSDAY | PBL_CRON_WDAY_FRIDAY), + 1447459200}, // now, -Th-Fr-Sa // 2015 Nov 15, 00:00:00 - {-1, -1, -1, -1, WDAY_ANY & ~(WDAY_THURSDAY | WDAY_FRIDAY | WDAY_SATURDAY), 1447545600}, + {-1, -1, -1, -1, + PBL_CRON_WDAY_ANY & ~(PBL_CRON_WDAY_THURSDAY | PBL_CRON_WDAY_FRIDAY | PBL_CRON_WDAY_SATURDAY), + 1447545600}, // now, -Th-Fr-Sa-Su // 2015 Nov 16, 00:00:00 - {-1, -1, -1, -1, WDAY_MONDAY | WDAY_TUESDAY | WDAY_WEDNESDAY, 1447632000}, + {-1, -1, -1, -1, PBL_CRON_WDAY_MONDAY | PBL_CRON_WDAY_TUESDAY | PBL_CRON_WDAY_WEDNESDAY, + 1447632000}, // now, -Th-Fr-Sa-Su-Mo // 2015 Nov 17, 00:00:00 - {-1, -1, -1, -1, WDAY_TUESDAY | WDAY_WEDNESDAY, 1447718400}, + {-1, -1, -1, -1, PBL_CRON_WDAY_TUESDAY | PBL_CRON_WDAY_WEDNESDAY, 1447718400}, // now, -Th-Fr-Sa-Su-Mo-Tu // 2015 Nov 18, 00:00:00 - {-1, -1, -1, -1, WDAY_WEDNESDAY, 1447804800}, + {-1, -1, -1, -1, PBL_CRON_WDAY_WEDNESDAY, 1447804800}, // now, -We // now - {-1, -1, -1, -1, WDAY_ANY & ~WDAY_WEDNESDAY, s_2015_nov12_123456_gmt}, + {-1, -1, -1, -1, PBL_CRON_WDAY_ANY & ~PBL_CRON_WDAY_WEDNESDAY, s_2015_nov12_123456_gmt}, // now, wday=0 // now {-1, -1, -1, -1, 0, s_2015_nov12_123456_gmt}, @@ -467,38 +464,38 @@ struct { //////// wday+ time finding // 19th, -Th // 2015 Nov 20, 00:00:00 - {-1, 18, -1, -1, WDAY_ANY & ~WDAY_THURSDAY, 1447977600}, + {-1, 18, -1, -1, PBL_CRON_WDAY_ANY & ~PBL_CRON_WDAY_THURSDAY, 1447977600}, // Dec, -Tu // 2015 Dec 2, 00:00:00 - {11, -1, -1, -1, WDAY_ANY & ~WDAY_TUESDAY, 1449014400}, + {11, -1, -1, -1, PBL_CRON_WDAY_ANY & ~PBL_CRON_WDAY_TUESDAY, 1449014400}, //////// 'bogus' time finding // minute // 2015 Nov 12, 12:60:00 = 2015 Nov 12, 13:00:00 - {-1, -1, -1, 60, WDAY_ANY, 1447333200}, + {-1, -1, -1, 60, PBL_CRON_WDAY_ANY, 1447333200}, // hour // 2015 Nov 12, 24:00:00 = 2015 Nov 13, 00:00:00 - {-1, -1, 24, -1, WDAY_ANY, 1447372800}, + {-1, -1, 24, -1, PBL_CRON_WDAY_ANY, 1447372800}, // mday // 2015 Nov 33, 00:00:00 = 2015 Dec 3, 00:00:00 - {-1, 32, -1, -1, WDAY_ANY, 1449100800}, + {-1, 32, -1, -1, PBL_CRON_WDAY_ANY, 1449100800}, // month // 2015 Month13 1, 00:00:00 = 2016 Jan 1, 00:00:00 - {12, -1, -1, -1, WDAY_ANY, 1451606400}, + {12, -1, -1, -1, PBL_CRON_WDAY_ANY, 1451606400}, // Sentinel {0, 0, 0, 0, 0, 0}, }; void test_cron__simples(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .may_be_instant = true, }; @@ -523,7 +520,7 @@ void test_cron__simples(void) { void test_cron__dst_simple_to(void) { // Nov 21st, 01:00:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -541,7 +538,7 @@ void test_cron__dst_simple_to(void) { void test_cron__dst_simple_from(void) { // Dec 21st, 01:00:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -559,7 +556,7 @@ void test_cron__dst_simple_from(void) { void test_cron__dst_rollover_to(void) { // Nov 20th, 03:00:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -577,7 +574,7 @@ void test_cron__dst_rollover_to(void) { void test_cron__dst_rollover_from(void) { // Dec 20th, 02:00:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -598,7 +595,7 @@ void test_cron__dst_hole_to(void) { // A failure in this test is not necessarily a problem. // Nov 20th, 02:30:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -619,7 +616,7 @@ void test_cron__dst_hole_from(void) { // A failure in this test is not necessarily a problem. // Dec 20th, 01:30:00 local - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, @@ -635,7 +632,7 @@ void test_cron__dst_hole_from(void) { prv_basic_test(&s_timezone_gmt, &test_cron, s_2015_nov12_123456_gmt, advance, advance, 1); } -static void prv_counting_cb(CronJob *job, void *cb_data) { +static void prv_counting_cb(struct pbl_cron_job *job, void *cb_data) { static int s_counter = 0; job->cb_data = (void *)((uintptr_t)++s_counter); } @@ -652,60 +649,62 @@ static void prv_counting_cb(CronJob *job, void *cb_data) { }, void test_cron__scheduled_after(void) { - CronJob jobs[] = { - CRON_JOB(CRON_MINUTE_ANY, CRON_HOUR_ANY, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_counting_cb) - CRON_JOB(CRON_MINUTE_ANY, CRON_HOUR_ANY, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_cron_callback) - CRON_JOB(1, CRON_HOUR_ANY, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_cron_callback) - CRON_JOB(3, CRON_HOUR_ANY, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_cron_callback) - CRON_JOB(10, CRON_HOUR_ANY, 1, CRON_MONTH_ANY, prv_cron_callback) CRON_JOB( - 25, CRON_HOUR_ANY, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_cron_callback) - CRON_JOB(55, 1, CRON_MDAY_ANY, CRON_MONTH_ANY, prv_cron_callback) CRON_JOB( - CRON_MINUTE_ANY, CRON_HOUR_ANY, 1, CRON_MONTH_ANY, prv_cron_callback) + struct pbl_cron_job jobs[] = { + CRON_JOB(PBL_CRON_MINUTE_ANY, PBL_CRON_HOUR_ANY, PBL_CRON_MDAY_ANY, PBL_CRON_MONTH_ANY, + prv_counting_cb) CRON_JOB(PBL_CRON_MINUTE_ANY, PBL_CRON_HOUR_ANY, PBL_CRON_MDAY_ANY, + PBL_CRON_MONTH_ANY, prv_cron_callback) + CRON_JOB(1, PBL_CRON_HOUR_ANY, PBL_CRON_MDAY_ANY, PBL_CRON_MONTH_ANY, prv_cron_callback) + CRON_JOB(3, PBL_CRON_HOUR_ANY, PBL_CRON_MDAY_ANY, PBL_CRON_MONTH_ANY, prv_cron_callback) + CRON_JOB(10, PBL_CRON_HOUR_ANY, 1, PBL_CRON_MONTH_ANY, prv_cron_callback) CRON_JOB( + 25, PBL_CRON_HOUR_ANY, PBL_CRON_MDAY_ANY, PBL_CRON_MONTH_ANY, prv_cron_callback) + CRON_JOB(55, 1, PBL_CRON_MDAY_ANY, PBL_CRON_MONTH_ANY, prv_cron_callback) + CRON_JOB(PBL_CRON_MINUTE_ANY, PBL_CRON_HOUR_ANY, 1, PBL_CRON_MONTH_ANY, + prv_cron_callback) }; - CronJob new_job = { + struct pbl_cron_job new_job = { .cb = prv_counting_cb, .cb_data = (void *)0, }; prv_set_rtc(s_2015_nov12_123456_gmt, &s_timezone_gmt); - cron_clear_all_jobs(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_clear_all_jobs(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); for (int i = 0; i < ARRAY_LENGTH(jobs); ++i) { - cron_job_schedule(&jobs[i]); + pbl_cron_job_schedule(&jobs[i]); } - cron_job_schedule_after(&jobs[0], &new_job); + pbl_cron_job_schedule_after(&jobs[0], &new_job); cl_assert_equal_i((uintptr_t)jobs[0].cb_data, 0); cl_assert_equal_i((uintptr_t)new_job.cb_data, 0); - cl_assert_equal_i(cron_service_get_job_count(), ARRAY_LENGTH(jobs) + 1); + cl_assert_equal_i(pbl_cron_get_job_count(), ARRAY_LENGTH(jobs) + 1); fake_rtc_increment_time(0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i((uintptr_t)jobs[0].cb_data, 1); cl_assert_equal_i((uintptr_t)new_job.cb_data, 2); - cl_assert_equal_i(cron_service_get_job_count(), 6); + cl_assert_equal_i(pbl_cron_get_job_count(), 6); fake_rtc_increment_time(SECONDS_PER_DAY * 60); - cron_service_wakeup(); - cl_assert_equal_i(cron_service_get_job_count(), 0); + pbl_cron_wakeup(); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); } void test_cron__offset_negative_seconds_one_wday(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 0, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = -SECONDS_PER_DAY, - .wday = WDAY_FRIDAY, + .wday = PBL_CRON_WDAY_FRIDAY, .may_be_instant = false, }; @@ -714,14 +713,14 @@ void test_cron__offset_negative_seconds_one_wday(void) { } void test_cron__offset_negative_seconds_any_day(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 0, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = -SECONDS_PER_DAY, .may_be_instant = false, @@ -732,17 +731,17 @@ void test_cron__offset_negative_seconds_any_day(void) { } void test_cron__offset_positive_seconds_one_wday(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 0, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = SECONDS_PER_DAY, - .wday = WDAY_THURSDAY, + .wday = PBL_CRON_WDAY_THURSDAY, .may_be_instant = false, }; @@ -751,14 +750,14 @@ void test_cron__offset_positive_seconds_one_wday(void) { } void test_cron__offset_positive_seconds_any_day(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 0, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = SECONDS_PER_DAY, .may_be_instant = false, @@ -769,14 +768,14 @@ void test_cron__offset_positive_seconds_any_day(void) { } void test_cron__offset_negative_seconds_every_second(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = -SECONDS_PER_MINUTE, .may_be_instant = true, @@ -786,14 +785,14 @@ void test_cron__offset_negative_seconds_every_second(void) { } void test_cron__offset_positive_seconds_every_second(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, - .minute = CRON_MINUTE_ANY, - .hour = CRON_HOUR_ANY, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .minute = PBL_CRON_MINUTE_ANY, + .hour = PBL_CRON_HOUR_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = SECONDS_PER_MINUTE, .may_be_instant = true, @@ -803,14 +802,14 @@ void test_cron__offset_positive_seconds_every_second(void) { } void test_cron__offset_negative_seconds_any_day_dst(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 1, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = -30 * SECONDS_PER_MINUTE, .may_be_instant = false, @@ -821,14 +820,14 @@ void test_cron__offset_negative_seconds_any_day_dst(void) { } void test_cron__offset_positive_seconds_any_day_dst(void) { - CronJob test_cron = { + struct pbl_cron_job test_cron = { .cb = prv_cron_callback, .cb_data = (void *)0, .minute = 30, .hour = 0, - .mday = CRON_MDAY_ANY, - .month = CRON_MONTH_ANY, + .mday = PBL_CRON_MDAY_ANY, + .month = PBL_CRON_MONTH_ANY, .offset_seconds = 30 * SECONDS_PER_MINUTE, .may_be_instant = false, diff --git a/tests/fw/services/test_do_not_disturb.c b/tests/fw/services/test_do_not_disturb.c index 75bdc19d27..3051d23b41 100644 --- a/tests/fw/services/test_do_not_disturb.c +++ b/tests/fw/services/test_do_not_disturb.c @@ -6,7 +6,7 @@ #include "applib/ui/action_toggle.h" #include "kernel/events.h" #include "resource/resource.h" -#include "pbl/services/cron.h" +#include #include "pbl/services/new_timer/new_timer.h" #include "pbl/services/system_task.h" #include "pbl/services/system_task.h" @@ -122,7 +122,7 @@ static void prv_assert_settings_value(const void *key, size_t key_len, const voi } static void prv_assert_seconds_until_update(time_t expected) { - cl_assert_equal_i(cron_service_get_next_execute_time() - rtc_get_time(), expected); + cl_assert_equal_i(pbl_cron_get_next_execute_time() - rtc_get_time(), expected); } static void prv_assert_manually_dnd_setting_val(bool expected_value) { @@ -141,7 +141,7 @@ void test_do_not_disturb__initialize(void) { rtc_set_time(s_thursday_00_00); alerts_preferences_init(); - cron_service_init(); + pbl_cron_init(); do_not_disturb_init(); do_not_disturb_set_manually_enabled(false); @@ -162,7 +162,7 @@ void test_do_not_disturb__cleanup(void) { do_not_disturb_set_manually_enabled(false); do_not_disturb_set_schedule_enabled(WeekdaySchedule, false); do_not_disturb_set_schedule_enabled(WeekendSchedule, false); - cron_service_deinit(); + pbl_cron_deinit(); } void test_do_not_disturb__manually_enable(void) { @@ -411,13 +411,13 @@ void test_do_not_disturb__cron_fires_schedule_boundaries(void) { prv_assert_seconds_until_update(3600); rtc_set_time(s_thursday_01_00); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert(do_not_disturb_is_active() == true); prv_assert_seconds_until_update(11.5 * SECONDS_PER_HOUR); do_not_disturb_set_manually_enabled(true); rtc_set_time(s_thursday_13_00); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert(do_not_disturb_is_active() == false); cl_assert(do_not_disturb_is_manually_enabled() == false); prv_assert_seconds_until_update(12 * SECONDS_PER_HOUR); @@ -575,12 +575,12 @@ void test_do_not_disturb__weekday_weekend_schedule(void) { // Timer will go off at 07:00 on Thursday. (7.0 hours) prv_assert_seconds_until_update(25200); - cl_assert(cron_service_get_job_count() != 0); + cl_assert(pbl_cron_get_job_count() != 0); do_not_disturb_set_schedule_enabled(WeekdaySchedule, false); active = do_not_disturb_is_active(); cl_assert(active == false); // Neither schedules enabled, nothing should be scheduled - cl_assert_equal_i(cron_service_get_job_count(), 0); + cl_assert_equal_i(pbl_cron_get_job_count(), 0); do_not_disturb_set_schedule_enabled(WeekdaySchedule, true); active = do_not_disturb_is_active(); diff --git a/tests/fw/test_alarm.c b/tests/fw/test_alarm.c index bd5ee4ae29..d68f07e59e 100644 --- a/tests/fw/test_alarm.c +++ b/tests/fw/test_alarm.c @@ -80,14 +80,14 @@ void test_alarm__initialize(void) { pfs_init(false); pfs_format(false); - cron_service_init(); + pbl_cron_init(); alarm_init(); alarm_service_enable_alarms(true); } void test_alarm__cleanup(void) { - cron_service_deinit(); + pbl_cron_deinit(); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -449,7 +449,7 @@ void test_alarm__handle_clock_change(void) { s_current_hour = 13; s_current_minute = 14; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -509,7 +509,7 @@ void test_alarm__recurring_daily_alarm_timeout_ahead(void) { s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -524,7 +524,7 @@ void test_alarm__recurring_daily_alarm_timeout_behind(void) { // Alarm set for tomorrow, so add 24 hours. s_current_hour = 10 + 24; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -554,7 +554,7 @@ void test_alarm__recurring_daily_alarm(void) { // First alarm goes off. Second one should be up s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 13); @@ -564,7 +564,7 @@ void test_alarm__recurring_daily_alarm(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); cl_assert_equal_i(s_num_alarm_events_put, 2); cl_assert_equal_i(s_num_timeline_adds, 20); @@ -575,7 +575,7 @@ void test_alarm__recurring_daily_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_friday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); cl_assert_equal_i(s_num_alarm_events_put, 3); cl_assert_equal_i(s_num_timeline_adds, 27); @@ -585,7 +585,7 @@ void test_alarm__recurring_daily_alarm(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 4); cl_assert_equal_i(s_num_alarm_events_put, 4); cl_assert_equal_i(s_num_timeline_adds, 34); @@ -596,7 +596,7 @@ void test_alarm__recurring_daily_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 5); cl_assert_equal_i(s_num_alarm_events_put, 5); cl_assert_equal_i(s_num_timeline_adds, 41); @@ -606,7 +606,7 @@ void test_alarm__recurring_daily_alarm(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 6); cl_assert_equal_i(s_num_alarm_events_put, 6); cl_assert_equal_i(s_num_timeline_adds, 48); @@ -617,7 +617,7 @@ void test_alarm__recurring_daily_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_sunday; // Make sure the wday can wrap properly - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 7); cl_assert_equal_i(s_num_alarm_events_put, 7); cl_assert_equal_i(s_num_timeline_adds, 55); @@ -634,13 +634,13 @@ void test_alarm__recurring_weekends_alarm_timeout_ahead(void) { s_current_hour = 10; s_current_minute = 29; s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); // Only 1 pin should be added (for Saturday) cl_assert_equal_i(s_num_timeline_adds, 1); s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_timeline_adds, 3); } @@ -671,7 +671,7 @@ void test_alarm__recurring_weekends_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 6); @@ -681,7 +681,7 @@ void test_alarm__recurring_weekends_alarm(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); cl_assert_equal_i(s_num_alarm_events_put, 2); cl_assert_equal_i(s_num_timeline_adds, 9); @@ -692,7 +692,7 @@ void test_alarm__recurring_weekends_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_sunday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); cl_assert_equal_i(s_num_alarm_events_put, 3); cl_assert_equal_i(s_num_timeline_adds, 11); @@ -702,7 +702,7 @@ void test_alarm__recurring_weekends_alarm(void) { // Second alarm goes off. First one should be up again, but not until Saturday s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 4); cl_assert_equal_i(s_num_alarm_events_put, 4); cl_assert_equal_i(s_num_timeline_adds, 12); @@ -743,7 +743,7 @@ void test_alarm__recurring_weekday_alarm(void) { // First alarm goes off. Second one should be up s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 8); @@ -753,7 +753,7 @@ void test_alarm__recurring_weekday_alarm(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); cl_assert_equal_i(s_num_alarm_events_put, 2); cl_assert_equal_i(s_num_timeline_adds, 11); @@ -764,7 +764,7 @@ void test_alarm__recurring_weekday_alarm(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_friday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); cl_assert_equal_i(s_num_alarm_events_put, 3); cl_assert_equal_i(s_num_timeline_adds, 14); @@ -774,7 +774,7 @@ void test_alarm__recurring_weekday_alarm(void) { // Second alarm goes off. First one should be up again, but not until Monday s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 4); cl_assert_equal_i(s_num_alarm_events_put, 4); cl_assert_equal_i(s_num_timeline_adds, 17); @@ -820,7 +820,7 @@ void test_alarm__just_once_alarm(void) { // First alarm goes off. Second one should be up s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); prv_assert_alarm_config(id1, 10, 30, true, ALARM_KIND_JUST_ONCE, just_once_schedule_thursday); cl_assert_equal_i(s_num_alarm_events_put, 1); @@ -831,7 +831,7 @@ void test_alarm__just_once_alarm(void) { // Second alarm goes off. No alarms should be up s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); prv_assert_alarm_config(id2, 11, 30, true, ALARM_KIND_JUST_ONCE, just_once_schedule_thursday); cl_assert_equal_i(s_num_alarm_events_put, 2); @@ -855,27 +855,27 @@ void test_alarm__custom_alarm_everyday(void) { // It's currently Thursday @ 00:00. s_current_day = s_friday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); s_current_day = s_sunday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); s_current_day = s_monday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 4); s_current_day = s_tuesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 5); s_current_day = s_wednesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 6); } @@ -894,27 +894,27 @@ void test_alarm__custom_alarm_weekends_and_weekday(void) { // It's currently Thursday @ 00:00. s_current_day = s_friday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); s_current_day = s_sunday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_monday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); s_current_day = s_tuesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); s_current_day = s_wednesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); } @@ -933,27 +933,27 @@ void test_alarm__custom_alarm_partial_weekdays(void) { // It's currently Thursday @ 00:00. s_current_day = s_friday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_sunday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_monday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); s_current_day = s_tuesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); s_current_day = s_wednesday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); } @@ -985,7 +985,7 @@ void test_alarm__custom_alarm_weekends(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_saturday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 6); @@ -995,7 +995,7 @@ void test_alarm__custom_alarm_weekends(void) { // Second alarm goes off. First one should be up again s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); cl_assert_equal_i(s_num_alarm_events_put, 2); cl_assert_equal_i(s_num_timeline_adds, 9); @@ -1006,7 +1006,7 @@ void test_alarm__custom_alarm_weekends(void) { s_current_hour = 10; s_current_minute = 30; s_current_day = s_sunday; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 3); cl_assert_equal_i(s_num_alarm_events_put, 3); cl_assert_equal_i(s_num_timeline_adds, 11); @@ -1016,7 +1016,7 @@ void test_alarm__custom_alarm_weekends(void) { // Second alarm goes off. First one should be up again, but not until Saturday s_current_hour = 11; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 4); cl_assert_equal_i(s_num_alarm_events_put, 4); cl_assert_equal_i(s_num_timeline_adds, 12); @@ -1058,7 +1058,7 @@ void test_alarm__custom_alarm_multiple(void) { s_current_day = s_sunday; s_current_hour = 12; s_current_minute = 15; - cron_service_wakeup(); + pbl_cron_wakeup(); bool schedule_2[7] = {false, true, false, false, false, false, false}; id2 = alarm_create(&(AlarmInfo){ .hour = 13, @@ -1072,7 +1072,7 @@ void test_alarm__custom_alarm_multiple(void) { s_current_day = s_tuesday; s_current_hour = 1; s_current_minute = 0; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 2); } @@ -1090,7 +1090,7 @@ void test_alarm__disable_upcoming_alarm(void) { // The 10:30 alarm should not have gone off s_current_hour = 11; s_current_minute = 0; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); // Disable the 11:30 alarm @@ -1098,14 +1098,14 @@ void test_alarm__disable_upcoming_alarm(void) { // The 11:30 alarm should not go off either s_current_hour = 12; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); // Enable the 11:30 alarm - now it should go off s_current_hour = 11; alarm_set_enabled(id2, true); s_current_hour = 12; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -1123,7 +1123,7 @@ void test_alarm__delete_upcoming_alarm(void) { // The 10:30 alarm should not go off s_current_hour = 11; s_current_minute = 0; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); // Delete the 11:30 alarm @@ -1131,7 +1131,7 @@ void test_alarm__delete_upcoming_alarm(void) { // The 11:30 alarm should not go off either s_current_hour = 12; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); } @@ -1147,14 +1147,14 @@ void test_alarm__alarm_type_change_updates_timeout(void) { // Alarm should not go off on Thursday anymore s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); // Alarm should go off on the weekend s_current_day = s_saturday; s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -1235,11 +1235,11 @@ void test_alarm__skip_two_alarms(void) { // One of the alarms should go off s_current_hour = 10; s_current_minute = 30; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); // The other alarm should not go off - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -1248,8 +1248,8 @@ void test_alarm__skip_two_alarms(void) { //! Restarts the alarm service the way a reboot would, leaving the settings file intact. static void prv_simulate_reboot(void) { - cron_service_deinit(); - cron_service_init(); + pbl_cron_deinit(); + pbl_cron_init(); alarm_init(); alarm_service_enable_alarms(true); } @@ -1290,7 +1290,7 @@ void test_alarm__alarm_not_fired_when_reboot_precedes_it(void) { // The alarm is still armed and goes off at its own time s_current_hour = 6; s_current_minute = 0; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } @@ -1337,7 +1337,7 @@ void test_alarm__missed_just_once_alarm_rearmed_for_next_day(void) { s_current_day = s_friday; s_current_hour = 6; s_current_minute = 0; - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); } diff --git a/tests/fw/test_alarm_common.h b/tests/fw/test_alarm_common.h index 20bce952d9..956d46f8bc 100644 --- a/tests/fw/test_alarm_common.h +++ b/tests/fw/test_alarm_common.h @@ -9,7 +9,7 @@ #include #include "resource/timeline_resource_ids.auto.h" -#include "pbl/services/cron.h" +#include #include "pbl/services/new_timer/new_timer.h" #include "pbl/services/system_task.h" #include "pbl/services/filesystem/pfs.h" diff --git a/tests/fw/test_alarm_smart.c b/tests/fw/test_alarm_smart.c index 950927f43d..e421c9ea9a 100644 --- a/tests/fw/test_alarm_smart.c +++ b/tests/fw/test_alarm_smart.c @@ -81,14 +81,14 @@ void test_alarm_smart__initialize(void) { pfs_init(false); pfs_format(false); - cron_service_init(); + pbl_cron_init(); alarm_init(); alarm_service_enable_alarms(true); } void test_alarm_smart__cleanup(void) { - cron_service_deinit(); + pbl_cron_deinit(); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -116,13 +116,13 @@ void test_alarm_smart__trigger_30_min_early_awake(void) { // Don't trigger too early prv_set_time(s_current_day, 9, 49); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); cl_assert_equal_i(s_num_alarm_events_put, 0); // Trigger at the right time prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 6); @@ -141,7 +141,7 @@ void test_alarm_smart__trigger_30_min_early_vmc(void) { s_sleep_state = ActivitySleepStateLightSleep; s_last_vmc = 1; prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_last_timeline_item_added->header.timestamp, rtc_get_time()); @@ -159,7 +159,7 @@ void test_alarm_smart__dont_trigger_30_min_early_deep_sleep(void) { s_sleep_state_seconds = 0; s_last_vmc = 0; prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 0); } @@ -178,7 +178,7 @@ void test_alarm_smart__trigger_15_min_early_light_sleep(void) { // Smart alarms are first triggered by cron at T-30min prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 0); @@ -223,7 +223,7 @@ void test_alarm_smart__trigger_at_timeout(void) { // Smart alarms are first triggered by cron at T-30min prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 0); @@ -262,7 +262,7 @@ void test_alarm_smart__user_snooze_fires_after_delay(void) { s_sleep_state_seconds = 0; s_last_vmc = 0; prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); @@ -295,7 +295,7 @@ void test_alarm_smart__user_snooze_survives_clock_change(void) { s_rand = 4; prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarm_events_put, 0); const int num_checks = 6; @@ -334,7 +334,7 @@ void test_alarm_smart__clock_change_still_force_triggers_sleep_poll(void) { s_rand = 4; prv_set_time(s_current_day, 10, 0); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarm_events_put, 0); // A couple of sleep polls, so the smart snooze counter is non-zero but the alarm has not fired @@ -374,13 +374,13 @@ void test_alarm_smart__across_midnight_boundary(void) { // Don't trigger too early prv_set_time(s_sunday, 23, 44); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 0); cl_assert_equal_i(s_num_alarm_events_put, 0); // Trigger at the right time prv_set_time(s_sunday, 23, 45); - cron_service_wakeup(); + pbl_cron_wakeup(); cl_assert_equal_i(s_num_alarms_fired, 1); cl_assert_equal_i(s_num_alarm_events_put, 1); cl_assert_equal_i(s_num_timeline_adds, 2); diff --git a/tests/stubs/stubs_cron.h b/tests/stubs/stubs_cron.h index cf166730ff..3074c98071 100644 --- a/tests/stubs/stubs_cron.h +++ b/tests/stubs/stubs_cron.h @@ -3,20 +3,21 @@ #pragma once -#include +#include -time_t cron_job_get_execute_time(const CronJob *job) { +time_t pbl_cron_job_get_execute_time(const struct pbl_cron_job *job) { return 0; } -time_t cron_job_get_execute_time_from_epoch(const CronJob *job, time_t local_epoch) { +time_t pbl_cron_job_get_execute_time_from_epoch(const struct pbl_cron_job *job, + time_t local_epoch) { return 0; } -time_t cron_job_schedule(CronJob *job) { +time_t pbl_cron_job_schedule(struct pbl_cron_job *job) { return 0; } -bool cron_job_unschedule(CronJob *job) { +bool pbl_cron_job_unschedule(struct pbl_cron_job *job) { return true; }