]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_VERSIONED_LIBRARY_PATH.dtest/main.c
1 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=9 -current_version 9 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt9/libfoo.dylib
2 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib
3 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=11 -current_version 11 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt11/libfoo.dylib
4 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/alt12/libfoo.dylib
6 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/libfoo2.dylib
7 // BUILD(macos): $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/libfoo2.dylib -o $BUILD_DIR/alt12/libfoo2.dylib
9 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH.exe $BUILD_DIR/libfoo.dylib
10 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-10.exe $BUILD_DIR/libfoo.dylib
11 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-11.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11
12 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11
13 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt9:@loader_path/alt11
14 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-911c.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@executable_path/alt9:@executable_path/alt11
15 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1112.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12
16 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1112b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11:@loader_path/alt12
17 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1211.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12 -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt11
18 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-1211b.exe $BUILD_DIR/libfoo.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12:@loader_path/alt11
19 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing.exe $BUILD_DIR/libfoo2.dylib -Wl,-dyld_env,DYLD_VERSIONED_LIBRARY_PATH=@loader_path/alt12
20 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe -DUSE_DLOPEN -DRUN_DIR="$RUN_DIR" -DDYLIB_NAME="libfoo.dylib"
21 // BUILD(macos): $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-missing-dlopen.exe -DUSE_DLOPEN -DRUN_DIR="$RUN_DIR" -DDYLIB_NAME="libfoo2.dylib"
23 // BUILD(macos): $SKIP_INSTALL $BUILD_DIR/libfoo2.dylib
25 // BUILD(macos): $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH.exe
26 // BUILD(macos): $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_LIBRARY_PATH-11.exe
28 // BUILD(ios,tvos,watchos,bridgeos):
30 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 10
31 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 11
32 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 10
33 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9:$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 11
34 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11:$RUN_DIR/alt12 ./env-DYLD_VERSIONED_LIBRARY_PATH.exe 12
35 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-10.exe 10
36 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 11
37 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911.exe 11
38 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911b.exe 11
39 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-911c.exe 11
40 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1112.exe 12
41 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1112b.exe 12
42 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1211.exe 12
43 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-1211b.exe 12
44 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 11
45 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt12 ./env-DYLD_VERSIONED_LIBRARY_PATH-11.exe 12
46 // FIXME: Forcibly disable testing with closures since macOS does not use them and they are currently broken
47 // RUN: DYLD_USE_CLOSURES=0 ./env-DYLD_VERSIONED_LIBRARY_PATH-missing.exe 12
49 // RUN: ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 10
50 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 11
51 // RUN: DYLD_VERSIONED_LIBRARY_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_LIBRARY_PATH-dlopen.exe 10
52 // RUN: DYLD_VERSIONED_LIBRARY_PATH="/AppleInternal/CoreOS/tests/dyld/env-DYLD_VERSIONED_LIBRARY_PATH/alt12" ./env-DYLD_VERSIONED_LIBRARY_PATH-missing-dlopen.exe 12
54 #include <stdio.h> // fprintf(), NULL
55 #include <stdlib.h> // exit(), EXIT_SUCCESS
57 #include <stdlib.h> // for atoi()
59 #include "test_support.h"
67 int main(int argc
, const char* argv
[])
69 int expectedResult
= atoi(argv
[1]);
71 void * handle
= dlopen(RUN_DIR
"/" DYLIB_NAME
, RTLD_LAZY
);
73 FAIL("dlopen(\"%s\") failed with error \"%s\"", RUN_DIR
"/" DYLIB_NAME
, dlerror());
75 int (*foo
)() = dlsym(handle
, "foo");
77 FAIL("dlsym(\"foo\") failed with error \"%s\"", dlerror());
80 int actualResult
= foo();
81 if ( actualResult
!= expectedResult
) {
82 FAIL("Using wrong dylib. foo() returned %d, expected %d", actualResult
, expectedResult
);