mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-17 00:01:52 +00:00
test: first scaffolfing of the initial structure
Signed-off-by: Andrea Terzolo <andrea.terzolo@polito.it>
This commit is contained in:
parent
dca76ba93c
commit
88bac44f05
@ -18,6 +18,7 @@ option(USE_BUNDLED_DEPS "Bundle hard to find dependencies into the Falco binary"
|
|||||||
option(BUILD_WARNINGS_AS_ERRORS "Enable building with -Wextra -Werror flags" OFF)
|
option(BUILD_WARNINGS_AS_ERRORS "Enable building with -Wextra -Werror flags" OFF)
|
||||||
option(MINIMAL_BUILD "Build a minimal version of Falco, containing only the engine and basic input/output (EXPERIMENTAL)" OFF)
|
option(MINIMAL_BUILD "Build a minimal version of Falco, containing only the engine and basic input/output (EXPERIMENTAL)" OFF)
|
||||||
option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
|
option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
|
||||||
|
option(BUILD_FALCO_UNIT_TESTS "Build falco unit tests" OFF)
|
||||||
|
|
||||||
# gVisor is currently only supported on Linux x86_64
|
# gVisor is currently only supported on Linux x86_64
|
||||||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT MINIMAL_BUILD)
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT MINIMAL_BUILD)
|
||||||
@ -223,3 +224,7 @@ include(falcoctl)
|
|||||||
|
|
||||||
# Packages configuration
|
# Packages configuration
|
||||||
include(CPackConfig)
|
include(CPackConfig)
|
||||||
|
|
||||||
|
if(BUILD_FALCO_UNIT_TESTS)
|
||||||
|
add_subdirectory(unit_tests)
|
||||||
|
endif()
|
||||||
|
65
unit_tests/CMakeLists.txt
Normal file
65
unit_tests/CMakeLists.txt
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
message(STATUS "Falco unit tests build enabled")
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG release-1.12.1
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
set(FALCO_UNIT_TESTS_SOURCES
|
||||||
|
"${ENGINE_TESTS}"
|
||||||
|
"${FALCO_TESTS}"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FALCO_UNIT_TESTS_INCLUDES
|
||||||
|
PRIVATE
|
||||||
|
${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
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FALCO_UNIT_TESTS_DEPENDENCIES
|
||||||
|
gtest
|
||||||
|
gtest_main
|
||||||
|
falco_engine
|
||||||
|
sinsp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FALCO_UNIT_TESTS_LIBRARIES
|
||||||
|
gtest
|
||||||
|
gtest_main
|
||||||
|
falco_engine
|
||||||
|
sinsp
|
||||||
|
)
|
||||||
|
|
||||||
|
message(STATUS "FALCO_UNIT_TESTS_SOURCES: ${FALCO_UNIT_TESTS_SOURCES}")
|
||||||
|
message(STATUS "FALCO_UNIT_TESTS_INCLUDES: ${FALCO_UNIT_TESTS_INCLUDES}")
|
||||||
|
message(STATUS "FALCO_UNIT_TESTS_DEPENDENCIES: ${FALCO_UNIT_TESTS_DEPENDENCIES}")
|
||||||
|
message(STATUS "FALCO_UNIT_TESTS_LIBRARIES: ${FALCO_UNIT_TESTS_LIBRARIES}")
|
||||||
|
|
||||||
|
add_executable(falco_unit_tests ${FALCO_UNIT_TESTS_SOURCES})
|
||||||
|
target_include_directories(falco_unit_tests ${FALCO_UNIT_TESTS_INCLUDES})
|
||||||
|
target_link_libraries(falco_unit_tests ${FALCO_UNIT_TESTS_DEPENDENCIES})
|
||||||
|
add_dependencies(falco_unit_tests ${FALCO_UNIT_TESTS_LIBRARIES})
|
||||||
|
|
||||||
|
# add_test(multiply_gtests falco_unit_tests)
|
12
unit_tests/README.md
Normal file
12
unit_tests/README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Falco unit tests
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
Under `unit_tests/engine` and `unit_tests/falco` directories, we have different test suites that could be a single file or an entire directory according to the number and the complexity of tests.
|
||||||
|
|
||||||
|
## Build and Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cmake -DMINIMAL_BUILD=On -DBUILD_BPF=Off -DBUILD_DRIVER=Off -DBUILD_FALCO_UNIT_TESTS=On ..
|
||||||
|
make falco_unit_tests
|
||||||
|
```
|
38
unit_tests/engine/test_falco_utils.cpp
Normal file
38
unit_tests/engine/test_falco_utils.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <engine/falco_utils.h>
|
||||||
|
|
||||||
|
TEST(FalcoUtils, is_unix_scheme)
|
||||||
|
{
|
||||||
|
/* Wrong prefix */
|
||||||
|
ASSERT_EQ(falco::utils::network::is_unix_scheme("something:///run/falco/falco.sock"), false);
|
||||||
|
|
||||||
|
/* Similar prefix, but wrong */
|
||||||
|
ASSERT_EQ(falco::utils::network::is_unix_scheme("unix///falco.sock"), false);
|
||||||
|
|
||||||
|
/* Right prefix, passed as an `rvalue` */
|
||||||
|
ASSERT_EQ(falco::utils::network::is_unix_scheme("unix:///falco.sock"), true);
|
||||||
|
|
||||||
|
/* Right prefix, passed as a `std::string` */
|
||||||
|
std::string url_string("unix:///falco.sock");
|
||||||
|
ASSERT_EQ(falco::utils::network::is_unix_scheme(url_string), true);
|
||||||
|
|
||||||
|
/* Right prefix, passed as a `char[]` */
|
||||||
|
char url_char[] = "unix:///falco.sock";
|
||||||
|
ASSERT_EQ(falco::utils::network::is_unix_scheme(url_char), true);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user