[ros-diffs] [cwittich] 35833: -add a xml config file -load and parse settings

cwittich at svn.reactos.org cwittich at svn.reactos.org
Sun Aug 31 17:21:46 CEST 2008


Author: cwittich
Date: Sun Aug 31 10:21:45 2008
New Revision: 35833

URL: http://svn.reactos.org/svn/reactos?rev=35833&view=rev
Log:
-add a xml config file
-load and parse settings

Added:
    trunk/tools/sysreg2/options.c   (with props)
    trunk/tools/sysreg2/sysreg.xml   (with props)
Modified:
    trunk/tools/sysreg2/console.c
    trunk/tools/sysreg2/makefile
    trunk/tools/sysreg2/sysreg.h
    trunk/tools/sysreg2/virt.c

Modified: trunk/tools/sysreg2/console.c
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/console.c?rev=35833&r1=35832&r2=35833&view=diff
==============================================================================
--- trunk/tools/sysreg2/console.c [iso-8859-1] (original)
+++ trunk/tools/sysreg2/console.c [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -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;

Modified: trunk/tools/sysreg2/makefile
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/makefile?rev=35833&r1=35832&r2=35833&view=diff
==============================================================================
--- trunk/tools/sysreg2/makefile [iso-8859-1] (original)
+++ trunk/tools/sysreg2/makefile [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -10,7 +10,7 @@
 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) 
 

Added: trunk/tools/sysreg2/options.c
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/options.c?rev=35833&view=auto
==============================================================================
--- trunk/tools/sysreg2/options.c (added)
+++ trunk/tools/sysreg2/options.c [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -1,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;
+}
+

Propchange: trunk/tools/sysreg2/options.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/tools/sysreg2/sysreg.h
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/sysreg.h?rev=35833&r1=35832&r2=35833&view=diff
==============================================================================
--- trunk/tools/sysreg2/sysreg.h [iso-8859-1] (original)
+++ trunk/tools/sysreg2/sysreg.h [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -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);  

Added: trunk/tools/sysreg2/sysreg.xml
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/sysreg.xml?rev=35833&view=auto
==============================================================================
--- trunk/tools/sysreg2/sysreg.xml (added)
+++ trunk/tools/sysreg2/sysreg.xml [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -1,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>

Propchange: trunk/tools/sysreg2/sysreg.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/tools/sysreg2/virt.c
URL: http://svn.reactos.org/svn/reactos/trunk/tools/sysreg2/virt.c?rev=35833&r1=35832&r2=35833&view=diff
==============================================================================
--- trunk/tools/sysreg2/virt.c [iso-8859-1] (original)
+++ trunk/tools/sysreg2/virt.c [iso-8859-1] Sun Aug 31 10:21:45 2008
@@ -51,7 +51,7 @@
         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 @@
             name = virDomainGetName(vDomPtr);
             domname = strdup(name);
             virDomainFree(vDomPtr);
-            vDomPtr = virDomainLookupByName(vConn, domname);
             free(domname);
         }
     }
@@ -121,32 +120,42 @@
 
 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;
 }
 



More information about the Ros-diffs mailing list