testckpt.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <errno.h>
  37. #include <unistd.h>
  38. #include <sys/types.h>
  39. #include <sys/socket.h>
  40. #include <sys/select.h>
  41. #include <sys/un.h>
  42. #include "ais_types.h"
  43. #include "ais_ckpt.h"
  44. int ckptinv;
  45. void printSaNameT (SaNameT *name)
  46. {
  47. int i;
  48. for (i = 0; i < name->length; i++) {
  49. printf ("%c", name->value[i]);
  50. }
  51. }
  52. SaVersionT version = { 'A', 1, 1 };
  53. SaNameT checkpointName = { 5, "abra\0" };
  54. SaCkptCheckpointCreationAttributesT checkpointCreationAttributes = {
  55. SA_CKPT_WR_ALL_REPLICAS,
  56. 100000,
  57. 0,
  58. 5,
  59. 20000,
  60. 10
  61. };
  62. SaCkptSectionIdT sectionId1 = {
  63. "section ID #1",
  64. 14
  65. };
  66. SaCkptSectionIdT sectionId2 = {
  67. "section ID #2",
  68. 14
  69. };
  70. SaCkptSectionCreationAttributesT sectionCreationAttributes1 = {
  71. &sectionId1,
  72. 0xFFFFFFFF
  73. };
  74. SaCkptSectionCreationAttributesT sectionCreationAttributes2 = {
  75. &sectionId2,
  76. 0xFFFFFFFF
  77. };
  78. char readBuffer1[1025];
  79. char readBuffer2[1025];
  80. SaCkptIOVectorElementT ReadVectorElements[] = {
  81. {
  82. {
  83. "section ID #1",
  84. 14
  85. },
  86. readBuffer1,
  87. sizeof (readBuffer1),
  88. 0,
  89. 0
  90. },
  91. {
  92. {
  93. "section ID #2",
  94. 14
  95. },
  96. readBuffer2,
  97. sizeof (readBuffer2),
  98. 0,
  99. 0
  100. }
  101. };
  102. #define DATASIZE 127000
  103. char data[DATASIZE];
  104. SaCkptIOVectorElementT WriteVectorElements[] = {
  105. {
  106. {
  107. "section ID #1",
  108. 14
  109. },
  110. data, /*"written data #1, this should extend past end of old section data", */
  111. DATASIZE, /*sizeof ("data #1, this should extend past end of old section data") + 1, */
  112. 0, //5,
  113. 0
  114. }
  115. #ifdef COMPILE_OUT
  116. {
  117. {
  118. "section ID #2",
  119. 14
  120. },
  121. data, /*"written data #2, this should extend past end of old section data" */
  122. DATASIZE, /*sizeof ("written data #2, this should extend past end of old section data") + 1, */
  123. 0, //3,
  124. 0
  125. }
  126. #endif
  127. };
  128. int main (void) {
  129. SaCkptCheckpointHandleT checkpointHandle;
  130. SaCkptCheckpointHandleT checkpointHandle2;
  131. SaCkptCheckpointHandleT checkpointHandleRead;
  132. SaCkptCheckpointStatusT checkpointStatus;
  133. SaCkptSectionIteratorT sectionIterator;
  134. SaCkptSectionDescriptorT sectionDescriptor;
  135. SaUint32T erroroneousVectorIndex = 0;
  136. SaErrorT error;
  137. error = saCkptCheckpointOpen (&checkpointName,
  138. &checkpointCreationAttributes,
  139. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  140. 0,
  141. &checkpointHandle);
  142. printf ("first open result %d (should be 1)\n", error);
  143. // start of stuff
  144. error = saCkptSectionCreate (&checkpointHandle,
  145. &sectionCreationAttributes1,
  146. "Initial Data #0",
  147. strlen ("Initial Data #0") + 1);
  148. printf ("create1 error is %d\n", error);
  149. error = saCkptSectionCreate (&checkpointHandle,
  150. &sectionCreationAttributes2,
  151. "Initial Data #0",
  152. strlen ("Initial Data #0") + 1);
  153. printf ("create2 error is %d\n", error);
  154. printf ("saCkptSectionCreate result %d (should be 1)\n", error);
  155. #ifdef cmpout
  156. for (ckptinv = 0; ckptinv < 500000; ckptinv++) {
  157. printf ("Writing checkpoint loop %d\n", ckptinv);
  158. /*
  159. * Test checkpoint write
  160. */
  161. error = saCkptCheckpointWrite (&checkpointHandle,
  162. WriteVectorElements,
  163. 1,
  164. &erroroneousVectorIndex);
  165. if (error != SA_OK) {
  166. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  167. exit (1);
  168. }
  169. }
  170. exit (1);
  171. #endif
  172. error = saCkptCheckpointUnlink (&checkpointName);
  173. printf ("unlink result %d (should be 1)\n", error);
  174. error = saCkptCheckpointOpen (&checkpointName,
  175. &checkpointCreationAttributes,
  176. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  177. 0,
  178. &checkpointHandle2);
  179. printf ("open after unlink result %d (should be 7)\n", error);
  180. error = saCkptCheckpointClose (&checkpointHandle);
  181. printf ("close result %d (should be 1)\n", error);
  182. error = saCkptCheckpointOpen (&checkpointName,
  183. &checkpointCreationAttributes,
  184. SA_CKPT_CHECKPOINT_READ,
  185. 0,
  186. &checkpointHandleRead);
  187. printf ("read only open result %d (should be 1)\n", error);
  188. error = saCkptCheckpointOpen (&checkpointName,
  189. &checkpointCreationAttributes,
  190. SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
  191. 0,
  192. &checkpointHandle);
  193. printf ("open after unlink/close result %d (should be 1)\n", error);
  194. error = saCkptCheckpointRetentionDurationSet (&checkpointHandle,
  195. 10000);
  196. printf ("set checkpoint retention duration result %d (should be 1)\n", error);
  197. error = saCkptCheckpointStatusGet (&checkpointHandle,
  198. &checkpointStatus);
  199. printf ("saCkptCheckpointStatusGet result %d (should be 1)\n", error);
  200. if (error == SA_OK) {
  201. printf ("Memory used %d in %d sections.\n", (int)checkpointStatus.memoryUsed,
  202. (int)checkpointStatus.numberOfSections);
  203. }
  204. error = saCkptSectionCreate (&checkpointHandleRead,
  205. &sectionCreationAttributes1,
  206. "Initial Data #0",
  207. strlen ("Initial Data #0") + 1);
  208. printf ("saCkptSectionCreate result %d (should be 11)\n", error);
  209. error = saCkptSectionCreate (&checkpointHandle,
  210. &sectionCreationAttributes1,
  211. "Initial Data #0",
  212. strlen ("Initial Data #0") + 1);
  213. printf ("saCkptSectionCreate result %d (should be 1)\n", error);
  214. error = saCkptSectionCreate (&checkpointHandle,
  215. &sectionCreationAttributes1,
  216. "Initial Data #0",
  217. strlen ("Initial Data #0") + 1);
  218. printf ("saCkptSectionCreate result %d (should be 14)\n", error);
  219. #ifdef COMPILE_OUT
  220. error = saCkptSectionDelete (&checkpointHandle,
  221. &sectionId1);
  222. printf ("saCkptSectionDelete result %d (should be 1)\n", error);
  223. error = saCkptSectionCreate (&checkpointHandle,
  224. &sectionCreationAttributes1,
  225. "Initial Data #0",
  226. strlen ("Initial Data #0") + 1);
  227. printf ("saCkptSectionCreate result %d (should be 1)\n", error);
  228. #endif
  229. error = saCkptSectionExpirationTimeSet (&checkpointHandle,
  230. &sectionId1,
  231. 0xFFAAAAAA);
  232. printf ("saCkptSectionExpirationTimeSet result %d (should be 1)\n", error);
  233. error = saCkptSectionOverwrite (&checkpointHandle,
  234. &sectionId1,
  235. "Overwrite Data #1",
  236. strlen ("Overwrite Data #1") + 1);
  237. printf ("saCkptSectionOverwrite result %d (should be 1)\n", error);
  238. /*
  239. * Test checkpoint read
  240. */
  241. memset (readBuffer1, 0, sizeof (readBuffer1));
  242. memset (readBuffer2, 0, sizeof (readBuffer2));
  243. error = saCkptSectionCreate (&checkpointHandle,
  244. &sectionCreationAttributes2,
  245. "Initial Data #2",
  246. strlen ("Initial Data #2") + 1);
  247. printf ("saCkptSectionCreate result %d (should be 1)\n", error);
  248. error = saCkptCheckpointRead (&checkpointHandle,
  249. ReadVectorElements,
  250. 2,
  251. &erroroneousVectorIndex);
  252. printf ("saCkptCheckpointRead result %d (should be 1)\n", error);
  253. printf ("Buffers after checkpoint read\n");
  254. printf (" buffer #1: '%s'\n", readBuffer1);
  255. printf (" buffer #2: '%s'\n", readBuffer2);
  256. //sleep (20);
  257. #ifdef COMPILE_OUT
  258. for (ckptinv = 0; ckptinv < 2000; ckptinv++) {
  259. /*
  260. * Test checkpoint write
  261. */
  262. error = saCkptCheckpointWrite (&checkpointHandle,
  263. WriteVectorElements,
  264. 2,
  265. &erroroneousVectorIndex);
  266. if (error != SA_OK) {
  267. printf ("Writing checkpoint loop %d\n", ckptinv);
  268. printf ("saCkptCheckpointWrite result %d (should be 1)\n", error);
  269. exit (1);
  270. }
  271. }
  272. exit (1);
  273. #endif
  274. error = saCkptCheckpointRead (&checkpointHandle,
  275. ReadVectorElements,
  276. 2,
  277. &erroroneousVectorIndex);
  278. // printf ("saCkptCheckpointRead result %d (should be 1)\n", error);
  279. // printf ("Buffers after checkpoint write are:\n");
  280. // printf (" buffer #1: '%s'\n", readBuffer1);
  281. // printf (" buffer #2: '%s'\n", readBuffer2);
  282. error = saCkptCheckpointStatusGet (&checkpointHandle,
  283. &checkpointStatus);
  284. printf ("saCkptCheckpointStatusGet result %d (should be 1)\n", error);
  285. if (error == SA_OK) {
  286. printf ("Memory used %d in %d sections.\n", (int)checkpointStatus.memoryUsed,
  287. (int)checkpointStatus.numberOfSections);
  288. }
  289. error = saCkptSectionIteratorInitialize (&checkpointHandle,
  290. 0,
  291. 0,
  292. &sectionIterator);
  293. printf ("saCkptSectionIteratorInitialize result %d (should be 1)\n", error);
  294. /*
  295. * Iterate all sections
  296. */
  297. do {
  298. error = saCkptSectionIteratorNext (&sectionIterator,
  299. &sectionDescriptor);
  300. printf ("saCkptSectionIteratorNext result %d (should be 1)\n", error);
  301. if (error == SA_OK) {
  302. printf ("Section '%s' expires %llx size %d state %x update %llx\n",
  303. sectionDescriptor.sectionId.id,
  304. sectionDescriptor.expirationTime,
  305. sectionDescriptor.sectionSize,
  306. sectionDescriptor.sectionState,
  307. sectionDescriptor.lastUpdate);
  308. }
  309. } while (error == SA_OK);
  310. error = saCkptSectionIteratorFinalize (&sectionIterator);
  311. printf ("saCkptSectionIteratorFinalize result %d (should be 1)\n", error);
  312. return (0);
  313. }