VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstSSM.cpp@ 400

Last change on this file since 400 was 23, checked in by vboxsync, 18 years ago

string.h & stdio.h + header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.3 KB
Line 
1/* $Id: tstSSM.cpp 23 2007-01-15 14:08:28Z vboxsync $ */
2/** @file
3 * Saved State Manager Testcase.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <VBox/ssm.h>
27#include <VBox/vm.h>
28
29#include <VBox/log.h>
30#include <VBox/sup.h>
31#include <VBox/err.h>
32#include <VBox/param.h>
33#include <iprt/runtime.h>
34#include <iprt/assert.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/time.h>
38
39
40const uint8_t gabPage[PAGE_SIZE] = {0};
41
42const char gachMem1[] = "sdfg\1asdfa\177hjkl;sdfghjkl;dfghjkl;dfghjkl;\0\0asdf;kjasdf;lkjasd;flkjasd;lfkjasd\0;lfk";
43
44uint8_t gabBigMem[8*1024*1024];
45
46/** initializes gabBigMem with some non zero stuff. */
47void initBigMem(void)
48{
49#if 0
50 uint32_t *puch = (uint32_t *)&gabBigMem[0];
51 uint32_t *puchEnd = (uint32_t *)&gabBigMem[sizeof(gabBigMem)];
52 uint32_t u32 = 0xdeadbeef;
53 for (; puch < puchEnd; puch++)
54 {
55 *puch = u32;
56 u32 += 19;
57 u32 = (u32 << 1) | (u32 >> 31);
58 }
59#else
60 uint8_t *pb = &gabBigMem[0];
61 uint8_t *pbEnd = &gabBigMem[sizeof(gabBigMem)];
62 for (; pb < pbEnd; pb += 16)
63 {
64 char szTmp[17];
65 RTStrPrintf(szTmp, sizeof(szTmp), "aaaa%08Xzzzz", (uint32_t)(uintptr_t)pb);
66 memcpy(pb, szTmp, 16);
67 }
68#endif
69}
70
71/**
72 * Execute state save operation.
73 *
74 * @returns VBox status code.
75 * @param pDevIns Device instance of the device which registered the data unit.
76 * @param pSSM SSM operation handle.
77 */
78DECLCALLBACK(int) Item01Save(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
79{
80 uint64_t u64Start = RTTimeNanoTS();
81
82 /*
83 * Test writing some memory block.
84 */
85 int rc = SSMR3PutMem(pSSM, gachMem1, sizeof(gachMem1));
86 if (VBOX_FAILURE(rc))
87 {
88 RTPrintf("Item01: #1 - SSMR3PutMem -> %Vrc\n", rc);
89 return rc;
90 }
91
92 /*
93 * Test writing a zeroterminated string.
94 */
95 rc = SSMR3PutStrZ(pSSM, "String");
96 if (VBOX_FAILURE(rc))
97 {
98 RTPrintf("Item01: #1 - SSMR3PutMem -> %Vrc\n", rc);
99 return rc;
100 }
101
102
103 /*
104 * Test the individual integer put functions to see that they all work.
105 * (Testcases are also known as "The Land of The Ugly Code"...)
106 */
107#define ITEM(suff,bits, val) \
108 rc = SSMR3Put##suff(pSSM, val); \
109 if (VBOX_FAILURE(rc)) \
110 { \
111 RTPrintf("Item01: #" #suff " - SSMR3Put" #suff "(," #val ") -> %Vrc\n", rc); \
112 return rc; \
113 }
114 /* copy & past with the load one! */
115 ITEM(U8, uint8_t, 0xff);
116 ITEM(U8, uint8_t, 0x0);
117 ITEM(U8, uint8_t, 1);
118 ITEM(U8, uint8_t, 42);
119 ITEM(U8, uint8_t, 230);
120 ITEM(S8, int8_t, -128);
121 ITEM(S8, int8_t, 127);
122 ITEM(S8, int8_t, 12);
123 ITEM(S8, int8_t, -76);
124 ITEM(U16, uint16_t, 0xffff);
125 ITEM(U16, uint16_t, 0x0);
126 ITEM(S16, int16_t, 32767);
127 ITEM(S16, int16_t, -32768);
128 ITEM(U32, uint32_t, 4294967295U);
129 ITEM(U32, uint32_t, 0);
130 ITEM(U32, uint32_t, 42);
131 ITEM(U32, uint32_t, 2342342344U);
132 ITEM(S32, int32_t, -2147483647-1);
133 ITEM(S32, int32_t, 2147483647);
134 ITEM(S32, int32_t, 42);
135 ITEM(S32, int32_t, 568459834);
136 ITEM(S32, int32_t, -58758999);
137 ITEM(U64, uint64_t, 18446744073709551615ULL);
138 ITEM(U64, uint64_t, 0);
139 ITEM(U64, uint64_t, 42);
140 ITEM(U64, uint64_t, 593023944758394234ULL);
141 ITEM(S64, int64_t, 9223372036854775807LL);
142 ITEM(S64, int64_t, -9223372036854775807LL - 1);
143 ITEM(S64, int64_t, 42);
144 ITEM(S64, int64_t, 21398723459873LL);
145 ITEM(S64, int64_t, -5848594593453453245LL);
146#undef ITEM
147
148 uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
149 RTPrintf("tstSSM: Saved 1st item in %RI64 ns\n", u64Elapsed);
150 return 0;
151}
152
153/**
154 * Prepare state load operation.
155 *
156 * @returns VBox status code.
157 * @param pDevIns Device instance of the device which registered the data unit.
158 * @param pSSM SSM operation handle.
159 */
160DECLCALLBACK(int) Item01Load(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
161{
162 /*
163 * Load the memory block.
164 */
165 char achTmp[sizeof(gachMem1)];
166 int rc = SSMR3GetMem(pSSM, achTmp, sizeof(gachMem1));
167 if (VBOX_FAILURE(rc))
168 {
169 RTPrintf("Item01: #1 - SSMR3GetMem -> %Vrc\n", rc);
170 return rc;
171 }
172
173 /*
174 * Load the string.
175 */
176 rc = SSMR3GetStrZ(pSSM, achTmp, sizeof(achTmp));
177 if (VBOX_FAILURE(rc))
178 {
179 RTPrintf("Item01: #2 - SSMR3GetStrZ -> %Vrc\n", rc);
180 return rc;
181 }
182
183 /*
184 * Test the individual integer put functions to see that they all work.
185 * (Testcases are also known as "The Land of The Ugly Code"...)
186 */
187#define ITEM(suff, type, val) \
188 do { \
189 type var = {0}; \
190 rc = SSMR3Get##suff(pSSM, &var); \
191 if (VBOX_FAILURE(rc)) \
192 { \
193 RTPrintf("Item01: #" #suff " - SSMR3Get" #suff "(," #val ") -> %Vrc\n", rc); \
194 return rc; \
195 } \
196 if (var != val) \
197 { \
198 RTPrintf("Item01: #" #suff " - SSMR3Get" #suff "(," #val ") -> %d returned wrong value!\n", rc); \
199 return VERR_GENERAL_FAILURE; \
200 } \
201 } while (0)
202 /* copy & past with the load one! */
203 ITEM(U8, uint8_t, 0xff);
204 ITEM(U8, uint8_t, 0x0);
205 ITEM(U8, uint8_t, 1);
206 ITEM(U8, uint8_t, 42);
207 ITEM(U8, uint8_t, 230);
208 ITEM(S8, int8_t, -128);
209 ITEM(S8, int8_t, 127);
210 ITEM(S8, int8_t, 12);
211 ITEM(S8, int8_t, -76);
212 ITEM(U16, uint16_t, 0xffff);
213 ITEM(U16, uint16_t, 0x0);
214 ITEM(S16, int16_t, 32767);
215 ITEM(S16, int16_t, -32768);
216 ITEM(U32, uint32_t, 4294967295U);
217 ITEM(U32, uint32_t, 0);
218 ITEM(U32, uint32_t, 42);
219 ITEM(U32, uint32_t, 2342342344U);
220 ITEM(S32, int32_t, -2147483647-1);
221 ITEM(S32, int32_t, 2147483647);
222 ITEM(S32, int32_t, 42);
223 ITEM(S32, int32_t, 568459834);
224 ITEM(S32, int32_t, -58758999);
225 ITEM(U64, uint64_t, 18446744073709551615ULL);
226 ITEM(U64, uint64_t, 0);
227 ITEM(U64, uint64_t, 42);
228 ITEM(U64, uint64_t, 593023944758394234ULL);
229 ITEM(S64, int64_t, 9223372036854775807LL);
230 ITEM(S64, int64_t, -9223372036854775807LL - 1);
231 ITEM(S64, int64_t, 42);
232 ITEM(S64, int64_t, 21398723459873LL);
233 ITEM(S64, int64_t, -5848594593453453245LL);
234#undef ITEM
235
236 return 0;
237}
238
239
240/**
241 * Execute state save operation.
242 *
243 * @returns VBox status code.
244 * @param pDevIns Device instance of the device which registered the data unit.
245 * @param pSSM SSM operation handle.
246 */
247DECLCALLBACK(int) Item02Save(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
248{
249 uint64_t u64Start = RTTimeNanoTS();
250
251 /*
252 * Put the size.
253 */
254 size_t cb = sizeof(gabBigMem);
255 int rc = SSMR3PutU32(pSSM, cb);
256 if (VBOX_FAILURE(rc))
257 {
258 RTPrintf("Item02: PutU32 -> %Vrc\n", rc);
259 return rc;
260 }
261
262 /*
263 * Put 8MB of memory to the file in 3 chunks.
264 */
265 uint8_t *pbMem = &gabBigMem[0];
266 size_t cbChunk = cb / 47;
267 rc = SSMR3PutMem(pSSM, pbMem, cbChunk);
268 if (VBOX_FAILURE(rc))
269 {
270 RTPrintf("Item02: PutMem(,%p,%#x) -> %Vrc\n", pbMem, cbChunk, rc);
271 return rc;
272 }
273 cb -= cbChunk;
274 pbMem += cbChunk;
275
276 /* next piece. */
277 cbChunk *= 19;
278 rc = SSMR3PutMem(pSSM, pbMem, cbChunk);
279 if (VBOX_FAILURE(rc))
280 {
281 RTPrintf("Item02: PutMem(,%p,%#x) -> %Vrc\n", pbMem, cbChunk, rc);
282 return rc;
283 }
284 cb -= cbChunk;
285 pbMem += cbChunk;
286
287 /* last piece. */
288 cbChunk = cb;
289 rc = SSMR3PutMem(pSSM, pbMem, cbChunk);
290 if (VBOX_FAILURE(rc))
291 {
292 RTPrintf("Item02: PutMem(,%p,%#x) -> %Vrc\n", pbMem, cbChunk, rc);
293 return rc;
294 }
295
296 uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
297 RTPrintf("tstSSM: Saved 2nd item in %RI64 ns\n", u64Elapsed);
298 return 0;
299}
300
301/**
302 * Prepare state load operation.
303 *
304 * @returns VBox status code.
305 * @param pDevIns Device instance of the device which registered the data unit.
306 * @param pSSM SSM operation handle.
307 */
308DECLCALLBACK(int) Item02Load(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
309{
310 /*
311 * Load the size.
312 */
313 uint32_t cb;
314 int rc = SSMR3GetU32(pSSM, &cb);
315 if (VBOX_FAILURE(rc))
316 {
317 RTPrintf("Item02: SSMR3GetU32 -> %Vrc\n", rc);
318 return rc;
319 }
320 if (cb != sizeof(gabBigMem))
321 {
322 RTPrintf("Item02: loaded size doesn't match the real thing. %#x != %#x\n", cb, sizeof(gabBigMem));
323 return VERR_GENERAL_FAILURE;
324 }
325
326 /*
327 * Load the memory chunk by chunk.
328 */
329 uint8_t *pbMem = &gabBigMem[0];
330 char achTmp[16383];
331 size_t cbChunk = sizeof(achTmp);
332 while (cb > 0)
333 {
334 cbChunk -= 7;
335 if (cbChunk < 64)
336 cbChunk = sizeof(achTmp) - (cbChunk % 47);
337 if (cbChunk > cb)
338 cbChunk = cb;
339 rc = SSMR3GetMem(pSSM, &achTmp[0], cbChunk);
340 if (VBOX_FAILURE(rc))
341 {
342 RTPrintf("Item02: SSMR3GetMem(,,%#x) -> %d offset %#x\n", cbChunk, rc, pbMem - &gabBigMem[0]);
343 return rc;
344 }
345 if (memcmp(achTmp, pbMem, cbChunk))
346 {
347 RTPrintf("Item02: compare failed. mem offset=%#x cbChunk=%#x\n", pbMem - &gabBigMem[0], cbChunk);
348 return VERR_GENERAL_FAILURE;
349 }
350
351 /* next */
352 pbMem += cbChunk;
353 cb -= cbChunk;
354 }
355
356 return 0;
357}
358
359
360/**
361 * Execute state save operation.
362 *
363 * @returns VBox status code.
364 * @param pDevIns Device instance of the device which registered the data unit.
365 * @param pSSM SSM operation handle.
366 */
367DECLCALLBACK(int) Item03Save(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
368{
369 uint64_t u64Start = RTTimeNanoTS();
370
371 /*
372 * Put the size.
373 */
374 size_t cb = 512*_1M;
375 int rc = SSMR3PutU32(pSSM, cb);
376 if (VBOX_FAILURE(rc))
377 {
378 RTPrintf("Item03: PutU32 -> %Vrc\n", rc);
379 return rc;
380 }
381
382 /*
383 * Put 512 MB page by page.
384 */
385 const uint8_t *pu8Org = &gabBigMem[0];
386 while (cb > 0)
387 {
388 rc = SSMR3PutMem(pSSM, pu8Org, PAGE_SIZE);
389 if (VBOX_FAILURE(rc))
390 {
391 RTPrintf("Item03: PutMem(,%p,%#x) -> %Vrc\n", pu8Org, PAGE_SIZE, rc);
392 return rc;
393 }
394
395 /* next */
396 cb -= PAGE_SIZE;
397 pu8Org += PAGE_SIZE;
398 if (pu8Org > &gabBigMem[sizeof(gabBigMem)])
399 pu8Org = &gabBigMem[0];
400 }
401
402 uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
403 RTPrintf("tstSSM: Saved 3rd item in %RI64 ns\n", u64Elapsed);
404 return 0;
405}
406
407/**
408 * Prepare state load operation.
409 *
410 * @returns VBox status code.
411 * @param pDevIns Device instance of the device which registered the data unit.
412 * @param pSSM SSM operation handle.
413 */
414DECLCALLBACK(int) Item03Load(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
415{
416 /*
417 * Load the size.
418 */
419 uint32_t cb;
420 int rc = SSMR3GetU32(pSSM, &cb);
421 if (VBOX_FAILURE(rc))
422 {
423 RTPrintf("Item03: SSMR3GetU32 -> %Vrc\n", rc);
424 return rc;
425 }
426 if (cb != 512*_1M)
427 {
428 RTPrintf("Item03: loaded size doesn't match the real thing. %#x != %#x\n", cb, 512*_1M);
429 return VERR_GENERAL_FAILURE;
430 }
431
432 /*
433 * Load the memory page by page.
434 */
435 const uint8_t *pu8Org = &gabBigMem[0];
436 while (cb > 0)
437 {
438 char achPage[PAGE_SIZE];
439 rc = SSMR3GetMem(pSSM, &achPage[0], PAGE_SIZE);
440 if (VBOX_FAILURE(rc))
441 {
442 RTPrintf("Item03: SSMR3GetMem(,,%#x) -> %Vrc offset %#x\n", PAGE_SIZE, rc, 512*_1M - cb);
443 return rc;
444 }
445 if (memcmp(achPage, pu8Org, PAGE_SIZE))
446 {
447 RTPrintf("Item03: compare failed. mem offset=%#x\n", 512*_1M - cb);
448 return VERR_GENERAL_FAILURE;
449 }
450
451 /* next */
452 cb -= PAGE_SIZE;
453 pu8Org += PAGE_SIZE;
454 if (pu8Org > &gabBigMem[sizeof(gabBigMem)])
455 pu8Org = &gabBigMem[0];
456 }
457
458 return 0;
459}
460
461
462/**
463 * Execute state save operation.
464 *
465 * @returns VBox status code.
466 * @param pDevIns Device instance of the device which registered the data unit.
467 * @param pSSM SSM operation handle.
468 */
469DECLCALLBACK(int) Item04Save(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
470{
471 uint64_t u64Start = RTTimeNanoTS();
472
473 /*
474 * Put the size.
475 */
476 size_t cb = 512*_1M;
477 int rc = SSMR3PutU32(pSSM, cb);
478 if (VBOX_FAILURE(rc))
479 {
480 RTPrintf("Item04: PutU32 -> %Vrc\n", rc);
481 return rc;
482 }
483
484 /*
485 * Put 512 MB page by page.
486 */
487 while (cb > 0)
488 {
489 rc = SSMR3PutMem(pSSM, gabPage, PAGE_SIZE);
490 if (VBOX_FAILURE(rc))
491 {
492 RTPrintf("Item04: PutMem(,%p,%#x) -> %Vrc\n", gabPage, PAGE_SIZE, rc);
493 return rc;
494 }
495
496 /* next */
497 cb -= PAGE_SIZE;
498 }
499
500 uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
501 RTPrintf("tstSSM: Saved 4th item in %RI64 ns\n", u64Elapsed);
502 return 0;
503}
504
505/**
506 * Prepare state load operation.
507 *
508 * @returns VBox status code.
509 * @param pDevIns Device instance of the device which registered the data unit.
510 * @param pSSM SSM operation handle.
511 */
512DECLCALLBACK(int) Item04Load(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t u32Version)
513{
514 /*
515 * Load the size.
516 */
517 uint32_t cb;
518 int rc = SSMR3GetU32(pSSM, &cb);
519 if (VBOX_FAILURE(rc))
520 {
521 RTPrintf("Item04: SSMR3GetU32 -> %Vrc\n", rc);
522 return rc;
523 }
524 if (cb != 512*_1M)
525 {
526 RTPrintf("Item04: loaded size doesn't match the real thing. %#x != %#x\n", cb, 512*_1M);
527 return VERR_GENERAL_FAILURE;
528 }
529
530 /*
531 * Load the memory page by page.
532 */
533 while (cb > 0)
534 {
535 char achPage[PAGE_SIZE];
536 rc = SSMR3GetMem(pSSM, &achPage[0], PAGE_SIZE);
537 if (VBOX_FAILURE(rc))
538 {
539 RTPrintf("Item04: SSMR3GetMem(,,%#x) -> %Vrc offset %#x\n", PAGE_SIZE, rc, 512*_1M - cb);
540 return rc;
541 }
542 if (memcmp(achPage, gabPage, PAGE_SIZE))
543 {
544 RTPrintf("Item04: compare failed. mem offset=%#x\n", 512*_1M - cb);
545 return VERR_GENERAL_FAILURE;
546 }
547
548 /* next */
549 cb -= PAGE_SIZE;
550 }
551
552 return 0;
553}
554
555
556int main(int argc, char **argv)
557{
558 /*
559 * Init runtime and static data.
560 */
561 RTR3Init();
562 RTPrintf("tstSSM: TESTING...\n");
563 initBigMem();
564 const char *pszFilename = "SSMTestSave#1";
565
566 /*
567 * Create empty VM structure and init SSM.
568 */
569 PVM pVM;
570 int rc = SUPInit(NULL);
571 if (VBOX_SUCCESS(rc))
572 rc = SUPPageAlloc((sizeof(*pVM) + PAGE_SIZE - 1) >> PAGE_SHIFT, (void **)&pVM);
573 if (VBOX_FAILURE(rc))
574 {
575 RTPrintf("Fatal error: SUP Failure! rc=%Vrc\n", rc);
576 return 1;
577 }
578
579 rc = STAMR3Init(pVM);
580 if (VBOX_FAILURE(rc))
581 {
582 RTPrintf("Fatal error: STAMR3Init failed! rc=%Vrc\n", rc);
583 return 1;
584 }
585
586/*
587 rc = SSMR3Init(pVM);
588 if (VBOX_FAILURE(rc))
589 {
590 RTPrintf("Fatal error: SSMR3Init failed! rc=%Vrc\n", rc);
591 return 1;
592 }
593*/
594
595 /*
596 * Register a few callbacks.
597 */
598 rc = SSMR3Register(pVM, NULL, "SSM Testcase Data Item no.1 (all types)", 1, 0, 256,
599 NULL, Item01Save, NULL,
600 NULL, Item01Load, NULL);
601 if (VBOX_FAILURE(rc))
602 {
603 RTPrintf("SSMR3Register #1 -> %Vrc\n", rc);
604 return 1;
605 }
606
607 rc = SSMR3Register(pVM, NULL, "SSM Testcase Data Item no.2 (rand mem)", 2, 0, _1M * 8,
608 NULL, Item02Save, NULL,
609 NULL, Item02Load, NULL);
610 if (VBOX_FAILURE(rc))
611 {
612 RTPrintf("SSMR3Register #2 -> %Vrc\n", rc);
613 return 1;
614 }
615
616 rc = SSMR3Register(pVM, NULL, "SSM Testcase Data Item no.3 (big mem)", 0, 123, 512*_1M,
617 NULL, Item03Save, NULL,
618 NULL, Item03Load, NULL);
619 if (VBOX_FAILURE(rc))
620 {
621 RTPrintf("SSMR3Register #3 -> %Vrc\n", rc);
622 return 1;
623 }
624
625 rc = SSMR3Register(pVM, NULL, "SSM Testcase Data Item no.4 (big zero mem)", 0, 42, 512*_1M,
626 NULL, Item04Save, NULL,
627 NULL, Item04Load, NULL);
628 if (VBOX_FAILURE(rc))
629 {
630 RTPrintf("SSMR3Register #4 -> %Vrc\n", rc);
631 return 1;
632 }
633
634 /*
635 * Attempt a save.
636 */
637 uint64_t u64Start = RTTimeNanoTS();
638 rc = SSMR3Save(pVM, pszFilename, SSMAFTER_DESTROY, NULL, NULL);
639 if (VBOX_FAILURE(rc))
640 {
641 RTPrintf("SSMR3Save #1 -> %Vrc\n", rc);
642 return 1;
643 }
644 uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
645 RTPrintf("tstSSM: Saved in %RI64 ns\n", u64Elapsed);
646
647 /*
648 * Attempt a load.
649 */
650 u64Start = RTTimeNanoTS();
651 rc = SSMR3Load(pVM, pszFilename, SSMAFTER_RESUME, NULL, NULL);
652 if (VBOX_FAILURE(rc))
653 {
654 RTPrintf("SSMR3Load #1 -> %Vrc\n", rc);
655 return 1;
656 }
657 u64Elapsed = RTTimeNanoTS() - u64Start;
658 RTPrintf("tstSSM: Loaded in %RI64 ns\n", u64Elapsed);
659
660 /*
661 * Validate it.
662 */
663 u64Start = RTTimeNanoTS();
664 rc = SSMR3ValidateFile(pszFilename);
665 if (VBOX_FAILURE(rc))
666 {
667 RTPrintf("SSMR3ValidateFile #1 -> %Vrc\n", rc);
668 return 1;
669 }
670 u64Elapsed = RTTimeNanoTS() - u64Start;
671 RTPrintf("tstSSM: Validated in %RI64 ns\n", u64Elapsed);
672
673 /*
674 * Open it and read.
675 */
676 u64Start = RTTimeNanoTS();
677 PSSMHANDLE pSSM;
678 rc = SSMR3Open(pszFilename, 0, &pSSM);
679 if (VBOX_FAILURE(rc))
680 {
681 RTPrintf("SSMR3Open #1 -> %Vrc\n", rc);
682 return 1;
683 }
684 u64Elapsed = RTTimeNanoTS() - u64Start;
685 RTPrintf("tstSSM: Opened in %RI64 ns\n", u64Elapsed);
686
687 /* negative */
688 u64Start = RTTimeNanoTS();
689 rc = SSMR3Seek(pSSM, "some unit that doesn't exist", 0, NULL);
690 if (rc != VERR_SSM_UNIT_NOT_FOUND)
691 {
692 RTPrintf("SSMR3Seek #1 negative -> %Vrc\n", rc);
693 return 1;
694 }
695 u64Elapsed = RTTimeNanoTS() - u64Start;
696 RTPrintf("tstSSM: Failed seek in %RI64 ns\n", u64Elapsed);
697
698 /* 2nd unit */
699 rc = SSMR3Seek(pSSM, "SSM Testcase Data Item no.2 (rand mem)", 0, NULL);
700 if (VBOX_FAILURE(rc))
701 {
702 RTPrintf("SSMR3Seek #1 unit 2-> %Vrc\n", rc);
703 return 1;
704 }
705 uint32_t u32Version = 0xbadc0ded;
706 rc = SSMR3Seek(pSSM, "SSM Testcase Data Item no.2 (rand mem)", 0, &u32Version);
707 if (VBOX_FAILURE(rc))
708 {
709 RTPrintf("SSMR3Seek #1 unit 2-> %Vrc\n", rc);
710 return 1;
711 }
712 u64Start = RTTimeNanoTS();
713 rc = Item02Load(NULL, pSSM, u32Version);
714 if (VBOX_FAILURE(rc))
715 {
716 RTPrintf("Item02Load #1 -> %Vrc\n", rc);
717 return 1;
718 }
719 u64Elapsed = RTTimeNanoTS() - u64Start;
720 RTPrintf("tstSSM: Loaded 2nd item in %RI64 ns\n", u64Elapsed);
721
722 /* 1st unit */
723 u32Version = 0xbadc0ded;
724 rc = SSMR3Seek(pSSM, "SSM Testcase Data Item no.1 (all types)", 0, &u32Version);
725 if (VBOX_FAILURE(rc))
726 {
727 RTPrintf("SSMR3Seek #1 unit 1 -> %Vrc\n", rc);
728 return 1;
729 }
730 u64Start = RTTimeNanoTS();
731 rc = Item01Load(NULL, pSSM, u32Version);
732 if (VBOX_FAILURE(rc))
733 {
734 RTPrintf("Item01Load #1 -> %Vrc\n", rc);
735 return 1;
736 }
737 u64Elapsed = RTTimeNanoTS() - u64Start;
738 RTPrintf("tstSSM: Loaded 1st item in %RI64 ns\n", u64Elapsed);
739
740 /* 3st unit */
741 u32Version = 0xbadc0ded;
742 rc = SSMR3Seek(pSSM, "SSM Testcase Data Item no.3 (big mem)", 123, &u32Version);
743 if (VBOX_FAILURE(rc))
744 {
745 RTPrintf("SSMR3Seek #3 unit 1 -> %Vrc\n", rc);
746 return 1;
747 }
748 u64Start = RTTimeNanoTS();
749 rc = Item03Load(NULL, pSSM, u32Version);
750 if (VBOX_FAILURE(rc))
751 {
752 RTPrintf("Item01Load #3 -> %Vrc\n", rc);
753 return 1;
754 }
755 u64Elapsed = RTTimeNanoTS() - u64Start;
756 RTPrintf("tstSSM: Loaded 3rd item in %RI64 ns\n", u64Elapsed);
757
758 /* close */
759 rc = SSMR3Close(pSSM);
760 if (VBOX_FAILURE(rc))
761 {
762 RTPrintf("SSMR3Close #1 -> %Vrc\n", rc);
763 return 1;
764 }
765
766 RTPrintf("tstSSM: SUCCESS\n");
767 return 0;
768}
769
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette