1
1
#ifdef __linux__
2
2
3
+ #include < gmock/gmock.h>
3
4
#include < gtest/gtest.h>
4
5
5
6
#include " codeCache.h"
7
+ #include " libraries.h"
6
8
#include " symbols_linux.h"
7
9
#include " log.h"
8
10
@@ -27,7 +29,7 @@ TEST(Elf, readSymTable) {
27
29
exit (1 );
28
30
}
29
31
char path[PATH_MAX];
30
- snprintf (path, sizeof (path) - 1 , " %s/../build/test/resources/unresolved-functions/main" , cwd);
32
+ snprintf (path, sizeof (path) - 1 , " %s/../build/test/resources/native-libs/ unresolved-functions/main" , cwd);
31
33
if (access (path, R_OK) != 0 ) {
32
34
fprintf (stdout, " Missing test resource %s. Skipping the test\n " , path);
33
35
exit (0 );
@@ -36,6 +38,57 @@ TEST(Elf, readSymTable) {
36
38
ElfParser::parseFile (&cc, nullptr , path, false );
37
39
}
38
40
41
+ class ElfReladyn : public ::testing::Test {
42
+ protected:
43
+ Libraries* _libs = nullptr ;
44
+ CodeCache* _libreladyn = nullptr ;
45
+
46
+ // This method is called before each test.
47
+ void SetUp () override {
48
+ char cwd[PATH_MAX - 64 ];
49
+ if (getcwd (cwd, sizeof (cwd)) == nullptr ) {
50
+ exit (1 );
51
+ }
52
+ char path[PATH_MAX];
53
+ snprintf (path, sizeof (path) - 1 , " %s/../build/test/resources/native-libs/reladyn-lib/libreladyn.so" , cwd);
54
+ if (access (path, R_OK) != 0 ) {
55
+ fprintf (stdout, " Missing test resource %s. Skipping the test\n " , path);
56
+ exit (0 );
57
+ }
58
+ void * handle = dlopen (path, RTLD_NOW);
59
+ ASSERT_THAT (handle, ::testing::NotNull ());
60
+
61
+ _libs = Libraries::instance ();
62
+ _libs->updateSymbols (false );
63
+ _libreladyn = _libs->findLibraryByName (" libreladyn" );
64
+ ASSERT_THAT (_libreladyn, ::testing::NotNull ());
65
+ }
66
+
67
+ // This method is called after each test.
68
+ void TearDown () override {
69
+ // Clean up resources.
70
+ }
71
+
72
+ CodeCache* libreladyn () {
73
+ return _libreladyn;
74
+ }
75
+ };
76
+
77
+ TEST_F (ElfReladyn, resolveFromRela_plt) {
78
+ void * sym = libreladyn ()->findImport (im_pthread_create);
79
+ ASSERT_THAT (sym, ::testing::NotNull ());
80
+ }
81
+
82
+ TEST_F (ElfReladyn, resolveFromRela_dyn_R_GLOB_DAT) {
83
+ void * sym = libreladyn ()->findImport (im_pthread_setspecific);
84
+ ASSERT_THAT (sym, ::testing::NotNull ());
85
+ }
86
+
87
+ TEST_F (ElfReladyn, resolveFromRela_dyn_R_ABS64) {
88
+ void * sym = libreladyn ()->findImport (im_pthread_exit);
89
+ ASSERT_THAT (sym, ::testing::NotNull ());
90
+ }
91
+
39
92
class ElfTest : public ::testing::Test {
40
93
protected:
41
94
void SetUp () override {
@@ -247,7 +300,7 @@ TEST_P(ElfTestParam, invalidElfSmallMappingAfterUnmap) {
247
300
248
301
// Construct the path to the test resource
249
302
char path[PATH_MAX];
250
- snprintf (path, sizeof (path) - 1 , " %s/../build/test/resources/small-lib/libsmall-lib.so" , cwd);
303
+ snprintf (path, sizeof (path) - 1 , " %s/../build/test/resources/native-libs/ small-lib/libsmall-lib.so" , cwd);
251
304
if (access (path, R_OK) != 0 ) {
252
305
fprintf (stdout, " Missing test resource %s. Skipping the test\n " , path);
253
306
exit (1 );
0 commit comments