]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest/main.c
2fbce3adaeb1bad3783859c96d1450f0d5fafa94
[apple/dyld.git] / testing / test-cases / env-DYLD_VERSIONED_FRAMEWORK_PATH.dtest / main.c
1
2 // BUILD_ONLY: MacOSX
3 // BUILD: mkdir -p $BUILD_DIR/Foo.framework $BUILD_DIR/alt11/Foo.framework/Versions/A $BUILD_DIR/alt9/Foo.framework
4 // BUILD: mkdir -p $BUILD_DIR/alt12/Foo.framework $BUILD_DIR/Bar.framework $BUILD_DIR/alt11/Bar.framework/Versions/A
5 // BUILD: mkdir -p $BUILD_DIR/Foo2.framework $BUILD_DIR/alt12/Foo2.framework
6 // BUILD: $CC foo.c -dynamiclib -DRESULT=9 -current_version 9 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt9/Foo.framework/Foo
7 // BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/Foo.framework/Foo
8 // BUILD: $CC foo.c -dynamiclib -DRESULT=11 -current_version 11 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt11/Foo.framework/Versions/A/Foo
9 // BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/Foo.framework/Foo -o $BUILD_DIR/alt12/Foo.framework/Foo
10
11 // BUILD: $CC foo.c -dynamiclib -DRESULT=10 -current_version 10 -install_name $RUN_DIR/Foo2.framework/Foo2 -o $BUILD_DIR/Foo2.framework/Foo2
12 // BUILD: $CC foo.c -dynamiclib -DRESULT=12 -current_version 12 -install_name $RUN_DIR/Foo2.framework/Foo2 -o $BUILD_DIR/alt12/Foo2.framework/Foo2
13
14 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH.exe $BUILD_DIR/Foo.framework/Foo
15 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH-missing.exe -Wl,-dyld_env,DYLD_VERSIONED_FRAMEWORK_PATH=@loader_path/alt12 $BUILD_DIR/Foo2.framework/Foo2
16
17 // BUILD: cd $BUILD_DIR/alt11/Foo.framework && ln -sf Versions/A/Foo
18 // BUILD: rm -rf $BUILD_DIR/Foo2.framework
19 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_VERSIONED_FRAMEWORK_PATH.exe
20
21 // RUN: ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 10
22 // RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt11 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 11 "alt11/Foo.framework/Versions/A/Foo"
23 // RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt9 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 10
24 // RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt9:$RUN_DIR/alt11 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 11
25 // RUN: DYLD_VERSIONED_FRAMEWORK_PATH=$RUN_DIR/alt11:$RUN_DIR/alt12 ./env-DYLD_VERSIONED_FRAMEWORK_PATH.exe 12
26 // FIXME: Forcibly disable testing with closures since macOS does not use them and they are currently broken
27 // RUN: DYLD_USE_CLOSURES=0 ./env-DYLD_VERSIONED_FRAMEWORK_PATH-missing.exe 12
28
29 #include <stdio.h> // fprintf(), NULL
30 #include <stdlib.h> // exit(), EXIT_SUCCESS
31 #include <dlfcn.h>
32 #include <string.h>
33 #include <stdlib.h> // for atoi()
34
35 #include "test_support.h"
36
37 extern int foo();
38
39 int main(int argc, const char* argv[])
40 {
41 if ( argc > 2 ) {
42 bool found = false;
43 uint32_t count = _dyld_image_count();
44 for(uint32_t i=0; i < count; ++i) {
45 const char* name = _dyld_get_image_name(i);
46 if ( strstr(name, argv[2]) != NULL ) {
47 found = true;
48 }
49 }
50 if ( !found ) {
51 FAIL("Dylib has wrong path");
52 return EXIT_SUCCESS;
53 }
54 }
55
56 int expectedResult = atoi(argv[1]);
57 int actualResult = foo();
58 if ( actualResult != expectedResult ) {
59 FAIL("Using wrong dylib. foo() returned %d, expected %d", actualResult, expectedResult);
60 } else {
61 PASS("Success");
62 }
63 return 0;
64 }
65