Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/libparodus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 10 additions & 12 deletions src/libparodus_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libparodus_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 40 additions & 7 deletions tests/libpd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<count; i++) {
(*event_num)++;
if (send_event_msg ("---LIBPARODUS---", "---ParodusService---",
"---EventMessagePayload####", *event_num, send_flag) != 0)
return -1;
if (0==i)
test_send_svc_alive (test_instance1);
(*event_num)++;
if (send_event_msg ("---LIBPARODUS---", "---ParodusService---",
"---EventMessagePayload####", *event_num, send_flag) != 0)
return -1;
}
return 0;
}
Expand Down Expand Up @@ -939,10 +954,14 @@ void test_1(void)
if (using_mock) {
cfg1.keepalive_timeout_secs = 20;
}
else if (keep_alive_test_timeout > 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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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')) {
Expand All @@ -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);
}

}

Expand Down