]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/env-DYLD_IMAGE_SUFFIX.dtest/main.c
dyld-851.27.tar.gz
[apple/dyld.git] / testing / test-cases / env-DYLD_IMAGE_SUFFIX.dtest / main.c
1
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
10
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
19
20
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <dlfcn.h>
27
28 #include "test_support.h"
29
30 extern int foo();
31 extern int bar();
32
33 typedef int (*IntProc)();
34
35 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
36 const char* suffix = getenv("DYLD_IMAGE_SUFFIX");
37 if ( suffix == NULL )
38 suffix = "";
39
40 const int expectedFoo = (strstr(suffix, "_other") != NULL) ? 42 : 1;
41 const int expectedBar = (strstr(suffix, "_alt") != NULL) ? 42 : 1;;
42
43 #ifdef RUN_DIR
44 void* fooHandle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_LAZY);
45 if ( fooHandle == NULL ) {
46 FAIL("libfoo.dylib could not be loaded, %s", dlerror());
47 }
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());
51 }
52 IntProc fooProc = (IntProc)dlsym(fooHandle, "foo");
53 if ( fooProc == NULL ) {
54 FAIL("symbol 'foo' not found %s", dlerror());
55 }
56 IntProc barProc = (IntProc)dlsym(barHandle, "bar");
57 if ( barProc == NULL ) {
58 FAIL("symbol 'bar' not found %s", dlerror());
59 }
60 int fooValue = (*fooProc)();
61 int barValue = (*barProc)();
62 #else
63 int fooValue = foo();
64 int barValue = bar();
65 #endif
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);
70 else
71 PASS("Success");
72 }
73