Skip to content

Commit

Permalink
Add bpf2c_plugin for use with bpf_conformance test suite (microsoft#1475
Browse files Browse the repository at this point in the history
)

* Add bpf2c_plugin

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix CMake so that it builds correctly

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Remove bpf_conformance as a submodule

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Download bpf_conformance artifact

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Extract bpf_conformance\

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Fix path

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Execute bpf_conformance in CI/CD

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* Pickup latest artifacts"

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

* PR feedback

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: saxena-anurag <43585259+saxena-anurag@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 25, 2022
1 parent c7c967b commit b7deedc
Show file tree
Hide file tree
Showing 13 changed files with 743 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ jobs:
gather_dumps: true
capture_etw: true

# Run the bpf2c conformance tests in GitHub.
bpf2c_conformance:
# Always run this job.
needs: regular
if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push'
uses: ./.github/workflows/reusable-test.yml
with:
test_command: .\bpf_conformance_runner.exe --test_file_directory tests --plugin_path bpf2c_plugin.exe --cpu_version v2 --debug true --plugin_options "--include %SOURCE_ROOT%\include"
name: bpf2c_conformance
build_artifact: Build-x64
environment: windows-2019
vs_dev: true
code_coverage: true
gather_dumps: true
capture_etw: true

# Run the driver tests on self-hosted runners.
driver:
# Always run this job.
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,31 @@ jobs:
search_artifacts: false
skip_unpack: true

- name: Download demo bpf_conformance repository artifacts
uses: dawidd6/action-download-artifact@7847792dd435a50521b8e3bd3576dae7459d1fa8
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: CICD.yml
workflow_conclusion: success
name: bpf_conformance-${{ matrix.configurations }}
path: ${{github.workspace}}
repo: Alan-Jowett/bpf_conformance
check_artifacts: false
search_artifacts: false
skip_unpack: true

- name: Extract artifacts to build path
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
cd ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
tar -xf ..\..\x64-${{ matrix.configurations }}-cilium-xdp.zip
- name: Extract bpf_conformance repository artifacts to build path
working-directory: ${{env.GITHUB_WORKSPACE}}
run: |
cd ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
tar -xf ..\..\bpf_conformance-${{ matrix.configurations }}.zip
- name: Upload Build Output
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
runs-on: ${{inputs.environment}}
env:
# Configuration type to build.
SOURCE_ROOT: ${{github.workspace}}
NAME: ${{inputs.name}}
BUILD_CONFIGURATION: ${{matrix.configurations}}
BUILD_PLATFORM: x64
Expand Down
6 changes: 3 additions & 3 deletions docs/InstallEbpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ to install eBPF on all Windows nodes in a Kubernetes cluster.

1. Deploy the binaries to `C:\Temp` on the machine (Windows Host) where you built the binaries.
Start an admin Powershell on the Windows Host and do `.\x64\debug\deploy-ebpf`.
2. Build ebpf-for-windows image.

2. Build ebpf-for-windows image.

