summaryrefslogtreecommitdiff
path: root/runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc')
-rw-r--r--runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc b/runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc
new file mode 100644
index 000000000..d615cc928
--- /dev/null
+++ b/runtime/contrib/heap_trace/tests/src/symbol_searcher_test.cc
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "gtest/gtest.h"
+#include "test_sample1.h"
+#include "test_sample2.h"
+#include "test_sample4.h"
+
+#include "symbol_searcher.h"
+
+#include <dlfcn.h>
+#include <linux/limits.h>
+#include <unistd.h>
+
+#include <cstdlib>
+
+#include <experimental/filesystem>
+
+namespace fs = std::experimental::filesystem;
+
+fs::path exePath()
+{
+ char result[PATH_MAX] = {0};
+ ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
+ return fs::path(result).parent_path();
+}
+
+namespace backstage
+{
+
+struct SymbolSearcher : public ::testing::Test
+{
+};
+
+TEST_F(SymbolSearcher, should_find_symbol_in_linked_library)
+{
+ ASSERT_TRUE((void *)funcDefinedOnlyInTestSample4 == findSymbol("funcDefinedOnlyInTestSample4"));
+}
+
+TEST_F(SymbolSearcher, should_find_symbol_in_library_which_have_been_loaded_in_runtime)
+{
+ fs::path pathToTestLib = exePath() / "libtest_sample2.so";
+ void *handle = dlopen(pathToTestLib.c_str(), RTLD_NOW);
+
+ ASSERT_TRUE(handle);
+ ASSERT_TRUE(dlsym(handle, "funcDefinedOnlyInTestSample2") ==
+ findSymbol("funcDefinedOnlyInTestSample2"));
+ dlclose(handle);
+}
+
+TEST_F(SymbolSearcher,
+ should_ignore_symbols_found_in_current_translation_unit_if_there_is_another_alternative)
+{
+ fs::path pathToTestSample2 = exePath() / "libtest_sample2.so";
+ void *test_sample2_handle = dlopen(pathToTestSample2.c_str(), RTLD_NOW);
+ void *func_addr_in_test_sample2 =
+ dlsym(test_sample2_handle, "funcWhichCallFuncDefinedInTestSample3");
+
+ ASSERT_TRUE(test_sample2_handle);
+ ASSERT_TRUE((void *)funcDefinedInTestSample3_ButWrappedInTestSample1 !=
+ reinterpret_cast<void *(*)()>(func_addr_in_test_sample2)());
+
+ dlclose(test_sample2_handle);
+}
+
+} // namespace backstage