• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Alan-Jowett / ebpf-verifier / 15194704016

22 May 2025 08:53AM UTC coverage: 88.11% (-0.07%) from 88.177%
15194704016

push

github

elazarg
uniform class names and explicit constructors for adapt_sgraph.hpp

Signed-off-by: Elazar Gershuni <elazarg@gmail.com>

27 of 30 new or added lines in 1 file covered. (90.0%)

481 existing lines in 33 files now uncovered.

8552 of 9706 relevant lines covered (88.11%)

9089054.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.64
/src/test/conformance_check.cpp
1
// Copyright (c) Prevail Verifier contributors.
2
// SPDX-License-Identifier: MIT
3

4
// This program reads BPF instructions from stdin and memory contents from
5
// the first argument. It then executes the BPF program and prints the
6
// value of r0 at the end of execution.
7
// The program is intended to be used with the bpf conformance test suite.
8

9
#include <iostream>
10
#include <sstream>
11
#include <string>
12
#include <vector>
13

14
#include "CLI11/CLI11.hpp"
15
#include "ebpf_verifier.hpp"
16
#include "ebpf_yaml.hpp"
17

18
using namespace prevail;
19

20
/**
21
 * @brief Read in a string of hex bytes and return a vector of bytes.
22
 *
23
 * @param[in] input String containing hex bytes.
24
 * @return Vector of bytes.
25
 */
26
std::vector<std::byte> base16_decode(const std::string& input) {
876✔
27
    std::vector<std::byte> output;
876✔
28
    std::stringstream ss(input);
876✔
29
    std::string value;
876✔
30
    while (std::getline(ss, value, ' ')) {
56,632✔
31
        if (value.empty()) {
55,756✔
32
            continue;
27,878✔
33
        }
34
        try {
13,939✔
35
            output.push_back(static_cast<std::byte>(std::stoi(value, nullptr, 16)));
27,878✔
36
        } catch (std::invalid_argument&) {
×
37
            std::cerr << "base16_decode failed to decode " << value << "\n";
×
38
        } catch (std::out_of_range&) {
×
UNCOV
39
            std::cerr << "base16_decode failed to decode " << value << "\n";
×
UNCOV
40
        }
×
41
    }
42
    return output;
1,752✔
43
}
876✔
44

45
/**
46
 * @brief This program reads BPF instructions from stdin and memory contents from
47
 * the first argument. It then executes the BPF program and prints the
48
 * value of r0 at the end of execution.
49
 */
50
int main(int argc, char** argv) {
438✔
51
    CLI::App app{"Check conformance"};
1,095✔
52
    bool debug = false;
438✔
53
    app.add_flag("--debug", debug, "Debug");
1,095✔
54
    std::string memory_string;
438✔
55
    app.add_option("--memory,memory", memory_string, "base16 memory bytes");
1,095✔
56
    std::string program_string;
438✔
57
    app.add_option("--program", program_string, "base16 program bytes");
1,095✔
58
    std::string other_positional_argument;
438✔
59

60
    // Currently the conformance test project passes an empty string as an additional
61
    // positional argument. We need to accept it to make CLI11 parsing pass until
62
    // the test project is fixed.
63
    app.add_option("other", other_positional_argument, "Other");
1,095✔
64
    CLI11_PARSE(app, argc, argv);
438✔
65

66
    if (program_string.empty()) {
438✔
67
        std::getline(std::cin, program_string);
438✔
68
    }
69

70
    const auto& result = run_conformance_test_case(base16_decode(memory_string), base16_decode(program_string), debug);
438✔
71
    if (!result.success) {
438✔
72
        // Write failure reason to stdout since the bpf conformance library does not look at stderr.
73
        std::cout << "Verification failed\n";
2✔
74
        return 1;
1✔
75
    }
76
    if (result.r0_value.is_top()) {
436✔
77
        std::cout << "Couldn't determine r0 value\n";
4✔
78
        return 1;
2✔
79
    }
80
    if (!result.r0_value.singleton()) {
432✔
81
        std::cout << "r0 value is range [" << result.r0_value.lb() << ", " << result.r0_value.ub() << "]\n";
5✔
82
        return 1;
2✔
83
    }
84

85
    // Print output so the conformance test suite can check it.
86
    if (result.r0_value.singleton() && result.r0_value.singleton().value().fits_cast_to<int64_t>()) {
430✔
87
        std::cout << std::hex << result.r0_value.singleton().value().cast_to<uint64_t>() << std::endl;
645✔
88
    } else {
89
        std::cout << result.r0_value << std::endl;
219✔
90
    }
91

92
    return 0;
215✔
93
}
657✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc