summaryrefslogtreecommitdiff
path: root/ACE/tests/TSS_Static_Test.cpp
blob: c86f1e4fee63e4dc65a9610b5438d9ccb2b8b418 (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

//=============================================================================
/**
 *  @file    TSS_Static_Test.cpp
 *
 *   This program tests the interaction between TSS and thread keys
 *   created during static construction.  VxWorks static construction
 *   is quite broken.  This test is designed to test changes to work
 *   around a bug in the VxWorks loader that constructs static objects
 *   multiple times.  It sounds hard to believe, but I've seen it!
 *
 *  @author Chad Elliott <elliott_c@ociweb.com>
 */
//=============================================================================


#include "test_config.h"
#include "ace/ACE.h"
#include "ace/Init_ACE.h"
#include "ace/Thread.h"


#if defined (ACE_HAS_TSS_EMULATION)

class Some_Object
{
public:
  Some_Object ();
  ~Some_Object ();
};

Some_Object::Some_Object ()
{
  ACE::init ();

  // Cause the ACE_Log_Msg to be constructed during static construction
  ACE_DEBUG ((LM_DEBUG, ""));

  // Assign something to TSS during static construction
  ACE_thread_key_t key;
  if (ACE_Thread::keycreate (&key, 0) == 0)
    {
      ACE_Thread::setspecific (key, this);
    }
}


Some_Object::~Some_Object ()
{
  ACE::fini ();
}


static Some_Object sobject;

int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("TSS_Static_Test"));

  int status = 0;
  ACE_thread_key_t key;
  if (ACE_Thread::keycreate (&key, 0) == 0)
    {
      void* specific = 0;
      if (ACE_Thread::getspecific (key, &specific) == 0)
        {
          if (specific == 0)
            {
              ACE_DEBUG ((LM_DEBUG, "Got back pointer: %x from key: %d. "
                                    "Good!\n",
                                    (size_t)specific, key));
            }
          else
            {
              ++status;
              ACE_ERROR ((LM_ERROR, "Something (%x) was found in tss "
                                    "slot %d.\n"
                                    "Nothing should be stored in our "
                                    "TSS slot!\n",
                                    (size_t)specific, key));
            }
        }
      else
        {
          ++status;
          ACE_ERROR ((LM_ERROR, "Unable to get the thread specific "
                                "storage.\n"));
        }
    }
  else
    {
      ++status;
      ACE_ERROR ((LM_ERROR, "Unable to create the thread specific "
                            "storage key.\n"));
    }
  ACE_END_TEST;
  return status;
}
#else
int
run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("TSS_Static_Test"));
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("This test requires TSS Emulation.\n")));
  ACE_END_TEST;
  return 0;
}
#endif /* ACE_HAS_TSS_EMULATION */