mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-16 15:51:55 +00:00
tests: add a basic test to check config precedence
Signed-off-by: Andrea Terzolo <andreaterzolo3@gmail.com>
This commit is contained in:
parent
2778b12344
commit
bc8f61ca68
@ -27,10 +27,18 @@ FetchContent_MakeAvailable(googletest)
|
|||||||
file(GLOB_RECURSE ENGINE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/engine/*.cpp)
|
file(GLOB_RECURSE ENGINE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/engine/*.cpp)
|
||||||
file(GLOB_RECURSE FALCO_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/falco/*.cpp)
|
file(GLOB_RECURSE FALCO_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/falco/*.cpp)
|
||||||
|
|
||||||
|
# Create a libscap_test_var.h file with some variables used by our tests
|
||||||
|
# for example the kmod path or the bpf path.
|
||||||
|
configure_file (
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/falco_test_var.h.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/falco_test_var.h"
|
||||||
|
)
|
||||||
|
|
||||||
set(FALCO_UNIT_TESTS_SOURCES
|
set(FALCO_UNIT_TESTS_SOURCES
|
||||||
"${ENGINE_TESTS}"
|
"${ENGINE_TESTS}"
|
||||||
falco/test_configuration.cpp
|
falco/test_configuration.cpp
|
||||||
falco/app/actions/test_select_event_sources.cpp
|
falco/app/actions/test_select_event_sources.cpp
|
||||||
|
falco/app/actions/test_load_config.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||||
@ -45,6 +53,7 @@ set(FALCO_UNIT_TESTS_INCLUDES
|
|||||||
${CMAKE_SOURCE_DIR}/userspace
|
${CMAKE_SOURCE_DIR}/userspace
|
||||||
${CMAKE_BINARY_DIR}/userspace/falco # we need it to include indirectly `config_falco.h` file
|
${CMAKE_BINARY_DIR}/userspace/falco # we need it to include indirectly `config_falco.h` file
|
||||||
${CMAKE_SOURCE_DIR}/userspace/engine # we need it to include indirectly `falco_common.h` file
|
${CMAKE_SOURCE_DIR}/userspace/engine # we need it to include indirectly `falco_common.h` file
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}" # we need it to include `falco_test_var.h`
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FALCO_UNIT_TESTS_DEPENDENCIES
|
set(FALCO_UNIT_TESTS_DEPENDENCIES
|
||||||
|
34
unit_tests/falco/app/actions/test_load_config.cpp
Normal file
34
unit_tests/falco/app/actions/test_load_config.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
/*
|
||||||
|
Copyright (C) 2023 The Falco Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless ASSERTd by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "app_action_helpers.h"
|
||||||
|
#include "falco_test_var.h"
|
||||||
|
|
||||||
|
TEST(ActionLoadConfig, check_depracated_falco_038_configs)
|
||||||
|
{
|
||||||
|
auto action = falco::app::actions::load_config;
|
||||||
|
|
||||||
|
// todo!: remove in 0.38.0 since we don't have anymore any precedence
|
||||||
|
{
|
||||||
|
falco::app::state s;
|
||||||
|
s.options.conf_filename = ENGINE_SELECTION_TEST_CONFIG;
|
||||||
|
EXPECT_ACTION_OK(action(s));
|
||||||
|
EXPECT_EQ(s.config->m_modern_ebpf.m_buf_size_preset, 5);
|
||||||
|
EXPECT_TRUE(s.config->m_modern_ebpf.m_drop_failed_exit);
|
||||||
|
EXPECT_EQ(s.config->m_modern_ebpf.m_cpus_for_each_syscall_buffer, 3);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
# Copyright (C) 2023 The Falco Authors.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
################
|
||||||
|
# Falco engine #
|
||||||
|
################
|
||||||
|
|
||||||
|
engine:
|
||||||
|
kind: modern-ebpf
|
||||||
|
kmod:
|
||||||
|
buf_size_preset: 4
|
||||||
|
drop_failed_exit: false
|
||||||
|
ebpf:
|
||||||
|
probe: /path/to/probe.o
|
||||||
|
buf_size_preset: 4
|
||||||
|
drop_failed_exit: false
|
||||||
|
modern-ebpf:
|
||||||
|
cpus_for_each_syscall_buffer: 1
|
||||||
|
buf_size_preset: 5 # This should win over the other config
|
||||||
|
drop_failed_exit: false
|
||||||
|
replay:
|
||||||
|
trace_file: /path/to/file.scap
|
||||||
|
gvisor:
|
||||||
|
config: /path/to/gvisor.yaml
|
||||||
|
root: /gvisor/root
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Falco performance tuning (advanced) #
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
syscall_buf_size_preset: 4
|
||||||
|
|
||||||
|
syscall_drop_failed_exit: true # This should win over the other config
|
||||||
|
|
||||||
|
modern_bpf:
|
||||||
|
cpus_for_each_syscall_buffer: 3 # Should win this 3 over the 1 in the other config
|
3
unit_tests/falco_test_var.h.in
Normal file
3
unit_tests/falco_test_var.h.in
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define ENGINE_SELECTION_TEST_CONFIG "${CMAKE_SOURCE_DIR}/unit_tests/falco/test_configs/test_engine_selection_precedence.yaml"
|
Loading…
Reference in New Issue
Block a user