dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / dlopen-fail-cleanly.dtest / main.c
1
2 // BUILD: $CC c.c -dynamiclib -o $BUILD_DIR/libcextra.dylib -install_name $RUN_DIR/libc.dylib -DEXTRA_SYMBOL=1
3 // BUILD: $CC c.c -dynamiclib -o $BUILD_DIR/libc.dylib -install_name $RUN_DIR/libc.dylib
4 // BUILD: $CC b.m -dynamiclib -o $BUILD_DIR/libb.dylib -install_name $RUN_DIR/libb.dylib $BUILD_DIR/libcextra.dylib -framework Foundation
5 // BUILD: $CC a.c -dynamiclib -o $BUILD_DIR/liba.dylib -install_name $RUN_DIR/liba.dylib $BUILD_DIR/libb.dylib
6 // BUILD: $CC main.c -DRUN_DIR="$RUN_DIR" -o $BUILD_DIR/dlopen-fail-cleanly.exe
7
8 // BUILD: $SKIP_INSTALL $BUILD_DIR/libcextra.dylib
9
10
11 // RUN: ./dlopen-fail-cleanly.exe
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <dlfcn.h>
16 #include <mach-o/dyld.h>
17
18 #include "test_support.h"
19
20 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
21 // dlopen dylib chain that should fail
22 void* handle = dlopen(RUN_DIR "/liba.dylib", RTLD_NOW);
23 if ( handle != NULL ) {
24 FAIL("dlopen(liba.dylib) expected to fail but did not");
25 }
26
27 // iterate loaded images and make sure no residue from failed dlopen
28 const char* foundPath = NULL;
29 int count = _dyld_image_count();
30 for (int i=0; i < count; ++i) {
31 const char* path = _dyld_get_image_name(i);
32 LOG("path[%2d]=%s", i, path);
33 if ( strstr(path, RUN_DIR "/lib") != NULL ) {
34 FAIL("Found unexpected loaded image: %s", path);
35 }
36 }
37
38 PASS("Success");
39 }
40