diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 1d1279c55..a38946ee2 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -96,6 +96,18 @@ jobs: code_coverage: true gather_dumps: true + # Run Cilium regression tests in GitHub. + cilium_tests: + uses: ./.github/workflows/reusable-test.yml + with: + name: cilium_tests + test_command: cilium_tests.exe -d yes + build_job: regular / build + build_artifact: Build-x64 + environment: windows-2019 + code_coverage: false + gather_dumps: true + # Run the quick stress tests in GitHub. stress: uses: ./.github/workflows/reusable-test.yml diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 9ea9b5c6a..dfd3d3366 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -101,6 +101,28 @@ jobs: working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: copy "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\clang*" . + # 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}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + tar -xf ..\..\x64-${{ matrix.configurations }}-cilium-xdp.zip + - name: Upload Build Output uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 with: diff --git a/ebpf-for-windows.sln b/ebpf-for-windows.sln index 44f12e74b..3e8c7e543 100644 --- a/ebpf-for-windows.sln +++ b/ebpf-for-windows.sln @@ -6,7 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ebpfverifier", "external\ebpf-verifier\build\ebpfverifier.vcxproj", "{7D5B4E68-C0FA-3F86-9405-F6400219B440}" ProjectSection(ProjectDependencies) = postProject {231EE32B-EBA4-4FE5-A55B-DB18F539D403} = {231EE32B-EBA4-4FE5-A55B-DB18F539D403} - {10883FE6-9448-32DE-A899-0D98B8CA914D} = {10883FE6-9448-32DE-A899-0D98B8CA914D} + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A} = {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A} EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libs", "libs", "{B02E60AE-1254-459C-8824-AC6CDB6AE52E}" @@ -121,7 +121,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xdp_tests", "tests\xdp\xdp_ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bpftool", "tools\bpftool\bpftool.vcxproj", "{CA179B38-EBF5-4371-B830-73486E35250B}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yaml-cpp", "external\ebpf-verifier\build\yaml-cpp.vcxproj", "{10883FE6-9448-32DE-A899-0D98B8CA914D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yaml-cpp", "external\ebpf-verifier\build\yaml-cpp.vcxproj", "{98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bpf2c", "tools\bpf2c\bpf2c.vcxproj", "{69B97E52-18DC-434E-A6E4-4C0F3E88C44A}" ProjectSection(ProjectDependencies) = postProject @@ -140,6 +140,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "socket_tests", "tests\socke EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bpftool_tests", "tests\bpftool_tests\bpftool_tests.vcxproj", "{8B5B061B-3170-4D1B-8C5B-E86B890C14B8}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cilium_tests", "tests\cilium\cilium_tests.vcxproj", "{8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nuget", "tools\nuget\nuget.vcxproj", "{7629D5D0-5A80-4528-87ED-60FC83C5552B}" EndProject Global @@ -1132,26 +1134,26 @@ Global {CA179B38-EBF5-4371-B830-73486E35250B}.RelWithDebInfo|x64.ActiveCfg = Release|x64 {CA179B38-EBF5-4371-B830-73486E35250B}.RelWithDebInfo|x64.Build.0 = Release|x64 {CA179B38-EBF5-4371-B830-73486E35250B}.RelWithDebInfo|x86.ActiveCfg = Debug|Win32 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Debug|ARM.ActiveCfg = Debug|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Debug|ARM64.ActiveCfg = Debug|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Debug|x64.ActiveCfg = Debug|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Debug|x64.Build.0 = Debug|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Debug|x86.ActiveCfg = Debug|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.MinSizeRel|ARM.ActiveCfg = MinSizeRel|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.MinSizeRel|ARM64.ActiveCfg = MinSizeRel|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Release|ARM.ActiveCfg = Release|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Release|ARM64.ActiveCfg = Release|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Release|x64.ActiveCfg = Release|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Release|x64.Build.0 = Release|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.Release|x86.ActiveCfg = Release|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.RelWithDebInfo|ARM.ActiveCfg = RelWithDebInfo|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.RelWithDebInfo|ARM64.ActiveCfg = RelWithDebInfo|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {10883FE6-9448-32DE-A899-0D98B8CA914D}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Debug|ARM.ActiveCfg = Debug|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Debug|ARM64.ActiveCfg = Debug|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Debug|x64.ActiveCfg = Debug|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Debug|x64.Build.0 = Debug|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Debug|x86.ActiveCfg = Debug|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.MinSizeRel|ARM.ActiveCfg = MinSizeRel|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.MinSizeRel|ARM64.ActiveCfg = MinSizeRel|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Release|ARM.ActiveCfg = Release|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Release|ARM64.ActiveCfg = Release|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Release|x64.ActiveCfg = Release|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Release|x64.Build.0 = Release|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.Release|x86.ActiveCfg = Release|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.RelWithDebInfo|ARM.ActiveCfg = RelWithDebInfo|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.RelWithDebInfo|ARM64.ActiveCfg = RelWithDebInfo|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 {69B97E52-18DC-434E-A6E4-4C0F3E88C44A}.Debug|ARM.ActiveCfg = Debug|Win32 {69B97E52-18DC-434E-A6E4-4C0F3E88C44A}.Debug|ARM64.ActiveCfg = Debug|Win32 {69B97E52-18DC-434E-A6E4-4C0F3E88C44A}.Debug|x64.ActiveCfg = Debug|x64 @@ -1332,6 +1334,34 @@ Global {8B5B061B-3170-4D1B-8C5B-E86B890C14B8}.RelWithDebInfo|x64.Build.0 = Release|x64 {8B5B061B-3170-4D1B-8C5B-E86B890C14B8}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {8B5B061B-3170-4D1B-8C5B-E86B890C14B8}.RelWithDebInfo|x86.Build.0 = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|ARM.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|ARM64.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|x64.ActiveCfg = Debug|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|x64.Build.0 = Debug|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|x86.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Debug|x86.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|ARM.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|ARM.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|ARM64.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|ARM64.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|x64.ActiveCfg = Debug|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|x64.Build.0 = Debug|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|x86.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.MinSizeRel|x86.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|ARM.ActiveCfg = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|ARM64.ActiveCfg = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|x64.ActiveCfg = Release|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|x64.Build.0 = Release|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|x86.ActiveCfg = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.Release|x86.Build.0 = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|ARM.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|ARM.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|ARM64.ActiveCfg = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|ARM64.Build.0 = Debug|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|x64.Build.0 = Release|x64 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60}.RelWithDebInfo|x86.Build.0 = Release|Win32 {7629D5D0-5A80-4528-87ED-60FC83C5552B}.Debug|ARM.ActiveCfg = Debug|Win32 {7629D5D0-5A80-4528-87ED-60FC83C5552B}.Debug|ARM64.ActiveCfg = Debug|Win32 {7629D5D0-5A80-4528-87ED-60FC83C5552B}.Debug|x64.ActiveCfg = Debug|x64 @@ -1398,7 +1428,7 @@ Global {724EB55A-CCFC-4662-92E3-B664CDA365E7} = {492C9B22-9237-4996-9E33-CA14D3533616} {07DC6181-84A2-4A14-A806-5E9AF6C929C2} = {492C9B22-9237-4996-9E33-CA14D3533616} {CA179B38-EBF5-4371-B830-73486E35250B} = {B09749EC-3D14-414B-BA9B-CD20E218DC84} - {10883FE6-9448-32DE-A899-0D98B8CA914D} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} + {98D56B8A-D8EB-3D98-B8EE-C83696B4D58A} = {69CDB6A1-434D-4BC9-9BFF-D12DF7EDBB6B} {69B97E52-18DC-434E-A6E4-4C0F3E88C44A} = {B09749EC-3D14-414B-BA9B-CD20E218DC84} {61DF9973-81B9-4006-9148-52F58259BBCF} = {492C9B22-9237-4996-9E33-CA14D3533616} {8BD3552A-2CFB-4A59-AB15-2031B97ADA1E} = {492C9B22-9237-4996-9E33-CA14D3533616} @@ -1406,6 +1436,7 @@ Global {D88F9CE2-8DA2-44FB-AF7C-06466A180F31} = {492C9B22-9237-4996-9E33-CA14D3533616} {EED9DAC6-8B98-4C33-969A-E8CEDE8E985E} = {492C9B22-9237-4996-9E33-CA14D3533616} {8B5B061B-3170-4D1B-8C5B-E86B890C14B8} = {492C9B22-9237-4996-9E33-CA14D3533616} + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60} = {492C9B22-9237-4996-9E33-CA14D3533616} {7629D5D0-5A80-4528-87ED-60FC83C5552B} = {B09749EC-3D14-414B-BA9B-CD20E218DC84} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/libs/api/libbpf_object.cpp b/libs/api/libbpf_object.cpp index 333612f5f..be4321772 100644 --- a/libs/api/libbpf_object.cpp +++ b/libs/api/libbpf_object.cpp @@ -87,7 +87,7 @@ bpf_object__open_file(const char* path, const struct bpf_object_open_opts* opts) return (struct bpf_object*)libbpf_err_ptr(-EINVAL); } - struct bpf_object* object; + struct bpf_object* object = nullptr; const char* error_message; ebpf_result_t result = ebpf_object_open(path, opts->object_name, opts->pin_root_path, nullptr, nullptr, &object, &error_message); diff --git a/tests/cilium/cilium_tests.cpp b/tests/cilium/cilium_tests.cpp new file mode 100644 index 000000000..c34812739 --- /dev/null +++ b/tests/cilium/cilium_tests.cpp @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation +// SPDX-License-Identifier: MIT + +#define CATCH_CONFIG_MAIN + +#include + +#include "bpf/libbpf.h" +#include "catch_wrapper.hpp" +#include "ebpf_api.h" + +#define SAMPLE_PATH "" +#define CILIUM_XDP_SECTIONS_SNAT 10 +#define CILIUM_XDP_SECTIONS_DSR 12 + +void +verify_program(_In_z_ const char* file, uint32_t expected_section_count) +{ + struct bpf_object_open_opts opts = {0}; + bpf_program* program = nullptr; + uint32_t section_count = 0; + struct bpf_object* object = bpf_object__open_file(file, &opts); + REQUIRE(object != nullptr); + + while (true) { + program = bpf_program__next(program, object); + if (program == nullptr) { + break; + } + section_count++; + const char* section_name = bpf_program__section_name(program); + REQUIRE(section_name != nullptr); + +#ifndef SKIP_VERIFICATION + uint32_t result; + ebpf_api_verifier_stats_t stats; + const char* error_message = nullptr; + const char* report = nullptr; + REQUIRE( + (result = ebpf_api_elf_verify_section_from_file(file, section_name, false, &report, &error_message, &stats), + ebpf_free_string(error_message), + error_message = nullptr, + result == 0)); + REQUIRE(report != nullptr); + ebpf_free_string(report); +#endif + } + + REQUIRE(section_count == expected_section_count); +} + +TEST_CASE("verify_snat_program", "[cilium][xdp]") +{ + verify_program(SAMPLE_PATH "bpf_xdp_snat.o", CILIUM_XDP_SECTIONS_SNAT); +} +TEST_CASE("verify_dsr_program", "[cilium][xdp]") +{ + verify_program(SAMPLE_PATH "bpf_xdp_dsr.o", CILIUM_XDP_SECTIONS_DSR); +} diff --git a/tests/cilium/cilium_tests.vcxproj b/tests/cilium/cilium_tests.vcxproj new file mode 100644 index 000000000..c1e332061 --- /dev/null +++ b/tests/cilium/cilium_tests.vcxproj @@ -0,0 +1,153 @@ + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {8DD6577A-CBBE-43FE-9FC3-E42CB013CC60} + cilium_tests + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + + + false + + + false + $(IncludePath) + + + false + + + + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + _DEBUG;_CONSOLE;SKIP_VERIFICATION;%(PreprocessorDefinitions) + true + $(SolutionDir)include;$(SolutionDir)tests\libs\common;$(SolutionDir)tests\libs\util;$(OutDir);$(SolutionDir)external\catch2\src;$(SolutionDir)external\catch2\build\generated-includes;$(SolutionDir)external\bpftool;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories) + + + Console + DebugFull + ws2_32.lib;%(AdditionalDependencies) + + + + + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + $(SolutionDir)include;$(SolutionDir)tests\libs\common;$(SolutionDir)tests\libs\util;$(OutDir);$(SolutionDir)external\catch2\src;$(SolutionDir)external\catch2\build\generated-includes;$(SolutionDir)external\bpftool;$(SolutionDir)external\ebpf-verifier\src;%(AdditionalIncludeDirectories) + + + Console + true + true + DebugFull + ws2_32.lib;%(AdditionalDependencies) + + + + + + + + {75fe223a-3e45-4b0e-a2e8-04285e52e440} + + + {8bd3552a-2cfb-4a59-ab15-2031b97ada1e} + + + + + + + \ No newline at end of file