Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Crash_On_Write / client.cpp
blob6d3b85d08fb95be9f2dcc39669425c4da2658945
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 int iterations = 2000;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:i:"));
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 '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-k <ior> "
30 "-i iterations "
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 single_iteration (Test::Oneway_Receiver_ptr oneway_receiver)
42 try
44 oneway_receiver->receive_oneway ();
45 ACE_Time_Value tv (0, 40000);
46 ACE_OS::sleep (tv);
48 catch (const CORBA::Exception&)
50 return 1;
52 return 0;
55 int
56 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
58 try
60 CORBA::ORB_var orb =
61 CORBA::ORB_init (argc, argv);
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 CORBA::Object_var tmp =
67 orb->string_to_object(ior);
69 Test::Oneway_Receiver_var oneway_receiver =
70 Test::Oneway_Receiver::_narrow(tmp.in ());
72 if (CORBA::is_nil (oneway_receiver.in ()))
74 ACE_ERROR_RETURN ((LM_DEBUG,
75 "Nil process reference <%s>\n",
76 ior),
77 1);
80 int normal_count = 0;
81 int exception_count = 0;
82 for (int i = 0; i != iterations; ++i)
84 int result = single_iteration (oneway_receiver.in ());
85 if (result)
86 exception_count++;
87 else
88 normal_count++;
90 if (i % 100 == 0)
91 ACE_DEBUG ((LM_DEBUG, "Finished iteration %d\n", i));
93 // Lets not waste any more time than we have to
94 if (exception_count > 10 && normal_count > 0)
95 break;
98 if (exception_count == 0)
99 ACE_ERROR ((LM_ERROR, "ERROR: no exceptions detected\n"));
101 if (normal_count == 0)
102 ACE_ERROR ((LM_ERROR, "ERROR: no request was succesful\n"));
104 orb->destroy ();
106 catch (const CORBA::Exception& ex)
108 ex._tao_print_exception ("Exception caught:");
109 return 1;
112 return 0;