source: test/pyregfi-smoketest.py @ 215

Last change on this file since 215 was 215, checked in by tim, 14 years ago

improvements to smoketest script, additional test case
added a function to get a key's parent in both regfi and pyregfi
bug fixes

  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/env python3
2
3import sys
4import gc
5import time
6import pyregfi
7
8def usage():
9    sys.stderr.write("USAGE: pyregfi-smoketest.py hive1 [hive2 ...]\n")
10
11
12# helper function
13def getCurrentPath(key):
14    if key == None:
15        return ''
16    path = []
17    p = key
18    while p != None:
19        path.append(p.name)
20        if p.is_root():
21            break
22        else:
23            p = p.get_parent()
24    path.reverse()
25    del path[0]
26
27    return path
28
29
30# Uses the HiveIterator to walk all keys
31# Gathers various (meaningless) statistics to exercise simple attribute access
32# and to hopefully smoke out any bugs that can be identified by changing stats
33def iterTally(hive):
34    key_count = 0
35    key_lens = 0
36    key_rawlens = 0
37    value_count = 0
38    value_lens = 0
39    value_rawlens = 0
40
41    for k in hive:
42        key_count += 1
43        if k.name != None:
44            key_lens += len(k.name)
45        if k.name_raw != None:
46            key_rawlens += len(k.name_raw)
47
48        for v in k.values:
49            value_count += 1
50            if v.name != None:
51                value_lens += len(v.name)
52            if v.name_raw != None:
53                value_rawlens += len(v.name_raw)
54
55    print("  Counts: keys=%d, values=%d" % (key_count, value_count))
56    print("  Total name length: keys=%d, values=%d" % (key_lens, value_lens))
57    print("  Total raw name lengths: keys=%d, values=%d" % (key_rawlens, value_rawlens))
58
59
60# For each key in the hive, this traverses the parent links up to the root,
61# recording the path as it goes, and then uses the subtree/descend method
62# to find the same key again, verifying it is the same.  This test is currently
63# very slow because no key caching is used.
64def iterParentWalk(hive):
65    i = 1
66    for k in hive:
67        path = getCurrentPath(k)
68        try:
69            hive_iter = hive.subtree(path)
70            if hive_iter.current_key() != k:
71                print("WARNING: k != current_key for path '%s'." % path)
72            else:
73                i += 1
74        except Exception as e:
75            print("WARNING: Could not decend to path '%s'.\nError:\n %s\n%s" % (path,e.args,e))
76    print("   Successfully tested paths on %d keys." % i)
77
78
79if len(sys.argv) < 2:
80    usage()
81    sys.exit(1)
82
83
84tests = [("iterTally",iterTally),("iterParentWalk",iterParentWalk),]
85
86files = []
87for f in sys.argv[1:]:
88    files.append((f, open(f,"r+b")))
89
90
91start_time = time.time()
92for hname,fh in files:
93    hive = pyregfi.Hive(fh)
94    for tname,t in tests:
95        teststart = time.time()
96        tstr = "'%s' on '%s'" % (tname,hname)
97        print("##BEGIN %s:" % tstr)
98        t(hive)
99        print("##END %s; runtime=%f; messages:" % (tstr, time.time() - teststart))
100        print(pyregfi.GetLogMessages())
101        print
102        sys.stdout.flush()
103
104hive = None
105files = None
106tests = None
107gc.collect()
108print("### Tests Completed, runtime: %f ###" % (time.time() -  start_time))
109#print(gc.garbage)
Note: See TracBrowser for help on using the repository browser.