]> git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/NSCreateObjectFileImageFromFile-stress.dtest/main.cpp
dyld-750.5.tar.gz
[apple/dyld.git] / testing / test-cases / NSCreateObjectFileImageFromFile-stress.dtest / main.cpp
1 // BUILD_ONLY: MacOSX
2
3 // BUILD: $CXX main.cpp -o $BUILD_DIR/NSCreateObjectFileImageFromFile-stress.exe -Wno-deprecated-declarations
4 // BUILD: $CC foo.c -o $BUILD_DIR/foo.bundle -bundle
5
6 // RUN: ./NSCreateObjectFileImageFromFile-stress.exe $RUN_DIR/foo.bundle
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <dlfcn.h>
12 #include <mach-o/dyld.h>
13 #include <vector>
14
15 #include "test_support.h"
16
17 int main(int argc, const char* argv[], const char* envp[], const char* apple[]) {
18 const char* path = argv[1];
19
20 std::vector<NSObjectFileImage> ofis;
21 for (unsigned i = 0; i != 32; ++i) {
22 NSObjectFileImage ofi;
23 if ( NSCreateObjectFileImageFromFile(path, &ofi) != NSObjectFileImageSuccess ) {
24 FAIL("NSCreateObjectFileImageFromFile failed");
25 }
26 ofis.push_back(ofi);
27 }
28
29 for(unsigned i = 0; i != 32; ++i) {
30 NSObjectFileImage ofi = ofis[i];
31 NSModule mod = NSLinkModule(ofi, path, NSLINKMODULE_OPTION_NONE);
32 if ( mod == NULL ) {
33 FAIL("NSLinkModule failed");
34 }
35
36 NSSymbol sym = NSLookupSymbolInModule(mod, "_fooInBundle");
37 if ( sym == NULL ) {
38 FAIL("NSLookupSymbolInModule failed");
39 }
40
41 void* func = NSAddressOfSymbol(sym);
42 if ( func == NULL ) {
43 FAIL("NSAddressOfSymbol failed");
44 }
45
46 Dl_info info;
47 if ( dladdr(func, &info) == 0 ) {
48 FAIL("dladdr(&p, xx) fail");
49 }
50 LOG("_fooInBundle found in %s", info.dli_fname);
51
52 if ( !NSUnLinkModule(mod, NSUNLINKMODULE_OPTION_NONE) ) {
53 FAIL("NSUnLinkModule failed");
54 }
55
56 if ( dladdr(func, &info) != 0 ) {
57 FAIL("dladdr(&p, xx) found but should not have");
58 }
59 }
60
61 for (unsigned i = 0; i != 32; ++i) {
62 NSObjectFileImage ofi = ofis[i];
63 if ( !NSDestroyObjectFileImage(ofi) ) {
64 FAIL("NSDestroyObjectFileImage failed");
65 }
66 }
67
68 PASS("Success");
69 }
70