Skip to content
Merged
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
24 changes: 14 additions & 10 deletions tests/end_to_end/netsh_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,15 +1108,14 @@ TEST_CASE("show processes", "[netsh][processes]")
}
}

#if !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)

TEST_CASE("pin/unpin program", "[netsh][pin]")
static void
_test_pin_unpin_program(ebpf_execution_type_t execution_type)
{
_test_helper_netsh test_helper;
test_helper.initialize();
int result = 0;
auto output =
_run_netsh_command(handle_ebpf_add_program, L"bindmonitor.o", nullptr, L"pinpath=bindmonitor", &result);
const wchar_t* file_name = (execution_type == EBPF_EXECUTION_NATIVE ? L"bindmonitor_um.dll" : L"bindmonitor.o");
auto output = _run_netsh_command(handle_ebpf_add_program, file_name, nullptr, L"pinpath=bindmonitor", &result);
REQUIRE(result == EBPF_SUCCESS);
const char prefix[] = "Loaded with ID";
REQUIRE(output.substr(0, sizeof(prefix) - 1) == prefix);
Expand Down Expand Up @@ -1155,13 +1154,16 @@ TEST_CASE("pin/unpin program", "[netsh][pin]")
_run_netsh_command(handle_ebpf_delete_program, sid.c_str(), nullptr, nullptr, &result);
}

TEST_CASE("pin/unpin map", "[netsh][pin]")
DECLARE_ALL_TEST_CASES("pin/unpin program", "[netsh][pin]", _test_pin_unpin_program);

static void
_test_pin_unpin_map(ebpf_execution_type_t execution_type)
{
_test_helper_netsh test_helper;
test_helper.initialize();
int result = 0;
auto output =
_run_netsh_command(handle_ebpf_add_program, L"bindmonitor.o", L"bind", L"pinpath=bindmonitor", &result);
const wchar_t* file_name = (execution_type == EBPF_EXECUTION_NATIVE ? L"bindmonitor_um.dll" : L"bindmonitor.o");
auto output = _run_netsh_command(handle_ebpf_add_program, file_name, L"bind", L"pinpath=bindmonitor", &result);
REQUIRE(result == EBPF_SUCCESS);
const char prefix[] = "Loaded with ID";
REQUIRE(output.substr(0, sizeof(prefix) - 1) == prefix);
Expand All @@ -1176,7 +1178,8 @@ TEST_CASE("pin/unpin map", "[netsh][pin]")
REQUIRE(id > 0);
auto sid = std::to_wstring(id);

auto offset = output.find("audit_map", digit + 1);
const char* map_name = (execution_type == EBPF_EXECUTION_NATIVE ? "limits_map" : "audit_map");
auto offset = output.find(map_name, digit + 1);
REQUIRE(offset != std::string::npos);
auto pins = strtoul(output.c_str() + offset - 4, nullptr, 10);
REQUIRE(pins == 0);
Expand Down Expand Up @@ -1210,4 +1213,5 @@ TEST_CASE("pin/unpin map", "[netsh][pin]")

_run_netsh_command(handle_ebpf_delete_program, std::to_wstring(pid).c_str(), nullptr, nullptr, &result);
}
#endif // !defined(CONFIG_BPF_JIT_DISABLED) || !defined(CONFIG_BPF_INTERPRETER_DISABLED)

DECLARE_ALL_TEST_CASES("pin/unpin map", "[netsh][pin]", _test_pin_unpin_map);
27 changes: 27 additions & 0 deletions tests/end_to_end/netsh_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@
#pragma region
// Mock Netsh.exe APIs.

#define CONCAT(s1, s2) s1 s2
#define DECLARE_TEST_CASE(_name, _group, _function, _suffix, _execution_type) \
TEST_CASE(CONCAT(_name, _suffix), _group) { _function(_execution_type); }
#define DECLARE_NATIVE_TEST(_name, _group, _function) \
DECLARE_TEST_CASE(_name, _group, _function, "-native", EBPF_EXECUTION_NATIVE)
#if !defined(CONFIG_BPF_JIT_DISABLED)
#define DECLARE_JIT_TEST(_name, _group, _function) \
DECLARE_TEST_CASE(_name, _group, _function, "-jit", EBPF_EXECUTION_JIT)
#else
#define DECLARE_JIT_TEST(_name, _group, _function)
#endif
#if !defined(CONFIG_BPF_INTERPRETER_DISABLED)
#define DECLARE_INTERPRET_TEST(_name, _group, _function) \
DECLARE_TEST_CASE(_name, _group, _function, "-interpret", EBPF_EXECUTION_INTERPRET)
#else
#define DECLARE_INTERPRET_TEST(_name, _group, _function)
#endif

#define DECLARE_ALL_TEST_CASES(_name, _group, _function) \
DECLARE_JIT_TEST(_name, _group, _function) \
DECLARE_NATIVE_TEST(_name, _group, _function) \
DECLARE_INTERPRET_TEST(_name, _group, _function)

#define DECLARE_JIT_TEST_CASES(_name, _group, _function) \
DECLARE_JIT_TEST(_name, _group, _function) \
DECLARE_NATIVE_TEST(_name, _group, _function)

// This function has incorrect SAL annotations, but it's declared in public headers so we can't fix it.
DWORD WINAPI
PreprocessCommand(
Expand Down
6 changes: 3 additions & 3 deletions tests/end_to_end/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,6 @@ _test_helper_end_to_end::~_test_helper_end_to_end()
// Run down duplicate handles, if any.
_duplicate_handles.rundown();

// Detach all the native module clients.
_unload_all_native_modules();

clear_program_info_cache();

{
Expand All @@ -788,6 +785,9 @@ _test_helper_end_to_end::~_test_helper_end_to_end()
ebpf_core_terminate();
}

// Detach all the native module clients.
_unload_all_native_modules();

device_io_control_handler = nullptr;
cancel_io_ex_handler = nullptr;
create_file_handler = nullptr;
Expand Down
Loading
Loading