mirror of
https://github.com/plasma-umass/coz.git
synced 2024-09-11 04:55:25 +03:00
Add basic googletest
* Basic test case, load toy.cpp and check line 17 is found
This commit is contained in:
parent
e0c48e801d
commit
7c2b272861
@ -41,6 +41,7 @@ if(INSTALL_COZ)
|
||||
endif()
|
||||
|
||||
add_subdirectory(libcoz)
|
||||
add_subdirectory(test)
|
||||
|
||||
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
|
||||
if(BUILD_BENCHMARKS)
|
||||
|
@ -2,7 +2,6 @@ set(sources
|
||||
${PROJECT_SOURCE_DIR}/include/coz.h
|
||||
inspect.cpp
|
||||
inspect.h
|
||||
libcoz.cpp
|
||||
perf.cpp
|
||||
perf.h
|
||||
profiler.cpp
|
||||
@ -14,7 +13,8 @@ set(sources
|
||||
util.h
|
||||
)
|
||||
|
||||
add_library(coz MODULE ${sources} ${public_headers})
|
||||
add_library(coz MODULE libcoz.cpp ${sources} ${public_headers})
|
||||
add_library(coz_nopre SHARED ${sources} ${public_headers})
|
||||
if(CONAN_PACKAGE_VERSION)
|
||||
set_target_properties(coz PROPERTIES VERSION ${CONAN_PACKAGE_VERSION})
|
||||
endif()
|
||||
@ -23,6 +23,7 @@ target_include_directories(coz
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
target_link_libraries(coz PRIVATE ${CMAKE_DL_LIBS} rt Threads::Threads libelfin::libelfin)
|
||||
target_link_libraries(coz_nopre PRIVATE ${CMAKE_DL_LIBS} rt Threads::Threads libelfin::libelfin)
|
||||
|
||||
add_library(coz-instrumentation INTERFACE)
|
||||
target_include_directories(coz-instrumentation
|
||||
@ -39,3 +40,4 @@ if(INSTALL_COZ)
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
endif()
|
||||
|
||||
|
@ -145,6 +145,10 @@ public:
|
||||
|
||||
static memory_map& get_instance();
|
||||
|
||||
/// Find a debug version of provided file and add all of its in-scope lines to the map
|
||||
bool process_file(const std::string& name, uintptr_t load_address,
|
||||
const std::unordered_set<std::string>& source_scope);
|
||||
|
||||
private:
|
||||
memory_map() : _files(std::map<std::string, std::shared_ptr<file>>()),
|
||||
_ranges(std::map<interval, std::shared_ptr<line>>()) {}
|
||||
@ -164,10 +168,6 @@ private:
|
||||
|
||||
void add_range(std::string filename, size_t line_no, interval range);
|
||||
|
||||
/// Find a debug version of provided file and add all of its in-scope lines to the map
|
||||
bool process_file(const std::string& name, uintptr_t load_address,
|
||||
const std::unordered_set<std::string>& source_scope);
|
||||
|
||||
/// Add entries for all inlined calls
|
||||
void process_inlines(const dwarf::die& d,
|
||||
const dwarf::line_table& table,
|
||||
|
33
test/CMakeLists.txt
Normal file
33
test/CMakeLists.txt
Normal file
@ -0,0 +1,33 @@
|
||||
cmake_minimum_required(VERSION 3.13.0)
|
||||
project(coz VERSION 0.2.2 LANGUAGES C CXX)
|
||||
|
||||
enable_testing()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CONAN_CMAKE_SILENT_OUTPUT ON)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # release-1.12.1
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
add_executable(
|
||||
load_basic_test
|
||||
load_basic_test.cpp
|
||||
)
|
||||
target_link_libraries(
|
||||
load_basic_test
|
||||
PRIVATE
|
||||
GTest::gtest_main
|
||||
#libcoz.so
|
||||
coz_nopre
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(load_basic_test)
|
18
test/load_basic_test.cpp
Normal file
18
test/load_basic_test.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "../libcoz/inspect.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
TEST(BasicTestCases, TestMapForPrebuiltToy) {
|
||||
auto toy_file = "../benchmarks/toy/toy";
|
||||
unordered_set<string> source_scope{"%/toy.cpp"};
|
||||
auto& mm = memory_map::get_instance();
|
||||
mm.process_file(toy_file, 0, source_scope);
|
||||
auto x = mm.find_line("toy.cpp:17");
|
||||
EXPECT_EQ(x->get_line(), 17);
|
||||
}
|
Loading…
Reference in New Issue
Block a user