summaryrefslogtreecommitdiffstats
path: root/test.py
blob: 59608a83cdf541db3af49494d03fcbc785b1503d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
#.awk '$0 ~ /case [0-9]+: .. 3/ { print $2 }' src/dmidecode.c|tr ':\n' ', '

from pprint import pprint
import os, sys, random

print "Importing module...",
import dmidecode
print "Done"

print "Testing check for write permission on dump...",
print not dmidecode.dump() and "Good" or "Bad"

print "Testing that default device is /dev/mem",
print dmidecode.get_dev() == "/dev/mem" and "Good" or "Bad"

print "Testing ability to change device to /tmp/foo...",
print dmidecode.set_dev("/tmp/foo") and "Good" or "Bad"

print "Testing that device has changed to /tmp/foo...",
print dmidecode.get_dev() == "/tmp/foo" and "Good" or "Bad"

print "Testing that write on new file is ok...",
print dmidecode.dump() and "Good" or "Bad"

print "Testing that file was actually written...",
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..."%dev); sys.stdout.flush()
  total += 1
  if dmidecode.set_dev(dev) and dmidecode.get_dev() == dev:
    success += 1
    sys.stdout.write("...\n")
    for i in types:
      sys.stdout.write("   * Testing type %i..."%i); sys.stdout.flush()
      output = dmidecode.type(i).keys()
      total += 1
      sys.stdout.write("Done (%s)\n"%output)
      success += 1
    for section in sections:
      total += 1
      sys.stdout.write("   * Testing %s..."%section); sys.stdout.flush()
      output = getattr(dmidecode, section)().keys()
      sys.stdout.write("Done (%s)\n"%output)
      success += 1
  else:
    sys.stdout.write("FAILED\n")

print "Score: %d/%d"%(success, total)