a. To build the image on the Windows Host, make sure docker is installed. [install docker on Windows Server](https://docs.microsoft.com/en-us/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-Server/).
Start an admin Powershell on the Windows Host and run `.\images\build-images.ps1` and provide parameters for `repository`, `tag` and `OSVersion`.

Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ starting from authoring a new eBPF program in C.

To try out this tutorial yourself, you will need:

- Clang and nuget from [Prerequisites tools](GettingStarted.md#Prerequisites).
- a VM that can [load a Windows driver](https://github.com/microsoft/ebpf-for-windows/blob/main/docs/GettingStarted.md#installing-ebpf-for-windows).
- Follow the [VM install instructions](https://github.com/microsoft/ebpf-for-windows/blob/main/docs/vm-setup.md) to get started quickly.
- Clang and nuget from [Prerequisites tools](GettingStarted.md#Prerequisites).
- a VM that can [load a Windows driver](https://github.com/microsoft/ebpf-for-windows/blob/main/docs/GettingStarted.md#installing-ebpf-for-windows).
- Follow the [VM install instructions](https://github.com/microsoft/ebpf-for-windows/blob/main/docs/vm-setup.md) to get started quickly.
- [eBPF installed](https://github.com/microsoft/ebpf-for-windows/blob/main/docs/InstallEbpf.md) on the VM. Using the MSI installer from a release is the fastest way to get started.
- ebpf-for-windows nuget package: `nuget install eBPF-for-Windows`

Expand Down
31 changes: 31 additions & 0 deletions ebpf-for-windows.sln
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "verifier_fuzzer", "tests\li
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core_helper_fuzzer", "tests\libfuzzer\core_helper_fuzzer\core_helper_fuzzer.vcxproj", "{88A3E85F-669F-4CEA-8207-2E1545528D62}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bpf2c_plugin", "tests\bpf2c_plugin\bpf2c_plugin.vcxproj", "{F106D38A-AC35-4B5A-AEEE-7235E4915A72}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netebpfext_user", "netebpfext\user\netebpfext_user.vcxproj", "{630BB78F-6211-41D8-8E3A-096E22E169EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netebpfext_unit", "tests\netebpfext_unit\netebpfext_unit.vcxproj", "{E619B985-44B3-4292-A585-5CD0C4315ED3}"
Expand Down Expand Up @@ -1569,6 +1571,34 @@ Global
{88A3E85F-669F-4CEA-8207-2E1545528D62}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{88A3E85F-669F-4CEA-8207-2E1545528D62}.RelWithDebInfo|x64.Build.0 = Release|x64
{88A3E85F-669F-4CEA-8207-2E1545528D62}.RelWithDebInfo|x86.ActiveCfg = Release|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|ARM.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|ARM64.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|x64.ActiveCfg = Debug|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|x64.Build.0 = Debug|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|x86.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Debug|x86.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|ARM.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|ARM.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|ARM64.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|ARM64.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|x64.ActiveCfg = Debug|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|x64.Build.0 = Debug|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|x86.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.MinSizeRel|x86.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|ARM.ActiveCfg = Release|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|ARM64.ActiveCfg = Release|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|x64.ActiveCfg = Release|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|x64.Build.0 = Release|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|x86.ActiveCfg = Release|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.Release|x86.Build.0 = Release|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|ARM.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|ARM.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|ARM64.ActiveCfg = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|ARM64.Build.0 = Debug|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|x64.Build.0 = Release|x64
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{F106D38A-AC35-4B5A-AEEE-7235E4915A72}.RelWithDebInfo|x86.Build.0 = Release|Win32
{630BB78F-6211-41D8-8E3A-096E22E169EF}.Debug|ARM.ActiveCfg = Debug|Win32
{630BB78F-6211-41D8-8E3A-096E22E169EF}.Debug|ARM64.ActiveCfg = Debug|Win32
{630BB78F-6211-41D8-8E3A-096E22E169EF}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -1681,6 +1711,7 @@ Global
{A0A0D663-DCF7-4BB1-9DDB-7964C3C31603} = {E184CBC2-4B62-499F-8A4A-F15A5A182259}
{DCF12929-B975-4874-A80F-9EAF1CC5A5A0} = {E184CBC2-4B62-499F-8A4A-F15A5A182259}
{88A3E85F-669F-4CEA-8207-2E1545528D62} = {E184CBC2-4B62-499F-8A4A-F15A5A182259}
{F106D38A-AC35-4B5A-AEEE-7235E4915A72} = {492C9B22-9237-4996-9E33-CA14D3533616}
{630BB78F-6211-41D8-8E3A-096E22E169EF} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B}
{E619B985-44B3-4292-A585-5CD0C4315ED3} = {492C9B22-9237-4996-9E33-CA14D3533616}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion include/bpf2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern "C"
{
void (*programs)(_Outptr_result_buffer_maybenull_(*count) program_entry_t** programs, _Out_ size_t* count);
void (*maps)(_Outptr_result_buffer_maybenull_(*count) map_entry_t** maps, _Out_ size_t* count);
void (*hash)(_Outptr_result_buffer_maybenull_(*size) uint8_t** hash, _Out_ size_t* size);
void (*hash)(_Outptr_result_buffer_maybenull_(*size) const uint8_t** hash, _Out_ size_t* size);
} metadata_table_t;

inline uint16_t
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: MIT

add_subdirectory("api_test")
add_subdirectory("bpf2c_plugin")
add_subdirectory("bpf2c_tests")
add_subdirectory("bpftool_tests")
add_subdirectory("cilium")
Expand Down
74 changes: 74 additions & 0 deletions tests/bpf2c_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT

add_executable("bpf2c_plugin"
bpf2c_plugin.cpp
../../tools/bpf2c/bpf_code_generator.h
../../tools/bpf2c/bpf_code_generator.cpp
)

target_include_directories("bpf2c_plugin" PRIVATE
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/tools/bpf2c"
"${CMAKE_SOURCE_DIR}/external/ubpf/vm"
"${CMAKE_BINARY_DIR}/external/ubpf/vm"
"${CMAKE_SOURCE_DIR}/external/ubpf/vm/inc"
"${CMAKE_BINARY_DIR}/external/ubpf/vm/inc"
"${CMAKE_SOURCE_DIR}/external/ebpf-verifier/src"
)

target_link_libraries("bpf2c_plugin" PRIVATE
"ebpf_for_windows_cpp_settings"
"common_tests"
"EbpfApi"
"rpc_interface"
"test_util"
"Catch2::Catch2WithMain"
"ws2_32.lib"
)

target_compile_definitions("bpf2c_plugin" PRIVATE
_WINSOCK_DEPRECATED_NO_WARNINGS
_CONSOLE
)

function(generateTemplate source_file_name)
find_program(powershell_path "powershell" REQUIRED)

set(template_name "${source_file_name}.template")
set(template_path "${CMAKE_CURRENT_BINARY_DIR}/${template_name}")

add_custom_command(
OUTPUT
"${template_path}"

COMMAND
"${powershell_path}" -NonInteractive -ExecutionPolicy Unrestricted "${CMAKE_SOURCE_DIR}/scripts/escape_text.ps1" "${CMAKE_CURRENT_SOURCE_DIR}/${source_file_name}.cpp" "${template_path}"

VERBATIM

COMMENT
"ebpf-for-windows - Generating: ${source_file_name}"

WORKING_DIRECTORY
"${CMAKE_CURRENT_BINARY_DIR}"
)

add_custom_target("${source_file_name}_builder"
DEPENDS "${template_path}"
)

add_library("${source_file_name}" INTERFACE)
target_include_directories("${source_file_name}" INTERFACE
"${CMAKE_CURRENT_BINARY_DIR}"
)

add_dependencies("${source_file_name}"
"${source_file_name}_builder"
)
endfunction()

generateTemplate("bpf2c_test")
target_link_libraries("bpf2c_plugin" PRIVATE
"bpf2c_test"
)
Loading

0 comments on commit b7deedc

Please sign in to comment.