1 //FUZZ: disable check_for_lack_ACE_OS
3 #include "ace/config-lite.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 ...
18 #if defined (ACE_HAS_THREADS)
19 # define CAN_USE_THREADS
21 # undef CAN_USE_THREADS
24 #if !(defined (WIN32) || defined (ACE_VXWORKS) || defined (ACE_HAS_LYNXOS_178))\
25 && !defined ACE_FACE_SAFETY_EXTENDED
31 # if defined (ACE_DLL_SUFFIX)
32 const char *DllTestName
= "./libBug_2980_Regression" ACE_DLL_SUFFIX
;
34 const char *DllTestName
= "./libBug_2980_Regression.so";
35 #endif /* ACE_DLL_SUFFIX */
38 # if defined CAN_USE_THREADS
46 #if defined (__BORLANDC__)
47 # define PRINTF std::printf
49 # define PRINTF printf
53 typedef int (* voidfunction
)(void);
56 #if defined (CAN_RUN_TEST)
57 static void * dllHandle
;
58 static voidfunction capi_init
= 0;
59 static voidfunction capi_fini
= 0;
60 static voidfunction capi_dosomething
= 0;
61 #endif /* defined (CAN_RUN_TEST) */
67 #if defined (CAN_RUN_TEST)
69 PRINTF ("loadDll - entered\n");
70 const char *subdir_env
= getenv ("ACE_EXE_SUB_DIR");
74 (char *) malloc (2 + strlen (subdir_env
) + strlen (DllTestName
));
75 strcpy (dllFile
, subdir_env
);
76 strcat (dllFile
, "/");
77 strcat (dllFile
, DllTestName
);
78 dllHandle
= dlopen (dllFile
, RTLD_NOW
);
83 dllHandle
= dlopen (DllTestName
, RTLD_NOW
);
88 PRINTF ("unable to load library: %s\n", dlerror());
89 assert(dllHandle
!= 0);
92 void* temp
= dlsym (dllHandle
, "capi_init");
93 memcpy (&capi_init
, &temp
, sizeof (temp
));
96 PRINTF ("unable to resolve symbol capi_init: %s\n", dlerror());
97 assert(capi_init
!= 0);
100 temp
= dlsym (dllHandle
, "capi_fini");
101 memcpy (&capi_fini
, &temp
, sizeof (temp
));
104 PRINTF ("unable to resolve symbol capi_fini: %s\n", dlerror());
105 assert(capi_fini
!= 0);
108 temp
= dlsym (dllHandle
, "capi_dosomething");
109 memcpy (&capi_dosomething
, &temp
, sizeof (temp
));
110 if (capi_dosomething
== 0)
112 PRINTF ("unable to resolve symbol capi_dosomething: %s\n", dlerror());
113 assert(capi_dosomething
!= 0);
116 PRINTF ("loadDll - leaving\n");
117 #endif /* defined (CAN_RUN_TEST) */
122 void* unloadDll(void*)
124 #if defined (CAN_RUN_TEST)
125 PRINTF ("unloadDll - entered\n");
128 PRINTF ("unloadDll - leaving\n");
129 #endif /* defined (CAN_RUN_TEST) */
133 void * loadunloadDll(void *pp
)
137 #if defined (CAN_RUN_TEST)
138 assert(capi_dosomething
!= 0);
140 #endif /* defined (CAN_RUN_TEST) */
146 // FUZZ: disable check_for_improper_main_declaration
147 int main (int, char *[])
149 #if !defined (CAN_RUN_TEST)
150 # ifndef ACE_FACE_SAFETY_EXTENDED
151 PRINTF ("Terminating because this test has not been designed "
152 "to run on WIN32 or VXWORKS.\n");
155 PRINTF ("main called\n");
156 PRINTF ("main - calling loadDll\n");
158 # if defined (CAN_USE_THREADS)
161 result
= pthread_create(&tid1
, 0, &loadDll
, 0);
164 PRINTF ("pthread_create() failed: %d\n", result
);
168 pthread_join(tid1
, 0);
169 PRINTF ("loadDll thread finished and re-joined\n");
174 PRINTF ("loadDll finished\n");
176 # endif /* defined (CAN_USE_THREADS) */
178 PRINTF ("main - calling unloadDll\n");
180 # if defined (CAN_USE_THREADS)
182 result
= pthread_create(&tid2
, 0, &unloadDll
, 0);
185 PRINTF ("pthread_create() failed: %d\n", result
);
188 pthread_join(tid2
, 0);
189 PRINTF ("unloadDll thread finished and re-joined\n");
194 PRINTF ("unloadDll finished\n");
196 # endif /* defined (CAN_USE_THREADS) */
198 PRINTF ("main finished\n");
199 #endif /* defined (CAN_RUN_TEST) */
204 //FUZZ: enable check_for_lack_ACE_OS