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