Add kernel tests for native_only build. (#2407)
* fix api_tests * fix native and socket kernel tests * fix bpftool_tests * fix cmake build * fix sample ext app * fix tests * add new cicd test * fix analyze build * change to using guids * code cleanup * code cleanup * fix bad merge * revert cicd job name * cr comments
This commit is contained in:
Родитель
c7ea6fea59
Коммит
c52f3dbe89
|
@ -155,6 +155,25 @@ jobs:
|
|||
# driver tests manually gather code coverage
|
||||
code_coverage: false
|
||||
|
||||
# Run the native-only driver tests on self-hosted runners.
|
||||
driver_native_only:
|
||||
# Always run this job.
|
||||
# Only run this on repos that have self-host runners.
|
||||
needs: regular_native-only
|
||||
if: github.repository == 'microsoft/ebpf-for-windows'
|
||||
uses: ./.github/workflows/reusable-test.yml
|
||||
with:
|
||||
pre_test: .\setup_ebpf_cicd_tests.ps1
|
||||
test_command: .\execute_ebpf_cicd_tests.ps1
|
||||
post_test: .\cleanup_ebpf_cicd_tests.ps1
|
||||
name: driver
|
||||
build_artifact: Build-x64-native-only
|
||||
environment: ebpf_cicd_tests
|
||||
# driver test copies dumps to testlog folder.
|
||||
gather_dumps: false
|
||||
# driver tests manually gather code coverage
|
||||
code_coverage: false
|
||||
|
||||
ossar:
|
||||
# Always run this job.
|
||||
needs: regular
|
||||
|
|
|
@ -253,7 +253,7 @@ function Invoke-XDPTest1
|
|||
Write-Log "Running XDP Test1 ..."
|
||||
|
||||
# Load reflect_packet without specifying interface on VM1.
|
||||
$ProgId = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.o" -LogFileName $LogFileName
|
||||
$ProgId = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.sys" -LogFileName $LogFileName
|
||||
|
||||
# Run XDP reflect test from VM2 targeting both interfaces of VM1.
|
||||
Invoke-XDPTestOnVM $VM2 "xdp_reflect_test" $VM1Interface1V4Address $VM1Interface1V6Address $LogFileName
|
||||
|
@ -280,7 +280,7 @@ function Invoke-XDPTest2
|
|||
Write-Log "Running XDP Test2 ..."
|
||||
|
||||
# Load reflect_packet on interface1 on VM1.
|
||||
$ProgId = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.o" -Interface $VM1Interface1Alias -LogFileName $LogFileName
|
||||
$ProgId = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.sys" -Interface $VM1Interface1Alias -LogFileName $LogFileName
|
||||
|
||||
# Attach the program on interface2 on VM1.
|
||||
Set-eBPFProgramOnVM -VM $VM1 -ProgId $ProgId -Interface $VM1Interface2Alias -LogFileName $LogFileName
|
||||
|
@ -310,10 +310,10 @@ function Invoke-XDPTest3
|
|||
Write-Log "Running XDP Test3 ..."
|
||||
|
||||
# Load reflect_packet on interface1 of VM1.
|
||||
$ProgId1 = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.o" -Interface $VM1Interface1Alias -LogFileName $LogFileName
|
||||
$ProgId1 = Add-eBPFProgramOnVM -VM $VM1 -Program "reflect_packet.sys" -Interface $VM1Interface1Alias -LogFileName $LogFileName
|
||||
|
||||
# Load encap_reflact_packet on interface2 on VM1.
|
||||
$ProgId2 = Add-eBPFProgramOnVM -VM $VM1 -Program "encap_reflect_packet.o" -Interface $VM1Interface2Alias -LogFileName $LogFileName
|
||||
$ProgId2 = Add-eBPFProgramOnVM -VM $VM1 -Program "encap_reflect_packet.sys" -Interface $VM1Interface2Alias -LogFileName $LogFileName
|
||||
|
||||
# Run XDP reflect test from VM2 targeting first interface of VM1.
|
||||
Invoke-XDPTestOnVM $VM2 "xdp_reflect_test" $VM1Interface1V4Address $VM1Interface1V6Address $LogFileName
|
||||
|
@ -339,10 +339,10 @@ function Invoke-XDPTest4
|
|||
Write-Log "Running XDP Test4 ..."
|
||||
|
||||
# Load encap_reflect_packet on VM1.
|
||||
$ProgId1 = Add-eBPFProgramOnVM -VM $VM1 -Program "encap_reflect_packet.o" -LogFileName $LogFileName
|
||||
$ProgId1 = Add-eBPFProgramOnVM -VM $VM1 -Program "encap_reflect_packet.sys" -LogFileName $LogFileName
|
||||
|
||||
# Load decap_permit_packet on VM2.
|
||||
$ProgId2 = Add-eBPFProgramOnVM -VM $VM2 -Program "decap_permit_packet.o" -LogFileName $LogFileName
|
||||
$ProgId2 = Add-eBPFProgramOnVM -VM $VM2 -Program "decap_permit_packet.sys" -LogFileName $LogFileName
|
||||
|
||||
# Run XDP reflect test from VM2 targeting first interface of VM1.
|
||||
Invoke-XDPTestOnVM $VM2 "xdp_reflect_test" $VM1Interface1V4Address $VM1Interface1V6Address $LogFileName
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "common_tests.h"
|
||||
#include "ebpf_structs.h"
|
||||
#include "misc_helper.h"
|
||||
#include "native_helper.hpp"
|
||||
#include "program_helper.h"
|
||||
#include "service_helper.h"
|
||||
#include "socket_helper.h"
|
||||
|
@ -285,6 +286,17 @@ TEST_CASE("pinned_map_enum", "[pinned_map_enum]") { ebpf_test_pinned_map_enum();
|
|||
#define INTERPRET_LOAD_RESULT 0
|
||||
#endif
|
||||
|
||||
static int32_t
|
||||
_get_expected_jit_result(int32_t expected_result)
|
||||
{
|
||||
#if defined(CONFIG_BPF_JIT_DISABLED)
|
||||
UNREFERENCED_PARAMETER(expected_result);
|
||||
return -EOTHER;
|
||||
#else
|
||||
return expected_result;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load droppacket (JIT) without providing expected program type.
|
||||
DECLARE_LOAD_TEST_CASE("droppacket.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_JIT, JIT_LOAD_RESULT);
|
||||
|
||||
|
@ -295,7 +307,7 @@ DECLARE_LOAD_TEST_CASE("droppacket.sys", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_NA
|
|||
DECLARE_DUPLICATE_LOAD_TEST_CASE("droppacket.sys", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_NATIVE, 2, 0);
|
||||
|
||||
// Load droppacket (ANY) without providing expected program type.
|
||||
DECLARE_LOAD_TEST_CASE("droppacket.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_ANY, 0);
|
||||
DECLARE_LOAD_TEST_CASE("droppacket.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_ANY, JIT_LOAD_RESULT);
|
||||
|
||||
// Load droppacket (INTERPRET) without providing expected program type.
|
||||
DECLARE_LOAD_TEST_CASE("droppacket.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_INTERPRET, INTERPRET_LOAD_RESULT);
|
||||
|
@ -313,17 +325,18 @@ DECLARE_LOAD_TEST_CASE("bindmonitor.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_INT
|
|||
DECLARE_LOAD_TEST_CASE("bindmonitor.o", BPF_PROG_TYPE_BIND, EBPF_EXECUTION_JIT, JIT_LOAD_RESULT);
|
||||
|
||||
// Try to load bindmonitor with providing wrong program type.
|
||||
DECLARE_LOAD_TEST_CASE("bindmonitor.o", BPF_PROG_TYPE_XDP, EBPF_EXECUTION_ANY, -EACCES);
|
||||
DECLARE_LOAD_TEST_CASE("bindmonitor.o", BPF_PROG_TYPE_XDP, EBPF_EXECUTION_ANY, _get_expected_jit_result(-EACCES));
|
||||
|
||||
// Try to load an unsafe program.
|
||||
DECLARE_LOAD_TEST_CASE("droppacket_unsafe.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_ANY, -EACCES);
|
||||
DECLARE_LOAD_TEST_CASE(
|
||||
"droppacket_unsafe.o", BPF_PROG_TYPE_UNSPEC, EBPF_EXECUTION_ANY, _get_expected_jit_result(-EACCES));
|
||||
|
||||
// Try to load multiple programs of different program types
|
||||
TEST_CASE("test_ebpf_multiple_programs_load_jit")
|
||||
{
|
||||
struct _ebpf_program_load_test_parameters test_parameters[] = {
|
||||
{"droppacket.o", BPF_PROG_TYPE_XDP}, {"bindmonitor.o", BPF_PROG_TYPE_BIND}};
|
||||
_test_multiple_programs_load(_countof(test_parameters), test_parameters, EBPF_EXECUTION_JIT, 0);
|
||||
_test_multiple_programs_load(_countof(test_parameters), test_parameters, EBPF_EXECUTION_JIT, JIT_LOAD_RESULT);
|
||||
}
|
||||
|
||||
TEST_CASE("test_ebpf_multiple_programs_load_interpret")
|
||||
|
@ -334,17 +347,37 @@ TEST_CASE("test_ebpf_multiple_programs_load_interpret")
|
|||
_countof(test_parameters), test_parameters, EBPF_EXECUTION_INTERPRET, INTERPRET_LOAD_RESULT);
|
||||
}
|
||||
|
||||
TEST_CASE("test_ebpf_program_next_previous", "[test_ebpf_program_next_previous]")
|
||||
#if !defined(CONFIG_BPF_JIT_DISABLED)
|
||||
TEST_CASE("test_ebpf_program_next_previous_jit", "[test_ebpf_program_next_previous]")
|
||||
{
|
||||
_test_program_next_previous("droppacket.o", DROP_PACKET_PROGRAM_COUNT);
|
||||
_test_program_next_previous("bindmonitor.o", BIND_MONITOR_PROGRAM_COUNT);
|
||||
}
|
||||
|
||||
TEST_CASE("test_ebpf_map_next_previous", "[test_ebpf_map_next_previous]")
|
||||
TEST_CASE("test_ebpf_map_next_previous_jit", "[test_ebpf_map_next_previous]")
|
||||
{
|
||||
_test_map_next_previous("droppacket.o", DROP_PACKET_MAP_COUNT);
|
||||
_test_map_next_previous("bindmonitor.o", BIND_MONITOR_MAP_COUNT);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("test_ebpf_program_next_previous_native", "[test_ebpf_program_next_previous]")
|
||||
{
|
||||
native_module_helper_t droppacket_helper("droppacket", EBPF_EXECUTION_NATIVE);
|
||||
_test_program_next_previous(droppacket_helper.get_file_name().c_str(), DROP_PACKET_PROGRAM_COUNT);
|
||||
|
||||
native_module_helper_t bindmonitor_helper("bindmonitor", EBPF_EXECUTION_NATIVE);
|
||||
_test_program_next_previous(bindmonitor_helper.get_file_name().c_str(), BIND_MONITOR_PROGRAM_COUNT);
|
||||
}
|
||||
|
||||
TEST_CASE("test_ebpf_map_next_previous_native", "[test_ebpf_map_next_previous]")
|
||||
{
|
||||
native_module_helper_t droppacket_helper("droppacket", EBPF_EXECUTION_NATIVE);
|
||||
_test_map_next_previous(droppacket_helper.get_file_name().c_str(), DROP_PACKET_MAP_COUNT);
|
||||
|
||||
native_module_helper_t bindmonitor_helper("bindmonitor", EBPF_EXECUTION_NATIVE);
|
||||
_test_map_next_previous(bindmonitor_helper.get_file_name().c_str(), BIND_MONITOR_MAP_COUNT);
|
||||
}
|
||||
|
||||
void
|
||||
perform_socket_bind(const uint16_t test_port, bool expect_success = true)
|
||||
|
@ -497,13 +530,14 @@ _test_nested_maps(bpf_map_type type)
|
|||
TEST_CASE("array_map_of_maps", "[map_in_map]") { _test_nested_maps(BPF_MAP_TYPE_ARRAY_OF_MAPS); }
|
||||
TEST_CASE("hash_map_of_maps", "[map_in_map]") { _test_nested_maps(BPF_MAP_TYPE_HASH_OF_MAPS); }
|
||||
|
||||
TEST_CASE("tailcall_load_test", "[tailcall_load_test]")
|
||||
void
|
||||
tailcall_load_test(_In_z_ const char* file_name)
|
||||
{
|
||||
int result;
|
||||
struct bpf_object* object = nullptr;
|
||||
fd_t program_fd;
|
||||
|
||||
result = _program_load_helper("tail_call_multiple.o", BPF_PROG_TYPE_XDP, EBPF_EXECUTION_ANY, &object, &program_fd);
|
||||
result = _program_load_helper(file_name, BPF_PROG_TYPE_XDP, EBPF_EXECUTION_ANY, &object, &program_fd);
|
||||
REQUIRE(result == 0);
|
||||
|
||||
REQUIRE(program_fd > 0);
|
||||
|
@ -539,6 +573,12 @@ TEST_CASE("tailcall_load_test", "[tailcall_load_test]")
|
|||
bpf_object__close(object);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_BPF_JIT_DISABLED)
|
||||
TEST_CASE("tailcall_load_test_jit", "[tailcall_load_test]") { tailcall_load_test("tail_call_multiple.o"); }
|
||||
#endif
|
||||
|
||||
TEST_CASE("tailcall_load_test_native", "[tailcall_load_test]") { tailcall_load_test("tail_call_multiple.sys"); }
|
||||
|
||||
int
|
||||
perform_bind(_Out_ SOCKET* socket, uint16_t port_number)
|
||||
{
|
||||
|
@ -775,9 +815,9 @@ bpf_user_helpers_test(ebpf_execution_type_t execution_type)
|
|||
struct bpf_object* object = nullptr;
|
||||
uint64_t process_thread_id = get_current_pid_tgid();
|
||||
hook_helper_t hook(EBPF_ATTACH_TYPE_BIND);
|
||||
const char* file_name = (execution_type == EBPF_EXECUTION_NATIVE) ? "bindmonitor.sys" : "bindmonitor.o";
|
||||
native_module_helper_t module_helper("bindmonitor", execution_type);
|
||||
program_load_attach_helper_t _helper(
|
||||
file_name, BPF_PROG_TYPE_BIND, "BindMonitor", execution_type, nullptr, 0, hook);
|
||||
module_helper.get_file_name().c_str(), BPF_PROG_TYPE_BIND, "BindMonitor", execution_type, nullptr, 0, hook);
|
||||
object = _helper.get_object();
|
||||
|
||||
perform_socket_bind(0, true);
|
||||
|
@ -800,7 +840,9 @@ bpf_user_helpers_test(ebpf_execution_type_t execution_type)
|
|||
LsaFreeReturnBuffer(data);
|
||||
}
|
||||
|
||||
#if !defined(CONFIG_BPF_JIT_DISABLED)
|
||||
TEST_CASE("bpf_user_helpers_test_jit", "[api_test]") { bpf_user_helpers_test(EBPF_EXECUTION_JIT); }
|
||||
#endif
|
||||
TEST_CASE("bpf_user_helpers_test_native", "[api_test]") { bpf_user_helpers_test(EBPF_EXECUTION_NATIVE); }
|
||||
|
||||
// This test tests resource reclamation and clean-up after a premature/abnormal user mode application exit.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "capture_helper.hpp"
|
||||
#include "catch_wrapper.hpp"
|
||||
#include "ebpf_api.h"
|
||||
#include "native_helper.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <filesystem>
|
||||
|
@ -68,7 +69,7 @@ TEST_CASE("prog help", "[prog][help]")
|
|||
REQUIRE(result == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("prog load map_in_map.o", "[prog][load]")
|
||||
TEST_CASE("prog load map_in_map", "[prog][load]")
|
||||
{
|
||||
int result;
|
||||
std::string output;
|
||||
|
@ -77,7 +78,10 @@ TEST_CASE("prog load map_in_map.o", "[prog][load]")
|
|||
REQUIRE(output == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
output = run_command("bpftool --legacy prog load map_in_map.o map_in_map", &result);
|
||||
char command[80];
|
||||
sprintf_s(
|
||||
command, sizeof(command), "bpftool --legacy prog load map_in_map%s map_in_map", EBPF_PROGRAM_FILE_EXTENSION);
|
||||
output = run_command(command, &result);
|
||||
REQUIRE(output == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
|
@ -121,8 +125,11 @@ TEST_CASE("prog attach by interface alias", "[prog][load]")
|
|||
{
|
||||
int result;
|
||||
std::string output;
|
||||
char command[80];
|
||||
sprintf_s(
|
||||
command, sizeof(command), "bpftool --legacy prog load droppacket%s droppacket", EBPF_PROGRAM_FILE_EXTENSION);
|
||||
|
||||
output = run_command("bpftool --legacy prog load droppacket.o droppacket", &result);
|
||||
output = run_command(command, &result);
|
||||
REQUIRE(output == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
|
@ -204,8 +211,11 @@ TEST_CASE("prog prog run", "[prog][load]")
|
|||
{
|
||||
int result;
|
||||
std::string output;
|
||||
char command[80];
|
||||
sprintf_s(
|
||||
command, sizeof(command), "bpftool --legacy prog load droppacket%s droppacket", EBPF_PROGRAM_FILE_EXTENSION);
|
||||
|
||||
output = run_command("bpftool --legacy prog load droppacket.o droppacket", &result);
|
||||
output = run_command(command, &result);
|
||||
REQUIRE(output == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "ebpf_nethooks.h"
|
||||
#include "ebpf_structs.h"
|
||||
#include "misc_helper.h"
|
||||
#include "native_helper.hpp"
|
||||
#include "socket_helper.h"
|
||||
#include "socket_tests_common.h"
|
||||
#include "watchdog.h"
|
||||
|
@ -285,9 +286,10 @@ static void
|
|||
_load_and_attach_ebpf_programs(_Outptr_ struct bpf_object** return_object)
|
||||
{
|
||||
int result;
|
||||
struct bpf_object* object = bpf_object__open("cgroup_sock_addr2.o");
|
||||
REQUIRE(object != nullptr);
|
||||
native_module_helper_t helper("cgroup_sock_addr2");
|
||||
|
||||
struct bpf_object* object = bpf_object__open(helper.get_file_name().c_str());
|
||||
REQUIRE(object != nullptr);
|
||||
REQUIRE(bpf_object__load(object) == 0);
|
||||
|
||||
if (_globals.attach_v4_program) {
|
||||
|
|
|
@ -10,6 +10,9 @@ add_library("test_util" STATIC
|
|||
ioctl_helper.h
|
||||
ioctl_helper.cpp
|
||||
|
||||
native_helper.hpp
|
||||
native_helper.cpp
|
||||
|
||||
netsh_helper.cpp
|
||||
|
||||
program_helper.h
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "catch_wrapper.hpp"
|
||||
#include "ebpf_execution_type.h"
|
||||
#include "native_helper.hpp"
|
||||
|
||||
#include <rpc.h>
|
||||
|
||||
void
|
||||
_native_module_helper::initialize(_In_z_ const char* file_name_prefix, ebpf_execution_type_t execution_type)
|
||||
{
|
||||
GUID random_guid;
|
||||
char* guid_string = nullptr;
|
||||
#if defined(CONFIG_BPF_JIT_DISABLED)
|
||||
ebpf_execution_type_t system_default = ebpf_execution_type_t::EBPF_EXECUTION_NATIVE;
|
||||
#else
|
||||
ebpf_execution_type_t system_default = ebpf_execution_type_t::EBPF_EXECUTION_ANY;
|
||||
#endif
|
||||
|
||||
if (execution_type == ebpf_execution_type_t::EBPF_EXECUTION_ANY) {
|
||||
execution_type = system_default;
|
||||
}
|
||||
if (execution_type == ebpf_execution_type_t::EBPF_EXECUTION_NATIVE) {
|
||||
_delete_file_on_destruction = true;
|
||||
std::string file_name_prefix_string(file_name_prefix);
|
||||
std::string original_file_name = file_name_prefix_string + std::string(EBPF_PROGRAM_FILE_EXTENSION_NATIVE);
|
||||
|
||||
// Generate a random GUID to append to the file name.
|
||||
REQUIRE(UuidCreate(&random_guid) == RPC_S_OK);
|
||||
|
||||
REQUIRE(UuidToStringA(&random_guid, (RPC_CSTR*)&guid_string) == RPC_S_OK);
|
||||
|
||||
_file_name =
|
||||
file_name_prefix_string + std::string(guid_string) + std::string(EBPF_PROGRAM_FILE_EXTENSION_NATIVE);
|
||||
REQUIRE(CopyFileA(original_file_name.c_str(), _file_name.c_str(), TRUE) == TRUE);
|
||||
} else {
|
||||
_file_name = std::string(file_name_prefix) + std::string(EBPF_PROGRAM_FILE_EXTENSION_JIT);
|
||||
}
|
||||
}
|
||||
|
||||
_native_module_helper::~_native_module_helper()
|
||||
{
|
||||
if (_delete_file_on_destruction) {
|
||||
DeleteFileA(_file_name.c_str());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
#pragma comment(lib, "rpcrt4")
|
||||
|
||||
#define EBPF_PROGRAM_FILE_EXTENSION_JIT ".o"
|
||||
#define EBPF_PROGRAM_FILE_EXTENSION_NATIVE ".sys"
|
||||
#if defined(CONFIG_BPF_JIT_DISABLED)
|
||||
#define EBPF_PROGRAM_FILE_EXTENSION EBPF_PROGRAM_FILE_EXTENSION_NATIVE
|
||||
#else
|
||||
#define EBPF_PROGRAM_FILE_EXTENSION EBPF_PROGRAM_FILE_EXTENSION_JIT
|
||||
#endif
|
||||
|
||||
typedef class _native_module_helper
|
||||
{
|
||||
public:
|
||||
_native_module_helper(_In_z_ const char* file_name_prefix)
|
||||
{
|
||||
initialize(file_name_prefix, ebpf_execution_type_t::EBPF_EXECUTION_ANY);
|
||||
}
|
||||
_native_module_helper(_In_z_ const char* file_name_prefix, ebpf_execution_type_t execution_type)
|
||||
{
|
||||
initialize(file_name_prefix, execution_type);
|
||||
}
|
||||
std::string
|
||||
get_file_name() const
|
||||
{
|
||||
printf("_native_module_helper::get_file_name: %s\n", _file_name.c_str());
|
||||
return _file_name;
|
||||
}
|
||||
~_native_module_helper();
|
||||
|
||||
private:
|
||||
void
|
||||
initialize(_In_z_ const char* file_name_prefix, ebpf_execution_type_t execution_type);
|
||||
std::string _file_name;
|
||||
bool _delete_file_on_destruction = false;
|
||||
} native_module_helper_t;
|
|
@ -22,6 +22,7 @@
|
|||
<ClCompile Include="capture_helper.cpp" />
|
||||
<ClCompile Include="hash.cpp" />
|
||||
<ClCompile Include="ioctl_helper.cpp" />
|
||||
<ClCompile Include="native_helper.cpp" />
|
||||
<ClCompile Include="netsh_helper.cpp" />
|
||||
<ClCompile Include="service_helper.cpp" />
|
||||
<ClCompile Include="socket_helper.cpp" />
|
||||
|
@ -31,6 +32,7 @@
|
|||
<ClInclude Include="hash.h" />
|
||||
<ClInclude Include="header.h" />
|
||||
<ClInclude Include="ioctl_helper.h" />
|
||||
<ClInclude Include="native_helper.hpp" />
|
||||
<ClInclude Include="service_helper.h" />
|
||||
<ClInclude Include="socket_helper.h" />
|
||||
<ClInclude Include="program_helper.h" />
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (c) Microsoft Corporation
|
||||
SPDX-License-Identifier: MIT
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="capture_helper.cpp" />
|
||||
|
@ -8,6 +12,7 @@
|
|||
<ClCompile Include="socket_helper.cpp" />
|
||||
<ClCompile Include="program_helper.cpp" />
|
||||
<ClCompile Include="hash.cpp" />
|
||||
<ClCompile Include="native_helper.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ioctl_helper.h" />
|
||||
|
@ -17,5 +22,6 @@
|
|||
<ClInclude Include="wer_report.hpp" />
|
||||
<ClInclude Include="hash.h" />
|
||||
<ClInclude Include="header.h" />
|
||||
<ClInclude Include="native_helper.hpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -7,6 +7,7 @@
|
|||
#include "bpf/libbpf.h"
|
||||
#include "catch_wrapper.hpp"
|
||||
#include "common_tests.h"
|
||||
#include "native_helper.hpp"
|
||||
#include "netsh_test_helper.h"
|
||||
#include "program_helper.h"
|
||||
#include "sample_ext_app.h"
|
||||
|
@ -146,9 +147,15 @@ utility_helpers_test(ebpf_execution_type_t execution_type)
|
|||
{
|
||||
struct bpf_object* object = nullptr;
|
||||
hook_helper_t hook(EBPF_ATTACH_TYPE_SAMPLE);
|
||||
const char* file_name = (execution_type == EBPF_EXECUTION_NATIVE) ? "test_sample_ebpf.sys" : "test_sample_ebpf.o";
|
||||
native_module_helper_t native_module_helper("test_sample_ebpf", execution_type);
|
||||
program_load_attach_helper_t _helper(
|
||||
file_name, BPF_PROG_TYPE_SAMPLE, "test_utility_helpers", execution_type, nullptr, 0, hook);
|
||||
native_module_helper.get_file_name().c_str(),
|
||||
BPF_PROG_TYPE_SAMPLE,
|
||||
"test_utility_helpers",
|
||||
execution_type,
|
||||
nullptr,
|
||||
0,
|
||||
hook);
|
||||
object = _helper.get_object();
|
||||
|
||||
std::vector<char> dummy(1);
|
||||
|
@ -166,6 +173,8 @@ TEST_CASE("utility_helpers_test_interpret", "[sample_ext_test]") { utility_helpe
|
|||
TEST_CASE("utility_helpers_test_jit", "[sample_ext_test]") { utility_helpers_test(EBPF_EXECUTION_JIT); }
|
||||
#endif
|
||||
TEST_CASE("utility_helpers_test_native", "[sample_ext_test]") { utility_helpers_test(EBPF_EXECUTION_NATIVE); }
|
||||
|
||||
#if !defined(CONFIG_BPF_JIT_DISABLED)
|
||||
TEST_CASE("netsh_add_program_test_sample_ebpf", "[sample_ext_test]")
|
||||
{
|
||||
int result;
|
||||
|
@ -174,3 +183,4 @@ TEST_CASE("netsh_add_program_test_sample_ebpf", "[sample_ext_test]")
|
|||
REQUIRE(result == NO_ERROR);
|
||||
REQUIRE(output.starts_with("Loaded with"));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "common_tests.h"
|
||||
#include "ebpf_nethooks.h"
|
||||
#include "ebpf_structs.h"
|
||||
#include "native_helper.hpp"
|
||||
#include "socket_helper.h"
|
||||
#include "socket_tests_common.h"
|
||||
#include "watchdog.h"
|
||||
|
@ -35,7 +36,9 @@ connection_test(
|
|||
_Inout_ receiver_socket_t& receiver_socket,
|
||||
uint32_t protocol)
|
||||
{
|
||||
struct bpf_object* object = bpf_object__open("cgroup_sock_addr.o");
|
||||
native_module_helper_t helper("cgroup_sock_addr");
|
||||
|
||||
struct bpf_object* object = bpf_object__open(helper.get_file_name().c_str());
|
||||
REQUIRE(object != nullptr);
|
||||
// Load the programs.
|
||||
REQUIRE(bpf_object__load(object) == 0);
|
||||
|
@ -162,8 +165,9 @@ TEST_CASE("attach_sock_addr_programs", "[sock_addr_tests]")
|
|||
{
|
||||
bpf_prog_info program_info = {};
|
||||
uint32_t program_info_size = sizeof(program_info);
|
||||
native_module_helper_t helper("cgroup_sock_addr");
|
||||
|
||||
struct bpf_object* object = bpf_object__open("cgroup_sock_addr.o");
|
||||
struct bpf_object* object = bpf_object__open(helper.get_file_name().c_str());
|
||||
REQUIRE(object != nullptr);
|
||||
// Load the programs.
|
||||
REQUIRE(bpf_object__load(object) == 0);
|
||||
|
@ -254,7 +258,8 @@ connection_monitor_test(
|
|||
uint32_t protocol,
|
||||
bool disconnect)
|
||||
{
|
||||
struct bpf_object* object = bpf_object__open("sockops.o");
|
||||
native_module_helper_t helper("sockops");
|
||||
struct bpf_object* object = bpf_object__open(helper.get_file_name().c_str());
|
||||
REQUIRE(object != nullptr);
|
||||
// Load the programs.
|
||||
REQUIRE(bpf_object__load(object) == 0);
|
||||
|
@ -430,7 +435,8 @@ TEST_CASE("connection_monitor_test_disconnect_tcp_v6", "[sock_ops_tests]")
|
|||
|
||||
TEST_CASE("attach_sockops_programs", "[sock_ops_tests]")
|
||||
{
|
||||
struct bpf_object* object = bpf_object__open("sockops.o");
|
||||
native_module_helper_t helper("sockops");
|
||||
struct bpf_object* object = bpf_object__open(helper.get_file_name().c_str());
|
||||
REQUIRE(object != nullptr);
|
||||
// Load the programs.
|
||||
REQUIRE(bpf_object__load(object) == 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче