VirtualBox

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

Last change on this file since 11997 was 11822, checked in by vboxsync, 16 years ago

IPRT: RTR3Init cleanup.

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