tstVMM-2.cpp revision 4ae0468b4ae87a83e1a5f8c4f98ff78e840fde85
/* $Id$ */
/** @file
* VMM Testcase - no. 2.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/semaphore.h>
#include <stdio.h> /** @todo get rid of this. */
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define TESTCASE "tstVMM-2"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct TSTVMMARGS
{
/** The filename. */
const char *pszFilename;
/** The opened file. */
} TSTVMMARGS, *PTSTVMMARGS;
/**
* Configuration constructor - takes flat file as input.
*/
{
/*
* Read the file.
*/
unsigned iLine = 0;
char szLine[16384];
{
iLine++;
/* leading blanks */
psz++;
if (*psz == '[')
{
/*
* Key path.
*/
psz++;
if (*psz != '/')
{
return VERR_GENERAL_FAILURE;
}
if (!pszEnd)
{
return VERR_GENERAL_FAILURE;
}
pszEnd--;
*pszEnd++ = '/';
*pszEnd = '\0';
/*
* Create the key path.
*/
{
*pszCurEnd = '\0';
if (!pChild)
{
if (VBOX_FAILURE(rc))
{
*pszCurEnd = '/';
RTPrintf("%s(%d): error: failed to create node '%s', rc=%d.\n", pArgs->pszFilename, iLine, psz, rc);
return rc;
}
}
/* next path component */
*pszCurEnd = '/';
}
}
{
/*
* Value Name.
*/
char *pszNameEnd;
{
/* quoted name */
for (;;)
{
if (!pszNameEnd)
{
return VERR_GENERAL_FAILURE;
}
break;
pszNameEnd++;
}
*pszNameEnd-- = '\0';
*pszName++ = '\0';
}
else
{
/* unquoted name. Name ends before '<type>' or '='. */
if (!pszNameEnd)
{
return VERR_GENERAL_FAILURE;
}
*pszNameEnd-- = '\0';
pszNameEnd--;
if (!pszNameEnd)
{
return VERR_GENERAL_FAILURE;
}
}
if (pszName == pszNameEnd)
{
return VERR_GENERAL_FAILURE;
}
/* check if equal sign present and skip past it and all following blanks. */
if (!psz)
{
return VERR_GENERAL_FAILURE;
}
psz++;
psz++;
/*
* Value.
*/
{
/* string */
char *pszValueEnd = psz;
for (;;)
{
if (!pszValueEnd)
{
return VERR_GENERAL_FAILURE;
}
break;
pszValueEnd++;
}
*pszValueEnd-- = '\0';
*psz++ = '\0';
if (VBOX_FAILURE(rc))
{
RTPrintf("%s(%d): error: failed to insert string value named '%s' and with value '%s', rc=%d.\n",
return rc;
}
}
{
/* byte string */
return VERR_GENERAL_FAILURE;
}
{
/* integer */
{ /* hex */
psz += 2;
{
u64 *= 16;
psz++;
}
}
else
{ /* decimal */
{
u64 *= 10;
psz++;
}
}
{
RTPrintf("%s(%d): error: unexpected char(s) after number '%.10s'\n", pArgs->pszFilename, iLine, psz);
return VERR_GENERAL_FAILURE;
}
if (VBOX_FAILURE(rc))
{
RTPrintf("%s(%d): error: failed to insert integer value named '%s' and with value %#llx, rc=%d.\n",
return rc;
}
}
else
{
return VERR_GENERAL_FAILURE;
}
}
/* else: skip */
} /* for each line */
LogFlow(("%s: successfully read config\n"));
return VINF_SUCCESS;
}
{
TSTVMMARGS Args = {0};
int rcRet = 0; /* error count. */
int fPowerOn = 0;
/*
* Parse arguments.
*/
for (int i = 1; i < argc; i++)
{
if (*psz == '-')
{
psz++;
if (*psz == '-')
psz++;
{
if (Args.pszFilename)
{
RTPrintf("syntax error: only one config argument!\n");
return 1;
}
if (i + 1 >= argc)
{
RTPrintf("syntax error: no configuration filename!\n");
return 1;
}
{
return 1;
}
}
fPowerOn = 1;
{
RTPrintf("syntax: %s [options]\n"
"\n"
"options (prefixed with a dash or two)\n"
" config <filename> Load the flat config file.\n"
" help This help text.\n", argv[0]);
return 1;
}
else
{
return 1;
}
}
else
{
RTPrintf("syntax error: Sorry dude, no idea what you're passing to me.\n"
" arg %d '%s'\n", i, argv[i]);
return 1;
}
}
/*
* Create empty VM.
*/
if (VBOX_SUCCESS(rc))
{
/*
* Power it on if that was requested.
*/
if (fPowerOn)
{
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
{
/*
* Power Off the VM.
*/
if (VBOX_SUCCESS(rc))
{
if (VBOX_SUCCESS(rc))
else
{
rcRet++;
}
}
else
{
rcRet++;
}
}
}
else
{
rcRet++;
}
}
/*
* Cleanup.
*/
if (!VBOX_SUCCESS(rc))
{
rcRet++;
}
}
else
{
rcRet++;
}
return rcRet;
}