Skip to content

Commit

Permalink
new(test/e2e,cmake): initial support for e2e tests with container plu…
Browse files Browse the repository at this point in the history
…gin.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Dec 18, 2024
1 parent 7c9c651 commit 9fb9e6a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
32 changes: 32 additions & 0 deletions cmake/modules/container_plugin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.
#

set(CONTAINER_DIR "${PROJECT_BINARY_DIR}/container-prefix/src/container_plugin")
set(CONTAINER_LIBRARY "${CONTAINER_DIR}/libcontainer.so")
if(NOT TARGET container_plugin)
message(STATUS "Building container plugin in '${CONTAINER_DIR}'")
ExternalProject_Add(
container_plugin
PREFIX "${PROJECT_BINARY_DIR}/container-prefix"
GIT_REPOSITORY "https://github.com/FedeDP/container_plugin"
GIT_TAG "main"
# URL_HASH "SHA256="
CONFIGURE_COMMAND ""
BUILD_COMMAND make
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS ${CONTAINER_LIBRARY}
INSTALL_COMMAND ""
)
endif()
12 changes: 8 additions & 4 deletions test/e2e/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ endif()

set(E2E_CONTEXT ${CMAKE_CURRENT_BINARY_DIR}/ctx)

include(container_plugin)

# When running in CI, dump the reports in /tmp/
if(DEFINED ENV{CI})
set(E2E_REPORT /tmp/)
Expand All @@ -34,7 +36,8 @@ add_custom_target(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/driver/scap.ko ${E2E_CONTEXT}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/driver/bpf/probe.o
${E2E_CONTEXT}
DEPENDS sinsp-example driver bpf
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CONTAINER_LIBRARY} ${E2E_CONTEXT}
DEPENDS sinsp-example driver bpf container_plugin
)

add_custom_target(
Expand All @@ -52,8 +55,9 @@ add_custom_target(
# Run e2e tests with the kernel module
COMMAND
docker run --rm --name sinsp-e2e-tester -e KERNEL_MODULE=/driver/scap.ko -e
BPF_PROBE=/driver/probe.o -v /var/run/docker.sock:/var/run/docker.sock -v
${E2E_REPORT}/report:/report sinsp-e2e-tester:latest
BPF_PROBE=/driver/probe.o -e CONTAINER_PLUGIN=/plugins/libcontainer.so -v
/var/run/docker.sock:/var/run/docker.sock -v ${E2E_REPORT}/report:/report
sinsp-e2e-tester:latest
DEPENDS e2e-containers
)

Expand All @@ -62,7 +66,7 @@ add_custom_target(
COMMAND mkdir -p ${E2E_REPORT}/report
# Run e2e tests with the kernel module
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_tests.sh
DEPENDS sinsp-example driver bpf
DEPENDS sinsp-example driver bpf container_plugin
)

# This is a list of containers run by the e2e tests, if you add a different one please add it to the
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/containers/sinsp.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ RUN apt-get update && \
COPY /sinsp-example /usr/local/bin/sinsp-example
COPY /probe.o /driver/probe.o
COPY /scap.ko /driver/scap.ko
COPY /libcontainer.so /plugins/libcontainer.so

ENTRYPOINT [ "sinsp-example", "-j", "-a" ]
ENTRYPOINT [ "sinsp-example", "-j", "-a", "-p", "/plugins/libcontainer.so" ]
1 change: 1 addition & 0 deletions test/e2e/scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ E2E_DIR="${SCRIPT_DIR}/.."
export SINSP_EXAMPLE_PATH=${BUILD_DIR}/libsinsp/examples/sinsp-example
export KERNEL_MODULE=${BUILD_DIR}/driver/scap.ko
export BPF_PROBE=${BUILD_DIR}/driver/bpf/probe.o
export CONTAINER_PLUGIN=${BUILD_DIR}/container-prefix/src/container_plugin/libcontainer.so

if [[ -z "${CI+x}" ]];then
E2E_REPORT="${BUILD_DIR}"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/tests/commons/sinspqa/sinsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def container_spec(image: str = 'sinsp-example:latest', args: list = [], env: di


def process_spec(path: str, args: list, env: dict) -> dict:
args.extend(['-p', os.environ.get('CONTAINER_PLUGIN')])
return {
'path': path,
'args': args,
Expand Down

0 comments on commit 9fb9e6a

Please sign in to comment.