2 //=============================================================================
4 * @file Unload_libACE.cpp
6 * This is a simple test of library unloading that uses
7 * an application which has _not_ been linked with libACE
8 * but uses dlopen() to dynamically load libACE
9 * and then uses dlclose() to unload it.
11 * @author David Smith <dts@prismtech.com> and Don Sharp <Donald.Sharp@prismtech.com>
13 //=============================================================================
16 //FUZZ: disable check_for_lack_ACE_OS
17 //FUZZ: disable check_for_improper_main_declaration
21 #undef UNLOAD_LIBACE_TEST
23 #if defined (__GNUC__)
24 #if !defined (ACE_VXWORKS) && !defined (__MINGW32__) && !defined (__CYGWIN32__)
25 #define UNLOAD_LIBACE_TEST 1
26 #endif /* !ACE_VXWORKS && !__MINGW32__ && !CYGWIN32 */
29 #if defined (ACE_AS_STATIC_LIBS)
30 #undef UNLOAD_LIBACE_TEST
31 #endif /* ACE_AS_STATIC_LIBS */
33 #ifdef UNLOAD_LIBACE_TEST
42 #define TIME_STAMP_FIELD_WIDTH 32
45 time_stamp (char date_and_time
[], int date_and_timelen
, int format
)
47 static char const *const month_name
[] =
63 static char const *const day_of_week_name
[] =
76 if (date_and_timelen
>= TIME_STAMP_FIELD_WIDTH
)
82 now
= localtime (&timeval
); /* Get current local time. */
86 sprintf (date_and_time
,
87 "%3s %3s %2d %04d %02d:%02d:%02d.%06d",
88 day_of_week_name
[now
->tm_wday
],
89 month_name
[now
->tm_mon
],
91 (int) now
->tm_year
+ 1900,
93 (int) now
->tm_min
, (int) now
->tm_sec
, (int) 0);
97 sprintf (date_and_time
,
98 "%3s %2d %02d:%02d:%02d.%03d %04d",
99 month_name
[now
->tm_mon
],
103 (int) now
->tm_sec
, (int) 0,
104 (int) now
->tm_year
+ 1900);
115 char const *const program
= "UnloadLibACE";
124 if ((logfp
= fopen ("log/UnloadLibACE.log", "w")) != 0)
126 setvbuf (logfp
, 0, _IONBF
, 0);
127 // reassign stdout/stderr to log file
128 int fdno
= fileno (logfp
);
130 dup2 (fdno
, fileno (stdout
));
131 dup2 (fdno
, fileno (stderr
));
132 setvbuf (stdout
, 0, _IONBF
, 0);
133 setvbuf (stderr
, 0, _IONBF
, 0);
137 printf ("%s@LM_DEBUG@ Starting %s test at %s\n",
138 time_stamp (tbuf
, BUFSIZ
, 'T'),
139 program
, time_stamp (ybuf
, BUFSIZ
, 'Y'));
141 if ((ace_root
= getenv ("ACE_ROOT")) != 0)
145 strcpy (buf
, ace_root
);
146 strcat (buf
, "/lib/");
147 const char *subdir_env
= getenv ("ACE_EXE_SUB_DIR");
150 strcat (buf
, subdir_env
);
154 #if defined (ACE_LIB_NAME)
155 strcat (buf
, ACE_LIB_NAME
);
158 #endif /* ACE_LIB_NAME */
159 #if defined (__APPLE__)
160 strcat (buf
, ".dylib");
163 #endif /* (__hpux) */
165 handle
= dlopen (buf
, RTLD_LAZY
);
168 // is it because of "No such file or directory" ?
172 "%s@LM_ERROR@ dlopen() returned NULL\n",
173 time_stamp (tbuf
, BUFSIZ
, 'T'));
175 "%s@LM_ERROR@ dlerror() says: %s\n",
176 time_stamp (tbuf
, BUFSIZ
, 'T'), dlerror ());
181 printf ("%s@LM_DEBUG@ dlopen() did not find %s\n",
182 time_stamp (tbuf
, BUFSIZ
, 'T'), buf
);
186 else if (dlclose (handle
) != 0)
189 "%s@LM_ERROR@ dlclose() failed : %s\n",
190 time_stamp (tbuf
, BUFSIZ
, 'T'), strerror (errno
));
197 "%s@LM_ERROR@ ACE_ROOT environment variable not set\n",
198 time_stamp (tbuf
, BUFSIZ
, 'T'));
210 // Couldn't go into the log file !!!
211 printf ("%s@LM_DEBUG@ Starting %s test at %s\n",
212 time_stamp (tbuf
, BUFSIZ
, 'T'),
213 program
, time_stamp (ybuf
, BUFSIZ
, 'Y'));
216 "%s@LM_ERROR@ Could not open log/UnloadLibACE.log : %s\n",
217 time_stamp (tbuf
, BUFSIZ
, 'T'), strerror (errno
));
221 printf ("%s@LM_DEBUG@ Ending %s test at %s\n",
222 time_stamp (tbuf
, BUFSIZ
, 'T'),
223 program
, time_stamp (ybuf
, BUFSIZ
, 'Y'));
230 // Don't change this since we do NOT want to use ACE for this test!
235 # if defined (WIN32) && defined (ACE_USES_WCHAR)
236 // Borrow include list from ace_wchar.h
237 # if !defined (__BORLANDC__)
238 # include /**/ <wchar.h>
239 # endif /* __BORLANDC__ */
242 wmain (int, wchar_t **)
246 #endif /* (WIN32) && (ACE_USES_WCHAR) */
248 char const *const program
= "UnloadLibACE";
252 if ((logfp
= fopen ("log/UnloadLibACE.log", "w")) != 0)
254 fprintf (logfp
, "@LM_DEBUG@ Starting %s test\n", program
);
255 fprintf (logfp
, "@LM_DEBUG@ %s test not implemented for this platform\n",
257 fprintf (logfp
, "@LM_DEBUG@ Ending %s test\n", program
);
264 #endif /* UNLOAD_LIBACE_TEST */