Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add basic googletest #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ if(INSTALL_COZ)
endif()

add_subdirectory(libcoz)
add_subdirectory(test)

option(BUILD_BENCHMARKS "Build benchmarks" OFF)
if(BUILD_BENCHMARKS)
Expand Down
6 changes: 4 additions & 2 deletions libcoz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set(sources
${PROJECT_SOURCE_DIR}/include/coz.h
inspect.cpp
inspect.h
libcoz.cpp
perf.cpp
perf.h
profiler.cpp
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -39,3 +40,4 @@ if(INSTALL_COZ)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

8 changes: 4 additions & 4 deletions libcoz/inspect.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class memory_map {

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>>()) {}
Expand All @@ -164,10 +168,6 @@ class memory_map {

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,
Expand Down
33 changes: 33 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions test/load_basic_test.cpp
Original file line number Diff line number Diff line change
@@ -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);
}