mirror of
https://github.com/reactos/sysreg2.git
synced 2024-11-23 11:29:55 +00:00
-add a xml config file
-load and parse settings svn path=/trunk/tools/sysreg2/; revision=814
This commit is contained in:
parent
e4acd4a9d6
commit
42ab2830ba
@ -2,7 +2,7 @@
|
||||
#include <termios.h>
|
||||
#include <poll.h>
|
||||
|
||||
void ProcessDebugData(const char* tty, int timeout)
|
||||
void ProcessDebugData(const char* tty, int timeout, int stage )
|
||||
{
|
||||
int ttyfd, i;
|
||||
struct termios ttyattr, rawattr;
|
||||
|
2
makefile
2
makefile
@ -10,7 +10,7 @@ LFLAGS := -s -L/usr/lib64
|
||||
LIBS := -lgcc -lm -lvirt -ltasn1 -lz -lxml2 -lgnutls
|
||||
INC := -I/usr/include/libvirt/ -I/usr/include/libxml2/
|
||||
|
||||
SRCS := virt.c utils.c console.c
|
||||
SRCS := virt.c utils.c console.c options.c
|
||||
|
||||
OBJS := $(SRCS:.c=.o)
|
||||
|
||||
|
64
options.c
Normal file
64
options.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include "sysreg.h"
|
||||
|
||||
bool LoadSettings(const char* XmlConfig)
|
||||
{
|
||||
xmlDocPtr xml = NULL;
|
||||
xmlXPathObjectPtr obj = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
char TempStr[255];
|
||||
int Stage;
|
||||
const char* StageNames[] = {
|
||||
"firststage",
|
||||
"secondstage",
|
||||
"thirdstage"
|
||||
};
|
||||
|
||||
xml = xmlReadFile(XmlConfig, NULL, 0);
|
||||
if (!xml)
|
||||
return false;
|
||||
ctxt = xmlXPathNewContext(xml);
|
||||
if (!ctxt)
|
||||
{
|
||||
xmlFreeDoc(xml);
|
||||
return false;
|
||||
}
|
||||
|
||||
obj = xmlXPathEval(BAD_CAST"string(/settings/@file)",ctxt);
|
||||
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
|
||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
|
||||
{
|
||||
strncpy(AppSettings.Filename, obj->stringval, 254);
|
||||
}
|
||||
|
||||
obj = xmlXPathEval(BAD_CAST"string(/settings/@name)",ctxt);
|
||||
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
|
||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
|
||||
{
|
||||
strncpy(AppSettings.Name, obj->stringval, 79);
|
||||
}
|
||||
|
||||
obj = xmlXPathEval(BAD_CAST"number(/settings/general/timeout/@ms)",ctxt);
|
||||
if ((obj != NULL) && (obj->type == XPATH_NUMBER))
|
||||
{
|
||||
/* when no value is set - return value is negative
|
||||
* which means infinite */
|
||||
AppSettings.Timeout = (int)obj->floatval;
|
||||
}
|
||||
|
||||
for (Stage=0;Stage<3;Stage++)
|
||||
{
|
||||
strcpy(TempStr, "string(/settings/");
|
||||
strcat(TempStr, StageNames[Stage]);
|
||||
strcat(TempStr, "/@bootdevice)");
|
||||
obj = xmlXPathEval((xmlChar*) TempStr,ctxt);
|
||||
if ((obj != NULL) && ((obj->type == XPATH_STRING) &&
|
||||
(obj->stringval != NULL) && (obj->stringval[0] != 0)))
|
||||
{
|
||||
strncpy(AppSettings.Stage[Stage].BootDevice, obj->stringval, 7);
|
||||
}
|
||||
}
|
||||
xmlFreeDoc(xml);
|
||||
xmlXPathFreeContext(ctxt);
|
||||
return true;
|
||||
}
|
||||
|
23
sysreg.h
23
sysreg.h
@ -10,6 +10,25 @@
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
char* ReadFile (const char *filename);
|
||||
void ProcessDebugData(const char* tty, int timeout);
|
||||
typedef struct {
|
||||
char BootDevice[8];
|
||||
} stage;
|
||||
|
||||
typedef struct {
|
||||
int Timeout;
|
||||
char Filename[255];
|
||||
char Name[80];
|
||||
stage Stage[3];
|
||||
} Settings;
|
||||
|
||||
Settings AppSettings;
|
||||
|
||||
/* utils.c */
|
||||
char* ReadFile (const char* filename);
|
||||
ssize_t safewrite(int fd, const void *buf, size_t count);
|
||||
|
||||
/* options.c */
|
||||
bool LoadSettings(const char* XmlConfig);
|
||||
|
||||
/* console.c */
|
||||
void ProcessDebugData(const char* tty, int timeout, int stage);
|
||||
|
13
sysreg.xml
Normal file
13
sysreg.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<settings vm="ReactOS" file="/opt/buildbot/kvmtest/reactos.xml">
|
||||
<general>
|
||||
<!-- kill the VM after n milliseconds without debug msg -->
|
||||
<timeout ms="20000"/>
|
||||
</general2
|
||||
<firststage bootdevice="cdrom">
|
||||
<success on="SYSREG_CHECKPOINT:USETUP_COMPLETE"/>
|
||||
</firststage>
|
||||
<secondstage bootdevice="hd">
|
||||
</secondstage>
|
||||
<thirdstage bootdevice="hd">
|
||||
</thirdstage>
|
||||
</settings>
|
43
virt.c
43
virt.c
@ -51,7 +51,7 @@ bool IsVirtualMachineRunning(virConnectPtr vConn, const char* name)
|
||||
int i;
|
||||
for(i=0; i<iDomains; i++)
|
||||
{
|
||||
if (strcmp(name, names[i]) == 0)
|
||||
if (strcasecmp(name, names[i]) == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,6 @@ virDomainPtr LaunchVirtualMachine(virConnectPtr vConn, const char* XmlFileName,
|
||||
name = virDomainGetName(vDomPtr);
|
||||
domname = strdup(name);
|
||||
virDomainFree(vDomPtr);
|
||||
vDomPtr = virDomainLookupByName(vConn, domname);
|
||||
free(domname);
|
||||
}
|
||||
}
|
||||
@ -121,32 +120,42 @@ virDomainPtr LaunchVirtualMachine(virConnectPtr vConn, const char* XmlFileName,
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
virConnectPtr vConn;
|
||||
virDomainPtr vDom;
|
||||
int Stage;
|
||||
int Stages = 1; /* 1 for testing, should be set to 3 later */
|
||||
|
||||
if (!LoadSettings("sysreg.xml"))
|
||||
{
|
||||
printf("Can not load configuration file\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
vConn = virConnectOpen("qemu:///session");
|
||||
|
||||
if (IsVirtualMachineRunning(vConn, "reactos"))
|
||||
printf("Virtual Machine is already running\n");
|
||||
else
|
||||
for (Stage=0;Stage<Stages; Stage++)
|
||||
{
|
||||
vDom = LaunchVirtualMachine(vConn, "/opt/buildbot/kvmtest/reactos.xml", "cdrom");
|
||||
if (IsVirtualMachineRunning(vConn, AppSettings.Name))
|
||||
printf("Virtual Machine is already running\n");
|
||||
else
|
||||
{
|
||||
if (vDom)
|
||||
vDom = LaunchVirtualMachine(vConn, AppSettings.Filename,
|
||||
AppSettings.Stage[Stage].BootDevice);
|
||||
{
|
||||
printf("Domain %s started.\n", virDomainGetName(vDom));
|
||||
printf("%s\n", GetConsole(vDom));
|
||||
ProcessDebugData(GetConsole(vDom), 10000 /*10 sec */);
|
||||
|
||||
virDomainDestroy(vDom);
|
||||
virDomainUndefine(vDom);
|
||||
virDomainFree(vDom);
|
||||
}
|
||||
if (vDom)
|
||||
{
|
||||
printf("Domain %s started.\n", virDomainGetName(vDom));
|
||||
ProcessDebugData(GetConsole(vDom),
|
||||
AppSettings.Timeout, Stage);
|
||||
virDomainDestroy(vDom);
|
||||
virDomainUndefine(vDom);
|
||||
virDomainFree(vDom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virConnectClose(vConn);
|
||||
return 1;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user