testevt.c 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189
  1. /*
  2. * Copyright (c) 2004 Mark Haverkamp
  3. * Copyright (c) 2004 Open Source Development Lab
  4. *
  5. * All rights reserved.
  6. *
  7. * This software licensed under BSD license, the text of which follows:
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  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.
  20. *
  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.
  32. */
  33. /*
  34. * Test program for event service
  35. *
  36. * test_initialize ();
  37. * Version check in saEvtInitialze()
  38. *
  39. * test_channel();
  40. * Test basic channel operations. Open/close/subscribe/unsubscribe
  41. *
  42. * test_event();
  43. * Event operations: allocation, free, setting and getting
  44. * attributes, publishing.
  45. *
  46. * test_multi_channel1();
  47. * test_multi_channel1();
  48. * test_multi_channel1();
  49. * Test events on multiple channels and multiple subscriptions.
  50. *
  51. * test_retention();
  52. * Test event retention times.
  53. *
  54. * test_unlink_channel();
  55. * Test event channel unlink.
  56. */
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <string.h>
  60. #include <unistd.h>
  61. #include <sys/poll.h>
  62. #include <malloc.h>
  63. #include "ais_types.h"
  64. #include "saEvt.h"
  65. extern int get_sa_error(SaAisErrorT, char *, int);
  66. char result_buf[256];
  67. int result_buf_len = sizeof(result_buf);
  68. #define TRY_WAIT 2
  69. void testresult (SaAisErrorT result, SaAisErrorT expected, int test_no)
  70. {
  71. if (result == expected) {
  72. printf ("Test %d passed\n", test_no);
  73. } else {
  74. get_sa_error(result, result_buf, result_buf_len);
  75. printf ("ERROR: Test %d FAILED (expected %d got %s)\n",
  76. test_no, expected, result_buf);
  77. }
  78. }
  79. SaVersionT version1 = { 'B', 0x01, 0x01 };
  80. SaVersionT version2 = { 'b', 0x01, 0x01 };
  81. SaVersionT version3 = { 'c', 0x01, 0x01 };
  82. SaVersionT version4 = { 'b', 0x02, 0x01 };
  83. SaVersionT version5 = { 'b', 0xff, 0x01 };
  84. SaVersionT version6 = { 'b', 0x01, 0xff };
  85. SaVersionT version7 = { 'B', 0xff, 0xff };
  86. SaVersionT version8 = { 'C', 0xff, 0xff };
  87. struct version_test {
  88. SaVersionT *version;
  89. SaAisErrorT result;
  90. };
  91. struct version_test versions[] = {
  92. { &version1, SA_AIS_OK },
  93. { &version2, SA_AIS_OK },
  94. { &version3, SA_AIS_ERR_VERSION },
  95. { &version4, SA_AIS_ERR_VERSION},
  96. { &version8, SA_AIS_ERR_VERSION},
  97. { 0, SA_AIS_ERR_VERSION}
  98. };
  99. int version_size = sizeof(versions) / sizeof(struct version_test);
  100. void open_callback(SaInvocationT invocation,
  101. SaEvtChannelHandleT channelHandle,
  102. SaAisErrorT error);
  103. void event_callback(SaEvtSubscriptionIdT subscriptionId,
  104. const SaEvtEventHandleT eventHandle,
  105. const SaSizeT eventDataSize);
  106. SaEvtCallbacksT callbacks = {
  107. open_callback,
  108. event_callback
  109. };
  110. char channel[256] = "TESTEVT_CHANNEL";
  111. char unlink_channel[256] = "TESTEVT_UNLINK_CHANNEL";
  112. SaEvtSubscriptionIdT subscription_id = 0xabcdef;
  113. SaInvocationT open_invocation = 0xaa55cc33;
  114. unsigned long long test_ret_time = 30000000000ULL; /* 30 seconds */
  115. /*
  116. * event data
  117. */
  118. long *exp_data;
  119. #define DATA_SIZE 2048 /* default data size */
  120. #define LCOUNT DATA_SIZE/sizeof(long)
  121. /*
  122. * Test saEvtInitialize and version checking.
  123. */
  124. void test_initialize (void) {
  125. SaAisErrorT result;
  126. SaEvtHandleT handle;
  127. int i;
  128. /*
  129. * version check tests
  130. */
  131. printf("Test lib version check on initlialize\n");
  132. for (i=0; i < version_size; i++) {
  133. do {
  134. result = saEvtInitialize (&handle, 0, versions[i].version);
  135. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  136. testresult (result, versions[i].result, i);
  137. if (result == SA_AIS_OK) {
  138. saEvtFinalize(handle);
  139. }
  140. }
  141. }
  142. #define patt1 "Filter pattern 1"
  143. #define patt1_size sizeof(patt1)
  144. #define patt2 "Filter pattern 2"
  145. #define patt2_size sizeof(patt2)
  146. #define patt3 "Filter pattern 3"
  147. #define patt3_size sizeof(patt3)
  148. #define patt4 "Filter pattern 4"
  149. #define patt4_size sizeof(patt4)
  150. SaEvtEventFilterT filters[] = {
  151. {SA_EVT_PREFIX_FILTER, {patt1_size, patt1_size, patt1}},
  152. {SA_EVT_SUFFIX_FILTER, {patt2_size, patt2_size, patt2}},
  153. {SA_EVT_EXACT_FILTER, {patt3_size, patt3_size, patt3}},
  154. {SA_EVT_PASS_ALL_FILTER, {patt4_size, patt4_size, patt4}}
  155. };
  156. SaEvtEventFilterArrayT subscribe_filters = {
  157. sizeof(filters)/sizeof(SaEvtEventFilterT),
  158. filters
  159. };
  160. /*
  161. * Process the open callback
  162. */
  163. void open_callback(SaInvocationT invocation,
  164. SaEvtChannelHandleT channel_handle,
  165. SaAisErrorT error)
  166. {
  167. SaAisErrorT result;
  168. printf(" Received open channel callback\n");
  169. if (error != SA_AIS_OK) {
  170. get_sa_error(error, result_buf, result_buf_len);
  171. printf("ERROR: async channel open result: %s\n", result_buf);
  172. return;
  173. }
  174. if (invocation != open_invocation) {
  175. printf("ERROR: Unexpected invocation value: e 0x%llx, a 0x%llx\n",
  176. open_invocation, invocation);
  177. }
  178. printf(" Close async channel:\n");
  179. do {
  180. result = saEvtChannelClose(channel_handle);
  181. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  182. if (result != SA_AIS_OK) {
  183. get_sa_error(result, result_buf, result_buf_len);
  184. printf("ERROR: channel close result: %s\n", result_buf);
  185. return;
  186. }
  187. }
  188. /*
  189. * Test channel operations.
  190. * 1. Open a channel.
  191. * 2. Close a channel.
  192. * 3. Channel subscription.
  193. * 4. Channel unsubscribe
  194. * 5. unsubscribe/finalize with no channel close.
  195. * 6. Multiple subscriptions.
  196. * 7. Duplicate subscription ID.
  197. * 8. unsubscribe non-exsistent subscription ID.
  198. * 9. Open a channel async.
  199. *
  200. */
  201. void
  202. test_channel()
  203. {
  204. SaEvtHandleT handle;
  205. SaEvtChannelHandleT channel_handle;
  206. SaEvtChannelOpenFlagsT flags;
  207. SaNameT channel_name;
  208. SaAisErrorT result;
  209. struct pollfd pfd;
  210. int nfd;
  211. SaSelectionObjectT fd;
  212. int timeout = 5000;
  213. flags = SA_EVT_CHANNEL_PUBLISHER |
  214. SA_EVT_CHANNEL_SUBSCRIBER |
  215. SA_EVT_CHANNEL_CREATE;
  216. strcpy(channel_name.value, channel);
  217. channel_name.length = strlen(channel);
  218. /*
  219. * Channel open/close test
  220. */
  221. printf("Test Channel operations:\n");
  222. printf(" Channel open:\n");
  223. do {
  224. result = saEvtInitialize (&handle,
  225. &callbacks, versions[0].version);
  226. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  227. if (result != SA_AIS_OK) {
  228. get_sa_error(result, result_buf, result_buf_len);
  229. printf("ERROR: Event Initialize result: %s\n", result_buf);
  230. return;
  231. }
  232. do {
  233. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  234. &channel_handle);
  235. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  236. if (result != SA_AIS_OK) {
  237. get_sa_error(result, result_buf, result_buf_len);
  238. printf("ERROR: channel open result: %s\n", result_buf);
  239. do {
  240. result = saEvtFinalize(handle);
  241. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  242. if (result != SA_AIS_OK) {
  243. get_sa_error(result, result_buf, result_buf_len);
  244. printf("ERROR: Event Finalize result: %s\n", result_buf);
  245. }
  246. return;
  247. }
  248. printf(" Channel close:\n");
  249. do {
  250. result = saEvtChannelClose(channel_handle);
  251. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  252. if (result != SA_AIS_OK) {
  253. get_sa_error(result, result_buf, result_buf_len);
  254. printf("ERROR: channel close result: %s\n", result_buf);
  255. return;
  256. }
  257. do {
  258. result = saEvtFinalize(handle);
  259. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  260. if (result != SA_AIS_OK) {
  261. get_sa_error(result, result_buf, result_buf_len);
  262. printf("ERROR: Event Finalize result: %s\n", result_buf);
  263. return;
  264. }
  265. /*
  266. * Test channel subscribe
  267. */
  268. printf(" Channel subscribe:\n");
  269. do {
  270. result = saEvtInitialize (&handle, &callbacks,
  271. versions[0].version);
  272. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  273. if (result != SA_AIS_OK) {
  274. get_sa_error(result, result_buf, result_buf_len);
  275. printf("ERROR: Event Initialize result: %s\n", result_buf);
  276. return;
  277. }
  278. do {
  279. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  280. &channel_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: channel open result: %s\n", result_buf);
  285. do {
  286. result = saEvtFinalize(handle);
  287. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  288. if (result != SA_AIS_OK) {
  289. get_sa_error(result, result_buf, result_buf_len);
  290. printf("ERROR: Finalize result: %s\n", result_buf);
  291. }
  292. return;
  293. }
  294. do {
  295. result = saEvtEventSubscribe(channel_handle,
  296. &subscribe_filters,
  297. subscription_id);
  298. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  299. if (result != SA_AIS_OK) {
  300. get_sa_error(result, result_buf, result_buf_len);
  301. printf("ERROR: event subscribe result: %s\n", result_buf);
  302. do {
  303. result = saEvtChannelClose(channel_handle);
  304. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  305. if (result != SA_AIS_OK) {
  306. get_sa_error(result, result_buf, result_buf_len);
  307. printf("ERROR: Channel close result: %s\n", result_buf);
  308. }
  309. do {
  310. result = saEvtFinalize(handle);
  311. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  312. if (result != SA_AIS_OK) {
  313. get_sa_error(result, result_buf, result_buf_len);
  314. printf("ERROR: Finalize result: %s\n", result_buf);
  315. }
  316. return;
  317. }
  318. printf(" Channel unsubscribe:\n");
  319. do {
  320. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  321. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  322. if (result != SA_AIS_OK) {
  323. get_sa_error(result, result_buf, result_buf_len);
  324. printf("ERROR: event unsubscribe result: %s\n", result_buf);
  325. do {
  326. result = saEvtChannelClose(channel_handle);
  327. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  328. if (result != SA_AIS_OK) {
  329. get_sa_error(result, result_buf, result_buf_len);
  330. printf("ERROR: Channel close result: %s\n", result_buf);
  331. }
  332. do {
  333. result = saEvtFinalize(handle);
  334. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  335. if (result != SA_AIS_OK) {
  336. get_sa_error(result, result_buf, result_buf_len);
  337. printf("ERROR: Finalize result: %s\n", result_buf);
  338. }
  339. return;
  340. }
  341. do {
  342. result = saEvtChannelClose(channel_handle);
  343. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  344. if (result != SA_AIS_OK) {
  345. get_sa_error(result, result_buf, result_buf_len);
  346. printf("ERROR: Channel close result: %s\n", result_buf);
  347. }
  348. do {
  349. result = saEvtFinalize(handle);
  350. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  351. if (result != SA_AIS_OK) {
  352. get_sa_error(result, result_buf, result_buf_len);
  353. printf("ERROR: Finalize result: %s\n", result_buf);
  354. }
  355. /*
  356. * Test channel subscribe with no close
  357. */
  358. printf(" Channel subscribe with no close at end:\n");
  359. do {
  360. result = saEvtInitialize (&handle, &callbacks,
  361. versions[0].version);
  362. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  363. if (result != SA_AIS_OK) {
  364. get_sa_error(result, result_buf, result_buf_len);
  365. printf("ERROR: Event Initialize result: %s\n", result_buf);
  366. return;
  367. }
  368. do {
  369. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  370. &channel_handle);
  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: channel open result: %s\n", result_buf);
  375. result = saEvtFinalize(handle);
  376. return;
  377. }
  378. do {
  379. result = saEvtEventSubscribe(channel_handle,
  380. &subscribe_filters,
  381. subscription_id);
  382. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  383. if (result != SA_AIS_OK) {
  384. get_sa_error(result, result_buf, result_buf_len);
  385. printf("ERROR: event subscribe result: %s\n", result_buf);
  386. result = saEvtChannelClose(channel_handle);
  387. }
  388. do {
  389. result = saEvtFinalize(handle);
  390. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  391. if (result != SA_AIS_OK) {
  392. get_sa_error(result, result_buf, result_buf_len);
  393. printf("ERROR: Finalize failed\n");
  394. return;
  395. }
  396. /*
  397. * Test multiple subscriptions
  398. */
  399. printf(" Multiple subscriptions\n");
  400. do {
  401. result = saEvtInitialize (&handle, &callbacks,
  402. versions[0].version);
  403. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  404. if (result != SA_AIS_OK) {
  405. get_sa_error(result, result_buf, result_buf_len);
  406. printf("ERROR: Event Initialize result: %s\n", result_buf);
  407. return;
  408. }
  409. do {
  410. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  411. &channel_handle);
  412. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  413. if (result != SA_AIS_OK) {
  414. get_sa_error(result, result_buf, result_buf_len);
  415. printf("ERROR: channel open result: %s\n", result_buf);
  416. do {
  417. result = saEvtFinalize(handle);
  418. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  419. if (result != SA_AIS_OK) {
  420. get_sa_error(result, result_buf, result_buf_len);
  421. printf("ERROR: Finalize result: %s\n", result_buf);
  422. }
  423. return;
  424. }
  425. do {
  426. result = saEvtEventSubscribe(channel_handle,
  427. &subscribe_filters,
  428. subscription_id);
  429. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  430. if (result != SA_AIS_OK) {
  431. get_sa_error(result, result_buf, result_buf_len);
  432. printf("ERROR: First event subscribe result: %s\n", result_buf);
  433. do {
  434. result = saEvtChannelClose(channel_handle);
  435. } 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: Channel close result: %s\n", result_buf);
  439. }
  440. do {
  441. result = saEvtFinalize(handle);
  442. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  443. if (result != SA_AIS_OK) {
  444. get_sa_error(result, result_buf, result_buf_len);
  445. printf("ERROR: Finalize result: %s\n", result_buf);
  446. }
  447. return;
  448. }
  449. do {
  450. result = saEvtEventSubscribe(channel_handle,
  451. &subscribe_filters,
  452. subscription_id+1);
  453. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  454. if (result != SA_AIS_OK) {
  455. get_sa_error(result, result_buf, result_buf_len);
  456. printf("ERROR: second event subscribe result: %s\n", result_buf);
  457. do {
  458. result = saEvtChannelClose(channel_handle);
  459. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  460. if (result != SA_AIS_OK) {
  461. get_sa_error(result, result_buf, result_buf_len);
  462. printf("ERROR: Channel close result: %s\n", result_buf);
  463. }
  464. do {
  465. result = saEvtFinalize(handle);
  466. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  467. if (result != SA_AIS_OK) {
  468. get_sa_error(result, result_buf, result_buf_len);
  469. printf("ERROR: Finalize result: %s\n", result_buf);
  470. }
  471. return;
  472. }
  473. /*
  474. * Test duplicate subscription
  475. */
  476. printf(" Duplicate subscription\n");
  477. do {
  478. result = saEvtEventSubscribe(channel_handle,
  479. &subscribe_filters,
  480. subscription_id);
  481. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  482. if (result != SA_AIS_ERR_EXIST) {
  483. get_sa_error(result, result_buf, result_buf_len);
  484. printf("ERROR: First event subscribe result: %s\n", result_buf);
  485. result = saEvtChannelClose(channel_handle);
  486. result = saEvtFinalize(handle);
  487. return;
  488. }
  489. /*
  490. * Test unsubscribe non-existent sub_id
  491. */
  492. printf(" Unsubscribe non-existent sub_id\n");
  493. do {
  494. result = saEvtEventUnsubscribe(channel_handle,
  495. subscription_id+2);
  496. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  497. if (result != SA_AIS_ERR_NOT_EXIST) {
  498. get_sa_error(result, result_buf, result_buf_len);
  499. printf("ERROR: event unsubscribe result: %s\n", result_buf);
  500. do {
  501. result = saEvtChannelClose(channel_handle);
  502. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  503. if (result != SA_AIS_OK) {
  504. get_sa_error(result, result_buf, result_buf_len);
  505. printf("ERROR: Channel close result: %s\n", result_buf);
  506. }
  507. do {
  508. result = saEvtFinalize(handle);
  509. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  510. if (result != SA_AIS_OK) {
  511. get_sa_error(result, result_buf, result_buf_len);
  512. printf("ERROR: Finalize result: %s\n", result_buf);
  513. }
  514. return;
  515. }
  516. do {
  517. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  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: first event unsubscribe result: %s\n", result_buf);
  522. }
  523. do {
  524. result = saEvtEventUnsubscribe(channel_handle,
  525. subscription_id+1);
  526. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  527. if (result != SA_AIS_OK) {
  528. get_sa_error(result, result_buf, result_buf_len);
  529. printf("ERROR: second event unsubscribe result: %s\n", result_buf);
  530. }
  531. do {
  532. result = saEvtChannelClose(channel_handle);
  533. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  534. if (result != SA_AIS_OK) {
  535. get_sa_error(result, result_buf, result_buf_len);
  536. printf("ERROR: Channel close result: %s\n", result_buf);
  537. }
  538. do {
  539. result = saEvtFinalize(handle);
  540. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  541. if (result != SA_AIS_OK) {
  542. get_sa_error(result, result_buf, result_buf_len);
  543. printf("ERROR: Finalize result: %s\n", result_buf);
  544. }
  545. /*
  546. * Test opening a channel async.
  547. */
  548. printf(" Channel open async:\n");
  549. do {
  550. result = saEvtInitialize (&handle, &callbacks,
  551. versions[0].version);
  552. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  553. if (result != SA_AIS_OK) {
  554. get_sa_error(result, result_buf, result_buf_len);
  555. printf("ERROR: Event Initialize result: %s\n", result_buf);
  556. return;
  557. }
  558. do {
  559. result = saEvtChannelOpenAsync(handle, open_invocation,
  560. &channel_name, flags);
  561. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  562. if (result != SA_AIS_OK) {
  563. get_sa_error(result, result_buf, result_buf_len);
  564. printf("ERROR: channel open async result: %s\n", result_buf);
  565. do {
  566. result = saEvtFinalize(handle);
  567. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  568. if (result != SA_AIS_OK) {
  569. get_sa_error(result, result_buf, result_buf_len);
  570. printf("ERROR: Event Finalize result: %s\n", result_buf);
  571. }
  572. return;
  573. }
  574. /*
  575. * See if we got the open callback
  576. */
  577. do {
  578. result = saEvtSelectionObjectGet(handle, &fd);
  579. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  580. if (result != SA_AIS_OK) {
  581. get_sa_error(result, result_buf, result_buf_len);
  582. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  583. /* error */
  584. return;
  585. }
  586. pfd.fd = fd;
  587. pfd.events = POLLIN;
  588. nfd = poll(&pfd, 1, timeout);
  589. if (nfd <= 0) {
  590. printf("ERROR: poll fds %d\n", nfd);
  591. if (nfd < 0) {
  592. perror("ERROR: poll error");
  593. }
  594. /* Error */
  595. return;
  596. }
  597. do {
  598. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  599. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  600. if (result != SA_AIS_OK) {
  601. get_sa_error(result, result_buf, result_buf_len);
  602. printf("ERROR: saEvtDispatch %s\n", result_buf);
  603. /* error */
  604. return;
  605. }
  606. do {
  607. result = saEvtFinalize(handle);
  608. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  609. if (result != SA_AIS_OK) {
  610. get_sa_error(result, result_buf, result_buf_len);
  611. printf("ERROR: Event Finalize result: %s\n", result_buf);
  612. return;
  613. }
  614. printf("Done\n");
  615. }
  616. SaUint8T pat0[100];
  617. SaUint8T pat1[100];
  618. SaUint8T pat2[100];
  619. SaUint8T pat3[100];
  620. SaUint8T pat4[100];
  621. SaEvtEventPatternT evt_patts[5] = {
  622. {100, 100, pat0},
  623. {100, 100, pat1},
  624. {100, 100, pat2},
  625. {100, 100, pat3},
  626. {100, 100, pat4}};
  627. SaEvtEventPatternArrayT evt_pat_get_array = { 5, 0, evt_patts };
  628. SaEvtEventPatternT patterns[] = {
  629. {patt1_size, patt1_size, patt1},
  630. {patt2_size, patt2_size, patt2},
  631. {patt3_size, patt3_size, patt3},
  632. {patt4_size, patt4_size, patt4}
  633. };
  634. SaNameT test_pub_name = {13, "Test Pub Name"};
  635. #define TEST_PRIORITY 2
  636. SaEvtEventPatternArrayT evt_pat_set_array = {
  637. sizeof(patterns)/sizeof(SaEvtEventPatternT),
  638. sizeof(patterns)/sizeof(SaEvtEventPatternT),
  639. patterns
  640. };
  641. char event_data[1000];
  642. #define EVENT_DATA_SIZE 1000
  643. SaEvtEventIdT event_id = 0;
  644. SaUint8T priority;
  645. SaTimeT retention_time = 0ULL;
  646. SaNameT publisher_name = {0, {0}};
  647. SaSizeT event_data_size;
  648. /*
  649. * Test event operations.
  650. *
  651. * 1. Event allocation
  652. * 2. Get event attributes (no pointers).
  653. * 3. Get event attributes with pointers.
  654. * 4. Set/Get event attributes.
  655. * 5. Get event user data no pointer or count
  656. * 6. Get event user data with pointer and no count
  657. * 7. Get event user data with no pointer with a count.
  658. * 8. Get event user data with pointer and count.
  659. * 9. Get event user data woth a short count.
  660. * 10. Free event.
  661. * 11. Publish with no set patterns.
  662. * 12. Publish with set patterns and event user data.
  663. *
  664. */
  665. void
  666. event_callback(SaEvtSubscriptionIdT my_subscription_id,
  667. const SaEvtEventHandleT event_handle,
  668. const SaSizeT my_event_data_size)
  669. {
  670. SaAisErrorT result;
  671. SaUint8T my_priority;
  672. SaTimeT my_retention_time;
  673. SaNameT my_publisher_name = {0, {0}};
  674. SaTimeT my_publish_time;
  675. SaEvtEventIdT my_event_id;
  676. int i;
  677. long *act_data;
  678. SaSizeT data_size;
  679. printf(" event_callback called\n");
  680. if (my_subscription_id != subscription_id) {
  681. printf("ERROR: sub ID: e=%x, a=%x\n",
  682. subscription_id, my_subscription_id);
  683. }
  684. if (my_event_data_size != event_data_size) {
  685. printf("ERROR: event data size e=%lld, a=%lld\n",
  686. event_data_size,
  687. my_event_data_size);
  688. }
  689. evt_pat_get_array.patternsNumber = 4;
  690. do {
  691. result = saEvtEventAttributesGet(event_handle,
  692. &evt_pat_get_array, /* patterns */
  693. &my_priority, /* priority */
  694. &my_retention_time, /* retention time */
  695. &my_publisher_name, /* publisher name */
  696. &my_publish_time, /* publish time */
  697. &my_event_id /* event_id */
  698. );
  699. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  700. if (result != SA_AIS_OK) {
  701. get_sa_error(result, result_buf, result_buf_len);
  702. printf("ERROR: event get attr result(2): %s\n", result_buf);
  703. goto evt_free;
  704. }
  705. if (my_event_id != event_id) {
  706. printf("ERROR: Call back event ID error: e=%llx, a=%llx\n",
  707. (unsigned long long)event_id, (unsigned long long)my_event_id);
  708. }
  709. if (evt_pat_get_array.patternsNumber != 4) {
  710. printf("ERROR: pattern array count not 4: %lld\n",
  711. evt_pat_get_array.patternsNumber);
  712. }
  713. for (i = 0; i < evt_pat_get_array.patternsNumber; i++) {
  714. if (evt_pat_get_array.patterns[i].patternSize !=
  715. evt_pat_set_array.patterns[i].patternSize) {
  716. printf("ERROR: pattern %d count not equal g=%lld, s=%lld\n",
  717. i,
  718. evt_pat_get_array.patterns[i].patternSize,
  719. evt_pat_set_array.patterns[i].patternSize);
  720. printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
  721. i,
  722. evt_pat_get_array.patterns[i].pattern,
  723. evt_pat_set_array.patterns[i].pattern);
  724. } else {
  725. if (memcmp(evt_pat_get_array.patterns[i].pattern,
  726. evt_pat_set_array.patterns[i].pattern,
  727. evt_pat_get_array.patterns[i].patternSize) != 0){
  728. printf(
  729. "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
  730. i,
  731. evt_pat_get_array.patterns[i].pattern,
  732. evt_pat_set_array.patterns[i].pattern);
  733. }
  734. }
  735. }
  736. if (priority != my_priority) {
  737. printf("ERROR: priority: e=0x%x a=0x%x\n",
  738. priority, my_priority);
  739. }
  740. if (retention_time != my_retention_time) {
  741. printf("ERROR: retention: e=0x%llx a=0x%llx\n",
  742. (unsigned long long)retention_time,
  743. (unsigned long long)my_retention_time);
  744. }
  745. if (publisher_name.length != my_publisher_name.length) {
  746. printf("ERROR: publisher name length: e=%d, a=%d\n",
  747. publisher_name.length,
  748. my_publisher_name.length);
  749. } else {
  750. if (memcmp(publisher_name.value, my_publisher_name.value,
  751. publisher_name.length) != 0) {
  752. printf("ERROR: publisher name content: e=%s, a=%s\n",
  753. publisher_name.value,
  754. my_publisher_name.value);
  755. }
  756. }
  757. act_data = malloc(my_event_data_size);
  758. memset(act_data, 0, my_event_data_size);
  759. data_size = my_event_data_size;
  760. do {
  761. result = saEvtEventDataGet(event_handle, act_data, &data_size);
  762. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  763. if (result != SA_AIS_OK) {
  764. get_sa_error(result, result_buf, result_buf_len);
  765. printf("ERROR: event data get result: %s\n", result_buf);
  766. goto dat_free;
  767. }
  768. if (data_size != event_data_size) {
  769. printf("ERROR: Data size: e=%lld a=%lld\n",
  770. event_data_size, data_size);
  771. }
  772. for (i = 0; i < (data_size/sizeof(long)); i++) {
  773. if (act_data[i] != exp_data[i]) {
  774. printf("ERROR: Event Data e=%lx a=%lx at index %d\n",
  775. exp_data[i], act_data[i], i);
  776. break;
  777. }
  778. }
  779. dat_free:
  780. free(act_data);
  781. evt_free:
  782. do {
  783. result = saEvtEventFree(event_handle);
  784. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  785. if (result != SA_AIS_OK) {
  786. get_sa_error(result, result_buf, result_buf_len);
  787. printf("ERROR: event free result: %s\n", result_buf);
  788. }
  789. }
  790. void
  791. test_event()
  792. {
  793. SaEvtHandleT handle;
  794. SaEvtChannelHandleT channel_handle;
  795. SaEvtEventHandleT event_handle;
  796. SaEvtChannelOpenFlagsT flags;
  797. SaNameT channel_name;
  798. SaTimeT publish_time;
  799. struct pollfd pfd;
  800. int nfd;
  801. SaSelectionObjectT fd;
  802. int timeout = 5000;
  803. SaAisErrorT result;
  804. int i;
  805. flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER |
  806. SA_EVT_CHANNEL_CREATE;
  807. strcpy(channel_name.value, channel);
  808. channel_name.length = strlen(channel);
  809. printf("Test Event operations:\n");
  810. do {
  811. result = saEvtInitialize (&handle, &callbacks, versions[0].version);
  812. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  813. if (result != SA_AIS_OK) {
  814. get_sa_error(result, result_buf, result_buf_len);
  815. printf("ERROR: Event Initialize result: %s\n", result_buf);
  816. return;
  817. }
  818. do {
  819. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  820. &channel_handle);
  821. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  822. if (result != SA_AIS_OK) {
  823. get_sa_error(result, result_buf, result_buf_len);
  824. printf("ERROR: channel open result: %s\n", result_buf);
  825. goto evt_fin;
  826. }
  827. /*
  828. * Allocate an event
  829. */
  830. printf(" Event allocation\n");
  831. do {
  832. result = saEvtEventAllocate(channel_handle, &event_handle);
  833. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  834. if (result != SA_AIS_OK) {
  835. get_sa_error(result, result_buf, result_buf_len);
  836. printf("ERROR: event Allocate result: %s\n", result_buf);
  837. goto evt_close;
  838. }
  839. printf(" Get event attributes(1)\n");
  840. do {
  841. result = saEvtEventAttributesGet(event_handle,
  842. 0, /* patterns */
  843. 0, /* priority */
  844. 0, /* retention time */
  845. 0, /* publisher name */
  846. 0, /* publish time */
  847. 0 /* event_id */
  848. );
  849. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  850. if (result != SA_AIS_OK) {
  851. get_sa_error(result, result_buf, result_buf_len);
  852. printf("ERROR: event get attr result(1): %s\n", result_buf);
  853. goto evt_free;
  854. }
  855. /*
  856. * Get event attributes, this time supply pointers.
  857. * validate the default values.
  858. */
  859. printf(" Get event attributes(2)\n");
  860. evt_pat_get_array.patternsNumber = 4;
  861. do {
  862. result = saEvtEventAttributesGet(event_handle,
  863. &evt_pat_get_array, /* patterns */
  864. &priority, /* priority */
  865. &retention_time, /* retention time */
  866. &publisher_name, /* publisher name */
  867. &publish_time, /* publish time */
  868. &event_id /* event_id */
  869. );
  870. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  871. if (result != SA_AIS_OK) {
  872. get_sa_error(result, result_buf, result_buf_len);
  873. printf("ERROR: event get attr result(2): %s\n", result_buf);
  874. goto evt_free;
  875. }
  876. if (evt_pat_get_array.patternsNumber != 0) {
  877. printf("ERROR: pattern array count not zero: %lld\n",
  878. evt_pat_get_array.patternsNumber);
  879. }
  880. if (priority != SA_EVT_LOWEST_PRIORITY) {
  881. printf("ERROR: priority not lowest: 0x%x\n", priority);
  882. }
  883. if (retention_time != 0) {
  884. printf("ERROR: retention time not zero: %0llx\n",
  885. (unsigned long long)retention_time);
  886. }
  887. if (publisher_name.length != 0) {
  888. printf("ERROR: publisher name not null: %s\n", publisher_name.value);
  889. }
  890. if (event_id != 0) {
  891. printf("ERROR: event id not zero: 0x%llx\n",
  892. (unsigned long long)event_id);
  893. }
  894. /*
  895. * Set some attributes, then read them back
  896. */
  897. printf(" Set/get event attributes(1)\n");
  898. do {
  899. result = saEvtEventAttributesSet(event_handle,
  900. &evt_pat_set_array,
  901. TEST_PRIORITY,
  902. test_ret_time,
  903. &test_pub_name);
  904. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  905. if (result != SA_AIS_OK) {
  906. get_sa_error(result, result_buf, result_buf_len);
  907. printf("ERROR: event set attr result(1): %s\n", result_buf);
  908. goto evt_free;
  909. }
  910. evt_pat_get_array.patternsNumber = 4;
  911. do {
  912. result = saEvtEventAttributesGet(event_handle,
  913. &evt_pat_get_array, /* patterns */
  914. &priority, /* priority */
  915. &retention_time, /* retention time */
  916. &publisher_name, /* publisher name */
  917. &publish_time, /* publish time */
  918. &event_id /* event_id */
  919. );
  920. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  921. if (result != SA_AIS_OK) {
  922. get_sa_error(result, result_buf, result_buf_len);
  923. printf("ERROR: event get attr result(2): %s\n", result_buf);
  924. goto evt_free;
  925. }
  926. if (evt_pat_get_array.patternsNumber != 4) {
  927. printf("ERROR: pattern array count not 4: %lld\n",
  928. evt_pat_get_array.patternsNumber);
  929. }
  930. for (i = 0; i < evt_pat_get_array.patternsNumber; i++) {
  931. if (evt_pat_get_array.patterns[i].patternSize !=
  932. evt_pat_set_array.patterns[i].patternSize) {
  933. printf("ERROR: pattern %d count not equal g=%lld, s=%lld\n",
  934. i,
  935. evt_pat_get_array.patterns[i].patternSize,
  936. evt_pat_set_array.patterns[i].patternSize);
  937. printf("ERROR: pattern %d content g=\"%s\", s=\"%s\"\n",
  938. i,
  939. evt_pat_get_array.patterns[i].pattern,
  940. evt_pat_set_array.patterns[i].pattern);
  941. } else {
  942. if (memcmp(evt_pat_get_array.patterns[i].pattern,
  943. evt_pat_set_array.patterns[i].pattern,
  944. evt_pat_get_array.patterns[i].patternSize) != 0){
  945. printf(
  946. "ERROR: pattern %d don't match g=\"%s\", s=\"%s\"\n",
  947. i,
  948. evt_pat_get_array.patterns[i].pattern,
  949. evt_pat_set_array.patterns[i].pattern);
  950. }
  951. }
  952. }
  953. if (priority != TEST_PRIORITY) {
  954. printf("ERROR: priority: e=0x%x a=0x%x\n",
  955. TEST_PRIORITY, priority);
  956. }
  957. if (retention_time != test_ret_time) {
  958. printf("ERROR: retention: e=0x%llx a=0x%llx\n",
  959. (unsigned long long)test_ret_time,
  960. (unsigned long long)retention_time);
  961. }
  962. if (publisher_name.length != test_pub_name.length) {
  963. printf("ERROR: publisher name length: e=%d, a=%d\n",
  964. test_pub_name.length,
  965. publisher_name.length);
  966. } else {
  967. if (memcmp(publisher_name.value, test_pub_name.value,
  968. publisher_name.length) != 0) {
  969. printf("ERROR: publisher name content: e=%s, a=%s\n",
  970. test_pub_name.value,
  971. publisher_name.value);
  972. }
  973. }
  974. if (event_id != 0) {
  975. printf("ERROR: event id not zero: 0x%llx\n",
  976. (unsigned long long)event_id);
  977. }
  978. /*
  979. * event user data
  980. */
  981. printf(" Get event data(1)\n");
  982. do {
  983. result = saEvtEventDataGet(event_handle, 0, 0);
  984. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  985. if (result != SA_AIS_OK) {
  986. get_sa_error(result, result_buf, result_buf_len);
  987. printf("ERROR: Get event data(1) result: %s\n", result_buf);
  988. }
  989. printf(" Get event data(2)\n");
  990. do {
  991. result = saEvtEventDataGet(event_handle, event_data, 0);
  992. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  993. if (result != SA_AIS_OK) {
  994. get_sa_error(result, result_buf, result_buf_len);
  995. printf("ERROR: Get event data(2) result: %s\n", result_buf);
  996. }
  997. printf(" Get event data(3)\n");
  998. event_data_size = EVENT_DATA_SIZE;
  999. do {
  1000. result = saEvtEventDataGet(event_handle, 0, &event_data_size);
  1001. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1002. if (result != SA_AIS_OK) {
  1003. get_sa_error(result, result_buf, result_buf_len);
  1004. printf("ERROR: Get event data(3) result: %s\n", result_buf);
  1005. }
  1006. printf(" Get event data(4)\n");
  1007. event_data_size = EVENT_DATA_SIZE;
  1008. do {
  1009. result = saEvtEventDataGet(event_handle, event_data,
  1010. &event_data_size);
  1011. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1012. if (result != SA_AIS_OK) {
  1013. get_sa_error(result, result_buf, result_buf_len);
  1014. printf("ERROR: Get event data(4) result: %s\n", result_buf);
  1015. }
  1016. printf(" Get event data(5)\n");
  1017. event_data_size = 1;
  1018. do {
  1019. result = saEvtEventDataGet(event_handle, event_data,
  1020. &event_data_size);
  1021. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1022. if (result != SA_AIS_OK) {
  1023. get_sa_error(result, result_buf, result_buf_len);
  1024. printf("ERROR: Get event data(5) result: %s\n", result_buf);
  1025. }
  1026. printf(" Free event(1)\n");
  1027. do {
  1028. result = saEvtEventFree(event_handle);
  1029. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1030. if (result != SA_AIS_OK) {
  1031. get_sa_error(result, result_buf, result_buf_len);
  1032. printf("ERROR: event free result: %s\n", result_buf);
  1033. }
  1034. /*
  1035. * Test publication.
  1036. */
  1037. printf(" Publish with no patterns set\n");
  1038. do {
  1039. result = saEvtEventAllocate(channel_handle, &event_handle);
  1040. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1041. if (result != SA_AIS_OK) {
  1042. get_sa_error(result, result_buf, result_buf_len);
  1043. printf("ERROR: event Allocate result: %s\n", result_buf);
  1044. goto evt_close;
  1045. }
  1046. do {
  1047. result = saEvtEventPublish(event_handle, 0, 0, &event_id);
  1048. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1049. if (result != SA_AIS_ERR_INVALID_PARAM) {
  1050. get_sa_error(result, result_buf, result_buf_len);
  1051. printf("ERROR: event Publish result(1): %s\n", result_buf);
  1052. goto evt_close;
  1053. }
  1054. /*
  1055. * Publish with pattens
  1056. */
  1057. printf(" Publish with patterns set\n");
  1058. do {
  1059. result = saEvtEventSubscribe(channel_handle,
  1060. &subscribe_filters,
  1061. subscription_id);
  1062. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1063. if (result != SA_AIS_OK) {
  1064. get_sa_error(result, result_buf, result_buf_len);
  1065. printf("ERROR: event subscribe result: %s\n", result_buf);
  1066. do {
  1067. result = saEvtChannelClose(channel_handle);
  1068. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1069. if (result != SA_AIS_OK) {
  1070. get_sa_error(result, result_buf, result_buf_len);
  1071. printf("ERROR: Channel close result: %s\n", result_buf);
  1072. }
  1073. do {
  1074. result = saEvtFinalize(handle);
  1075. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1076. if (result != SA_AIS_OK) {
  1077. get_sa_error(result, result_buf, result_buf_len);
  1078. printf("ERROR: Finalize result: %s\n", result_buf);
  1079. }
  1080. return;
  1081. }
  1082. retention_time = 0ULL;
  1083. do {
  1084. result = saEvtEventAttributesSet(event_handle,
  1085. &evt_pat_set_array,
  1086. TEST_PRIORITY,
  1087. retention_time,
  1088. &test_pub_name);
  1089. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1090. if (result != SA_AIS_OK) {
  1091. get_sa_error(result, result_buf, result_buf_len);
  1092. printf("ERROR: event set attr result(2): %s\n", result_buf);
  1093. goto evt_free;
  1094. }
  1095. /*
  1096. * Generate event data
  1097. */
  1098. exp_data = malloc(DATA_SIZE);
  1099. for (i = 0; i < LCOUNT; i++) {
  1100. exp_data[i] = lrand48();
  1101. }
  1102. event_data_size = DATA_SIZE;
  1103. /*
  1104. * Send it
  1105. */
  1106. do {
  1107. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1108. &event_id);
  1109. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1110. if (result != SA_AIS_OK) {
  1111. get_sa_error(result, result_buf, result_buf_len);
  1112. printf("ERROR: event Publish result(2): %s\n", result_buf);
  1113. goto evt_close;
  1114. }
  1115. /*
  1116. * See if we got the event
  1117. */
  1118. do {
  1119. result = saEvtSelectionObjectGet(handle, &fd);
  1120. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1121. if (result != SA_AIS_OK) {
  1122. get_sa_error(result, result_buf, result_buf_len);
  1123. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  1124. /* error */
  1125. return;
  1126. }
  1127. pfd.fd = fd;
  1128. pfd.events = POLLIN;
  1129. nfd = poll(&pfd, 1, timeout);
  1130. if (nfd <= 0) {
  1131. printf("ERROR: poll fds %d\n", nfd);
  1132. if (nfd < 0) {
  1133. perror("ERROR: poll error");
  1134. }
  1135. /* Error */
  1136. return;
  1137. }
  1138. do {
  1139. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  1140. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1141. if (result != SA_AIS_OK) {
  1142. get_sa_error(result, result_buf, result_buf_len);
  1143. printf("ERROR: saEvtDispatch %s\n", result_buf);
  1144. /* error */
  1145. return;
  1146. }
  1147. /*
  1148. * Test cleanup
  1149. */
  1150. evt_free:
  1151. do {
  1152. result = saEvtEventFree(event_handle);
  1153. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1154. if (result != SA_AIS_OK) {
  1155. get_sa_error(result, result_buf, result_buf_len);
  1156. printf("ERROR: event free result: %s\n", result_buf);
  1157. }
  1158. evt_close:
  1159. do {
  1160. result = saEvtChannelClose(channel_handle);
  1161. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1162. if (result != SA_AIS_OK) {
  1163. get_sa_error(result, result_buf, result_buf_len);
  1164. printf("ERROR: channel close result: %s\n", result_buf);
  1165. }
  1166. evt_fin:
  1167. do {
  1168. result = saEvtFinalize(handle);
  1169. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1170. if (result != SA_AIS_OK) {
  1171. get_sa_error(result, result_buf, result_buf_len);
  1172. printf("ERROR: Event Finalize result: %s\n", result_buf);
  1173. }
  1174. printf("Done\n");
  1175. }
  1176. SaEvtEventIdT event_id1;
  1177. SaEvtEventIdT event_id2;
  1178. SaEvtEventIdT event_id3;
  1179. SaEvtSubscriptionIdT sub1 = 0x101010;
  1180. SaEvtSubscriptionIdT sub2 = 0x202020;
  1181. static int call_count = 0;
  1182. /*
  1183. * Handle call back for multi-test1
  1184. * Checks event ID with subscription ID to make sure that we
  1185. * received an event on the correct subscription.
  1186. */
  1187. void
  1188. multi_test_callback1(SaEvtSubscriptionIdT my_subscription_id,
  1189. const SaEvtEventHandleT event_handle,
  1190. const SaSizeT my_event_data_size)
  1191. {
  1192. SaAisErrorT result;
  1193. SaUint8T my_priority;
  1194. SaTimeT my_retention_time;
  1195. SaNameT my_publisher_name = {0, {0}};
  1196. SaTimeT my_publish_time;
  1197. SaEvtEventIdT my_event_id;
  1198. SaEvtSubscriptionIdT exp_sub_id;
  1199. printf(" multi_test_callback1 called(%d)\n", ++call_count);
  1200. evt_pat_get_array.patternsNumber = 4;
  1201. do {
  1202. result = saEvtEventAttributesGet(event_handle,
  1203. &evt_pat_get_array, /* patterns */
  1204. &my_priority, /* priority */
  1205. &my_retention_time, /* retention time */
  1206. &my_publisher_name, /* publisher name */
  1207. &my_publish_time, /* publish time */
  1208. &my_event_id /* event_id */
  1209. );
  1210. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1211. if (result != SA_AIS_OK) {
  1212. get_sa_error(result, result_buf, result_buf_len);
  1213. printf("ERROR: event get attr result: %s\n", result_buf);
  1214. goto evt_free;
  1215. }
  1216. if (my_event_id == event_id1) {
  1217. exp_sub_id = sub1;
  1218. } else if (my_event_id == event_id2) {
  1219. exp_sub_id = sub2;
  1220. } else if (my_event_id == event_id3) {
  1221. printf("ERROR: Received event 3 but not subscribed\n");
  1222. goto evt_free;
  1223. } else {
  1224. printf("ERROR: Received event %llx but not sent\n",
  1225. (unsigned long long)my_event_id);
  1226. goto evt_free;
  1227. }
  1228. if (my_subscription_id != exp_sub_id) {
  1229. printf("ERROR: sub ID: e=%x, a=%x\n",
  1230. exp_sub_id, my_subscription_id);
  1231. goto evt_free;
  1232. }
  1233. if (evt_pat_get_array.patternsNumber != 1) {
  1234. printf("ERROR: pattern array count not 1: %lld\n",
  1235. evt_pat_get_array.patternsNumber);
  1236. }
  1237. evt_free:
  1238. do {
  1239. result = saEvtEventFree(event_handle);
  1240. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1241. if (result != SA_AIS_OK) {
  1242. get_sa_error(result, result_buf, result_buf_len);
  1243. printf("ERROR: event free result: %s\n", result_buf);
  1244. }
  1245. }
  1246. /*
  1247. * Test multiple channel operations
  1248. * 1. Test multiple subscriptions on a single channel and receiving
  1249. * events.
  1250. * 2. Test multiple openings of a single channel and receving events.
  1251. * 3. Test opening of multiple channels and receiving events
  1252. */
  1253. void
  1254. test_multi_channel1()
  1255. {
  1256. SaEvtEventFilterT filt1[1] = {
  1257. {SA_EVT_EXACT_FILTER, {8,8, "ChanPat1"}},
  1258. };
  1259. SaEvtEventFilterT filt2[1] = {
  1260. {SA_EVT_EXACT_FILTER, {8, 8, "ChanPat2"}},
  1261. };
  1262. SaEvtEventFilterArrayT sub_filt = {
  1263. 1, NULL
  1264. };
  1265. SaEvtEventPatternT pat1 = {8, 8, "ChanPat1"};
  1266. SaEvtEventPatternT pat2 = {8, 8, "ChanPat2"};
  1267. SaEvtEventPatternT pat3 = {8, 8, "ChanPat3"};
  1268. SaEvtEventPatternArrayT evt_pat = {
  1269. 1, 1, NULL
  1270. };
  1271. SaEvtHandleT handle;
  1272. SaEvtChannelHandleT channel_handle;
  1273. SaEvtEventHandleT event_handle;
  1274. SaEvtChannelOpenFlagsT flags;
  1275. SaNameT channel_name;
  1276. SaEvtCallbacksT multi_callbacks = {
  1277. 0,
  1278. multi_test_callback1
  1279. };
  1280. struct pollfd pfd;
  1281. int nfd;
  1282. SaSelectionObjectT fd;
  1283. int timeout = 5000;
  1284. SaAisErrorT result;
  1285. flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER |
  1286. SA_EVT_CHANNEL_CREATE;
  1287. strcpy(channel_name.value, channel);
  1288. channel_name.length = strlen(channel);
  1289. printf("Test multiple operations:\n");
  1290. do {
  1291. result = saEvtInitialize (&handle, &multi_callbacks,
  1292. versions[0].version);
  1293. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1294. if (result != SA_AIS_OK) {
  1295. get_sa_error(result, result_buf, result_buf_len);
  1296. printf("ERROR: Event Initialize result: %s\n", result_buf);
  1297. return;
  1298. }
  1299. do {
  1300. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  1301. &channel_handle);
  1302. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1303. if (result != SA_AIS_OK) {
  1304. get_sa_error(result, result_buf, result_buf_len);
  1305. printf("ERROR: channel open result: %s\n", result_buf);
  1306. goto evt_fin;
  1307. }
  1308. /*
  1309. * Allocate an event
  1310. */
  1311. do {
  1312. result = saEvtEventAllocate(channel_handle, &event_handle);
  1313. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1314. if (result != SA_AIS_OK) {
  1315. get_sa_error(result, result_buf, result_buf_len);
  1316. printf("ERROR: event Allocate result: %s\n", result_buf);
  1317. goto evt_close;
  1318. }
  1319. /*
  1320. * 1. Test multiple subscriptions on a single channel and receiving
  1321. * events.
  1322. *
  1323. * Subscribe twice with two different filters. Then send three events.
  1324. * One will match the first filter, the second will match the second
  1325. * filter, the third will match none. We will validate that we receive
  1326. * two events and that the subscription IDs match what we expect for the
  1327. * given pattern.
  1328. */
  1329. sub_filt.filters = filt1;
  1330. do {
  1331. result = saEvtEventSubscribe(channel_handle,
  1332. &sub_filt,
  1333. sub1);
  1334. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1335. if (result != SA_AIS_OK) {
  1336. get_sa_error(result, result_buf, result_buf_len);
  1337. printf("ERROR: event subscribe(1) result: %s\n", result_buf);
  1338. goto evt_free;
  1339. }
  1340. sub_filt.filters = filt2;
  1341. do {
  1342. result = saEvtEventSubscribe(channel_handle,
  1343. &sub_filt,
  1344. sub2);
  1345. } 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 subscribe(2) result: %s\n", result_buf);
  1349. goto evt_free;
  1350. }
  1351. retention_time = 0ULL;
  1352. evt_pat.patterns = &pat1;
  1353. do {
  1354. result = saEvtEventAttributesSet(event_handle,
  1355. &evt_pat,
  1356. TEST_PRIORITY,
  1357. retention_time,
  1358. &test_pub_name);
  1359. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1360. if (result != SA_AIS_OK) {
  1361. get_sa_error(result, result_buf, result_buf_len);
  1362. printf("ERROR: event set attr result(1): %s\n", result_buf);
  1363. goto evt_free;
  1364. }
  1365. do {
  1366. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1367. &event_id1);
  1368. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1369. if (result != SA_AIS_OK) {
  1370. get_sa_error(result, result_buf, result_buf_len);
  1371. printf("ERROR: event Publish result:(1) %s\n", result_buf);
  1372. goto evt_close;
  1373. }
  1374. evt_pat.patterns = &pat2;
  1375. do {
  1376. result = saEvtEventAttributesSet(event_handle,
  1377. &evt_pat,
  1378. TEST_PRIORITY,
  1379. retention_time,
  1380. &test_pub_name);
  1381. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1382. if (result != SA_AIS_OK) {
  1383. get_sa_error(result, result_buf, result_buf_len);
  1384. printf("ERROR: event set attr result(2): %s\n", result_buf);
  1385. goto evt_free;
  1386. }
  1387. do {
  1388. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1389. &event_id2);
  1390. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1391. if (result != SA_AIS_OK) {
  1392. get_sa_error(result, result_buf, result_buf_len);
  1393. printf("ERROR: event Publish result:(2) %s\n", result_buf);
  1394. goto evt_close;
  1395. }
  1396. evt_pat.patterns = &pat3;
  1397. do {
  1398. result = saEvtEventAttributesSet(event_handle,
  1399. &evt_pat,
  1400. TEST_PRIORITY,
  1401. retention_time,
  1402. &test_pub_name);
  1403. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1404. if (result != SA_AIS_OK) {
  1405. get_sa_error(result, result_buf, result_buf_len);
  1406. printf("ERROR: event set attr result(3): %s\n", result_buf);
  1407. goto evt_free;
  1408. }
  1409. do {
  1410. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1411. &event_id3);
  1412. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1413. if (result != SA_AIS_OK) {
  1414. get_sa_error(result, result_buf, result_buf_len);
  1415. printf("ERROR: event Publish result:(3) %s\n", result_buf);
  1416. goto evt_close;
  1417. }
  1418. /*
  1419. * See if we got the event
  1420. */
  1421. do {
  1422. result = saEvtSelectionObjectGet(handle, &fd);
  1423. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1424. if (result != SA_AIS_OK) {
  1425. get_sa_error(result, result_buf, result_buf_len);
  1426. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  1427. /* error */
  1428. return;
  1429. }
  1430. while(1) {
  1431. pfd.fd = fd;
  1432. pfd.events = POLLIN;
  1433. nfd = poll(&pfd, 1, timeout);
  1434. if (nfd == 0) {
  1435. break;
  1436. } else if (nfd < 0) {
  1437. perror("ERROR: poll error");
  1438. break;
  1439. }
  1440. do {
  1441. result = saEvtDispatch(handle, SA_DISPATCH_ALL);
  1442. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1443. if (result != SA_AIS_OK) {
  1444. get_sa_error(result, result_buf, result_buf_len);
  1445. printf("ERROR: saEvtDispatch %s\n", result_buf);
  1446. /* error */
  1447. goto evt_free;
  1448. }
  1449. }
  1450. if (call_count != 2) {
  1451. printf("ERROR: call back count: e=2, a=%d\n", call_count);
  1452. goto evt_free;
  1453. }
  1454. /*
  1455. * Test cleanup
  1456. */
  1457. evt_free:
  1458. do {
  1459. result = saEvtEventFree(event_handle);
  1460. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1461. if (result != SA_AIS_OK) {
  1462. get_sa_error(result, result_buf, result_buf_len);
  1463. printf("ERROR: event free result: %s\n", result_buf);
  1464. }
  1465. evt_close:
  1466. do {
  1467. result = saEvtChannelClose(channel_handle);
  1468. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1469. if (result != SA_AIS_OK) {
  1470. get_sa_error(result, result_buf, result_buf_len);
  1471. printf("ERROR: channel close result: %s\n", result_buf);
  1472. }
  1473. evt_fin:
  1474. do {
  1475. result = saEvtFinalize(handle);
  1476. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1477. if (result != SA_AIS_OK) {
  1478. get_sa_error(result, result_buf, result_buf_len);
  1479. printf("ERROR: Event Finalize result: %s\n", result_buf);
  1480. }
  1481. printf("Done\n");
  1482. }
  1483. /*
  1484. * Handle call back for multi-test2
  1485. * Counts events received. Makes sure that we get one event from
  1486. * each subscription.
  1487. *
  1488. */
  1489. void
  1490. multi_test_callback2(SaEvtSubscriptionIdT my_subscription_id,
  1491. const SaEvtEventHandleT event_handle,
  1492. const SaSizeT my_event_data_size)
  1493. {
  1494. SaAisErrorT result;
  1495. SaUint8T my_priority;
  1496. SaTimeT my_retention_time;
  1497. SaNameT my_publisher_name = {0, {0}};
  1498. SaTimeT my_publish_time;
  1499. SaEvtEventIdT my_event_id;
  1500. SaEvtSubscriptionIdT last_sub_id = 0;
  1501. printf(" multi_test_callback2 called(%d)\n", ++call_count);
  1502. evt_pat_get_array.patternsNumber = 4;
  1503. do {
  1504. result = saEvtEventAttributesGet(event_handle,
  1505. &evt_pat_get_array, /* patterns */
  1506. &my_priority, /* priority */
  1507. &my_retention_time, /* retention time */
  1508. &my_publisher_name, /* publisher name */
  1509. &my_publish_time, /* publish time */
  1510. &my_event_id /* event_id */
  1511. );
  1512. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1513. if (result != SA_AIS_OK) {
  1514. get_sa_error(result, result_buf, result_buf_len);
  1515. printf("ERROR: event get attr result: %s\n", result_buf);
  1516. goto evt_free;
  1517. }
  1518. if (my_event_id != event_id1) {
  1519. printf("ERROR: Received wrong event\n");
  1520. goto evt_free;
  1521. }
  1522. if (last_sub_id == 0) {
  1523. if (my_subscription_id != sub1 &&
  1524. my_subscription_id != sub2) {
  1525. printf("ERROR: Received bad subscription ID\n");
  1526. goto evt_free;
  1527. }
  1528. last_sub_id = my_subscription_id;
  1529. } else {
  1530. if (my_subscription_id == last_sub_id) {
  1531. printf("ERROR: Received subscription ID twice\n");
  1532. goto evt_free;
  1533. }
  1534. if (my_subscription_id != sub1 &&
  1535. my_subscription_id != sub2) {
  1536. printf("ERROR: Received bad subscription ID\n");
  1537. goto evt_free;
  1538. }
  1539. }
  1540. if (evt_pat_get_array.patternsNumber != 1) {
  1541. printf("ERROR: pattern array count not 1: %lld\n",
  1542. evt_pat_get_array.patternsNumber);
  1543. }
  1544. evt_free:
  1545. do {
  1546. result = saEvtEventFree(event_handle);
  1547. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1548. if (result != SA_AIS_OK) {
  1549. get_sa_error(result, result_buf, result_buf_len);
  1550. printf("ERROR: event free result: %s\n", result_buf);
  1551. }
  1552. }
  1553. void
  1554. test_multi_channel2()
  1555. {
  1556. SaEvtEventFilterT filt1[1] = {
  1557. {SA_EVT_EXACT_FILTER, {8, 8, "ChanPat1"}},
  1558. };
  1559. SaEvtEventFilterArrayT sub_filt = {
  1560. 1, NULL
  1561. };
  1562. SaEvtEventPatternT pat1 = {8, 8, "ChanPat1"};
  1563. SaEvtEventPatternArrayT evt_pat = {
  1564. 1, 1, NULL
  1565. };
  1566. SaEvtHandleT handle;
  1567. SaEvtChannelHandleT channel_handle;
  1568. SaEvtChannelHandleT channel_handle1;
  1569. SaEvtEventHandleT event_handle;
  1570. SaEvtChannelOpenFlagsT flags;
  1571. SaNameT channel_name;
  1572. SaEvtCallbacksT multi_callbacks = {
  1573. 0,
  1574. multi_test_callback2
  1575. };
  1576. struct pollfd pfd;
  1577. int nfd;
  1578. SaSelectionObjectT fd;
  1579. int timeout = 5000;
  1580. SaAisErrorT result;
  1581. flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER |
  1582. SA_EVT_CHANNEL_CREATE;
  1583. strcpy(channel_name.value, channel);
  1584. channel_name.length = strlen(channel);
  1585. /*
  1586. * 2. Test multiple openings of a single channel and receving events.
  1587. *
  1588. * Open and subscribe to a channel twice. When an event is sent, it
  1589. * should be delivered twice, once for each open channel.
  1590. */
  1591. printf("Test multiple opens/subscribes:\n");
  1592. do {
  1593. result = saEvtInitialize (&handle, &multi_callbacks,
  1594. versions[0].version);
  1595. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1596. if (result != SA_AIS_OK) {
  1597. get_sa_error(result, result_buf, result_buf_len);
  1598. printf("ERROR: Event Initialize result: %s\n", result_buf);
  1599. return;
  1600. }
  1601. do {
  1602. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  1603. &channel_handle);
  1604. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1605. if (result != SA_AIS_OK) {
  1606. get_sa_error(result, result_buf, result_buf_len);
  1607. printf("ERROR: channel open(0) result: %s\n", result_buf);
  1608. goto evt_fin;
  1609. }
  1610. do {
  1611. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  1612. &channel_handle1);
  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: channel open(1) result: %s\n", result_buf);
  1617. goto evt_fin;
  1618. }
  1619. do {
  1620. result = saEvtEventAllocate(channel_handle, &event_handle);
  1621. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1622. if (result != SA_AIS_OK) {
  1623. get_sa_error(result, result_buf, result_buf_len);
  1624. printf("ERROR: event Allocate result: %s\n", result_buf);
  1625. goto evt_close;
  1626. }
  1627. sub_filt.filters = filt1;
  1628. do {
  1629. result = saEvtEventSubscribe(channel_handle,
  1630. &sub_filt,
  1631. sub1);
  1632. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1633. if (result != SA_AIS_OK) {
  1634. get_sa_error(result, result_buf, result_buf_len);
  1635. printf("ERROR: event subscribe(0) result: %s\n", result_buf);
  1636. goto evt_free;
  1637. }
  1638. sub_filt.filters = filt1;
  1639. do {
  1640. result = saEvtEventSubscribe(channel_handle1,
  1641. &sub_filt,
  1642. sub2);
  1643. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1644. if (result != SA_AIS_OK) {
  1645. get_sa_error(result, result_buf, result_buf_len);
  1646. printf("ERROR: event subscribe(1) result: %s\n", result_buf);
  1647. goto evt_free;
  1648. }
  1649. retention_time = 0ULL;
  1650. evt_pat.patterns = &pat1;
  1651. do {
  1652. result = saEvtEventAttributesSet(event_handle,
  1653. &evt_pat,
  1654. TEST_PRIORITY,
  1655. retention_time,
  1656. &test_pub_name);
  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: event set attr result: %s\n", result_buf);
  1661. goto evt_free;
  1662. }
  1663. do {
  1664. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1665. &event_id1);
  1666. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1667. if (result != SA_AIS_OK) {
  1668. get_sa_error(result, result_buf, result_buf_len);
  1669. printf("ERROR: event Publish result: %s\n", result_buf);
  1670. goto evt_close;
  1671. }
  1672. /*
  1673. * See if we got the event
  1674. */
  1675. do {
  1676. result = saEvtSelectionObjectGet(handle, &fd);
  1677. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1678. if (result != SA_AIS_OK) {
  1679. get_sa_error(result, result_buf, result_buf_len);
  1680. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  1681. /* error */
  1682. return;
  1683. }
  1684. call_count = 0;
  1685. while(1) {
  1686. pfd.fd = fd;
  1687. pfd.events = POLLIN;
  1688. nfd = poll(&pfd, 1, timeout);
  1689. if (nfd == 0) {
  1690. break;
  1691. } else if (nfd < 0) {
  1692. perror("ERROR: poll error");
  1693. break;
  1694. }
  1695. do {
  1696. result = saEvtDispatch(handle, SA_DISPATCH_ALL);
  1697. } 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: saEvtDispatch %s\n", result_buf);
  1701. /* error */
  1702. goto evt_free;
  1703. }
  1704. }
  1705. if (call_count != 2) {
  1706. printf("ERROR: call back count: e=2, a=%d\n", call_count);
  1707. goto evt_free;
  1708. }
  1709. /*
  1710. * Test cleanup
  1711. */
  1712. evt_free:
  1713. do {
  1714. result = saEvtEventFree(event_handle);
  1715. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1716. if (result != SA_AIS_OK) {
  1717. get_sa_error(result, result_buf, result_buf_len);
  1718. printf("ERROR: event free result: %s\n", result_buf);
  1719. }
  1720. evt_close:
  1721. do {
  1722. result = saEvtChannelClose(channel_handle);
  1723. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1724. if (result != SA_AIS_OK) {
  1725. get_sa_error(result, result_buf, result_buf_len);
  1726. printf("ERROR: channel close result(0): %s\n", result_buf);
  1727. }
  1728. do {
  1729. result = saEvtChannelClose(channel_handle1);
  1730. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1731. if (result != SA_AIS_OK) {
  1732. get_sa_error(result, result_buf, result_buf_len);
  1733. printf("ERROR: channel close result(1): %s\n", result_buf);
  1734. }
  1735. evt_fin:
  1736. do {
  1737. result = saEvtFinalize(handle);
  1738. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1739. if (result != SA_AIS_OK) {
  1740. get_sa_error(result, result_buf, result_buf_len);
  1741. printf("ERROR: Event Finalize result: %s\n", result_buf);
  1742. }
  1743. printf("Done\n");
  1744. }
  1745. /*
  1746. * Handle call back for multi-test3
  1747. * Verifies that the event recevied is associated with the correct
  1748. * subscription.
  1749. *
  1750. */
  1751. void
  1752. multi_test_callback3(SaEvtSubscriptionIdT my_subscription_id,
  1753. const SaEvtEventHandleT event_handle,
  1754. const SaSizeT my_event_data_size)
  1755. {
  1756. SaAisErrorT result;
  1757. SaUint8T my_priority;
  1758. SaTimeT my_retention_time;
  1759. SaNameT my_publisher_name = {0, {0}};
  1760. SaTimeT my_publish_time;
  1761. SaEvtEventIdT my_event_id;
  1762. printf(" multi_test_callback2 called(%d)\n", ++call_count);
  1763. evt_pat_get_array.patternsNumber = 4;
  1764. do {
  1765. result = saEvtEventAttributesGet(event_handle,
  1766. &evt_pat_get_array, /* patterns */
  1767. &my_priority, /* priority */
  1768. &my_retention_time, /* retention time */
  1769. &my_publisher_name, /* publisher name */
  1770. &my_publish_time, /* publish time */
  1771. &my_event_id /* event_id */
  1772. );
  1773. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1774. if (result != SA_AIS_OK) {
  1775. get_sa_error(result, result_buf, result_buf_len);
  1776. printf("ERROR: event get attr result: %s\n", result_buf);
  1777. goto evt_free;
  1778. }
  1779. if ((my_subscription_id != sub1) && (my_subscription_id != sub2)) {
  1780. printf("ERROR: Received wrong subscription ID %x\n",
  1781. my_subscription_id);
  1782. printf(" sub1 %x, sub2 %x\n", sub1, sub2);
  1783. goto evt_free;
  1784. }
  1785. if ((my_event_id != event_id1) && (my_event_id != event_id2)) {
  1786. printf("ERROR: Received wrong event ID %llx\n",
  1787. (unsigned long long)my_event_id);
  1788. printf(" id1 %llx, id2 %llx\n",
  1789. (unsigned long long)event_id1,
  1790. (unsigned long long)event_id2);
  1791. goto evt_free;
  1792. }
  1793. if ((my_subscription_id == sub1) && (my_event_id != event_id1)) {
  1794. printf("ERROR: Received event on wrong subscription\n");
  1795. goto evt_free;
  1796. }
  1797. if ((my_subscription_id == sub2) && (my_event_id != event_id2)) {
  1798. printf("ERROR: Received event on wrong subscription\n");
  1799. goto evt_free;
  1800. }
  1801. if (evt_pat_get_array.patternsNumber != 1) {
  1802. printf("ERROR: pattern array count not 1: %lld\n",
  1803. evt_pat_get_array.patternsNumber);
  1804. }
  1805. evt_free:
  1806. do {
  1807. result = saEvtEventFree(event_handle);
  1808. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1809. if (result != SA_AIS_OK) {
  1810. get_sa_error(result, result_buf, result_buf_len);
  1811. printf("ERROR: event free result: %s\n", result_buf);
  1812. }
  1813. }
  1814. void
  1815. test_multi_channel3()
  1816. {
  1817. SaEvtEventFilterT filt1[1] = {
  1818. {SA_EVT_PREFIX_FILTER, {7, 7, "ChanPat"}},
  1819. };
  1820. SaEvtEventFilterArrayT sub_filt = {
  1821. 1, NULL
  1822. };
  1823. SaEvtEventPatternT pat1 = {8, 8, "ChanPat1"};
  1824. SaEvtEventPatternT pat2 = {8, 8, "ChanPat2"};
  1825. SaEvtEventPatternArrayT evt_pat = {
  1826. 1, 1, NULL
  1827. };
  1828. SaEvtHandleT handle;
  1829. SaEvtChannelHandleT channel_handle;
  1830. SaEvtChannelHandleT channel_handle1;
  1831. SaEvtEventHandleT event_handle;
  1832. SaEvtEventHandleT event_handle1;
  1833. SaEvtChannelOpenFlagsT flags;
  1834. SaNameT channel_name;
  1835. SaNameT channel_name1;
  1836. SaEvtCallbacksT multi_callbacks = {
  1837. 0,
  1838. multi_test_callback3
  1839. };
  1840. struct pollfd pfd;
  1841. int nfd;
  1842. SaSelectionObjectT fd;
  1843. int timeout = 5000;
  1844. SaAisErrorT result;
  1845. flags = SA_EVT_CHANNEL_PUBLISHER|SA_EVT_CHANNEL_SUBSCRIBER |
  1846. SA_EVT_CHANNEL_CREATE;
  1847. strcpy(channel_name.value, channel);
  1848. channel_name.length = strlen(channel_name.value);
  1849. strcpy(channel_name1.value, channel);
  1850. strcat(channel_name1.value, "_1");
  1851. channel_name1.length = strlen(channel_name1.value);
  1852. /*
  1853. * 3. Test opening of multiple channels and receiving events.
  1854. * Open and subscribe to two different channels twice.
  1855. * Subscribe to each channel with the same filters.
  1856. * Sending an event on one channel should be received in the
  1857. * call-back with the subscription ID corresponding to the sent
  1858. * channel.
  1859. */
  1860. printf("Test multiple different channels/subscribes:\n");
  1861. do {
  1862. result = saEvtInitialize (&handle, &multi_callbacks,
  1863. versions[0].version);
  1864. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1865. if (result != SA_AIS_OK) {
  1866. get_sa_error(result, result_buf, result_buf_len);
  1867. printf("ERROR: Event Initialize result: %s\n", result_buf);
  1868. return;
  1869. }
  1870. do {
  1871. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  1872. &channel_handle);
  1873. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1874. if (result != SA_AIS_OK) {
  1875. get_sa_error(result, result_buf, result_buf_len);
  1876. printf("ERROR: channel open(0) result: %s\n", result_buf);
  1877. goto evt_fin;
  1878. }
  1879. do {
  1880. result = saEvtChannelOpen(handle, &channel_name1, flags, 0,
  1881. &channel_handle1);
  1882. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1883. if (result != SA_AIS_OK) {
  1884. get_sa_error(result, result_buf, result_buf_len);
  1885. printf("ERROR: channel open(1) result: %s\n", result_buf);
  1886. goto evt_fin;
  1887. }
  1888. do {
  1889. result = saEvtEventAllocate(channel_handle, &event_handle);
  1890. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1891. if (result != SA_AIS_OK) {
  1892. get_sa_error(result, result_buf, result_buf_len);
  1893. printf("ERROR: event Allocate(0) result: %s\n", result_buf);
  1894. goto evt_close;
  1895. }
  1896. do {
  1897. result = saEvtEventAllocate(channel_handle1, &event_handle1);
  1898. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1899. if (result != SA_AIS_OK) {
  1900. get_sa_error(result, result_buf, result_buf_len);
  1901. printf("ERROR: event Allocate(1) result: %s\n", result_buf);
  1902. goto evt_close;
  1903. }
  1904. sub_filt.filters = filt1;
  1905. do {
  1906. result = saEvtEventSubscribe(channel_handle,
  1907. &sub_filt,
  1908. sub1);
  1909. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1910. if (result != SA_AIS_OK) {
  1911. get_sa_error(result, result_buf, result_buf_len);
  1912. printf("ERROR: event subscribe(0) result: %s\n", result_buf);
  1913. goto evt_free;
  1914. }
  1915. sub_filt.filters = filt1;
  1916. do {
  1917. result = saEvtEventSubscribe(channel_handle1,
  1918. &sub_filt,
  1919. sub2);
  1920. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1921. if (result != SA_AIS_OK) {
  1922. get_sa_error(result, result_buf, result_buf_len);
  1923. printf("ERROR: event subscribe(1) result: %s\n", result_buf);
  1924. goto evt_free;
  1925. }
  1926. retention_time = 0ULL;
  1927. evt_pat.patterns = &pat1;
  1928. do {
  1929. result = saEvtEventAttributesSet(event_handle,
  1930. &evt_pat,
  1931. TEST_PRIORITY,
  1932. retention_time,
  1933. &test_pub_name);
  1934. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1935. if (result != SA_AIS_OK) {
  1936. get_sa_error(result, result_buf, result_buf_len);
  1937. printf("ERROR: event set attr(0) result: %s\n", result_buf);
  1938. goto evt_free;
  1939. }
  1940. evt_pat.patterns = &pat2;
  1941. do {
  1942. result = saEvtEventAttributesSet(event_handle1,
  1943. &evt_pat,
  1944. TEST_PRIORITY,
  1945. retention_time,
  1946. &test_pub_name);
  1947. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1948. if (result != SA_AIS_OK) {
  1949. get_sa_error(result, result_buf, result_buf_len);
  1950. printf("ERROR: event set attr(1) result: %s\n", result_buf);
  1951. goto evt_free;
  1952. }
  1953. do {
  1954. result = saEvtEventPublish(event_handle, exp_data, DATA_SIZE,
  1955. &event_id1);
  1956. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1957. if (result != SA_AIS_OK) {
  1958. get_sa_error(result, result_buf, result_buf_len);
  1959. printf("ERROR: event Publish result: %s\n", result_buf);
  1960. goto evt_close;
  1961. }
  1962. do {
  1963. result = saEvtEventPublish(event_handle1, exp_data, DATA_SIZE,
  1964. &event_id2);
  1965. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1966. if (result != SA_AIS_OK) {
  1967. get_sa_error(result, result_buf, result_buf_len);
  1968. printf("ERROR: event Publish result: %s\n", result_buf);
  1969. goto evt_close;
  1970. }
  1971. /*
  1972. * See if we got the events
  1973. */
  1974. do {
  1975. result = saEvtSelectionObjectGet(handle, &fd);
  1976. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1977. if (result != SA_AIS_OK) {
  1978. get_sa_error(result, result_buf, result_buf_len);
  1979. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  1980. /* error */
  1981. return;
  1982. }
  1983. call_count = 0;
  1984. while(1) {
  1985. pfd.fd = fd;
  1986. pfd.events = POLLIN;
  1987. nfd = poll(&pfd, 1, timeout);
  1988. if (nfd == 0) {
  1989. break;
  1990. } else if (nfd < 0) {
  1991. perror("ERROR: poll error");
  1992. break;
  1993. }
  1994. do {
  1995. result = saEvtDispatch(handle, SA_DISPATCH_ALL);
  1996. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  1997. if (result != SA_AIS_OK) {
  1998. get_sa_error(result, result_buf, result_buf_len);
  1999. printf("ERROR: saEvtDispatch %s\n", result_buf);
  2000. /* error */
  2001. goto evt_free;
  2002. }
  2003. }
  2004. if (call_count != 2) {
  2005. printf("ERROR: call back count: e=2, a=%d\n", call_count);
  2006. goto evt_free;
  2007. }
  2008. /*
  2009. * Test cleanup
  2010. */
  2011. evt_free:
  2012. do {
  2013. result = saEvtEventFree(event_handle);
  2014. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2015. if (result != SA_AIS_OK) {
  2016. get_sa_error(result, result_buf, result_buf_len);
  2017. printf("ERROR: event free result: %s\n", result_buf);
  2018. }
  2019. do {
  2020. result = saEvtEventFree(event_handle1);
  2021. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2022. if (result != SA_AIS_OK) {
  2023. get_sa_error(result, result_buf, result_buf_len);
  2024. printf("ERROR: event free result: %s\n", result_buf);
  2025. }
  2026. evt_close:
  2027. do {
  2028. result = saEvtChannelClose(channel_handle);
  2029. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2030. if (result != SA_AIS_OK) {
  2031. get_sa_error(result, result_buf, result_buf_len);
  2032. printf("ERROR: channel close result(0): %s\n", result_buf);
  2033. }
  2034. do {
  2035. result = saEvtChannelClose(channel_handle1);
  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: channel close result(1): %s\n", result_buf);
  2040. }
  2041. evt_fin:
  2042. do {
  2043. result = saEvtFinalize(handle);
  2044. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2045. if (result != SA_AIS_OK) {
  2046. get_sa_error(result, result_buf, result_buf_len);
  2047. printf("ERROR: Event Finalize result: %s\n", result_buf);
  2048. }
  2049. printf("Done\n");
  2050. }
  2051. /*
  2052. * Test event retention
  2053. * Test 1: publish the event with a retention time and then
  2054. * subscribe. If the event was retained, we should receive it.
  2055. *
  2056. * Test 2: Publish the event, sleep until it expires, then
  2057. * subscribe. We shouldn't get an event delivered.
  2058. *
  2059. * Test 3: Publish an event with a retention time.
  2060. * subscribe.
  2061. * wait for it.
  2062. * unsubscribe
  2063. * Clear it.
  2064. * Then subscribe and make sure that the messages isn't delivered.
  2065. *
  2066. */
  2067. #define EXPIRE_TIME 10 /* Seconds */
  2068. SaEvtEventIdT retained_id;
  2069. int got_event;
  2070. void
  2071. event_callback_retained(SaEvtSubscriptionIdT my_subscription_id,
  2072. const SaEvtEventHandleT event_handle,
  2073. const SaSizeT my_event_data_size)
  2074. {
  2075. SaAisErrorT result;
  2076. //printf("event_callback_retained called\n");
  2077. do {
  2078. result = saEvtEventAttributesGet(event_handle,
  2079. 0, /* patterns */
  2080. 0, /* priority */
  2081. 0, /* retention time */
  2082. 0, /* publisher name */
  2083. 0, /* publish time */
  2084. &retained_id /* event_id */
  2085. );
  2086. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2087. if (result != SA_AIS_OK) {
  2088. get_sa_error(result, result_buf, result_buf_len);
  2089. printf("ERROR: callback attr get result: %s\n", result_buf);
  2090. return;
  2091. }
  2092. got_event = 1;
  2093. }
  2094. void
  2095. test_retention()
  2096. {
  2097. SaEvtHandleT handle;
  2098. SaEvtChannelHandleT channel_handle;
  2099. SaEvtEventHandleT event_handle;
  2100. SaEvtChannelOpenFlagsT flags;
  2101. SaNameT channel_name;
  2102. SaEvtCallbacksT callbacks_retain = {
  2103. 0,
  2104. event_callback_retained
  2105. };
  2106. struct pollfd pfd;
  2107. int nfd;
  2108. SaSelectionObjectT fd;
  2109. int timeout = (EXPIRE_TIME + 5);
  2110. SaAisErrorT result;
  2111. flags = SA_EVT_CHANNEL_PUBLISHER |
  2112. SA_EVT_CHANNEL_SUBSCRIBER |
  2113. SA_EVT_CHANNEL_CREATE;
  2114. strcpy(channel_name.value, channel);
  2115. channel_name.length = strlen(channel);
  2116. printf("Test Event retention:\n");
  2117. do {
  2118. result = saEvtInitialize (&handle, &callbacks_retain,
  2119. versions[0].version);
  2120. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2121. if (result != SA_AIS_OK) {
  2122. get_sa_error(result, result_buf, result_buf_len);
  2123. printf("ERROR: Event Initialize result: %s\n", result_buf);
  2124. return;
  2125. }
  2126. do {
  2127. result = saEvtSelectionObjectGet(handle, &fd);
  2128. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2129. if (result != SA_AIS_OK) {
  2130. get_sa_error(result, result_buf, result_buf_len);
  2131. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  2132. /* error */
  2133. return;
  2134. }
  2135. do {
  2136. result = saEvtChannelOpen(handle, &channel_name, flags, 0,
  2137. &channel_handle);
  2138. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2139. if (result != SA_AIS_OK) {
  2140. get_sa_error(result, result_buf, result_buf_len);
  2141. printf("ERROR: channel open result: %s\n", result_buf);
  2142. goto evt_fin;
  2143. }
  2144. /*
  2145. * Allocate an event
  2146. */
  2147. do {
  2148. result = saEvtEventAllocate(channel_handle, &event_handle);
  2149. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2150. if (result != SA_AIS_OK) {
  2151. get_sa_error(result, result_buf, result_buf_len);
  2152. printf("ERROR: event Allocate result: %s\n", result_buf);
  2153. goto evt_close;
  2154. }
  2155. retention_time = (EXPIRE_TIME)*1000000000ULL;
  2156. do {
  2157. result = saEvtEventAttributesSet(event_handle,
  2158. &evt_pat_set_array,
  2159. TEST_PRIORITY,
  2160. retention_time,
  2161. &test_pub_name);
  2162. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2163. if (result != SA_AIS_OK) {
  2164. get_sa_error(result, result_buf, result_buf_len);
  2165. printf("ERROR: event set attr result: %s\n", result_buf);
  2166. goto evt_free;
  2167. }
  2168. /*
  2169. * Test 1: publish the event with a retention time and then
  2170. * subscribe. If the event was retained, we should receive it.
  2171. */
  2172. printf(" Receive retained event\n");
  2173. got_event=0;
  2174. retained_id=0;
  2175. do {
  2176. result = saEvtEventPublish(event_handle, exp_data, 0, &event_id);
  2177. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2178. if (result != SA_AIS_OK) {
  2179. get_sa_error(result, result_buf, result_buf_len);
  2180. printf("ERROR: event Publish result(1): %s\n", result_buf);
  2181. goto evt_close;
  2182. }
  2183. do {
  2184. result = saEvtEventSubscribe(channel_handle,
  2185. &subscribe_filters,
  2186. subscription_id);
  2187. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2188. if (result != SA_AIS_OK) {
  2189. get_sa_error(result, result_buf, result_buf_len);
  2190. printf("ERROR: event subscribe result: %s\n", result_buf);
  2191. goto evt_free;
  2192. }
  2193. pfd.fd = fd;
  2194. pfd.events = POLLIN;
  2195. nfd = poll(&pfd, 1, 1000);
  2196. if (nfd <= 0) {
  2197. printf("ERROR: poll fds %d\n", nfd);
  2198. if (nfd < 0) {
  2199. perror("ERROR: poll error");
  2200. }
  2201. /* Error */
  2202. goto evt_free;
  2203. }
  2204. do {
  2205. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  2206. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2207. if (result != SA_AIS_OK) {
  2208. get_sa_error(result, result_buf, result_buf_len);
  2209. printf("ERROR: saEvtDispatch %s\n", result_buf);
  2210. /* error */
  2211. goto evt_free;
  2212. }
  2213. if (!got_event) {
  2214. printf("ERROR: retained event not recevied\n");
  2215. goto evt_free;
  2216. }
  2217. if (retained_id != event_id) {
  2218. printf("ERROR: received the wrong event: e=%llx, a=%llx\n",
  2219. (unsigned long long)event_id,
  2220. (unsigned long long)retained_id);
  2221. goto evt_free;
  2222. }
  2223. do {
  2224. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  2225. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2226. if (result != SA_AIS_OK) {
  2227. get_sa_error(result, result_buf, result_buf_len);
  2228. printf("ERROR: unsubscribe result: %s\n", result_buf);
  2229. goto evt_free;
  2230. }
  2231. /*
  2232. * Test 2: Publish the event, sleep until it expires, then
  2233. * subscribe. We shouldn't get an event delivered.
  2234. */
  2235. printf(" Expire retained event\n");
  2236. got_event=0;
  2237. retained_id=0;
  2238. do {
  2239. result = saEvtEventPublish(event_handle, exp_data, 0, &event_id);
  2240. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2241. if (result != SA_AIS_OK) {
  2242. get_sa_error(result, result_buf, result_buf_len);
  2243. printf("ERROR: event Publish result(1): %s\n", result_buf);
  2244. goto evt_close;
  2245. }
  2246. do {
  2247. result = saEvtSelectionObjectGet(handle, &fd);
  2248. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2249. if (result != SA_AIS_OK) {
  2250. get_sa_error(result, result_buf, result_buf_len);
  2251. printf("ERROR: saEvtSelectionObject get %s\n", result_buf);
  2252. /* error */
  2253. return;
  2254. }
  2255. /*
  2256. * Wait for the event to expire, then subscribe. We shouldn't get
  2257. * an event
  2258. */
  2259. sleep(timeout);
  2260. do {
  2261. result = saEvtEventSubscribe(channel_handle,
  2262. &subscribe_filters,
  2263. subscription_id);
  2264. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2265. if (result != SA_AIS_OK) {
  2266. get_sa_error(result, result_buf, result_buf_len);
  2267. printf("ERROR: event subscribe result: %s\n", result_buf);
  2268. result = saEvtChannelClose(channel_handle);
  2269. goto evt_free;
  2270. }
  2271. pfd.fd = fd;
  2272. pfd.events = POLLIN;
  2273. nfd = poll(&pfd, 1, 1000);
  2274. if (nfd != 0) {
  2275. printf("ERROR: poll fds %d\n", nfd);
  2276. if (nfd < 0) {
  2277. perror("ERROR: poll error");
  2278. }
  2279. /* Error */
  2280. goto evt_free;
  2281. }
  2282. do {
  2283. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  2284. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2285. if (result != SA_AIS_OK) {
  2286. get_sa_error(result, result_buf, result_buf_len);
  2287. printf("ERROR: unsubscribe result: %s\n", result_buf);
  2288. goto evt_free;
  2289. }
  2290. /*
  2291. * Test 3:
  2292. * Publish an event with a retention time.
  2293. * subscribe.
  2294. * wait for it.
  2295. * unsubscribe
  2296. * Clear it.
  2297. * Then subscribe and make sure that the message isn't delivered.
  2298. */
  2299. printf(" Clear event retention time\n");
  2300. got_event=0;
  2301. retained_id=0;
  2302. do {
  2303. result = saEvtEventPublish(event_handle, exp_data, 0, &event_id);
  2304. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2305. if (result != SA_AIS_OK) {
  2306. get_sa_error(result, result_buf, result_buf_len);
  2307. printf("ERROR: event Publish result(2): %s\n", result_buf);
  2308. goto evt_free;
  2309. }
  2310. do {
  2311. result = saEvtEventSubscribe(channel_handle,
  2312. &subscribe_filters,
  2313. subscription_id);
  2314. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2315. if (result != SA_AIS_OK) {
  2316. get_sa_error(result, result_buf, result_buf_len);
  2317. printf("ERROR: event subscribe result: %s\n", result_buf);
  2318. goto evt_free;
  2319. }
  2320. pfd.fd = fd;
  2321. pfd.events = POLLIN;
  2322. nfd = poll(&pfd, 1, 1000);
  2323. if (nfd <= 0) {
  2324. printf("ERROR: poll fds %d\n", nfd);
  2325. if (nfd < 0) {
  2326. perror("ERROR: poll error");
  2327. }
  2328. /* Error */
  2329. goto evt_free;
  2330. }
  2331. do {
  2332. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  2333. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2334. if (result != SA_AIS_OK) {
  2335. get_sa_error(result, result_buf, result_buf_len);
  2336. printf("ERROR: saEvtDispatch %s\n", result_buf);
  2337. /* error */
  2338. goto evt_free;
  2339. }
  2340. if (!got_event) {
  2341. printf("ERROR: retained event not recevied\n");
  2342. goto evt_free;
  2343. }
  2344. if (retained_id != event_id) {
  2345. printf("ERROR: received the wrong event: e=%llx, a=%llx\n",
  2346. (unsigned long long)event_id,
  2347. (unsigned long long)retained_id);
  2348. goto evt_free;
  2349. }
  2350. do {
  2351. result = saEvtEventUnsubscribe(channel_handle, subscription_id);
  2352. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2353. if (result != SA_AIS_OK) {
  2354. get_sa_error(result, result_buf, result_buf_len);
  2355. printf("ERROR: unsubscribe result: %s\n", result_buf);
  2356. goto evt_free;
  2357. }
  2358. do {
  2359. result = saEvtEventRetentionTimeClear(channel_handle, event_id);
  2360. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2361. if (result != SA_AIS_OK) {
  2362. get_sa_error(result, result_buf, result_buf_len);
  2363. printf("ERROR: clear retention time result: %s\n", result_buf);
  2364. goto evt_free;
  2365. }
  2366. do {
  2367. result = saEvtEventSubscribe(channel_handle,
  2368. &subscribe_filters,
  2369. subscription_id);
  2370. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2371. if (result != SA_AIS_OK) {
  2372. get_sa_error(result, result_buf, result_buf_len);
  2373. printf("ERROR: event subscribe result: %s\n", result_buf);
  2374. goto evt_free;
  2375. }
  2376. pfd.fd = fd;
  2377. pfd.events = POLLIN;
  2378. nfd = poll(&pfd, 1, 1000);
  2379. if (nfd != 0) {
  2380. printf("ERROR: poll fds %d\n", nfd);
  2381. if (nfd < 0) {
  2382. perror("ERROR: poll error");
  2383. }
  2384. /* Error */
  2385. goto evt_free;
  2386. }
  2387. /*
  2388. * Test cleanup
  2389. */
  2390. evt_free:
  2391. do {
  2392. result = saEvtEventFree(event_handle);
  2393. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2394. if (result != SA_AIS_OK) {
  2395. get_sa_error(result, result_buf, result_buf_len);
  2396. printf("ERROR: event free result: %s\n", result_buf);
  2397. }
  2398. evt_close:
  2399. do {
  2400. result = saEvtChannelClose(channel_handle);
  2401. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2402. if (result != SA_AIS_OK) {
  2403. get_sa_error(result, result_buf, result_buf_len);
  2404. printf("ERROR: channel close result: %s\n", result_buf);
  2405. }
  2406. evt_fin:
  2407. do {
  2408. result = saEvtFinalize(handle);
  2409. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2410. if (result != SA_AIS_OK) {
  2411. get_sa_error(result, result_buf, result_buf_len);
  2412. printf("ERROR: Event Finalize result: %s\n", result_buf);
  2413. }
  2414. printf("Done\n");
  2415. }
  2416. void
  2417. unlink_chan_callback(SaEvtSubscriptionIdT my_subscription_id,
  2418. const SaEvtEventHandleT event_handle,
  2419. const SaSizeT my_event_data_size)
  2420. {
  2421. SaAisErrorT result;
  2422. SaUint8T my_priority;
  2423. SaTimeT my_retention_time;
  2424. SaNameT my_publisher_name = {0, {0}};
  2425. SaTimeT my_publish_time;
  2426. SaEvtEventIdT my_event_id;
  2427. SaEvtSubscriptionIdT exp_sub_id;
  2428. printf(" unlink_chan_callback called(%d)\n", ++call_count);
  2429. evt_pat_get_array.patternsNumber = 4;
  2430. do {
  2431. result = saEvtEventAttributesGet(event_handle,
  2432. &evt_pat_get_array, /* patterns */
  2433. &my_priority, /* priority */
  2434. &my_retention_time, /* retention time */
  2435. &my_publisher_name, /* publisher name */
  2436. &my_publish_time, /* publish time */
  2437. &my_event_id /* event_id */
  2438. );
  2439. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2440. if (result != SA_AIS_OK) {
  2441. get_sa_error(result, result_buf, result_buf_len);
  2442. printf("ERROR: event get attr result: %s\n", result_buf);
  2443. goto evt_free;
  2444. }
  2445. if (my_event_id == event_id1) {
  2446. exp_sub_id = sub1;
  2447. } else if (my_event_id == event_id2) {
  2448. exp_sub_id = sub2;
  2449. } else {
  2450. printf("ERROR: Received event %llx but not sent\n",
  2451. (unsigned long long)my_event_id);
  2452. goto evt_free;
  2453. }
  2454. if (my_subscription_id != exp_sub_id) {
  2455. printf("ERROR: sub ID: e=%x, a=%x\n",
  2456. exp_sub_id, my_subscription_id);
  2457. goto evt_free;
  2458. }
  2459. evt_free:
  2460. do {
  2461. result = saEvtEventFree(event_handle);
  2462. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2463. if (result != SA_AIS_OK) {
  2464. get_sa_error(result, result_buf, result_buf_len);
  2465. printf("ERROR: event free result: %s\n", result_buf);
  2466. }
  2467. }
  2468. /*
  2469. * Test channel unlink operations.
  2470. * 1. Unlink channel.
  2471. * 2. Open/create a channel, close channel, open channel.
  2472. * 3. unlink channel, Open channel.
  2473. * 4. Open/create, unlink channel, close channel, open channel.
  2474. * 5. Open/create a channel, unlink channel, open/create channel, send
  2475. * event on each.
  2476. * 6. unlink all, close all.
  2477. */
  2478. SaEvtCallbacksT unlink_callbacks = {
  2479. open_callback,
  2480. unlink_chan_callback
  2481. };
  2482. void
  2483. test_unlink_channel()
  2484. {
  2485. SaEvtHandleT handle;
  2486. SaEvtChannelHandleT channel_handle1;
  2487. SaEvtChannelHandleT channel_handle2;
  2488. SaEvtEventHandleT event_handle1;
  2489. SaEvtEventHandleT event_handle2;
  2490. SaEvtChannelOpenFlagsT flags1, flags2;
  2491. SaNameT channel_name;
  2492. SaAisErrorT result;
  2493. struct pollfd pfd;
  2494. int nfd;
  2495. SaSelectionObjectT fd;
  2496. int timeout = 5000;
  2497. flags1 = SA_EVT_CHANNEL_PUBLISHER |
  2498. SA_EVT_CHANNEL_SUBSCRIBER |
  2499. SA_EVT_CHANNEL_CREATE;
  2500. flags2 = SA_EVT_CHANNEL_PUBLISHER |
  2501. SA_EVT_CHANNEL_SUBSCRIBER;
  2502. printf("Test Channel Unlink operations:\n");
  2503. do {
  2504. result = saEvtInitialize (&handle, &unlink_callbacks,
  2505. versions[0].version);
  2506. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2507. if (result != SA_AIS_OK) {
  2508. get_sa_error(result, result_buf, result_buf_len);
  2509. printf("ERROR: Event Initialize result: %s\n", result_buf);
  2510. goto unlink_exit;
  2511. }
  2512. /*
  2513. * 1. Unlink channel.
  2514. *
  2515. * Unlink previously opened channel should return OK.
  2516. * Unlink of non-existent channel should return error.
  2517. */
  2518. printf(" 1 Channel unlink:\n");
  2519. strcpy(channel_name.value, channel);
  2520. channel_name.length = strlen(channel);
  2521. do {
  2522. result = saEvtChannelUnlink(handle, &channel_name);
  2523. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2524. if (result != SA_AIS_OK) {
  2525. get_sa_error(result, result_buf, result_buf_len);
  2526. printf("ERROR: channel unlink(1) result: %s\n", result_buf);
  2527. goto unlink_exit;
  2528. }
  2529. strcpy(channel_name.value, unlink_channel);
  2530. channel_name.length = strlen(unlink_channel);
  2531. do {
  2532. result = saEvtChannelUnlink(handle, &channel_name);
  2533. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2534. if (result != SA_AIS_ERR_NOT_EXIST) {
  2535. get_sa_error(result, result_buf, result_buf_len);
  2536. printf("ERROR: channel unlink(2) result: %s\n", result_buf);
  2537. goto unlink_exit;
  2538. }
  2539. /*
  2540. * 2. Open/create a channel, close channel, open channel.
  2541. *
  2542. * Open/create the channel.
  2543. * Close the channel.
  2544. * Open without create. This should succeed in the B spec.
  2545. */
  2546. printf(" 2 Channel open/close/open:\n");
  2547. do {
  2548. result = saEvtChannelOpen(handle, &channel_name, flags1, 0,
  2549. &channel_handle1);
  2550. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2551. if (result != SA_AIS_OK) {
  2552. get_sa_error(result, result_buf, result_buf_len);
  2553. printf("ERROR: channel open(1) result: %s\n", result_buf);
  2554. goto unlink_exit;
  2555. }
  2556. do {
  2557. result = saEvtChannelClose(channel_handle1);
  2558. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2559. if (result != SA_AIS_OK) {
  2560. get_sa_error(result, result_buf, result_buf_len);
  2561. printf("ERROR: channel close(1) result: %s\n", result_buf);
  2562. goto unlink_exit;
  2563. }
  2564. do {
  2565. result = saEvtChannelOpen(handle, &channel_name, flags2, 0,
  2566. &channel_handle1);
  2567. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2568. if (result != SA_AIS_OK) {
  2569. get_sa_error(result, result_buf, result_buf_len);
  2570. printf("ERROR: channel open(2) result: %s\n", result_buf);
  2571. goto unlink_exit;
  2572. }
  2573. /*
  2574. * 3. unlink channel, Open channel, close channel
  2575. *
  2576. * Unlink the channel. Should mark for deletion but not
  2577. * delete it since it is already open.
  2578. * Open the channel without create. This should fail since
  2579. * the channel is marked for deletion and a new version
  2580. * hasn't been created.
  2581. * Close channel.
  2582. */
  2583. printf(" 3 Channel unlink/open/close:\n");
  2584. do {
  2585. result = saEvtChannelUnlink(handle, &channel_name);
  2586. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2587. if (result != SA_AIS_OK) {
  2588. get_sa_error(result, result_buf, result_buf_len);
  2589. printf("ERROR: channel unlink result: %s\n", result_buf);
  2590. goto unlink_exit;
  2591. }
  2592. do {
  2593. result = saEvtChannelOpen(handle, &channel_name, flags2, 0,
  2594. &channel_handle2);
  2595. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2596. if (result != SA_AIS_ERR_NOT_EXIST) {
  2597. get_sa_error(result, result_buf, result_buf_len);
  2598. printf("ERROR: channel open result: %s\n", result_buf);
  2599. goto unlink_exit;
  2600. }
  2601. do {
  2602. result = saEvtChannelClose(channel_handle1);
  2603. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2604. if (result != SA_AIS_OK) {
  2605. get_sa_error(result, result_buf, result_buf_len);
  2606. printf("ERROR: channel close(1) result: %s\n", result_buf);
  2607. goto unlink_exit;
  2608. }
  2609. /*
  2610. *
  2611. * 4. Open/create, unlink channel, close channel, open channel.
  2612. *
  2613. * Open/create the channel.
  2614. * unlink the channel.
  2615. * close the channel. This should delete the channel instance since
  2616. * it was marked for deletion.
  2617. * open the channel without create. This should fail since the
  2618. * channel doesn't exist anymore.
  2619. */
  2620. printf(" 4 Channel open/unlink/close/open:\n");
  2621. do {
  2622. result = saEvtChannelOpen(handle, &channel_name, flags1, 0,
  2623. &channel_handle1);
  2624. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2625. if (result != SA_AIS_OK) {
  2626. get_sa_error(result, result_buf, result_buf_len);
  2627. printf("ERROR: channel open(1) result: %s\n", result_buf);
  2628. goto unlink_exit;
  2629. }
  2630. do {
  2631. result = saEvtChannelUnlink(handle, &channel_name);
  2632. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2633. if (result != SA_AIS_OK) {
  2634. get_sa_error(result, result_buf, result_buf_len);
  2635. printf("ERROR: channel unlink result: %s\n", result_buf);
  2636. goto unlink_exit;
  2637. }
  2638. do {
  2639. result = saEvtChannelClose(channel_handle1);
  2640. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2641. if (result != SA_AIS_OK) {
  2642. get_sa_error(result, result_buf, result_buf_len);
  2643. printf("ERROR: channel close(1) result: %s\n", result_buf);
  2644. goto unlink_exit;
  2645. }
  2646. do {
  2647. result = saEvtChannelOpen(handle, &channel_name, flags2, 0,
  2648. &channel_handle1);
  2649. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2650. if (result != SA_AIS_ERR_NOT_EXIST) {
  2651. get_sa_error(result, result_buf, result_buf_len);
  2652. printf("ERROR: channel open(2) result: %s\n", result_buf);
  2653. goto unlink_exit;
  2654. }
  2655. /*
  2656. * 5. Open/create a channel, unlink channel, open/create channel, send
  2657. * event on each.
  2658. *
  2659. * Open/create.
  2660. * unlink. Mark for deletion.
  2661. * open/create. Create new channel of same name.
  2662. * send event on each open channel. The events should be received on
  2663. * separate channels.
  2664. */
  2665. printf(" 5 Channel open/unlink/open/send:\n");
  2666. do {
  2667. result = saEvtChannelOpen(handle, &channel_name, flags1, 0,
  2668. &channel_handle1);
  2669. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2670. if (result != SA_AIS_OK) {
  2671. get_sa_error(result, result_buf, result_buf_len);
  2672. printf("ERROR: channel open result: %s\n", result_buf);
  2673. goto unlink_exit;
  2674. }
  2675. do {
  2676. result = saEvtChannelUnlink(handle, &channel_name);
  2677. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2678. if (result != SA_AIS_OK) {
  2679. get_sa_error(result, result_buf, result_buf_len);
  2680. printf("ERROR: channel unlink result: %s\n", result_buf);
  2681. goto unlink_exit;
  2682. }
  2683. do {
  2684. result = saEvtChannelOpen(handle, &channel_name, flags1, 0,
  2685. &channel_handle2);
  2686. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2687. if (result != SA_AIS_OK) {
  2688. get_sa_error(result, result_buf, result_buf_len);
  2689. printf("ERROR: channel open result: %s\n", result_buf);
  2690. goto unlink_exit;
  2691. }
  2692. do {
  2693. result = saEvtEventSubscribe(channel_handle1,
  2694. &subscribe_filters,
  2695. sub1);
  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: channel subscribe(1) result: %s\n", result_buf);
  2700. goto unlink_exit;
  2701. }
  2702. do {
  2703. result = saEvtEventSubscribe(channel_handle2,
  2704. &subscribe_filters,
  2705. sub2);
  2706. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2707. if (result != SA_AIS_OK) {
  2708. get_sa_error(result, result_buf, result_buf_len);
  2709. printf("ERROR: channel subscribe(2) result: %s\n", result_buf);
  2710. goto unlink_exit;
  2711. }
  2712. retention_time = 0ULL;
  2713. do {
  2714. result = saEvtEventAllocate(channel_handle1, &event_handle1);
  2715. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2716. if (result != SA_AIS_OK) {
  2717. get_sa_error(result, result_buf, result_buf_len);
  2718. printf("ERROR: event allocate(1) result: %s\n", result_buf);
  2719. goto unlink_exit;
  2720. }
  2721. do {
  2722. result = saEvtEventAttributesSet(event_handle1,
  2723. &evt_pat_set_array,
  2724. TEST_PRIORITY,
  2725. retention_time,
  2726. &test_pub_name);
  2727. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2728. if (result != SA_AIS_OK) {
  2729. get_sa_error(result, result_buf, result_buf_len);
  2730. printf("ERROR: event set(1) result: %s\n", result_buf);
  2731. goto unlink_exit;
  2732. }
  2733. do {
  2734. result = saEvtEventAllocate(channel_handle2, &event_handle2);
  2735. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2736. if (result != SA_AIS_OK) {
  2737. get_sa_error(result, result_buf, result_buf_len);
  2738. printf("ERROR: event allocate(2) result: %s\n", result_buf);
  2739. goto unlink_exit;
  2740. }
  2741. do {
  2742. result = saEvtEventAttributesSet(event_handle2,
  2743. &evt_pat_set_array,
  2744. TEST_PRIORITY,
  2745. retention_time,
  2746. &test_pub_name);
  2747. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2748. if (result != SA_AIS_OK) {
  2749. get_sa_error(result, result_buf, result_buf_len);
  2750. printf("ERROR: event set(2) result: %s\n", result_buf);
  2751. goto unlink_exit;
  2752. }
  2753. do {
  2754. result = saEvtEventPublish(event_handle1, 0, 0, &event_id1);
  2755. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2756. if (result != SA_AIS_OK) {
  2757. get_sa_error(result, result_buf, result_buf_len);
  2758. printf("ERROR: event publish(1) result: %s\n", result_buf);
  2759. goto unlink_exit;
  2760. }
  2761. do {
  2762. result = saEvtEventPublish(event_handle2, 0, 0, &event_id2);
  2763. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2764. if (result != SA_AIS_OK) {
  2765. get_sa_error(result, result_buf, result_buf_len);
  2766. printf("ERROR: event publish(2) result: %s\n", result_buf);
  2767. goto unlink_exit;
  2768. }
  2769. do {
  2770. result = saEvtSelectionObjectGet(handle, &fd);
  2771. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2772. if (result != SA_AIS_OK) {
  2773. get_sa_error(result, result_buf, result_buf_len);
  2774. printf("ERROR: select object get result: %s\n", result_buf);
  2775. goto unlink_exit;
  2776. }
  2777. /*
  2778. * We should see a total of two events processed, not four
  2779. * as if both events were recevied on both channels.
  2780. */
  2781. call_count = 0;
  2782. do {
  2783. pfd.fd = fd;
  2784. pfd.events = POLLIN;
  2785. nfd = poll(&pfd, 1, timeout);
  2786. if (nfd <= 0) {
  2787. if (nfd < 0) {
  2788. perror("ERROR: poll error");
  2789. goto unlink_exit;
  2790. }
  2791. } else {
  2792. do {
  2793. result = saEvtDispatch(handle, SA_DISPATCH_ONE);
  2794. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2795. if (result != SA_AIS_OK) {
  2796. get_sa_error(result, result_buf, result_buf_len);
  2797. printf("ERROR: saEvtDispatch %s\n", result_buf);
  2798. goto unlink_exit;
  2799. }
  2800. }
  2801. } while (nfd > 0);
  2802. if (call_count != 2) {
  2803. printf("ERROR: processed %d events\n", call_count);
  2804. goto unlink_exit;
  2805. }
  2806. /*
  2807. * 6. unlink all, close all.
  2808. *
  2809. * close all open channels.
  2810. * unlink the channel.
  2811. * open without create the channel. Verify that the channel no
  2812. * longer exists.
  2813. */
  2814. printf(" 6 Channel unlink all/close all/open:\n");
  2815. unlink_exit:
  2816. saEvtChannelClose(channel_handle1);
  2817. saEvtChannelClose(channel_handle2);
  2818. saEvtChannelUnlink(handle, &channel_name);
  2819. do {
  2820. result = saEvtFinalize(handle);
  2821. } while ((result == SA_AIS_ERR_TRY_AGAIN) && !sleep(TRY_WAIT));
  2822. if (result != SA_AIS_OK) {
  2823. get_sa_error(result, result_buf, result_buf_len);
  2824. printf("ERROR: Event Finalize result: %s\n", result_buf);
  2825. }
  2826. printf("Done\n");
  2827. }
  2828. int main (void)
  2829. {
  2830. test_initialize ();
  2831. test_channel();
  2832. test_event();
  2833. test_multi_channel1();
  2834. test_multi_channel2();
  2835. test_multi_channel3();
  2836. test_retention();
  2837. test_unlink_channel();
  2838. return (0);
  2839. }
  2840. /*
  2841. * vi: set autoindent tabstop=4 shiftwidth=4 :
  2842. */