libosmocore 1.9.0.192-1c24
Osmocom core library
timer_clockgettime.c File Reference

Overriding Time: osmo_clock_gettime() More...

#include "config.h"

Detailed Description

Overriding Time: osmo_clock_gettime()

  • Useful to write and reproduce tests that depend on specific time factors. This API allows to fake the timespec provided by clock_gettime() by using a small shim osmo_clock_gettime().
  • Choose the clock you want to override, for instance CLOCK_MONOTONIC.
  • If the clock override is disabled (default) for a given clock, osmo_clock_gettime() will do the same as regular clock_gettime().
  • If you want osmo_clock_gettime() to provide a specific time, you must enable time override with osmo_clock_override_enable(), then set a pointer to the timespec storing the fake time for that specific clock (struct timespec *ts = osmo_clock_override_gettimespec()) and set it as desired. Next time osmo_clock_gettime() is called, it will return the values previously set through the ts pointer.
  • A helper osmo_clock_override_add() is provided to increment a given overriden clock with a specific amount of time.