Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / MT_Timeout / client.cpp
blob21e9291f016352661d6894b305721597e6076154
1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
4 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
5 int iterations = 500;
6 int threads = 4;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:n:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
21 case 'i':
22 iterations = ACE_OS::atoi (get_opts.opt_arg ());
23 break;
25 case 'n':
26 threads = ACE_OS::atoi (get_opts.opt_arg ());
27 break;
29 case '?':
30 default:
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "usage: %s "
33 "-k <ior> "
34 "-i <iterations> "
35 "-i <threads> "
36 "\n",
37 argv [0]),
38 -1);
40 // Indicates successful parsing of the command line
41 return 0;
44 int
45 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
47 try
49 CORBA::ORB_var orb =
50 CORBA::ORB_init (argc, argv);
52 if (parse_args (argc, argv) != 0)
53 return 1;
55 CORBA::Object_var tmp =
56 orb->string_to_object(ior);
58 Test::Sleep_Service_var sleep_service =
59 Test::Sleep_Service::_narrow(tmp.in ());
61 if (CORBA::is_nil (sleep_service.in ()))
63 ACE_ERROR_RETURN ((LM_DEBUG,
64 "Nil process reference <%s>\n",
65 ior),
66 1);
69 Client_Task task0 (orb.in (),
70 sleep_service.in (),
71 iterations,
72 10 * 1000,
73 20 * 1000);
74 Client_Task task1 (orb.in (),
75 sleep_service.in (),
76 iterations,
77 50 * 1000,
78 20 * 1000);
80 if (task0.activate (THR_NEW_LWP | THR_JOINABLE, threads, 1) == -1)
82 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
84 if (task1.activate (THR_NEW_LWP | THR_JOINABLE, threads, 1) == -1)
86 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
88 ACE_Thread_Manager::instance ()->wait ();
90 // Get back in sync with the server..
91 sleep_service->go_to_sleep (0);
93 sleep_service->shutdown ();
95 orb->destroy ();
97 ACE_DEBUG ((LM_DEBUG,
98 "Task 0: Successful calls = %d, timed out calls = %d\n",
99 task0.successful_calls (),
100 task0.timed_out_calls ()));
102 ACE_DEBUG ((LM_DEBUG,
103 "Task 1: Successful calls = %d, timed out calls = %d\n",
104 task1.successful_calls (),
105 task1.timed_out_calls ()));
107 // No more than 5 % of the calls are allowed to have a too big
108 // difference
109 if (task0.too_big_difference_calls () > iterations/20
110 || task1.too_big_difference_calls () > iterations/20)
112 //FUZZ: disable check_for_lack_ACE_OS
113 ACE_DEBUG ((LM_DEBUG,
114 "Warning: Too many calls have a too big difference between "
115 "timeout and elapsed time (task0: %d, task1: %d)\n",
116 task0.too_big_difference_calls (),
117 task1.too_big_difference_calls ()));
118 //FUZZ: enable check_for_lack_ACE_OS
120 else if (task0.too_big_difference_calls () != 0
121 || task1.too_big_difference_calls () != 0)
123 ACE_DEBUG ((LM_DEBUG,
124 "Warning: some calls (task0: %d, task1: %d) "
125 "exceeded their expected elapsed times\n",
126 task0.too_big_difference_calls (),
127 task1.too_big_difference_calls ()));
130 if (task0.timed_out_calls () == 0)
132 ACE_ERROR ((LM_ERROR,
133 "ERROR: non-zero number of timeouts "
134 "expected for task 0\n"));
137 if (task1.successful_calls () != 0)
139 ACE_ERROR ((LM_ERROR,
140 "ERROR: zero successful calls "
141 "expected for task 1\n"));
144 catch (const CORBA::Exception& ex)
146 ex._tao_print_exception ("Exception caught:");
147 return 1;
150 return 0;