tstSSM.cpp revision c97989161fbe75bc14cea477a5443bbf474dd3ad
/* $Id$ */
/** @file
* Saved State Manager Testcase.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
const char gachMem1[] = "sdfg\1asdfa\177hjkl;sdfghjkl;dfghjkl;dfghjkl;\0\0asdf;kjasdf;lkjasd;flkjasd;lfkjasd\0;lfk";
/** initializes gabBigMem with some non zero stuff. */
void initBigMem(void)
{
#if 0
{
u32 += 19;
}
#else
{
char szTmp[17];
}
#endif
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Test writing some memory block.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Test writing a zeroterminated string.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Test the individual integer put functions to see that they all work.
* (Testcases are also known as "The Land of The Ugly Code"...)
*/
if (VBOX_FAILURE(rc)) \
{ \
return rc; \
}
/* copy & past with the load one! */
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Load the memory block.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Load the string.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Test the individual integer put functions to see that they all work.
* (Testcases are also known as "The Land of The Ugly Code"...)
*/
do { \
if (VBOX_FAILURE(rc)) \
{ \
return rc; \
} \
{ \
return VERR_GENERAL_FAILURE; \
} \
} while (0)
/* copy & past with the load one! */
return 0;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Put 8MB of memory to the file in 3 chunks.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/* next piece. */
cbChunk *= 19;
if (VBOX_FAILURE(rc))
{
return rc;
}
/* last piece. */
if (VBOX_FAILURE(rc))
{
return rc;
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Load the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory chunk by chunk.
*/
char achTmp[16383];
while (cb > 0)
{
cbChunk -= 7;
if (cbChunk < 64)
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Put 512 MB page by page.
*/
while (cb > 0)
{
if (VBOX_FAILURE(rc))
{
return rc;
}
/* next */
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Load the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory page by page.
*/
while (cb > 0)
{
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
/*
* Put 512 MB page by page.
*/
while (cb > 0)
{
if (VBOX_FAILURE(rc))
{
return rc;
}
/* next */
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
{
/*
* Load the size.
*/
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory page by page.
*/
while (cb > 0)
{
if (VBOX_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
{
/*
* Init runtime and static data.
*/
RTR3Init();
RTPrintf("tstSSM: TESTING...\n");
initBigMem();
const char *pszFilename = "SSMTestSave#1";
/*
* Create empty VM structure and init SSM.
*/
if (VBOX_SUCCESS(rc))
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
rc = SSMR3Init(pVM);
if (VBOX_FAILURE(rc))
{
RTPrintf("Fatal error: SSMR3Init failed! rc=%Vrc\n", rc);
return 1;
}
*/
/*
* Register a few callbacks.
*/
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
* Attempt a save.
*/
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
* Attempt a load.
*/
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
* Validate it.
*/
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/*
* Open it and read.
*/
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/* negative */
u64Start = RTTimeNanoTS();
if (rc != VERR_SSM_UNIT_NOT_FOUND)
{
return 1;
}
/* 2nd unit */
if (VBOX_FAILURE(rc))
{
return 1;
}
if (VBOX_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/* 1st unit */
u32Version = 0xbadc0ded;
if (VBOX_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/* 3st unit */
u32Version = 0xbadc0ded;
if (VBOX_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (VBOX_FAILURE(rc))
{
return 1;
}
/* close */
if (VBOX_FAILURE(rc))
{
return 1;
}
RTPrintf("tstSSM: SUCCESS\n");
return 0;
}