Changeset 213 for test


Ignore:
Timestamp:
03/25/11 11:48:27 (14 years ago)
Author:
tim
Message:

fixed some pyregfi parameter bugs
fixed some iterator memory management problems
updated smoketest script to use ctypes pyregfi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r209 r213  
    1 #!/usr/bin/env python
     1#!/usr/bin/env python3
    22
    33import sys
     4import gc
    45import pyregfi
    56
    6 files = sys.argv[1:]
     7def usage():
     8    sys.stderr.write("USAGE: pyregfi-smoketest.py hive1 [hive2 ...]\n")
    79
    810
    9 def iter_values(key):
    10     i = 0
    11     for value in key.values():
    12         i += 1
    13        
    14     return i
     11# Uses the HiveIterator to walk all keys
     12# Gathers various (meaningless) statistics to exercise simple attribute access
     13# and to hopefully smoke out any bugs that can be identified by changing stats
     14def iterTally(hive):
     15    key_count = 0
     16    key_lens = 0
     17    key_rawlens = 0
     18    value_count = 0
     19    value_lens = 0
     20    value_rawlens = 0
     21
     22    for k in hive:
     23        key_count += 1
     24        if k.name != None:
     25            key_lens += len(k.name)
     26        if k.name_raw != None:
     27            key_rawlens += len(k.name_raw)
     28
     29        for v in k.values:
     30            value_count += 1
     31            if v.name != None:
     32                value_lens += len(v.name)
     33            if v.name_raw != None:
     34                value_rawlens += len(v.name_raw)
     35
     36    print("  Counts: keys=%d, values=%d\n" % (key_count, value_count))
     37    print("  Total name length: keys=%d, values=%d\n" % (key_lens, value_lens))
     38    print("  Total raw name lengths: keys=%d, values=%d\n" % (key_rawlens, value_rawlens))
    1539
    1640
    17 for f in files:
    18     rf = pyregfi.RegistryFile(f)
    19     iter = rf.TreeIterator()
    2041
    21     num_keys = 0
    22     num_values = 0
    23     # The iterator now walks the entire registry hive, depth-first
    24     for key in iter:
    25         #print key.key.keyname
    26         num_keys +=1
    27         num_values += iter_values(key)
     42if len(sys.argv) < 2:
     43    usage()
     44    sys.exit(1)
    2845
    29     print "keys: %d" % num_keys
    30     print "values: %d" % num_values
     46files = []
     47for f in sys.argv[1:]:
     48    files.append((f, open(f,"r+b")))
    3149
     50tests = [("iterTally",iterTally),]
    3251
    33 iter = rf.TreeIterator()
    34 root = iter.current()
    35 for key in root.subkeys():
    36     for subkey in key.subkeys():
    37         for subsubkey in subkey.subkeys():
    38             print key.key.keyname
     52for hname,fh in files:
     53    hive = pyregfi.Hive(fh)
     54    for tname,t in tests:
     55        tstr = "'%s' on '%s'" % (tname,hname)
     56        print("##BEGIN %s:" % tstr)
     57        t(hive)
     58        print("##END %s; messages:" % tstr)
     59        print(pyregfi.GetLogMessages())
     60        print
     61    hive = None
     62    gc.collect()
    3963
     64files = None
     65tests = None
     66gc.collect()
     67print gc.garbage
Note: See TracChangeset for help on using the changeset viewer.