Changeset 228 for test


Ignore:
Timestamp:
04/18/11 16:25:46 (13 years ago)
Author:
tim
Message:

added a test case for pyregfi multithreaded use
updated the regfi multithreaded test case
fixed several ctypes interface problems in pyregfi
added locking to pyregfi iterators for thread safety
fixed regfi talloc race conditions with an additional lock

Location:
test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/Makefile

    r180 r228  
    55OPTS=-std=gnu99 -pedantic -Wall -ggdb
    66INC:=-I../trunk/include -I../trunk/src -I/usr/local/include
    7 LIB=-L/usr/local/lib -lm -lpthread
     7LIB=-L/usr/local/lib -lm -lpthread -ltalloc
    88
    99REGFI_THREADTEST=regfi-threadtest
     
    1414
    1515deps:
    16         cd ../trunk && $(MAKE) clean
    17         cd ../trunk && $(MAKE) lib
     16        cd ../trunk && scons libregfi
    1817
    1918$(REGFI_THREADTEST): regfi-threadtest.o
  • test/pyregfi-smoketest.py

    r227 r228  
    55import io
    66import time
     7import threading
    78import pyregfi
    89
     
    189190        pass
    190191
     192
     193def threadIterMain(iter):
     194    x = 0
     195    try:
     196        for k in iter:
     197            #x += len(k.name) + len(k.subkeys)
     198            pass
     199    except Exception as e:
     200        print("%s dying young: %s" % (threading.current_thread().name, repr(e)))
     201        # Exceptions are thrown on iteration because python state gets out of
     202        # whack.  That's fine, because we're really just interested in finding
     203        # segfaults.  People should not use iterators without locks, but it
     204        # should at least not segfault on them.
     205        pass
     206    print("%s finished" % threading.current_thread().name)
     207
     208def iterMultithread(hive, fh):
     209    num_threads = 10
     210    iter = pyregfi.HiveIterator(hive)
     211    threads = []
     212    for t in range(0,num_threads):
     213        threads.append(threading.Thread(target=threadIterMain, args=(iter,)))
     214    for t in threads:
     215        t.start()
     216    for t in threads:
     217        t.join()
     218   
     219
    191220tests = {
    192221    "iterTallyNames":iterTallyNames,
     
    197226    "iterIterWalk":iterIterWalk,
    198227    "iterCallbackIO":iterCallbackIO,
     228    "iterMultithread":iterMultithread,
    199229    }
    200230
  • test/regfi-threadtest.c

    r185 r228  
    22 * A program to stress test regfi under multithreaded use.
    33 *
    4  * Copyright (C) 2005-2010 Timothy D. Morgan
     4 * Copyright (C) 2005-2011 Timothy D. Morgan
    55 * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
    66 *
     
    4646
    4747
    48 
    4948void traverseValueList(REGFI_ITERATOR* iter)
    5049{
    51   const REGFI_VK_REC* value;
    52 
    53   value = regfi_iterator_first_value(iter);
    54   while(value != NULL)
    55   {
     50  const REGFI_VK* value;
     51  bool ret;
     52
     53  for(ret=regfi_iterator_first_value(iter);
     54      ret;
     55      ret=regfi_iterator_next_value(iter))
     56  {
     57    value = regfi_iterator_cur_value(iter);
    5658    printMsgs(iter->f);
    5759    regfi_free_record(value);
    58     value = regfi_iterator_next_value(iter);
    5960  }
    6061}
     
    6364void traverseKeyTree(REGFI_ITERATOR* iter)
    6465{
    65   const REGFI_NK_REC* root = NULL;
    66   const REGFI_NK_REC* cur = NULL;
    67   const REGFI_NK_REC* sub = NULL;
    68   const REGFI_SK_REC* sk;
     66  const REGFI_NK* root = NULL;
     67  const REGFI_NK* cur = NULL;
     68  const REGFI_NK* sub = NULL;
     69  const REGFI_SK* sk;
    6970  bool print_this = true;
    7071
    7172  root = cur = regfi_iterator_cur_key(iter);
    72   sub = regfi_iterator_first_subkey(iter);
     73  regfi_iterator_first_subkey(iter);
     74  sub = regfi_iterator_cur_subkey(iter);
    7375  printMsgs(iter->f);
    7476
     
    8688      {
    8789        /* We're done with this sub-tree, going up and hitting other branches. */
     90        regfi_free_record(cur);
    8891        if(!regfi_iterator_up(iter))
    8992        {
     
    9598        /*      fprintf(stderr, "%s\n", cur->keyname);*/
    9699        printMsgs(iter->f);
    97         sk = regfi_iterator_cur_sk(iter);
    98         printMsgs(iter->f);
    99100        if(cur == NULL)
    100101          bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
    101      
    102         sub = regfi_iterator_next_subkey(iter);
     102        sk = regfi_fetch_sk(iter->f, cur);
     103        printMsgs(iter->f);
     104        regfi_free_record(sk);
     105
     106        regfi_iterator_next_subkey(iter);
     107        sub = regfi_iterator_cur_subkey(iter);
    103108      }
    104109      print_this = false;
     
    108113       * Let's move down and print this first sub-tree out.
    109114       */
     115      regfi_free_record(cur);
    110116      if(!regfi_iterator_down(iter))
    111117      {
     
    118124      regfi_free_record(sub);
    119125
    120       sub = regfi_iterator_first_subkey(iter);
     126      regfi_iterator_first_subkey(iter);
     127      sub = regfi_iterator_cur_subkey(iter);
    121128      printMsgs(iter->f);
    122129      print_this = true;
     
    124131    printMsgs(iter->f);
    125132  } while(!((cur == root) && (sub == NULL)));
     133  regfi_free_record(root);
    126134
    127135  if(print_verbose)
     
    138146  regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR);
    139147
    140   iter = regfi_iterator_new((REGFI_FILE*)f, REGFI_ENCODING_ASCII);
     148  iter = regfi_iterator_new((REGFI_FILE*)f);
    141149  if(iter == NULL)
    142150  {
     
    198206  }
    199207
    200   f = regfi_alloc(fd);
     208  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
    201209  if(f == NULL)
    202210  {
     
    214222    pthread_join(threads[i], NULL);
    215223
     224  free(threads);
    216225  regfi_free(f);
    217226  close(fd);
Note: See TracChangeset for help on using the changeset viewer.