aboutsummaryrefslogtreecommitdiffstats
path: root/tests/osmux
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2017-04-26 16:00:03 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2017-04-27 08:50:01 +0000
commit3460ad7f31fb1daa529662a1b2ac4d4b0f5e9a7e (patch)
treeec5490773e0b440c5e93b390a90c3f9754e76809 /tests/osmux
parente98afe5808176efb60298a2f764e8e11efaf580b (diff)
osmux: Use osmo_gettimeofday for testing puroposes
This way we can use fake time and osmux_test take 700ms instead of >2sec to run. Change-Id: Ic39cab74400aca8262a00c0d06884230b1a15ca3
Diffstat (limited to 'tests/osmux')
-rw-r--r--tests/osmux/osmux_test.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
index 9941ce3..63f89f1 100644
--- a/tests/osmux/osmux_test.c
+++ b/tests/osmux/osmux_test.c
@@ -26,6 +26,7 @@
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/timer.h>
#include <osmocom/netif/osmux.h>
#include <osmocom/netif/rtp.h>
@@ -54,6 +55,8 @@ static uint8_t rtp_pkt[] = {
0xf2, 0x26, 0x33, 0x65, 0x54,
};
+#define PKT_TIME_USEC 20*1000
+
static int rtp_pkts;
static int mark_pkts;
#if OSMUX_TEST_USE_TIMING
@@ -67,7 +70,7 @@ static void tx_cb(struct msgb *msg, void *data)
#if OSMUX_TEST_USE_TIMING
struct timeval now, diff;
- gettimeofday(&now, NULL);
+ osmo_gettimeofday(&now, NULL);
timersub(&now, &last, &diff);
last = now;
@@ -159,10 +162,17 @@ static void osmux_test_marker(int ccid) {
osmux_xfrm_input_deliver(&h_input);
}
}
+#if !OSMUX_TEST_USE_TIMING
+ osmo_gettimeofday_override_add(0, PKT_TIME_USEC);
+#endif
}
- while (rtp_pkts)
+ while (rtp_pkts) {
+#if !OSMUX_TEST_USE_TIMING
+ osmo_gettimeofday_override_add(1, 0);
+#endif
osmo_select_main(0);
+ }
if (mark_pkts) {
fprintf(stdout, "RTP M bit (marker) mismatch! %d\n", mark_pkts);
@@ -204,7 +214,7 @@ static void osmux_test_loop(int ccid)
if (i % 4 == 0) {
#if OSMUX_TEST_USE_TIMING
- gettimeofday(&last, NULL);
+ osmo_gettimeofday(&last, NULL);
#endif
/* After four RTP messages, squash them into the OSMUX
@@ -217,8 +227,12 @@ static void osmux_test_loop(int ccid)
* messages that are extracted from OSMUX has been
* delivered.
*/
- for (j = 0; j < k-2; j++)
+ for (j = 0; j < k-2; j++) {
osmo_select_main(0);
+#if !OSMUX_TEST_USE_TIMING
+ osmo_gettimeofday_override_add(0, PKT_TIME_USEC);
+#endif
+ }
k = 0;
}
@@ -239,6 +253,12 @@ int main(void)
exit(EXIT_FAILURE);
}
+#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;
+#endif
+
/* This test doesn't use it, but osmux requires it internally. */
osmo_init_logging(&osmux_test_log_info);
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);