diff options
-rwxr-xr-x | examples/test.py | 83 | ||||
-rw-r--r-- | src/dmidecode.c | 6 | ||||
-rw-r--r-- | src/dmidecodemodule.c | 2 | ||||
-rw-r--r-- | src/setup-dbg.py | 5 | ||||
-rw-r--r-- | src/setup.py | 4 | ||||
-rw-r--r-- | src/xmlpythonizer.c | 2 |
6 files changed, 66 insertions, 36 deletions
diff --git a/examples/test.py b/examples/test.py index 79f11d3..c645d02 100755 --- a/examples/test.py +++ b/examples/test.py @@ -5,6 +5,29 @@ from pprint import pprint import os, sys, random, tempfile, time import commands +DUMPS_D = "../../pydmidata/" + +def ascii(s, i): return "\033[%d;1m%s\033[0m"%(30+i, str(s)) +def black(s): return "\033[30;1m%s\033[0m"%(str(s)) +def red(s): return "\033[31;1m%s\033[0m"%(str(s)) +def green(s): return "\033[32;1m%s\033[0m"%(str(s)) +def yellow(s): return "\033[33;1m%s\033[0m"%(str(s)) +def blue(s): return "\033[34;1m%s\033[0m"%(str(s)) +def magenta(s): return "\033[35;1m%s\033[0m"%(str(s)) +def cyan(s): return "\033[36;1m%s\033[0m"%(str(s)) +def white(s): return "\033[37;1m%s\033[0m"%(str(s)) + +DISPATCH = { + 1 : red, + 2 : green, + 3 : yellow, + 4 : blue, + 5 : magenta, + 6 : cyan, + 7 : white, +} + +LINE = "%s\n"%(magenta("="*80)) dmidecode = True in [os.path.exists(os.path.join(_, "dmidecode")) for _ in os.getenv("PATH").split(':')] if dmidecode: print "Please install `dmidecode' (the binary) for complete testing." @@ -22,40 +45,40 @@ def test(r): total += 1 if r: - sys.stdout.write("Good\n") + sys.stdout.write("%s\n"%green("PASS")) success += 1 return True else: - sys.stdout.write("FAILED\n") + sys.stdout.write("%s\n"%red("FAIL")) return False total += 1 -print "-"*80 -sys.stdout.write("Importing module...") +sys.stdout.write(LINE) +sys.stdout.write(" * Importing module...") try: import dmidecode success += 1 - sys.stdout.write("Done\n") - sys.stdout.write(" * Version: %s\n"%dmidecode.version) - sys.stdout.write(" * DMI Version String: %s\n"%dmidecode.dmi) + sys.stdout.write("%s\n"%green("PASS")) + sys.stdout.write(" * Version: %s\n"%blue(dmidecode.version)) + sys.stdout.write(" * DMI Version String: %s\n"%blue(dmidecode.dmi)) print "-"*80 - sys.stdout.write("Testing that default device is /dev/mem...") + sys.stdout.write(" * Testing that default device is /dev/mem...") test(dmidecode.get_dev() == "/dev/mem") - sys.stdout.write("Testing that write-lock will not break on dump()...") + sys.stdout.write(" * Testing that write-lock will not break on dump()...") test(not dmidecode.dump()) - sys.stdout.write("Testing ability to change device to %s..."%DUMP) + sys.stdout.write(" * Testing ability to change device to %s..."%DUMP) test(dmidecode.set_dev(DUMP)) - sys.stdout.write("Testing that device has changed to %s..."%DUMP) + 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...") + sys.stdout.write(" * Testing that write on new file is ok...") test(dmidecode.dump()) - sys.stdout.write("Testing that file was actually written...") + sys.stdout.write(" * Testing that file was actually written...") time.sleep(0.1) test(os.path.exists(DUMP)) os.unlink(DUMP) @@ -64,39 +87,39 @@ try: bad_types = [-1, -1000, 256] sections = ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"] devices = [] - if os.path.exists("private"): - devices.extend([os.path.join("private", _) for _ in os.listdir("private")]) - devices.remove('private/.svn') + if os.path.exists(DUMPS_D): + 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 `private' and drop them in there.\n") + 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") random.shuffle(types) random.shuffle(devices) random.shuffle(sections) for dev in devices: - sys.stdout.write(" * Testing %s..."%dev); sys.stdout.flush() + sys.stdout.write(" * Testing %s..."%yellow(dev)); sys.stdout.flush() if test(dmidecode.set_dev(dev) and dmidecode.get_dev() == dev): - print "-"*80 - print sections + sys.stdout.write(LINE) + i = 0 for section in sections: - sys.stdout.write(" * Testing %s..."%section); sys.stdout.flush() + i += 0 + sys.stdout.write(" * Testing %s (%s/%d)..."%cyan(section), i, len(sections)); sys.stdout.flush() output = getattr(dmidecode, section)() test(output is not False) - if output: sys.stdout.write(" * %s\n"%output.keys()) + if output: sys.stdout.write(" * %s\n"%black(output.keys())) - print "-"*80 + sys.stdout.write(LINE) for i in bad_types: - sys.stdout.write(" * Testing bad type %i..."%i); sys.stdout.flush() + sys.stdout.write(" * Testing bad type %s..."%red(i)); sys.stdout.flush() try: output = dmidecode.type(i) test(output is False) except SystemError: - sys.stdout.write("FAILED\n") + sys.stdout.write("%s\n"%red("FAIL")) - print "-"*80 + sys.stdout.write(LINE) for i in types: - sys.stdout.write(" * Testing type %i..."%i); sys.stdout.flush() + sys.stdout.write(" * Testing type %s..."%red(i)); sys.stdout.flush() output = dmidecode.type(i) if dmidecode: _output = commands.getoutput("dmidecode -t %d"%i).strip().split('\n') @@ -107,6 +130,8 @@ try: sys.stdout.write(" * %s\n"%output.keys()) except ImportError: - sys.stdout.write("FAILED\n") + sys.stdout.write("%s\n"%red("FAIL")) -sys.stdout.write("Score: %d/%d\n"%(success, total)) +color = red +if success == total: color = green +sys.stdout.write("Score: %s/%s\n"%(color(success), color(total))) diff --git a/src/dmidecode.c b/src/dmidecode.c index 9a0baa8..de6fb2a 100644 --- a/src/dmidecode.c +++ b/src/dmidecode.c @@ -4931,7 +4931,9 @@ int dumpling(u8 * buf, const char *dumpfile, u8 mode) if((buff = mem_chunk(base, len, DEFAULT_MEM_DEV)) != NULL) { //. Part 1. +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", len, dumpfile); +#endif write_dump(32, len, buff, dumpfile, 0); free(buff); @@ -4941,14 +4943,18 @@ int dumpling(u8 * buf, const char *dumpfile, u8 mode) memcpy(crafted, buf, 32); overwrite_dmi_address(crafted + 0x10); +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", crafted[0x05], dumpfile); +#endif write_dump(0, crafted[0x05], crafted, dumpfile, 1); } else { u8 crafted[16]; memcpy(crafted, buf, 16); overwrite_dmi_address(crafted); +#ifdef NDEBUG printf("# Writing %d bytes to %s.\n", 0x0F, dumpfile); +#endif write_dump(0, 0x0F, crafted, dumpfile, 1); } } else { diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c index 20739a1..1b56837 100644 --- a/src/dmidecodemodule.c +++ b/src/dmidecodemodule.c @@ -488,7 +488,7 @@ PyMODINIT_FUNC initdmidecode(void) module = Py_InitModule3((char *)"dmidecode", DMIDataMethods, "Python extension module for dmidecode"); - version = PyString_FromString("2.10"); + version = PyString_FromString("3.10.6"); Py_INCREF(version); PyModule_AddObject(module, "version", version); diff --git a/src/setup-dbg.py b/src/setup-dbg.py index 8b66f21..0b7a2ed 100644 --- a/src/setup-dbg.py +++ b/src/setup-dbg.py @@ -8,6 +8,7 @@ setup( author = "Nima Talebi & David Sommerseth", author_email = "nima@it.net.au, davids@redhat.com", url = "http://projects.autonomy.net.au/python-dmidecode/", + data_files = [ ('share/python-dmidecode-dbg', ['src/pythonmap.xml']) ], ext_modules = [ Extension( "dmidecode", @@ -21,9 +22,7 @@ setup( "src/xmlpythonizer.c" ], include_dirs = [ "/usr/include/libxml2" ], - libraries = [ "util", "xml2" ], - #libraries = [ "util", "xml2", "efence" ], - data_files = [ ('share/python-dmidecode', ['src/pythonmap.xml']) ] + libraries = [ "util", "xml2" ], #[ "util", "xml2", "efence" ], ) ] ) diff --git a/src/setup.py b/src/setup.py index ded7db4..f9904af 100644 --- a/src/setup.py +++ b/src/setup.py @@ -8,6 +8,7 @@ setup( author = "Nima Talebi & David Sommerseth", author_email = "nima@it.net.au, davids@redhat.com", url = "http://projects.autonomy.net.au/python-dmidecode/", + data_files = [ ('share/python-dmidecode', ['src/pythonmap.xml']) ], ext_modules = [ Extension( "dmidecode", @@ -22,8 +23,7 @@ setup( ], include_dirs = [ "/usr/include/libxml2" ], library_dirs = [ "/home/nima/dev-room/projects/dmidecode" ], - libraries = [ "util", "xml2" ], - data_files = [ ('share/python-dmidecode', ['src/pythonmap.xml']) ] + libraries = [ "util", "xml2" ] ) ] ) diff --git a/src/xmlpythonizer.c b/src/xmlpythonizer.c index d987802..dceeaa2 100644 --- a/src/xmlpythonizer.c +++ b/src/xmlpythonizer.c @@ -880,7 +880,7 @@ PyMODINIT_FUNC initxmlpythonizer(void) { Py_InitModule3((char *)"xmlpythonizer", DemoMethods, "XML to Python Proof-of-Concept Python Module"); - PyObject *version = PyString_FromString("2.10"); + PyObject *version = PyString_FromString("3.10.6"); Py_INCREF(version); PyModule_AddObject(module, "version", version); } |