summaryrefslogtreecommitdiff
path: root/tests/Time_Service_Test.cpp
blob: d26eb9fb83cf322412bc22d426671b5de9c8b76e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
// 
// = FILENAME
//    Time_Service_Test
//
// = DESCRIPTION
//    This example tests the Time Service server and clerk
//    components. The test forks and execs two processes to run both
//    the clerk and the time server. The clerk and the server
//    communicate for a short duration after which the main process
//    kills both the processes. No command line arguments are needed
//    to run the test.
//
// = AUTHOR
//    Prashant Jain
// 
// ============================================================================

#include "ace/OS.h"

#include "test_config.h"
#include "ace/Process.h"

int
main (int, char *[])
{
  ACE_START_TEST ("Time_Service_Test");

  char app[BUFSIZ];
  char server_conf[BUFSIZ];
  char clerk_conf[BUFSIZ];

  ACE_OS::sprintf (server_conf, "%s", ACE_PLATFORM "server.conf");
  ACE_OS::sprintf (clerk_conf, "%s", ACE_PLATFORM "clerk.conf");

  ACE_OS::sprintf (app, ".." ACE_DIRECTORY_SEPARATOR_STR "netsvcs" ACE_DIRECTORY_SEPARATOR_STR
		   "servers" ACE_DIRECTORY_SEPARATOR_STR "main" ACE_PLATFORM_EXE_SUFFIX);

  char *s_argv[4];
  s_argv[0] = app;
  s_argv[1] = "-f";
  s_argv[2] = server_conf;
  s_argv[3] = 0;

  ACE_Process server;

  if (server.start (s_argv) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG, "%n %p.\n", "Server fork failed"), 0);
  else
    ACE_DEBUG ((LM_DEBUG, "Server forked with pid = %d.\n", server.getpid ()));

  ACE_OS::sleep (3);
  s_argv[2] = clerk_conf;

  ACE_Process clerk;

  if (clerk.start (s_argv) == -1)
    ACE_ERROR_RETURN ((LM_DEBUG, "%p.\n", "Clerk fork failed"), 0);
  else
    ACE_DEBUG ((LM_DEBUG, "Server forked with pid = %d.\n", clerk.getpid ()));

  ACE_DEBUG ((LM_DEBUG, "Sleeping...\n"));
  ACE_OS::sleep (10);

  if (clerk.kill () == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "Kill failed for clerk.\n"), -1);

  if (server.kill () == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "Kill failed for server.\n"), -1);

  ACE_END_TEST;
  return 0;
}