Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore(libs): apply code formatting #2051

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
71 changes: 35 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@
#
# 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
# 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
# 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.
# 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.
#

# Prior to doing anything, we make sure that we aren't trying to
# run cmake in-tree.
# Prior to doing anything, we make sure that we aren't trying to run cmake in-tree.
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/CMakeLists.txt)
message(FATAL_ERROR
"Looks like you are trying to run CMake from the base source directory.\n"
"** RUNNING CMAKE FROM THE BASE DIRECTORY WILL NOT WORK **\n"
"To Fix:\n"
" 1. Remove the CMakeCache.txt file in this directory. ex: rm CMakeCache.txt\n"
" 2. Create a build directory from here. ex: mkdir build\n"
" 3. cd into that directory. ex: cd build\n"
" 4. Run cmake from the build directory. ex: cmake ..\n"
" 5. Run make from the build directory. ex: make\n"
"Full paste-able example:\n"
"( rm -f CMakeCache.txt; mkdir build; cd build; cmake ..; make )")
message(
FATAL_ERROR
"Looks like you are trying to run CMake from the base source directory.\n"
"** RUNNING CMAKE FROM THE BASE DIRECTORY WILL NOT WORK **\n"
"To Fix:\n"
" 1. Remove the CMakeCache.txt file in this directory. ex: rm CMakeCache.txt\n"
" 2. Create a build directory from here. ex: mkdir build\n"
" 3. cd into that directory. ex: cd build\n"
" 4. Run cmake from the build directory. ex: cmake ..\n"
" 5. Run make from the build directory. ex: make\n"
"Full paste-able example:\n"
"( rm -f CMakeCache.txt; mkdir build; cd build; cmake ..; make )"
)
endif()

cmake_minimum_required(VERSION 3.12)
Expand All @@ -38,8 +37,8 @@ if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()

# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows + CMake >= 3.15 and link
# with the static (MultiThreaded) CRT unless instructed otherwise.
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows + CMake >= 3.15 and link with the static
# (MultiThreaded) CRT unless instructed otherwise.
if(NOT (CMAKE_MSVC_RUNTIME_LIBRARY OR BUILD_SHARED_LIBS))
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
Expand All @@ -54,9 +53,13 @@ endif()
project(falcosecurity-libs)

option(USE_BUNDLED_DEPS "Enable bundled dependencies instead of using the system ones" ON)
option(MINIMAL_BUILD "Produce a minimal build with only the essential features (no container metadata)" OFF)
option(MINIMAL_BUILD
"Produce a minimal build with only the essential features (no container metadata)" OFF
)
option(MUSL_OPTIMIZED_BUILD "Enable if you want a musl optimized build" OFF)
option(USE_BUNDLED_DRIVER "Use the driver/ subdirectory in the build process (only available in Linux)" ON)
option(USE_BUNDLED_DRIVER
"Use the driver/ subdirectory in the build process (only available in Linux)" ON
)
option(ENABLE_DRIVERS_TESTS "Enable driver tests (bpf, kernel module, modern bpf)" OFF)
option(ENABLE_LIBSCAP_TESTS "Enable libscap unit tests" OFF)
option(ENABLE_LIBSINSP_E2E_TESTS "Enable libsinsp e2e tests" OFF)
Expand All @@ -76,8 +79,7 @@ endif()
include(GNUInstallDirs)

# Add path for custom CMake modules.
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

include(versions)

Expand Down Expand Up @@ -113,7 +115,7 @@ if(CREATE_TEST_TARGETS)
include(gtest)
endif()

