aboutsummaryrefslogtreecommitdiffstats
path: root/tests/osmux
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-10-04 11:53:08 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2019-10-04 12:43:43 +0200
commit71abacdda0a1143762213e383ce8413c2fe63ee1 (patch)
tree61955e7327e0aabf34cd3c0790d55c4f237eea24 /tests/osmux
parent69e04689bffcf41f41ceedbdb84aab681f623904 (diff)
tests: osmux_test: Use fake time also for monotonic clock
Currently osmux related code uses both gettimeofday on some parts and clock_gettime(CLOCK_MONOTONIC) on others (for different purposes). Let's fake both clocks and not only the one used by gettimeofday API. Change-Id: I4e1a0eb4f8c4ea1bc0f963afa18b116d3af9978c
Diffstat (limited to 'tests/osmux')
-rw-r--r--tests/osmux/osmux_test.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
index e2eb777..6825b56 100644
--- a/tests/osmux/osmux_test.c
+++ b/tests/osmux/osmux_test.c
@@ -63,6 +63,31 @@ static int mark_pkts;
static struct timeval last;
#endif
+#define clock_debug(fmt, args...) \
+ do { \
+ struct timespec ts; \
+ struct timeval tv; \
+ osmo_clock_gettime(CLOCK_MONOTONIC, &ts); \
+ osmo_gettimeofday(&tv, NULL); \
+ printf("sys={%lu.%06lu}, mono={%lu.%06lu}: " fmt, \
+ tv.tv_sec, tv.tv_usec, ts.tv_sec, ts.tv_nsec/1000, ##args); \
+ } while(0)
+
+static void clock_override_enable(bool enable)
+{
+ osmo_gettimeofday_override = enable;
+ osmo_clock_override_enable(CLOCK_MONOTONIC, enable);
+}
+
+static void clock_override_add_debug(long sec, long usec, bool dbg)
+{
+ osmo_gettimeofday_override_add(sec, usec);
+ osmo_clock_override_add(CLOCK_MONOTONIC, sec, usec*1000);
+ if (dbg)
+ clock_debug("clock_override_add\n");
+}
+#define clock_override_add(sec, usec) clock_override_add_debug(sec, usec, false)
+
static void tx_cb(struct msgb *msg, void *data)
{
struct rtp_hdr *rtph = (struct rtp_hdr *)msg->data;
@@ -161,13 +186,13 @@ static void osmux_test_marker(int ccid) {
}
}
#if !OSMUX_TEST_USE_TIMING
- osmo_gettimeofday_override_add(0, PKT_TIME_USEC);
+ clock_override_add(0, PKT_TIME_USEC);
#endif
}
while (rtp_pkts) {
#if !OSMUX_TEST_USE_TIMING
- osmo_gettimeofday_override_add(1, 0);
+ clock_override_add(1, 0);
#endif
osmo_select_main(0);
}
@@ -234,7 +259,7 @@ static void osmux_test_loop(int ccid)
for (j = 0; j < k-2; j++) {
osmo_select_main(0);
#if !OSMUX_TEST_USE_TIMING
- osmo_gettimeofday_override_add(0, PKT_TIME_USEC);
+ clock_override_add(0, PKT_TIME_USEC);
#endif
}
@@ -260,7 +285,7 @@ int main(void)
#if !OSMUX_TEST_USE_TIMING
/* This test uses fake time to speedup the run, unless we want to manually
* test time specific stuff */
- osmo_gettimeofday_override = true;
+ clock_override_enable(true);
#endif
/* This test doesn't use it, but osmux requires it internally. */