diff --git a/attach/base_attach_impl/base_attach_impl.hpp b/attach/base_attach_impl/base_attach_impl.hpp index ba55af57..2c78f359 100644 --- a/attach/base_attach_impl/base_attach_impl.hpp +++ b/attach/base_attach_impl/base_attach_impl.hpp @@ -5,6 +5,7 @@ #include #include #include "attach_private_data.hpp" +#include namespace bpftime { namespace attach @@ -71,7 +72,8 @@ inline uint64_t bpftime_set_retval(uint64_t value) } else { spdlog::error( "Called bpftime_set_retval, but no retval callback was set"); - assert(false); + throw std::invalid_argument( + "Called bpftime_set_retval, but no retval callback was set"); } return 0; } @@ -87,7 +89,8 @@ inline uint64_t bpftime_override_return(uint64_t ctx, uint64_t value) } else { spdlog::error( "Called bpftime_override_return, but no retval callback was set"); - assert(false); + throw std::invalid_argument( + "Called bpftime_override_return, but no retval callback was set"); } return 0; } diff --git a/attach/frida_uprobe_attach_impl/CMakeLists.txt b/attach/frida_uprobe_attach_impl/CMakeLists.txt index 245905fb..4e024b63 100644 --- a/attach/frida_uprobe_attach_impl/CMakeLists.txt +++ b/attach/frida_uprobe_attach_impl/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES test/test_replace_attach_with_override.cpp test/test_attach_with_unified_interface.cpp test/test_attach_private_data_parsing.cpp + test/test_base_attach_impl.cpp ) option(TEST_LCOV "option for lcov" OFF) add_executable(bpftime_frida_uprobe_attach_tests ${TEST_SOURCES}) diff --git a/attach/frida_uprobe_attach_impl/test/test_base_attach_impl.cpp b/attach/frida_uprobe_attach_impl/test/test_base_attach_impl.cpp new file mode 100644 index 00000000..7a98ce36 --- /dev/null +++ b/attach/frida_uprobe_attach_impl/test/test_base_attach_impl.cpp @@ -0,0 +1,32 @@ +#include "catch2/catch_test_macros.hpp" +#include +#include +#include + +using namespace bpftime::attach; +using namespace bpftime; + +TEST_CASE("Test bpftime_set_retval") +{ + curr_thread_override_return_callback.reset(); + REQUIRE_THROWS(bpftime_set_retval(0)); + bool called = false; + curr_thread_override_return_callback = [&](uint64_t, uint64_t) { + called = true; + }; + bpftime_set_retval(0); + REQUIRE(called); +} + +TEST_CASE("Test bpftime_override_return") +{ + curr_thread_override_return_callback.reset(); + REQUIRE_THROWS(bpftime_override_return(0, 0)); + + bool called = false; + curr_thread_override_return_callback = [&](uint64_t, uint64_t) { + called = true; + }; + bpftime_override_return(0, 0); + REQUIRE(called); +}