Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / tests / Bug_2980_Regression_Test.cpp
blob002cf03b53c2c514366ee8ca552e29fd25e4d22d
1 //FUZZ: disable check_for_lack_ACE_OS
3 #include "ace/config-lite.h"
5 #include <iostream>
6 #include <assert.h>
7 #include <cstdio>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <string.h>
12 // This is a non-ACE driver program which loads an ACE-based DLL. The
13 // usual ACE-related defines will not apply and we must use
14 // platform-specific ones.
16 // This test has not been made to work on Windows and vxWorks, yet ...
17 #if defined (ACE_HAS_THREADS)
18 # define CAN_USE_THREADS
19 #else
20 # undef CAN_USE_THREADS
21 #endif
23 #if !(defined (WIN32) || defined (ACE_VXWORKS) || defined (ACE_HAS_LYNXOS_178))\
24 && !defined ACE_FACE_SAFETY_EXTENDED
25 # define CAN_RUN_TEST
27 # include <dlfcn.h>
29 namespace {
30 # if defined (ACE_DLL_SUFFIX)
31 const char *DllTestName = "./libBug_2980_Regression" ACE_DLL_SUFFIX;
32 #else
33 const char *DllTestName = "./libBug_2980_Regression.so";
34 #endif /* ACE_DLL_SUFFIX */
37 # if defined CAN_USE_THREADS
38 # include <pthread.h>
39 # endif
41 #else
42 # undef CAN_RUN_TEST
43 #endif
45 using voidfunction = int (*)();
47 #if defined (CAN_RUN_TEST)
48 static void * dllHandle;
49 static voidfunction capi_init = 0;
50 static voidfunction capi_fini = 0;
51 static voidfunction capi_dosomething = 0;
52 #endif /* defined (CAN_RUN_TEST) */
54 extern "C"
55 void* loadDll(void*)
57 #if defined (CAN_RUN_TEST)
58 std::printf ("loadDll - entered\n");
59 const char *subdir_env = getenv ("ACE_EXE_SUB_DIR");
60 if (subdir_env)
62 char *dllFile =
63 (char *) malloc (2 + strlen (subdir_env) + strlen (DllTestName));
64 strcpy (dllFile, subdir_env);
65 strcat (dllFile, "/");
66 strcat (dllFile, DllTestName);
67 dllHandle = dlopen (dllFile, RTLD_NOW);
68 free (dllFile);
70 else
72 dllHandle = dlopen (DllTestName, RTLD_NOW);
75 if (dllHandle == 0)
77 std::printf ("unable to load library: %s\n", dlerror());
78 assert(dllHandle != 0);
81 void* temp = dlsym (dllHandle, "capi_init");
82 memcpy (&capi_init, &temp, sizeof (temp));
83 if (capi_init == 0)
85 std::printf ("unable to resolve symbol capi_init: %s\n", dlerror());
86 assert(capi_init != 0);
89 temp = dlsym (dllHandle, "capi_fini");
90 memcpy (&capi_fini, &temp, sizeof (temp));
91 if (capi_fini == 0)
93 std::printf ("unable to resolve symbol capi_fini: %s\n", dlerror());
94 assert(capi_fini != 0);
97 temp = dlsym (dllHandle, "capi_dosomething");
98 memcpy (&capi_dosomething, &temp, sizeof (temp));
99 if (capi_dosomething == 0)
101 std::printf ("unable to resolve symbol capi_dosomething: %s\n", dlerror());
102 assert(capi_dosomething != 0);
104 capi_init();
105 std::printf ("loadDll - leaving\n");
106 #endif /* defined (CAN_RUN_TEST) */
107 return 0;
110 extern "C"
111 void* unloadDll(void*)
113 #if defined (CAN_RUN_TEST)
114 std::printf ("unloadDll - entered\n");
115 capi_fini();
116 dlclose(dllHandle);
117 std::printf ("unloadDll - leaving\n");
118 #endif /* defined (CAN_RUN_TEST) */
119 return 0;
122 void * loadunloadDll(void *pp)
124 loadDll(pp);
126 #if defined (CAN_RUN_TEST)
127 assert(capi_dosomething != 0);
128 capi_dosomething();
129 #endif /* defined (CAN_RUN_TEST) */
131 unloadDll(pp);
133 return 0;
135 // FUZZ: disable check_for_improper_main_declaration
136 int main (int, char *[])
138 #if !defined (CAN_RUN_TEST)
139 # ifndef ACE_FACE_SAFETY_EXTENDED
140 std::printf ("Terminating because this test has not been designed "
141 "to run on WIN32 or VXWORKS.\n");
142 # endif
143 #else
144 std::printf ("main called\n");
145 std::printf ("main - calling loadDll\n");
147 # if defined (CAN_USE_THREADS)
148 int result = 0;
149 pthread_t tid1;
150 result = pthread_create(&tid1, 0, &loadDll, 0);
151 if (result != 0)
153 std::printf ("pthread_create() failed: %d\n", result);
154 return result;
157 pthread_join(tid1, 0);
158 std::printf ("loadDll thread finished and re-joined\n");
160 # else
162 loadDll(0);
163 std::printf ("loadDll finished\n");
165 # endif /* defined (CAN_USE_THREADS) */
167 std::printf ("main - calling unloadDll\n");
169 # if defined (CAN_USE_THREADS)
170 pthread_t tid2;
171 result = pthread_create(&tid2, 0, &unloadDll, 0);
172 if (result != 0)
174 std::printf ("pthread_create() failed: %d\n", result);
175 return 1;
177 pthread_join(tid2, 0);
178 std::printf ("unloadDll thread finished and re-joined\n");
180 # else
182 unloadDll(0);
183 std::printf ("unloadDll finished\n");
185 # endif /* defined (CAN_USE_THREADS) */
187 std::printf ("main finished\n");
188 #endif /* defined (CAN_RUN_TEST) */
190 return 0;
192 //FUZZ: enable check_for_lack_ACE_OS