2 * Copyright (c) 2004-2005 Mark Haverkamp
3 * Copyright (c) 2004-2005 Open Source Development Lab
7 * This software licensed under BSD license, the text of which follows:
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * - Neither the name of the Open Source Development Lab nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
35 * Test program for event service
38 * Version check in saEvtInitialze()
41 * Test basic channel operations. Open/close/subscribe/unsubscribe
44 * Event operations: allocation, free, setting and getting
45 * attributes, publishing.
47 * test_multi_channel1();
48 * test_multi_channel1();
49 * test_multi_channel1();
50 * Test events on multiple channels and multiple subscriptions.
53 * Test event retention times.
55 * test_unlink_channel();
56 * Test event channel unlink.
68 extern int get_sa_error(SaAisErrorT
, char *, int);
70 int result_buf_len
= sizeof(result_buf
);
74 void testresult (SaAisErrorT result
, SaAisErrorT expected
, int test_no
)
76 if (result
== expected
) {
77 printf ("Test %d passed\n", test_no
);
79 get_sa_error(result
, result_buf
, result_buf_len
);
80 printf ("ERROR: Test %d FAILED (expected %d got %s)\n",
81 test_no
, expected
, result_buf
);
85 SaVersionT version1
= { 'B', 0x01, 0x01 };
86 SaVersionT version2
= { 'A', 0x01, 0x01 };
87 SaVersionT version3
= { 'B', 0x02, 0x01 };
88 SaVersionT version4
= { 'B', 0x01, 0xff };
89 SaVersionT version5
= { 'C', 0xff, 0xff };
96 struct version_test versions
[] = {
97 { &version1
, SA_AIS_OK
},
98 { &version2
, SA_AIS_ERR_VERSION
},
99 { &version3
, SA_AIS_ERR_VERSION
},
100 { &version4
, SA_AIS_OK
},
101 { &version5
, SA_AIS_ERR_VERSION
},
102 { 0, SA_AIS_ERR_INVALID_PARAM
}
105 int version_size
= sizeof(versions
) / sizeof(struct version_test
);
107 void open_callback(SaInvocationT invocation
,
108 SaEvtChannelHandleT channelHandle
,
110 void event_callback(SaEvtSubscriptionIdT subscriptionId
,
111 const SaEvtEventHandleT eventHandle
,
112 const SaSizeT eventDataSize
);
114 SaEvtCallbacksT callbacks
= {
119 char channel
[256] = "TESTEVT_CHANNEL";
120 char unlink_channel
[256] = "TESTEVT_UNLINK_CHANNEL";
121 SaEvtSubscriptionIdT subscription_id
= 0xabcdef;
122 SaInvocationT open_invocation
= 0xaa55cc33;
123 unsigned long long test_ret_time
= 30000000000ULL; /* 30 seconds */
131 #define DATA_SIZE 2048 /* default data size */
132 #define LCOUNT DATA_SIZE/sizeof(long)
135 * Test saEvtInitialize and version checking.
137 void test_initialize (void) {
144 * version check tests
146 printf("Test lib version check on initlialize\n");
147 for (i
=0; i
< version_size
; i
++) {
149 result
= saEvtInitialize (&handle
, 0, versions
[i
].version
);
150 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
152 testresult (result
, versions
[i
].result
, i
);
153 if (result
== SA_AIS_OK
) {
154 saEvtFinalize(handle
);
161 #define _patt1 "Filter pattern 1"
162 #define patt1 (SaUint8T *) _patt1
163 #define patt1_size sizeof(_patt1)
165 #define _patt2 "Filter pattern 2"
166 #define patt2 (SaUint8T *) _patt2
167 #define patt2_size sizeof(_patt2)
169 #define _patt3 "Filter pattern 3"
170 #define patt3 (SaUint8T *) _patt3
171 #define patt3_size sizeof(_patt3)
173 #define _patt4 "Filter pattern 4"
174 #define patt4 (SaUint8T *) _patt4
175 #define patt4_size sizeof(_patt4)
178 SaEvtEventFilterT filters
[] = {
179 {SA_EVT_PREFIX_FILTER
, {patt1_size
, patt1_size
, patt1
}},
180 {SA_EVT_SUFFIX_FILTER
, {patt2_size
, patt2_size
, patt2
}},
181 {SA_EVT_EXACT_FILTER
, {patt3_size
, patt3_size
, patt3
}},
182 {SA_EVT_PASS_ALL_FILTER
, {patt4_size
, patt4_size
, patt4
}}
185 SaEvtEventFilterArrayT subscribe_filters
= {
186 sizeof(filters
)/sizeof(SaEvtEventFilterT
),
191 * Process the open callback
193 void open_callback(SaInvocationT invocation
,
194 SaEvtChannelHandleT channel_handle
,
199 printf(" Received open channel callback\n");
200 if (error
!= SA_AIS_OK
) {
201 get_sa_error(error
, result_buf
, result_buf_len
);
202 printf("ERROR: async channel open result: %s\n", result_buf
);
205 if (invocation
!= open_invocation
) {
206 printf("ERROR: Unexpected invocation value: e 0x%llx, a 0x%llx\n",
207 (long long)open_invocation
, (long long)invocation
);
210 printf(" Close async channel:\n");
212 result
= saEvtChannelClose(channel_handle
);
213 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
215 if (result
!= SA_AIS_OK
) {
216 get_sa_error(result
, result_buf
, result_buf_len
);
217 printf("ERROR: channel close result: %s\n", result_buf
);
222 * Test channel operations.
224 * 2. Close a channel.
225 * 3. Channel subscription.
226 * 4. Channel unsubscribe
227 * 5. unsubscribe/finalize with no channel close.
228 * 6. Multiple subscriptions.
229 * 7. Duplicate subscription ID.
230 * 8. unsubscribe non-exsistent subscription ID.
231 * 9. Open a channel async.
238 SaEvtChannelHandleT channel_handle
;
239 SaEvtChannelOpenFlagsT flags
;
240 SaNameT channel_name
;
245 SaSelectionObjectT fd
;
248 flags
= SA_EVT_CHANNEL_PUBLISHER
|
249 SA_EVT_CHANNEL_SUBSCRIBER
|
250 SA_EVT_CHANNEL_CREATE
;
251 strcpy((char *)channel_name
.value
, channel
);
252 channel_name
.length
= strlen(channel
);
254 * Channel open/close test
256 printf("Test Channel operations:\n");
258 printf(" Channel open:\n");
260 result
= saEvtInitialize (&handle
,
261 &callbacks
, versions
[0].version
);
262 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
264 if (result
!= SA_AIS_OK
) {
265 get_sa_error(result
, result_buf
, result_buf_len
);
266 printf("ERROR: Event Initialize result: %s\n", result_buf
);
271 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
273 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
276 if (result
!= SA_AIS_OK
) {
277 get_sa_error(result
, result_buf
, result_buf_len
);
278 printf("ERROR: channel open result: %s\n", result_buf
);
280 result
= saEvtFinalize(handle
);
281 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
282 if (result
!= SA_AIS_OK
) {
283 get_sa_error(result
, result_buf
, result_buf_len
);
284 printf("ERROR: Event Finalize result: %s\n", result_buf
);
289 printf(" Channel close:\n");
291 result
= saEvtChannelClose(channel_handle
);
292 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
294 if (result
!= SA_AIS_OK
) {
295 get_sa_error(result
, result_buf
, result_buf_len
);
296 printf("ERROR: channel close result: %s\n", result_buf
);
301 result
= saEvtFinalize(handle
);
302 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
304 if (result
!= SA_AIS_OK
) {
305 get_sa_error(result
, result_buf
, result_buf_len
);
306 printf("ERROR: Event Finalize result: %s\n", result_buf
);
311 * Test channel subscribe
313 printf(" Channel subscribe:\n");
315 result
= saEvtInitialize (&handle
, &callbacks
,
316 versions
[0].version
);
317 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
318 if (result
!= SA_AIS_OK
) {
319 get_sa_error(result
, result_buf
, result_buf_len
);
320 printf("ERROR: Event Initialize result: %s\n", result_buf
);
324 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
326 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
327 if (result
!= SA_AIS_OK
) {
328 get_sa_error(result
, result_buf
, result_buf_len
);
329 printf("ERROR: channel open result: %s\n", result_buf
);
331 result
= saEvtFinalize(handle
);
332 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
333 if (result
!= SA_AIS_OK
) {
334 get_sa_error(result
, result_buf
, result_buf_len
);
335 printf("ERROR: Finalize result: %s\n", result_buf
);
341 result
= saEvtEventSubscribe(channel_handle
,
344 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
346 if (result
!= SA_AIS_OK
) {
347 get_sa_error(result
, result_buf
, result_buf_len
);
348 printf("ERROR: event subscribe result: %s\n", result_buf
);
350 result
= saEvtChannelClose(channel_handle
);
351 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
352 if (result
!= SA_AIS_OK
) {
353 get_sa_error(result
, result_buf
, result_buf_len
);
354 printf("ERROR: Channel close result: %s\n", result_buf
);
357 result
= saEvtFinalize(handle
);
358 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
359 if (result
!= SA_AIS_OK
) {
360 get_sa_error(result
, result_buf
, result_buf_len
);
361 printf("ERROR: Finalize result: %s\n", result_buf
);
367 printf(" Channel unsubscribe:\n");
370 result
= saEvtEventUnsubscribe(channel_handle
, subscription_id
);
371 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
372 if (result
!= SA_AIS_OK
) {
373 get_sa_error(result
, result_buf
, result_buf_len
);
374 printf("ERROR: event unsubscribe result: %s\n", result_buf
);
376 result
= saEvtChannelClose(channel_handle
);
377 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
378 if (result
!= SA_AIS_OK
) {
379 get_sa_error(result
, result_buf
, result_buf_len
);
380 printf("ERROR: Channel close result: %s\n", result_buf
);
383 result
= saEvtFinalize(handle
);
384 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
385 if (result
!= SA_AIS_OK
) {
386 get_sa_error(result
, result_buf
, result_buf_len
);
387 printf("ERROR: Finalize result: %s\n", result_buf
);
392 result
= saEvtChannelClose(channel_handle
);
393 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
394 if (result
!= SA_AIS_OK
) {
395 get_sa_error(result
, result_buf
, result_buf_len
);
396 printf("ERROR: Channel close result: %s\n", result_buf
);
399 result
= saEvtFinalize(handle
);
400 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
401 if (result
!= SA_AIS_OK
) {
402 get_sa_error(result
, result_buf
, result_buf_len
);
403 printf("ERROR: Finalize result: %s\n", result_buf
);
407 * Test channel subscribe with no close
409 printf(" Channel subscribe with no close at end:\n");
411 result
= saEvtInitialize (&handle
, &callbacks
,
412 versions
[0].version
);
413 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
414 if (result
!= SA_AIS_OK
) {
415 get_sa_error(result
, result_buf
, result_buf_len
);
416 printf("ERROR: Event Initialize result: %s\n", result_buf
);
420 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
422 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
423 if (result
!= SA_AIS_OK
) {
424 get_sa_error(result
, result_buf
, result_buf_len
);
425 printf("ERROR: channel open result: %s\n", result_buf
);
426 result
= saEvtFinalize(handle
);
431 result
= saEvtEventSubscribe(channel_handle
,
434 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
436 if (result
!= SA_AIS_OK
) {
437 get_sa_error(result
, result_buf
, result_buf_len
);
438 printf("ERROR: event subscribe result: %s\n", result_buf
);
439 result
= saEvtChannelClose(channel_handle
);
443 result
= saEvtFinalize(handle
);
444 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
445 if (result
!= SA_AIS_OK
) {
446 get_sa_error(result
, result_buf
, result_buf_len
);
447 printf("ERROR: Finalize failed\n");
452 * Test multiple subscriptions
454 printf(" Multiple subscriptions\n");
456 result
= saEvtInitialize (&handle
, &callbacks
,
457 versions
[0].version
);
458 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
459 if (result
!= SA_AIS_OK
) {
460 get_sa_error(result
, result_buf
, result_buf_len
);
461 printf("ERROR: Event Initialize result: %s\n", result_buf
);
465 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
467 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
468 if (result
!= SA_AIS_OK
) {
469 get_sa_error(result
, result_buf
, result_buf_len
);
470 printf("ERROR: channel open result: %s\n", result_buf
);
472 result
= saEvtFinalize(handle
);
473 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
474 if (result
!= SA_AIS_OK
) {
475 get_sa_error(result
, result_buf
, result_buf_len
);
476 printf("ERROR: Finalize result: %s\n", result_buf
);
482 result
= saEvtEventSubscribe(channel_handle
,
485 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
487 if (result
!= SA_AIS_OK
) {
488 get_sa_error(result
, result_buf
, result_buf_len
);
489 printf("ERROR: First event subscribe result: %s\n", result_buf
);
491 result
= saEvtChannelClose(channel_handle
);
492 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
493 if (result
!= SA_AIS_OK
) {
494 get_sa_error(result
, result_buf
, result_buf_len
);
495 printf("ERROR: Channel close result: %s\n", result_buf
);
498 result
= saEvtFinalize(handle
);
499 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
500 if (result
!= SA_AIS_OK
) {
501 get_sa_error(result
, result_buf
, result_buf_len
);
502 printf("ERROR: Finalize result: %s\n", result_buf
);
508 result
= saEvtEventSubscribe(channel_handle
,
511 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
513 if (result
!= SA_AIS_OK
) {
514 get_sa_error(result
, result_buf
, result_buf_len
);
515 printf("ERROR: second event subscribe result: %s\n", result_buf
);
517 result
= saEvtChannelClose(channel_handle
);
518 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
519 if (result
!= SA_AIS_OK
) {
520 get_sa_error(result
, result_buf
, result_buf_len
);
521 printf("ERROR: Channel close result: %s\n", result_buf
);
524 result
= saEvtFinalize(handle
);
525 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
526 if (result
!= SA_AIS_OK
) {
527 get_sa_error(result
, result_buf
, result_buf_len
);
528 printf("ERROR: Finalize result: %s\n", result_buf
);
534 * Test duplicate subscription
536 printf(" Duplicate subscription\n");
539 result
= saEvtEventSubscribe(channel_handle
,
542 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
544 if (result
!= SA_AIS_ERR_EXIST
) {
545 get_sa_error(result
, result_buf
, result_buf_len
);
546 printf("ERROR: First event subscribe result: %s\n", result_buf
);
547 result
= saEvtChannelClose(channel_handle
);
548 result
= saEvtFinalize(handle
);
553 * Test unsubscribe non-existent sub_id
555 printf(" Unsubscribe non-existent sub_id\n");
558 result
= saEvtEventUnsubscribe(channel_handle
,
560 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
561 if (result
!= SA_AIS_ERR_NOT_EXIST
) {
562 get_sa_error(result
, result_buf
, result_buf_len
);
563 printf("ERROR: event unsubscribe result: %s\n", result_buf
);
565 result
= saEvtChannelClose(channel_handle
);
566 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
567 if (result
!= SA_AIS_OK
) {
568 get_sa_error(result
, result_buf
, result_buf_len
);
569 printf("ERROR: Channel close result: %s\n", result_buf
);
572 result
= saEvtFinalize(handle
);
573 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
574 if (result
!= SA_AIS_OK
) {
575 get_sa_error(result
, result_buf
, result_buf_len
);
576 printf("ERROR: Finalize result: %s\n", result_buf
);
582 result
= saEvtEventUnsubscribe(channel_handle
, subscription_id
);
583 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
584 if (result
!= SA_AIS_OK
) {
585 get_sa_error(result
, result_buf
, result_buf_len
);
586 printf("ERROR: first event unsubscribe result: %s\n", result_buf
);
589 result
= saEvtEventUnsubscribe(channel_handle
,
591 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
592 if (result
!= SA_AIS_OK
) {
593 get_sa_error(result
, result_buf
, result_buf_len
);
594 printf("ERROR: second event unsubscribe result: %s\n", result_buf
);
597 result
= saEvtChannelClose(channel_handle
);
598 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
599 if (result
!= SA_AIS_OK
) {
600 get_sa_error(result
, result_buf
, result_buf_len
);
601 printf("ERROR: Channel close result: %s\n", result_buf
);
604 result
= saEvtFinalize(handle
);
605 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
606 if (result
!= SA_AIS_OK
) {
607 get_sa_error(result
, result_buf
, result_buf_len
);
608 printf("ERROR: Finalize result: %s\n", result_buf
);
612 * Test opening a channel async.
614 printf(" Channel open async:\n");
616 result
= saEvtInitialize (&handle
, &callbacks
,
617 versions
[0].version
);
618 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
620 if (result
!= SA_AIS_OK
) {
621 get_sa_error(result
, result_buf
, result_buf_len
);
622 printf("ERROR: Event Initialize result: %s\n", result_buf
);
627 result
= saEvtChannelOpenAsync(handle
, open_invocation
,
628 &channel_name
, flags
);
629 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
632 if (result
!= SA_AIS_OK
) {
633 get_sa_error(result
, result_buf
, result_buf_len
);
634 printf("ERROR: channel open async result: %s\n", result_buf
);
636 result
= saEvtFinalize(handle
);
637 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
638 if (result
!= SA_AIS_OK
) {
639 get_sa_error(result
, result_buf
, result_buf_len
);
640 printf("ERROR: Event Finalize result: %s\n", result_buf
);
645 * See if we got the open callback
648 result
= saEvtSelectionObjectGet(handle
, &fd
);
649 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
650 if (result
!= SA_AIS_OK
) {
651 get_sa_error(result
, result_buf
, result_buf_len
);
652 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
658 nfd
= poll(&pfd
, 1, timeout
);
660 printf("ERROR: poll fds %d\n", nfd
);
662 perror("ERROR: poll error");
669 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
670 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
671 if (result
!= SA_AIS_OK
) {
672 get_sa_error(result
, result_buf
, result_buf_len
);
673 printf("ERROR: saEvtDispatch %s\n", result_buf
);
681 result
= saEvtFinalize(handle
);
682 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
684 if (result
!= SA_AIS_OK
) {
685 get_sa_error(result
, result_buf
, result_buf_len
);
686 printf("ERROR: Event Finalize result: %s\n", result_buf
);
701 SaEvtEventPatternT evt_patts
[5] = {
707 SaEvtEventPatternArrayT evt_pat_get_array
= { 5, 0, evt_patts
};
709 SaEvtEventPatternT patterns
[] = {
710 {patt1_size
, patt1_size
, patt1
},
711 {patt2_size
, patt2_size
, patt2
},
712 {patt3_size
, patt3_size
, patt3
},
713 {patt4_size
, patt4_size
, patt4
}
715 SaNameT test_pub_name
= {13, "Test Pub Name"};
716 #define TEST_PRIORITY 2
718 SaEvtEventPatternArrayT evt_pat_set_array
= {
719 sizeof(patterns
)/sizeof(SaEvtEventPatternT
),
720 sizeof(patterns
)/sizeof(SaEvtEventPatternT
),
724 char event_data
[1000];
725 #define EVENT_DATA_SIZE 1000
727 SaEvtEventIdT event_id
= 0;
729 SaTimeT retention_time
= 0ULL;
730 SaNameT publisher_name
= {0, {0}};
731 SaSizeT event_data_size
= 0;
732 int expected_pat_count
;
735 * Test event operations.
737 * 1. Event allocation
738 * 2. Get event attributes (no pointers).
739 * 3. Get event attributes with pointers.
740 * 4. Set/Get event attributes.
741 * 5. Get event user data no pointer or count
742 * 6. Get event user data with pointer and no count
743 * 7. Get event user data with no pointer with a count.
744 * 8. Get event user data with pointer and count.
745 * 9. Get event user data woth a short count.
747 * 11. Publish with no set patterns.
748 * 12. Publish with set patterns and event user data.
752 event_callback(SaEvtSubscriptionIdT my_subscription_id
,
753 const SaEvtEventHandleT event_handle
,
754 const SaSizeT my_event_data_size
)
757 SaUint8T my_priority
;
758 SaTimeT my_retention_time
;
759 SaNameT my_publisher_name
= {0, {0}};
760 SaTimeT my_publish_time
;
761 SaEvtEventIdT my_event_id
;
766 printf(" event_callback called\n");
767 if (my_subscription_id
!= subscription_id
) {
768 printf("ERROR: sub ID: e=%x, a=%x\n",
769 subscription_id
, my_subscription_id
);
771 if (my_event_data_size
!= event_data_size
) {
772 printf("ERROR: event data size e=%llu, a=%llu\n",
773 (unsigned long long)event_data_size
,
774 (unsigned long long)my_event_data_size
);
777 evt_pat_get_array
.patternsNumber
= 4;
779 result
= saEvtEventAttributesGet(event_handle
,
780 &evt_pat_get_array
, /* patterns */
781 &my_priority
, /* priority */
782 &my_retention_time
, /* retention time */
783 &my_publisher_name
, /* publisher name */
784 &my_publish_time
, /* publish time */
785 &my_event_id
/* event_id */
787 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
788 if (result
!= SA_AIS_OK
) {
789 get_sa_error(result
, result_buf
, result_buf_len
);
790 printf("ERROR: event get attr result(2): %s\n", result_buf
);
794 if (my_event_id
!= event_id
) {
795 printf("ERROR: Call back event ID error: e=%llx, a=%llx\n",
796 (unsigned long long)event_id
, (unsigned long long)my_event_id
);
799 if (evt_pat_get_array
.patternsNumber
!= expected_pat_count
) {
800 printf("ERROR: pattern array count not %d: %llu\n",
802 (unsigned long long)evt_pat_get_array
.patternsNumber
);
805 if (expected_pat_count
== 0) {
809 for (i
= 0; i
< evt_pat_get_array
.patternsNumber
; i
++) {
810 if (evt_pat_get_array
.patterns
[i
].patternSize
!=
811 evt_pat_set_array
.patterns
[i
].patternSize
) {
812 printf("ERROR: pattern %d count not equal g=%llu, s=%llu\n",
814 (unsigned long long)evt_pat_get_array
.patterns
[i
].patternSize
,
815 (unsigned long long)evt_pat_set_array
.patterns
[i
].patternSize
);
816 printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
818 evt_pat_get_array
.patterns
[i
].pattern
,
819 evt_pat_set_array
.patterns
[i
].pattern
);
821 if (memcmp(evt_pat_get_array
.patterns
[i
].pattern
,
822 evt_pat_set_array
.patterns
[i
].pattern
,
823 evt_pat_get_array
.patterns
[i
].patternSize
) != 0){
825 "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
827 evt_pat_get_array
.patterns
[i
].pattern
,
828 evt_pat_set_array
.patterns
[i
].pattern
);
833 if (priority
!= my_priority
) {
834 printf("ERROR: priority: e=0x%x a=0x%x\n",
835 priority
, my_priority
);
837 if (retention_time
!= my_retention_time
) {
838 printf("ERROR: retention: e=0x%llx a=0x%llx\n",
839 (unsigned long long)retention_time
,
840 (unsigned long long)my_retention_time
);
842 if (publisher_name
.length
!= my_publisher_name
.length
) {
843 printf("ERROR: publisher name length: e=%d, a=%d\n",
844 publisher_name
.length
,
845 my_publisher_name
.length
);
847 if (memcmp(publisher_name
.value
, my_publisher_name
.value
,
848 publisher_name
.length
) != 0) {
849 printf("ERROR: publisher name content: e=%s, a=%s\n",
850 publisher_name
.value
,
851 my_publisher_name
.value
);
855 act_data
= malloc(my_event_data_size
);
856 memset(act_data
, 0, my_event_data_size
);
857 data_size
= my_event_data_size
;
859 result
= saEvtEventDataGet(event_handle
, act_data
, &data_size
);
860 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
861 if (result
!= SA_AIS_OK
) {
862 get_sa_error(result
, result_buf
, result_buf_len
);
863 printf("ERROR: event data get result: %s\n", result_buf
);
866 if (data_size
!= event_data_size
) {
867 printf("ERROR: Data size: e=%llu a=%llu\n",
868 (unsigned long long)event_data_size
,
869 (unsigned long long)data_size
);
871 for (i
= 0; i
< (data_size
/sizeof(long)); i
++) {
872 if (act_data
[i
] != exp_data
[i
]) {
873 printf("ERROR: Event Data e=%lx a=%lx at index %d\n",
874 exp_data
[i
], act_data
[i
], i
);
883 result
= saEvtEventFree(event_handle
);
884 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
885 if (result
!= SA_AIS_OK
) {
886 get_sa_error(result
, result_buf
, result_buf_len
);
887 printf("ERROR: event free result: %s\n", result_buf
);
895 SaEvtChannelHandleT channel_handle
;
896 SaEvtEventHandleT event_handle
;
897 SaEvtChannelOpenFlagsT flags
;
898 SaNameT channel_name
;
900 SaTimeT publish_time
;
903 SaSelectionObjectT fd
;
912 flags
= SA_EVT_CHANNEL_PUBLISHER
|SA_EVT_CHANNEL_SUBSCRIBER
|
913 SA_EVT_CHANNEL_CREATE
;
914 strcpy((char *)channel_name
.value
, channel
);
915 channel_name
.length
= strlen(channel
);
917 printf("Test Event operations:\n");
920 result
= saEvtInitialize (&handle
, &callbacks
, versions
[0].version
);
921 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
922 if (result
!= SA_AIS_OK
) {
923 get_sa_error(result
, result_buf
, result_buf_len
);
924 printf("ERROR: Event Initialize result: %s\n", result_buf
);
928 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
930 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
931 if (result
!= SA_AIS_OK
) {
932 get_sa_error(result
, result_buf
, result_buf_len
);
933 printf("ERROR: channel open result: %s\n", result_buf
);
940 printf(" Event allocation\n");
942 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
943 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
944 if (result
!= SA_AIS_OK
) {
945 get_sa_error(result
, result_buf
, result_buf_len
);
946 printf("ERROR: event Allocate result: %s\n", result_buf
);
950 printf(" Get event attributes(1)\n");
952 result
= saEvtEventAttributesGet(event_handle
,
955 0, /* retention time */
956 0, /* publisher name */
957 0, /* publish time */
960 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
961 if (result
!= SA_AIS_OK
) {
962 get_sa_error(result
, result_buf
, result_buf_len
);
963 printf("ERROR: event get attr result(1): %s\n", result_buf
);
968 * Get event attributes, this time supply pointers.
969 * validate the default values.
971 printf(" Get event attributes(2)\n");
972 evt_pat_get_array
.patternsNumber
= 4;
974 result
= saEvtEventAttributesGet(event_handle
,
975 &evt_pat_get_array
, /* patterns */
976 &priority
, /* priority */
977 &retention_time
, /* retention time */
978 &publisher_name
, /* publisher name */
979 &publish_time
, /* publish time */
980 &event_id
/* event_id */
982 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
983 if (result
!= SA_AIS_OK
) {
984 get_sa_error(result
, result_buf
, result_buf_len
);
985 printf("ERROR: event get attr result(2): %s\n", result_buf
);
988 if (evt_pat_get_array
.patternsNumber
!= 0) {
989 printf("ERROR: pattern array count not zero: %llu\n",
990 (unsigned long long)evt_pat_get_array
.patternsNumber
);
992 if (priority
!= SA_EVT_LOWEST_PRIORITY
) {
993 printf("ERROR: priority not lowest: 0x%x\n", priority
);
995 if (retention_time
!= 0) {
996 printf("ERROR: retention time not zero: %0llx\n",
997 (unsigned long long)retention_time
);
999 if (publisher_name
.length
!= 0) {
1000 printf("ERROR: publisher name not null: %s\n", publisher_name
.value
);
1002 if (event_id
!= 0) {
1003 printf("ERROR: event id not zero: 0x%llx\n",
1004 (unsigned long long)event_id
);
1009 * Set some attributes, then read them back
1011 printf(" Set/get event attributes(1)\n");
1013 result
= saEvtEventAttributesSet(event_handle
,
1018 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1019 if (result
!= SA_AIS_OK
) {
1020 get_sa_error(result
, result_buf
, result_buf_len
);
1021 printf("ERROR: event set attr result(1): %s\n", result_buf
);
1025 evt_pat_get_array
.patternsNumber
= 4;
1027 result
= saEvtEventAttributesGet(event_handle
,
1028 &evt_pat_get_array
, /* patterns */
1029 &priority
, /* priority */
1030 &retention_time
, /* retention time */
1031 &publisher_name
, /* publisher name */
1032 &publish_time
, /* publish time */
1033 &event_id
/* event_id */
1035 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1036 if (result
!= SA_AIS_OK
) {
1037 get_sa_error(result
, result_buf
, result_buf_len
);
1038 printf("ERROR: event get attr result(2): %s\n", result_buf
);
1041 if (evt_pat_get_array
.patternsNumber
!= 4) {
1042 printf("ERROR: pattern array count not 4: %llu\n",
1043 (unsigned long long)evt_pat_get_array
.patternsNumber
);
1045 for (i
= 0; i
< evt_pat_get_array
.patternsNumber
; i
++) {
1046 if (evt_pat_get_array
.patterns
[i
].patternSize
!=
1047 evt_pat_set_array
.patterns
[i
].patternSize
) {
1048 printf("ERROR: pattern %d count not equal g=%lld, s=%lld\n",
1050 (unsigned long long)evt_pat_get_array
.patterns
[i
].patternSize
,
1051 (unsigned long long)evt_pat_set_array
.patterns
[i
].patternSize
);
1052 printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
1054 evt_pat_get_array
.patterns
[i
].pattern
,
1055 evt_pat_set_array
.patterns
[i
].pattern
);
1057 if (memcmp(evt_pat_get_array
.patterns
[i
].pattern
,
1058 evt_pat_set_array
.patterns
[i
].pattern
,
1059 evt_pat_get_array
.patterns
[i
].patternSize
) != 0){
1061 "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
1063 evt_pat_get_array
.patterns
[i
].pattern
,
1064 evt_pat_set_array
.patterns
[i
].pattern
);
1069 if (priority
!= TEST_PRIORITY
) {
1070 printf("ERROR: priority: e=0x%x a=0x%x\n",
1071 TEST_PRIORITY
, priority
);
1073 if (retention_time
!= test_ret_time
) {
1074 printf("ERROR: retention: e=0x%llx a=0x%llx\n",
1075 (unsigned long long)test_ret_time
,
1076 (unsigned long long)retention_time
);
1078 if (publisher_name
.length
!= test_pub_name
.length
) {
1079 printf("ERROR: publisher name length: e=%d, a=%d\n",
1080 test_pub_name
.length
,
1081 publisher_name
.length
);
1083 if (memcmp(publisher_name
.value
, test_pub_name
.value
,
1084 publisher_name
.length
) != 0) {
1085 printf("ERROR: publisher name content: e=%s, a=%s\n",
1086 test_pub_name
.value
,
1087 publisher_name
.value
);
1091 if (event_id
!= 0) {
1092 printf("ERROR: event id not zero: 0x%llx\n",
1093 (unsigned long long)event_id
);
1099 event_data_size
= 0;
1100 printf(" Get event data(1)\n");
1102 result
= saEvtEventDataGet(event_handle
, 0, &event_data_size
);
1103 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1104 if (result
!= SA_AIS_ERR_NO_SPACE
) {
1105 get_sa_error(result
, result_buf
, result_buf_len
);
1106 printf("ERROR: Get event data(1) result: %s\n", result_buf
);
1108 printf(" Get event data(2)\n");
1110 result
= saEvtEventDataGet(event_handle
, event_data
, &event_data_size
);
1111 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1112 if (result
!= SA_AIS_ERR_BAD_HANDLE
) {
1113 get_sa_error(result
, result_buf
, result_buf_len
);
1114 printf("ERROR: Get event data(2) result: %s\n", result_buf
);
1116 printf(" Get event data(3)\n");
1117 event_data_size
= EVENT_DATA_SIZE
;
1119 result
= saEvtEventDataGet(event_handle
, 0, &event_data_size
);
1120 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1121 if (result
!= SA_AIS_ERR_NO_SPACE
) {
1122 get_sa_error(result
, result_buf
, result_buf_len
);
1123 printf("ERROR: Get event data(3) result: %s\n", result_buf
);
1125 printf(" Get event data(4)\n");
1126 event_data_size
= EVENT_DATA_SIZE
;
1128 result
= saEvtEventDataGet(event_handle
, event_data
,
1130 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1131 if (result
!= SA_AIS_ERR_BAD_HANDLE
) {
1132 get_sa_error(result
, result_buf
, result_buf_len
);
1133 printf("ERROR: Get event data(4) result: %s\n", result_buf
);
1135 printf(" Get event data(5)\n");
1136 event_data_size
= 1;
1138 result
= saEvtEventDataGet(event_handle
, event_data
,
1140 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1141 if (result
!= SA_AIS_ERR_BAD_HANDLE
) {
1142 get_sa_error(result
, result_buf
, result_buf_len
);
1143 printf("ERROR: Get event data(5) result: %s\n", result_buf
);
1146 printf(" Free event(1)\n");
1148 result
= saEvtEventFree(event_handle
);
1149 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1150 if (result
!= SA_AIS_OK
) {
1151 get_sa_error(result
, result_buf
, result_buf_len
);
1152 printf("ERROR: event free result: %s\n", result_buf
);
1159 printf(" Publish with no patterns set\n");
1161 event_data_size
= 0;
1163 result
= saEvtEventSubscribe(channel_handle
,
1166 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1168 if (result
!= SA_AIS_OK
) {
1169 get_sa_error(result
, result_buf
, result_buf_len
);
1170 printf("ERROR: event subscribe result: %s\n", result_buf
);
1172 result
= saEvtChannelClose(channel_handle
);
1173 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1174 if (result
!= SA_AIS_OK
) {
1175 get_sa_error(result
, result_buf
, result_buf_len
);
1176 printf("ERROR: Channel close result: %s\n", result_buf
);
1179 result
= saEvtFinalize(handle
);
1180 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1181 if (result
!= SA_AIS_OK
) {
1182 get_sa_error(result
, result_buf
, result_buf_len
);
1183 printf("ERROR: Finalize result: %s\n", result_buf
);
1189 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
1190 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1191 if (result
!= SA_AIS_OK
) {
1192 get_sa_error(result
, result_buf
, result_buf_len
);
1193 printf("ERROR: event Allocate result: %s\n", result_buf
);
1197 expected_pat_count
= 0;
1199 result
= saEvtEventPublish(event_handle
, 0, 0, &event_id
);
1200 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1201 if (result
!= SA_AIS_OK
) {
1202 get_sa_error(result
, result_buf
, result_buf_len
);
1203 printf("ERROR: event Publish result(1): %s\n", result_buf
);
1208 * See if we got the event
1211 result
= saEvtSelectionObjectGet(handle
, &fd
);
1212 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1213 if (result
!= SA_AIS_OK
) {
1214 get_sa_error(result
, result_buf
, result_buf_len
);
1215 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
1220 pfd
.events
= POLLIN
;
1221 nfd
= poll(&pfd
, 1, timeout
);
1223 printf("ERROR: poll fds %d\n", nfd
);
1225 perror("ERROR: poll error");
1232 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
1233 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1234 if (result
!= SA_AIS_OK
) {
1235 get_sa_error(result
, result_buf
, result_buf_len
);
1236 printf("ERROR: saEvtDispatch %s\n", result_buf
);
1243 * Publish with pattens
1245 printf(" Publish with patterns set\n");
1247 retention_time
= 0ULL;
1249 result
= saEvtEventAttributesSet(event_handle
,
1254 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1255 if (result
!= SA_AIS_OK
) {
1256 get_sa_error(result
, result_buf
, result_buf_len
);
1257 printf("ERROR: event set attr result(2): %s\n", result_buf
);
1262 * Generate event data
1264 exp_data
= malloc(DATA_SIZE
);
1265 for (i
= 0; i
< LCOUNT
; i
++) {
1266 exp_data
[i
] = lrand48();
1268 event_data_size
= DATA_SIZE
;
1269 expected_pat_count
= 4;
1275 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
1277 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1278 if (result
!= SA_AIS_OK
) {
1279 get_sa_error(result
, result_buf
, result_buf_len
);
1280 printf("ERROR: event Publish result(2): %s\n", result_buf
);
1285 * See if we got the event
1288 result
= saEvtSelectionObjectGet(handle
, &fd
);
1289 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1290 if (result
!= SA_AIS_OK
) {
1291 get_sa_error(result
, result_buf
, result_buf_len
);
1292 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
1297 pfd
.events
= POLLIN
;
1298 nfd
= poll(&pfd
, 1, timeout
);
1300 printf("ERROR: poll fds %d\n", nfd
);
1302 perror("ERROR: poll error");
1309 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
1310 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1311 if (result
!= SA_AIS_OK
) {
1312 get_sa_error(result
, result_buf
, result_buf_len
);
1313 printf("ERROR: saEvtDispatch %s\n", result_buf
);
1325 result
= saEvtEventFree(event_handle
);
1326 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1327 if (result
!= SA_AIS_OK
) {
1328 get_sa_error(result
, result_buf
, result_buf_len
);
1329 printf("ERROR: event free result: %s\n", result_buf
);
1334 result
= saEvtChannelClose(channel_handle
);
1335 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1337 if (result
!= SA_AIS_OK
) {
1338 get_sa_error(result
, result_buf
, result_buf_len
);
1339 printf("ERROR: channel close result: %s\n", result_buf
);
1343 result
= saEvtFinalize(handle
);
1344 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1346 if (result
!= SA_AIS_OK
) {
1347 get_sa_error(result
, result_buf
, result_buf_len
);
1348 printf("ERROR: Event Finalize result: %s\n", result_buf
);
1354 SaEvtEventIdT event_id1
;
1355 SaEvtEventIdT event_id2
;
1356 SaEvtEventIdT event_id3
;
1357 SaEvtSubscriptionIdT sub1
= 0x101010;
1358 SaEvtSubscriptionIdT sub2
= 0x202020;
1359 static int call_count
= 0;
1362 * Handle call back for multi-test1
1363 * Checks event ID with subscription ID to make sure that we
1364 * received an event on the correct subscription.
1367 multi_test_callback1(SaEvtSubscriptionIdT my_subscription_id
,
1368 const SaEvtEventHandleT event_handle
,
1369 const SaSizeT my_event_data_size
)
1372 SaUint8T my_priority
;
1373 SaTimeT my_retention_time
;
1374 SaNameT my_publisher_name
= {0, {0}};
1375 SaTimeT my_publish_time
;
1376 SaEvtEventIdT my_event_id
;
1377 SaEvtSubscriptionIdT exp_sub_id
;
1379 printf(" multi_test_callback1 called(%d)\n", ++call_count
);
1381 evt_pat_get_array
.patternsNumber
= 4;
1383 result
= saEvtEventAttributesGet(event_handle
,
1384 &evt_pat_get_array
, /* patterns */
1385 &my_priority
, /* priority */
1386 &my_retention_time
, /* retention time */
1387 &my_publisher_name
, /* publisher name */
1388 &my_publish_time
, /* publish time */
1389 &my_event_id
/* event_id */
1391 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1392 if (result
!= SA_AIS_OK
) {
1393 get_sa_error(result
, result_buf
, result_buf_len
);
1394 printf("ERROR: event get attr result: %s\n", result_buf
);
1398 if (my_event_id
== event_id1
) {
1400 } else if (my_event_id
== event_id2
) {
1402 } else if (my_event_id
== event_id3
) {
1403 printf("ERROR: Received event 3 but not subscribed\n");
1406 printf("ERROR: Received event %llx but not sent\n",
1407 (unsigned long long)my_event_id
);
1411 if (my_subscription_id
!= exp_sub_id
) {
1412 printf("ERROR: sub ID: e=%x, a=%x\n",
1413 exp_sub_id
, my_subscription_id
);
1417 if (evt_pat_get_array
.patternsNumber
!= 1) {
1418 printf("ERROR: pattern array count not 1: %lld\n",
1419 (unsigned long long)evt_pat_get_array
.patternsNumber
);
1424 result
= saEvtEventFree(event_handle
);
1425 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1426 if (result
!= SA_AIS_OK
) {
1427 get_sa_error(result
, result_buf
, result_buf_len
);
1428 printf("ERROR: event free result: %s\n", result_buf
);
1433 * Test multiple channel operations
1434 * 1. Test multiple subscriptions on a single channel and receiving
1436 * 2. Test multiple openings of a single channel and receving events.
1437 * 3. Test opening of multiple channels and receiving events
1440 test_multi_channel1()
1443 SaEvtEventFilterT filt1
[1] = {
1444 {SA_EVT_EXACT_FILTER
, {8,8, (SaUint8T
*) "ChanPat1"}},
1446 SaEvtEventFilterT filt2
[1] = {
1447 {SA_EVT_EXACT_FILTER
, {8, 8, (SaUint8T
*) "ChanPat2"}},
1450 SaEvtEventFilterArrayT sub_filt
= {
1454 SaEvtEventPatternT pat1
= {8, 8, (SaUint8T
*) "ChanPat1"};
1455 SaEvtEventPatternT pat2
= {8, 8, (SaUint8T
*) "ChanPat2"};
1456 SaEvtEventPatternT pat3
= {8, 8, (SaUint8T
*) "ChanPat3"};
1458 SaEvtEventPatternArrayT evt_pat
= {
1463 SaEvtHandleT handle
;
1464 SaEvtChannelHandleT channel_handle
;
1465 SaEvtEventHandleT event_handle
;
1466 SaEvtChannelOpenFlagsT flags
;
1467 SaNameT channel_name
;
1468 SaEvtCallbacksT multi_callbacks
= {
1470 multi_test_callback1
1475 SaSelectionObjectT fd
;
1482 flags
= SA_EVT_CHANNEL_PUBLISHER
|SA_EVT_CHANNEL_SUBSCRIBER
|
1483 SA_EVT_CHANNEL_CREATE
;
1484 strcpy((char *)channel_name
.value
, channel
);
1485 channel_name
.length
= strlen(channel
);
1487 printf("Test multiple operations:\n");
1490 result
= saEvtInitialize (&handle
, &multi_callbacks
,
1491 versions
[0].version
);
1492 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1493 if (result
!= SA_AIS_OK
) {
1494 get_sa_error(result
, result_buf
, result_buf_len
);
1495 printf("ERROR: Event Initialize result: %s\n", result_buf
);
1499 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
1501 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1502 if (result
!= SA_AIS_OK
) {
1503 get_sa_error(result
, result_buf
, result_buf_len
);
1504 printf("ERROR: channel open result: %s\n", result_buf
);
1512 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
1513 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1514 if (result
!= SA_AIS_OK
) {
1515 get_sa_error(result
, result_buf
, result_buf_len
);
1516 printf("ERROR: event Allocate result: %s\n", result_buf
);
1521 * 1. Test multiple subscriptions on a single channel and receiving
1524 * Subscribe twice with two different filters. Then send three events.
1525 * One will match the first filter, the second will match the second
1526 * filter, the third will match none. We will validate that we receive
1527 * two events and that the subscription IDs match what we expect for the
1531 sub_filt
.filters
= filt1
;
1533 result
= saEvtEventSubscribe(channel_handle
,
1536 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1537 if (result
!= SA_AIS_OK
) {
1538 get_sa_error(result
, result_buf
, result_buf_len
);
1539 printf("ERROR: event subscribe(1) result: %s\n", result_buf
);
1543 sub_filt
.filters
= filt2
;
1545 result
= saEvtEventSubscribe(channel_handle
,
1548 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1549 if (result
!= SA_AIS_OK
) {
1550 get_sa_error(result
, result_buf
, result_buf_len
);
1551 printf("ERROR: event subscribe(2) result: %s\n", result_buf
);
1556 retention_time
= 0ULL;
1558 evt_pat
.patterns
= &pat1
;
1560 result
= saEvtEventAttributesSet(event_handle
,
1565 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1566 if (result
!= SA_AIS_OK
) {
1567 get_sa_error(result
, result_buf
, result_buf_len
);
1568 printf("ERROR: event set attr result(1): %s\n", result_buf
);
1573 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
1575 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1576 if (result
!= SA_AIS_OK
) {
1577 get_sa_error(result
, result_buf
, result_buf_len
);
1578 printf("ERROR: event Publish result:(1) %s\n", result_buf
);
1582 evt_pat
.patterns
= &pat2
;
1584 result
= saEvtEventAttributesSet(event_handle
,
1589 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1590 if (result
!= SA_AIS_OK
) {
1591 get_sa_error(result
, result_buf
, result_buf_len
);
1592 printf("ERROR: event set attr result(2): %s\n", result_buf
);
1597 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
1599 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1600 if (result
!= SA_AIS_OK
) {
1601 get_sa_error(result
, result_buf
, result_buf_len
);
1602 printf("ERROR: event Publish result:(2) %s\n", result_buf
);
1606 evt_pat
.patterns
= &pat3
;
1608 result
= saEvtEventAttributesSet(event_handle
,
1613 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1614 if (result
!= SA_AIS_OK
) {
1615 get_sa_error(result
, result_buf
, result_buf_len
);
1616 printf("ERROR: event set attr result(3): %s\n", result_buf
);
1621 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
1623 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1624 if (result
!= SA_AIS_OK
) {
1625 get_sa_error(result
, result_buf
, result_buf_len
);
1626 printf("ERROR: event Publish result:(3) %s\n", result_buf
);
1631 * See if we got the event
1634 result
= saEvtSelectionObjectGet(handle
, &fd
);
1635 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1636 if (result
!= SA_AIS_OK
) {
1637 get_sa_error(result
, result_buf
, result_buf_len
);
1638 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
1645 pfd
.events
= POLLIN
;
1646 nfd
= poll(&pfd
, 1, timeout
);
1649 } else if (nfd
< 0) {
1650 perror("ERROR: poll error");
1656 result
= saEvtDispatch(handle
, SA_DISPATCH_ALL
);
1657 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1658 if (result
!= SA_AIS_OK
) {
1659 get_sa_error(result
, result_buf
, result_buf_len
);
1660 printf("ERROR: saEvtDispatch %s\n", result_buf
);
1667 if (call_count
!= 2) {
1668 printf("ERROR: call back count: e=2, a=%d\n", call_count
);
1677 result
= saEvtEventFree(event_handle
);
1678 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1679 if (result
!= SA_AIS_OK
) {
1680 get_sa_error(result
, result_buf
, result_buf_len
);
1681 printf("ERROR: event free result: %s\n", result_buf
);
1686 result
= saEvtChannelClose(channel_handle
);
1687 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1689 if (result
!= SA_AIS_OK
) {
1690 get_sa_error(result
, result_buf
, result_buf_len
);
1691 printf("ERROR: channel close result: %s\n", result_buf
);
1695 result
= saEvtFinalize(handle
);
1696 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1698 if (result
!= SA_AIS_OK
) {
1699 get_sa_error(result
, result_buf
, result_buf_len
);
1700 printf("ERROR: Event Finalize result: %s\n", result_buf
);
1707 * Handle call back for multi-test2
1708 * Counts events received. Makes sure that we get one event from
1709 * each subscription.
1713 multi_test_callback2(SaEvtSubscriptionIdT my_subscription_id
,
1714 const SaEvtEventHandleT event_handle
,
1715 const SaSizeT my_event_data_size
)
1718 SaUint8T my_priority
;
1719 SaTimeT my_retention_time
;
1720 SaNameT my_publisher_name
= {0, {0}};
1721 SaTimeT my_publish_time
;
1722 SaEvtEventIdT my_event_id
;
1723 SaEvtSubscriptionIdT last_sub_id
= 0;
1725 printf(" multi_test_callback2 called(%d)\n", ++call_count
);
1727 evt_pat_get_array
.patternsNumber
= 4;
1729 result
= saEvtEventAttributesGet(event_handle
,
1730 &evt_pat_get_array
, /* patterns */
1731 &my_priority
, /* priority */
1732 &my_retention_time
, /* retention time */
1733 &my_publisher_name
, /* publisher name */
1734 &my_publish_time
, /* publish time */
1735 &my_event_id
/* event_id */
1737 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1738 if (result
!= SA_AIS_OK
) {
1739 get_sa_error(result
, result_buf
, result_buf_len
);
1740 printf("ERROR: event get attr result: %s\n", result_buf
);
1744 if (my_event_id
!= event_id1
) {
1745 printf("ERROR: Received wrong event\n");
1749 if (last_sub_id
== 0) {
1750 if (my_subscription_id
!= sub1
&&
1751 my_subscription_id
!= sub2
) {
1752 printf("ERROR: Received bad subscription ID\n");
1755 last_sub_id
= my_subscription_id
;
1757 if (my_subscription_id
== last_sub_id
) {
1758 printf("ERROR: Received subscription ID twice\n");
1761 if (my_subscription_id
!= sub1
&&
1762 my_subscription_id
!= sub2
) {
1763 printf("ERROR: Received bad subscription ID\n");
1768 if (evt_pat_get_array
.patternsNumber
!= 1) {
1769 printf("ERROR: pattern array count not 1: %llu\n",
1770 (unsigned long long)evt_pat_get_array
.patternsNumber
);
1775 result
= saEvtEventFree(event_handle
);
1776 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1777 if (result
!= SA_AIS_OK
) {
1778 get_sa_error(result
, result_buf
, result_buf_len
);
1779 printf("ERROR: event free result: %s\n", result_buf
);
1784 test_multi_channel2()
1787 SaEvtEventFilterT filt1
[1] = {
1788 {SA_EVT_EXACT_FILTER
, {8, 8, (SaUint8T
*) "ChanPat1"}},
1791 SaEvtEventFilterArrayT sub_filt
= {
1795 SaEvtEventPatternT pat1
= {8, 8, (SaUint8T
*) "ChanPat1"};
1797 SaEvtEventPatternArrayT evt_pat
= {
1802 SaEvtHandleT handle
;
1803 SaEvtChannelHandleT channel_handle
;
1804 SaEvtChannelHandleT channel_handle1
;
1805 SaEvtEventHandleT event_handle
;
1806 SaEvtChannelOpenFlagsT flags
;
1807 SaNameT channel_name
;
1808 SaEvtCallbacksT multi_callbacks
= {
1810 multi_test_callback2
1815 SaSelectionObjectT fd
;
1822 flags
= SA_EVT_CHANNEL_PUBLISHER
|SA_EVT_CHANNEL_SUBSCRIBER
|
1823 SA_EVT_CHANNEL_CREATE
;
1824 strcpy((char *)channel_name
.value
, channel
);
1825 channel_name
.length
= strlen(channel
);
1828 * 2. Test multiple openings of a single channel and receving events.
1830 * Open and subscribe to a channel twice. When an event is sent, it
1831 * should be delivered twice, once for each open channel.
1833 printf("Test multiple opens/subscribes:\n");
1836 result
= saEvtInitialize (&handle
, &multi_callbacks
,
1837 versions
[0].version
);
1838 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1839 if (result
!= SA_AIS_OK
) {
1840 get_sa_error(result
, result_buf
, result_buf_len
);
1841 printf("ERROR: Event Initialize result: %s\n", result_buf
);
1846 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
1848 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1849 if (result
!= SA_AIS_OK
) {
1850 get_sa_error(result
, result_buf
, result_buf_len
);
1851 printf("ERROR: channel open(0) result: %s\n", result_buf
);
1856 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
1858 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1859 if (result
!= SA_AIS_OK
) {
1860 get_sa_error(result
, result_buf
, result_buf_len
);
1861 printf("ERROR: channel open(1) result: %s\n", result_buf
);
1866 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
1867 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1868 if (result
!= SA_AIS_OK
) {
1869 get_sa_error(result
, result_buf
, result_buf_len
);
1870 printf("ERROR: event Allocate result: %s\n", result_buf
);
1873 sub_filt
.filters
= filt1
;
1875 result
= saEvtEventSubscribe(channel_handle
,
1878 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1879 if (result
!= SA_AIS_OK
) {
1880 get_sa_error(result
, result_buf
, result_buf_len
);
1881 printf("ERROR: event subscribe(0) result: %s\n", result_buf
);
1884 sub_filt
.filters
= filt1
;
1886 result
= saEvtEventSubscribe(channel_handle1
,
1889 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1890 if (result
!= SA_AIS_OK
) {
1891 get_sa_error(result
, result_buf
, result_buf_len
);
1892 printf("ERROR: event subscribe(1) result: %s\n", result_buf
);
1895 retention_time
= 0ULL;
1897 evt_pat
.patterns
= &pat1
;
1899 result
= saEvtEventAttributesSet(event_handle
,
1904 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1905 if (result
!= SA_AIS_OK
) {
1906 get_sa_error(result
, result_buf
, result_buf_len
);
1907 printf("ERROR: event set attr result: %s\n", result_buf
);
1912 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
1914 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1915 if (result
!= SA_AIS_OK
) {
1916 get_sa_error(result
, result_buf
, result_buf_len
);
1917 printf("ERROR: event Publish result: %s\n", result_buf
);
1921 * See if we got the event
1924 result
= saEvtSelectionObjectGet(handle
, &fd
);
1925 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1926 if (result
!= SA_AIS_OK
) {
1927 get_sa_error(result
, result_buf
, result_buf_len
);
1928 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
1937 pfd
.events
= POLLIN
;
1938 nfd
= poll(&pfd
, 1, timeout
);
1941 } else if (nfd
< 0) {
1942 perror("ERROR: poll error");
1948 result
= saEvtDispatch(handle
, SA_DISPATCH_ALL
);
1949 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1950 if (result
!= SA_AIS_OK
) {
1951 get_sa_error(result
, result_buf
, result_buf_len
);
1952 printf("ERROR: saEvtDispatch %s\n", result_buf
);
1959 if (call_count
!= 2) {
1960 printf("ERROR: call back count: e=2, a=%d\n", call_count
);
1969 result
= saEvtEventFree(event_handle
);
1970 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1971 if (result
!= SA_AIS_OK
) {
1972 get_sa_error(result
, result_buf
, result_buf_len
);
1973 printf("ERROR: event free result: %s\n", result_buf
);
1978 result
= saEvtChannelClose(channel_handle
);
1979 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1981 if (result
!= SA_AIS_OK
) {
1982 get_sa_error(result
, result_buf
, result_buf_len
);
1983 printf("ERROR: channel close result(0): %s\n", result_buf
);
1986 result
= saEvtChannelClose(channel_handle1
);
1987 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1989 if (result
!= SA_AIS_OK
) {
1990 get_sa_error(result
, result_buf
, result_buf_len
);
1991 printf("ERROR: channel close result(1): %s\n", result_buf
);
1995 result
= saEvtFinalize(handle
);
1996 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
1998 if (result
!= SA_AIS_OK
) {
1999 get_sa_error(result
, result_buf
, result_buf_len
);
2000 printf("ERROR: Event Finalize result: %s\n", result_buf
);
2007 * Handle call back for multi-test3
2008 * Verifies that the event recevied is associated with the correct
2013 multi_test_callback3(SaEvtSubscriptionIdT my_subscription_id
,
2014 const SaEvtEventHandleT event_handle
,
2015 const SaSizeT my_event_data_size
)
2018 SaUint8T my_priority
;
2019 SaTimeT my_retention_time
;
2020 SaNameT my_publisher_name
= {0, {0}};
2021 SaTimeT my_publish_time
;
2022 SaEvtEventIdT my_event_id
;
2024 printf(" multi_test_callback2 called(%d)\n", ++call_count
);
2026 evt_pat_get_array
.patternsNumber
= 4;
2028 result
= saEvtEventAttributesGet(event_handle
,
2029 &evt_pat_get_array
, /* patterns */
2030 &my_priority
, /* priority */
2031 &my_retention_time
, /* retention time */
2032 &my_publisher_name
, /* publisher name */
2033 &my_publish_time
, /* publish time */
2034 &my_event_id
/* event_id */
2036 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2037 if (result
!= SA_AIS_OK
) {
2038 get_sa_error(result
, result_buf
, result_buf_len
);
2039 printf("ERROR: event get attr result: %s\n", result_buf
);
2043 if ((my_subscription_id
!= sub1
) && (my_subscription_id
!= sub2
)) {
2044 printf("ERROR: Received wrong subscription ID %x\n",
2045 my_subscription_id
);
2046 printf(" sub1 %x, sub2 %x\n", sub1
, sub2
);
2050 if ((my_event_id
!= event_id1
) && (my_event_id
!= event_id2
)) {
2051 printf("ERROR: Received wrong event ID %llx\n",
2052 (unsigned long long)my_event_id
);
2053 printf(" id1 %llx, id2 %llx\n",
2054 (unsigned long long)event_id1
,
2055 (unsigned long long)event_id2
);
2059 if ((my_subscription_id
== sub1
) && (my_event_id
!= event_id1
)) {
2060 printf("ERROR: Received event on wrong subscription\n");
2063 if ((my_subscription_id
== sub2
) && (my_event_id
!= event_id2
)) {
2064 printf("ERROR: Received event on wrong subscription\n");
2068 if (evt_pat_get_array
.patternsNumber
!= 1) {
2069 printf("ERROR: pattern array count not 1: %llu\n",
2070 (unsigned long long)evt_pat_get_array
.patternsNumber
);
2075 result
= saEvtEventFree(event_handle
);
2076 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2077 if (result
!= SA_AIS_OK
) {
2078 get_sa_error(result
, result_buf
, result_buf_len
);
2079 printf("ERROR: event free result: %s\n", result_buf
);
2084 test_multi_channel3()
2087 SaEvtEventFilterT filt1
[1] = {
2088 {SA_EVT_PREFIX_FILTER
, {7, 7, (SaUint8T
*) "ChanPat"}},
2091 SaEvtEventFilterArrayT sub_filt
= {
2095 SaEvtEventPatternT pat1
= {8, 8, (SaUint8T
*) "ChanPat1"};
2096 SaEvtEventPatternT pat2
= {8, 8, (SaUint8T
*) "ChanPat2"};
2098 SaEvtEventPatternArrayT evt_pat
= {
2103 SaEvtHandleT handle
;
2104 SaEvtChannelHandleT channel_handle
;
2105 SaEvtChannelHandleT channel_handle1
;
2106 SaEvtEventHandleT event_handle
;
2107 SaEvtEventHandleT event_handle1
;
2108 SaEvtChannelOpenFlagsT flags
;
2109 SaNameT channel_name
;
2110 SaNameT channel_name1
;
2111 SaEvtCallbacksT multi_callbacks
= {
2113 multi_test_callback3
2118 SaSelectionObjectT fd
;
2125 flags
= SA_EVT_CHANNEL_PUBLISHER
|SA_EVT_CHANNEL_SUBSCRIBER
|
2126 SA_EVT_CHANNEL_CREATE
;
2127 strcpy((char *)channel_name
.value
, channel
);
2128 channel_name
.length
= strlen((char *)channel_name
.value
);
2129 strcpy((char *)channel_name1
.value
, channel
);
2130 strcat((char *)channel_name1
.value
, "_1");
2131 channel_name1
.length
= strlen((char *)channel_name1
.value
);
2135 * 3. Test opening of multiple channels and receiving events.
2136 * Open and subscribe to two different channels twice.
2137 * Subscribe to each channel with the same filters.
2138 * Sending an event on one channel should be received in the
2139 * call-back with the subscription ID corresponding to the sent
2142 printf("Test multiple different channels/subscribes:\n");
2145 result
= saEvtInitialize (&handle
, &multi_callbacks
,
2146 versions
[0].version
);
2147 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2148 if (result
!= SA_AIS_OK
) {
2149 get_sa_error(result
, result_buf
, result_buf_len
);
2150 printf("ERROR: Event Initialize result: %s\n", result_buf
);
2155 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
2157 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2158 if (result
!= SA_AIS_OK
) {
2159 get_sa_error(result
, result_buf
, result_buf_len
);
2160 printf("ERROR: channel open(0) result: %s\n", result_buf
);
2165 result
= saEvtChannelOpen(handle
, &channel_name1
, flags
, SA_TIME_MAX
,
2167 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2168 if (result
!= SA_AIS_OK
) {
2169 get_sa_error(result
, result_buf
, result_buf_len
);
2170 printf("ERROR: channel open(1) result: %s\n", result_buf
);
2175 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
2176 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2177 if (result
!= SA_AIS_OK
) {
2178 get_sa_error(result
, result_buf
, result_buf_len
);
2179 printf("ERROR: event Allocate(0) result: %s\n", result_buf
);
2183 result
= saEvtEventAllocate(channel_handle1
, &event_handle1
);
2184 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2185 if (result
!= SA_AIS_OK
) {
2186 get_sa_error(result
, result_buf
, result_buf_len
);
2187 printf("ERROR: event Allocate(1) result: %s\n", result_buf
);
2191 sub_filt
.filters
= filt1
;
2193 result
= saEvtEventSubscribe(channel_handle
,
2196 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2197 if (result
!= SA_AIS_OK
) {
2198 get_sa_error(result
, result_buf
, result_buf_len
);
2199 printf("ERROR: event subscribe(0) result: %s\n", result_buf
);
2202 sub_filt
.filters
= filt1
;
2204 result
= saEvtEventSubscribe(channel_handle1
,
2207 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2208 if (result
!= SA_AIS_OK
) {
2209 get_sa_error(result
, result_buf
, result_buf_len
);
2210 printf("ERROR: event subscribe(1) result: %s\n", result_buf
);
2213 retention_time
= 0ULL;
2215 evt_pat
.patterns
= &pat1
;
2217 result
= saEvtEventAttributesSet(event_handle
,
2222 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2223 if (result
!= SA_AIS_OK
) {
2224 get_sa_error(result
, result_buf
, result_buf_len
);
2225 printf("ERROR: event set attr(0) result: %s\n", result_buf
);
2229 evt_pat
.patterns
= &pat2
;
2231 result
= saEvtEventAttributesSet(event_handle1
,
2236 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2237 if (result
!= SA_AIS_OK
) {
2238 get_sa_error(result
, result_buf
, result_buf_len
);
2239 printf("ERROR: event set attr(1) result: %s\n", result_buf
);
2244 result
= saEvtEventPublish(event_handle
, exp_data
, DATA_SIZE
,
2246 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2247 if (result
!= SA_AIS_OK
) {
2248 get_sa_error(result
, result_buf
, result_buf_len
);
2249 printf("ERROR: event Publish result: %s\n", result_buf
);
2253 result
= saEvtEventPublish(event_handle1
, exp_data
, DATA_SIZE
,
2255 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2256 if (result
!= SA_AIS_OK
) {
2257 get_sa_error(result
, result_buf
, result_buf_len
);
2258 printf("ERROR: event Publish result: %s\n", result_buf
);
2262 * See if we got the events
2265 result
= saEvtSelectionObjectGet(handle
, &fd
);
2266 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2267 if (result
!= SA_AIS_OK
) {
2268 get_sa_error(result
, result_buf
, result_buf_len
);
2269 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
2278 pfd
.events
= POLLIN
;
2279 nfd
= poll(&pfd
, 1, timeout
);
2282 } else if (nfd
< 0) {
2283 perror("ERROR: poll error");
2289 result
= saEvtDispatch(handle
, SA_DISPATCH_ALL
);
2290 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2291 if (result
!= SA_AIS_OK
) {
2292 get_sa_error(result
, result_buf
, result_buf_len
);
2293 printf("ERROR: saEvtDispatch %s\n", result_buf
);
2300 if (call_count
!= 2) {
2301 printf("ERROR: call back count: e=2, a=%d\n", call_count
);
2310 result
= saEvtEventFree(event_handle
);
2311 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2312 if (result
!= SA_AIS_OK
) {
2313 get_sa_error(result
, result_buf
, result_buf_len
);
2314 printf("ERROR: event free result: %s\n", result_buf
);
2317 result
= saEvtEventFree(event_handle1
);
2318 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2319 if (result
!= SA_AIS_OK
) {
2320 get_sa_error(result
, result_buf
, result_buf_len
);
2321 printf("ERROR: event free result: %s\n", result_buf
);
2326 result
= saEvtChannelClose(channel_handle
);
2327 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2329 if (result
!= SA_AIS_OK
) {
2330 get_sa_error(result
, result_buf
, result_buf_len
);
2331 printf("ERROR: channel close result(0): %s\n", result_buf
);
2334 result
= saEvtChannelClose(channel_handle1
);
2335 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2337 if (result
!= SA_AIS_OK
) {
2338 get_sa_error(result
, result_buf
, result_buf_len
);
2339 printf("ERROR: channel close result(1): %s\n", result_buf
);
2343 result
= saEvtFinalize(handle
);
2344 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2346 if (result
!= SA_AIS_OK
) {
2347 get_sa_error(result
, result_buf
, result_buf_len
);
2348 printf("ERROR: Event Finalize result: %s\n", result_buf
);
2355 * Test event retention
2356 * Test 1: publish the event with a retention time and then
2357 * subscribe. If the event was retained, we should receive it.
2359 * Test 2: Publish the event, sleep until it expires, then
2360 * subscribe. We shouldn't get an event delivered.
2362 * Test 3: Publish an event with a retention time.
2367 * Then subscribe and make sure that the messages isn't delivered.
2370 #define EXPIRE_TIME 10 /* Seconds */
2371 SaEvtEventIdT retained_id
;
2375 event_callback_retained(SaEvtSubscriptionIdT my_subscription_id
,
2376 const SaEvtEventHandleT event_handle
,
2377 const SaSizeT my_event_data_size
)
2380 //printf("event_callback_retained called\n");
2382 result
= saEvtEventAttributesGet(event_handle
,
2385 0, /* retention time */
2386 0, /* publisher name */
2387 0, /* publish time */
2388 &retained_id
/* event_id */
2390 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2391 if (result
!= SA_AIS_OK
) {
2392 get_sa_error(result
, result_buf
, result_buf_len
);
2393 printf("ERROR: callback attr get result: %s\n", result_buf
);
2402 SaEvtHandleT handle
;
2403 SaEvtChannelHandleT channel_handle
;
2404 SaEvtEventHandleT event_handle
;
2405 SaEvtChannelOpenFlagsT flags
;
2406 SaNameT channel_name
;
2407 SaEvtCallbacksT callbacks_retain
= {
2409 event_callback_retained
2414 SaSelectionObjectT fd
;
2415 int timeout
= (EXPIRE_TIME
+ 5);
2418 flags
= SA_EVT_CHANNEL_PUBLISHER
|
2419 SA_EVT_CHANNEL_SUBSCRIBER
|
2420 SA_EVT_CHANNEL_CREATE
;
2421 strcpy((char *)channel_name
.value
, channel
);
2422 channel_name
.length
= strlen(channel
);
2424 printf("Test Event retention:\n");
2427 result
= saEvtInitialize (&handle
, &callbacks_retain
,
2428 versions
[0].version
);
2429 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2430 if (result
!= SA_AIS_OK
) {
2431 get_sa_error(result
, result_buf
, result_buf_len
);
2432 printf("ERROR: Event Initialize result: %s\n", result_buf
);
2437 result
= saEvtSelectionObjectGet(handle
, &fd
);
2438 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2439 if (result
!= SA_AIS_OK
) {
2440 get_sa_error(result
, result_buf
, result_buf_len
);
2441 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
2447 result
= saEvtChannelOpen(handle
, &channel_name
, flags
, SA_TIME_MAX
,
2449 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2450 if (result
!= SA_AIS_OK
) {
2451 get_sa_error(result
, result_buf
, result_buf_len
);
2452 printf("ERROR: channel open result: %s\n", result_buf
);
2460 result
= saEvtEventAllocate(channel_handle
, &event_handle
);
2461 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2462 if (result
!= SA_AIS_OK
) {
2463 get_sa_error(result
, result_buf
, result_buf_len
);
2464 printf("ERROR: event Allocate result: %s\n", result_buf
);
2469 retention_time
= (EXPIRE_TIME
)*1000000000ULL;
2471 result
= saEvtEventAttributesSet(event_handle
,
2476 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2477 if (result
!= SA_AIS_OK
) {
2478 get_sa_error(result
, result_buf
, result_buf_len
);
2479 printf("ERROR: event set attr result: %s\n", result_buf
);
2484 * Test 1: publish the event with a retention time and then
2485 * subscribe. If the event was retained, we should receive it.
2487 printf(" Receive retained event\n");
2491 result
= saEvtEventPublish(event_handle
, exp_data
, 0, &event_id
);
2492 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2493 if (result
!= SA_AIS_OK
) {
2494 get_sa_error(result
, result_buf
, result_buf_len
);
2495 printf("ERROR: event Publish result(1): %s\n", result_buf
);
2501 result
= saEvtEventSubscribe(channel_handle
,
2504 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2506 if (result
!= SA_AIS_OK
) {
2507 get_sa_error(result
, result_buf
, result_buf_len
);
2508 printf("ERROR: event subscribe result: %s\n", result_buf
);
2513 pfd
.events
= POLLIN
;
2514 nfd
= poll(&pfd
, 1, 1000);
2516 printf("ERROR: poll fds %d\n", nfd
);
2518 perror("ERROR: poll error");
2525 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
2526 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2527 if (result
!= SA_AIS_OK
) {
2528 get_sa_error(result
, result_buf
, result_buf_len
);
2529 printf("ERROR: saEvtDispatch %s\n", result_buf
);
2535 printf("ERROR: retained event not recevied\n");
2538 if (retained_id
!= event_id
) {
2539 printf("ERROR: received the wrong event: e=%llx, a=%llx\n",
2540 (unsigned long long)event_id
,
2541 (unsigned long long)retained_id
);
2546 result
= saEvtEventUnsubscribe(channel_handle
, subscription_id
);
2547 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2548 if (result
!= SA_AIS_OK
) {
2549 get_sa_error(result
, result_buf
, result_buf_len
);
2550 printf("ERROR: unsubscribe result: %s\n", result_buf
);
2555 * Test 2: Publish the event, sleep until it expires, then
2556 * subscribe. We shouldn't get an event delivered.
2558 printf(" Expire retained event\n");
2562 result
= saEvtEventPublish(event_handle
, exp_data
, 0, &event_id
);
2563 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2564 if (result
!= SA_AIS_OK
) {
2565 get_sa_error(result
, result_buf
, result_buf_len
);
2566 printf("ERROR: event Publish result(1): %s\n", result_buf
);
2571 result
= saEvtSelectionObjectGet(handle
, &fd
);
2572 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2573 if (result
!= SA_AIS_OK
) {
2574 get_sa_error(result
, result_buf
, result_buf_len
);
2575 printf("ERROR: saEvtSelectionObject get %s\n", result_buf
);
2581 * Wait for the event to expire, then subscribe. We shouldn't get
2587 result
= saEvtEventSubscribe(channel_handle
,
2590 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2592 if (result
!= SA_AIS_OK
) {
2593 get_sa_error(result
, result_buf
, result_buf_len
);
2594 printf("ERROR: event subscribe result: %s\n", result_buf
);
2595 result
= saEvtChannelClose(channel_handle
);
2600 pfd
.events
= POLLIN
;
2601 nfd
= poll(&pfd
, 1, 1000);
2603 printf("ERROR: poll fds %d\n", nfd
);
2605 perror("ERROR: poll error");
2612 result
= saEvtEventUnsubscribe(channel_handle
, subscription_id
);
2613 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2614 if (result
!= SA_AIS_OK
) {
2615 get_sa_error(result
, result_buf
, result_buf_len
);
2616 printf("ERROR: unsubscribe result: %s\n", result_buf
);
2622 * Publish an event with a retention time.
2627 * Then subscribe and make sure that the message isn't delivered.
2629 printf(" Clear event retention time\n");
2633 result
= saEvtEventPublish(event_handle
, exp_data
, 0, &event_id
);
2634 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2635 if (result
!= SA_AIS_OK
) {
2636 get_sa_error(result
, result_buf
, result_buf_len
);
2637 printf("ERROR: event Publish result(2): %s\n", result_buf
);
2642 result
= saEvtEventSubscribe(channel_handle
,
2645 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2646 if (result
!= SA_AIS_OK
) {
2647 get_sa_error(result
, result_buf
, result_buf_len
);
2648 printf("ERROR: event subscribe result: %s\n", result_buf
);
2653 pfd
.events
= POLLIN
;
2654 nfd
= poll(&pfd
, 1, 1000);
2656 printf("ERROR: poll fds %d\n", nfd
);
2658 perror("ERROR: poll error");
2665 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
2666 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2667 if (result
!= SA_AIS_OK
) {
2668 get_sa_error(result
, result_buf
, result_buf_len
);
2669 printf("ERROR: saEvtDispatch %s\n", result_buf
);
2675 printf("ERROR: retained event not recevied\n");
2678 if (retained_id
!= event_id
) {
2679 printf("ERROR: received the wrong event: e=%llx, a=%llx\n",
2680 (unsigned long long)event_id
,
2681 (unsigned long long)retained_id
);
2686 result
= saEvtEventUnsubscribe(channel_handle
, subscription_id
);
2687 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2688 if (result
!= SA_AIS_OK
) {
2689 get_sa_error(result
, result_buf
, result_buf_len
);
2690 printf("ERROR: unsubscribe result: %s\n", result_buf
);
2695 result
= saEvtEventRetentionTimeClear(channel_handle
, event_id
);
2696 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2697 if (result
!= SA_AIS_OK
) {
2698 get_sa_error(result
, result_buf
, result_buf_len
);
2699 printf("ERROR: clear retention time result: %s\n", result_buf
);
2704 result
= saEvtEventSubscribe(channel_handle
,
2707 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2708 if (result
!= SA_AIS_OK
) {
2709 get_sa_error(result
, result_buf
, result_buf_len
);
2710 printf("ERROR: event subscribe result: %s\n", result_buf
);
2715 pfd
.events
= POLLIN
;
2716 nfd
= poll(&pfd
, 1, 1000);
2718 printf("ERROR: poll fds %d\n", nfd
);
2720 perror("ERROR: poll error");
2731 result
= saEvtEventFree(event_handle
);
2732 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2733 if (result
!= SA_AIS_OK
) {
2734 get_sa_error(result
, result_buf
, result_buf_len
);
2735 printf("ERROR: event free result: %s\n", result_buf
);
2740 result
= saEvtChannelClose(channel_handle
);
2741 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2743 if (result
!= SA_AIS_OK
) {
2744 get_sa_error(result
, result_buf
, result_buf_len
);
2745 printf("ERROR: channel close result: %s\n", result_buf
);
2749 result
= saEvtFinalize(handle
);
2750 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2752 if (result
!= SA_AIS_OK
) {
2753 get_sa_error(result
, result_buf
, result_buf_len
);
2754 printf("ERROR: Event Finalize result: %s\n", result_buf
);
2761 unlink_chan_callback(SaEvtSubscriptionIdT my_subscription_id
,
2762 const SaEvtEventHandleT event_handle
,
2763 const SaSizeT my_event_data_size
)
2766 SaUint8T my_priority
;
2767 SaTimeT my_retention_time
;
2768 SaNameT my_publisher_name
= {0, {0}};
2769 SaTimeT my_publish_time
;
2770 SaEvtEventIdT my_event_id
;
2771 SaEvtSubscriptionIdT exp_sub_id
;
2773 printf(" unlink_chan_callback called(%d)\n", ++call_count
);
2775 evt_pat_get_array
.patternsNumber
= 4;
2777 result
= saEvtEventAttributesGet(event_handle
,
2778 &evt_pat_get_array
, /* patterns */
2779 &my_priority
, /* priority */
2780 &my_retention_time
, /* retention time */
2781 &my_publisher_name
, /* publisher name */
2782 &my_publish_time
, /* publish time */
2783 &my_event_id
/* event_id */
2785 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2786 if (result
!= SA_AIS_OK
) {
2787 get_sa_error(result
, result_buf
, result_buf_len
);
2788 printf("ERROR: event get attr result: %s\n", result_buf
);
2792 if (my_event_id
== event_id1
) {
2794 } else if (my_event_id
== event_id2
) {
2797 printf("ERROR: Received event %llx but not sent\n",
2798 (unsigned long long)my_event_id
);
2802 if (my_subscription_id
!= exp_sub_id
) {
2803 printf("ERROR: sub ID: e=%x, a=%x\n",
2804 exp_sub_id
, my_subscription_id
);
2810 result
= saEvtEventFree(event_handle
);
2811 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2812 if (result
!= SA_AIS_OK
) {
2813 get_sa_error(result
, result_buf
, result_buf_len
);
2814 printf("ERROR: event free result: %s\n", result_buf
);
2819 * Test channel unlink operations.
2820 * 1. Unlink channel.
2821 * 2. Open/create a channel, close channel, open channel.
2822 * 3. unlink channel, Open channel.
2823 * 4. Open/create, unlink channel, close channel, open channel.
2824 * 5. Open/create a channel, unlink channel, open/create channel, send
2826 * 6. unlink all, close all.
2828 SaEvtCallbacksT unlink_callbacks
= {
2830 unlink_chan_callback
2833 test_unlink_channel()
2835 SaEvtHandleT handle
;
2836 SaEvtChannelHandleT channel_handle1
;
2837 SaEvtChannelHandleT channel_handle2
;
2838 SaEvtEventHandleT event_handle1
;
2839 SaEvtEventHandleT event_handle2
;
2840 SaEvtChannelOpenFlagsT flags1
, flags2
;
2841 SaNameT channel_name
;
2846 SaSelectionObjectT fd
;
2849 flags1
= SA_EVT_CHANNEL_PUBLISHER
|
2850 SA_EVT_CHANNEL_SUBSCRIBER
|
2851 SA_EVT_CHANNEL_CREATE
;
2853 flags2
= SA_EVT_CHANNEL_PUBLISHER
|
2854 SA_EVT_CHANNEL_SUBSCRIBER
;
2857 printf("Test Channel Unlink operations:\n");
2860 result
= saEvtInitialize (&handle
, &unlink_callbacks
,
2861 versions
[0].version
);
2862 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2864 if (result
!= SA_AIS_OK
) {
2865 get_sa_error(result
, result_buf
, result_buf_len
);
2866 printf("ERROR: Event Initialize result: %s\n", result_buf
);
2871 * 1. Unlink channel.
2873 * Unlink previously opened channel should return OK.
2874 * Unlink of non-existent channel should return error.
2876 printf(" 1 Channel unlink:\n");
2878 strcpy((char *)channel_name
.value
, channel
);
2879 channel_name
.length
= strlen(channel
);
2881 result
= saEvtChannelUnlink(handle
, &channel_name
);
2882 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2883 if (result
!= SA_AIS_OK
) {
2884 get_sa_error(result
, result_buf
, result_buf_len
);
2885 printf("ERROR: channel unlink(1) result: %s\n", result_buf
);
2889 strcpy((char *)channel_name
.value
, unlink_channel
);
2890 channel_name
.length
= strlen(unlink_channel
);
2892 result
= saEvtChannelUnlink(handle
, &channel_name
);
2893 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2894 if (result
!= SA_AIS_ERR_NOT_EXIST
) {
2895 get_sa_error(result
, result_buf
, result_buf_len
);
2896 printf("ERROR: channel unlink(2) result: %s\n", result_buf
);
2901 * 2. Open/create a channel, close channel, open channel.
2903 * Open/create the channel.
2904 * Close the channel.
2905 * Open without create. This should succeed in the B spec.
2907 printf(" 2 Channel open/close/open:\n");
2910 result
= saEvtChannelOpen(handle
, &channel_name
, flags1
, SA_TIME_MAX
,
2912 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2915 if (result
!= SA_AIS_OK
) {
2916 get_sa_error(result
, result_buf
, result_buf_len
);
2917 printf("ERROR: channel open(1) result: %s\n", result_buf
);
2922 result
= saEvtChannelClose(channel_handle1
);
2923 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2925 if (result
!= SA_AIS_OK
) {
2926 get_sa_error(result
, result_buf
, result_buf_len
);
2927 printf("ERROR: channel close(1) result: %s\n", result_buf
);
2932 result
= saEvtChannelOpen(handle
, &channel_name
, flags2
, SA_TIME_MAX
,
2934 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2935 if (result
!= SA_AIS_OK
) {
2936 get_sa_error(result
, result_buf
, result_buf_len
);
2937 printf("ERROR: channel open(2) result: %s\n", result_buf
);
2942 * 3. unlink channel, Open channel, close channel
2944 * Unlink the channel. Should mark for deletion but not
2945 * delete it since it is already open.
2946 * Open the channel without create. This should fail since
2947 * the channel is marked for deletion and a new version
2948 * hasn't been created.
2951 printf(" 3 Channel unlink/open/close:\n");
2954 result
= saEvtChannelUnlink(handle
, &channel_name
);
2955 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2956 if (result
!= SA_AIS_OK
) {
2957 get_sa_error(result
, result_buf
, result_buf_len
);
2958 printf("ERROR: channel unlink result: %s\n", result_buf
);
2963 result
= saEvtChannelOpen(handle
, &channel_name
, flags2
, SA_TIME_MAX
,
2965 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2966 if (result
!= SA_AIS_ERR_NOT_EXIST
) {
2967 get_sa_error(result
, result_buf
, result_buf_len
);
2968 printf("ERROR: channel open result: %s\n", result_buf
);
2972 result
= saEvtChannelClose(channel_handle1
);
2973 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2974 if (result
!= SA_AIS_OK
) {
2975 get_sa_error(result
, result_buf
, result_buf_len
);
2976 printf("ERROR: channel close(1) result: %s\n", result_buf
);
2982 * 4. Open/create, unlink channel, close channel, open channel.
2984 * Open/create the channel.
2985 * unlink the channel.
2986 * close the channel. This should delete the channel instance since
2987 * it was marked for deletion.
2988 * open the channel without create. This should fail since the
2989 * channel doesn't exist anymore.
2991 printf(" 4 Channel open/unlink/close/open:\n");
2993 result
= saEvtChannelOpen(handle
, &channel_name
, flags1
, SA_TIME_MAX
,
2995 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
2996 if (result
!= SA_AIS_OK
) {
2997 get_sa_error(result
, result_buf
, result_buf_len
);
2998 printf("ERROR: channel open(1) result: %s\n", result_buf
);
3003 result
= saEvtChannelUnlink(handle
, &channel_name
);
3004 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3005 if (result
!= SA_AIS_OK
) {
3006 get_sa_error(result
, result_buf
, result_buf_len
);
3007 printf("ERROR: channel unlink result: %s\n", result_buf
);
3012 result
= saEvtChannelClose(channel_handle1
);
3013 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3014 if (result
!= SA_AIS_OK
) {
3015 get_sa_error(result
, result_buf
, result_buf_len
);
3016 printf("ERROR: channel close(1) result: %s\n", result_buf
);
3021 result
= saEvtChannelOpen(handle
, &channel_name
, flags2
, SA_TIME_MAX
,
3023 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3024 if (result
!= SA_AIS_ERR_NOT_EXIST
) {
3025 get_sa_error(result
, result_buf
, result_buf_len
);
3026 printf("ERROR: channel open(2) result: %s\n", result_buf
);
3031 * 5. Open/create a channel, unlink channel, open/create channel, send
3035 * unlink. Mark for deletion.
3036 * open/create. Create new channel of same name.
3037 * send event on each open channel. The events should be received on
3038 * separate channels.
3040 printf(" 5 Channel open/unlink/open/send:\n");
3043 result
= saEvtChannelOpen(handle
, &channel_name
, flags1
, SA_TIME_MAX
,
3045 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3046 if (result
!= SA_AIS_OK
) {
3047 get_sa_error(result
, result_buf
, result_buf_len
);
3048 printf("ERROR: channel open result: %s\n", result_buf
);
3053 result
= saEvtChannelUnlink(handle
, &channel_name
);
3054 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3055 if (result
!= SA_AIS_OK
) {
3056 get_sa_error(result
, result_buf
, result_buf_len
);
3057 printf("ERROR: channel unlink result: %s\n", result_buf
);
3062 result
= saEvtChannelOpen(handle
, &channel_name
, flags1
, SA_TIME_MAX
,
3064 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3065 if (result
!= SA_AIS_OK
) {
3066 get_sa_error(result
, result_buf
, result_buf_len
);
3067 printf("ERROR: channel open result: %s\n", result_buf
);
3072 result
= saEvtEventSubscribe(channel_handle1
,
3075 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3076 if (result
!= SA_AIS_OK
) {
3077 get_sa_error(result
, result_buf
, result_buf_len
);
3078 printf("ERROR: channel subscribe(1) result: %s\n", result_buf
);
3083 result
= saEvtEventSubscribe(channel_handle2
,
3086 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3087 if (result
!= SA_AIS_OK
) {
3088 get_sa_error(result
, result_buf
, result_buf_len
);
3089 printf("ERROR: channel subscribe(2) result: %s\n", result_buf
);
3093 retention_time
= 0ULL;
3095 result
= saEvtEventAllocate(channel_handle1
, &event_handle1
);
3096 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3097 if (result
!= SA_AIS_OK
) {
3098 get_sa_error(result
, result_buf
, result_buf_len
);
3099 printf("ERROR: event allocate(1) result: %s\n", result_buf
);
3103 result
= saEvtEventAttributesSet(event_handle1
,
3108 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3109 if (result
!= SA_AIS_OK
) {
3110 get_sa_error(result
, result_buf
, result_buf_len
);
3111 printf("ERROR: event set(1) result: %s\n", result_buf
);
3116 result
= saEvtEventAllocate(channel_handle2
, &event_handle2
);
3117 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3118 if (result
!= SA_AIS_OK
) {
3119 get_sa_error(result
, result_buf
, result_buf_len
);
3120 printf("ERROR: event allocate(2) result: %s\n", result_buf
);
3124 result
= saEvtEventAttributesSet(event_handle2
,
3129 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3130 if (result
!= SA_AIS_OK
) {
3131 get_sa_error(result
, result_buf
, result_buf_len
);
3132 printf("ERROR: event set(2) result: %s\n", result_buf
);
3137 result
= saEvtEventPublish(event_handle1
, 0, 0, &event_id1
);
3138 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3139 if (result
!= SA_AIS_OK
) {
3140 get_sa_error(result
, result_buf
, result_buf_len
);
3141 printf("ERROR: event publish(1) result: %s\n", result_buf
);
3145 result
= saEvtEventPublish(event_handle2
, 0, 0, &event_id2
);
3146 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3147 if (result
!= SA_AIS_OK
) {
3148 get_sa_error(result
, result_buf
, result_buf_len
);
3149 printf("ERROR: event publish(2) result: %s\n", result_buf
);
3155 result
= saEvtSelectionObjectGet(handle
, &fd
);
3156 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3157 if (result
!= SA_AIS_OK
) {
3158 get_sa_error(result
, result_buf
, result_buf_len
);
3159 printf("ERROR: select object get result: %s\n", result_buf
);
3164 * We should see a total of two events processed, not four
3165 * as if both events were recevied on both channels.
3170 pfd
.events
= POLLIN
;
3171 nfd
= poll(&pfd
, 1, timeout
);
3174 perror("ERROR: poll error");
3180 result
= saEvtDispatch(handle
, SA_DISPATCH_ONE
);
3181 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3182 if (result
!= SA_AIS_OK
) {
3183 get_sa_error(result
, result_buf
, result_buf_len
);
3184 printf("ERROR: saEvtDispatch %s\n", result_buf
);
3190 if (call_count
!= 2) {
3191 printf("ERROR: processed %d events\n", call_count
);
3197 * 6. unlink all, close all.
3199 * close all open channels.
3200 * unlink the channel.
3201 * open without create the channel. Verify that the channel no
3204 printf(" 6 Channel unlink all/close all/open:\n");
3207 saEvtChannelClose(channel_handle1
);
3208 saEvtChannelClose(channel_handle2
);
3209 saEvtChannelUnlink(handle
, &channel_name
);
3211 result
= saEvtFinalize(handle
);
3212 } while ((result
== SA_AIS_ERR_TRY_AGAIN
) && !sleep(TRY_WAIT
));
3213 if (result
!= SA_AIS_OK
) {
3214 get_sa_error(result
, result_buf
, result_buf_len
);
3215 printf("ERROR: Event Finalize result: %s\n", result_buf
);
3226 test_multi_channel1();
3227 test_multi_channel2();
3228 test_multi_channel3();
3230 test_unlink_channel();
3236 * vi: set autoindent tabstop=4 shiftwidth=4 :