Skip to content

Commit eebd7bf

Browse files
committed
Add a utility to check the Kernel version.
Signed-off-by: fruffy <[email protected]>
1 parent ea11a88 commit eebd7bf

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

backends/ebpf/CMakeLists.txt

+5-18
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,8 @@ set (EBPF_ERRORS_SUITES
182182
"${P4C_SOURCE_DIR}/testdata/p4_16_ebpf_errors/*.p4"
183183
)
184184

185-
# determine the kernel version
186-
execute_process(COMMAND uname -r
187-
OUTPUT_VARIABLE P4C_EBPF_KERNEL_VER
188-
OUTPUT_STRIP_TRAILING_WHITESPACE
189-
RESULT_VARIABLE rc)
190-
message(STATUS "Detected kernel version: ${P4C_EBPF_KERNEL_VER}")
191-
# Check if the kernel version is new enough to support ebpf features
192-
set (MIN_KERNEL 4.15.0)
193-
string (REGEX MATCH "[0-9]+[^-]*" KERNEL_VER ${CMAKE_SYSTEM})
194-
if (${KERNEL_VER} VERSION_LESS ${MIN_KERNEL} )
195-
MESSAGE(WARNING "Kernel version ${KERNEL_VER} too small, expected ${MIN_KERNEL}. Ignoring ebpf kernel tests...")
196-
set (SUPPORTS_KERNEL False)
197-
else()
198-
set (SUPPORTS_KERNEL True)
199-
endif()
185+
include(CheckLinuxKernel)
186+
check_minimum_kernel_version("4.15.0" SUPPORTS_KERNEL)
200187

201188
# Check if we have the right llvm version
202189
set (MIN_LLVM 3.7.1)
@@ -212,14 +199,14 @@ if (NOT LLVM_RET)
212199
if (${LLVM_PACKAGE_VERSION} VERSION_LESS ${MIN_LLVM})
213200
message(WARNING "LLVM version ${LLVM_PACKAGE_VERSION} too small, expected ${MIN_LLVM}.
214201
Ignoring ebpf tests...")
215-
set (SUPPORTS_KERNEL False)
202+
set (SUPPORTS_KERNEL FALSE)
216203
endif()
217204
else()
218205
message(WARNING
219206
"Did not find an LLVM version that can compile the eBPF kernel tests...\n"
220207
"'llvm-config' reason: ${LLVM_PACKAGE_VERSION}\n"
221208
"'llvm-config' return value: ${LLVM_RET}" )
222-
set (SUPPORTS_KERNEL False)
209+
set (SUPPORTS_KERNEL FALSE)
223210
endif()
224211

225212
# check for the libbpf library
@@ -230,7 +217,7 @@ else()
230217
message(WARNING "Missing the libbpf dependency, disabling kernel tests."
231218
" You can install libbpf by running './build_libbpf' in the "
232219
"${CMAKE_CURRENT_SOURCE_DIR} folder.")
233-
set (SUPPORTS_KERNEL False)
220+
set (SUPPORTS_KERNEL FALSE)
234221
endif()
235222

236223
# Only add the kernel tests if the two requirements are met

backends/tc/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,16 @@ macro(p4tc_add_test_with_args tag driver isXfail alias p4test test_args cmake_ar
133133
set_tests_properties(${__testname} PROPERTIES TIMEOUT 1000)
134134
endmacro(p4tc_add_test_with_args)
135135

136-
p4c_add_tests("p4tc" ${P4TC_COMPILER_DRIVER} "${P4_16_SUITES}" "")
136+
include(CheckLinuxKernel)
137+
check_minimum_kernel_version("5.0.0" SUPPORTS_KERNEL)
137138

138139
set(ENABLE_P4TC_STF_TESTS ON)
140+
141+
if (SUPPORTS_KERNEL)
142+
p4c_add_tests("p4tc" ${P4TC_COMPILER_DRIVER} "${P4_16_SUITES}" "")
143+
set(ENABLE_P4TC_STF_TESTS OFF)
144+
endif()
145+
139146
# brctl is required for the P4TC STF tests.
140147
find_program(BRCTL_EXEC brctl)
141148
# clang is required for the P4TC STF tests.

0 commit comments

Comments
 (0)