Skip to content

Commit

Permalink
backends/ebpf: Prevent compiling backend tests if dependencies are no…
Browse files Browse the repository at this point in the history
…t installed

- The added code checks for required dependencies before adding tests.
- This makes sures the Test don't fail due to missing dependencies.

Signed-off-by: Parth Shitole <f20212907@goa.bits-pilani.ac.in>
  • Loading branch information
root authored and ParthShitole committed Oct 23, 2024
1 parent b4a9df0 commit 6149a81
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,33 @@ endif()
# enable CTest
enable_testing ()

# Macro to check dependencies before adding tests

macro(CHECK_DEPENDENCIES TEST_DEPENDENCY_PROGRAMS TEST_DEPENDENCY_LIBRARIES)
set(TEST_DEPENDENCY_PRESENT TRUE PARENT_SCOPE)

foreach(PROG ${TEST_DEPENDENCY_PROGRAMS})
find_program(${PROG}_FOUND ${PROG})
if (${PROG}_FOUND)
message(STATUS "Found program ${PROG} at ${${PROG}_FOUND}")
else()
message(WARNING "Missing program ${PROG}, disabling relevant tests."
" Please install ${PROG} and ensure it is in your PATH.")
set(TEST_DEPENDENCY_PRESENT FALSE PARENT_SCOPE)
endif()
endforeach()

foreach(LIB ${TEST_DEPENDENCY_LIBRARIES})
find_library(${LIB}_FOUND ${LIB} HINTS "${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/")
if (${LIB}_FOUND)
message(STATUS "Found library ${LIB} at ${${LIB}_FOUND}")
else()
message(WARNING "Missing library ${LIB}, disabling relevant tests."
" Please install ${LIB}.")
set(TEST_DEPENDENCY_PRESENT FALSE PARENT_SCOPE)
endif()
endforeach()
endmacro()

# if we want to manage versions in CMake ...
# include (cmake/P4CVersion.cmake)
Expand Down
50 changes: 31 additions & 19 deletions backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ else()
set (SUPPORTS_KERNEL False)
endif()

# List of executable dependencies
set(TEST_DEPENDENCY_PROGRAMS scapy tcpdump pcap)

# List of library dependencies
set(TEST_DEPENDENCY_LIBRARIES libpcap-dev gcc-multilib)

CHECK_DEPENDENCIES("${TEST_DEPENDENCY_PROGRAMS}" "${TEST_DEPENDENCY_LIBRARIES}")

# check for the libbpf library
find_library(LIBBPF NAMES bpf HINTS "${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/")
if (LIBBPF)
Expand All @@ -232,25 +240,29 @@ else()
set (SUPPORTS_KERNEL False)
endif()

# Only add the kernel tests if the two requirements are met
if (SUPPORTS_KERNEL)
p4c_add_tests("ebpf-kernel" ${EBPF_DRIVER_KERNEL} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_KERNEL}")
p4c_add_tests("ebpf-kernel" ${EBPF_DRIVER_KERNEL} ${EBPF_KERNEL_TEST_SUITES} "${XFAIL_TESTS_KERNEL}")
# These are special tests with args that are not included
# in the default ebpf tests
p4c_add_test_with_args("ebpf-kernel" ${EBPF_DRIVER_KERNEL} FALSE "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-conntrack-ebpf.c" "")
p4c_add_test_with_args("ebpf-kernel" ${EBPF_DRIVER_KERNEL} FALSE "testdata/p4_16_samples/ebpf_checksum_extern.p4" "testdata/p4_16_samples/ebpf_checksum_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-checksum-ebpf.c" "")
endif()
# ToDo Add check which verifies that BCC is installed
# Ideally, this is done via check for the python package
p4c_add_tests("ebpf-bcc" ${EBPF_DRIVER_BCC} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_BCC}")
p4c_add_tests("ebpf" ${EBPF_DRIVER_TEST} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_TEST}")
p4c_add_tests("ebpf-errors" ${EBPF_DRIVER_TEST} ${EBPF_ERRORS_SUITES} "${XFAIL_TESTS_TEST}")
if(TEST_DEPENDENCY_PRESENT)
# Only add the kernel tests if the two requirements are met
if (SUPPORTS_KERNEL)
p4c_add_tests("ebpf-kernel" ${EBPF_DRIVER_KERNEL} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_KERNEL}")
p4c_add_tests("ebpf-kernel" ${EBPF_DRIVER_KERNEL} ${EBPF_KERNEL_TEST_SUITES} "${XFAIL_TESTS_KERNEL}")
# These are special tests with args that are not included
# in the default ebpf tests
p4c_add_test_with_args("ebpf-kernel" ${EBPF_DRIVER_KERNEL} FALSE "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-conntrack-ebpf.c" "")
p4c_add_test_with_args("ebpf-kernel" ${EBPF_DRIVER_KERNEL} FALSE "testdata/p4_16_samples/ebpf_checksum_extern.p4" "testdata/p4_16_samples/ebpf_checksum_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-checksum-ebpf.c" "")
endif()
# ToDo Add check which verifies that BCC is installed
# Ideally, this is done via check for the python package
p4c_add_tests("ebpf-bcc" ${EBPF_DRIVER_BCC} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_BCC}")
p4c_add_tests("ebpf" ${EBPF_DRIVER_TEST} ${EBPF_TEST_SUITES} "${XFAIL_TESTS_TEST}")
p4c_add_tests("ebpf-errors" ${EBPF_DRIVER_TEST} ${EBPF_ERRORS_SUITES} "${XFAIL_TESTS_TEST}")

# These are special tests with args that are not included in the default ebpf tests
p4c_add_test_with_args("ebpf" ${EBPF_DRIVER_TEST} FALSE "testdata/p4_16_samples/ebpf_checksum_extern.p4" "testdata/p4_16_samples/ebpf_checksum_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-checksum-ebpf.c" "")
# FIXME:This does not work yet
# We do not have support for dynamic addition of tables in the test framework
p4c_add_test_with_args("ebpf" ${EBPF_DRIVER_TEST} TRUE "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-conntrack-ebpf.c" "")
# These are special tests with args that are not included in the default ebpf tests
p4c_add_test_with_args("ebpf" ${EBPF_DRIVER_TEST} FALSE "testdata/p4_16_samples/ebpf_checksum_extern.p4" "testdata/p4_16_samples/ebpf_checksum_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-checksum-ebpf.c" "")
# FIXME:This does not work yet
# We do not have support for dynamic addition of tables in the test framework
p4c_add_test_with_args("ebpf" ${EBPF_DRIVER_TEST} TRUE "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "testdata/p4_16_samples/ebpf_conntrack_extern.p4" "--extern-file ${P4C_SOURCE_DIR}/testdata/extern_modules/extern-conntrack-ebpf.c" "")
else()
message(WARNING "Skipped adding Tests due to missing dependencies. Please install the dependencies and try again")
endif()

message(STATUS "Done with configuring BPF back end")

0 comments on commit 6149a81

Please sign in to comment.