static inline void check_update_watchdog(Uploader *u) { usec_t after; usec_t elapsed_time; if (u->watchdog_usec <= 0) return; after = now(CLOCK_MONOTONIC); elapsed_time = usec_sub_unsigned(after, u->watchdog_timestamp); if (elapsed_time > u->watchdog_usec / 2) { log_debug("Update watchdog timer"); sd_notify(false, "WATCHDOG=1"); u->watchdog_timestamp = after; } }
static void test_usec_sub_unsigned(void) { log_info("/* %s */", __func__); assert_se(usec_sub_unsigned(0, 0) == 0); assert_se(usec_sub_unsigned(0, 2) == 0); assert_se(usec_sub_unsigned(0, USEC_INFINITY) == 0); assert_se(usec_sub_unsigned(1, 0) == 1); assert_se(usec_sub_unsigned(1, 1) == 0); assert_se(usec_sub_unsigned(1, 2) == 0); assert_se(usec_sub_unsigned(1, 3) == 0); assert_se(usec_sub_unsigned(1, USEC_INFINITY) == 0); assert_se(usec_sub_unsigned(USEC_INFINITY-1, 0) == USEC_INFINITY-1); assert_se(usec_sub_unsigned(USEC_INFINITY-1, 1) == USEC_INFINITY-2); assert_se(usec_sub_unsigned(USEC_INFINITY-1, 2) == USEC_INFINITY-3); assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY-2) == 1); assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY-1) == 0); assert_se(usec_sub_unsigned(USEC_INFINITY-1, USEC_INFINITY) == 0); assert_se(usec_sub_unsigned(USEC_INFINITY, 0) == USEC_INFINITY); assert_se(usec_sub_unsigned(USEC_INFINITY, 1) == USEC_INFINITY); assert_se(usec_sub_unsigned(USEC_INFINITY, 2) == USEC_INFINITY); assert_se(usec_sub_unsigned(USEC_INFINITY, USEC_INFINITY) == USEC_INFINITY); }