diff --git a/src/libparodus.c b/src/libparodus.c index 532eb89..c93bb1c 100644 --- a/src/libparodus.c +++ b/src/libparodus.c @@ -1116,3 +1116,12 @@ void test_get_counts (libpd_instance_t instance, *reconnect_count = inst->reconnect_count; } +int test_send_registration_msg (libpd_instance_t instance, int *oserr) +{ + int rtn; + extra_err_info_t err_info; + __instance_t *inst = (__instance_t *) instance; + rtn = send_registration_msg (inst, &err_info); + *oserr = err_info.oserr; + return rtn; +} diff --git a/src/libparodus_time.c b/src/libparodus_time.c index 442af55..d76e671 100644 --- a/src/libparodus_time.c +++ b/src/libparodus_time.c @@ -133,23 +133,21 @@ int make_current_timestamp (char *timestamp) return 0; } -int get_expire_time (uint32_t ms, struct timespec *ts) +int get_expire_time (unsigned msecs, struct timespec *ts) { - struct timeval tv; - int err = gettimeofday (&tv, NULL); - if (err != 0) { - libpd_log_err (LEVEL_ERROR, errno, ("Error getting time of day\n")); - return err; - } - tv.tv_sec += ms/1000; - tv.tv_usec += (ms%1000) * 1000; - if (tv.tv_usec >= 1000000) { + uint32_t ms = (uint32_t) msecs; + struct timespec tv; + + clock_gettime (CLOCK_REALTIME, &tv); + tv.tv_sec += ms/1000UL; + tv.tv_nsec += (ms%1000UL) * 1000000UL; + if (tv.tv_nsec >= 1000000000L) { tv.tv_sec += 1; - tv.tv_usec -= 1000000; + tv.tv_nsec -= 1000000000L; } ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000L; + ts->tv_nsec = tv.tv_nsec; return 0; } diff --git a/src/libparodus_time.h b/src/libparodus_time.h index 55d68cd..58506a1 100644 --- a/src/libparodus_time.h +++ b/src/libparodus_time.h @@ -85,7 +85,7 @@ int make_current_timestamp (char *timestamp); * @param ts expiration time * @return 0 on success, valid errno otherwise. */ -int get_expire_time (uint32_t ms, struct timespec *ts); +int get_expire_time (unsigned msecs, struct timespec *ts); /** * Delay diff --git a/tests/libpd_test.c b/tests/libpd_test.c index fd9ce58..3d3d1d0 100644 --- a/tests/libpd_test.c +++ b/tests/libpd_test.c @@ -104,6 +104,8 @@ static bool do_multiple_rcv_test = false; static bool connect_on_every_send = false; static bool do_multiple_inits_test = false; static bool switch_service_names = false; +static int keep_alive_test_timeout = 0; +static bool do_reregister_test = false; static libpd_instance_t test_instance1; static libpd_instance_t test_instance2; @@ -132,6 +134,8 @@ extern int test_close_receiver (libpd_instance_t instance, int *oserr); extern void test_send_wrp_queue_ok (libpd_mq_t wrp_queue, int *oserr); extern void test_get_counts (libpd_instance_t instance, int *keep_alive_count, int *reconnect_count); +extern int test_send_registration_msg + (libpd_instance_t instance, int *oserr); #if TEST_ENVIRONMENT==2 @@ -319,6 +323,15 @@ int send_reply (libpd_instance_t instance, wrp_msg_t *wrp_msg) return libparodus_send (instance, wrp_msg); } +int test_send_svc_alive (libpd_instance_t instance) +{ + wrp_msg_t svc_alive_msg; + + svc_alive_msg.msg_type = WRP_MSG_TYPE__SVC_ALIVE; + return libparodus_send (instance, (wrp_msg_t *) &svc_alive_msg); +} + + char *new_str (const char *str) { char *buf = malloc (strlen(str) + 1); @@ -400,12 +413,14 @@ int send_event_msgs (unsigned *msg_num, unsigned *event_num, int count, return 0; } if (both) - send_flag = 1; + send_flag = 1; for (i=0; i 0) { + cfg1.keepalive_timeout_secs = keep_alive_test_timeout; + } if (switch_service_names) { const char *tmp = cfg1.service_name; cfg1.service_name = cfg2.service_name; cfg2.service_name = tmp; + cfg1.client_url = GOOD_CLIENT_URL2; } rtn = libparodus_init(&test_instance1, &cfg1); CU_ASSERT_FATAL (rtn == 0); @@ -1017,6 +1036,12 @@ void test_1(void) if (send_event_msgs (&msg_num, &event_num, 5, false) != 0) break; } + if (do_reregister_test) { + if (msgs_received_count == 5) { + rtn = test_send_registration_msg (test_instance1, &oserr); + libpd_log (LEVEL_INFO, ("LIBPD_TEST: libparodus_reregister rtn = %d\n", rtn)); + } + } } CU_ASSERT (reply_error_count == 0); if (reply_error_count != 0) { @@ -1104,11 +1129,15 @@ int main( int argc, char **argv __attribute__((unused)) ) if (argc <= 1) using_mock = true; else { - const char *arg = argv[1]; + char *arg = argv[1]; if ((arg[0] == 's') || (arg[0] == 'S')) no_mock_send_only_test = true; - if ((arg[0] == 'r') || (arg[0] == 'R')) + if ((arg[0] == 'r') || (arg[0] == 'R')) { + if ((arg[1] == 'r') || (arg[1] == 'R')) + do_reregister_test = true; + else do_multiple_rcv_test = true; + } if ((arg[0] == 'm') || (arg[0] == 'M')) do_multiple_inst_test = true; if ((arg[0] == 'b') || (arg[0] == 'B')) { @@ -1130,6 +1159,10 @@ int main( int argc, char **argv __attribute__((unused)) ) if (arg[0] == '2') { switch_service_names = true; } + if (arg[0] == 'k') { + arg[0] = '#'; + keep_alive_test_timeout = get_msg_num (arg); + } }