dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / _dyld_launch_mode.dtest / main.c
1
2 // BUILD: $CC main.c -o $BUILD_DIR/dyld_launch_mode.exe
3
4 // RUN: ./dyld_launch_mode.exe
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <mach-o/dyld_priv.h>
10 #include <dlfcn.h>
11
12 #include "test_support.h"
13
14 int main(int argc, const char* argv[], const char* envp[], const char* apple[])
15 {
16 const char* modeStr = getenv("DYLD_USE_CLOSURES");
17 if ( modeStr == NULL ) {
18 FAIL("dyld_launch_mode: DYLD_USE_CLOSURES env var not set");
19 }
20
21 uint32_t expectedFlags;
22 uint32_t launchFlags = _dyld_launch_mode();
23 fprintf(stderr, "launchFlags=0x%08x\n", launchFlags);
24
25 if ( strcmp(modeStr, "0") == 0 ) {
26 expectedFlags = 0;
27 }
28 else if ( strcmp(modeStr, "1") == 0 ) {
29 expectedFlags = DYLD_LAUNCH_MODE_USING_CLOSURE | DYLD_LAUNCH_MODE_BUILT_CLOSURE_AT_LAUNCH;
30 }
31 else if ( strcmp(modeStr, "2") == 0 ) {
32 expectedFlags = DYLD_LAUNCH_MODE_USING_CLOSURE | DYLD_LAUNCH_MODE_BUILT_CLOSURE_AT_LAUNCH | DYLD_LAUNCH_MODE_MINIMAL_CLOSURE;
33 }
34 else {
35 FAIL("dyld_launch_mode: DYLD_USE_CLOSURES value unknown");
36 }
37
38
39 if ( launchFlags == expectedFlags )
40 PASS("dyld_launch_mode");
41 else
42 FAIL("dyld_launch_mode: expected flags to be 0x%08X but were 0x%08X", expectedFlags, launchFlags);
43
44 return 0;
45 }
46