2 //=============================================================================
4 * @file Time_Service_Test.cpp
6 * This example tests the Time Service server and clerk
7 * components. The test forks and execs two processes to run both
8 * the clerk and the time server. The clerk and the server
9 * communicate for a short duration after which the main process
10 * kills both the processes. No command line arguments are needed
13 * @author Prashant Jain <pjain@cs.wustl.edu>
15 //=============================================================================
18 #include "test_config.h"
19 #include "ace/Process.h"
20 #include "ace/Lib_Find.h"
21 #include "ace/OS_NS_string.h"
22 #include "ace/OS_NS_unistd.h"
25 ACE_TEXT ("..") ACE_DIRECTORY_SEPARATOR_STR \
26 ACE_TEXT ("netsvcs") ACE_DIRECTORY_SEPARATOR_STR \
27 ACE_TEXT ("servers") ACE_DIRECTORY_SEPARATOR_STR \
28 ACE_TEXT ("main") ACE_PLATFORM_EXE_SUFFIX \
29 ACE_TEXT (" -f ") ACE_PLATFORM
32 run_main (int, ACE_TCHAR
*[])
34 ACE_START_TEST (ACE_TEXT ("Time_Service_Test"));
36 // Make sure that the backing store is not there. We need to make
37 // sure because this test kills the Time Clerk and on some platforms
38 // the Clerk is not allowed to do a graceful shutdown. By cleaning
39 // the backing store here, we are sure that we get a fresh start and
40 // no garbage data from a possible aborted run
41 ACE_TCHAR backing_store
[MAXPATHLEN
+ 1];
43 #if defined (ACE_DEFAULT_BACKING_STORE)
44 // Create a temporary file.
45 ACE_OS::strcpy (backing_store
,
46 ACE_DEFAULT_BACKING_STORE
);
47 #else /* ACE_DEFAULT_BACKING_STORE */
48 if (ACE::get_temp_dir (backing_store
,
49 MAXPATHLEN
- 17) == -1) // -17 for ace-malloc-XXXXXX
52 ACE_TEXT ("Temporary path too long, ")
53 ACE_TEXT ("defaulting to current directory\n")));
57 // Add the filename to the end
58 ACE_OS::strcat (backing_store
,
59 ACE_TEXT ("ace-malloc-XXXXXX"));
61 #endif /* ACE_DEFAULT_BACKING_STORE */
63 ACE_OS::unlink (backing_store
);
65 const ACE_TCHAR
*server_cl
= APPLICATION
ACE_TEXT ("server.conf");
66 ACE_Process_Options server_options
;
67 #ifndef ACE_LACKS_VA_FUNCTIONS
68 server_options
.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs
, server_cl
);
72 if (server
.spawn (server_options
) == -1)
73 ACE_ERROR_RETURN ((LM_DEBUG
,
74 ACE_TEXT ("%n; %p (%s).\n"),
75 ACE_TEXT ("Server fork failed"),
80 ACE_TEXT ("Server forked with pid = %d.\n"),
85 const ACE_TCHAR
*clerk_cl
= APPLICATION
ACE_TEXT ("clerk.conf");
86 ACE_Process_Options clerk_options
;
87 #ifndef ACE_LACKS_VA_FUNCTIONS
88 clerk_options
.command_line (ACE_TEXT ("%") ACE_TEXT_PRIs
, clerk_cl
);
92 if (clerk
.spawn (clerk_options
) == -1)
93 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT ("%n; %p: (%s).\n"),
94 ACE_TEXT ("Clerk fork failed"), clerk_cl
), -1);
96 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Clerk forked with pid = %d.\n"),
99 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Sleeping...\n")));
102 if (clerk
.terminate () == -1)
103 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("Terminate failed for clerk.\n")),
106 if (server
.terminate () == -1)
107 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("Terminate failed for server.\n")),
110 // Because we kill the clerk process, on Win32 it may not do a
111 // graceful shutdown and the backing store file is left behind.
112 if (clerk
.wait () != 0)
113 ACE_OS::unlink (backing_store
);