aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-09-19 15:16:00 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2019-09-19 15:16:02 +0200
commitb6f91251415d9ccdcb60a52ed65df9f378b46465 (patch)
treed39f0019f45973639993ae6092473314583fd699
parenta1e9de1ec4847b2f571065aa4ad8b9795d282418 (diff)
stream_test: Use fake time
By using fake own-controlled time we get two benefits: * Test doesn't take 9 seconds to run anymore * More fine-grade control of different events happening (and associated race conditions). Change-Id: I16b2884b289bfe40dfb8d743dce01bb4c208d117
-rw-r--r--tests/stream/stream_test.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c
index 439ea1a..4fd8573 100644
--- a/tests/stream/stream_test.c
+++ b/tests/stream/stream_test.c
@@ -19,9 +19,12 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
+#include <osmocom/core/timer.h>
#include <osmocom/netif/stream.h>
+#define RECONNECT_TIMEOUT_SECS 9
+
#define DSTREAMTEST 0
struct log_info_cat osmo_stream_test_cat[] = {
[DSTREAMTEST] = {
@@ -100,6 +103,7 @@ static int read_cb_cli(struct osmo_stream_cli *cli)
/* N. B: normally receiving 0 bytes means that we should close the connection and re-establish it
but to test autoreconnection logic we ignore it in here to let the test run till completion */
LOGCLI(cli, "0-byte read, auto-reconnect will be triggered if enabled\n");
+ osmo_gettimeofday_override_add(RECONNECT_TIMEOUT_SECS, 0);
}
if (!cli_data) {
@@ -116,7 +120,7 @@ static int read_cb_cli(struct osmo_stream_cli *cli)
static struct osmo_stream_cli *init_client_reconnection(struct osmo_stream_cli *cli, bool autoreconnect)
{
/* setting negative timeout ensures that we disable reconnection logic */
- osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? 9 : -1);
+ osmo_stream_cli_set_reconnect_timeout(cli, autoreconnect ? RECONNECT_TIMEOUT_SECS : -1);
if (osmo_stream_cli_open(cli) < 0) {
LOGCLI(cli, "unable to open client\n");
@@ -352,6 +356,9 @@ int main(void)
char *host = "127.0.0.11";
unsigned port = 1111;
void *tall_test = talloc_named_const(NULL, 1, "osmo_stream_test");
+
+ osmo_gettimeofday_override = true;
+
msgb_talloc_ctx_init(tall_test, 0);
osmo_init_logging2(tall_test, &osmo_stream_test_log_info);
log_set_log_level(osmo_stderr_target, LOGL_INFO);