Ejemplo n.º 1
0
void nfs4_owner_PrintAll(void)
{
  HashTable_Log(COMPONENT_STATE, ht_nfs4_owner);
}                               /* nfs4_owner_PrintAll */
Ejemplo n.º 2
0
main(int argc, char *argv[])
{
  char localmachine[256];

  cache_inode_client_t client;
  LRU_parameter_t lru_param;
  LRU_status_t lru_status;
  cache_inode_fsal_data_t fsdata;

  fsal_status_t status;
  fsal_parameter_t init_param;
  fsal_name_t name;
  fsal_path_t path;
  fsal_attrib_mask_t mask;
  fsal_path_t pathroot;
  fsal_attrib_list_t attribs;
  fsal_handle_t root_handle;

  cache_inode_endofdir_t eod_met;
  cache_inode_dir_entry_t dirent_array[100];
  cache_inode_dir_entry_t dirent_array_loop[5];
  unsigned int nbfound;

  unsigned int begin_cookie = 0;
  hash_buffer_t key, value;

  uid_t uid;
  fsal_cred_t cred;

  cache_inode_status_t cache_status;
  cache_inode_parameter_t cache_param;
  cache_inode_client_parameter_t cache_client_param;

  hash_table_t *ht = NULL;
  fsal_attrib_list_t attrlookup;
  cache_entry_t *cache_entry_root = NULL;
  cache_entry_t *cache_entry_lookup = NULL;
  cache_entry_t *cache_entry_lookup2 = NULL;
  cache_entry_t *cache_entry_lookup3 = NULL;
  cache_entry_t *cache_entry_lookup4 = NULL;
  cache_entry_t *cache_entry_dircont = NULL;

  cache_inode_gc_policy_t gcpol;

  char *configfile = argv[1];
  int i = 0;
  int rc = 0;

  /* Init the Buddy System allocation */
  if((rc = BuddyInit(NULL)) != BUDDY_SUCCESS)
    {
      LogTest("Error initializing memory allocator");
      exit(1);
    }


  /* init debug */
  SetDefaultLogging("TEST");
  SetNamePgm("test_cache_inode");
  SetNameFunction("main");
  InitLogging();

#if defined( _USE_GHOSTFS )
  if(argc != 2)
    {
      LogTest("Please set the configuration file as parameter");
      exit(1);
    }
#endif

  /* Obtention du nom de la machine */
  if(gethostname(localmachine, sizeof(localmachine)) != 0)
    {
      LogError(COMPONENT_STDOUT,ERR_SYS, ERR_GETHOSTNAME, errno);
      exit(1);
    }
  else
    SetNameHost(localmachine);

  AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL);
  AddFamilyError(ERR_CACHE_INODE, "FSAL related Errors", tab_errstatus_cache_inode);

  /* creating log */
  LogTest( "Starting the test");
  LogTest( "-----------------");

#if defined( _USE_GHOSTFS )
  if(FSAL_IS_ERROR(status = FSAL_str2path(configfile,
                                          strlen(configfile) + 1,
                                          &(init_param.fs_specific_info.
                                            definition_file))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }
#elif defined( _USE_HPSS )

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, Flags);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugValue);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TransferType);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, NumRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, BusyRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, TotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, GKTotalDelay);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, LimitedRetries);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, MaxConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ReuseDataConnections);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, UsePortRange);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RetryStageInp);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DMAPWriteUpdates);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, ServerName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DescName);

  init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.PrincipalName,
          HPSS_SSM, HPSS_MAX_PRINCIPAL_NAME);

  init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE;
  strncpy(init_param.fs_specific_info.hpss_config.KeytabPath,
          HPSS_KEYTAB, HPSS_MAX_PATH_NAME);

  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, DebugPath);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, HostName);
  FSAL_SET_INIT_DEFAULT(init_param.fs_specific_info, RegistrySiteName);

