Skip to content

Commit

Permalink
Merge branch 'main' into div32
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-Jowett committed Feb 13, 2024
2 parents b2f9564 + 56950c4 commit 61cbd82
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions include/bpf_conformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef enum class _bpf_conformance_groups
divmul64 = 0x00000020,
packet = 0x00000040,
callx = 0x00000080,
default_groups = base32 | base64 | atomic32 | atomic64 | divmul32 | divmul64, // not callx or packet
} bpf_conformance_groups_t;

inline bpf_conformance_groups_t
Expand Down Expand Up @@ -118,6 +119,7 @@ bpf_conformance_options(
* @param[in] include_test_regex A regex that matches the tests to include.
* @param[in] exclude_test_regex A regex that matches the tests to exclude.
* @param[in] cpu_version The CPU version to run the tests with.
* @param[in] groups The conformance groups to run the tests with.
* @param[in] list_instructions_option Option controlling which instructions to list.
* @param[in] debug Print debug information.
* @return The test results for each test file.
Expand All @@ -130,6 +132,7 @@ bpf_conformance(
std::optional<std::string> include_test_regex = std::nullopt,
std::optional<std::string> exclude_test_regex = std::nullopt,
bpf_conformance_test_cpu_version_t cpu_version = bpf_conformance_test_cpu_version_t::v3,
bpf_conformance_groups_t groups = bpf_conformance_groups_t::default_groups,
bpf_conformance_list_instructions_t list_instructions_option =
bpf_conformance_list_instructions_t::LIST_INSTRUCTIONS_NONE,
bool debug = false)
Expand All @@ -138,6 +141,7 @@ bpf_conformance(
options.include_test_regex = include_test_regex;
options.exclude_test_regex = exclude_test_regex;
options.cpu_version = cpu_version;
options.groups = groups,
options.list_instructions_option = list_instructions_option;
options.debug = debug;
return bpf_conformance_options(test_files, plugin_path, plugin_options, options);
Expand Down
5 changes: 2 additions & 3 deletions src/bpf_assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,12 @@ typedef class _bpf_assembler
if (mode == "helper") {
if (target.starts_with('%')) {
inst.opcode |= EBPF_SRC_REG;
inst.imm = 0;
inst.src = _decode_register(target);
inst.dst = _decode_register(target);
} else {
inst.opcode |= EBPF_SRC_IMM;
inst.imm = _decode_imm32(target);
inst.src = 0;
}
inst.src = 0;
} else if (mode == "local") {
inst.imm = _decode_jump_target(target);
inst.src = 1;
Expand Down
50 changes: 38 additions & 12 deletions src/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ _get_test_files(const std::filesystem::path& test_file_directory)

static const std::map<std::string, bpf_conformance_groups_t> _conformance_groups = {
{"atomic32", bpf_conformance_groups_t::atomic32},
{"atomic64", bpf_conformance_groups_t::atomic64},
{"atomic64", bpf_conformance_groups_t::atomic32 | bpf_conformance_groups_t::atomic64},
{"base32", bpf_conformance_groups_t::base32},
{"base64", bpf_conformance_groups_t::base64},
{"base64", bpf_conformance_groups_t::base32 | bpf_conformance_groups_t::base64},
{"callx", bpf_conformance_groups_t::callx},
{"divmul32", bpf_conformance_groups_t::divmul32},
{"divmul64", bpf_conformance_groups_t::divmul64},
{"divmul64", bpf_conformance_groups_t::divmul32 | bpf_conformance_groups_t::divmul64},
{"packet", bpf_conformance_groups_t::packet}};

static std::optional<bpf_conformance_groups_t>
Expand All @@ -79,6 +79,19 @@ _get_conformance_group_by_name(std::string group)
return _conformance_groups.find(group)->second;
}

static std::string
_get_conformance_group_names()
{
std::string result;
for (const auto& entry : _conformance_groups) {
if (!result.empty()) {
result += ", ";
}
result += entry.first;
}
return result;
}

int
main(int argc, char** argv)
{
Expand All @@ -98,13 +111,13 @@ main(int argc, char** argv)
"debug", boost::program_options::value<bool>(), "Print debug information")(
"xdp_prolog", boost::program_options::value<bool>(), "XDP prolog")(
"elf", boost::program_options::value<bool>(), "ELF format")(
"cpu_version", boost::program_options::value<std::string>(), "CPU version")(
"cpu_version", boost::program_options::value<std::string>(), "CPU version (valid values: v1, v2, v3, v4), default is v3")(
"include_groups",
boost::program_options::value<std::vector<std::string>>()->multitoken(),
"Include conformance groups")(
("Include conformance groups (valid group names: " + _get_conformance_group_names() + ")").c_str())(
"exclude_groups",
boost::program_options::value<std::vector<std::string>>()->multitoken(),
"Exclude conformance groups")(
"Exclude conformance groups, where callx and packet are excluded by default")(
"include_regex", boost::program_options::value<std::string>(), "Include regex")(
"exclude_regex", boost::program_options::value<std::string>(), "Exclude regex");

Expand All @@ -113,7 +126,24 @@ main(int argc, char** argv)
boost::program_options::notify(vm);

if (vm.count("help")) {
std::cout << desc << std::endl;
std::cout << "Usage: bpf_conformance_runner [options]" << std::endl;
std::cout << std::endl << desc;
std::cout << R"(
Examples:
bpf_conformance_runner --test_file_directory ./tests --plugin_path ./my_plugin --exclude_groups atomic64
Run all tests in the ./tests directory, allowing instructions in cpu version 3
but without the atomic64 (or atomic32 which is a subset of atomic64), callx, or packet
conformance groups.
bpf_conformance_runner --test_file_directory ./tests --plugin_path ./my_plugin --cpu_version v2 --include_groups callx atomic64 --exclude_groups atomic32
Run all tests in the ./tests directory, allowing instructions in cpu version 2
plus the callx and atomic64 conformance groups, except for those in atomic32 or packet.
bpf_conformance_runner --test_file_directory ./tests --plugin_path ./my_plugin --exclude_regex "lock+"
Run all tests in the ./tests directory, allowing instructions in cpu version 3
but without the callx or packet conformance group, skipping any tests whose
filenames contain "loc" followed by one or more "k"s.
)";
return 1;
}

Expand Down Expand Up @@ -156,11 +186,7 @@ main(int argc, char** argv)
}

// Enable default conformance groups, which don't include callx or packet.
bpf_conformance_groups_t groups = bpf_conformance_groups_t::base32 | bpf_conformance_groups_t::base64 |
bpf_conformance_groups_t::divmul32 | bpf_conformance_groups_t::divmul64;
if (cpu_version >= bpf_conformance_test_cpu_version_t::v3) {
groups |= bpf_conformance_groups_t::atomic32 | bpf_conformance_groups_t::atomic64;
}
bpf_conformance_groups_t groups = bpf_conformance_groups_t::default_groups;
if (vm.count("include_groups")) {
auto include_groups = vm["include_groups"].as<std::vector<std::string>>();
for (std::string group_name : include_groups) {
Expand Down

0 comments on commit 61cbd82

Please sign in to comment.