source: test/pyregfi-smoketest.py @ 216

Last change on this file since 216 was 216, checked in by tim, 13 years ago

added a new testcase to the smoketest for data attributes
fixed data naming issues in pyregfi

  • Property svn:executable set to *
File size: 3.6 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 iterTallyNames(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
79# Uses the HiveIterator to walk all keys
80# Gathers various (meaningless) statistics about data/data_raw attributes
81def iterTallyData(hive):
82    data_stat = 0.0
83    dataraw_stat = 0.0
84   
85    for k in hive:
86        for v in k.values:
87            d = v.data
88            if d == None:
89                data_stat += 0.1
90            elif hasattr(d, "__len__"):
91                data_stat += len(d)
92            else:
93                data_stat += d/2.0**64
94
95            d = v.data_raw
96            if d == None:
97                dataraw_stat += 0.1
98            else:
99                dataraw_stat += len(d)
100
101    print("  Data stat: %f" % data_stat)
102    print("  Raw data stat: %f" % dataraw_stat)
103
104
105
106if len(sys.argv) < 2:
107    usage()
108    sys.exit(1)
109
110
111#tests = [("iterTallyNames",iterTallyNames),("iterParentWalk",iterParentWalk),]
112tests = [("iterTallyData",iterTallyData),]
113
114files = []
115for f in sys.argv[1:]:
116    files.append((f, open(f,"r+b")))
117
118
119start_time = time.time()
120for hname,fh in files:
121    hive = pyregfi.Hive(fh)
122    for tname,t in tests:
123        teststart = time.time()
124        tstr = "'%s' on '%s'" % (tname,hname)
125        print("##BEGIN %s:" % tstr)
126        t(hive)
127        print("##END %s; runtime=%f; messages:" % (tstr, time.time() - teststart))
128        print(pyregfi.GetLogMessages())
129        print
130        sys.stdout.flush()
131
132hive = None
133files = None
134tests = None
135gc.collect()
136print("### Tests Completed, runtime: %f ###" % (time.time() -  start_time))
137#print(gc.garbage)
Note: See TracBrowser for help on using the repository browser.