cmakefile (#1075)
This commit is contained in:
Родитель
b7df2bec27
Коммит
6b98a8d384
|
@ -38,7 +38,7 @@ jobs:
|
|||
if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'
|
||||
uses: ./.github/workflows/reusable-build.yml
|
||||
with:
|
||||
build_artifact: Build-x64
|
||||
build_artifact: Build-x64-vcxproj
|
||||
generate_release_package: true
|
||||
|
||||
cmake:
|
||||
|
@ -46,7 +46,7 @@ jobs:
|
|||
if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'
|
||||
uses: ./.github/workflows/reusable-cmake-build.yml
|
||||
with:
|
||||
build_artifact: Build-x64-cmake
|
||||
build_artifact: Build-x64
|
||||
|
||||
# Run the unit tests in GitHub.
|
||||
unit_tests:
|
||||
|
@ -56,7 +56,7 @@ jobs:
|
|||
with:
|
||||
name: unit_tests
|
||||
test_command: unit_tests.exe -d yes
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
environment: windows-2019
|
||||
code_coverage: true
|
||||
|
@ -72,7 +72,7 @@ jobs:
|
|||
pre_test: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat"
|
||||
test_command: bpf2c_tests.exe -d yes
|
||||
name: bpf2c
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
environment: windows-2019
|
||||
code_coverage: true
|
||||
|
@ -90,7 +90,7 @@ jobs:
|
|||
test_command: powershell ".\execute_ebpf_cicd_tests.ps1"
|
||||
post_test: powershell ".\cleanup_ebpf_cicd_tests.ps1"
|
||||
name: driver
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
environment: ebpf_cicd_tests
|
||||
# driver test copies dumps to testlog folder.
|
||||
|
@ -103,7 +103,7 @@ jobs:
|
|||
if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'
|
||||
uses: ./.github/workflows/ossar-scan.yml
|
||||
with:
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
|
||||
# Additional jobs to run on pull and schedule only (skip push).
|
||||
|
@ -148,7 +148,7 @@ jobs:
|
|||
with:
|
||||
name: cilium_tests
|
||||
test_command: cilium_tests.exe -d yes
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
environment: windows-2019
|
||||
code_coverage: false
|
||||
|
@ -163,7 +163,7 @@ jobs:
|
|||
name: stress
|
||||
# Until there is a dedicated stress test, re-use the perf test.
|
||||
test_command: ebpf_performance.exe
|
||||
build_job: regular / build
|
||||
build_job: cmake / build
|
||||
build_artifact: Build-x64
|
||||
environment: windows-2019
|
||||
# No code coverage on stress.
|
||||
|
|
|
@ -38,6 +38,12 @@ jobs:
|
|||
with:
|
||||
submodules: 'recursive'
|
||||
|
||||
- name: Install tools
|
||||
working-directory: ${{env.GITHUB_WORKSPACE}}
|
||||
run: |
|
||||
choco install -y llvm --version 11.0.1 --allow-downgrade
|
||||
echo "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
|
||||
- name: Cache nuget packages
|
||||
uses: actions/cache@f63a711791a8e7cc2d5463afc081136e00085800
|
||||
env:
|
||||
|
@ -58,6 +64,28 @@ jobs:
|
|||
run: |
|
||||
cmake --build build --config ${{env.BUILD_CONFIGURATION }}
|
||||
|
||||
# Download and extract demo repo artifacts. These then get uploaded along with the build artifacts.
|
||||
# The subequent tests will directly get these when they download the build artifacts. In case
|
||||
# a test fails, the .o files used for the test will be available in the uploaded build artifacts.
|
||||
- name: Download demo repository artifacts
|
||||
uses: dawidd6/action-download-artifact@b2abf1705491048a2d7074f7d90513044fd25d39
|
||||
with:
|
||||
github_token: ${{secrets.GITHUB_TOKEN}}
|
||||
workflow: cicd.yml
|
||||
workflow_conclusion: success
|
||||
name: x64-${{ matrix.configurations }}-cilium-xdp
|
||||
path: ${{github.workspace}}
|
||||
repo: microsoft/ebpf-for-windows-demo
|
||||
check_artifacts: false
|
||||
search_artifacts: false
|
||||
skip_unpack: false
|
||||
|
||||
- name: Extract artifacts to build path
|
||||
working-directory: ${{env.GITHUB_WORKSPACE}}
|
||||
run: |
|
||||
cd ${{github.workspace}}/build/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
|
||||
tar -xf ..\..\..\x64-${{ matrix.configurations }}-cilium-xdp.zip
|
||||
|
||||
- name: Upload Build Output
|
||||
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
||||
with:
|
||||
|
|
|
@ -8,6 +8,9 @@ cmake_minimum_required(VERSION 3.20)
|
|||
# SDK which corresponds to 19041.
|
||||
set(CMAKE_SYSTEM_VERSION 10.0.19041.0)
|
||||
|
||||
# Uncomment the following line for debugging project dependencies.
|
||||
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
|
||||
|
||||
project("ebpf-for-windows")
|
||||
|
||||
include("cmake/options.cmake")
|
||||
|
@ -15,6 +18,7 @@ include("cmake/settings.cmake")
|
|||
include("cmake/git_commit.cmake")
|
||||
include("cmake/codesign.cmake")
|
||||
include("cmake/midl_compiler_finder.cmake")
|
||||
include("cmake/process_bpf_source_file.cmake")
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH
|
||||
"${CMAKE_SOURCE_DIR}/external/FindWDK/cmake"
|
||||
|
@ -23,15 +27,15 @@ list(APPEND CMAKE_MODULE_PATH
|
|||
locateMidlCompiler()
|
||||
find_package(WDK REQUIRED)
|
||||
|
||||
add_subdirectory("external")
|
||||
add_subdirectory("rpc_interface")
|
||||
add_subdirectory("ebpfapi")
|
||||
add_subdirectory("libs")
|
||||
add_subdirectory("tools")
|
||||
add_subdirectory("ebpfsvc")
|
||||
add_subdirectory("netebpfext")
|
||||
add_subdirectory("ebpfcore")
|
||||
add_subdirectory("ebpfsvc")
|
||||
add_subdirectory("external")
|
||||
add_subdirectory("libs")
|
||||
add_subdirectory("netebpfext")
|
||||
add_subdirectory("rpc_interface")
|
||||
add_subdirectory("scripts")
|
||||
add_subdirectory("tools")
|
||||
|
||||
if(EBPFFORWINDOWS_ENABLE_TESTS)
|
||||
include("CTest")
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set (output_dir ${CMAKE_BINARY_DIR}/x64/$<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>)
|
||||
|
||||
function(add_bpftonative_command file_name kernel_mode unsafe_program)
|
||||
find_program(powershell_path "powershell" REQUIRED)
|
||||
if (${kernel_mode} STREQUAL "$true")
|
||||
set (output_file ${output_dir}/${file_name}.sys)
|
||||
else()
|
||||
set (output_file ${output_dir}/${file_name}_um.dll)
|
||||
endif()
|
||||
|
||||
set(command_line ${powershell_path} -NonInteractive -ExecutionPolicy Unrestricted ${CMAKE_SOURCE_DIR}/scripts/Convert-BpfToNative.ps1 -ProgramName ${file_name} -SolutionDir ${CMAKE_SOURCE_DIR} -OutputDir ${output_dir} -Platform x64 -Configuration $(Configuration) -KernelMode ${kernel_mode})
|
||||
|
||||
set (input_file ${output_dir}/${file_name}.o)
|
||||
if (${unsafe_program})
|
||||
set(output_file $<$<CONFIG:Debug>:${output_file}>$<$<CONFIG:Release>:${dummy}>)
|
||||
string(JOIN " " command_line_string ${command_line})
|
||||
set(command_line ${command_line} -SkipVerification $true)
|
||||
set(input_file $<$<CONFIG:Debug>:${input_file}>$<$<CONFIG:Release>:${dummy}>)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${output_file}
|
||||
COMMAND
|
||||
${command_line}
|
||||
DEPENDS
|
||||
${input_file}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(build_bpf_samples unsafe_program)
|
||||
file(GLOB files *.c)
|
||||
|
||||
get_filename_component(target_name ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||
|
||||
foreach(file ${files})
|
||||
get_filename_component(file_name ${file} NAME_WE)
|
||||
set (sources_list ${sources_list}; ${file})
|
||||
set (elf_list ${elf_list};${output_dir}/${file_name}.o)
|
||||
set (native_driver_list ${native_driver_list}; ${output_dir}/${file_name}.sys; ${output_dir}/${file_name}_um.dll)
|
||||
if (${unsafe_program})
|
||||
set (native_driver_list $<$<CONFIG:Debug>:${native_driver_list}>$<$<CONFIG:Release>:${dummy}>)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_custom_target(${target_name}_elf DEPENDS ${elf_list} SOURCES ${sources_list})
|
||||
|
||||
add_custom_target(${target_name}_native ALL DEPENDS "${native_driver_list}" SOURCES ${elf_list})
|
||||
add_dependencies(${target_name}_native ${target_name}_elf "bpf2c")
|
||||
|
||||
set_target_properties(${target_name}_elf PROPERTIES VS_GLOBAL_ClangFlags "-g -target bpf -O2 -Werror")
|
||||
set_target_properties(${target_name}_elf PROPERTIES VS_GLOBAL_IncludePath
|
||||
"-I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/external/bpftool -I${CMAKE_SOURCE_DIR}/tests/xdp -I${CMAKE_SOURCE_DIR}/tests/socket -I${CMAKE_SOURCE_DIR}/tests/sample/ext/inc")
|
||||
|
||||
foreach(file ${files})
|
||||
get_filename_component(file_name ${file} NAME_WE)
|
||||
find_program(clang_path "clang" REQUIRED)
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${output_dir}/${file_name}.o
|
||||
COMMAND
|
||||
${clang_path} "$(ClangFlags)" "$(IncludePath)" -c ${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.c -o ${output_dir}/${file_name}.o
|
||||
DEPENDS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${file_name}.c
|
||||
)
|
||||
add_bpftonative_command(${file_name} "$true" ${unsafe_program})
|
||||
add_bpftonative_command(${file_name} "$false" ${unsafe_program})
|
||||
endforeach()
|
||||
|
||||
endfunction()
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set (output_dir PUBLIC ${CMAKE_BINARY_DIR}/x64/$<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>)
|
||||
|
||||
# Some targets do not play well with the default definitions (such
|
||||
# as bpftool and /DWIN32). Remove them from the variables for now
|
||||
set(settings_variable_list
|
||||
|
@ -39,6 +41,10 @@ target_link_libraries("ebpf_for_windows_common_settings" INTERFACE
|
|||
)
|
||||
|
||||
|
||||
target_link_options("ebpf_for_windows_common_settings" INTERFACE
|
||||
/DEBUG:Full
|
||||
)
|
||||
|
||||
if(EBPFFORWINDOWS_ENABLE_DISABLE_EBPF_INTERPRETER)
|
||||
target_compile_definitions("ebpf_for_windows_common_settings" INTERFACE
|
||||
CONFIG_BPF_JIT_ALWAYS_ON=1
|
||||
|
|
|
@ -24,6 +24,7 @@ add_library("api" STATIC
|
|||
)
|
||||
|
||||
target_include_directories("api" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api_common"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
"${CMAKE_SOURCE_DIR}/rpc_interface"
|
||||
|
|
|
@ -13,6 +13,7 @@ add_library("service" STATIC
|
|||
)
|
||||
|
||||
target_include_directories("service" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/rpc_interface"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api_common"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
|
|
|
@ -5,9 +5,9 @@ set(rpc_interface_h_name "rpc_interface_h.h")
|
|||
set(rpc_interface_c_name "rpc_interface_c.c")
|
||||
set(rpc_interface_s_name "rpc_interface_s.c")
|
||||
|
||||
set(rpc_interface_h_path "${CMAKE_CURRENT_BINARY_DIR}/${rpc_interface_h_name}")
|
||||
set(rpc_interface_c_path "${CMAKE_CURRENT_BINARY_DIR}/${rpc_interface_c_name}")
|
||||
set(rpc_interface_s_path "${CMAKE_CURRENT_BINARY_DIR}/${rpc_interface_s_name}")
|
||||
set(rpc_interface_h_path "${CMAKE_BINARY_DIR}/${rpc_interface_h_name}")
|
||||
set(rpc_interface_c_path "${CMAKE_BINARY_DIR}/${rpc_interface_c_name}")
|
||||
set(rpc_interface_s_path "${CMAKE_BINARY_DIR}/${rpc_interface_s_name}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory("setup_build")
|
||||
|
||||
if(EBPFFORWINDOWS_ENABLE_INSTALL)
|
||||
install(
|
||||
FILES
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
param([parameter(Mandatory = $true)] [string] $ProgramName,
|
||||
[parameter(Mandatory = $false)] [string] $SolutionDir = $Pwd,
|
||||
[parameter(Mandatory = $false)] [string] $OutputDir = $Pwd,
|
||||
[parameter(Mandatory = $false)] [string] $Platform = "x64",
|
||||
[ValidateSet("Release", "Debug")][parameter(Mandatory = $false)] [string] $Configuration = "Release",
|
||||
[parameter(Mandatory = $false)] [bool] $SkipVerification = $false,
|
||||
|
@ -22,9 +23,9 @@ if ($null -eq (Get-Command 'msbuild.exe' -ErrorAction SilentlyContinue)) {
|
|||
throw "Unable to locate msbuild.exe. This command needs to run within a 'Developer Command Prompt'"
|
||||
}
|
||||
|
||||
$fileExists = Test-Path -Path ("$SolutionDir\$Platform\$Configuration\$ProgramName.o")
|
||||
$fileExists = Test-Path -Path ("$OutputDir\$ProgramName.o")
|
||||
if (!$fileExists) {
|
||||
$errorString = "Can't find program file: " + "$SolutionDir\$Platform\$Configuration\$ProgramName.o"
|
||||
$errorString = "Can't find program file: " + "$OutputDir\$ProgramName.o"
|
||||
throw $errorString
|
||||
}
|
||||
|
||||
|
@ -37,8 +38,10 @@ if (!$KernelMode) {
|
|||
|
||||
$AdditionalOptions = If ($SkipVerification) {"--no-verify"} Else {""}
|
||||
|
||||
msbuild /p:SolutionDir="$SolutionDir\" /p:OutDir="$SolutionDir\$Platform\$Configuration\" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:ProgramName="$ProgramName" /p:AdditionalOptions="$AdditionalOptions" $ProjectFile
|
||||
msbuild /p:SolutionDir="$SolutionDir\" /p:OutDir="$OutputDir" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:ProgramName="$ProgramName" /p:AdditionalOptions="$AdditionalOptions" $ProjectFile
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Build failed for $ProgramName.o"
|
||||
}
|
||||
}
|
||||
|
||||
Pop-Location
|
|
@ -0,0 +1,102 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set (output_dir ${CMAKE_BINARY_DIR}/x64/$<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>)
|
||||
|
||||
set (debug_redist_bins ${output_dir}/concrt140d.dll;
|
||||
${output_dir}/msvcp140d.dll;
|
||||
${output_dir}/msvcp140d_atomic_wait.dll;
|
||||
${output_dir}/msvcp140d_codecvt_ids.dll;
|
||||
${output_dir}/msvcp140_1d.dll;
|
||||
${output_dir}/msvcp140_2d.dll;
|
||||
${output_dir}/vccorlib140d.dll;
|
||||
${output_dir}/vcruntime140d.dll;
|
||||
${output_dir}/vcruntime140_1d.dll;
|
||||
)
|
||||
|
||||
set (redist_bins ${output_dir}/concrt140.dll;
|
||||
${output_dir}/msvcp140.dll;
|
||||
${output_dir}/msvcp140_1.dll;
|
||||
${output_dir}/msvcp140_2.dll;
|
||||
${output_dir}/msvcp140_atomic_wait.dll;
|
||||
${output_dir}/msvcp140_codecvt_ids.dll;
|
||||
${output_dir}/vccorlib140.dll;
|
||||
${output_dir}/vcruntime140.dll;
|
||||
${output_dir}/vcruntime140_1.dll;
|
||||
)
|
||||
|
||||
set (output_redist_bins $<$<CONFIG:Debug>:${debug_redist_bins}>$<$<CONFIG:Release>:${redist_bins}>)
|
||||
|
||||
set (input_redist_bins $<$<CONFIG:Debug>:$(VC_DebugCppRuntimeFilesPath_x64)/Microsoft.VC142.DebugCRT>$<$<CONFIG:Release>:$(VC_CppRuntimeFilesPath_x64)/Microsoft.VC142.CRT>)
|
||||
|
||||
set (ucrtbased_dll $<$<CONFIG:Debug>:${output_dir}/ucrtbased.dll>)
|
||||
|
||||
set (output_ucrtbased_dll $<$<CONFIG:Debug>:${ucrtbased_dll}>)
|
||||
|
||||
set (misc_files "install-ebpf.bat"
|
||||
"run_tests.bat"
|
||||
"uninstall-ebpf.bat"
|
||||
"common.psm1"
|
||||
"config_test_vm.psm1"
|
||||
"setup_ebpf_cicd_tests.ps1"
|
||||
"execute_ebpf_cicd_tests.ps1"
|
||||
"cleanup_ebpf_cicd_tests.ps1"
|
||||
"install_ebpf.psm1"
|
||||
"run_driver_tests.psm1"
|
||||
"test_execution.json"
|
||||
"vm_run_tests.psm1"
|
||||
"vm_list.json"
|
||||
"ebpfforwindows.wprp"
|
||||
"ebpf-all.guid"
|
||||
"ebpf-printk.guid"
|
||||
)
|
||||
|
||||
foreach(file ${misc_files})
|
||||
set( input_misc_files ${input_misc_files} "${CMAKE_SOURCE_DIR}/scripts/${file}")
|
||||
set( output_misc_files ${output_misc_files} "${output_dir}/${file}")
|
||||
endforeach()
|
||||
|
||||
set (dependency_list ${CMAKE_SOURCE_DIR}/scripts/pre-commit;
|
||||
${CMAKE_SOURCE_DIR}/include/git_commit_id.h;
|
||||
"${output_redist_bins}"
|
||||
"${output_ucrtbased_dll}"
|
||||
"${output_misc_files}")
|
||||
|
||||
add_custom_target(setup_build ALL DEPENDS "${dependency_list}")
|
||||
|
||||
find_program(powershell_path "powershell" REQUIRED)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${CMAKE_SOURCE_DIR}/scripts/pre-commit
|
||||
COMMAND
|
||||
${powershell_path} -NonInteractive -ExecutionPolicy Unrestricted ${CMAKE_SOURCE_DIR}/scripts/copy_pre_commit.ps1 ${CMAKE_SOURCE_DIR}/scripts/pre-commit
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${CMAKE_SOURCE_DIR}/include/git_commit_id.h
|
||||
COMMAND
|
||||
${powershell_path} -NonInteractive -ExecutionPolicy Unrestricted ${CMAKE_SOURCE_DIR}/scripts/generate-commitid.ps1 ${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${output_redist_bins}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy_directory \"${input_redist_bins}\" ${output_dir}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${output_ucrtbased_dll}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy \"$(UniversalDebugCRT_ExecutablePath_x64)/ucrtbased.dll\" ${output_dir}
|
||||
)
|
||||
|
||||
add_custom_command (
|
||||
OUTPUT
|
||||
"${output_misc_files}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy ${input_misc_files} ${output_dir}
|
||||
)
|
|
@ -2,8 +2,13 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory("api_test")
|
||||
add_subdirectory("libs")
|
||||
add_subdirectory("bpf2c_tests")
|
||||
add_subdirectory("bpftool_tests")
|
||||
add_subdirectory("cilium")
|
||||
add_subdirectory("fuzz")
|
||||
add_subdirectory("libs")
|
||||
add_subdirectory("performance")
|
||||
add_subdirectory("sample")
|
||||
add_subdirectory("socket")
|
||||
add_subdirectory("xdp")
|
||||
add_subdirectory("unit")
|
||||
|
|
|
@ -44,12 +44,6 @@ target_compile_options("bpf2c_tests" PRIVATE
|
|||
"/WX-"
|
||||
)
|
||||
|
||||
configure_file(
|
||||
bpf_test.cpp
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/bpf_test.cpp"
|
||||
COPYONLY
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME "bpf2c_tests"
|
||||
COMMAND "${CMAKE_COMMAND}" -E env "PATH=$<TARGET_FILE_DIR:EbpfApi>;$ENV{PATH}" "$<TARGET_FILE:bpf2c_tests>"
|
||||
|
@ -139,10 +133,25 @@ set(expected_file_list
|
|||
test_utility_helpers_sys.c
|
||||
)
|
||||
|
||||
foreach(expected_file ${expected_file_list})
|
||||
configure_file(
|
||||
"expected/${expected_file}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${expected_file}"
|
||||
COPYONLY
|
||||
)
|
||||
set (input_bpf_test_cpp ${CMAKE_CURRENT_SOURCE_DIR}/bpf_test.cpp)
|
||||
set (output_bpf_test_cpp ${output_dir}/bpf_test.cpp)
|
||||
|
||||
foreach(file ${expected_file_list})
|
||||
set( input_expected_files ${input_expected_files} ${CMAKE_CURRENT_SOURCE_DIR}/expected/${file})
|
||||
set( output_expected_files ${output_expected_files} ${output_dir}/${file})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(bpf2c_tests_expected_files ALL DEPENDS ${output_bpf_test_cpp} ${output_expected_files} SOURCES ${input_bpf_test_cpp} ${input_expected_files})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${output_expected_files}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E make_directory "${output_dir}/expected"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy ${input_bpf_test_cpp} ${output_bpf_test_cpp}
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy ${input_expected_files} ${output_dir}/expected
|
||||
DEPENDS
|
||||
${input_bpf_test_cpp} ${input_expected_files}
|
||||
)
|
||||
|
|
|
@ -36,6 +36,7 @@ read_contents(const std::string& source, std::vector<std::function<std::string(c
|
|||
return return_value;
|
||||
}
|
||||
|
||||
template <char separator>
|
||||
std::string
|
||||
transform_line_directives(const std::string& string)
|
||||
{
|
||||
|
@ -45,12 +46,12 @@ transform_line_directives(const std::string& string)
|
|||
if (string.find("\"") == std::string::npos) {
|
||||
return string;
|
||||
}
|
||||
if (string.find("\\") == std::string::npos) {
|
||||
if ((string.find(separator) == std::string::npos)) {
|
||||
// Already trimmed.
|
||||
return string;
|
||||
}
|
||||
|
||||
return string.substr(0, string.find("\"") + 1) + string.substr(string.find_last_of("\\") + 1);
|
||||
return string.substr(0, string.find("\"") + 1) + string.substr(string.find_last_of(separator) + 1);
|
||||
}
|
||||
|
||||
// Workaround for: https://github.com/microsoft/ebpf-for-windows/issues/1060
|
||||
|
@ -117,8 +118,10 @@ run_test_elf(const std::string& elf_file, _test_mode test_mode)
|
|||
case _test_mode::Verify:
|
||||
case _test_mode::NoVerify: {
|
||||
auto raw_output = read_contents<std::ifstream>(
|
||||
std::string("expected\\") + name + suffix, {transform_line_directives, transform_fix_opcode_comment});
|
||||
auto raw_result = read_contents<std::istringstream>(out, {transform_line_directives});
|
||||
std::string("expected\\") + name + suffix,
|
||||
{transform_line_directives<'\\'>, transform_line_directives<'/'>, transform_fix_opcode_comment});
|
||||
auto raw_result = read_contents<std::istringstream>(
|
||||
out, {transform_line_directives<'\\'>, transform_line_directives<'/'>});
|
||||
|
||||
REQUIRE(raw_result.size() == raw_output.size());
|
||||
for (size_t i = 0; i < raw_result.size(); i++) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_executable("bpftooltests"
|
||||
bpftool_tests.cpp
|
||||
)
|
||||
|
||||
target_include_directories("bpftooltests" PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/util"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/src"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/build/generated-includes"
|
||||
)
|
||||
|
||||
target_link_libraries("bpftooltests" PRIVATE
|
||||
"ebpf_for_windows_cpp_settings"
|
||||
"Catch2::Catch2WithMain"
|
||||
"EbpfApi"
|
||||
"test_util"
|
||||
)
|
||||
|
||||
target_compile_definitions("bpftooltests" PRIVATE
|
||||
_CONSOLE
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_executable("cilium_tests"
|
||||
cilium_tests.cpp
|
||||
)
|
||||
|
||||
target_include_directories("cilium_tests" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/common"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/util"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/src"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/build/generated-includes"
|
||||
"${CMAKE_SOURCE_DIR}/external/bpftool"
|
||||
"${CMAKE_SOURCE_DIR}/external/ebpf-verifier/src"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries("cilium_tests" PRIVATE
|
||||
"ebpf_for_windows_cpp_settings"
|
||||
"Catch2::Catch2WithMain"
|
||||
"EbpfApi"
|
||||
"ws2_32"
|
||||
)
|
||||
|
||||
target_compile_definitions("cilium_tests" PRIVATE
|
||||
_CONSOLE
|
||||
$<$<CONFIG:DEBUG>:SKIP_VERIFICATION>
|
||||
)
|
|
@ -0,0 +1,63 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_executable("fuzz"
|
||||
../../libs/thunk/mock/mock.cpp
|
||||
../../libs/thunk/mock/mock.h
|
||||
|
||||
../end_to_end/test_helper.cpp
|
||||
../end_to_end/test_helper.hpp
|
||||
|
||||
execution_context.cpp
|
||||
)
|
||||
|
||||
target_include_directories("fuzz" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/src"
|
||||
"${CMAKE_SOURCE_DIR}/external/catch2/build/generated-includes"
|
||||
"${CMAKE_SOURCE_DIR}/external/bpftool"
|
||||
"${CMAKE_SOURCE_DIR}/external/ebpf-verifier/src"
|
||||
"${CMAKE_SOURCE_DIR}/external/ubpf/vm"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api_common"
|
||||
"${CMAKE_SOURCE_DIR}/libs/ebpfnetsh"
|
||||
"${CMAKE_SOURCE_DIR}/libs/execution_context"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform/user"
|
||||
"${CMAKE_SOURCE_DIR}/libs/service"
|
||||
"${CMAKE_SOURCE_DIR}/libs/thunk"
|
||||
"${CMAKE_SOURCE_DIR}/libs/thunk/mock"
|
||||
"${CMAKE_SOURCE_DIR}/netebpfext"
|
||||
"${CMAKE_SOURCE_DIR}/rpc_interface"
|
||||
"${CMAKE_SOURCE_DIR}/tests/end_to_end"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/common"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/util"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample/ext/inc"
|
||||
"${CMAKE_SOURCE_DIR}/tests/xdp"
|
||||
"${CMAKE_SOURCE_DIR}/tools/encode_program_info"
|
||||
)
|
||||
|
||||
target_link_libraries("fuzz" PRIVATE
|
||||
"ebpf_for_windows_cpp_settings"
|
||||
"api"
|
||||
"api_common"
|
||||
"Catch2::Catch2"
|
||||
"Catch2::Catch2WithMain"
|
||||
"common_tests"
|
||||
"EbpfApi"
|
||||
"execution_context_user"
|
||||
"external::ebpfverifier"
|
||||
"mincore.lib"
|
||||
"pe_parse"
|
||||
"platform_user"
|
||||
"service"
|
||||
"test_util"
|
||||
"ubpf_user"
|
||||
)
|
||||
|
||||
target_compile_definitions("fuzz" PRIVATE
|
||||
_CONSOLE
|
||||
)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory("ext")
|
||||
add_subdirectory("unsafe")
|
||||
|
||||
# build eBPF Samples.
|
||||
build_bpf_samples(0)
|
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_subdirectory("app")
|
||||
add_subdirectory("drv")
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_executable("sample_ext_app"
|
||||
sample_ext_app.cpp
|
||||
)
|
||||
|
||||
target_include_directories("sample_ext_app" PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/external/ebpf-verifier/src"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
"${CMAKE_SOURCE_DIR}/libs/ebpfnetsh"
|
||||
"${CMAKE_SOURCE_DIR}/libs/execution_context"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform/user"
|
||||
"${CMAKE_SOURCE_DIR}/netebpfext"
|
||||
"${CMAKE_SOURCE_DIR}/tests/end_to_end"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/util"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/common"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample/ext/inc"
|
||||
)
|
||||
|
||||
target_link_libraries("sample_ext_app" PRIVATE
|
||||
"ebpf_for_windows_cpp_settings"
|
||||
"common_tests"
|
||||
"iphlpapi"
|
||||
"EbpfApi"
|
||||
"netsh_static"
|
||||
"test_util"
|
||||
"Catch2::Catch2WithMain"
|
||||
)
|
||||
|
||||
target_compile_definitions("sample_ext_app" PRIVATE
|
||||
_CONSOLE
|
||||
_WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME "sample_ext_app"
|
||||
COMMAND "${CMAKE_COMMAND}" -E env "PATH=$<TARGET_FILE_DIR:EbpfApi>;$ENV{PATH}" "$<TARGET_FILE:sample_ext_app>"
|
||||
)
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
wdk_add_driver("sample_ebpf_ext" WINVER "${EBPFFORWINDOWS_WDK_WINVER}" KMDF "${EBPFFORWINDOWS_WDK_KMDF_VERSION}"
|
||||
sample_ext.h
|
||||
sample_ext.c
|
||||
|
||||
sample_ext_drv.c
|
||||
)
|
||||
|
||||
target_include_directories("sample_ebpf_ext" PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform/kernel"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample"
|
||||
"${CMAKE_SOURCE_DIR}/tests/sample/ext/inc"
|
||||
)
|
||||
|
||||
target_link_directories("sample_ebpf_ext" PRIVATE
|
||||
"${WDK_ROOT}/Lib/${WDK_VERSION}/km/x64"
|
||||
)
|
||||
|
||||
target_link_libraries("sample_ebpf_ext"
|
||||
"ebpf_for_windows_common_settings"
|
||||
"external::ebpfverifier_headers"
|
||||
"platform_kernel"
|
||||
"netio.lib"
|
||||
"wdmsec.lib"
|
||||
)
|
||||
|
||||
target_compile_definitions("sample_ebpf_ext" PRIVATE
|
||||
BINARY_COMPATIBLE=0
|
||||
NT
|
||||
POOL_NX_OPTIN_AUTO
|
||||
)
|
||||
|
||||
# api_common includes sample_ebpf_ext's headers. Since this is a driver
|
||||
# and it does not make sense to link against it, for now create
|
||||
# an interface target that just exports the include directory.
|
||||
add_library("sample_ebpf_ext_headers" INTERFACE)
|
||||
target_include_directories("sample_ebpf_ext_headers" SYSTEM INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
)
|
||||
|
||||
codeSign("sample_ebpf_ext")
|
||||
|
||||
if(EBPFFORWINDOWS_ENABLE_INSTALL)
|
||||
install(
|
||||
TARGETS "sample_ebpf_ext"
|
||||
DESTINATION "drivers"
|
||||
)
|
||||
|
||||
install(
|
||||
FILES "sample_ebpf_ext.inf"
|
||||
DESTINATION "drivers"
|
||||
)
|
||||
endif()
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (c) Microsoft Corporation
|
||||
SPDX-License-Identifier: MIT
|
||||
|
@ -97,8 +97,8 @@
|
|||
<FileType>CppCode</FileType>
|
||||
<Command>
|
||||
clang $(ClangFlags) -I../xdp -I../socket -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false
|
||||
</Command>
|
||||
<Outputs>$(OutputPath)%(Filename).o;$(OutputPath)%(Filename)_um.dll;$(OutputPath)%(Filename).sys</Outputs>
|
||||
</CustomBuild>
|
||||
|
@ -110,8 +110,8 @@
|
|||
<Command>clang $(ClangFlags) -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
|
||||
<Command>
|
||||
clang $(ClangFlags) -I../xdp -I../socket -I./ext/inc -c unsafe\%(Filename).c -o $(OutputPath)%(Filename).o
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true -SkipVerification $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false -SkipVerification $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true -SkipVerification $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false -SkipVerification $true
|
||||
</Command>
|
||||
<Outputs>$(OutputPath)%(Filename).o</Outputs>
|
||||
</CustomBuild>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# build eBPF Samples but skip verification.
|
||||
build_bpf_samples(1)
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_executable("socket_tests"
|
||||
socket_tests.cpp
|
||||
)
|
||||
|
||||
target_include_directories("socket_tests" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
"${CMAKE_SOURCE_DIR}/libs/execution_context"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform"
|
||||
"${CMAKE_SOURCE_DIR}/libs/platform/user"
|
||||
"${CMAKE_SOURCE_DIR}/external/ebpf-verifier/src"
|
||||
"${CMAKE_SOURCE_DIR}/tests/end_to_end"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/util"
|
||||
"${CMAKE_SOURCE_DIR}/tests/libs/common"
|
||||
)
|
||||
|
||||
target_link_libraries("socket_tests" PRIVATE
|
||||
"ebpf_for_windows_cpp_settings"
|
||||
"common_tests"
|
||||
"EbpfApi"
|
||||
"test_util"
|
||||
"ws2_32.lib"
|
||||
"Catch2::Catch2"
|
||||
)
|
||||
|
||||
target_compile_definitions("socket_tests" PRIVATE
|
||||
_CONSOLE
|
||||
_WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME "socket_tests"
|
||||
COMMAND "${CMAKE_COMMAND}" -E env "PATH=$<TARGET_FILE_DIR:EbpfApi>;$ENV{PATH}" "$<TARGET_FILE:socket_tests>"
|
||||
)
|
|
@ -22,6 +22,7 @@ add_executable("unit_tests"
|
|||
)
|
||||
|
||||
target_include_directories("unit_tests" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api_common"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
|
|
|
@ -6,6 +6,7 @@ add_executable("xdp_tests"
|
|||
)
|
||||
|
||||
target_include_directories("xdp_tests" PRIVATE
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${CMAKE_SOURCE_DIR}/include"
|
||||
"${CMAKE_SOURCE_DIR}/libs/api"
|
||||
"${CMAKE_SOURCE_DIR}/libs/execution_context"
|
||||
|
|
|
@ -23,6 +23,7 @@ target_link_libraries("bpf2c" PRIVATE
|
|||
)
|
||||
|
||||
target_compile_definitions("bpf2c" PRIVATE
|
||||
$<$<CONFIG:DEBUG>:ENABLE_SKIP_VERIFY>
|
||||
_CONSOLE
|
||||
)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче