Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / performance-tests / Misc / test_naming.cpp
blob50fa083bd15a793ff493224be18eb3a827f1acbf
2 //=============================================================================
3 /**
4 * @file test_naming.cpp
6 * This is an example to do performance testing of the Naming Service
7 * using both the normal Memory Pool as well as the light Memory Pool.
9 * @author Prashant Jain
11 //=============================================================================
14 #include "ace/OS_main.h"
15 #include "ace/ACE.h"
16 #include "ace/SString.h"
17 #include "ace/Naming_Context.h"
18 #include "ace/Profile_Timer.h"
19 #include "ace/Log_Msg.h"
20 #include "ace/OS_NS_stdio.h"
22 #define ACE_NS_MAX_ENTRIES 4000
24 static char name[BUFSIZ];
25 static char value[BUFSIZ];
26 static char type[BUFSIZ];
28 //FUZZ: disable check_for_lack_ACE_OS
29 void
30 bind (ACE_Naming_Context *ns_context, int result)
32 //FUZZ: enable check_for_lack_ACE_OS
34 // do the binds
35 for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
37 if (i % 50 == 0)
38 ACE_DEBUG ((LM_DEBUG, "."));
39 ACE_OS::sprintf (name, "%s%d", "name", i);
40 ACE_NS_WString w_name (name);
42 ACE_OS::sprintf (value, "%s%d", "value", i);
43 ACE_NS_WString w_value (value);
45 ACE_OS::sprintf (type, "%s%d", "type", i);
46 if (ns_context->bind (w_name, w_value, type) != result) {
47 ACE_ERROR ((LM_ERROR, "bind failed!"));
50 ACE_DEBUG ((LM_DEBUG, "\n"));
53 void
54 rebind (ACE_Naming_Context *ns_context, int result)
56 // do the rebinds
57 for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
59 ACE_OS::sprintf (name, "%s%d", "name", i);
60 ACE_NS_WString w_name (name);
61 ACE_OS::sprintf (value, "%s%d", "value", -i);
62 ACE_NS_WString w_value (value);
63 ACE_OS::sprintf (type, "%s%d", "type", -i);
64 if (ns_context->rebind (w_name, w_value, type) != result) {
65 ACE_ERROR ((LM_ERROR, "rebind failed!"));
70 void
71 unbind (ACE_Naming_Context *ns_context, int result)
73 // do the unbinds
74 for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
76 ACE_OS::sprintf (name, "%s%d", "name", i);
77 ACE_NS_WString w_name (name);
78 if (ns_context->unbind (w_name) != result) {
79 ACE_ERROR ((LM_ERROR, "unbind failed!"));
84 void
85 find (ACE_Naming_Context *ns_context, int sign, int result)
87 char temp_val[BUFSIZ];
88 char temp_type[BUFSIZ];
90 // do the finds
91 for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
93 ACE_OS::sprintf (name, "%s%d", "name", i);
94 ACE_NS_WString w_name (name);
96 ACE_NS_WString w_value;
97 char *type_out;
99 if (sign == 1)
101 ACE_OS::sprintf (temp_val, "%s%d", "value", i);
102 ACE_OS::sprintf (temp_type, "%s%d", "type", i);
104 else
106 ACE_OS::sprintf (temp_val, "%s%d", "value", -i);
107 ACE_OS::sprintf (temp_type, "%s%d", "type", -i);
110 ACE_NS_WString val (temp_val);
112 int resolve_result = ns_context->resolve (w_name, w_value, type_out);
113 if (resolve_result != result) {
114 ACE_ERROR ((LM_ERROR, "resolved failed!"));
116 ACE_ASSERT (resolve_result == result);
117 ACE_UNUSED_ARG (resolve_result); // To avoid compile warning
118 // with ACE_NDEBUG.
120 if (w_value.char_rep ())
122 ACE_DEBUG ((LM_DEBUG, "Name: %s\tValue: %s\tType: %s\n",
123 name, w_value.char_rep (), type_out));
124 ACE_ASSERT (w_value == val);
125 if (type_out)
127 ACE_ASSERT (ACE_OS::strcmp (type_out, temp_type) == 0);
128 delete[] type_out;
134 void do_testing (int argc, ACE_TCHAR *argv[], int light)
136 ACE_Profile_Timer timer;
138 ACE_Naming_Context ns_context;
139 ACE_Name_Options *name_options = ns_context.name_options ();
140 name_options->parse_args (argc, argv);
142 if (light == 0) // Use SYNC
144 name_options->database (ACE::basename (name_options->process_name (),
145 ACE_DIRECTORY_SEPARATOR_CHAR));
146 ns_context.open (ACE_Naming_Context::PROC_LOCAL);
148 else // Use NO-SYNC
150 const ACE_TCHAR *p = ACE::basename (name_options->process_name (),
151 ACE_DIRECTORY_SEPARATOR_CHAR);
152 ACE_TCHAR s[5 /* strlen ("light") */ + MAXNAMELEN + 1];
153 ACE_OS::sprintf (s, ACE_TEXT("light%s"), p);
154 name_options->database (s);
155 ns_context.open (ACE_Naming_Context::PROC_LOCAL, 1);
158 // Add bindings to the database
159 ACE_DEBUG ((LM_DEBUG, "Binding\n"));
161 timer.start ();
163 //FUZZ: disable check_for_lack_ACE_OS
164 bind (&ns_context, 0);
165 //FUZZ: enable check_for_lack_ACE_OS
167 ACE_DEBUG ((LM_DEBUG, "Unbinding\n"));
168 unbind (&ns_context, 0);
169 timer.stop ();
171 ACE_Profile_Timer::ACE_Elapsed_Time et;
173 timer.elapsed_time (et);
174 ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
175 et.real_time, et.user_time, et.system_time));
180 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
182 // Do testing with SYNC on
183 ACE_DEBUG ((LM_DEBUG, "SYNC is ON\n"));
184 do_testing (argc, argv, 0);
186 // Do testing with SYNC off
187 ACE_DEBUG ((LM_DEBUG, "SYNC is OFF\n"));
188 do_testing (argc, argv, 1);
189 return 0;