summaryrefslogtreecommitdiff
path: root/TAO/tests/Param_Test/client.cpp
blob: eb16cd274bcfd1feb3a08a6d14eaa440954bff91 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// $Id:

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    client.cpp
//
// = DESCRIPTION
//    This file contains the implementation of the client-side of the
//    Param_Test application.
//
// = AUTHORS
//      Aniruddha Gokhale
//
// ============================================================================

#if !defined (CLIENT_CPP)
#define CLIENT_CPP

#include "options.h"
#include "results.h"
#include "client.h"

// Constructor.p
template <class T>
Param_Test_Client<T>::Param_Test_Client (CORBA::ORB_ptr orb,
                                         Param_Test_ptr objref,
                                         T *t)
  : orb_ (orb),
    param_test_ (objref),
    test_object_ (t)
{
}

// destructor
template <class T>
Param_Test_Client<T>::~Param_Test_Client (void)
{
  CORBA::release (this->orb_);
  delete this->test_object_;
}

// All the individual tests
template <class T> int
Param_Test_Client<T>::run_sii_test (void)
{
  CORBA::ULong i;  // loop index
  CORBA::Environment env; // to track errors
  Options *opt = OPTIONS::instance (); // get the options
  const char *opname = this->test_object_->opname (); // operation

  // initialize call count and error count
  this->results_.call_count (0);
  this->results_.error_count (0);
  this->results_.iterations (opt->loop_count ());

  // initialize parameters for the test
  if (this->test_object_->init_parameters (this->param_test_, env) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "(%N:%l) client.cpp - run_sii_test:"
                  "init_parameters failed for opname - %s",
                  opname));
      return -1;
    }

  // Make the calls in a loop.
  for (i = 0; i < opt->loop_count (); i++)
    {
      this->results_.call_count (this->results_.call_count () + 1);
      if (opt->debug ())
        {
          ACE_DEBUG ((LM_DEBUG, "\n****** Before call values *****\n"));
          //          this->test_object_->print_values ();
        }

      // start the timing
      this->results_.start_timer ();

      // make the call
      if (this->test_object_->run_sii_test (this->param_test_, env) == -1)
        {
          this->results_.error_count (this->results_.error_count () + 1);
          env.print_exception (opname);
          ACE_ERROR ((LM_ERROR,
                      "(%N:%l) client.cpp - run_sii_test:"
                      "run_sii_test exception in iteration %d",
                      i));
          continue;
        }
      // stop the timer.
      this->results_.stop_timer ();

      // now check if the values returned are as expected
      if (opt->debug ())
        {
          ACE_DEBUG ((LM_DEBUG, "\n****** After call values *****\n"));
          this->test_object_->print_values ();
        }

      if (!this->test_object_->check_validity ())
        {
          this->results_.error_count (this->results_.error_count () + 1);
          ACE_ERROR ((LM_ERROR,
                      "(%N:%l) client.cpp - run_sii_test: "
                      "Invalid results in iteration %d - ",
                      i));
          continue;
        }
      // reset parameters for the test
      if (this->test_object_->reset_parameters () == -1)
        {
          ACE_ERROR ((LM_ERROR,
                  "(%N:%l) client.cpp - run_dii_test:"
                      "init_parameters failed for opname - %s",
                      opname));
          return -1;
        }
    }

  // print statistics
  this->results_.print_stats (this->test_object_->opname ());
  return this->results_.error_count ()? -1:0;
}

// use DII
template <class T> int
Param_Test_Client<T>::run_dii_test (void)
{
  CORBA::ULong i;  // loop index
  CORBA::Request_ptr req; // DII request
  const char *opname = this->test_object_->opname ();
  Options *opt = OPTIONS::instance ();
  CORBA::Environment env; // environment
  CORBA::NVList_ptr nvlist;  // argument list for DII parameters
  CORBA::NVList_ptr retval; // to access the NamedValue that stores the result

  // initialize call count and error count
  this->results_.call_count (0);
  this->results_.error_count (0);
  this->results_.iterations (opt->loop_count ());

  // initialize parameters for the test
  if (this->test_object_->init_parameters (this->param_test_, env) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "(%N:%l) client.cpp - run_dii_test:"
                  "init_parameters failed for opname - %s",
                  opname));
      return -1;
    }

  // Make the calls in a loop.
  for (i = 0; i < opt->loop_count (); i++)
    {
      this->results_.call_count (this->results_.call_count () + 1);

      // start the timing. We measure the entire overhead of DII, including the
      // time required to create and populate the NVList
      this->results_.start_timer ();

      // first create the argument list and populate it
      this->orb_->create_list (3, nvlist);
      this->orb_->create_list (1, retval);

      // add arguments and typecode for return valueto the NVList
      if (this->test_object_->add_args (nvlist, retval, env) == -1)
        {
          this->results_.error_count (this->results_.error_count () + 1);
          env.print_exception (opname);
          ACE_ERROR ((LM_ERROR,
                      "(%N:%l) client.cpp - "
                      "Failed to add args in iteration %d",
                      i));
          continue;
        }

      // create the request
      this->param_test_->_create_request (opname,
                                          nvlist,
                                          retval->item (0, env),
                                          req,
                                          0, //CORBA::OUT_LIST_MEMORY,
                                          env);
      // the OUT_LIST_MEMORY is to be used when the ORB assumes that we will
      // provide the top-level storage. With 0, the returned values for ret,
      // inout, and out parameters are all owned by the ORB and hence we must
      // not free them explicitly


      if (opt->debug ())
        {
          ACE_DEBUG ((LM_DEBUG, "\n****** Before call values *****\n"));
          //          this->test_object_->print_values ();
        }

      // Make the invocation, verify the result.
      req->invoke ();
      if (req->env ()->exception () != 0)
        {
          this->results_.error_count (this->results_.error_count () + 1);
          req->env ()->print_exception (opname);
          CORBA::release (req);
          continue;
        }

      if (opt->debug ())
        {
          ACE_DEBUG ((LM_DEBUG, "\n****** After call values *****\n"));
          this->test_object_->print_values ();
        }
      // now check if the values returned are as expected
      if (!this->test_object_->check_validity (req))
        {
          this->results_.error_count (this->results_.error_count () + 1);
          ACE_ERROR ((LM_ERROR,
                      "(%N:%l) client.cpp - "
                      "Invalid results in run_dii_test in iteration %d",
                      i));
          CORBA::release (req);
          continue;
        }
      // release the request
      CORBA::release (req);

      // stop the this->results_.
      this->results_.stop_timer ();

      // reset parameters for the test
      this->test_object_->reset_parameters ();

    } // for loop

  // print statistics
  this->results_.print_stats (opname);
  return this->results_.error_count ()? -1:0;

  return 0;
}


#endif /* CLIENT_CPP */