Skip to content

Commit

Permalink
update unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sy0307 committed Dec 23, 2024
1 parent c703c5d commit ca3efde
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions runtime/src/bpf_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ thread_local static void (*origin_segv_write_handler)(int, siginfo_t *,

static void segv_read_handler(int sig, siginfo_t *siginfo, void *ctx)
{
SPDLOG_INFO("segv_handler for probe_read called");
if (status_probe_read == PROBE_STATUS::NOT_RUNNING) {
SPDLOG_INFO("segv_handler for probe_read called 2");
if (origin_segv_read_handler != nullptr) {
origin_segv_read_handler(sig, siginfo, ctx);

Check warning on line 108 in runtime/src/bpf_helper.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/src/bpf_helper.cpp#L108

Added line #L108 was not covered by tests
} else {
SPDLOG_INFO("segv_handler for probe_read called 3");
SPDLOG_ERROR("no origin handler for probe_read");
throw std::runtime_error(
"segv_handler for probe_read called");

Check warning on line 112 in runtime/src/bpf_helper.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/src/bpf_helper.cpp#L110-L112

Added lines #L110 - L112 were not covered by tests
}
Expand Down Expand Up @@ -192,7 +190,9 @@ static void segv_write_handler(int sig, siginfo_t *siginfo, void *ctx)
if (origin_segv_write_handler) {
origin_segv_write_handler(sig, siginfo, ctx);

Check warning on line 191 in runtime/src/bpf_helper.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/src/bpf_helper.cpp#L191

Added line #L191 was not covered by tests
} else {
abort();
SPDLOG_ERROR("no origin handler for probe_write");
throw std::runtime_error(
"segv_handler for probe_write called");

Check warning on line 195 in runtime/src/bpf_helper.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/src/bpf_helper.cpp#L193-L195

Added lines #L193 - L195 were not covered by tests
}
} else if (status_probe_write == PROBE_STATUS::RUNNING_NO_ERROR) {
// set status to error
Expand Down
24 changes: 24 additions & 0 deletions runtime/unit-test/test_probe.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "catch2/catch_test_macros.hpp"
#include "spdlog/spdlog.h"
#include <csetjmp>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
Expand Down Expand Up @@ -83,4 +84,27 @@ TEST_CASE("Test Probe read/write size valid or not ")
for (size_t i = 0; i < 4; i++) {
REQUIRE(dst[i] == src[i]);
}
}


TEST_CASE("Test origin handler is null")
{
struct sigaction original_sa, sa;
int dst[4] = { 0 };
int src[4] = { 1, 2, 3, 4 };
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = nullptr;
if (sigaction(SIGSEGV, &sa, nullptr) < 0) {
REQUIRE(false);

Check warning on line 99 in runtime/unit-test/test_probe.cpp

View check run for this annotation

Codecov / codecov/patch

runtime/unit-test/test_probe.cpp#L99

Added line #L99 was not covered by tests
}
uint64_t size = sizeof(src);

int ret = bpftime_probe_read((uint64_t)(dst), size, (uint64_t)(src), 0,
0);
REQUIRE(ret == 0);

sigaction(SIGSEGV, nullptr, &original_sa);
auto handler = original_sa.sa_sigaction;
REQUIRE(handler != nullptr);
}

0 comments on commit ca3efde

Please sign in to comment.