Просмотр исходного кода

The A spec required patterns to be set but the B
spec doesn't. Fix lib/evt.c and test/testevt.c



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@708 fd59a12c-fef9-0310-b244-a6a79926bd2f

Mark Haverkamp 20 лет назад
Родитель
Сommit
d330f32d78
2 измененных файлов с 73 добавлено и 41 удалено
  1. 5 16
      lib/evt.c
  2. 68 25
      test/testevt.c

+ 5 - 16
lib/evt.c

@@ -1390,15 +1390,13 @@ saEvtEventAttributesSet(
 	edi->edi_priority = priority;
 	edi->edi_retention_time = retentionTime;
 
-	/*
-	 * publisherName or patternArray not allowed to be NULL
-	 */
-	if (!publisherName || !patternArray) {
-			error = SA_AIS_ERR_INVALID_PARAM;
-			goto attr_set_unlock;
+	if (publisherName) {
+		edi->edi_pub_name = *publisherName;
 	}
 
-	edi->edi_pub_name = *publisherName;
+	if (!patternArray) {
+		goto attr_set_unlock;
+	}
 
 	oldpatterns = edi->edi_patterns.patterns;
 	oldnumber = edi->edi_patterns.patternsNumber;
@@ -1778,15 +1776,6 @@ saEvtEventPublish(
 	}
 	pthread_mutex_lock(&edi->edi_mutex);
 
-	/*
-	 * See if patterns have been set for this event.  If not, we
-	 * can't publish.
-	 */
-	if (!edi->edi_patterns.patterns) {
-		error = SA_AIS_ERR_INVALID_PARAM;
-		goto pub_put1;
-	}
-
 	error = saHandleInstanceGet(&channel_handle_db, edi->edi_channel_handle,
 			(void*)&eci);
 	if (error != SA_AIS_OK) {

+ 68 - 25
test/testevt.c

@@ -725,6 +725,7 @@ SaUint8T priority;
 SaTimeT retention_time = 0ULL;
 SaNameT publisher_name = {0, {0}};
 SaSizeT event_data_size;
+int expected_pat_count;
 
 /*
  * Test event operations.
@@ -791,10 +792,15 @@ event_callback(SaEvtSubscriptionIdT my_subscription_id,
 			(unsigned long long)event_id, (unsigned long long)my_event_id);
 	}
 
-	if (evt_pat_get_array.patternsNumber != 4) {
-		printf("ERROR: pattern array count not 4: %lld\n", 
-					evt_pat_get_array.patternsNumber);
+	if (evt_pat_get_array.patternsNumber != expected_pat_count) {
+		printf("ERROR: pattern array count not %d: %lld\n", 
+					expected_pat_count, evt_pat_get_array.patternsNumber);
+	}
+
+	if (expected_pat_count == 0) {
+		goto evt_free;
 	}
+
 	for (i = 0; i < evt_pat_get_array.patternsNumber; i++) {
 		if (evt_pat_get_array.patterns[i].patternSize !=
 				evt_pat_set_array.patterns[i].patternSize) {
@@ -1145,6 +1151,32 @@ test_event()
 
 	printf("       Publish with no patterns set\n");
 
+	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("ERROR: event subscribe result: %s\n", result_buf);
+		do {
+			result = saEvtChannelClose(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("ERROR: Channel close result: %s\n", result_buf);
+		}
+		do {
+			result = saEvtFinalize(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("ERROR: Finalize result: %s\n", result_buf);
+		}
+		return;
+	}
+
 	do {
 		result = saEvtEventAllocate(channel_handle, &event_handle);
 	} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
@@ -1154,46 +1186,56 @@ test_event()
 		goto evt_close;
 	}
 
+	expected_pat_count = 0;
 	do {
 		result = saEvtEventPublish(event_handle, 0, 0, &event_id);
 	} while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
-	if (result != SA_AIS_ERR_INVALID_PARAM) {
+	if (result != SA_AIS_OK) {
 		get_sa_error(result, result_buf, result_buf_len);
 		printf("ERROR: event Publish result(1): %s\n", result_buf);
 		goto evt_close;
 	}
 
 	/*
-	 * Publish with pattens
+	 * See if we got the event
 	 */
-	printf("       Publish with patterns set\n");
-
 	do {
-		result = saEvtEventSubscribe(channel_handle,
-			&subscribe_filters,
-			subscription_id);
+		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("ERROR: event subscribe result: %s\n", result_buf);
-		do {
-			result = saEvtChannelClose(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("ERROR: Channel close result: %s\n", result_buf);
-		}
-		do {
-			result = saEvtFinalize(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("ERROR: Finalize result: %s\n", result_buf);
+		printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
+		/* error */
+		return;
+	}
+	pfd.fd = fd;
+	pfd.events = POLLIN;
+	nfd = poll(&pfd, 1, timeout);
+	if (nfd <= 0) {
+		printf("ERROR: poll fds %d\n", nfd);
+		if (nfd < 0) {
+			perror("ERROR: poll error");
 		}
+		/* Error */
 		return;
 	}
 
+	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("ERROR: saEvtDispatch %s\n", result_buf);
+		/* error */
+		return;
+	}
+
+
+	/*
+	 * Publish with pattens
+	 */
+	printf("       Publish with patterns set\n");
+
 	retention_time = 0ULL;
 	do {
 		result = saEvtEventAttributesSet(event_handle,
@@ -1216,6 +1258,7 @@ test_event()
 		exp_data[i] = lrand48();
 	}
 	event_data_size = DATA_SIZE;
+	expected_pat_count = 4;
 
 	/*
 	 * Send it