VirtualBox

source: vbox/trunk/src/VBox/VMM/testcase/tstSSM-2.cpp@ 85972

Last change on this file since 85972 was 83031, checked in by vboxsync, 5 years ago

VMM/tstSSM-2: Call RTR3InitExe() before doing anything else

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: tstSSM-2.cpp 83031 2020-02-10 10:02:23Z vboxsync $ */
2/** @file
3 * Saved State Manager Testcase: Extract the content of a saved state.
4 */
5
6/*
7 * Copyright (C) 2015-2020 Oracle Corporation
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
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <VBox/vmm/ssm.h>
23
24#include <VBox/log.h>
25#include <iprt/assert.h>
26#include <iprt/getopt.h>
27#include <iprt/errcore.h>
28#include <iprt/file.h>
29#include <iprt/path.h>
30#include <iprt/stream.h>
31#include <iprt/initterm.h>
32
33static RTEXITCODE extractUnit(const char *pszFilename, const char *pszUnitname, const char *pszOutputFilename)
34{
35 PSSMHANDLE pSSM;
36 int rc = SSMR3Open(pszFilename, 0, &pSSM);
37 RTEXITCODE rcExit = RTEXITCODE_FAILURE;
38 if (RT_SUCCESS(rc))
39 {
40 RTFILE hFile;
41 rc = RTFileOpen(&hFile, pszOutputFilename, RTFILE_O_DENY_NONE | RTFILE_O_WRITE | RTFILE_O_CREATE);
42 if (RT_SUCCESS(rc))
43 {
44 uint32_t version = 0;
45 rc = SSMR3Seek(pSSM, pszUnitname, 0 /* iInstance */, &version);
46 size_t cbUnit = 0;
47 if (RT_SUCCESS(rc))
48 {
49 for (;;)
50 {
51 uint8_t u8;
52 rc = SSMR3GetU8(pSSM, &u8);
53 if (RT_FAILURE(rc))
54 break;
55 size_t cbWritten;
56 rc = RTFileWrite(hFile, &u8, sizeof(u8), &cbWritten);
57 cbUnit++;
58 }
59 RTPrintf("Unit size %zu bytes, version %d\n", cbUnit, version);
60 }
61 else
62 RTPrintf("Cannot find unit '%s' (%Rrc)\n", pszUnitname, rc);
63 RTFileClose(hFile);
64 }
65 else
66 RTPrintf("Cannot open output file '%s' (%Rrc)\n", pszOutputFilename, rc);
67 SSMR3Close(pSSM);
68 }
69 else
70 RTPrintf("Cannot open SSM file '%s' (%Rrc)\n", pszFilename, rc);
71 return rcExit;
72}
73
74int main(int argc, char **argv)
75{
76 int rc = RTR3InitExe(argc, &argv, 0);
77 AssertRCReturn(rc, RTEXITCODE_INIT);
78
79 if (argc != 4)
80 {
81 RTPrintf("Usage: %s <SSM filename> <SSM unitname> <outfile>\n", RTPathFilename(argv[0]));
82 /* don't fail by default */
83 return RTEXITCODE_SUCCESS;
84 }
85 return extractUnit(argv[1], argv[2], argv[3]);
86}
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