Fix native module unit tests for low memory simulation scenario (#2084)

* fix tests

* cr comments

* fix

* Revert "fix"

This reverts commit 25206c5ff7.

* Revert "cr comments"

This reverts commit 4b91cea38e.

* fix
This commit is contained in:
Anurag Saxena 2023-02-19 08:57:12 -08:00 коммит произвёл GitHub
Родитель 8f64a0ca20
Коммит 2f1c78e712
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 50 добавлений и 16 удалений

Просмотреть файл

@ -2398,7 +2398,7 @@ TEST_CASE("load_native_program_negative4", "[end-to-end]")
size_t count_of_maps = 0; size_t count_of_maps = 0;
size_t count_of_programs = 0; size_t count_of_programs = 0;
std::wstring file_path(L"droppacket_um.dll"); std::wstring file_path(L"droppacket_um.dll");
ebpf_handle_t module_handle = ebpf_handle_invalid; _test_handle_helper module_handle;
ebpf_handle_t map_handles[INCORRECT_MAP_COUNT]; ebpf_handle_t map_handles[INCORRECT_MAP_COUNT];
ebpf_handle_t program_handles[PROGRAM_COUNT]; ebpf_handle_t program_handles[PROGRAM_COUNT];
@ -2417,7 +2417,11 @@ TEST_CASE("load_native_program_negative4", "[end-to-end]")
service_path = service_path + NATIVE_DRIVER_SERVICE_NAME; service_path = service_path + NATIVE_DRIVER_SERVICE_NAME;
REQUIRE( REQUIRE(
test_ioctl_load_native_module( test_ioctl_load_native_module(
service_path, &provider_module_id, &module_handle, &count_of_maps, &count_of_programs) == ERROR_SUCCESS); service_path,
&provider_module_id,
module_handle.get_handle_pointer(),
&count_of_maps,
&count_of_programs) == ERROR_SUCCESS);
// Try to load the programs by passing wrong map and program handles size. This should fail. // Try to load the programs by passing wrong map and program handles size. This should fail.
REQUIRE( REQUIRE(
@ -2427,9 +2431,6 @@ TEST_CASE("load_native_program_negative4", "[end-to-end]")
// Delete the created service. // Delete the created service.
Platform::_delete_service(service_handle); Platform::_delete_service(service_handle);
// Close the module handle.
Platform::CloseHandle(module_handle);
} }
// Try to load a .sys in user mode. // Try to load a .sys in user mode.
@ -2461,8 +2462,8 @@ TEST_CASE("load_native_program_negative6", "[end-to-end]")
SC_HANDLE service_handle2 = nullptr; SC_HANDLE service_handle2 = nullptr;
std::wstring service_path(SERVICE_PATH_PREFIX); std::wstring service_path(SERVICE_PATH_PREFIX);
std::wstring service_path2(SERVICE_PATH_PREFIX); std::wstring service_path2(SERVICE_PATH_PREFIX);
ebpf_handle_t module_handle = ebpf_handle_invalid; _test_handle_helper module_handle;
ebpf_handle_t module_handle2 = ebpf_handle_invalid; _test_handle_helper module_handle2;
size_t count_of_maps = 0; size_t count_of_maps = 0;
size_t count_of_programs = 0; size_t count_of_programs = 0;
set_native_module_failures(true); set_native_module_failures(true);
@ -2476,7 +2477,11 @@ TEST_CASE("load_native_program_negative6", "[end-to-end]")
service_path = service_path + NATIVE_DRIVER_SERVICE_NAME; service_path = service_path + NATIVE_DRIVER_SERVICE_NAME;
REQUIRE( REQUIRE(
test_ioctl_load_native_module( test_ioctl_load_native_module(
service_path, &provider_module_id, &module_handle, &count_of_maps, &count_of_programs) == ERROR_SUCCESS); service_path,
&provider_module_id,
module_handle.get_handle_pointer(),
&count_of_maps,
&count_of_programs) == ERROR_SUCCESS);
// Create a new service with same driver and same module id. // Create a new service with same driver and same module id.
_create_service_helper(L"droppacket_um.dll", NATIVE_DRIVER_SERVICE_NAME_2, &provider_module_id, &service_handle2); _create_service_helper(L"droppacket_um.dll", NATIVE_DRIVER_SERVICE_NAME_2, &provider_module_id, &service_handle2);
@ -2487,10 +2492,11 @@ TEST_CASE("load_native_program_negative6", "[end-to-end]")
service_path2 = service_path2 + NATIVE_DRIVER_SERVICE_NAME_2; service_path2 = service_path2 + NATIVE_DRIVER_SERVICE_NAME_2;
REQUIRE( REQUIRE(
test_ioctl_load_native_module( test_ioctl_load_native_module(
service_path2, &provider_module_id, &module_handle2, &count_of_maps, &count_of_programs) == service_path2,
ERROR_OBJECT_ALREADY_EXISTS); &provider_module_id,
module_handle2.get_handle_pointer(),
Platform::CloseHandle(module_handle); &count_of_maps,
&count_of_programs) == ERROR_OBJECT_ALREADY_EXISTS);
} }
// The below tests try to load native drivers for invalid programs (that will fail verification). // The below tests try to load native drivers for invalid programs (that will fail verification).
@ -2509,9 +2515,9 @@ TEST_CASE("load_native_program_negative8", "[end-to-end]")
size_t count_of_maps = 0; size_t count_of_maps = 0;
size_t count_of_programs = 0; size_t count_of_programs = 0;
std::wstring file_path(L"droppacket_um.dll"); std::wstring file_path(L"droppacket_um.dll");
ebpf_handle_t module_handle = ebpf_handle_invalid;
ebpf_handle_t map_handles; ebpf_handle_t map_handles;
ebpf_handle_t program_handles; ebpf_handle_t program_handles;
_test_handle_helper module_handle;
REQUIRE(UuidCreate(&provider_module_id) == RPC_S_OK); REQUIRE(UuidCreate(&provider_module_id) == RPC_S_OK);
@ -2522,15 +2528,17 @@ TEST_CASE("load_native_program_negative8", "[end-to-end]")
service_path = service_path + NATIVE_DRIVER_SERVICE_NAME; service_path = service_path + NATIVE_DRIVER_SERVICE_NAME;
REQUIRE( REQUIRE(
test_ioctl_load_native_module( test_ioctl_load_native_module(
service_path, &provider_module_id, &module_handle, &count_of_maps, &count_of_programs) == ERROR_SUCCESS); service_path,
&provider_module_id,
module_handle.get_handle_pointer(),
&count_of_maps,
&count_of_programs) == ERROR_SUCCESS);
// Try to load the programs from the module with 0 programs. // Try to load the programs from the module with 0 programs.
REQUIRE( REQUIRE(
test_ioctl_load_native_programs(&provider_module_id, nullptr, 1, &map_handles, 1, &program_handles) == test_ioctl_load_native_programs(&provider_module_id, nullptr, 1, &map_handles, 1, &program_handles) ==
ERROR_INVALID_PARAMETER); ERROR_INVALID_PARAMETER);
Platform::CloseHandle(module_handle);
// Delete the created service. // Delete the created service.
Platform::_delete_service(service_handle); Platform::_delete_service(service_handle);
} }

Просмотреть файл

@ -633,6 +633,13 @@ _test_helper_end_to_end::_test_helper_end_to_end()
api_initialized = true; api_initialized = true;
} }
_test_handle_helper::~_test_handle_helper()
{
if (handle != ebpf_handle_invalid) {
GlueCloseHandle((HANDLE)handle);
}
}
static void static void
_rundown_osfhandles() _rundown_osfhandles()
{ {

Просмотреть файл

@ -32,6 +32,25 @@ class _test_helper_libbpf
_single_instance_hook* cgroup_inet4_connect_hook; _single_instance_hook* cgroup_inet4_connect_hook;
}; };
class _test_handle_helper
{
public:
_test_handle_helper() : handle(ebpf_handle_invalid){};
_test_handle_helper(ebpf_handle_t handle) : handle(handle){};
_test_handle_helper(const _test_handle_helper& object) = delete;
void
operator=(const _test_handle_helper& object) = delete;
~_test_handle_helper();
ebpf_handle_t*
get_handle_pointer()
{
return &handle;
};
private:
ebpf_handle_t handle = ebpf_handle_invalid;
};
void void
set_native_module_failures(bool expected); set_native_module_failures(bool expected);