Test updates to handle SA_AIS_ERR_TRY_AGAIN return codes.

(Logical change 1.176)


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@596 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Mark Haverkamp 2005-04-15 20:05:46 +00:00
parent f333ad49d9
commit 8c90624817
3 changed files with 677 additions and 262 deletions

View File

@ -17,6 +17,7 @@
// #define EVENT_SUBSCRIBE
#define PUB_RETRIES 100
#define TRY_WAIT 2
extern int get_sa_error(SaAisErrorT, char *, int);
char result_buf[256];
@ -126,8 +127,6 @@ test_pub()
uint64_t test_retention;
int fd;
int i;
int j;
int did_dot;
SaEvtEventIdT event_id;
#ifdef EVENT_SUBSCRIBE
@ -149,20 +148,22 @@ test_pub()
channel_name.length = strlen(channel);
result = saEvtInitialize (&handle, &callbacks, &version);
do {
result = saEvtInitialize (&handle, &callbacks, &version);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("Event Initialize result: %s\n", result_buf);
exit(result);
return(result);
}
do {
result = saEvtChannelOpen(handle, &channel_name, flags, 0,
&channel_handle);
} while (result == SA_AIS_ERR_TRY_AGAIN);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("channel open result: %s\n", result_buf);
exit(result);
return(result);
}
/*
@ -171,59 +172,53 @@ test_pub()
printf("Publish\n");
#ifdef EVENT_SUBSCRIBE
result = saEvtEventSubscribe(channel_handle,
do {
result = saEvtEventSubscribe(channel_handle,
&subscribe_filters,
subscription_id);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event subscribe result: %s\n", result_buf);
exit(result);
return(result);
}
#endif
result = saEvtEventAllocate(channel_handle, &event_handle);
do {
result = saEvtEventAllocate(channel_handle, &event_handle);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event Allocate result: %s\n", result_buf);
exit(result);
return(result);
}
strcpy(test_pub_name.value, pubname);
test_pub_name.length = strlen(pubname);
test_retention = ret_time;
result = saEvtEventAttributesSet(event_handle,
do {
result = saEvtEventAttributesSet(event_handle,
&evt_pat_set_array,
TEST_PRIORITY,
test_retention,
&test_pub_name);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event set attr result(2): %s\n", result_buf);
exit(result);
return(result);
}
for (i = 0; i < pub_count; i++) {
did_dot = 0;
for (j = 0; j < PUB_RETRIES; j++) {
do {
result = saEvtEventPublish(event_handle, user_data,
user_data_size, &event_id);
if (result == SA_AIS_ERR_TRY_AGAIN) {
sleep(1);
fprintf(stderr, ".");
did_dot = 1;
continue;
}
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event Publish result(2): %s\n", result_buf);
exit(result);
}
if (did_dot) {
printf("\n");
}
break;
user_data_size, &event_id);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event Publish result(2): %s\n", result_buf);
return(result);
}
printf("Published event ID: 0x%llx\n",
(unsigned long long)event_id);
}
@ -231,34 +226,38 @@ test_pub()
/*
* See if we got the event
*/
result = saEvtSelectionObjectGet(handle, &fd);
do {
result = saEvtSelectionObjectGet(handle, &fd);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("saEvtSelectionObject get %s\n", result_buf);
/* error */
exit(result);
return(result);
}
#ifdef EVENT_SUBSCRIBE
for (i = 0; i < pub_count; i++) {
pfd.fd = fd;
pfd.events = POLLIN;
nfd = poll(&pfd, 1, timeout);
if (nfd <= 0) {
printf("poll fds %d\n", nfd);
if (nfd < 0) {
perror("poll error");
pfd.fd = fd;
pfd.events = POLLIN;
nfd = poll(&pfd, 1, timeout);
if (nfd <= 0) {
printf("poll fds %d\n", nfd);
if (nfd < 0) {
perror("poll error");
}
goto evt_free;
}
goto evt_free;
}
printf("Got poll event\n");
result = saEvtDispatch(handle, SA_DISPATCH_ONE);
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("saEvtDispatch %s\n", result_buf);
exit(result);
}
printf("Got poll event\n");
do {
result = saEvtDispatch(handle, SA_DISPATCH_ONE);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("saEvtDispatch %s\n", result_buf);
return(result);
}
}
#endif
@ -266,33 +265,35 @@ test_pub()
/*
* Test cleanup
*/
result = saEvtEventFree(event_handle);
do {
result = saEvtEventFree(event_handle);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event free result: %s\n", result_buf);
exit(result);
return(result);
}
do {
result = saEvtChannelClose(channel_handle);
} while (result == SA_AIS_ERR_TRY_AGAIN);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("channel close result: %s\n", result_buf);
exit(result);
return(result);
}
do {
result = saEvtFinalize(handle);
} while (result == SA_AIS_ERR_TRY_AGAIN);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("Event Finalize result: %s\n", result_buf);
exit(result);
return(result);
}
printf("Done\n");
return 0;
return SA_AIS_OK;
}
@ -316,7 +317,8 @@ event_callback( SaEvtSubscriptionIdT subscription_id,
printf("event data size %d\n", event_data_size);
evt_pat_get_array.patternsNumber = 4;
result = saEvtEventAttributesGet(event_handle,
do {
result = saEvtEventAttributesGet(event_handle,
&evt_pat_get_array, /* patterns */
&priority, /* priority */
&retention_time, /* retention time */
@ -324,6 +326,7 @@ event_callback( SaEvtSubscriptionIdT subscription_id,
&publish_time, /* publish time */
&event_id /* event_id */
);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("event get attr result(2): %s\n", result_buf);
@ -348,9 +351,11 @@ evt_free:
}
static int err_wait_time = -1;
int main (int argc, char **argv)
{
static const char opts[] = "c:i:t:n:x:u:w:";
static const char opts[] = "c:i:t:n:x:u:w:f:";
int ret;
int option;
@ -388,6 +393,10 @@ int main (int argc, char **argv)
case 'n':
strcpy(pubname, optarg);
break;
case 'f':
err_wait_time =
(unsigned int)strtoul(optarg, NULL, 0);
break;
case 'i':
subscription_id =
(unsigned int)strtoul(optarg, NULL, 0);
@ -410,13 +419,17 @@ int main (int argc, char **argv)
}
do {
ret = test_pub();
if (ret != 0) {
exit(ret);
}
if (wait_time < 0) {
if (ret != SA_AIS_OK) {
if (err_wait_time < 0) {
exit(ret);
} else {
sleep(err_wait_time);
}
} else if (wait_time < 0) {
break;
} else {
sleep(wait_time);
}
sleep(wait_time);
} while(1);
return 0;
}

View File

@ -16,6 +16,7 @@
#define TEST_EVENT_ORDER 1
#define EVT_FREQ 1000
#define TRY_WAIT 2
uint32_t evt_count = 0;
extern int get_sa_error(SaAisErrorT, char *, int);
@ -83,7 +84,7 @@ char user_data[65536];
char event_data[65536];
int user_data_size = 0;
void
int
test_subscription()
{
SaEvtHandleT handle;
@ -99,7 +100,7 @@ test_subscription()
int result;
SaAisErrorT result;
flags = SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE;
strcpy(channel_name.value, channel);
@ -107,14 +108,18 @@ test_subscription()
printf("Test subscription:\n");
result = saEvtInitialize (&handle, &callbacks, &version);
do {
result = saEvtInitialize (&handle, &callbacks, &version);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("Event Initialize result: %s\n", result_buf);
return;
return result;
}
result = saEvtChannelOpen(handle, &channel_name, flags, 0,
do {
result = saEvtChannelOpen(handle, &channel_name, flags, 0,
&channel_handle);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("channel open result: %s\n", result_buf);
@ -125,9 +130,11 @@ test_subscription()
sub_next = 1;
for (i = 0; i < sub_next; i++) {
result = saEvtEventSubscribe(channel_handle,
do {
result = saEvtEventSubscribe(channel_handle,
&subscribe_filters[i],
subscription_id[i]);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
@ -139,7 +146,9 @@ test_subscription()
/*
* See if we got the event
*/
result = saEvtSelectionObjectGet(handle, &fd);
do {
result = saEvtSelectionObjectGet(handle, &fd);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("saEvtSelectionObject get %s\n", result_buf);
@ -161,9 +170,11 @@ test_subscription()
if (pfd.revents & (POLLERR|POLLHUP)) {
printf("Error recieved on poll fd %d\n", fd);
return;
return SA_AIS_ERR_BAD_OPERATION;
}
result = saEvtDispatch(handle, SA_DISPATCH_ONE);
do {
result = saEvtDispatch(handle, SA_DISPATCH_ONE);
} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
if (result != SA_AIS_OK) {
get_sa_error(result, result_buf, result_buf_len);
printf("saEvtDispatch %s\n", result_buf);
@ -191,6 +202,7 @@ init_fin:
printf("Finalize result: %s\n", result_buf);
}
return result;
}
static char time_buf[1024];
@ -356,10 +368,11 @@ evt_free:
}
}
static int err_wait_time = -1;
int main (int argc, char **argv)
{
static const char opts[] = "c:s:n:qu:";
static const char opts[] = "c:s:n:qu:f:";
int option;
char *p;
@ -396,6 +409,10 @@ int main (int argc, char **argv)
case 'c':
strcpy(channel, optarg);
break;
case 'f':
err_wait_time =
(unsigned int)strtoul(optarg, NULL, 0);
break;
case 'n':
strcpy(pubname, optarg);
break;
@ -415,7 +432,15 @@ int main (int argc, char **argv)
return 1;
}
}
test_subscription();
do {
if (test_subscription() != SA_AIS_OK) {
if (err_wait_time > 0) {
sleep(err_wait_time);
} else {
return 1;
}
}
} while (err_wait_time > 0);
return 0;
}

File diff suppressed because it is too large Load Diff