]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_IMAGE_SUFFIX.dtest/main.c
2 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=1
3 // BUILD: $CC foo.c -dynamiclib -o $BUILD_DIR/libfoo_other.dylib -install_name $RUN_DIR/libfoo.dylib -DVALUE=42
4 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/Bar.framework/Bar -install_name $RUN_DIR/Bar.framework/Bar -DVALUE=1
5 // BUILD: $CC bar.c -dynamiclib -o $BUILD_DIR/Bar.framework/Bar_alt -install_name $RUN_DIR/Bar.framework/Bar -DVALUE=42
6 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_IMAGE_SUFFIX.exe $BUILD_DIR/libfoo.dylib $BUILD_DIR/Bar.framework/Bar
7 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_IMAGE_SUFFIX.exe
8 // BUILD: $CC main.c -o $BUILD_DIR/env-DYLD_IMAGE_SUFFIX-dynamic.exe -DRUN_DIR="$RUN_DIR"
9 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/env-DYLD_IMAGE_SUFFIX-dynamic.exe
11 // RUN: ./env-DYLD_IMAGE_SUFFIX.exe
12 // RUN: DYLD_IMAGE_SUFFIX=_other ./env-DYLD_IMAGE_SUFFIX.exe
13 // RUN: DYLD_IMAGE_SUFFIX=_alt ./env-DYLD_IMAGE_SUFFIX.exe
14 // RUN: DYLD_IMAGE_SUFFIX=_alt:_other ./env-DYLD_IMAGE_SUFFIX.exe
15 // RUN: ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
16 // RUN: DYLD_IMAGE_SUFFIX=_other ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
17 // RUN: DYLD_IMAGE_SUFFIX=_alt ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
18 // RUN: DYLD_IMAGE_SUFFIX=_alt:_other ./env-DYLD_IMAGE_SUFFIX-dynamic.exe
28 #include "test_support.h"
33 typedef int (*IntProc
)();
35 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
36 const char* suffix
= getenv("DYLD_IMAGE_SUFFIX");
40 const int expectedFoo
= (strstr(suffix
, "_other") != NULL
) ? 42 : 1;
41 const int expectedBar
= (strstr(suffix
, "_alt") != NULL
) ? 42 : 1;;
44 void* fooHandle
= dlopen(RUN_DIR
"/libfoo.dylib", RTLD_LAZY
);
45 if ( fooHandle
== NULL
) {
46 FAIL("libfoo.dylib could not be loaded, %s", dlerror());
48 void* barHandle
= dlopen(RUN_DIR
"/Bar.framework/Bar", RTLD_LAZY
);
49 if ( barHandle
== NULL
) {
50 FAIL("Bar.framework/Bar could not be loaded, %s", dlerror());
52 IntProc fooProc
= (IntProc
)dlsym(fooHandle
, "foo");
53 if ( fooProc
== NULL
) {
54 FAIL("symbol 'foo' not found %s", dlerror());
56 IntProc barProc
= (IntProc
)dlsym(barHandle
, "bar");
57 if ( barProc
== NULL
) {
58 FAIL("symbol 'bar' not found %s", dlerror());
60 int fooValue
= (*fooProc
)();
61 int barValue
= (*barProc
)();
66 if ( fooValue
!= expectedFoo
)
67 FAIL("foo()=%d expected=%d", fooValue
, expectedFoo
);
68 else if ( barValue
!= expectedBar
)
69 FAIL("bar()=%d expected=%d", barValue
, expectedBar
);