if (BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
get_shared_libs_versions(FALCOSECURITY_SHARED_LIBS_VERSION FALCOSECURITY_SHARED_LIBS_SOVERSION)
message(STATUS "Shared library version: ${FALCOSECURITY_SHARED_LIBS_VERSION}")
message(STATUS "Shared library soversion: ${FALCOSECURITY_SHARED_LIBS_SOVERSION}")
Expand All @@ -123,12 +125,9 @@ include(libscap)
include(libsinsp)

if(CREATE_TEST_TARGETS)
# Add command to run all unit tests at once via the make system.
# This is preferred vs using ctest's add_test because it will build
# the code and output to stdout.
add_custom_target(run-unit-tests
COMMAND ${CMAKE_MAKE_PROGRAM} run-unit-test-libsinsp
)
# Add command to run all unit tests at once via the make system. This is preferred vs using
# ctest's add_test because it will build the code and output to stdout.
add_custom_target(run-unit-tests COMMAND ${CMAKE_MAKE_PROGRAM} run-unit-test-libsinsp)

add_subdirectory(test/e2e)

Expand All @@ -155,4 +154,4 @@ endif()
option(ENABLE_BENCHMARKS "Enable Benchmarks" OFF)
if(ENABLE_BENCHMARKS)
add_subdirectory(benchmark)
endif()
endif()
37 changes: 18 additions & 19 deletions CMakeListsGtestInclude.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
#
# 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
# 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
# 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.
# 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.
#

cmake_minimum_required(VERSION 3.12)

project(googletest-download NONE)

include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "release-1.12.1"
SOURCE_DIR "${PROJECT_BINARY_DIR}/googletest-src"
BINARY_DIR "${PROJECT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
TEST_COMMAND ""
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG "release-1.12.1"
SOURCE_DIR "${PROJECT_BINARY_DIR}/googletest-src"
BINARY_DIR "${PROJECT_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
TEST_COMMAND ""
)
12 changes: 5 additions & 7 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
#
# Copyright (C) 2024 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
# 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
# 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.
#

Expand Down
36 changes: 14 additions & 22 deletions benchmark/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,48 @@ limitations under the License.
#include <libsinsp/utils.h>
#include <benchmark/benchmark.h>

static void BM_sinsp_split(benchmark::State& state)
{
static void BM_sinsp_split(benchmark::State& state) {
std::string str = "hello,world,";
for(auto _ : state)
{
for(auto _ : state) {
sinsp_split(str, ',');
}
}
BENCHMARK(BM_sinsp_split);

static void BM_sinsp_concatenate_paths_relative_path(benchmark::State& state)
{
static void BM_sinsp_concatenate_paths_relative_path(benchmark::State& state) {
std::string path1 = "/tmp/";
std::string path2 = "foo/bar";
for(auto _ : state)
{
for(auto _ : state) {
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_relative_path);

static void BM_sinsp_concatenate_paths_empty_path(benchmark::State& state)
{
static void BM_sinsp_concatenate_paths_empty_path(benchmark::State& state) {
std::string path1 = "/tmp/";
std::string path2 = "";
for(auto _ : state)
{
for(auto _ : state) {
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_empty_path);

static void BM_sinsp_concatenate_paths_absolute_path(benchmark::State& state)
{
static void BM_sinsp_concatenate_paths_absolute_path(benchmark::State& state) {
std::string path1 = "/tmp/";
std::string path2 = "/foo/bar";
for(auto _ : state)
{
for(auto _ : state) {
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_absolute_path);

static void BM_sinsp_split_container_image(benchmark::State& state)
{
std::string container_image = "localhost:12345/library/busybox:1.27.2@sha256:da39a3ee5e6b4b0d3255bfef95601890afd80709";
static void BM_sinsp_split_container_image(benchmark::State& state) {
std::string container_image =
"localhost:12345/library/"
"busybox:1.27.2@sha256:da39a3ee5e6b4b0d3255bfef95601890afd80709";
std::string hostname, port, name, tag, digest;
for(auto _ : state)
{
for(auto _ : state) {
sinsp_utils::split_container_image(container_image, hostname, port, name, tag, digest);
}
}
BENCHMARK(BM_sinsp_split_container_image);
BENCHMARK(BM_sinsp_split_container_image);
2 changes: 1 addition & 1 deletion benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ limitations under the License.

#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
BENCHMARK_MAIN();
Loading
Loading