Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: third_party/crazy_linker/crazy_linker/tests/test_dl_wrappers.cpp

Issue 23717023: Android: Add chrome-specific dynamic linker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address later issues. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // A crazy linker test to:
6 // - Load a library (libzoo.so) with the linker.
7 // - Find the address of the "Zoo" function in libzoo.so.
8 // - Call the Zoo() function, which will use dlopen() / dlsym() to
9 // find libbar.so (which depends on libfoo.so).
10 // - Close the library.
11
12 // This tests the dlopen/dlsym/dlclose wrappers provided by the crazy
13 // linker to loaded libraries.
14
15 #include <crazy_linker.h>
16
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 typedef bool (*FunctionPtr)();
22
23 static void Panic(const char* fmt, ...) {
24 va_list args;
25 fprintf(stderr, "PANIC: ");
26 va_start(args, fmt);
27 vfprintf(stderr, fmt, args);
28 va_end(args);
29 exit(1);
30 }
31
32 int main() {
33 crazy_context_t* context = crazy_context_create();
34 crazy_library_t* library;
35
36 // Load libzoo.so
37 if (!crazy_library_open(&library,
38 "libzoo.so",
39 context)) {
40 Panic("Could not open library: %s\n", crazy_context_get_error(context));
41 }
42
43 // Find the "Zoo" symbol.
44 FunctionPtr zoo_func;
45 if (!crazy_library_find_symbol(library,
46 "Zoo",
47 reinterpret_cast<void**>(&zoo_func))) {
48 Panic("Could not find 'Zoo' in libzoo.so\n");
49 }
50
51 // Call it.
52 bool ret = (*zoo_func)();
53 if (!ret)
54 Panic("'Zoo' function failed!");
55
56 // Close the library.
57 printf("Closing libzoo.so\n");
58 crazy_library_close(library);
59
60 crazy_context_destroy(context);
61
62 return 0;
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698