Changeset 220 for test


Ignore:
Timestamp:
03/31/11 13:20:05 (14 years ago)
Author:
tim
Message:

reorganized code
added remaining methods to iterator
added test case for new methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/pyregfi-smoketest.py

    r219 r220  
    88def usage():
    99    sys.stderr.write("USAGE: pyregfi-smoketest.py hive1 [hive2 ...]\n")
     10
     11
     12
     13
     14# Uses the HiveIterator to walk all keys
     15# Gathers various (meaningless) statistics to exercise simple attribute access
     16# and to hopefully smoke out any bugs that can be identified by changing stats
     17def iterTallyNames(hive):
     18    key_count = 0
     19    key_lens = 0
     20    key_rawlens = 0
     21    value_count = 0
     22    value_lens = 0
     23    value_rawlens = 0
     24
     25    for k in hive:
     26        key_count += 1
     27        if k.name != None:
     28            key_lens += len(k.name)
     29        if k.name_raw != None:
     30            key_rawlens += len(k.name_raw)
     31
     32        for v in k.values:
     33            value_count += 1
     34            if v.name != None:
     35                value_lens += len(v.name)
     36            if v.name_raw != None:
     37                value_rawlens += len(v.name_raw)
     38
     39    print("  Counts: keys=%d, values=%d" % (key_count, value_count))
     40    print("  Total name length: keys=%d, values=%d" % (key_lens, value_lens))
     41    print("  Total raw name lengths: keys=%d, values=%d" % (key_rawlens, value_rawlens))
    1042
    1143
     
    2355
    2456    return path
    25 
    26 
    27 # Uses the HiveIterator to walk all keys
    28 # Gathers various (meaningless) statistics to exercise simple attribute access
    29 # and to hopefully smoke out any bugs that can be identified by changing stats
    30 def iterTallyNames(hive):
    31     key_count = 0
    32     key_lens = 0
    33     key_rawlens = 0
    34     value_count = 0
    35     value_lens = 0
    36     value_rawlens = 0
    37 
    38     for k in hive:
    39         key_count += 1
    40         if k.name != None:
    41             key_lens += len(k.name)
    42         if k.name_raw != None:
    43             key_rawlens += len(k.name_raw)
    44 
    45         for v in k.values:
    46             value_count += 1
    47             if v.name != None:
    48                 value_lens += len(v.name)
    49             if v.name_raw != None:
    50                 value_rawlens += len(v.name_raw)
    51 
    52     print("  Counts: keys=%d, values=%d" % (key_count, value_count))
    53     print("  Total name length: keys=%d, values=%d" % (key_lens, value_lens))
    54     print("  Total raw name lengths: keys=%d, values=%d" % (key_rawlens, value_rawlens))
    55 
    5657
    5758# For each key in the hive, this traverses the parent links up to the root,
     
    154155    print("  Modified stat: %f" % modified_stat)
    155156
     157
     158
     159def iterIterWalk(hive):
     160    sk_stat = 0.0
     161    v_stat = 0.0
     162    iter = pyregfi.HiveIterator(hive)
     163    for k in iter:
     164        path = getCurrentPath(k)
     165        try:
     166            hive_iter = hive.subtree(path)
     167            sk = hive_iter.first_subkey()
     168            while sk != None:
     169                ssk = hive_iter.find_subkey(sk.name)
     170                sk_stat += len(ssk.name)
     171                sk = hive_iter.next_subkey()
     172
     173            v = hive_iter.first_value()
     174            while v != None:
     175                vv = hive_iter.find_value(v.name)
     176                v_stat += len(vv.name)
     177                v = hive_iter.next_value()
     178
     179        except Exception as e:
     180            print("WARNING: Could not decend to path '%s'.\nError:\n %s\n%s" % (path,e.args,e))
     181    print("   Subkey stat: %f" % sk_stat)
     182    print("   Value stat: %f" % v_stat)
     183
     184
     185
    156186if len(sys.argv) < 2:
    157187    usage()
     
    159189
    160190
    161 #tests = [("iterTallyNames",iterTallyNames),("iterParentWalk",iterParentWalk),("iterTallyData",iterTallyData),("recurseKeyTally",recurseKeyTally),("iterFetchRelated",iterFetchRelated),]
    162 tests = [("iterFetchRelated",iterFetchRelated),]
     191tests = [("iterTallyNames",iterTallyNames),
     192         ("iterParentWalk",iterParentWalk),
     193         ("iterTallyData",iterTallyData),
     194         ("recurseKeyTally",recurseKeyTally),
     195         ("iterFetchRelated",iterFetchRelated),
     196         ("iterIterWalk",iterIterWalk),]
     197
     198tests = [("iterIterWalk",iterIterWalk),]
     199
    163200
    164201files = []
Note: See TracChangeset for help on using the changeset viewer.