X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fregression%2Fust%2Fust-dl%2Fprog.c;h=e4288928fad5235245086f8f47087bcb4eb2ab3c;hb=c9e313bc594f40a86eed237dce222c0fc99c957f;hp=015eee6269830e8e6e2150c7d9dbf592bfd66e96;hpb=c70c42cca32058806a5c7d96d7cf2fae4d4fb75f;p=lttng-tools.git diff --git a/tests/regression/ust/ust-dl/prog.c b/tests/regression/ust/ust-dl/prog.c index 015eee626..e4288928f 100644 --- a/tests/regression/ust/ust-dl/prog.c +++ b/tests/regression/ust/ust-dl/prog.c @@ -1,16 +1,93 @@ +/* + * Copyright (C) 2016 Antoine Busque + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +/* _GNU_SOURCE is defined by config.h */ #include +#include +#include +#include + +#include -int main() +/* + * libfoo has a direct dependency on libbar. + * libbar has a direct dependency on libzzz. + * This test is therefore a mix of dlopen/dlclose and dlmopen/dlclose of + * libfoo, and of its direct dependencies. + */ +int main(void) { - void *handle; - int (*foo)(); + void *h0, *h2, *h3, *h4; + +#ifdef HAVE_DLMOPEN + void *h1; +#endif + + char *error; + int (*foo)(void); + + h0 = dlopen("libbar.so", RTLD_LAZY); + if (!h0) { + goto get_error; + } + +#ifdef HAVE_DLMOPEN + h1 = dlmopen(LM_ID_BASE, "libfoo.so", RTLD_LAZY); + if (!h1) { + goto get_error; + } +#endif + + h2 = dlopen("libzzz.so", RTLD_LAZY); + if (!h2) { + goto get_error; + } + h3 = dlopen("libfoo.so", RTLD_LAZY); + if (!h3) { + goto get_error; + } + h4 = dlopen("libfoo.so", RTLD_LAZY); + if (!h4) { + goto get_error; + } + + foo = dlsym(h3, "foo"); + error = dlerror(); + if (error != NULL) { + goto error; + } + + foo(); + + if (dlclose(h0)) { + goto get_error; + } - handle = dlopen("libfoo.so", RTLD_LAZY); - foo = dlsym(handle, "foo"); +#ifdef HAVE_DLMOPEN + if (dlclose(h1)) { + goto get_error; + } +#endif - (*foo)(); + if (dlclose(h2)) { + goto get_error; + } + if (dlclose(h3)) { + goto get_error; + } + if (dlclose(h4)) { + goto get_error; + } - dlclose(handle); + exit(EXIT_SUCCESS); - return 0; +get_error: + error = dlerror(); +error: + fprintf(stderr, "%s\n", error); + exit(EXIT_FAILURE); }