Exemplo n.º 1
0
int
main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Naming_Test"));
  ACE_TCHAR temp_file [BUFSIZ];
  ACE_Naming_Context *ns_context;
  ACE_NEW_RETURN (ns_context, ACE_Naming_Context, -1);

  ACE_Name_Options *name_options = ns_context->name_options ();

  name_options->parse_args (argc, argv);

  int unicode = 0;
#if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR))
  unicode = 1;
#endif /* ACE_WIN32 && ACE_USES_WCHAR */
  if (unicode && name_options->use_registry () == 1)
    {
      name_options->namespace_dir (ACE_TEXT ("Software\\ACE\\Name Service"));
      name_options->database (ACE_TEXT ("Version 1"));
    }
  else
    {
      ACE_OS::strcpy (temp_file, ACE::basename (name_options->process_name (),
						ACE_DIRECTORY_SEPARATOR_CHAR));
      ACE_OS_String::strcat (temp_file, ACE_TEXT ("XXXXXX"));

      // Set the database name using mktemp to generate a unique file name
      name_options->database (ACE_OS::mktemp (temp_file));
    }

  ACE_ASSERT (ns_context->open (ACE_Naming_Context::PROC_LOCAL, 1) != -1);

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("time to test %d iterations using %s\n"),
	      ACE_NS_MAX_ENTRIES, name_options->use_registry () ?
              ACE_TEXT ("Registry") : ACE_TEXT ("ACE")));

  ACE_Profile_Timer timer;

  timer.start ();
  // Add some bindings to the database
  test_bind (*ns_context);
  print_time (timer, "Binds");

  timer.start ();
  // Should find the entries
  test_find (*ns_context, 1, 0);
  print_time (timer, "Successful Finds");

  timer.start ();
  // Rebind with negative values
  test_rebind (*ns_context);
  print_time (timer, "Rebinds");

  timer.start ();
  // Should find the entries
  test_find (*ns_context,  -1, 0);
  print_time (timer, "Successful Finds");

  timer.start ();
  // Should not find the entries
  test_find_failure (*ns_context);
  print_time (timer, "UnSuccessful Finds");

  timer.start ();
  // Remove all bindings from database
  test_unbind (*ns_context);
  print_time (timer, "Unbinds");

  ACE_OS::sprintf (temp_file, ACE_TEXT ("%s%s%s"),
		   name_options->namespace_dir (),
		   ACE_DIRECTORY_SEPARATOR_STR,
		   name_options->database ());

  delete ns_context;

  // Remove any existing files.  No need to check return value here
  // since we don't care if the file doesn't exist.
  ACE_OS::unlink (temp_file);

  ACE_END_TEST;
  return 0;
}
Exemplo n.º 2
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Naming_Test"));
  ACE_TCHAR temp_file [BUFSIZ];
  ACE_Naming_Context *ns_context = 0;
  ACE_NEW_RETURN (ns_context, ACE_Naming_Context, -1);

  ACE_Name_Options *name_options = ns_context->name_options ();

  name_options->parse_args (argc, argv);
  /*
  ** NOTE! This is an experimental value and is not magic in any way. It
  ** works for me, on one system. It's needed because in the particular
  ** case here where the underlying mmap will allocate a small area and
  ** then try to grow it, it always moves it to a new location, which
  ** totally screws things up. I once tried forcing the realloc to do
  ** MAP_FIXED but that's not a good solution since it may overwrite other
  ** mapped areas of memory, like the heap, or the C library, and get very
  ** unexpected results.    (Steve Huston, 24-August-2007)
  */
# if defined (linux) && defined (__x86_64__)
  name_options->base_address ((char*)0x3c00000000);
#endif
  bool unicode = false;
#if (defined (ACE_WIN32) && defined (ACE_USES_WCHAR))
  unicode = true;
#endif /* ACE_WIN32 && ACE_USES_WCHAR */
  if (unicode && name_options->use_registry () == 1)
    {
      name_options->namespace_dir (ACE_TEXT ("Software\\ACE\\Name Service"));
      name_options->database (ACE_TEXT ("Version 1"));
    }
  else
    {
      const ACE_TCHAR* pname = ACE::basename (name_options->process_name (),
                                              ACE_DIRECTORY_SEPARATOR_CHAR);
      // Allow the user to determine where the context file will be
      // located just in case the current directory is not suitable for
      // locking.  We don't just set namespace_dir () on name_options
      // because that is not sufficient to work around locking problems
      // for Tru64 when the current directory is NFS mounted from a
      // system that does not properly support locking.
      ACE_TCHAR temp_dir [MAXPATHLEN];
      if (ACE::get_temp_dir (temp_dir, MAXPATHLEN - 15) == -1)
        // -15 for ace-file-XXXXXX
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("Temporary path too long, ")
                             ACE_TEXT ("defaulting to current directory\n")),
                             -1);
        }
      else
        {
          ACE_OS::chdir (temp_dir);
        }
      ACE_OS::strcpy (temp_file, pname);
      ACE_OS::strcat (temp_file, ACE_TEXT ("XXXXXX"));

      // Set the database name using mktemp to generate a unique file name
      name_options->database (ACE_OS::mktemp (temp_file));
    }

  if (ns_context->open (ACE_Naming_Context::PROC_LOCAL, 1) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("ns_context->open (PROC_LOCAL) %p\n"),
                         ACE_TEXT ("failed")),
                        -1);
    }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("time to test %d iterations using %s\n"),
              ACE_NS_MAX_ENTRIES, name_options->use_registry () ?
              ACE_TEXT ("Registry") : ACE_TEXT ("ACE")));

  ACE_Profile_Timer timer;

  timer.start ();
  // Add some bindings to the database
  test_bind (*ns_context);
  print_time (timer, "Binds");

  timer.start ();
  // Should find the entries
  test_find (*ns_context, 1, 0);
  print_time (timer, "Successful Finds");

  timer.start ();
  // Rebind with negative values
  test_rebind (*ns_context);
  print_time (timer, "Rebinds");

  timer.start ();
  // Should find the entries
  test_find (*ns_context,  -1, 0);
  print_time (timer, "Successful Finds");

  timer.start ();
  // Should not find the entries
  test_find_failure (*ns_context);
  print_time (timer, "UnSuccessful Finds");

  timer.start ();
  // Remove all bindings from database
  test_unbind (*ns_context);
  print_time (timer, "Unbinds");

  ACE_OS::sprintf (temp_file, ACE_TEXT ("%s%s%s"),
                   name_options->namespace_dir (),
                   ACE_DIRECTORY_SEPARATOR_STR,
                   name_options->database ());

  delete ns_context;

  // Remove any existing files.  No need to check return value here
  // since we don't care if the file doesn't exist.
  ACE_OS::unlink (temp_file);

  ACE_END_TEST;
  return 0;
}