]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_IMAGE_SUFFIX.dtest/main.c
49101dece3c1708044274d05397f80786ddf142b
2 // BUILD: mkdir -p $BUILD_DIR/Bar.framework
3 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=1
4 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo_other.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=42
5 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/Bar.framework/Bar -install_name $RUN_DIR/Bar.framework/Bar -DVALUE=1
6 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/Bar.framework/Bar_alt -install_name $RUN_DIR/Bar.framework/Bar -DVALUE=42
7 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_IMAGE_SUFFIX.exe $BUILD_DIR/libfoo.dylib $BUILD_DIR/Bar.framework/Bar
8 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_IMAGE_SUFFIX.exe
9 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_IMAGE_SUFFIX-dynamic.exe -DRUN_DIR="$RUN_DIR"
10 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_IMAGE_SUFFIX-dynamic.exe
12 // RUN: ./env-DYLD_IMAGE_SUFFIX.exe
13 // RUN: DYLD_IMAGE_SUFFIX=_other ./env-DYLD_IMAGE_SUFFIX.exe
14 // RUN: DYLD_IMAGE_SUFFIX=_alt ./env-DYLD_IMAGE_SUFFIX.exe
15 // RUN: DYLD_IMAGE_SUFFIX=_alt:_other ./env-DYLD_IMAGE_SUFFIX.exe
16 // RUN: ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
17 // RUN: DYLD_IMAGE_SUFFIX=_other ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
18 // RUN: DYLD_IMAGE_SUFFIX=_alt ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
19 // RUN: DYLD_IMAGE_SUFFIX=_alt:_other ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
32 typedef int (*IntProc
)();
36 const char* suffix
= getenv("DYLD_IMAGE_SUFFIX");
39 printf("[BEGIN] env-DYLD_IMAGE_SUFFIX-%s\n", suffix
);
41 const int expectedFoo
= (strstr(suffix
, "_other") != NULL
) ? 42 : 1;
42 const int expectedBar
= (strstr(suffix
, "_alt") != NULL
) ? 42 : 1;;
45 void* fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
46 if ( fooHandle
== NULL
) {
47 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, libfoo.dylib could not be loaded, %s\n", suffix
, dlerror());
50 void* barHandle
= dlopen(RUN_DIR
"/Bar.framework/Bar", RTLD_LAZY
);
51 if ( barHandle
== NULL
) {
52 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, Bar.framework/Bar could not be loaded, %s\n", suffix
, dlerror());
55 IntProc fooProc
= (IntProc
)dlsym(fooHandle
, "foo");
56 if ( fooProc
== NULL
) {
57 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, symbol 'foo' not found %s\n", suffix
, dlerror());
60 IntProc barProc
= (IntProc
)dlsym(barHandle
, "bar");
61 if ( barProc
== NULL
) {
62 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, symbol 'bar' not found %s\n", suffix
, dlerror());
65 int fooValue
= (*fooProc
)();
66 int barValue
= (*barProc
)();
71 if ( fooValue
!= expectedFoo
)
72 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, foo()=%d expected=%d\n", suffix
, fooValue
, expectedFoo
);
73 else if ( barValue
!= expectedBar
)
74 printf("[FAIL] env-DYLD_IMAGE_SUFFIX-%s, bar()=%d expected=%d\n", suffix
, barValue
, expectedBar
);
76 printf("[PASS] env-DYLD_IMAGE_SUFFIX-%s\n", suffix
);