tstSSM.cpp revision e79b5cfce37dfae817c33341900cf20651cf1592
/* $Id$ */
/** @file
* Saved State Manager Testcase.
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* 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 (GPL) 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VMInternal.h" /* createFakeVM */
#include <iprt/initterm.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define TSTSSM_BIG_CONFIG 1
#ifdef TSTSSM_BIG_CONFIG
#else
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
const char gachMem1[] = "sdfg\1asdfa\177hjkl;sdfghjkl;dfghjkl;dfghjkl;\0\0asdf;kjasdf;lkjasd;flkjasd;lfkjasd\0;lfk";
#ifdef TSTSSM_BIG_CONFIG
#else
#endif
/** initializes gabBigMem with some non zero stuff. */
void initBigMem(void)
{
#if 0
{
u32 += 19;
}
#else
{
char szTmp[17];
}
/* add some zero pages */
#endif
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Test writing some memory block.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Test writing a zeroterminated string.
*/
if (RT_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 (RT_FAILURE(rc)) \
{ \
return rc; \
}
/* copy & past with the load one! */
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
* @param uVersion The data layout version.
* @param uPass The data pass.
*/
{
if (uVersion != 0)
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory block.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Load the string.
*/
if (RT_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 (RT_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 pVM The cross context VM handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Put 8MB of memory to the file in 3 chunks.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/* next piece. */
cbChunk *= 19;
if (RT_FAILURE(rc))
{
return rc;
}
/* last piece. */
if (RT_FAILURE(rc))
{
return rc;
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
* @param uVersion The data layout version.
* @param uPass The data pass.
*/
{
if (uVersion != 0)
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the size.
*/
if (RT_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 (RT_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Put 512 MB page by page.
*/
while (cb > 0)
{
if (RT_FAILURE(rc))
{
return rc;
}
/* next */
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
* @param uVersion The data layout version.
* @param uPass The data pass.
*/
{
if (uVersion != 123)
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the size.
*/
if (RT_FAILURE(rc))
{
return rc;
}
if (cb != TSTSSM_ITEM_SIZE)
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory page by page.
*/
while (cb > 0)
{
if (RT_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
*/
{
/*
* Put the size.
*/
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Put 512 MB page by page.
*/
while (cb > 0)
{
if (RT_FAILURE(rc))
{
return rc;
}
/* next */
}
return 0;
}
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM The cross context VM handle.
* @param pSSM SSM operation handle.
* @param uVersion The data layout version.
* @param uPass The data pass.
*/
{
if (uVersion != 42)
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the size.
*/
if (RT_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/*
* Load the memory page by page.
*/
while (cb > 0)
{
if (RT_FAILURE(rc))
{
return rc;
}
{
return VERR_GENERAL_FAILURE;
}
/* next */
}
return 0;
}
/**
* Creates a mockup VM structure for testing SSM.
*
* @returns 0 on success, 1 on failure.
* @param ppVM Where to store Pointer to the VM.
*
*/
{
/*
* Allocate and init the UVM structure.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Allocate and init the VM structure.
*/
if (RT_SUCCESS(rc))
{
return 0;
}
}
else
}
else
}
else
return 1;
}
{
/*
* Init runtime and static data.
*/
RTPrintf("tstSSM: TESTING...\n");
initBigMem();
const char *pszFilename = "SSMTestSave#1";
/*
* Create an fake VM structure and init SSM.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (createFakeVM(&pVM))
return 1;
/*
* Register a few callbacks.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Attempt a save.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Attempt a load.
*/
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Validate it.
*/
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Open it and read.
*/
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/* negative */
u64Start = RTTimeNanoTS();
if (rc != VERR_SSM_UNIT_NOT_FOUND)
{
return 1;
}
/* another negative, now only the instance number isn't matching. */
if (rc != VERR_SSM_UNIT_NOT_FOUND)
{
return 1;
}
/* 2nd unit */
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/* 1st unit */
uVersion = 0xbadc0ded;
if (RT_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/* 3st unit */
uVersion = 0xbadc0ded;
if (RT_FAILURE(rc))
{
return 1;
}
u64Start = RTTimeNanoTS();
if (RT_FAILURE(rc))
{
return 1;
}
/* close */
if (RT_FAILURE(rc))
{
return 1;
}
/* delete */
RTPrintf("tstSSM: SUCCESS\n");
return 0;
}