Changeset 215 for test


Ignore:
Timestamp:
03/27/11 21:46:11 (14 years ago)
Author:
tim
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r214 r215  
    33import sys
    44import gc
     5import time
    56import pyregfi
    67
    78def usage():
    89    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
    928
    1029
     
    3958
    4059
     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
    4178
    4279if len(sys.argv) < 2:
     
    4481    sys.exit(1)
    4582
     83
     84tests = [("iterTally",iterTally),("iterParentWalk",iterParentWalk),]
     85
    4686files = []
    4787for f in sys.argv[1:]:
    4888    files.append((f, open(f,"r+b")))
    4989
    50 tests = [("iterTally",iterTally),]
    5190
     91start_time = time.time()
    5292for hname,fh in files:
    5393    hive = pyregfi.Hive(fh)
    5494    for tname,t in tests:
     95        teststart = time.time()
    5596        tstr = "'%s' on '%s'" % (tname,hname)
    5697        print("##BEGIN %s:" % tstr)
    5798        t(hive)
    58         print("##END %s; messages:" % tstr)
     99        print("##END %s; runtime=%f; messages:" % (tstr, time.time() - teststart))
    59100        print(pyregfi.GetLogMessages())
    60101        print
    61     hive = None
     102        sys.stdout.flush()
    62103
     104hive = None
    63105files = None
    64106tests = None
    65107gc.collect()
     108print("### Tests Completed, runtime: %f ###" % (time.time() -  start_time))
    66109#print(gc.garbage)
Note: See TracChangeset for help on using the changeset viewer.