From ecc5f901bbb8c888ca3c9e89296a98442bbb0f9e Mon Sep 17 00:00:00 2001 From: nima Date: Fri, 19 Dec 2008 23:45:55 +0000 Subject: Test case is close to complete, type 127 results in a segfault - (test case is serving its purpose). git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@130 abc39116-655e-4be6-ad55-d661dc543056 --- test.py | 61 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/test.py b/test.py index 157df5c..f00ce3c 100755 --- a/test.py +++ b/test.py @@ -2,7 +2,7 @@ #.awk '$0 ~ /case [0-9]+: .. 3/ { print $2 }' src/dmidecode.c|tr ':\n' ', ' from pprint import pprint -import os, sys +import os, sys, random print "Importing module...", import dmidecode @@ -24,36 +24,49 @@ print "Testing that write on new file is ok...", print dmidecode.dump() and "Good" or "Bad" print "Testing that file was actually written...", -print os.path.exists("/tmp/foo") and "Yes" or "No" - -dmidecode.dump() -os.unlink("/tmp/foo") - -#print os.stat("/tmp/foo") - -#. Now test get/set of memory device file... -#print dmidecode.get_dev() -#print dmidecode.set_dev("private/mem-XXX"); -#print dmidecode.get_dev() - -#. Test taking a dump... - -#. Test all functions using /dev/mem... +if os.path.exists("/tmp/foo"): + sys.stdout.write("Good\n") + os.unlink("/tmp/foo") +else: + sys.stdout.write("FAILED\n") +types = range(0, 42)+range(126, 128) +types = range(0, 42)+[126, 127] +sections = ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"] devices = [os.path.join("private", _) for _ in os.listdir("private")] devices.remove('private/.svn') devices.append("/dev/mem") +random.shuffle(types) +random.shuffle(devices) +random.shuffle(sections) + +total = 0 +success = 0 for dev in devices: - sys.stdout.write(" * Testing %s..."%dmidecode.get_dev()) + sys.stdout.write(" * Testing %s..."%dmidecode.get_dev()); sys.stdout.flush() + total += 1 if dmidecode.set_dev(dev): + success += 1 sys.stdout.write("...\n") - for section in ["bios", "system", "baseboard", "chassis", "processor", "memory", "cache", "connector", "slot"]: - sys.stdout.write(" * Testing %s..."%section) - output = getattr(dmidecode, section) - sys.stdout.write(output and "Done\n" or "FAILED\n") - for i in tuple(range(0, 42))+tuple(range(126, 128)): - sys.stdout.write(" * Testing...") + for i in types: + sys.stdout.write(" * Testing type %i..."%i); sys.stdout.flush() output = len(dmidecode.type(i)) - sys.stdout.write(output and "Done (%d)\n"%i or "FAILED\n") + total += 1 + if output: + sys.stdout.write("Done\n") + success += 1 + else: + sys.stdout.write("FAILED\n") + for section in sections: + total += 1 + sys.stdout.write(" * Testing %s..."%section); sys.stdout.flush() + output = getattr(dmidecode, section) + if output: + sys.stdout.write("Done\n") + success += 1 + else: + sys.stdout.write("FAILED\n") else: sys.stdout.write("FAILED\n") + +print "Score: %d/%d"%(success, total) -- cgit