#endif

  /* 2-common info (default) */
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread);
  FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite);

  /* Init */
  if(FSAL_IS_ERROR(status = FSAL_Init(&init_param)))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }

  /* getting creds */
  uid = getuid();

  if(FSAL_IS_ERROR(status = FSAL_GetUserCred(uid, NULL, &cred)))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
    }

  /* Init of the cache inode module */
  cache_param.hparam.index_size = 31;
  cache_param.hparam.alphabet_length = 10;      /* Buffer seen as a decimal polynom */
  cache_param.hparam.nb_node_prealloc = 100;
  cache_param.hparam.hash_func_key = cache_inode_fsal_hash_func;
  cache_param.hparam.hash_func_rbt = cache_inode_fsal_rbt_func;
  cache_param.hparam.hash_func_both = NULL ; /* BUGAZOMEU */
  cache_param.hparam.compare_key = cache_inode_compare_key_fsal;
  cache_param.hparam.key_to_str = display_key;
  cache_param.hparam.val_to_str = display_value;

  if((ht = cache_inode_init(cache_param, &cache_status)) == NULL)
    {
      LogTest( "Error %d while init hash ", cache_status);
    }
  else
    LogTest( "Hash Table address = %p", ht);

  /* We need a cache_client to acces the cache */
  cache_client_param.attrmask =
      FSAL_ATTRS_MANDATORY | FSAL_ATTR_MTIME | FSAL_ATTR_CTIME | FSAL_ATTR_ATIME;
  cache_client_param.nb_prealloc_entry = 1000;
  cache_client_param.nb_pre_dir_data = 200;
  cache_client_param.nb_pre_parent = 1200;
  cache_client_param.nb_pre_state_v4 = 100;

  cache_client_param.lru_param.nb_entry_prealloc = 1000;
  cache_client_param.lru_param.entry_to_str = lru_entry_to_str;
  cache_client_param.lru_param.clean_entry = lru_clean_entry;

  cache_client_param.grace_period_attr   = 0;
  cache_client_param.grace_period_link   = 0;
  cache_client_param.grace_period_dirent = 0;
  cache_client_param.expire_type_attr    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_link    = CACHE_INODE_EXPIRE_NEVER;
  cache_client_param.expire_type_dirent  = CACHE_INODE_EXPIRE_NEVER;

  /* Init the cache_inode client */
  if(cache_inode_client_init(&client, cache_client_param, 0, NULL) != 0)
    exit(1);

  /* Init the gc */
  gcpol.file_expiration_delay = 3;
  gcpol.directory_expiration_delay = 4;
  gcpol.hwmark_nb_entries = 6;
  gcpol.lwmark_nb_entries = 3;
  gcpol.run_interval = 4;

  cache_inode_set_gc_policy(gcpol);

  /* Getting the root of the FS */
  if((FSAL_IS_ERROR(status = FSAL_str2path("/", 2, &pathroot))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((FSAL_IS_ERROR(status = FSAL_lookupPath(&pathroot, &cred, &root_handle, &attribs))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }
  fsdata.cookie = 0;
  fsdata.handle = root_handle;

  /* Cache the root of the FS */
  if((cache_entry_root =
      cache_inode_make_root(&fsdata, 1, ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't init fs's root");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* Lookup a second time (entry should now be cached) */
  if((cache_entry_lookup2 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup2 != cache_entry_lookup)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup3 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if((cache_entry_lookup4 = cache_inode_lookup(cache_entry_root,
                                               &name,
                                               &attrlookup,
                                               ht,
                                               &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  if(cache_entry_lookup3 != cache_entry_lookup4)
    {
      LogTest("Error: lookup results should be the same");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("SunOS_5", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  cache_inode_print_dir(cache_entry_root);

  /* Test readdir */
  if(cache_inode_readdir(cache_entry_root,
                         0,
                         100,
                         &nbfound,
                         &eod_met,
                         dirent_array,
                         ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_readdir failed");
      exit(1);
    }

  LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met);
  for(i = 0; i < nbfound; i++)
    LogTest( "dirent_array[%d] ==> %s | %p", i,
                 dirent_array[i].name.name, dirent_array[i].pentry);

  cache_inode_print_dir(cache_entry_root);

  /* looping on readir */
  LogTest( "Loop directory in several pass");

  eod_met = TO_BE_CONTINUED;
  begin_cookie = 0;

  do
    {

      if(cache_inode_readdir(cache_entry_root,
                             begin_cookie,
                             2,
                             &nbfound,
                             &eod_met,
                             dirent_array_loop,
                             ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
        {
          LogTest("Error: cache_inode_readdir failed: %d", cache_status);
          exit(1);
        }

      for(i = 0; i < nbfound; i++)
        LogTest( " ==> %s | %p", dirent_array_loop[i].name.name,
                     dirent_array_loop[i].pentry);

      begin_cookie += nbfound;

    }
  while(eod_met == TO_BE_CONTINUED);

  LogTest( "---------------------------------");

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("cea", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }

  /* A lookup in the root fsal */
  if((FSAL_IS_ERROR(status = FSAL_str2name("log", 10, &name))))
    {
      LogError(COMPONENT_STDOUT,ERR_FSAL, status.major, status.minor);
      exit(1);
    }

  if((cache_entry_lookup = cache_inode_lookup(cache_entry_root,
                                              &name,
                                              &attrlookup,
                                              ht, &client, &cred, &cache_status)) == NULL)
    {
      LogTest( "Error: can't lookup");
      exit(1);
    }
  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

#ifdef _ADDITIONAL_TEST
  /* Trying to lookup from a DIR_CONTINUE */
  fsdata.handle = cache_entry_root->object.dir_begin.handle;
  fsdata.cookie = 3 * CHILDREN_ARRAY_SIZE;

  LogTest("Input key: (Handle=%p, Cookie=%d)", fsdata.handle, fsdata.cookie);

  /* Turn the input to a hash key */
  if(cache_inode_fsaldata_2_key(&key, &fsdata, NULL))
    {
      LogTest( "Impossible to allocate a key to that value");
      exit(1);
    }

  if(HashTable_Get(ht, &key, &value) != HASHTABLE_SUCCESS)
    {
      LogTest( "Key could not be found");
      exit(1);
    }

  /* pentry for the dir cont */
  cache_entry_dircont = (cache_entry_t *) value.pdata;

  /* Test readdir */
  if(cache_inode_readdir(cache_entry_dircont,
                         fsdata.cookie,
                         100,
                         &nbfound,
                         &eod_met,
                         dirent_array,
                         ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_readdir failed");
      exit(1);
    }
#endif

  LogTest( "Readdir nbfound=%d, eod_met=%d", nbfound, eod_met);
  for(i = 0; i < nbfound; i++)
    LogTest( "dirent_array[%d] ==> %s | %p ", i,
                 dirent_array[i].name.name, dirent_array[i].pentry);

  /* Call the GC */
  LogTest( "Sleeping %d second before gc (for gc invalidation)",
               gcpol.file_expiration_delay + 2);
  sleep(gcpol.file_expiration_delay + 2);

  if(cache_inode_gc(ht, &client, &cache_status) != CACHE_INODE_SUCCESS)
    {
      LogTest( "Error: cache_inode_gc failed");
      exit(1);
    }
  LogTest( "GC performed successfully");

  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

  /* Another readdir, after gc is made */
  eod_met = TO_BE_CONTINUED;
  begin_cookie = 0;

  LogTest( "ANOTHER READDIR AFTER GC");

  do
    {

      if(cache_inode_readdir(cache_entry_root,
                             begin_cookie,
                             2,
                             &nbfound,
                             &eod_met,
                             dirent_array_loop,
                             ht, &client, &cred, &cache_status) != CACHE_INODE_SUCCESS)
        {
          LogTest("Error: cache_inode_readdir failed: %d", cache_status);
          exit(1);
        }

      for(i = 0; i < nbfound; i++)
        LogTest( " ==> %s | %p", dirent_array_loop[i].name.name,
                     dirent_array_loop[i].pentry);

      begin_cookie += nbfound;

    }
  while(eod_met == TO_BE_CONTINUED);

  LogTest( "---------------------------------");

  /* Print the Hash Table */
  HashTable_Log(COMPONENT_STDOUT, ht);

  LogTest( "---------------------------------");

  /* The end of all the tests */
  LogTest( "All tests exited successfully");

  exit(0);
}                               /* main */
Ejemplo n.º 3
0
void nsm_client_PrintAll(void)
{
  HashTable_Log(COMPONENT_STATE, ht_nsm_client);
}                               /* nsm_client_PrintAll */
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
  SetDefaultLogging("TEST");
  SetNamePgm("test_cmchash");

  hash_table_t *ht = NULL;
  hash_parameter_t hparam;
  hash_buffer_t buffval;
  hash_buffer_t buffkey;
  hash_buffer_t buffval2;
  hash_buffer_t buffkey2;
  hash_stat_t statistiques;
  int i;
  int val;
  int rc;
  int res;
  struct Temps debut, fin;
  char tmpstr[10];
  char tmpstr2[10];
  char tmpstr3[10];
  char strtab[MAXTEST][10];
  int critere_recherche = 0;
  int random_val = 0;

  hparam.index_size = PRIME;
  hparam.alphabet_length = 10;
  hparam.nb_node_prealloc = NB_PREALLOC;
  hparam.hash_func_key = simple_hash_func;
  hparam.hash_func_rbt = rbt_hash_func;
  hparam.compare_key = compare_string_buffer;
  hparam.key_to_str = display_buff;
  hparam.val_to_str = display_buff;

  BuddyInit(NULL);

  /* Init de la table */
  if((ht = HashTable_Init(hparam)) == NULL)
    {
      LogTest("Test FAILED: Bad init");
      exit(1);
    }

  MesureTemps(&debut, NULL);
  LogTest("Created the table");

  for(i = 0; i < MAXTEST; i++)
    {
      sprintf(strtab[i], "%d", i);

      buffkey.len = strlen(strtab[i]);
      buffkey.pdata = strtab[i];

      buffval.len = strlen(strtab[i]);
      buffval.pdata = strtab[i];

      rc = HashTable_Set(ht, &buffkey, &buffval);
      LogFullDebug(COMPONENT_HASHTABLE,"Added %s , %d , return = %d", strtab[i], i, rc);
    }

  MesureTemps(&fin, &debut);
  LogTest("Time to insert %d entries: %s", MAXTEST,
         ConvertiTempsChaine(fin, NULL));

  LogFullDebug(COMPONENT_HASHTABLE, "-----------------------------------------");
  HashTable_Log(COMPONENT_HASHTABLE,ht);

  LogTest("=========================================");

  /* Premier test simple: verif de la coherence des valeurs lues */
  critere_recherche = CRITERE;

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  MesureTemps(&debut, NULL);
  rc = HashTable_Get(ht, &buffkey, &buffval);
  MesureTemps(&fin, &debut);

  LogTest("Recovery of %d th key ->%d", critere_recherche, rc);

  LogTest("Time to recover = %s", ConvertiTempsChaine(fin, NULL));

  if(rc != HASHTABLE_SUCCESS)
    {
      LogTest("Test FAILED: The key is not found");
      exit(1);
    }

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  MesureTemps(&debut, NULL);
  rc = HashTable_Get(ht, &buffkey, &buffval);
  MesureTemps(&fin, &debut);

  LogTest("Recovery of %d th key (test 2) -> %s", critere_recherche, rc);

  LogTest("Time to recover = %s", ConvertiTempsChaine(fin, NULL));

  if(rc != HASHTABLE_SUCCESS)
    {
      LogTest("Test FAILED: The key is not found (test 2)");
      exit(1);
    }

  LogTest("----> retrieved value = len %d ; val = %s", buffval.len, buffval.pdata);
  val = atoi(buffval.pdata);

  if(val != critere_recherche)
    {
      LogTest("Test FAILED: the reading is incorrect");
      exit(1);
    }

  LogTest("Now, I try to retrieve %d entries (taken at random, almost)",
         MAXGET);
  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXGET; i++)
    {
      random_val = random() % MAXTEST;
      sprintf(tmpstr, "%d", random_val);
      buffkey2.len = strlen(tmpstr);
      buffkey2.pdata = tmpstr;

      rc = HashTable_Get(ht, &buffkey2, &buffval2);
      LogFullDebug(COMPONENT_HASHTABLE,"\tPlaying key = %s  --> %s", buffkey2.pdata, buffval2.pdata);
      if(rc != HASHTABLE_SUCCESS)
        {
          LogTest("Error reading %d = %d", i, rc);
          LogTest("Test FAILED: the reading is incorrect");
          exit(1);
        }
    }
  MesureTemps(&fin, &debut);
  LogTest("Time to read %d elements = %s", MAXGET,
         ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  rc = HashTable_Del(ht, &buffkey, NULL, NULL);
  LogTest("Deleting the key %d --> %d", critere_recherche, rc);

  if(rc != HASHTABLE_SUCCESS)
    {
      LogTest("Test FAILED: delete incorrect");
      exit(1);
    }

  LogTest("=========================================");

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  rc = HashTable_Del(ht, &buffkey, NULL, NULL);
  LogTest("Deleting the key %d (2nd try) --> %d", critere_recherche, rc);

  if(rc != HASHTABLE_ERROR_NO_SUCH_KEY)
    {
      printf("Test FAILED: delete incorrect");
      exit(1);
    }

  LogTest("=========================================");

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  rc = HashTable_Get(ht, &buffkey, &buffval);
  LogTest
      ("Recovery of the %d key (erased) (must return HASH_ERROR_NO_SUCH_KEY) = %d --> %d",
       critere_recherche, HASHTABLE_ERROR_NO_SUCH_KEY, rc);

  if(rc != HASHTABLE_ERROR_NO_SUCH_KEY)
    {
      LogTest("Test FAILED: the reading is incorrect");
      exit(1);
    }
  LogTest("-----------------------------------------");

  LogTest
      ("Destruction of %d items, taken at random (well if you want ... I use srandom)",
       MAXDESTROY);
  srandom(getpid());
  random_val = random() % MAXTEST;

  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXDESTROY; i++)
    {
      /* 
      it used to be that the random values were chosen with
      repeated calls to random(), but if the same key comes up twice,
      that causes a fail.  This way we start with a random value and
      just linearly delete from it
      */

      random_val = (random_val + 1) % MAXTEST;
      sprintf(tmpstr, "%d", random_val);
      LogTest("\t Delete %d", random_val);
      buffkey.len = strlen(tmpstr);
      buffkey.pdata = tmpstr;

      rc = HashTable_Del(ht, &buffkey, NULL, NULL);
      

      if(rc != HASHTABLE_SUCCESS)
        {
          LogTest("Error on delete %d = %d", i, rc);
          LogTest("Test FAILED: delete incorrect");
          exit(1);
        }
    }
  MesureTemps(&fin, &debut);
  LogTest("Time to delete %d elements = %s", MAXDESTROY,
         ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");

  LogTest("Now, I try to retrieve %d entries (if necessary destroyed)",
         MAXGET);
  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXGET; i++)
    {
      random_val = random() % MAXTEST;
      sprintf(tmpstr, "%d", random_val);
      buffkey.len = strlen(tmpstr);
      buffkey.pdata = tmpstr;

      rc = HashTable_Get(ht, &buffkey, &buffval);
    }
  MesureTemps(&fin, &debut);
  LogTest("Tie to read %d elements = %s", MAXGET,
         ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");
  LogTest("Writing a duplicate key ");
  sprintf(tmpstr, "%d", CRITERE_2);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;
  rc = HashTable_Test_And_Set(ht, &buffkey, &buffval, HASHTABLE_SET_HOW_SET_NO_OVERWRITE);
  LogTest("The value should be HASHTABLE_ERROR_KEY_ALREADY_EXISTS  = %d --> %d",
         HASHTABLE_ERROR_KEY_ALREADY_EXISTS, rc);
  if(rc != HASHTABLE_ERROR_KEY_ALREADY_EXISTS)
    {
      LogTest("Test FAILED: duplicate key");
      exit(1);
    }
  LogTest("-----------------------------------------");

  HashTable_Log(COMPONENT_HASHTABLE,ht);
  LogFullDebug(COMPONENT_HASHTABLE,"-----------------------------------------");

  LogTest("Displaying table statistics ");
  HashTable_GetStats(ht, &statistiques);
  LogTest(" Number of entries = %d", statistiques.dynamic.nb_entries);

  LogTest("   Successful operations  : Set = %d,  Get = %d,  Del = %d,  Test = %d",
         statistiques.dynamic.ok.nb_set, statistiques.dynamic.ok.nb_get,
         statistiques.dynamic.ok.nb_del, statistiques.dynamic.ok.nb_test);

  LogTest("   Failed operations : Set = %d,  Get = %d,  Del = %d,  Test = %d",
         statistiques.dynamic.err.nb_set, statistiques.dynamic.err.nb_get,
         statistiques.dynamic.err.nb_del, statistiques.dynamic.err.nb_test);

  LogTest("   Operations 'NotFound': Set = %d,  Get = %d,  Del = %d,  Test = %d",
         statistiques.dynamic.notfound.nb_set, statistiques.dynamic.notfound.nb_get,
         statistiques.dynamic.notfound.nb_del, statistiques.dynamic.notfound.nb_test);

  LogTest
      ("  Calculated statistics: min_rbt_node = %d,  max_rbt_node = %d,  average_rbt_node = %d",
       statistiques.computed.min_rbt_num_node, statistiques.computed.max_rbt_num_node,
       statistiques.computed.average_rbt_num_node);

  /* Test sur la pertinence des valeurs de statistiques */
  if(statistiques.dynamic.ok.nb_set != MAXTEST)
    {
      LogTest("Test FAILED: Incorrect statistics: ok.nb_set ");
      exit(1);
    }

  if(statistiques.dynamic.ok.nb_get + statistiques.dynamic.notfound.nb_get !=
     2 * MAXGET + 3)
    {
      LogTest("Test FAILED: Incorrect statistics: *.nb_get ");
      exit(1);
    }

  if(statistiques.dynamic.ok.nb_del != MAXDESTROY + 1
     || statistiques.dynamic.notfound.nb_del != 1)
    {
      LogTest("Test ECHOUE : statistiques incorrectes: *.nb_del ");
      exit(1);
    }

  if(statistiques.dynamic.err.nb_test != 1)
    {
      LogTest("Test ECHOUE : statistiques incorrectes: err.nb_test ");
      exit(1);
    }

  /* Tous les tests sont ok */
  BuddyDumpMem(stdout);

  LogTest("\n-----------------------------------------");
  LogTest("Test succeeded: all tests pass successfully");

  exit(0);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
  SetDefaultLogging("TEST");
  SetNamePgm("test_libcmc_bugdelete");
  LogTest("Initialized test program");
  
  hash_table_t *ht = NULL;
  hash_parameter_t hparam;
  hash_buffer_t buffval;
  hash_buffer_t buffkey;
  hash_buffer_t buffval2;
  hash_buffer_t buffkey2;
  hash_stat_t statistiques;
  int i;
  int rc;
  struct Temps debut, fin;
  char tmpstr[10];
  char strtab[MAXTEST][10];
  int critere_recherche = 0;
  int random_val = 0;

  hparam.index_size = PRIME;
  hparam.alphabet_length = 10;
  hparam.nb_node_prealloc = NB_PREALLOC;
  hparam.hash_func_key = simple_hash_func;
  hparam.hash_func_rbt = rbt_hash_func;
  hparam.hash_func_both = NULL ; /* BUGAZOMEU */
  hparam.compare_key = compare_string_buffer;
  hparam.key_to_str = display_buff;
  hparam.val_to_str = display_buff;

  BuddyInit(NULL);

  /* Init de la table */
  if((ht = HashTable_Init(hparam)) == NULL)
    {
      LogTest("Test FAILED: Bad init");
      exit(1);
    }

  MesureTemps(&debut, NULL);
  LogTest("Created hash table");

  for(i = 0; i < MAXTEST; i++)
    {
      sprintf(strtab[i], "%d", i);

      buffkey.len = strlen(strtab[i]);
      buffkey.pdata = strtab[i];

      buffval.len = strlen(strtab[i]);
      buffval.pdata = strtab[i];

      rc = HashTable_Set(ht, &buffkey, &buffval);
      LogFullDebug(COMPONENT_HASHTABLE,
                   "Added %s , %d , return code = %d", strtab[i], i, rc);
    }

  MesureTemps(&fin, &debut);
  LogTest("Time to insert %d entries: %s", MAXTEST,
         ConvertiTempsChaine(fin, NULL));

  LogFullDebug(COMPONENT_HASHTABLE,
               "-----------------------------------------");
  HashTable_Log(COMPONENT_HASHTABLE, ht);
  LogFullDebug(COMPONENT_HASHTABLE,
               "=========================================");

  /* Premier test simple: verif de la coherence des valeurs lues */
  critere_recherche = CRITERE;

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  MesureTemps(&debut, NULL);
  rc = HashTable_Get(ht, &buffkey, &buffval);
  MesureTemps(&fin, &debut);

  LogTest("Now, I try to retrieve %d entries (taken at random, almost)",
          MAXGET);

  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXGET; i++)
    {
      random_val = random() % MAXTEST;
      sprintf(tmpstr, "%d", random_val);
      buffkey2.len = strlen(tmpstr);
      buffkey2.pdata = tmpstr;

      rc = HashTable_Get(ht, &buffkey2, &buffval2);
      LogTest("\tPlaying key = %s  --> %s", buffkey2.pdata, buffval2.pdata);
      if(rc != HASHTABLE_SUCCESS)
        {
          LogTest("Error reading %d = %d", i, rc);
          LogTest("Test FAILED: the reading is incorrect");
          exit(1);
        }
    }
  MesureTemps(&fin, &debut);
  LogTest("Time to read elements %d = %s", MAXGET,
         ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  sprintf(tmpstr, "%d", critere_recherche);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;

  srandom(getpid());

  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXDESTROY; i++)
    {
      random_val = bugdelete_key_array[i];
      sprintf(tmpstr, "%d", random_val);

      buffkey.len = strlen(tmpstr);
      buffkey.pdata = tmpstr;
      LogFullDebug(COMPONENT_HASHTABLE, "\t Erase %u -> %lu | %lu",
                   random_val,
                   simple_hash_func(&hparam, &buffkey),
                   rbt_hash_func(&hparam, &buffkey));

      rc = HashTable_Del(ht, &buffkey, NULL, NULL);
      if(rc != HASHTABLE_SUCCESS)
        {
          LogTest("Erreur lors de la destruction de %d = %d", random_val, rc);
          LogTest("Test FAILED: delete incorrect");
          exit(1);
        }
    }
  MesureTemps(&fin, &debut);
  LogTest("Time to delete %d elements = %s", MAXDESTROY,
          ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");

  LogTest("Now, I try to retrieve %d entries (possibly destroyed)",
          MAXGET);

  MesureTemps(&debut, NULL);
  for(i = 0; i < MAXGET; i++)
    {
      random_val = random() % MAXTEST;
      sprintf(tmpstr, "%d", random_val);
      buffkey.len = strlen(tmpstr);
      buffkey.pdata = tmpstr;

      rc = HashTable_Get(ht, &buffkey, &buffval);
    }
  MesureTemps(&fin, &debut);
  LogTest("Time to read %d elements = %s", MAXGET,
          ConvertiTempsChaine(fin, NULL));

  LogTest("-----------------------------------------");
  LogTest("Writing a duplicated key");
  sprintf(tmpstr, "%d", CRITERE_2);
  buffkey.len = strlen(tmpstr);
  buffkey.pdata = tmpstr;
  rc = HashTable_Test_And_Set(ht, &buffkey, &buffval, HASHTABLE_SET_HOW_SET_NO_OVERWRITE);
  LogTest("The value must be HASHTABLE_ERROR_KEY_ALREADY_EXISTS  = %d --> %d",
         HASHTABLE_ERROR_KEY_ALREADY_EXISTS, rc);
  if(rc != HASHTABLE_ERROR_KEY_ALREADY_EXISTS)
    {
      LogTest("Test ECHOUE : Clef redondante");
      exit(1);
    }
  LogTest("-----------------------------------------");

  HashTable_Log(COMPONENT_HASHTABLE,ht);
  LogFullDebug(COMPONENT_HASHTABLE,"-----------------------------------------");

  LogTest("Displaying table statistics");
  HashTable_GetStats(ht, &statistiques);
  LogTest(" Number of Entrees = %d", statistiques.dynamic.nb_entries);

  LogTest(" Successful operations : Set = %d,  Get = %d,  Del = %d,  Test = %d",
          statistiques.dynamic.ok.nb_set, statistiques.dynamic.ok.nb_get,
          statistiques.dynamic.ok.nb_del, statistiques.dynamic.ok.nb_test);

  LogTest("   Failed operations : Set = %d,  Get = %d,  Del = %d,  Test = %d",
          statistiques.dynamic.err.nb_set, statistiques.dynamic.err.nb_get,
          statistiques.dynamic.err.nb_del, statistiques.dynamic.err.nb_test);

  LogTest("   Operations 'NotFound': Set = %d,  Get = %d,  Del = %d,  Test = %d",
          statistiques.dynamic.notfound.nb_set, statistiques.dynamic.notfound.nb_get,
          statistiques.dynamic.notfound.nb_del, statistiques.dynamic.notfound.nb_test);

  LogTest("  Statistics computed: min_rbt_node = %d,  max_rbt_node = %d,  average_rbt_node = %d",
          statistiques.computed.min_rbt_num_node, statistiques.computed.max_rbt_num_node,
          statistiques.computed.average_rbt_num_node);

  /* Test sur la pertinence des valeurs de statistiques */
  if(statistiques.dynamic.ok.nb_set != MAXTEST)
    {
      LogTest("Test FAILED: Incorrect statistics: ok.nb_set ");
      exit(1);
    }

  if(statistiques.dynamic.ok.nb_get + statistiques.dynamic.notfound.nb_get !=
     2 * MAXGET + 1)
    {
      LogTest("Test FAILED: Incorrect statistics: *.nb_get.  Expected %d, got %d",
              2 * MAXGET + 1,
              statistiques.dynamic.ok.nb_get + statistiques.dynamic.notfound.nb_get);
      exit(1);
    }

  if(statistiques.dynamic.ok.nb_del != MAXDESTROY)
    {
      LogTest("Test FAILED: Incorrect statistics: *.nb_del. Expected %d, got %d",
              MAXDESTROY, statistiques.dynamic.ok.nb_del);
      exit(1);
    }

  if(statistiques.dynamic.notfound.nb_del != 0)
    {
      LogTest("Test FAILED: Incorrect statistics: *.nb_del. Expected %d, got %d",
              0, statistiques.dynamic.notfound.nb_del);
      exit(1);
    }



  if(statistiques.dynamic.err.nb_test != 1)
    {
      LogTest("Test FAILED: Incorrect statistics: err.nb_test ");
      exit(1);
    }

  /* Tous les tests sont ok */
  BuddyDumpMem(stdout);

  LogTest("\n-----------------------------------------");
  LogTest("Test succeeded: all tests pass successfully");

  exit(0);
}
Ejemplo n.º 6
0
int nfs_ip_name_populate(char *path)
{
  config_file_t config_file;
  config_item_t block;
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  char label[MAXNAMLEN];
  sockaddr_t ipaddr;
  nfs_ip_name_t *nfs_ip_name;
  sockaddr_t *pipaddr;
  hash_buffer_t buffkey;
  hash_buffer_t buffdata;

  config_file = config_ParseFile(path);

  if(!config_file)
    {
      LogCrit(COMPONENT_CONFIG, "Can't open file %s", path);

      return IP_NAME_NOT_FOUND;
    }

  /* Get the config BLOCK */
  if((block = config_FindItemByName(config_file, CONF_LABEL_IP_NAME_HOSTS)) == NULL)
    {
      LogCrit(COMPONENT_CONFIG,
              "Can't get label %s in file %s",
              CONF_LABEL_IP_NAME_HOSTS, path);
      return IP_NAME_NOT_FOUND;
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      /* Expected to be a block */
      return IP_NAME_NOT_FOUND;
    }

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          LogCrit(COMPONENT_CONFIG,
                  "Error reading key[%d] from section \"%s\" of configuration file.",
                  var_index, label);
          return IP_NAME_NOT_FOUND;
        }

      err = ipstring_to_sockaddr(key_value, &ipaddr);
      if(err != 0)
        {
          LogCrit(COMPONENT_CONFIG,
                  "Error converting %s to an ipaddress %s",
                  key_value, gai_strerror(err));
          return IP_NAME_NOT_FOUND;
        }

      /* Entry to be cached */
      nfs_ip_name = gsh_malloc(sizeof(nfs_ip_name_t));
      if(nfs_ip_name == NULL)
        return IP_NAME_INSERT_MALLOC_ERROR;

      pipaddr = gsh_malloc(sizeof(sockaddr_t));
      if(pipaddr == NULL)
        {
          gsh_free(nfs_ip_name);
          return IP_NAME_INSERT_MALLOC_ERROR;
        }

      strncpy(nfs_ip_name->hostname, key_name, MAXHOSTNAMELEN);
      nfs_ip_name->timestamp = time(NULL);
      memcpy(pipaddr, &ipaddr, sizeof(sockaddr_t));

      buffdata.pdata = (caddr_t) nfs_ip_name;
      buffdata.len = sizeof(nfs_ip_name_t);

      buffkey.pdata = (caddr_t) pipaddr;
      buffkey.len = sizeof(sockaddr_t);

      if(HashTable_Set(ht_ip_name, &buffkey, &buffdata) != HASHTABLE_SUCCESS)
        {
          gsh_free(nfs_ip_name);
          gsh_free(pipaddr);
          return IP_NAME_INSERT_MALLOC_ERROR;
        }
    }

  if(isFullDebug(COMPONENT_CONFIG))
    HashTable_Log(COMPONENT_CONFIG, ht_ip_name);

  return IP_NAME_SUCCESS;
}                               /* nfs_ip_name_populate */
Ejemplo n.º 7
0
void nfs41_Session_PrintAll(void)
{
  HashTable_Log(COMPONENT_SESSIONS, ht_session_id);
}                               /* nfs41_Session_PrintAll */