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 ...
17 #if defined (ACE_HAS_THREADS)
18 # define CAN_USE_THREADS
20 # undef CAN_USE_THREADS
23 #if !(defined (WIN32) || defined (ACE_VXWORKS) || defined (ACE_HAS_LYNXOS_178))\
24 && !defined ACE_FACE_SAFETY_EXTENDED
30 # if defined (ACE_DLL_SUFFIX)
31 const char *DllTestName
= "./libBug_2980_Regression" ACE_DLL_SUFFIX
;
33 const char *DllTestName
= "./libBug_2980_Regression.so";
34 #endif /* ACE_DLL_SUFFIX */
37 # if defined CAN_USE_THREADS
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) */
57 #if defined (CAN_RUN_TEST)
58 std::printf ("loadDll - entered\n");
59 const char *subdir_env
= getenv ("ACE_EXE_SUB_DIR");
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
);
72 dllHandle
= dlopen (DllTestName
, RTLD_NOW
);
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
));
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
));
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);
105 std::printf ("loadDll - leaving\n");
106 #endif /* defined (CAN_RUN_TEST) */
111 void* unloadDll(void*)
113 #if defined (CAN_RUN_TEST)
114 std::printf ("unloadDll - entered\n");
117 std::printf ("unloadDll - leaving\n");
118 #endif /* defined (CAN_RUN_TEST) */
122 void * loadunloadDll(void *pp
)
126 #if defined (CAN_RUN_TEST)
127 assert(capi_dosomething
!= 0);
129 #endif /* defined (CAN_RUN_TEST) */
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");
144 std::printf ("main called\n");
145 std::printf ("main - calling loadDll\n");
147 # if defined (CAN_USE_THREADS)
150 result
= pthread_create(&tid1
, 0, &loadDll
, 0);
153 std::printf ("pthread_create() failed: %d\n", result
);
157 pthread_join(tid1
, 0);
158 std::printf ("loadDll thread finished and re-joined\n");
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)
171 result
= pthread_create(&tid2
, 0, &unloadDll
, 0);
174 std::printf ("pthread_create() failed: %d\n", result
);
177 pthread_join(tid2
, 0);
178 std::printf ("unloadDll thread finished and re-joined\n");
183 std::printf ("unloadDll finished\n");
185 # endif /* defined (CAN_USE_THREADS) */
187 std::printf ("main finished\n");
188 #endif /* defined (CAN_RUN_TEST) */
192 //FUZZ: enable check_for_lack_ACE_OS