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