summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--contrib/python-dmidecode.spec19
-rw-r--r--debian/changelog10
-rw-r--r--src/version.h2
-rw-r--r--unit-tests/Makefile30
-rw-r--r--unit-tests/POCDemo.py12
-rw-r--r--unit-tests/demo.c99
-rw-r--r--unit-tests/demo.h14
-rw-r--r--unit-tests/dmixml.c248
-rw-r--r--unit-tests/dmixml.h43
-rw-r--r--unit-tests/libxml_wrap.h249
-rw-r--r--unit-tests/private/DellPrecisionWorkStation-490.dmpbin0 -> 3919 bytes
-rw-r--r--unit-tests/private/LenovoThinkPad-T61p.dmpbin0 -> 2469 bytes
-rwxr-xr-xunit-tests/unit70
14 files changed, 73 insertions, 732 deletions
diff --git a/Makefile b/Makefile
index 107dbdb..6793970 100644
--- a/Makefile
+++ b/Makefile
@@ -44,15 +44,20 @@ clean:
tarball:
rm -rf $(PACKAGE)-$(VERSION)
mkdir $(PACKAGE)-$(VERSION)
- cp -r contrib doc examples Makefile man README src dmidecode.py $(PACKAGE)-$(VERSION)
+ cp -r contrib doc examples Makefile man README src dmidecode.py unit-tests/ $(PACKAGE)-$(VERSION)
tar -czvf $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION)
-rpm: tarball
+rpm-prep:
mkdir -p rpm/{BUILD,RPMS,SRPMS,SPECS,SOURCES}
cp contrib/$(PACKAGE).spec rpm/SPECS
cp $(PACKAGE)-$(VERSION).tar.gz rpm/SOURCES
+
+rpm: tarball rpm-prep
rpmbuild -ba --define "_topdir $(shell pwd)/rpm" rpm/SPECS/$(PACKAGE).spec
+rpm-md5: tarball rpm-prep
+ rpmbuild-md5 -ba --define "_topdir $(shell pwd)/rpm" rpm/SPECS/$(PACKAGE).spec
+
unit:
$(MAKE) -C unit-tests
diff --git a/contrib/python-dmidecode.spec b/contrib/python-dmidecode.spec
index b2848e6..0d8bde2 100644
--- a/contrib/python-dmidecode.spec
+++ b/contrib/python-dmidecode.spec
@@ -1,15 +1,16 @@
-%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
-%{!?python_ver: %define python_ver %(%{__python} -c "import sys ; print sys.version[:3]")}
+%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
+%{!?python_ver: %global python_ver %(%{__python} -c "import sys ; print sys.version[:3]")}
Summary: Python module to access DMI data
Name: python-dmidecode
-Version: 3.10.7
+Version: 3.10.8
Release: 1%{?dist}
License: GPLv2
Group: System Environment/Libraries
URL: http://projects.autonomy.net.au/python-dmidecode/
Source0: http://src.autonomy.net.au/python-dmidecode/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
+Requires: libxml2-python
BuildRequires: libxml2-python
BuildRequires: libxml2-devel
BuildRequires: python-devel
@@ -24,6 +25,9 @@ as python data structures or as XML data using libxml2.
%build
make build
+cd unit-tests
+make
+cd ..
%install
rm -rf $RPM_BUILD_ROOT
@@ -42,9 +46,16 @@ rm -rf $RPM_BUILD_ROOT
%if "%{python_ver}" >= "2.5"
%{python_sitearch}/*.egg-info
%endif
-/usr/share/python-dmidecode/pymap.xml
+%{_datadir}/python-dmidecode/
%changelog
+* Thu Nov 26 2009 David Sommerseth <davids@redhat.com> - 3.10.7-3
+- Fixed even more .spec file issues and removed explicit mentioning
+ of /usr/share/python-dmidecode/pymap.xml
+
+* Wed Nov 25 2009 David Sommerseth <davids@redhat.com> - 3.10.7-2
+- Fixed some .spec file issues (proper Requires, use _datadir macro)
+
* Wed Sep 23 2009 Nima Talebi <nima@it.net.au> - 3.10.7-1
- Updated source0 to new 3.10.7 tar ball
diff --git a/debian/changelog b/debian/changelog
index dc103c6..439175d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+python-dmidecode (3.10.8-1) unstable; urgency=low
+
+ * New Upstream release.
+ * Packaged unit-test to tarball.
+ * Rewritten unit-test to be able to run as non-root user, where it will not
+ try to read /dev/mem.
+ * Added two dmidump data files to the unit-test.
+
+ -- Nima Talebi <nima@it.net.au> Mon, 14 Dec 2009 17:11:53 +1100
+
python-dmidecode (3.10.7-3) unstable; urgency=low
* Last of URI fixes (#540389).
diff --git a/src/version.h b/src/version.h
index 133c4e2..4ea8b89 100644
--- a/src/version.h
+++ b/src/version.h
@@ -1 +1 @@
-#define VERSION "3.10.7"
+#define VERSION "3.10.8"
diff --git a/unit-tests/Makefile b/unit-tests/Makefile
index 01706a3..be2fcf9 100644
--- a/unit-tests/Makefile
+++ b/unit-tests/Makefile
@@ -1,33 +1,5 @@
-## This one is important to get right ...
-## We need to link in the libxml2mod.so file from here
-PYLIBDIR := /usr/lib64/python2.5/site-packages
-PYLIBDIR := /usr/lib/python-support/python-libxml2/python2.5
-
-# Defaults, should be fine
-CFLAGS=-I. $(shell xml2-config --cflags) -g -Wall $(shell python-config --cflags)
-
-LIBS=$(shell xml2-config --libs) -lxml2mod $(shell python-config --libs)
-LIBDIR=-L $(PYLIBDIR)
-
-.SUFFIX=.c .o .so
-
-all : test
-
-demomodule.so : demo.o dmixml.o
- @echo "Linking: $@"
- @gcc -fPIC --shared -o $@ $^ $(LIBS) $(LIBDIR)
-
-.c.o :
- @echo "Compiling $<"
- @gcc -fPIC -c $< $(CFLAGS)
-
-#test : demomodule.so
test :
- @echo "=========================================="
- @echo " Running proof-of-concept code"
- @echo "=========================================="
- @echo ""
- @python unit
+ python unit
clean :
rm -f *.{py[oc],o,so} *~
diff --git a/unit-tests/POCDemo.py b/unit-tests/POCDemo.py
deleted file mode 100644
index 475a62b..0000000
--- a/unit-tests/POCDemo.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import libxml2
-import demomodule # This is our core module
-
-class POCDemo:
- """Demo of a wrapper class to return proper python libxml2 objects"""
-
- def GetXMLdoc(self):
- return libxml2.xmlDoc( _obj = demomodule.dump_doc() )
-
- def GetXMLnode(self):
- return libxml2.xmlNode( _obj = demomodule.dump_node() )
-
diff --git a/unit-tests/demo.c b/unit-tests/demo.c
deleted file mode 100644
index 265f3cb..0000000
--- a/unit-tests/demo.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For the avoidance of doubt the "preferred form" of this code is one which
- * is in an open unpatent encumbered format. Where cryptographic key signing
- * forms part of the process of creating an executable the information
- * including keys needed to generate an equivalently functional executable
- * are deemed to be part of the source code.
- */
-
-#include "demo.h"
-
-xmlNode *gen_nodes(const char *entry ) {
- xmlNode *c_xmlNode_root = NULL;
- xmlNode *c_xmlNode_tag = NULL;
-
- // Prepare a root node
- c_xmlNode_root = xmlNewNode(NULL, (xmlChar *) "dmixml_demo");
- assert( c_xmlNode_root != NULL );
-
- dmixml_AddAttribute(c_xmlNode_root, "entrypoint", "%s", entry);
-
- // Populate XML
- dmixml_AddTextChild(c_xmlNode_root, "Test", "Yes, just testing");
-
- c_xmlNode_tag = dmixml_AddTextChild(c_xmlNode_root, "tag1", "Another test");
- dmixml_AddAttribute(c_xmlNode_tag, "TestTagID", "%i", 1);
-
- c_xmlNode_tag = c_xmlNode_root;
- int i;
- for(i = 0; i <= 3; ++i) {
- c_xmlNode_tag = xmlNewChild(c_xmlNode_tag, NULL, (xmlChar *) "subtag", NULL);
- dmixml_AddAttribute(c_xmlNode_tag, "SubLevel", "%i", i);
- }
- dmixml_AddTextContent(c_xmlNode_tag, "%s - Adding data to the tag at sublevel %i", "TEST", i-1);
-
- return c_xmlNode_root;
-}
-
-
-
-
-PyObject* demo_dump_doc() {
- PyObject *py_xmlDoc = NULL;
- xmlDoc *c_xmlDoc = NULL;
-
- // Create an XML document
- c_xmlDoc = xmlNewDoc((xmlChar *) "1.0");
- assert( c_xmlDoc != NULL );
-
- // Generate XML nodes and assign the root node to the document
- xmlDocSetRootElement( c_xmlDoc, gen_nodes("demo_dump_doc") );
-
- py_xmlDoc = libxml_xmlDocPtrWrap((xmlDocPtr) c_xmlDoc);
- Py_INCREF(py_xmlDoc);
-
- return py_xmlDoc;
-}
-
-PyObject* demo_dump_node() {
- PyObject *py_xmlNode = NULL;
- xmlNode *nodes = NULL;
-
- nodes = gen_nodes("demo_dump_node");
- py_xmlNode = libxml_xmlNodePtrWrap((xmlNodePtr) nodes);
- Py_INCREF(py_xmlNode);
-
- return py_xmlNode;
-}
-
-
-
-static PyMethodDef DemoMethods[] = {
- { "dump_doc", demo_dump_doc, METH_NOARGS, (char *)"Return an XML document" },
- { "dump_node", demo_dump_node, METH_NOARGS, (char *)"Retuen an XML node" },
- { NULL, NULL, 0, NULL }
-};
-
-PyMODINIT_FUNC initdemomodule(void) {
- PyObject *module =
- Py_InitModule3((char *)"demomodule", DemoMethods,
- "LibXML2 DMIDecode Proof-of-Concept Python Module");
-
- PyObject *version = PyString_FromString("0.10");
- Py_INCREF(version);
- PyModule_AddObject(module, "version", version);
-}
diff --git a/unit-tests/demo.h b/unit-tests/demo.h
deleted file mode 100644
index 21a5468..0000000
--- a/unit-tests/demo.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <Python.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <libxml/tree.h>
-#include "libxml_wrap.h"
-
-#include "dmixml.h"
-
-extern PyObject* demo_dump(void);
-PyMODINIT_FUNC initdemomodule(void);
-PyObject* demo_dump_doc(void);
-PyObject* demo_dump_node(void);
diff --git a/unit-tests/dmixml.c b/unit-tests/dmixml.c
deleted file mode 100644
index dbca0c3..0000000
--- a/unit-tests/dmixml.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/* Simplified XML API for dmidecode
- *
- * Copyright 2009 David Sommerseth <davids@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For the avoidance of doubt the "preferred form" of this code is one which
- * is in an open unpatent encumbered format. Where cryptographic key signing
- * forms part of the process of creating an executable the information
- * including keys needed to generate an equivalently functional executable
- * are deemed to be part of the source code.
- */
-
-#include <string.h>
-#include <stdarg.h>
-#include <assert.h>
-
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <libxml/xmlstring.h>
-
-// Internal function for dmixml_* functions ... builds up a variable xmlChar* string
-xmlChar *dmixml_buildstr(size_t len, const char *fmt, va_list ap) {
- xmlChar *ret = NULL, *xmlfmt = NULL;
- xmlChar *ptr = NULL;
-
- ret = (xmlChar *) malloc(len+2);
- assert( ret != NULL );
- memset(ret, 0, len+2);
-
- xmlfmt = xmlCharStrdup(fmt);
- assert( xmlfmt != NULL );
-
- xmlStrVPrintf(ret, len, xmlfmt, ap);
- free(xmlfmt);
-
- // Right trim the string
- ptr = ret + xmlStrlen(ret)-1;
- while( (ptr >= ret) && (*ptr == ' ') ) {
- *ptr = 0;
- ptr--;
- }
- return ret;
-}
-
-
-// Adds an XML property/attribute to the given XML node
-//
-// xmldata_n = "<test/>";
-// dmixml_AddAttribute(xmldata_n, "value", "1234");
-// gives: xmldata_n = "<test value="1234/>"
-//
-
-xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...)
-{
- xmlChar *val_s = NULL, *atrname_s = NULL;
- xmlAttr *res = NULL;
- va_list ap;
-
- if( (node == NULL) || (atrname == NULL) || (fmt == NULL) ) {
- return NULL;
- }
-
- atrname_s = xmlCharStrdup(atrname);
- assert( atrname_s != NULL );
-
- va_start(ap, fmt);
- val_s = dmixml_buildstr(2048, fmt, ap);
- va_end(ap);
-
- res = xmlNewProp(node, atrname_s,
- (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
-
- free(atrname_s);
- free(val_s);
-
- assert( res != NULL );
- return res;
-}
-
-
-// Adds a new XML tag to the current node with the given tag name and value.
-//
-// xmldata_n = "<test>";
-// dmixml_AddTextChild(xmldata_n, "sublevel1", "value");
-// gives: xmldata_n = "<test><sublevel1>value</sublevel1></test>"
-//
-xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...)
-{
- xmlChar *val_s = NULL, *tagname_s = NULL;
- xmlNode *res = NULL;
- va_list ap;
-
- if( (node == NULL) || (tagname == NULL) || (fmt == NULL) ) {
- return NULL;
- }
-
- tagname_s = xmlCharStrdup(tagname);
- assert( tagname_s != NULL );
-
- va_start(ap, fmt);
- val_s = dmixml_buildstr(2048, fmt, ap);
- va_end(ap);
-
- // Do not add any contents if the string contents is "(null)"
- res = xmlNewTextChild(node, NULL, tagname_s,
- (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
-
- free(tagname_s);
- free(val_s);
-
- assert( res != NULL );
- return res;
-}
-
-// Adds a text node child to the current XML node
-//
-// xmldata_n = "<testdata/>;
-// dmixml_AddTextContent(xmldata_n, "some data value");
-// gives: xmldata_n = "<testdata>some data value</testdata>"
-//
-xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...)
-{
- xmlChar *val_s = NULL;
- xmlNode *res = NULL;
- va_list ap;
-
- if( (node == NULL) || (fmt == NULL) ) {
- return NULL;
- }
-
- va_start(ap, fmt);
- val_s = dmixml_buildstr(2048, fmt, ap);
- va_end(ap);
-
- if( xmlStrcmp(val_s, (xmlChar *) "(null)") != 0 ) {
- res = xmlAddChild(node, xmlNewText(val_s));
- } else {
- res = node;
- }
- free(val_s);
-
- assert( res != NULL );
- return res;
-}
-
-
-char *dmixml_GetAttrValue(xmlNode *node, const char *key) {
- xmlAttr *aptr = NULL;
- xmlChar *key_s = NULL;
-
- if( node == NULL ) {
- return NULL;
- }
-
- key_s = xmlCharStrdup(key);
- assert( key_s != NULL );
-
- for( aptr = node->properties; aptr != NULL; aptr = aptr->next ) {
- if( xmlStrcmp(aptr->name, key_s) == 0 ) {
- free(key_s); key_s = NULL;
- // FIXME: Should find better way how to return UTF-8 data
- return (char *)(aptr->children != NULL ? aptr->children->content : NULL);
- }
- }
- free(key_s); key_s = NULL;
- return NULL;
-}
-
-xmlNode *dmixml_FindNode(xmlNode *node, const char *key) {
- xmlNode *ptr_n = NULL;
- xmlChar *key_s = NULL;
-
- if( node->children == NULL ) {
- return NULL;
- }
-
- key_s = xmlCharStrdup(key);
- assert( key_s != NULL );
-
- for( ptr_n = node->children; ptr_n != NULL; ptr_n = ptr_n->next ) {
- if( (ptr_n->type == XML_ELEMENT_NODE)
- && (xmlStrcmp(ptr_n->name, key_s) == 0) ) {
- free(key_s); key_s = NULL;
- return ptr_n;
- }
- }
- free(key_s); key_s = NULL;
- return NULL;
-}
-
-inline char *dmixml_GetContent(xmlNode *node) {
- // FIXME: Should find better way how to return UTF-8 data
- return (((node != NULL) && (node->children != NULL)) ? (char *) node->children->content : NULL);
-}
-
-inline char *dmixml_GetNodeContent(xmlNode *node, const char *key) {
- return dmixml_GetContent(dmixml_FindNode(node, key));
-}
-
-char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx) {
- memset(buf, 0, buflen);
-
- if( xpo == NULL ) {
- return NULL;
- }
-
- switch( xpo->type ) {
- case XPATH_STRING:
- strncpy(buf, (char *)xpo->stringval, buflen-1);
- break;
-
- case XPATH_NUMBER:
- snprintf(buf, buflen-1, "%f", xpo->floatval);
- break;
-
- case XPATH_NODESET:
- if( (xpo->nodesetval != NULL) && (xpo->nodesetval->nodeNr >= (idx+1)) ) {
- char *str = dmixml_GetContent(xpo->nodesetval->nodeTab[idx]);
- if( str != NULL ) {
- strncpy(buf, str, buflen-1);
- } else {
- memset(buf, 0, buflen);
- }
- }
- break;
-
- default:
- fprintf(stderr, "dmixml_GetXPathContent(...):: "
- "Do not know how to handle XPath type %i\n",
- xpo->type);
- return NULL;
- }
- return buf;
-}
-
diff --git a/unit-tests/dmixml.h b/unit-tests/dmixml.h
deleted file mode 100644
index b1d86c6..0000000
--- a/unit-tests/dmixml.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Simplified XML API for dmidecode
- *
- * Copyright 2009 David Sommerseth <davids@redhat.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For the avoidance of doubt the "preferred form" of this code is one which
- * is in an open unpatent encumbered format. Where cryptographic key signing
- * forms part of the process of creating an executable the information
- * including keys needed to generate an equivalently functional executable
- * are deemed to be part of the source code.
- */
-
-#ifndef _XMLHELPER_H
-#define _XMLHELPER_H
-
-#include <stdarg.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-
-xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...);
-xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...);
-xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...);
-
-char *dmixml_GetAttrValue(xmlNode *node, const char *key);
-xmlNode *dmixml_FindNode(xmlNode *, const char *key);
-inline char *dmixml_GetContent(xmlNode *node);
-inline char *dmixml_GetNodeContent(xmlNode *node, const char *key);
-char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx);
-
-#endif
diff --git a/unit-tests/libxml_wrap.h b/unit-tests/libxml_wrap.h
deleted file mode 100644
index eaa5e96..0000000
--- a/unit-tests/libxml_wrap.h
+++ /dev/null
@@ -1,249 +0,0 @@
-#include <Python.h>
-#include <libxml/tree.h>
-#include <libxml/parser.h>
-#include <libxml/parserInternals.h>
-#include <libxml/catalog.h>
-#include <libxml/threads.h>
-#include <libxml/nanoftp.h>
-#include <libxml/nanohttp.h>
-#include <libxml/uri.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-#include <libxml/debugXML.h>
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
-#include <libxml/xinclude.h>
-#include <libxml/xpointer.h>
-#include <libxml/xmlunicode.h>
-#include <libxml/xmlregexp.h>
-#include <libxml/xmlautomata.h>
-#include <libxml/xmlreader.h>
-#ifdef LIBXML_SCHEMAS_ENABLED
-#include <libxml/relaxng.h>
-#include <libxml/xmlschemas.h>
-#endif
-
-/**
- * ATTRIBUTE_UNUSED:
- *
- * Macro used to signal to GCC unused function parameters
- * Repeated here since the definition is not available when
- * compiled outside the libxml2 build tree.
- */
-#ifdef __GNUC__
-#ifdef ATTRIBUTE_UNUSED
-#undef ATTRIBUTE_UNUSED
-#endif
-#ifndef ATTRIBUTE_UNUSED
-#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif /* ATTRIBUTE_UNUSED */
-#else
-#define ATTRIBUTE_UNUSED
-#endif
-
-#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlNode_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlNodePtr obj;
-} PyxmlNode_Object;
-
-#define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlXPathContext_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlXPathContextPtr obj;
-} PyxmlXPathContext_Object;
-
-#define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlXPathParserContext_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlXPathParserContextPtr obj;
-} PyxmlXPathParserContext_Object;
-
-#define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PyparserCtxt_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlParserCtxtPtr obj;
-} PyparserCtxt_Object;
-
-#define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PyValidCtxt_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlValidCtxtPtr obj;
-} PyValidCtxt_Object;
-
-#define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
- (((Pycatalog_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlCatalogPtr obj;
-} Pycatalog_Object;
-
-#ifdef LIBXML_REGEXP_ENABLED
-#define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlReg_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlRegexpPtr obj;
-} PyxmlReg_Object;
-#endif /* LIBXML_REGEXP_ENABLED */
-
-#ifdef LIBXML_READER_ENABLED
-#define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlTextReader_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlTextReaderPtr obj;
-} PyxmlTextReader_Object;
-
-#define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
- (((PyxmlTextReaderLocator_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlTextReaderLocatorPtr obj;
-} PyxmlTextReaderLocator_Object;
-#endif
-
-#define PyURI_Get(v) (((v) == Py_None) ? NULL : \
- (((PyURI_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlErrorPtr obj;
-} PyError_Object;
-
-#define PyError_Get(v) (((v) == Py_None) ? NULL : \
- (((PyError_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlOutputBufferPtr obj;
-} PyoutputBuffer_Object;
-
-#define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
- (((PyoutputBuffer_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlParserInputBufferPtr obj;
-} PyinputBuffer_Object;
-
-#define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
- (((PyinputBuffer_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlURIPtr obj;
-} PyURI_Object;
-
-/* FILE * have their own internal representation */
-#define PyFile_Get(v) (((v) == Py_None) ? NULL : \
- (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
-
-#ifdef LIBXML_SCHEMAS_ENABLED
-typedef struct {
- PyObject_HEAD
- xmlRelaxNGPtr obj;
-} PyrelaxNgSchema_Object;
-
-#define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
- (((PyrelaxNgSchema_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlRelaxNGParserCtxtPtr obj;
-} PyrelaxNgParserCtxt_Object;
-
-#define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PyrelaxNgParserCtxt_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlRelaxNGValidCtxtPtr obj;
-} PyrelaxNgValidCtxt_Object;
-
-#define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PyrelaxNgValidCtxt_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlSchemaPtr obj;
-} PySchema_Object;
-
-#define PySchema_Get(v) (((v) == Py_None) ? NULL : \
- (((PySchema_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlSchemaParserCtxtPtr obj;
-} PySchemaParserCtxt_Object;
-
-#define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PySchemaParserCtxt_Object *)(v))->obj))
-
-typedef struct {
- PyObject_HEAD
- xmlSchemaValidCtxtPtr obj;
-} PySchemaValidCtxt_Object;
-
-#define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
- (((PySchemaValidCtxt_Object *)(v))->obj))
-
-#endif /* LIBXML_SCHEMAS_ENABLED */
-
-PyObject * libxml_intWrap(int val);
-PyObject * libxml_longWrap(long val);
-PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
-PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
-PyObject * libxml_charPtrWrap(char *str);
-PyObject * libxml_constcharPtrWrap(const char *str);
-PyObject * libxml_charPtrConstWrap(const char *str);
-PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
-PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
-PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
-PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
-PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
-PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
-PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
-PyObject * libxml_doubleWrap(double val);
-PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
-PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
-PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
-PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
-PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
-PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
-PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
-PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
-PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
-#ifdef LIBXML_REGEXP_ENABLED
-PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
-#endif /* LIBXML_REGEXP_ENABLED */
-#ifdef LIBXML_READER_ENABLED
-PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
-PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
-#endif
-
-xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
-#ifdef LIBXML_SCHEMAS_ENABLED
-PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
-PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
-PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
-PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
-PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
-PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
-#endif /* LIBXML_SCHEMAS_ENABLED */
-PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error);
-PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
diff --git a/unit-tests/private/DellPrecisionWorkStation-490.dmp b/unit-tests/private/DellPrecisionWorkStation-490.dmp
new file mode 100644
index 0000000..17e0d6c
--- /dev/null
+++ b/unit-tests/private/DellPrecisionWorkStation-490.dmp
Binary files differ
diff --git a/unit-tests/private/LenovoThinkPad-T61p.dmp b/unit-tests/private/LenovoThinkPad-T61p.dmp
new file mode 100644
index 0000000..5815fc0
--- /dev/null
+++ b/unit-tests/private/LenovoThinkPad-T61p.dmp
Binary files differ
diff --git a/unit-tests/unit b/unit-tests/unit
index ac3edab..dbb1e2e 100755
--- a/unit-tests/unit
+++ b/unit-tests/unit
@@ -5,6 +5,13 @@ from pprint import pprint
import os, sys, random, tempfile, time
import commands
+# Setup temporary sys.path() with our build dir
+(sysname, nodename, release, version, machine) = os.uname()
+pyver = sys.version[:3]
+sys.path.insert(0,'../build/lib.%s-%s-%s' % (sysname.lower(), machine, pyver))
+
+root_user = (os.getuid() == 0 and True or False)
+
DUMPS_D = "private"
def ascii(s, i): return "\033[%d;1m%s\033[0m"%(30+i, str(s))
@@ -63,9 +70,13 @@ def test(r, msg=None, indent=1):
return False
sys.stdout.write(LINE)
-sys.stdout.write(" * Testing for dmidecode (upstream)...")
+sys.stdout.write(" * Testing for command line version of dmidecode ...")
dmidecode_bin = True in [os.path.exists(os.path.join(_, "dmidecode")) for _ in os.getenv("PATH").split(':')]
test(dmidecode_bin)
+if root_user:
+ sys.stdout.write(" * Running test as root user, all tests will be executed\n")
+else:
+ sys.stdout.write(" * %s\n"%red("Running test as normal user, some tests will be skipped"))
sys.stdout.write(" * Creation of temporary files...")
try:
@@ -79,9 +90,11 @@ except:
sys.stdout.write(LINE)
try:
sys.stdout.write(" * Importing module...")
+ sys.stdout.flush()
import libxml2
-# from dmidecodemod import *
import dmidecode
+ if not root_user:
+ sys.stdout.write("\n%s"%cyan("Not running as root, warning above is expected..."))
passed()
sys.stdout.write(" * Version: %s\n"%blue(dmidecode.version))
@@ -99,13 +112,16 @@ try:
sys.stdout.write(" * Testing that device has changed to %s..."%DUMP)
test(dmidecode.get_dev() == DUMP)
- sys.stdout.write(" * Testing that write on new file is ok...")
- test(dmidecode.dump())
+ if root_user:
+ sys.stdout.write(" * Testing that write on new file is ok...")
+ test(dmidecode.dump())
- sys.stdout.write(" * Testing that file was actually written...")
- time.sleep(0.1)
- if test(os.path.exists(DUMP)):
- os.unlink(DUMP)
+ sys.stdout.write(" * Testing that file was actually written...")
+ time.sleep(0.1)
+ if test(os.path.exists(DUMP)):
+ os.unlink(DUMP)
+ else:
+ sys.stdout.write(" * %s" %red("Skip testing API function, missing root privileges: dmidecode.dump()\n"))
types = range(0, 42)+range(126, 128)
bad_types = [-1, -1000, 256]
@@ -115,7 +131,20 @@ try:
devices.extend([os.path.join(DUMPS_D, _) for _ in os.listdir(DUMPS_D)])
else:
sys.stdout.write(" * If you have memory dumps to test, create a directory called `%s' and drop them in there.\n"%(DUMPS_D))
- devices.append("/dev/mem")
+
+ if root_user:
+ devices.append("/dev/mem")
+ else:
+ sys.stdout.write(" * %s\n"%red("Running test as normal user, will not try to read /dev/mem"))
+
+ try:
+ pymap = '../src/pymap.xml'
+ sys.stdout.write(" * Loading %s for XML->Python dictonary mapping..." % pymap)
+ dmidecode.pythonmap(pymap)
+ passed()
+ except:
+ failed()
+
random.shuffle(types)
random.shuffle(devices)
random.shuffle(sections)
@@ -165,6 +194,7 @@ try:
except LookupError, e:
failed(e, 2)
+
dmixml = dmidecode.dmidecodeXML()
try:
sys.stdout.write(" * XML: Swapping result type dmidecodeXML::SetResultType('-')...");
@@ -238,28 +268,6 @@ except ImportError, err:
failed()
print err
-
-"""
-import libxml2
-from POCDemo import POCDemo
-
-test = POCDemo()
-print "Please note the dmixml_demo/@entrypoint attribute in the root node"
-print
-print "-------- xmlDoc ---------------"
-xmldoc = test.GetXMLdoc()
-xmldoc.saveFormatFileEnc("-", "UTF-8", 1)
-
-print
-print "-------- xmlNode ---------------"
-xmldoc2 = libxml2.newDoc("1.0")
-xmlnode = test.GetXMLnode()
-xmldoc2.setRootElement(xmlnode)
-xmldoc2.saveFormatFileEnc("-", "UTF-8", 1)
-"""
-
-
-
sys.stdout.write(LINE)
sys.stdout.write("Devices : %s\n"%cyan(len(devices)))
sys.stdout.write("Total : %s\n"%blue(score["total"]))