Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
# SPDX-License-Identifier: MIT

.vscode
build
build
_codeql_build_dir
_codeql_detected_source_root
5 changes: 5 additions & 0 deletions runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ if (HAS_BPF_TEST_RUN_OPTS_BATCH_SIZE)
add_compile_definitions(HAS_BPF_TEST_RUN_OPTS_BATCH_SIZE)
endif()

Check_struct_has_member("bpf_test_run_opts" "flags" ${EBPF_INC_PATH}/bpf/bpf.h HAS_BPF_TEST_RUN_OPTS_FLAGS LANGUAGE CXX)
if (HAS_BPF_TEST_RUN_OPTS_FLAGS)
add_compile_definitions(HAS_BPF_TEST_RUN_OPTS_FLAGS)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
Expand Down
22 changes: 22 additions & 0 deletions runner/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
#include <vector>
#include <yaml-cpp/yaml.h>

#if defined(__linux__)
#include <linux/bpf.h>
// Define BPF_F_TEST_XDP_LIVE_FRAMES if not already defined
#ifndef BPF_F_TEST_XDP_LIVE_FRAMES
#define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1)
#endif
#endif

// Define unique_ptr to call bpf_object__close on destruction
struct bpf_object_deleter
{
Expand Down Expand Up @@ -209,6 +217,7 @@ main(int argc, char** argv)
std::string elf_file = test["elf_file"].as<std::string>();
int iteration_count = test["iteration_count"].as<int>();
std::optional<std::string> program_type;
bpf_prog_type actual_prog_type = DEFAULT_PROG_TYPE;
int batch_size;
bool pass_data = DEFAULT_PASS_DATA;
bool pass_context = DEFAULT_PASS_CONTEXT;
Expand Down Expand Up @@ -289,6 +298,7 @@ main(int argc, char** argv)
prog_type = DEFAULT_PROG_TYPE;
attach_type = DEFAULT_ATTACH_TYPE;
}
actual_prog_type = prog_type;
(void)bpf_program__set_type(program, prog_type);
}

Expand Down Expand Up @@ -344,6 +354,12 @@ main(int argc, char** argv)
opts.ctx_size_in = static_cast<uint32_t>(data_in.size());
opts.ctx_size_out = static_cast<uint32_t>(data_out.size());
}
#if defined(HAS_BPF_TEST_RUN_OPTS_FLAGS) && defined(__linux__)
// Set BPF_F_TEST_XDP_LIVE_FRAMES flag for XDP programs on Linux
if (actual_prog_type == BPF_PROG_TYPE_XDP) {
opts.flags |= BPF_F_TEST_XDP_LIVE_FRAMES;
}
#endif

if (bpf_prog_test_run_opts(bpf_program__fd(map_state_preparation_program), &opts)) {
throw std::runtime_error("Failed to run map_state_preparation program " + prep_program_name);
Expand Down Expand Up @@ -458,6 +474,12 @@ main(int argc, char** argv)
#if defined(HAS_BPF_TEST_RUN_OPTS_BATCH_SIZE)
opt.batch_size = batch_size;
#endif
#if defined(HAS_BPF_TEST_RUN_OPTS_FLAGS) && defined(__linux__)
// Set BPF_F_TEST_XDP_LIVE_FRAMES flag for XDP programs on Linux
if (actual_prog_type == BPF_PROG_TYPE_XDP) {
opt.flags |= BPF_F_TEST_XDP_LIVE_FRAMES;
}
#endif

int result = bpf_prog_test_run_opts(program, &opt);
if (result < 0) {
Expand Down
Loading