summaryrefslogtreecommitdiff
path: root/tests/Bug_3812_Regression/Bug_3812_Regression.cpp
blob: e485f7447a6bfb1e029121285d71fe65966bc7cd (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
// $Id$
#include "ace/Get_Opt.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/SString.h"
#include "ace/Manual_Event.h"
#include "ace/Task.h"
#include "ace/OS.h"

#include "tao/Transport_Cache_Manager_T.h"
#include "tao/ORB.h"
#include "tao/Condition.h"

class mock_transport;
class mock_tdi;
class mock_ps;

static int global_purged_count = 0;

#include "mock_tdi.h"
#include "mock_transport.h"
#include "mock_ps.h"

static TCM* tcm = 0;
static int result = 0;
static TAO_SYNCH_MUTEX test_lock;
static TAO_Condition<TAO_SYNCH_MUTEX> test_condition(test_lock);
static int n_threads = 1;

int
parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:"));
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 't':
        n_threads = ACE_OS::atoi(get_opts.opt_arg());
        break;
      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s "
                           "-t <n_threads>"
                           "\n",
                           argv [0]),
                          -1);
      }
  // Indicates sucessful parsing of the command line
  return 0;
}

class Client_Task : public ACE_Task_Base
{
  public : 
   Client_Task (mock_tdi& tdi, mock_transport& trans)
   : tdi_ (tdi),
     trans_ (trans)
   {
   }
   
   
  ~Client_Task () {};
   
  void process_listen_point ()
  {
    this->trans_.purge_entry ();
    // Allocate a new char to avoid the cache_transport malloc/free entry
    // on same address which makes it harder to verify test result.
    char*x = new char[1];
    tcm->cache_transport (&tdi_, &trans_);
    this->trans_.make_idle();
    delete x;
  }
   
  int svc ()
  {
    ACE_Guard<TAO_SYNCH_MUTEX> lock (test_lock);
    process_listen_point ();
    test_condition.signal ();
    return 0;
  };
   
   
 private:
    mock_tdi& tdi_;
    mock_transport& trans_;
};




int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      // We need an ORB to get an ORB core
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      size_t const transport_max = 10;
      int cache_maximum = 10;
      int purging_percentage = 20;
      mock_transport mytransport(orb->orb_core ());
      mock_tdi mytdi;
      mock_ps* myps = new mock_ps(1);
      TCM my_cache (purging_percentage, myps, cache_maximum, false, 0);

      tcm = &my_cache;
      tcm->cache_transport (&mytdi, &mytransport);

      Client_Task client_task(mytdi, mytransport);
      if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 2, 1) == -1)
        {
          ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
        }
       
      client_task.wait ();
      
      orb->destroy ();

    }
  catch (const CORBA::Exception&)
    {
      // Ignore exceptions..
    }
  return result;
}