Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [cmake] add asan to public options of commonlib * [ctf::remote] host can be passed as string * [pwn::system] update pidof signature to take a copy string view (not a reference) * [pwn::win::process] completely restored all features and tests * [ci/build] disable building docs * fixed x86 builds * added basic perf test for commonlib
- Loading branch information
Showing
19 changed files
with
420 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
enable_testing() | ||
set(TEST_EXECUTABLE_NAME tests_pwn_${PROJECT_NAME}) | ||
set(TEST_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
list(APPEND SOURCE_FILES | ||
list(APPEND TEST_SOURCE_FILES | ||
|
||
${TEST_DIR}/main.cpp | ||
${TEST_DIR}/pwn_common.cpp | ||
# Test cases | ||
${TEST_DIR}/tests_pwn_common.cpp | ||
|
||
# Performance tests | ||
${TEST_DIR}/perf_pwn_common.cpp | ||
) | ||
|
||
add_executable(${TEST_EXECUTABLE_NAME} ${SOURCE_FILES}) | ||
add_executable(PWN::Tests::${PROJECT_NAME} ALIAS ${TEST_EXECUTABLE_NAME}) | ||
add_dependencies(${TEST_EXECUTABLE_NAME} PWN::Deps::Catch2 PWN::${PROJECT_NAME}) | ||
target_link_libraries(${TEST_EXECUTABLE_NAME} PUBLIC PWN::Deps::Catch2 PWN::${PROJECT_NAME}) | ||
foreach(SOURCE_FILE ${TEST_SOURCE_FILES}) | ||
cmake_path(GET SOURCE_FILE STEM TEST_EXECUTABLE_NAME) | ||
add_executable(${TEST_EXECUTABLE_NAME} ${SOURCE_FILE}) | ||
add_dependencies(${TEST_EXECUTABLE_NAME} PWN::Deps::Catch2 PWN::${PROJECT_NAME}) | ||
target_link_libraries(${TEST_EXECUTABLE_NAME} PUBLIC PWN::Deps::Catch2 PWN::${PROJECT_NAME}) | ||
|
||
if(WIN32) | ||
target_link_options(${TEST_EXECUTABLE_NAME} PUBLIC /SUBSYSTEM:Console) | ||
endif(WIN32) | ||
if(WIN32) | ||
target_link_options(${TEST_EXECUTABLE_NAME} PUBLIC /SUBSYSTEM:Console) | ||
endif(WIN32) | ||
|
||
add_test(NAME ${TEST_EXECUTABLE_NAME} COMMAND $<TARGET_FILE:${TEST_EXECUTABLE_NAME}>) | ||
set_tests_properties(${TEST_EXECUTABLE_NAME} PROPERTIES LABELS Common LABELS Version) | ||
install(FILES $<TARGET_FILE:${TEST_EXECUTABLE_NAME}> DESTINATION Tests) | ||
add_test(NAME ${TEST_EXECUTABLE_NAME} COMMAND $<TARGET_FILE:${TEST_EXECUTABLE_NAME}>) | ||
set_tests_properties(${TEST_EXECUTABLE_NAME} PROPERTIES LABELS Common LABELS Version) | ||
install(FILES $<TARGET_FILE:${TEST_EXECUTABLE_NAME}> DESTINATION Tests) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#define CATCH_CONFIG_ENABLE_BENCHMARKING | ||
|
||
#include <catch.hpp> | ||
|
||
#include "Common.hpp" | ||
|
||
Result<int> | ||
TestFunc11(uint32_t i) | ||
{ | ||
if ( i == 42 ) | ||
{ | ||
return Ok(1); | ||
} | ||
|
||
return Err(ErrorCode::RuntimeError); | ||
} | ||
|
||
int | ||
TestFunc12(uint32_t i) | ||
{ | ||
if ( i == 42 ) | ||
{ | ||
return 1; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
|
||
Result<std::vector<int>> | ||
TestFunc21(uint32_t i) | ||
{ | ||
if ( i == 42 ) | ||
{ | ||
return Ok(std::move(std::vector<int> {1, 2, 3})); | ||
} | ||
|
||
return Err(ErrorCode::RuntimeError); | ||
} | ||
|
||
std::vector<int> | ||
TestFunc22(uint32_t i) | ||
{ | ||
if ( i == 42 ) | ||
{ | ||
return std::vector<int> {1, 2, 3}; | ||
} | ||
|
||
return std::vector<int> {}; | ||
} | ||
|
||
|
||
TEST_CASE("Simple perf checks", "Benchmarks::Error") | ||
{ | ||
BENCHMARK("[managed] basic return type - success") | ||
{ | ||
return std::move(TestFunc11(42)); | ||
}; | ||
|
||
BENCHMARK("[unmanaged] basic return type - success") | ||
{ | ||
return TestFunc12(42); // prevent optimization | ||
}; | ||
|
||
BENCHMARK("[managed] basic return type - failure") | ||
{ | ||
return std::move(TestFunc11(1)); | ||
}; | ||
|
||
BENCHMARK("[unmanaged] basic return type - failure") | ||
{ | ||
return TestFunc12(1); | ||
}; | ||
} |
2 changes: 2 additions & 0 deletions
2
Modules/Common/Tests/pwn_common.cpp → Modules/Common/Tests/tests_pwn_common.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#define CATCH_CONFIG_MAIN | ||
|
||
#include <catch.hpp> | ||
|
||
#include "Common.hpp" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.