aboutsummaryrefslogtreecommitdiffstats
path: root/tests/stream/stream_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stream/stream_test.c')
-rw-r--r--tests/stream/stream_test.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/tests/stream/stream_test.c b/tests/stream/stream_test.c
index 439ea1a..b4846bc 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] = {
@@ -54,8 +57,12 @@ static struct msgb *make_msgb(const char *m)
#define ASTR(rec) ((rec) ? "autoreconnecting" : "non-reconnecting")
/* client defs */
-#define LOGCLI(cli, fmt, args...) \
- printf("[%s] Client's %s(): " fmt, osmo_stream_cli_get_data(cli) ? "OK" : "NA", __func__, ##args)
+#define LOGCLI(cli, fmt, args...) do { \
+ struct timeval tv; \
+ osmo_gettimeofday(&tv, NULL); \
+ printf("{%lu.%06lu} [%s] Client's %s(): " fmt, tv.tv_sec, tv.tv_usec, \
+ osmo_stream_cli_get_data(cli) ? "OK" : "NA", __func__, ##args); \
+ } while (0)
#define CLI_SND(cli, m) do { \
struct msgb *msg = make_msgb(m); \
@@ -100,6 +107,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 +124,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");
@@ -224,9 +232,14 @@ static struct osmo_stream_cli *make_client(void *ctx, const char *host, unsigned
#define LOGLNK(lnk, fmt, args...) \
printf("[%s] Server's %s(): " fmt, osmo_stream_srv_link_get_data(lnk) ? "OK" : "NA", __func__, ##args)
-#define LOGSRV(srv, fmt, args...) \
- printf("[%s|%s] Server's %s(): " fmt, osmo_stream_srv_get_data(srv) ? "OK" : "NA", \
- osmo_stream_srv_link_get_data(osmo_stream_srv_get_master(srv)) ? "OK" : "NA", __func__, ##args)
+#define LOGSRV(srv, fmt, args...) do { \
+ struct timeval tv; \
+ osmo_gettimeofday(&tv, NULL); \
+ printf("{%lu.%06lu} [%s|%s] Server's %s(): " fmt, tv.tv_sec, tv.tv_usec, \
+ osmo_stream_srv_get_data(srv) ? "OK" : "NA", \
+ osmo_stream_srv_link_get_data(osmo_stream_srv_get_master(srv)) ? "OK" : "NA", \
+ __func__, ##args); \
+ } while (0)
#define SRV_SND(srv, m) do { \
struct msgb *msg = make_msgb(m); \
@@ -318,6 +331,7 @@ static int accept_cb_srv(struct osmo_stream_srv_link *lnk, int fd)
static void test_recon(void *ctx, const char *host, unsigned port, unsigned steps, struct osmo_stream_srv_link *lnk,
bool autoreconnect)
{
+ struct timeval tv;
struct osmo_stream_cli *cli = make_client(ctx, host, port, autoreconnect);
if (!cli)
return;
@@ -329,20 +343,24 @@ static void test_recon(void *ctx, const char *host, unsigned port, unsigned step
osmo_stream_srv_link_set_data(lnk, ctx);
while(steps--) {
+ osmo_gettimeofday_override_add(0, 1); /* small increment to easily spot iterations */
osmo_select_main(0);
- fprintf(stderr, "\n%s test step %u [client %s, server %s], FD reg %u\n", ASTR(autoreconnect), steps,
+ osmo_gettimeofday(&tv, NULL);
+ fprintf(stderr, "\n{%lu.%06lu} %s test step %u [client %s, server %s], FD reg %u\n",
+ tv.tv_sec, tv.tv_usec, ASTR(autoreconnect), steps,
osmo_stream_cli_get_data(cli) ? "OK" : "NA",
osmo_stream_srv_link_get_data(lnk) ? "OK" : "NA",
osmo_fd_is_registered(osmo_stream_cli_get_ofd(cli)));
if (test_stop_requested(lnk)) {
- printf("Server requested test termination\n");
+ printf("{%lu.%06lu} Server requested test termination\n",
+ tv.tv_sec, tv.tv_usec);
steps = 0;
}
}
osmo_stream_cli_destroy(cli);
- printf("%s test complete.\n\n", ASTR(autoreconnect));
+ printf("{%lu.%06lu} %s test complete.\n\n", tv.tv_sec, tv.tv_usec, ASTR(autoreconnect));
}
@@ -352,6 +370,11 @@ 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;
+ osmo_gettimeofday_override_time.tv_sec = 2;
+ osmo_gettimeofday_override_time.tv_usec = 0;
+
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);