Add a couple of regression tests for dlerror() handling.
This commit is contained in:
parent
15f633fbd3
commit
24b586b3b1
|
@ -1,5 +1,5 @@
|
|||
# $NetBSD: Makefile,v 1.1 2000/12/08 19:24:29 drochner Exp $
|
||||
# $NetBSD: Makefile,v 1.2 2002/11/14 21:10:45 nathanw Exp $
|
||||
|
||||
SUBDIR+= dlopen testlib
|
||||
SUBDIR+= dlopen testlib dlerror-false dlerror-cleared
|
||||
|
||||
.include <bsd.subdir.mk>
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# $NetBSD: Makefile,v 1.1 2002/11/14 21:10:46 nathanw Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= dlerror-cleared
|
||||
|
||||
regress:
|
||||
./${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <err.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *handle;
|
||||
char *error;
|
||||
|
||||
/*
|
||||
* Test that an error set by dlopen() persists past a successful
|
||||
* dlopen() call.
|
||||
*/
|
||||
handle = dlopen("libnonexistent.so", DL_LAZY);
|
||||
handle = dlopen("libm.so", DL_LAZY);
|
||||
error = dlerror();
|
||||
if (error == NULL)
|
||||
errx(1, "Failed: dlerror() was cleared by successful dlopen()\n");
|
||||
printf("OK: %s\n", error);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
# $NetBSD: Makefile,v 1.1 2002/11/14 21:10:47 nathanw Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= dlerror-false
|
||||
|
||||
LDADD= -Wl,-rpath,/var/nonexistent/lib
|
||||
|
||||
regress:
|
||||
./${PROG}
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,38 @@
|
|||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
#include <err.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *handle, *sym;
|
||||
char *error;
|
||||
|
||||
/*
|
||||
* Test for dlerror() being set by a successful library open.
|
||||
* Requires that the rpath be set to something that does not
|
||||
* include libm.so.
|
||||
*/
|
||||
|
||||
handle = dlopen("libm.so", DL_LAZY);
|
||||
error = dlerror();
|
||||
if (error != NULL)
|
||||
errx(1, "Error opening libm.so: %s", error);
|
||||
if (handle == NULL)
|
||||
errx(1, "Library handle is NULL but dlerror not set.");
|
||||
|
||||
sym = dlsym(handle, "sin");
|
||||
error = dlerror();
|
||||
if (error != NULL)
|
||||
errx(1, "Error looking up sin(): %s", error);
|
||||
if (sym == NULL)
|
||||
errx(1, "Looked-up symbol is NULL but dlerror not set.");
|
||||
|
||||
dlclose(handle);
|
||||
error = dlerror();
|
||||
if (error != NULL)
|
||||
errx(1, "Error calling dlclose(): %s", error);
|
||||
|
||||
printf("OK\n");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue