Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Map_Manager_Test.cpp
blobd55135235f70909254829d680610658a096ef292
2 //=============================================================================
3 /**
4 * @file Map_Manager_Test.cpp
6 * This is a simple test of the <ACE_Map_Manager> and
7 * <ACE_Hash_Map_Manager> that illustrates how to use the forward
8 * and reverse iterators.
10 * @author Irfan Pyarali <irfan@cs.wustl.edu>
11 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
12 * @author and Kirthika Parameswaran <kirthika@cs.wustl.edu>
14 //=============================================================================
17 #include "test_config.h"
18 #include "ace/Map_Manager.h"
19 #include "ace/Hash_Map_Manager.h"
20 #include "ace/Active_Map_Manager.h"
21 #include "ace/Profile_Timer.h"
22 #include "ace/Hash_Cache_Map_Manager_T.h"
23 #include "ace/Caching_Strategies_T.h"
25 using MUTEX = ACE_Null_Mutex;
26 using TYPE = ACE_UINT32;
27 using ACTIVE_KEY = ACE_Active_Map_Manager_Key;
28 using HASH_KEY = ACE_Hash<TYPE>;
29 using COMPARE_KEYS = ACE_Equal_To<TYPE>;
31 using MAP_MANAGER = ACE_Map_Manager<TYPE, TYPE, MUTEX>;
32 using ITERATOR = ACE_Map_Iterator<TYPE, TYPE, MUTEX>;
33 using REVERSE_ITERATOR = ACE_Map_Reverse_Iterator<TYPE, TYPE, MUTEX>;
34 using MAP_ENTRY = ACE_Map_Entry<TYPE, TYPE>;
35 using HASH_MAP_MANAGER = ACE_Hash_Map_Manager_Ex<TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX>;
36 using HASH_ITERATOR = ACE_Hash_Map_Iterator_Ex<TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX>;
37 using HASH_REVERSE_ITERATOR = ACE_Hash_Map_Reverse_Iterator_Ex<TYPE, TYPE, HASH_KEY, COMPARE_KEYS, MUTEX>;
38 using HASH_ENTRY = ACE_Hash_Map_Entry<TYPE, TYPE>;
39 using ACTIVE_MAP_MANAGER = ACE_Active_Map_Manager<TYPE>;
41 using CACHE_MAP_IMPL = ACE_Hash_Map_Manager_Ex<TYPE, std::pair<TYPE, int>, HASH_KEY, COMPARE_KEYS, MUTEX>;
42 using CACHE_ITER_IMPL = ACE_Hash_Map_Iterator_Ex<TYPE, std::pair<TYPE, int>, HASH_KEY, COMPARE_KEYS, MUTEX>;
43 using CACHE_REV_ITER_IMPL = ACE_Hash_Map_Reverse_Iterator_Ex<TYPE, std::pair<TYPE, int>, HASH_KEY, COMPARE_KEYS, MUTEX>;
44 using ATTR = int;
45 using NULL_CLEANUP = ANCLE<TYPE, TYPE, CACHE_MAP_IMPL>;
46 using NULL_UTILITY = ACE_Null_Caching_Utility<TYPE, TYPE, CACHE_MAP_IMPL, CACHE_ITER_IMPL, ATTR>;
47 using NULL_CACHING_STRATEGY = ANULL<ATTR, NULL_UTILITY>;
48 using CACHE_MAP_MANAGER = ACMM<TYPE, TYPE, CACHE_MAP_IMPL, CACHE_ITER_IMPL, CACHE_REV_ITER_IMPL, NULL_CACHING_STRATEGY, ATTR>;
49 using HASH_CACHE_MAP_MANAGER = ACE_Hash_Cache_Map_Manager<TYPE, TYPE, HASH_KEY, COMPARE_KEYS, NULL_CACHING_STRATEGY, ATTR>;
51 static int
52 test_cache_map_manager (size_t table_size,
53 size_t iterations,
54 int test_iterators)
56 NULL_CACHING_STRATEGY null_caching_strategy;
57 CACHE_MAP_MANAGER map (null_caching_strategy,
58 table_size);
59 TYPE i;
60 TYPE j = TYPE ();
61 ssize_t k;
63 for (i = 0; i < iterations; i++)
64 ACE_TEST_ASSERT (map.bind (i, i) != -1);
66 if (test_iterators)
69 i = 0;
71 CACHE_MAP_MANAGER::ITERATOR end = map.end ();
73 for (CACHE_MAP_MANAGER::ITERATOR iter = map.begin ();
74 iter != end;
75 ++iter)
77 ACE_DEBUG ((LM_DEBUG,
78 ACE_TEXT ("(%d|%d|%d)"),
80 (*iter).first (),
81 (*iter).second ()));
82 ++i;
85 ACE_DEBUG ((LM_DEBUG,
86 ACE_TEXT ("\n")));
87 ACE_TEST_ASSERT (i == iterations);
92 k = iterations - 1;
94 CACHE_MAP_MANAGER::REVERSE_ITERATOR rend = map.rend ();
96 for (CACHE_MAP_MANAGER::REVERSE_ITERATOR iter = map.rbegin ();
97 iter != rend;
98 ++iter)
100 ACE_DEBUG ((LM_DEBUG,
101 ACE_TEXT ("(%d|%d|%d)"),
103 (*iter).first (),
104 (*iter).second ()));
105 k--;
108 ACE_DEBUG ((LM_DEBUG,
109 ACE_TEXT ("\n")));
110 ACE_TEST_ASSERT (k == -1);
115 i = 0;
117 CACHE_MAP_MANAGER::iterator end = map.end ();
119 for (CACHE_MAP_MANAGER::iterator iter = map.begin ();
120 iter != end;
121 ++iter)
123 ACE_DEBUG ((LM_DEBUG,
124 ACE_TEXT ("(%d|%d|%d)"),
126 (*iter).first (),
127 (*iter).second ()));
128 ++i;
131 ACE_DEBUG ((LM_DEBUG,
132 ACE_TEXT ("\n")));
133 ACE_TEST_ASSERT (i == iterations);
138 k = iterations - 1;
140 CACHE_MAP_MANAGER::reverse_iterator rend = map.rend ();
142 for (CACHE_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
143 iter != rend;
144 ++iter)
146 ACE_DEBUG ((LM_DEBUG,
147 ACE_TEXT ("(%d|%d|%d)"),
149 (*iter).first (),
150 (*iter).second ()));
151 k--;
154 ACE_DEBUG ((LM_DEBUG,
155 ACE_TEXT ("\n")));
156 ACE_TEST_ASSERT (k == -1);
162 for (i = 0; i < iterations; ++i)
164 ACE_TEST_ASSERT (map.find (i, j) != -1);
165 ACE_TEST_ASSERT (i == j);
168 size_t remaining_entries = iterations;
169 for (i = 0; i < iterations; ++i)
171 ACE_TEST_ASSERT (map.unbind (i) != -1);
172 --remaining_entries;
173 ACE_TEST_ASSERT (map.current_size () == remaining_entries);
176 return 0;
179 static int
180 test_hash_cache_map_manager (size_t table_size,
181 size_t iterations,
182 int test_iterators)
184 NULL_CACHING_STRATEGY null_caching_strategy;
185 HASH_CACHE_MAP_MANAGER map (null_caching_strategy,
186 table_size);
187 TYPE i;
188 TYPE j = 0;
189 ssize_t k;
191 for (i = 0; i < iterations; i++)
192 ACE_TEST_ASSERT (map.bind (i, i) != -1);
194 if (test_iterators)
197 i = 0;
199 HASH_CACHE_MAP_MANAGER::ITERATOR end = map.end ();
201 for (HASH_CACHE_MAP_MANAGER::ITERATOR iter = map.begin ();
202 iter != end;
203 ++iter)
205 ACE_DEBUG ((LM_DEBUG,
206 ACE_TEXT ("(%d|%d|%d)"),
208 (*iter).first (),
209 (*iter).second ()));
210 ++i;
213 ACE_DEBUG ((LM_DEBUG,
214 ACE_TEXT ("\n")));
215 ACE_TEST_ASSERT (i == iterations);
220 k = iterations - 1;
222 HASH_CACHE_MAP_MANAGER::REVERSE_ITERATOR rend = map.rend ();
224 for (HASH_CACHE_MAP_MANAGER::REVERSE_ITERATOR iter = map.rbegin ();
225 iter != rend;
226 ++iter)
228 ACE_DEBUG ((LM_DEBUG,
229 ACE_TEXT ("(%d|%d|%d)"),
231 (*iter).first (),
232 (*iter).second ()));
233 k--;
236 ACE_DEBUG ((LM_DEBUG,
237 ACE_TEXT ("\n")));
238 ACE_TEST_ASSERT (k == -1);
243 i = 0;
245 HASH_CACHE_MAP_MANAGER::iterator end = map.end ();
247 for (HASH_CACHE_MAP_MANAGER::iterator iter = map.begin ();
248 iter != end;
249 ++iter)
251 ACE_DEBUG ((LM_DEBUG,
252 ACE_TEXT ("(%d|%d|%d)"),
254 (*iter).first (),
255 (*iter).second ()));
256 ++i;
259 ACE_DEBUG ((LM_DEBUG,
260 ACE_TEXT ("\n")));
261 ACE_TEST_ASSERT (i == iterations);
266 k = iterations - 1;
268 HASH_CACHE_MAP_MANAGER::reverse_iterator rend = map.rend ();
270 for (HASH_CACHE_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
271 iter != rend;
272 ++iter)
274 ACE_DEBUG ((LM_DEBUG,
275 ACE_TEXT ("(%d|%d|%d)"),
277 (*iter).first (),
278 (*iter).second ()));
279 k--;
282 ACE_DEBUG ((LM_DEBUG,
283 ACE_TEXT ("\n")));
284 ACE_TEST_ASSERT (k == -1);
290 for (i = 0; i < iterations; ++i)
292 ACE_TEST_ASSERT (map.find (i, j) != -1);
293 ACE_TEST_ASSERT (i == j);
296 size_t remaining_entries = iterations;
297 for (i = 0; i < iterations; ++i)
299 ACE_TEST_ASSERT (map.unbind (i) != -1);
300 --remaining_entries;
301 ACE_TEST_ASSERT (map.current_size () == remaining_entries);
303 return 0;
307 static int
308 test_active_map_manager (size_t table_size,
309 size_t iterations,
310 int test_iterators)
312 ACTIVE_MAP_MANAGER map (table_size);
313 TYPE i;
314 TYPE j = 0;
315 ssize_t k;
317 ACTIVE_MAP_MANAGER::key_type *active_keys;
319 ACE_NEW_RETURN (active_keys,
320 ACTIVE_MAP_MANAGER::key_type[iterations],
323 for (i = 0;
324 i < iterations;
325 i++)
326 ACE_TEST_ASSERT (map.bind (i, active_keys[i]) != -1);
328 if (test_iterators)
331 i = 0;
333 ACTIVE_MAP_MANAGER::iterator end = map.end ();
335 for (ACTIVE_MAP_MANAGER::iterator iter = map.begin ();
336 iter != end;
337 ++iter)
339 ACTIVE_MAP_MANAGER::ENTRY &entry = *iter;
340 ACE_DEBUG ((LM_DEBUG,
341 ACE_TEXT ("(%d|%d-%d|%d)"),
343 entry.ext_id_.slot_index (),
344 entry.ext_id_.slot_generation (),
345 entry.int_id_));
346 ++i;
349 ACE_DEBUG ((LM_DEBUG,
350 ACE_TEXT ("\n")));
351 ACE_TEST_ASSERT (i == iterations);
355 k = iterations - 1;
357 ACTIVE_MAP_MANAGER::reverse_iterator rend = map.rend ();
359 for (ACTIVE_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
360 iter != rend;
361 ++iter)
363 ACTIVE_MAP_MANAGER::ENTRY &entry = *iter;
364 ACE_UNUSED_ARG (entry);
365 ACE_DEBUG ((LM_DEBUG,
366 ACE_TEXT ("(%d|%d-%d|%d)"),
368 entry.ext_id_.slot_index (),
369 entry.ext_id_.slot_generation (),
370 entry.int_id_));
371 k--;
374 ACE_DEBUG ((LM_DEBUG,
375 ACE_TEXT ("\n")));
376 ACE_TEST_ASSERT (k == -1);
380 for (i = 0; i < iterations; ++i)
382 ACE_TEST_ASSERT (map.find (active_keys[i], j) != -1);
383 ACE_TEST_ASSERT (i == j);
386 size_t remaining_entries = iterations;
387 for (i = 0; i < iterations; ++i)
389 ACE_TEST_ASSERT (map.unbind (active_keys[i]) != -1);
390 --remaining_entries;
391 ACE_TEST_ASSERT (map.current_size () == remaining_entries);
394 delete [] active_keys;
396 return 0;
399 static int
400 test_hash_map_manager (size_t table_size,
401 size_t iterations,
402 int test_iterators)
404 HASH_MAP_MANAGER map (table_size);
405 TYPE i;
406 TYPE j = 0;
407 ssize_t k;
409 for (i = 0; i < iterations; i++)
410 ACE_TEST_ASSERT (map.bind (i, i) != -1);
412 if (test_iterators)
415 i = 0;
417 HASH_ITERATOR end = map.end ();
418 for (HASH_ITERATOR iter = map.begin ();
419 iter != end;
420 ++iter)
422 HASH_ENTRY &entry = *iter;
423 ACE_DEBUG ((LM_DEBUG,
424 ACE_TEXT ("(%d|%d|%d)"),
426 entry.ext_id_,
427 entry.int_id_));
428 ++i;
431 ACE_DEBUG ((LM_DEBUG,
432 ACE_TEXT ("\n")));
433 ACE_TEST_ASSERT (i == iterations);
437 i = 0;
438 HASH_ENTRY *entry = 0;
440 for (HASH_ITERATOR iterator (map);
441 iterator.next (entry) != 0;
442 iterator.advance ())
444 ACE_DEBUG ((LM_DEBUG,
445 ACE_TEXT ("(%d|%d|%d)"),
447 entry->ext_id_,
448 entry->int_id_));
449 ++i;
452 ACE_DEBUG ((LM_DEBUG,
453 ACE_TEXT ("\n")));
454 ACE_TEST_ASSERT (i == iterations);
458 k = iterations - 1;
459 HASH_REVERSE_ITERATOR rend = map.rend ();
461 for (HASH_REVERSE_ITERATOR iter = map.rbegin ();
462 iter != rend;
463 ++iter)
465 HASH_ENTRY &entry = *iter;
466 ACE_DEBUG ((LM_DEBUG,
467 ACE_TEXT ("(%d|%d|%d)"),
469 entry.ext_id_,
470 entry.int_id_));
471 k--;
474 ACE_DEBUG ((LM_DEBUG,
475 ACE_TEXT ("\n")));
476 ACE_TEST_ASSERT (k == -1);
480 k = iterations - 1;
481 HASH_ENTRY *entry = 0;
483 for (HASH_REVERSE_ITERATOR iterator (map);
484 iterator.next (entry) != 0;
485 iterator.advance ())
487 ACE_DEBUG ((LM_DEBUG,
488 ACE_TEXT ("(%d|%d|%d)"),
490 entry->ext_id_,
491 entry->int_id_));
492 k--;
495 ACE_DEBUG ((LM_DEBUG,
496 ACE_TEXT ("\n")));
497 ACE_TEST_ASSERT (k == -1);
501 i = 0;
503 HASH_MAP_MANAGER::iterator end = map.end ();
504 for (HASH_MAP_MANAGER::iterator iter = map.begin ();
505 iter != end;
506 ++iter)
508 HASH_MAP_MANAGER::ENTRY &entry = *iter;
509 ACE_DEBUG ((LM_DEBUG,
510 ACE_TEXT ("(%d|%d|%d)"),
512 entry.ext_id_,
513 entry.int_id_));
514 ++i;
517 ACE_DEBUG ((LM_DEBUG,
518 ACE_TEXT ("\n")));
519 ACE_TEST_ASSERT (i == iterations);
523 i = 0;
524 HASH_MAP_MANAGER::ENTRY *entry = 0;
526 for (HASH_MAP_MANAGER::ITERATOR iterator (map);
527 iterator.next (entry) != 0;
528 iterator.advance ())
530 ACE_DEBUG ((LM_DEBUG,
531 ACE_TEXT ("(%d|%d|%d)"),
533 entry->ext_id_,
534 entry->int_id_));
535 ++i;
538 ACE_DEBUG ((LM_DEBUG,
539 ACE_TEXT ("\n")));
540 ACE_TEST_ASSERT (i == iterations);
544 k = iterations - 1;
545 HASH_MAP_MANAGER::reverse_iterator rend = map.rend ();
547 for (HASH_MAP_MANAGER::reverse_iterator iter = map.rbegin ();
548 iter != rend;
549 ++iter)
551 HASH_MAP_MANAGER::ENTRY &entry = *iter;
552 ACE_DEBUG ((LM_DEBUG,
553 ACE_TEXT ("(%d|%d|%d)"),
555 entry.ext_id_,
556 entry.int_id_));
557 k--;
560 ACE_DEBUG ((LM_DEBUG,
561 ACE_TEXT ("\n")));
562 ACE_TEST_ASSERT (k == -1);
566 k = iterations - 1;
567 HASH_MAP_MANAGER::ENTRY *entry = 0;
569 for (HASH_MAP_MANAGER::REVERSE_ITERATOR iterator (map);
570 iterator.next (entry) != 0;
571 iterator.advance ())
573 ACE_DEBUG ((LM_DEBUG,
574 ACE_TEXT ("(%d|%d|%d)"),
576 entry->ext_id_,
577 entry->int_id_));
578 k--;
581 ACE_DEBUG ((LM_DEBUG,
582 ACE_TEXT ("\n")));
583 ACE_TEST_ASSERT (k == -1);
587 for (i = 0; i < iterations; ++i)
589 ACE_TEST_ASSERT (map.find (i, j) != -1);
590 ACE_TEST_ASSERT (i == j);
593 size_t remaining_entries = iterations;
594 for (i = 0; i < iterations; ++i)
596 ACE_TEST_ASSERT (map.unbind (i) != -1);
597 --remaining_entries;
598 ACE_TEST_ASSERT (map.current_size () == remaining_entries);
601 return 0;
604 static int
605 test_map_manager (size_t table_size,
606 size_t iterations,
607 int test_iterators)
609 MAP_MANAGER map (table_size);
610 TYPE i;
611 TYPE j = 0;
612 ssize_t k;
614 for (i = 0; i < iterations; ++i)
615 ACE_TEST_ASSERT (map.bind (i, i) != -1);
617 if (test_iterators)
620 i = 0;
622 ITERATOR end = map.end ();
623 for (ITERATOR iter = map.begin ();
624 iter != end;
625 ++iter)
627 MAP_ENTRY &entry = *iter;
628 ACE_DEBUG ((LM_DEBUG,
629 ACE_TEXT ("(%d|%d|%d)"),
631 entry.ext_id_,
632 entry.int_id_));
633 ++i;
636 ACE_DEBUG ((LM_DEBUG,
637 ACE_TEXT ("\n")));
638 ACE_TEST_ASSERT (i == iterations);
642 i = 0;
643 MAP_ENTRY *entry = 0;
645 for (ITERATOR iterator (map);
646 iterator.next (entry) != 0;
647 iterator.advance ())
649 ACE_DEBUG ((LM_DEBUG,
650 ACE_TEXT ("(%d|%d|%d)"),
652 entry->ext_id_,
653 entry->int_id_));
654 ++i;
657 ACE_DEBUG ((LM_DEBUG,
658 ACE_TEXT ("\n")));
659 ACE_TEST_ASSERT (i == iterations);
663 k = iterations - 1;
664 REVERSE_ITERATOR rend = map.rend ();
666 for (REVERSE_ITERATOR iter = map.rbegin ();
667 iter != rend;
668 ++iter)
670 MAP_ENTRY &entry = *iter;
671 ACE_DEBUG ((LM_DEBUG,
672 ACE_TEXT ("(%d|%d|%d)"),
674 entry.ext_id_,
675 entry.int_id_));
676 k--;
679 ACE_DEBUG ((LM_DEBUG,
680 ACE_TEXT ("\n")));
681 ACE_TEST_ASSERT (k == -1);
685 k = iterations - 1;
686 MAP_ENTRY *entry = 0;
688 for (REVERSE_ITERATOR iterator (map);
689 iterator.next (entry) != 0;
690 iterator.advance ())
692 ACE_DEBUG ((LM_DEBUG,
693 ACE_TEXT ("(%d|%d|%d)"),
695 entry->ext_id_,
696 entry->int_id_));
697 k--;
700 ACE_DEBUG ((LM_DEBUG,
701 ACE_TEXT ("\n")));
702 ACE_TEST_ASSERT (k == -1);
706 i = 0;
708 MAP_MANAGER::iterator end = map.end ();
709 for (MAP_MANAGER::iterator iter = map.begin ();
710 iter != end;
711 ++iter)
713 MAP_MANAGER::ENTRY &entry = *iter;
714 ACE_DEBUG ((LM_DEBUG,
715 ACE_TEXT ("(%d|%d|%d)"),
717 entry.ext_id_,
718 entry.int_id_));
719 ++i;
722 ACE_DEBUG ((LM_DEBUG,
723 ACE_TEXT ("\n")));
724 ACE_TEST_ASSERT (i == iterations);
728 i = 0;
729 MAP_MANAGER::ENTRY *entry = 0;
731 for (MAP_MANAGER::ITERATOR iterator (map);
732 iterator.next (entry) != 0;
733 iterator.advance ())
735 ACE_DEBUG ((LM_DEBUG,
736 ACE_TEXT ("(%d|%d|%d)"),
738 entry->ext_id_,
739 entry->int_id_));
740 ++i;
743 ACE_DEBUG ((LM_DEBUG,
744 ACE_TEXT ("\n")));
745 ACE_TEST_ASSERT (i == iterations);
749 k = iterations - 1;
750 MAP_MANAGER::reverse_iterator rend = map.rend ();
752 for (MAP_MANAGER::reverse_iterator iter = map.rbegin ();
753 iter != rend;
754 ++iter)
756 MAP_ENTRY &entry = *iter;
757 ACE_DEBUG ((LM_DEBUG,
758 ACE_TEXT ("(%d|%d|%d)"),
760 entry.ext_id_,
761 entry.int_id_));
762 k--;
765 ACE_DEBUG ((LM_DEBUG,
766 ACE_TEXT ("\n")));
767 ACE_TEST_ASSERT (k == -1);
771 k = iterations - 1;
772 MAP_MANAGER::ENTRY *entry = 0;
774 for (MAP_MANAGER::REVERSE_ITERATOR iterator (map);
775 iterator.next (entry) != 0;
776 iterator.advance ())
778 ACE_DEBUG ((LM_DEBUG,
779 ACE_TEXT ("(%d|%d|%d)"),
781 entry->ext_id_,
782 entry->int_id_));
783 k--;
786 ACE_DEBUG ((LM_DEBUG,
787 ACE_TEXT ("\n")));
788 ACE_TEST_ASSERT (k == -1);
792 for (i = 0; i < iterations; ++i)
794 ACE_TEST_ASSERT (map.find (i, j) != -1);
795 ACE_TEST_ASSERT (i == j);
798 size_t remaining_entries = iterations;
799 for (i = 0; i < iterations; ++i)
801 ACE_TEST_ASSERT (map.unbind (i) != -1);
802 --remaining_entries;
803 ACE_TEST_ASSERT (map.current_size () == remaining_entries);
807 // This is extra for the map manager.
809 for (i = 0; i < iterations; ++i)
810 ACE_TEST_ASSERT (map.bind (i, i) != -1);
812 // Unbind in one swoop.
813 map.unbind_all ();
814 ACE_TEST_ASSERT (map.current_size () == 0);
816 for (i = 0; i < iterations; ++i)
817 ACE_TEST_ASSERT (map.bind (i, i) != -1);
819 // Unbind one at a time.
820 MAP_MANAGER::iterator end = map.end ();
821 while (1)
823 MAP_MANAGER::iterator iter = map.begin ();
824 if (iter == end)
825 break;
826 ACE_TEST_ASSERT (map.unbind ((*iter).ext_id_) != -1);
829 ACE_TEST_ASSERT (map.current_size () == 0);
831 return 0;
834 static int
835 run_test (int (*ptf) (size_t, size_t, int),
836 size_t table_size,
837 size_t iterations,
838 int test_iterators,
839 const ACE_TCHAR *test_name)
841 ACE_Profile_Timer timer;
842 timer.start ();
844 (*ptf) (table_size, iterations, test_iterators);
846 timer.stop ();
848 ACE_Profile_Timer::ACE_Elapsed_Time et;
850 timer.elapsed_time (et);
852 ACE_TCHAR *test_iterators_string = 0;
854 if (test_iterators)
855 test_iterators_string =
856 const_cast<ACE_TCHAR*> (ACE_TEXT ( "includes executing iterators"));
857 else
858 test_iterators_string =
859 const_cast<ACE_TCHAR*> (ACE_TEXT ("doesn't include executing iterators"));
861 ACE_DEBUG ((LM_DEBUG,
862 ACE_TEXT ("time to test a map of size %d for %d iterations using %s (%s)\n"),
863 table_size,
864 iterations,
865 test_name,
866 test_iterators_string));
868 ACE_DEBUG ((LM_DEBUG,
869 ACE_TEXT ("real time = %f secs, user time = %f secs, system time = %f secs\n"),
870 et.real_time,
871 et.user_time,
872 et.system_time));
874 ACE_timer_t time_result = 0.0;
875 if (iterations != 0)
876 time_result = (et.real_time / ACE_timer_t (iterations)) * 1000000;
878 ACE_DEBUG ((LM_DEBUG,
879 ACE_TEXT ("time per call = %f usecs\n"),
880 time_result));
882 return 0;
886 run_main (int argc, ACE_TCHAR *argv[])
888 ACE_START_TEST (ACE_TEXT ("Map_Manager_Test"));
889 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE);
890 int result = 0;
891 size_t table_size = ACE_MAX_ITERATIONS / 2;
892 size_t iterations = ACE_MAX_ITERATIONS;
893 int test_iterators = 1;
895 if (argc > 1)
896 table_size = ACE_OS::atoi (argv[1]);
898 if (argc > 2)
899 iterations = ACE_OS::atoi (argv[2]);
901 if (argc > 3)
902 test_iterators = ACE_OS::atoi (argv[3]);
904 if (table_size == 0)
906 ACE_ERROR ((LM_ERROR, "LM_ERROR@Table size is 0\n"));
907 ++result;
909 else
911 // Test the <ACE_Map_Manager>.
912 result += run_test (&test_map_manager,
913 table_size,
914 iterations,
915 test_iterators,
916 ACE_TEXT ("Map_Manager"));
918 // Test the <ACE_Hash_Map_Manager>.
919 result += run_test (&test_hash_map_manager,
920 table_size,
921 iterations,
922 test_iterators,
923 ACE_TEXT ("Hash_Map_Manager"));
925 // Test the <ACE_Hash_Map_Manager>.
926 result += run_test (&test_active_map_manager,
927 table_size,
928 iterations,
929 test_iterators,
930 ACE_TEXT ("Active_Map_Manager"));
932 // Test the <ACE_Cache_Map_Manager>.
933 result += run_test (&test_cache_map_manager,
934 table_size,
935 iterations,
936 test_iterators,
937 ACE_TEXT ("Cache_Map_Manager"));
939 // Test the <ACE_Hash_Cache_Map_Manager>.
940 result += run_test (&test_hash_cache_map_manager,
941 table_size,
942 iterations,
943 test_iterators,
944 ACE_TEXT ("Hash_Cache_Map_Manager"));
946 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
947 ACE_END_TEST;
948 return result;