Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Prevent compiling backend tests if dependencies are not installed #4973

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Macro converted to a function and placed in P4CUtils
- The Previous implementation of a macro is now converted to a function and placed in the P4CUtils.cmake file
- Other minor changes are made to improve the functionality.

Signed-off-by: Parth Shitole <f20212907@goa.bits-pilani.ac.in>
  • Loading branch information
ParthShitole committed Oct 24, 2024
commit ae735d856088ecb4df46cabf444128ad6f3a7d86
26 changes: 0 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,32 +282,6 @@ endif()
# enable CTest
enable_testing ()

# Macro to check dependencies before adding tests

macro(CHECK_DEPENDENCIES TEST_DEPENDENCY_PROGRAMS TEST_DEPENDENCY_LIBRARIES)
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)
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)
endif()
endforeach()
endmacro()

# if we want to manage versions in CMake ...
# include (cmake/P4CVersion.cmake)
# set (CPACK_PACKAGE_VERSION_MAJOR ${__P4C_VERSION_MAJOR})
Expand Down
10 changes: 4 additions & 6 deletions backends/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,12 @@ else()
endif()

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

# List of library dependencies
set(TEST_DEPENDENCY_LIBRARIES libpcap-dev gcc-multilib)
set(TEST_DEPENDENCY_LIBRARIES libpcap-dev gcc-multilib scapy)
ParthShitole marked this conversation as resolved.
Show resolved Hide resolved

set(TEST_DEPENDENCY_PRESENT TRUE)

CHECK_DEPENDENCIES("${TEST_DEPENDENCY_PROGRAMS}" "${TEST_DEPENDENCY_LIBRARIES}")
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/")
Expand Down Expand Up @@ -264,7 +262,7 @@ if(TEST_DEPENDENCY_PRESENT)
# 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")
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")
33 changes: 33 additions & 0 deletions cmake/P4CUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,36 @@ 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
function(CHECK_DEPENDENCIES OUT_VAR TEST_DEPENDENCY_PROGRAMS TEST_DEPENDENCY_LIBRARIES)
set(ALL_FOUND TRUE)

foreach(PROG ${TEST_DEPENDENCY_PROGRAMS})
find_program(PROG_PATH ${PROG})
if (NOT 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} at ${PROG_PATH}")
endif()
endforeach()

foreach(LIB ${TEST_DEPENDENCY_LIBRARIES})
find_library(LIB_PATH ${LIB} HINTS "${CMAKE_CURRENT_SOURCE_DIR}/runtime/usr/lib64/")
if (NOT LIB_PATH)
message(WARNING "Missing library ${LIB}."
" Please install ${LIB}.")
set(ALL_FOUND FALSE)
else()
message(STATUS "Found library ${LIB} at ${LIB_PATH}")
endif()
endforeach()

if (ALL_FOUND)
set(${OUT_VAR} TRUE PARENT_SCOPE)
else()
set(${OUT_VAR} FALSE PARENT_SCOPE)
endif()
endfunction()