Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Increase general coverage #358

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "attach_private_data.hpp"
#include "base_attach_impl.hpp"
#include "catch2/catch_test_macros.hpp"
#include "frida_attach_private_data.hpp"
Expand All @@ -7,7 +8,6 @@
#include <frida_uprobe.hpp>
#include <memory>
#include <string>

using namespace bpftime::attach;

extern "C" uint64_t
Expand All @@ -16,6 +16,12 @@ __bpftime_test_attach_with_unified_interface_func(uint64_t a, uint64_t b)
return a + b;
}

TEST_CASE("Test base attach private data") {
attach_private_data data;
REQUIRE_THROWS(data.initialize_from_string("test"));

}

TEST_CASE("Test with unified interface")
{
std::unique_ptr<base_attach_impl> man =
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/bpf_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ uint64_t bpf_get_current_uid_gid(uint64_t, uint64_t, uint64_t, uint64_t,
uint64_t)
{
static int gid = getgid();
return (((uint64_t)gid) << 32) | gid;
static int uid = getuid();
return (((uint64_t)gid) << 32) | uid;
}

uint64_t bpftime_ktime_get_ns(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
const void *value,
uint64_t flags)
{
SPDLOG_DEBUG("Updating percpu array shared");

Check warning on line 51 in runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/src/bpf_map/shared/percpu_array_map_kernel_user.cpp#L51

Added line #L51 was not covered by tests
return bpf_map_update_elem(kernel_map_fd, key, value, flags);
}

Expand Down
9 changes: 7 additions & 2 deletions runtime/src/bpftime_shm_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ bool bpftime_shm::is_map_fd(int fd) const
}
bool bpftime_shm::is_ringbuf_map_fd(int fd) const
{
if (!is_map_fd(fd))
if (!is_map_fd(fd)) {
SPDLOG_ERROR("Expected fd {} to be a map fd", fd);
return false;
}
auto &map_impl = std::get<bpf_map_handler>(manager->get_handler(fd));
return map_impl.type == bpf_map_type::BPF_MAP_TYPE_RINGBUF;
}
Expand Down Expand Up @@ -703,7 +705,10 @@ const handler_manager *bpftime_shm::get_manager() const
{
return manager;
}

handler_manager &bpftime_shm::get_manager_mut()
{
return *manager;
}
bool bpftime_shm::is_perf_event_handler_fd(int fd) const
{
if (manager == nullptr || fd < 0 ||
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/bpftime_shm_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class bpftime_shm {
#endif

public:
boost::interprocess::managed_shared_memory &get_segment_manager()
{
return segment;
}
// Get the configuration object
const struct agent_config &get_agent_config();
// Set the configuration object
Expand Down Expand Up @@ -176,7 +180,7 @@ class bpftime_shm {
bpftime_shm(const char *shm_name, shm_open_type type);

const handler_manager *get_manager() const;

handler_manager &get_manager_mut();
std::optional<void *>
get_software_perf_event_raw_buffer(int fd, size_t buffer_sz) const;

Expand Down
3 changes: 3 additions & 0 deletions runtime/src/handler/map_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,9 @@ void bpf_map_handler::map_free(managed_shared_memory &memory)
memory.destroy<prog_array_map_impl>(container_name.c_str());
break;
#endif
case bpf_map_type::BPF_MAP_TYPE_ARRAY_OF_MAPS:
memory.destroy<array_map_of_maps_impl>(container_name.c_str());
break;
default:
auto func_ptr = global_map_ops_table[(int)type].map_free;
if (func_ptr) {
Expand Down
5 changes: 4 additions & 1 deletion runtime/unit-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ set(TEST_SOURCES
maps/test_external_map_ops.cpp
maps/test_bpftime_hash_map.cpp
maps/kernel_unit_tests.cpp

maps/test_map_handler.cpp

test_bpftime_shm_json.cpp
attach_with_ebpf/test_attach_filter_with_ebpf.cpp
attach_with_ebpf/test_attach_uprobe_with_ebpf.cpp
Expand All @@ -30,6 +31,8 @@ set(TEST_SOURCES
attach_with_ebpf/test_attach_replace.cpp

tailcall/test_user_to_kernel_tailcall.cpp

runtime/test_helpers.cpp
)

option(TEST_LCOV "option for lcov" OFF)
Expand Down
Loading
Loading