]>
git.saurik.com Git - apple/objc4.git/blob - test/libraryPath.c
6 // We use DYLD_LIBRARY_PATH to run the tests against a particular copy of
7 // libobjc. If this fails somehow (path is wrong, codesigning prevents loading,
8 // etc.) then the typical result is a silent failure and we end up testing
9 // /usr/lib/libobjc.A.dylib instead. This test detects when DYLD_LIBRARY_PATH is
10 // set but libobjc isn't loaded from it.
11 int main(int argc __unused
, char **argv
) {
12 char *containingDirectory
= realpath(dirname(argv
[0]), NULL
);
13 testprintf("containingDirectory is %s\n", containingDirectory
);
15 char *dyldLibraryPath
= getenv("DYLD_LIBRARY_PATH");
16 testprintf("DYLD_LIBRARY_PATH is %s\n", dyldLibraryPath
);
18 if (dyldLibraryPath
!= NULL
&& strlen(dyldLibraryPath
) > 0) {
20 int foundNonMatch
= 0;
22 dyldLibraryPath
= strdup(dyldLibraryPath
);
25 int success
= dladdr((void *)objc_msgSend
, &info
);
28 testprintf("libobjc is located at %s\n", info
.dli_fname
);
30 char *cursor
= dyldLibraryPath
;
32 while ((path
= strsep(&cursor
, ":"))) {
33 char *resolved
= realpath(path
, NULL
);
34 testprintf("Resolved %s to %s\n", path
, resolved
);
35 if (strcmp(resolved
, containingDirectory
) == 0) {
36 testprintf("This is equal to our containing directory, ignoring.\n");
39 testprintf("Comparing %s and %s\n", resolved
, info
.dli_fname
);
40 int comparison
= strncmp(resolved
, info
.dli_fname
, strlen(resolved
));
42 if (comparison
== 0) {
43 testprintf("Found a match!\n");
51 testprintf("Finished searching, foundMatch=%d foundNonMatch=%d\n", foundMatch
, foundNonMatch
);
52 testassert(foundMatch
|| !foundNonMatch
);