From bc8f61ca68dae5379009b03da91e8491549e7a66 Mon Sep 17 00:00:00 2001 From: Andrea Terzolo Date: Fri, 17 Nov 2023 17:49:32 +0100 Subject: [PATCH] tests: add a basic test to check config precedence Signed-off-by: Andrea Terzolo --- unit_tests/CMakeLists.txt | 9 ++++ .../falco/app/actions/test_load_config.cpp | 34 +++++++++++++ .../test_engine_selection_precedence.yaml | 51 +++++++++++++++++++ unit_tests/falco_test_var.h.in | 3 ++ 4 files changed, 97 insertions(+) create mode 100644 unit_tests/falco/app/actions/test_load_config.cpp create mode 100644 unit_tests/falco/test_configs/test_engine_selection_precedence.yaml create mode 100644 unit_tests/falco_test_var.h.in diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 69a56853..e93ebabb 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -27,10 +27,18 @@ FetchContent_MakeAvailable(googletest) file(GLOB_RECURSE ENGINE_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/engine/*.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 "${ENGINE_TESTS}" falco/test_configuration.cpp falco/app/actions/test_select_event_sources.cpp + falco/app/actions/test_load_config.cpp ) if (CMAKE_SYSTEM_NAME MATCHES "Linux") @@ -45,6 +53,7 @@ set(FALCO_UNIT_TESTS_INCLUDES ${CMAKE_SOURCE_DIR}/userspace ${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_CURRENT_BINARY_DIR}" # we need it to include `falco_test_var.h` ) set(FALCO_UNIT_TESTS_DEPENDENCIES diff --git a/unit_tests/falco/app/actions/test_load_config.cpp b/unit_tests/falco/app/actions/test_load_config.cpp new file mode 100644 index 00000000..3821a936 --- /dev/null +++ b/unit_tests/falco/app/actions/test_load_config.cpp @@ -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); + } +} diff --git a/unit_tests/falco/test_configs/test_engine_selection_precedence.yaml b/unit_tests/falco/test_configs/test_engine_selection_precedence.yaml new file mode 100644 index 00000000..994697de --- /dev/null +++ b/unit_tests/falco/test_configs/test_engine_selection_precedence.yaml @@ -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 diff --git a/unit_tests/falco_test_var.h.in b/unit_tests/falco_test_var.h.in new file mode 100644 index 00000000..208fb67b --- /dev/null +++ b/unit_tests/falco_test_var.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define ENGINE_SELECTION_TEST_CONFIG "${CMAKE_SOURCE_DIR}/unit_tests/falco/test_configs/test_engine_selection_precedence.yaml"