testevt.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /*
  2. * Test program for event service
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/poll.h>
  8. #include <malloc.h>
  9. #include "ais_types.h"
  10. #include "ais_evt.h"
  11. void testresult (SaErrorT result, SaErrorT expected, int test_no)
  12. {
  13. if (result == expected) {
  14. printf ("Test %d passed\n", test_no);
  15. } else {
  16. printf ("ERROR: Test %d FAILED (expected %d got %d)\n", test_no, expected, result);
  17. }
  18. }
  19. SaVersionT version1 = { 'A', 0x01, 0x01 };
  20. SaVersionT version2 = { 'a', 0x01, 0x01 };
  21. SaVersionT version3 = { 'b', 0x01, 0x01 };
  22. SaVersionT version4 = { 'a', 0x02, 0x01 };
  23. SaVersionT version5 = { 'a', 0xff, 0x01 };
  24. SaVersionT version6 = { 'a', 0x01, 0xff };
  25. SaVersionT version7 = { 'A', 0xff, 0xff };
  26. SaVersionT version8 = { 'B', 0xff, 0xff };
  27. struct version_test {
  28. SaVersionT *version;
  29. SaErrorT result;
  30. };
  31. struct version_test versions[] = {
  32. { &version1, SA_OK },
  33. { &version2, SA_OK },
  34. { &version3, SA_ERR_VERSION },
  35. { &version4, SA_ERR_VERSION},
  36. // { &version5, SA_OK },
  37. //{ &version6, SA_OK },
  38. //{ &version7, SA_OK },
  39. { &version8, SA_ERR_VERSION},
  40. { 0, SA_ERR_VERSION}
  41. };
  42. int version_size = sizeof(versions) / sizeof(struct version_test);
  43. void event_callback( SaEvtSubscriptionIdT subscriptionId,
  44. const SaEvtEventHandleT eventHandle,
  45. const SaSizeT eventDataSize);
  46. SaEvtCallbacksT callbacks = {
  47. 0,
  48. event_callback
  49. };
  50. char channel[256] = "TESTEVT_CHANNEL";
  51. SaEvtSubscriptionIdT subscription_id = 0xabcdef;
  52. unsigned long long test_ret_time = 30000000000ULL; /* 30 seconds */
  53. /*
  54. * event data
  55. */
  56. long *exp_data;
  57. #define DATA_SIZE 2048 /* default data size */
  58. #define LCOUNT DATA_SIZE/sizeof(long)
  59. void test_initialize (void) {
  60. int result;
  61. SaEvtHandleT handle;
  62. int i;
  63. /*
  64. * version check tests
  65. */
  66. printf("Test lib version check on initlialize\n");
  67. for (i=0; i < version_size; i++) {
  68. result = saEvtInitialize (&handle, 0, versions[i].version);
  69. testresult (result, versions[i].result, i);
  70. if (result == SA_OK) {
  71. saEvtFinalize(handle);
  72. }
  73. }
  74. }
  75. #define patt1 "Filter pattern 1"
  76. #define patt1_size sizeof(patt1)
  77. #define patt2 "Filter pattern 2"
  78. #define patt2_size sizeof(patt2)
  79. #define patt3 "Filter pattern 3"
  80. #define patt3_size sizeof(patt3)
  81. #define patt4 "Filter pattern 4"
  82. #define patt4_size sizeof(patt4)
  83. SaEvtEventFilterT filters[] = {
  84. {SA_EVT_PREFIX_FILTER, {patt1, patt1_size}},
  85. {SA_EVT_SUFFIX_FILTER, {patt2, patt2_size}},
  86. {SA_EVT_EXACT_FILTER, {patt3, patt3_size}},
  87. {SA_EVT_PASS_ALL_FILTER, {patt4, patt4_size}}
  88. };
  89. SaEvtEventFilterArrayT subscribe_filters = {
  90. filters,
  91. sizeof(filters)/sizeof(SaEvtEventFilterT)
  92. };
  93. void
  94. test_channel()
  95. {
  96. SaEvtHandleT handle;
  97. SaEvtChannelHandleT channel_handle;
  98. SaEvtChannelOpenFlagsT flags;
  99. SaNameT channel_name;
  100. int result;
  101. flags = SA_EVT_CHANNEL_PUBLISHER |
  102. SA_EVT_CHANNEL_SUBSCRIBER |
  103. SA_EVT_CHANNEL_CREATE;
  104. strcpy(channel_name.value, channel);
  105. channel_name.length = strlen(channel);
  106. /*
  107. * Channel open/close test
  108. */
  109. printf("Test Channel operations:\n");
  110. printf("Channel open:\n");
  111. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  112. if (result != SA_OK) {
  113. printf("ERROR: Event Initialize result: %d\n", result);
  114. return;
  115. }
  116. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  117. &channel_handle);
  118. if (result != SA_OK) {
  119. printf("ERROR: channel open result: %d\n", result);
  120. result = saEvtFinalize(handle);
  121. if (result != SA_OK)
  122. printf("ERROR: Event Finalize result: %d\n", result);
  123. return;
  124. }
  125. printf("Channel close:\n");
  126. result = saEvtChannelClose(channel_handle);
  127. if (result != SA_OK) {
  128. printf("ERROR: channel close result: %d\n", result);
  129. return;
  130. }
  131. result = saEvtFinalize(handle);
  132. if (result != SA_OK) {
  133. printf("ERROR: Event Finalize result: %d\n", result);
  134. return;
  135. }
  136. /*
  137. * Test channel subscribe
  138. */
  139. printf("Channel subscribe:\n");
  140. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  141. if (result != SA_OK) {
  142. printf("ERROR: Event Initialize result: %d\n", result);
  143. return;
  144. }
  145. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  146. &channel_handle);
  147. if (result != SA_OK) {
  148. printf("ERROR: channel open result: %d\n", result);
  149. result = saEvtFinalize(handle);
  150. if (result != SA_OK)
  151. printf("ERROR: Finalize result: %d\n", result);
  152. return;
  153. }
  154. result = saEvtEventSubscribe(channel_handle,
  155. &subscribe_filters,
  156. subscription_id);
  157. if (result != SA_OK) {
  158. printf("ERROR: event subscribe result: %d\n", result);
  159. result = saEvtChannelClose(channel_handle);
  160. if (result != SA_OK)
  161. printf("ERROR: Channel close result: %d\n", result);
  162. result = saEvtFinalize(handle);
  163. if (result != SA_OK)
  164. printf("ERROR: Finalize result: %d\n", result);
  165. return;
  166. }
  167. printf("Channel unsubscribe:\n");
  168. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  169. if (result != SA_OK) {
  170. printf("ERROR: event unsubscribe result: %d\n", result);
  171. result = saEvtChannelClose(channel_handle);
  172. if (result != SA_OK)
  173. printf("ERROR: Channel close result: %d\n", result);
  174. result = saEvtFinalize(handle);
  175. if (result != SA_OK)
  176. printf("ERROR: Finalize result: %d\n", result);
  177. return;
  178. }
  179. result = saEvtChannelClose(channel_handle);
  180. if (result != SA_OK)
  181. printf("ERROR: Channel close result: %d\n", result);
  182. result = saEvtFinalize(handle);
  183. if (result != SA_OK)
  184. printf("ERROR: Finalize result: %d\n", result);
  185. /*
  186. * Test channel subscribe with no close
  187. */
  188. printf("Channel subscribe with no close at end:\n");
  189. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  190. if (result != SA_OK) {
  191. printf("ERROR: Event Initialize result: %d\n", result);
  192. return;
  193. }
  194. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  195. &channel_handle);
  196. if (result != SA_OK) {
  197. printf("ERROR: channel open result: %d\n", result);
  198. result = saEvtFinalize(handle);
  199. return;
  200. }
  201. result = saEvtEventSubscribe(channel_handle,
  202. &subscribe_filters,
  203. subscription_id);
  204. if (result != SA_OK) {
  205. printf("ERROR: event subscribe result: %d\n", result);
  206. result = saEvtChannelClose(channel_handle);
  207. }
  208. result = saEvtFinalize(handle);
  209. if (result != SA_OK) {
  210. printf("ERROR: Finalize failed\n");
  211. return;
  212. }
  213. /*
  214. * Test multiple subscriptions
  215. */
  216. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  217. if (result != SA_OK) {
  218. printf("ERROR: Event Initialize result: %d\n", result);
  219. return;
  220. }
  221. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  222. &channel_handle);
  223. if (result != SA_OK) {
  224. printf("ERROR: channel open result: %d\n", result);
  225. result = saEvtFinalize(handle);
  226. if (result != SA_OK)
  227. printf("ERROR: Finalize result: %d\n", result);
  228. return;
  229. }
  230. result = saEvtEventSubscribe(channel_handle,
  231. &subscribe_filters,
  232. subscription_id);
  233. if (result != SA_OK) {
  234. printf("ERROR: First event subscribe result: %d\n", result);
  235. result = saEvtChannelClose(channel_handle);
  236. if (result != SA_OK)
  237. printf("ERROR: Channel close result: %d\n", result);
  238. result = saEvtFinalize(handle);
  239. if (result != SA_OK)
  240. printf("ERROR: Finalize result: %d\n", result);
  241. return;
  242. }
  243. result = saEvtEventSubscribe(channel_handle,
  244. &subscribe_filters,
  245. subscription_id+1);
  246. if (result != SA_OK) {
  247. printf("ERROR: second event subscribe result: %d\n", result);
  248. result = saEvtChannelClose(channel_handle);
  249. if (result != SA_OK)
  250. printf("ERROR: Channel close result: %d\n", result);
  251. result = saEvtFinalize(handle);
  252. if (result != SA_OK)
  253. printf("ERROR: Finalize result: %d\n", result);
  254. return;
  255. }
  256. /*
  257. * Test duplicate subscription
  258. */
  259. printf("Duplicate subscription\n");
  260. result = saEvtEventSubscribe(channel_handle,
  261. &subscribe_filters,
  262. subscription_id);
  263. if (result != SA_ERR_EXIST) {
  264. printf("ERROR: First event subscribe result: %d\n", result);
  265. result = saEvtChannelClose(channel_handle);
  266. result = saEvtFinalize(handle);
  267. return;
  268. }
  269. /*
  270. * Test unsubscribe non-existent sub_id
  271. */
  272. printf("Unsubscribe non-existent sub_id\n");
  273. result = saEvtEventUnsubscribe(channel_handle, subscription_id+2);
  274. if (result != SA_ERR_INVALID_PARAM) {
  275. printf("ERROR: event unsubscribe result: %d\n", result);
  276. result = saEvtChannelClose(channel_handle);
  277. if (result != SA_OK)
  278. printf("ERROR: Channel close result: %d\n", result);
  279. result = saEvtFinalize(handle);
  280. if (result != SA_OK)
  281. printf("ERROR: Finalize result: %d\n", result);
  282. return;
  283. }
  284. printf("Unsubscribe from both, close, and finalize\n");
  285. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  286. if (result != SA_OK)
  287. printf("ERROR: first event unsubscribe result: %d\n", result);
  288. result = saEvtEventUnsubscribe(channel_handle, subscription_id+1);
  289. if (result != SA_OK)
  290. printf("ERROR: second event unsubscribe result: %d\n", result);
  291. result = saEvtChannelClose(channel_handle);
  292. if (result != SA_OK)
  293. printf("ERROR: Channel close result: %d\n", result);
  294. result = saEvtFinalize(handle);
  295. if (result != SA_OK)
  296. printf("ERROR: Finalize result: %d\n", result);
  297. printf("Done\n");
  298. }
  299. SaUint8T pat0[100];
  300. SaUint8T pat1[100];
  301. SaUint8T pat2[100];
  302. SaUint8T pat3[100];
  303. SaUint8T pat4[100];
  304. SaEvtEventPatternT evt_patts[5] = {
  305. {pat0, 100},
  306. {pat1, 100},
  307. {pat2, 100},
  308. {pat3, 100},
  309. {pat4, 100}};
  310. SaEvtEventPatternArrayT evt_pat_get_array = { evt_patts, 0 };
  311. SaEvtEventPatternT patterns[] = {
  312. {patt1, patt1_size},
  313. {patt2, patt2_size},
  314. {patt3, patt3_size},
  315. {patt4, patt4_size}
  316. };
  317. SaNameT test_pub_name = {13, "Test Pub Name"};
  318. #define TEST_PRIORITY 2
  319. SaEvtEventPatternArrayT evt_pat_set_array = {
  320. patterns,
  321. sizeof(patterns)/sizeof(SaEvtEventPatternT)
  322. };
  323. char event_data[1000];
  324. #define EVENT_DATA_SIZE 1000
  325. SaEvtEventIdT event_id = 0;
  326. SaUint8T priority;
  327. SaTimeT retention_time = 0ULL;
  328. SaNameT publisher_name = {0, {0}};
  329. SaSizeT event_data_size;
  330. void
  331. test_event()
  332. {
  333. SaEvtHandleT handle;
  334. SaEvtChannelHandleT channel_handle;
  335. SaEvtEventHandleT event_handle;
  336. SaEvtChannelOpenFlagsT flags;
  337. SaNameT channel_name;
  338. SaTimeT publish_time;
  339. struct pollfd pfd;
  340. int nfd;
  341. int fd;
  342. int timeout = 5000;
  343. int result;
  344. int i;
  345. flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER;
  346. strcpy(channel_name.value, channel);
  347. channel_name.length = strlen(channel);
  348. printf("Test Event operations:\n");
  349. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  350. if (result != SA_OK) {
  351. printf("ERROR: Event Initialize result: %d\n", result);
  352. return;
  353. }
  354. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  355. &channel_handle);
  356. if (result != SA_OK) {
  357. printf("ERROR: channel open result: %d\n", result);
  358. goto evt_fin;
  359. }
  360. /*
  361. * Allocate an event
  362. */
  363. printf("Event allocation\n");
  364. result = saEvtEventAllocate(channel_handle, &event_handle);
  365. if (result != SA_OK) {
  366. printf("ERROR: event Allocate result: %d\n", result);
  367. goto evt_close;
  368. }
  369. printf("Get event attributes(1)\n");
  370. result = saEvtEventAttributesGet(event_handle,
  371. 0, /* patterns */
  372. 0, /* priority */
  373. 0, /* retention time */
  374. 0, /* publisher name */
  375. 0, /* publish time */
  376. 0 /* event_id */
  377. );
  378. if (result != SA_OK) {
  379. printf("ERROR: event get attr result(1): %d\n", result);
  380. goto evt_free;
  381. }
  382. /*
  383. * Get event attributes, this time supply pointers.
  384. * validate the default values.
  385. */
  386. printf("Get event attributes(2)\n");
  387. evt_pat_get_array.patternsNumber = 4;
  388. result = saEvtEventAttributesGet(event_handle,
  389. &evt_pat_get_array, /* patterns */
  390. &priority, /* priority */
  391. &retention_time, /* retention time */
  392. &publisher_name, /* publisher name */
  393. &publish_time, /* publish time */
  394. &event_id /* event_id */
  395. );
  396. if (result != SA_OK) {
  397. printf("ERROR: event get attr result(2): %d\n", result);
  398. goto evt_free;
  399. }
  400. if (evt_pat_get_array.patternsNumber != 0) {
  401. printf("ERROR: pattern array count not zero: %d\n",
  402. evt_pat_get_array.patternsNumber);
  403. }
  404. if (priority != SA_EVT_LOWEST_PRIORITY) {
  405. printf("ERROR: priority not lowest: 0x%x\n", priority);
  406. }
  407. if (retention_time != 0) {
  408. printf("ERROR: retention time not zero: %0llx\n", retention_time);
  409. }
  410. if (publisher_name.length != 0) {
  411. printf("ERROR: publisher name not null: %s\n", publisher_name.value);
  412. }
  413. if (event_id != 0) {
  414. printf("ERROR: event id not zero: 0x%llx\n", event_id);
  415. }
  416. /*
  417. * Set some attributes, then read them back
  418. */
  419. printf("Set event attributes(1)\n");
  420. result = saEvtEventAttributesSet(event_handle,
  421. &evt_pat_set_array,
  422. TEST_PRIORITY,
  423. test_ret_time,
  424. &test_pub_name);
  425. if (result != SA_OK) {
  426. printf("ERROR: event set attr result(1): %d\n", result);
  427. goto evt_free;
  428. }
  429. printf("Get event attributes(3)\n");
  430. evt_pat_get_array.patternsNumber = 4;
  431. result = saEvtEventAttributesGet(event_handle,
  432. &evt_pat_get_array, /* patterns */
  433. &priority, /* priority */
  434. &retention_time, /* retention time */
  435. &publisher_name, /* publisher name */
  436. &publish_time, /* publish time */
  437. &event_id /* event_id */
  438. );
  439. if (result != SA_OK) {
  440. printf("ERROR: event get attr result(2): %d\n", result);
  441. goto evt_free;
  442. }
  443. if (evt_pat_get_array.patternsNumber != 4) {
  444. printf("ERROR: pattern array count not 4: %d\n",
  445. evt_pat_get_array.patternsNumber);
  446. }
  447. for (i = 0; i < evt_pat_get_array.patternsNumber; i++) {
  448. if (evt_pat_get_array.patterns[i].patternSize !=
  449. evt_pat_set_array.patterns[i].patternSize) {
  450. printf("ERROR: pattern %d count not equal g=%d, s=%d\n",
  451. i,
  452. evt_pat_get_array.patterns[i].patternSize,
  453. evt_pat_set_array.patterns[i].patternSize);
  454. printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
  455. i,
  456. evt_pat_get_array.patterns[i].pattern,
  457. evt_pat_set_array.patterns[i].pattern);
  458. } else {
  459. if (memcmp(evt_pat_get_array.patterns[i].pattern,
  460. evt_pat_set_array.patterns[i].pattern,
  461. evt_pat_get_array.patterns[i].patternSize) != 0){
  462. printf(
  463. "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
  464. i,
  465. evt_pat_get_array.patterns[i].pattern,
  466. evt_pat_set_array.patterns[i].pattern);
  467. }
  468. }
  469. }
  470. if (priority != TEST_PRIORITY) {
  471. printf("ERROR: priority: e=0x%x a=0x%x\n",
  472. TEST_PRIORITY, priority);
  473. }
  474. if (retention_time != test_ret_time) {
  475. printf("ERROR: retention: e=0x%llx a=0x%llx\n",
  476. test_ret_time, retention_time);
  477. }
  478. if (publisher_name.length != test_pub_name.length) {
  479. printf("ERROR: publisher name length: e=%d, a=%d\n",
  480. test_pub_name.length,
  481. publisher_name.length);
  482. } else {
  483. if (memcmp(publisher_name.value, test_pub_name.value,
  484. publisher_name.length) != 0) {
  485. printf("ERROR: publisher name content: e=%s, a=%s\n",
  486. test_pub_name.value,
  487. publisher_name.value);
  488. }
  489. }
  490. if (event_id != 0) {
  491. printf("ERROR: event id not zero: 0x%llx\n", event_id);
  492. }
  493. /*
  494. * Event attr patterns: short reads/long reads
  495. */
  496. /* TODO */
  497. /*
  498. * event user data
  499. */
  500. printf("Get event data(1)\n");
  501. result = saEvtEventDataGet(event_handle, 0, 0);
  502. if (result != SA_OK) {
  503. printf("ERROR: Get event data(1) result: %d\n", result);
  504. }
  505. printf("Get event data(2)\n");
  506. result = saEvtEventDataGet(event_handle, event_data, 0);
  507. if (result != SA_OK) {
  508. printf("ERROR: Get event data(2) result: %d\n", result);
  509. }
  510. printf("Get event data(3)\n");
  511. event_data_size = EVENT_DATA_SIZE;
  512. result = saEvtEventDataGet(event_handle, 0, &event_data_size);
  513. if (result != SA_OK) {
  514. printf("ERROR: Get event data(3) result: %d\n", result);
  515. }
  516. printf("Get event data(4)\n");
  517. event_data_size = EVENT_DATA_SIZE;
  518. result = saEvtEventDataGet(event_handle, event_data, &event_data_size);
  519. if (result != SA_OK) {
  520. printf("ERROR: Get event data(4) result: %d\n", result);
  521. }
  522. printf("Get event data(5)\n");
  523. event_data_size = 1;
  524. result = saEvtEventDataGet(event_handle, event_data, &event_data_size);
  525. if (result != SA_OK) {
  526. printf("ERROR: Get event data(5) result: %d\n", result);
  527. }
  528. printf("Free event(1)\n");
  529. result = saEvtEventFree(event_handle);
  530. if (result != SA_OK) {
  531. printf("ERROR: event free result: %d\n", result);
  532. }
  533. /*
  534. * Test publication.
  535. */
  536. printf("Publish with no patterns set\n");
  537. result = saEvtEventAllocate(channel_handle, &event_handle);
  538. if (result != SA_OK) {
  539. printf("ERROR: event Allocate result: %d\n", result);
  540. goto evt_close;
  541. }
  542. result = saEvtEventPublish(event_handle, 0, 0, &event_id);
  543. if (result != SA_ERR_INVALID_PARAM) {
  544. printf("ERROR: event Publish result(1): %d\n", result);
  545. goto evt_close;
  546. }
  547. /*
  548. * Publish with pattens
  549. */
  550. printf("Publish with patterns set\n");
  551. result = saEvtEventSubscribe(channel_handle,
  552. &subscribe_filters,
  553. subscription_id);
  554. if (result != SA_OK) {
  555. printf("ERROR: event subscribe result: %d\n", result);
  556. result = saEvtChannelClose(channel_handle);
  557. if (result != SA_OK)
  558. printf("ERROR: Channel close result: %d\n", result);
  559. result = saEvtFinalize(handle);
  560. if (result != SA_OK)
  561. printf("ERROR: Finalize result: %d\n", result);
  562. return;
  563. }
  564. retention_time = 0ULL;
  565. result = saEvtEventAttributesSet(event_handle,
  566. &evt_pat_set_array,
  567. TEST_PRIORITY,
  568. retention_time,
  569. &test_pub_name);
  570. if (result != SA_OK) {
  571. printf("ERROR: event set attr result(2): %d\n", result);
  572. goto evt_free;
  573. }
  574. /*
  575. * Generate event data
  576. */
  577. exp_data = malloc(DATA_SIZE);
  578. for (i = 0; i < LCOUNT; i++) {
  579. exp_data[i] = lrand48();
  580. }
  581. event_data_size = DATA_SIZE;
  582. /*
  583. * Send it
  584. */
  585. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  586. &event_id);
  587. if (result != SA_OK) {
  588. printf("ERROR: event Publish result(2): %d\n", result);
  589. goto evt_close;
  590. }
  591. /*
  592. * See if we got the event
  593. */
  594. result = saEvtSelectionObjectGet(handle, &fd);
  595. if (result != SA_OK) {
  596. printf("ERROR: saEvtSelectionObject get %d\n", result);
  597. /* error */
  598. return;
  599. }
  600. pfd.fd = fd;
  601. pfd.events = POLLIN;
  602. nfd = poll(&pfd, 1, timeout);
  603. if (nfd <= 0) {
  604. printf("ERROR: poll fds %d\n", nfd);
  605. if (nfd < 0) {
  606. perror("ERROR: poll error");
  607. }
  608. /* Error */
  609. return;
  610. }
  611. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  612. if (result != SA_OK) {
  613. printf("ERROR: saEvtDispatch %d\n", result);
  614. /* error */
  615. return;
  616. }
  617. /*
  618. * Test cleanup
  619. */
  620. evt_free:
  621. result = saEvtEventFree(event_handle);
  622. if (result != SA_OK) {
  623. printf("ERROR: event free result: %d\n", result);
  624. }
  625. evt_close:
  626. result = saEvtChannelClose(channel_handle);
  627. if (result != SA_OK) {
  628. printf("ERROR: channel close result: %d\n", result);
  629. }
  630. evt_fin:
  631. result = saEvtFinalize(handle);
  632. if (result != SA_OK) {
  633. printf("ERROR: Event Finalize result: %d\n", result);
  634. }
  635. printf("Done\n");
  636. }
  637. void
  638. event_callback(SaEvtSubscriptionIdT my_subscription_id,
  639. const SaEvtEventHandleT event_handle,
  640. const SaSizeT my_event_data_size)
  641. {
  642. SaErrorT result;
  643. SaUint8T my_priority;
  644. SaTimeT my_retention_time;
  645. SaNameT my_publisher_name = {0, {0}};
  646. SaTimeT my_publish_time;
  647. SaEvtEventIdT my_event_id;
  648. int i;
  649. long *act_data;
  650. SaSizeT data_size;
  651. printf("event_callback called\n");
  652. if (my_subscription_id != subscription_id) {
  653. printf("ERROR: sub ID: e=%lx, a=%lx\n",
  654. subscription_id, my_subscription_id);
  655. }
  656. if (my_event_data_size != event_data_size) {
  657. printf("ERROR: event data size e=%d, a=%d\n",
  658. event_data_size,
  659. my_event_data_size);
  660. }
  661. evt_pat_get_array.patternsNumber = 4;
  662. result = saEvtEventAttributesGet(event_handle,
  663. &evt_pat_get_array, /* patterns */
  664. &my_priority, /* priority */
  665. &my_retention_time, /* retention time */
  666. &my_publisher_name, /* publisher name */
  667. &my_publish_time, /* publish time */
  668. &my_event_id /* event_id */
  669. );
  670. if (result != SA_OK) {
  671. printf("ERROR: event get attr result(2): %d\n", result);
  672. goto evt_free;
  673. }
  674. if (my_event_id != event_id) {
  675. printf("ERROR: Call back event ID error: e=%llx, a=%llx\n",
  676. event_id, my_event_id);
  677. }
  678. if (evt_pat_get_array.patternsNumber != 4) {
  679. printf("ERROR: pattern array count not 4: %d\n",
  680. evt_pat_get_array.patternsNumber);
  681. }
  682. for (i = 0; i < evt_pat_get_array.patternsNumber; i++) {
  683. if (evt_pat_get_array.patterns[i].patternSize !=
  684. evt_pat_set_array.patterns[i].patternSize) {
  685. printf("ERROR: pattern %d count not equal g=%d, s=%d\n",
  686. i,
  687. evt_pat_get_array.patterns[i].patternSize,
  688. evt_pat_set_array.patterns[i].patternSize);
  689. printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
  690. i,
  691. evt_pat_get_array.patterns[i].pattern,
  692. evt_pat_set_array.patterns[i].pattern);
  693. } else {
  694. if (memcmp(evt_pat_get_array.patterns[i].pattern,
  695. evt_pat_set_array.patterns[i].pattern,
  696. evt_pat_get_array.patterns[i].patternSize) != 0){
  697. printf(
  698. "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
  699. i,
  700. evt_pat_get_array.patterns[i].pattern,
  701. evt_pat_set_array.patterns[i].pattern);
  702. }
  703. }
  704. }
  705. if (priority != my_priority) {
  706. printf("ERROR: priority: e=0x%x a=0x%x\n",
  707. priority, my_priority);
  708. }
  709. if (retention_time != my_retention_time) {
  710. printf("ERROR: retention: e=0x%llx a=0x%llx\n",
  711. retention_time, my_retention_time);
  712. }
  713. if (publisher_name.length != my_publisher_name.length) {
  714. printf("ERROR: publisher name length: e=%d, a=%d\n",
  715. publisher_name.length,
  716. my_publisher_name.length);
  717. } else {
  718. if (memcmp(publisher_name.value, my_publisher_name.value,
  719. publisher_name.length) != 0) {
  720. printf("ERROR: publisher name content: e=%s, a=%s\n",
  721. publisher_name.value,
  722. my_publisher_name.value);
  723. }
  724. }
  725. act_data = malloc(my_event_data_size);
  726. memset(act_data, 0, my_event_data_size);
  727. data_size = my_event_data_size;
  728. result = saEvtEventDataGet(event_handle, act_data, &data_size);
  729. if (result != SA_OK) {
  730. printf("ERROR: event data get result: %d\n", result);
  731. goto dat_free;
  732. }
  733. if (data_size != event_data_size) {
  734. printf("ERROR: Data size: e=%d a=%d\n",
  735. event_data_size, data_size);
  736. }
  737. for (i = 0; i < (data_size/sizeof(long)); i++) {
  738. if (act_data[i] != exp_data[i]) {
  739. printf("ERROR: Event Data e=%lx a=%lx at index %d\n",
  740. exp_data[i], act_data[i], i);
  741. break;
  742. }
  743. }
  744. dat_free:
  745. free(act_data);
  746. evt_free:
  747. result = saEvtEventFree(event_handle);
  748. if (result != SA_OK) {
  749. printf("ERROR: event free result: %d\n", result);
  750. }
  751. }
  752. int main (void)
  753. {
  754. test_initialize ();
  755. test_channel();
  756. test_event();
  757. return (0);
  758. }