diff --git a/backends/ebpf/CMakeLists.txt b/backends/ebpf/CMakeLists.txt index 5f6c896d4be..ab4bbd98733 100644 --- a/backends/ebpf/CMakeLists.txt +++ b/backends/ebpf/CMakeLists.txt @@ -221,6 +221,14 @@ else() set (SUPPORTS_KERNEL False) endif() +# List of executable dependencies +set(TEST_DEPENDENCY_PROGRAMS gcc-multilib) + +# List of library dependencies +set(TEST_DEPENDENCY_LIBRARIES python3-six libgmp-dev libjansson-dev) + +CHECK_DEPENDENCIES(TEST_DEPENDENCY_PRESENT "${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) @@ -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") diff --git a/cmake/P4CUtils.cmake b/cmake/P4CUtils.cmake index 509c90f7b16..bd411a4156f 100644 --- a/cmake/P4CUtils.cmake +++ b/cmake/P4CUtils.cmake @@ -420,3 +420,46 @@ function(get_all_targets _result _dir) get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS) set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE) endfunction() + +# Checks for presence of programs and dependencies +# This function supports a optional parameter HINTS_DIRS. +# In case cmake is unable to find a library even if it is present, +# you can pass the exact directory path as the last parameter of this function. +# Eg. CHECK_DEPENDENCIES(VAR "${TEST_PROGRAMS}" "${TEST_LIBRARIES}" "${HINTS_DIRS}") +function(CHECK_DEPENDENCIES OUT_VAR TEST_DEPENDENCY_PROGRAMS TEST_DEPENDENCY_LIBRARIES) + set(ALL_FOUND TRUE) + + foreach(PROG ${TEST_DEPENDENCY_PROGRAMS}) + find_program(${PROG}_PROG_PATH ${PROG} NO_CACHE) + if (NOT ${PROG}_PROG_PATH) + message(WARNING "Missing program ${PROG}." + " Please install ${PROG} and ensure it is in your PATH.") + set(ALL_FOUND FALSE) + else() + message(STATUS "Found program ${PROG}") + endif() + endforeach() + + foreach(LIB ${TEST_DEPENDENCY_LIBRARIES}) + if (ARGC GREATER 3) + set(HINTS_DIRS_ARG ${ARGV4}) + find_library(${LIB}_LIB_PATH NAMES ${LIB} NO_CACHE HINTS ${HINTS_DIRS}) + else() + find_library(${LIB}_LIB_PATH NAMES ${LIB} NO_CACHE) + endif() + + if (NOT ${LIB}_LIB_PATH) + message(WARNING "Missing library ${LIB}." + " Please install ${LIB}.") + set(ALL_FOUND FALSE) + else() + message(STATUS "Found library ${LIB}") + endif() + endforeach() + + if (ALL_FOUND) + set(${OUT_VAR} TRUE PARENT_SCOPE) + else() + set(${OUT_VAR} FALSE PARENT_SCOPE) + endif() +endfunction() \ No newline at end of file