Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / tests / Timeprobe_Test.cpp
blobd4fa1f1d350ce3af3428cbcc213270c8d948a6d3
2 //=============================================================================
3 /**
4 * @file Timeprobe_Test.cpp
6 * This is a simple test of ACE Timeprobes.
8 * @author Irfan Pyarali <irfan@cs.wustl.edu>
9 */
10 //=============================================================================
13 //#define ACE_ENABLE_TIMEPROBES
14 //#define ACE_MT_TIMEPROBES
15 //#define ACE_TSS_TIMEPROBES
17 #include "test_config.h"
18 #include "ace/Singleton.h"
19 #include "ace/Synch_Traits.h"
20 #include "ace/Recursive_Thread_Mutex.h"
21 #include "ace/Null_Mutex.h"
22 #include "ace/OS_NS_unistd.h"
23 #include "ace/Timeprobe.h"
26 #if defined (ACE_ENABLE_TIMEPROBES)
28 static const char *events_descriptions_0[] =
30 "Event Zero",
31 "Event One",
32 "Event Two",
33 "Event Three",
34 "Event Four",
35 "Event Five",
36 "Event Six",
37 "Event Seven",
38 "Event Eight",
39 "Event Nine"
42 enum
44 EVENT_ZERO = 0,
45 EVENT_ONE,
46 EVENT_TWO,
47 EVENT_THREE,
48 EVENT_FOUR,
49 EVENT_FIVE,
50 EVENT_SIX,
51 EVENT_SEVEN,
52 EVENT_EIGHT,
53 EVENT_NINE
56 static const char *events_descriptions_1[] =
58 "Work start",
59 "Work end"
62 enum
64 WORK_START = 100,
65 WORK_END
68 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_1, WORK_START);
69 ACE_TIMEPROBE_EVENT_DESCRIPTIONS (events_descriptions_0, EVENT_ZERO);
71 #endif /* ACE_ENABLE_TIMEPROBES */
73 static void
74 work (int time)
76 ACE_FUNCTION_TIMEPROBE (WORK_START);
77 ACE_OS::sleep (time);
80 #if !defined (ACE_HAS_PURIFY)
81 // Test creation of ACE_Singletons during static object construction.
82 // Timeprobes can do that, when they're enabled. Purify would notice
83 // the memory in use at program termination.
84 static int
85 create_singleton ()
87 int *i = ACE_Singleton <int, ACE_SYNCH_RECURSIVE_MUTEX>::instance ();
88 *i = 3;
90 return *i;
93 int static_singleton_creator = create_singleton ();
94 #endif /* ! ACE_HAS_PURIFY */
96 int
97 run_main (int, ACE_TCHAR *[])
99 ACE_START_TEST (ACE_TEXT ("Timeprobe_Test"));
101 ACE_TIMEPROBE ("Starting Test");
103 for (int i = 0; i < 3; i++)
105 work (i);
106 ACE_TIMEPROBE (EVENT_ZERO + i);
109 ACE_TIMEPROBE ("Ending Test");
111 ACE_TIMEPROBE_PRINT;
113 ACE_END_TEST;
115 return 0;