2 //=============================================================================
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"
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
30 bind (ACE_Naming_Context
*ns_context
, int result
)
32 //FUZZ: enable check_for_lack_ACE_OS
35 for (int i
= 1; i
<= ACE_NS_MAX_ENTRIES
; i
++)
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"));
54 rebind (ACE_Naming_Context
*ns_context
, int result
)
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!"));
71 unbind (ACE_Naming_Context
*ns_context
, int result
)
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!"));
85 find (ACE_Naming_Context
*ns_context
, int sign
, int result
)
87 char temp_val
[BUFSIZ
];
88 char temp_type
[BUFSIZ
];
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
;
101 ACE_OS::sprintf (temp_val
, "%s%d", "value", i
);
102 ACE_OS::sprintf (temp_type
, "%s%d", "type", i
);
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
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
);
127 ACE_ASSERT (ACE_OS::strcmp (type_out
, temp_type
) == 0);
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
);
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"));
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);
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);