Skip to content

Commit

Permalink
increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kenlig committed Oct 19, 2024
1 parent 8a3f70a commit e0603f6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions attach/base_attach_impl/base_attach_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <functional>
#include <optional>
#include "attach_private_data.hpp"
#include <stdexcept>
namespace bpftime
{
namespace attach
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions attach/frida_uprobe_attach_impl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
32 changes: 32 additions & 0 deletions attach/frida_uprobe_attach_impl/test/test_base_attach_impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "catch2/catch_test_macros.hpp"
#include <base_attach_impl.hpp>
#include <catch2/catch_test_macros.hpp>
#include <cstdint>

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);
}

0 comments on commit e0603f6

Please sign in to comment.