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

Alan-Jowett / ebpf-verifier / 22160684311

18 Feb 2026 09:20PM UTC coverage: 88.256% (+1.1%) from 87.142%
22160684311

push

github

elazarg
lint

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

78 of 82 new or added lines in 6 files covered. (95.12%)

402 existing lines in 18 files now uncovered.

10731 of 12159 relevant lines covered (88.26%)

837642.51 hits per line

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

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

4
#include <algorithm>
5
#include <bit>
6
#include <fstream>
7
#include <iostream>
8
#include <map>
9
#include <ranges>
10
#include <set>
11
#include <span>
12
#include <sstream>
13
#include <stdexcept>
14
#include <variant>
15

16
#include <yaml-cpp/yaml.h>
17

18
#include "ebpf_verifier.hpp"
19
#include "ir/parse.hpp"
20
#include "ir/syntax.hpp"
21
#include "string_constraints.hpp"
22
#include "test/ebpf_yaml.hpp"
23
#include "verifier.hpp"
24

25
using std::string;
26
using std::vector;
27

28
namespace prevail {
29
// The YAML tests for Call depend on Linux prototypes.
30
// parse_instruction() in asm_parse.cpp explicitly uses
31
// g_ebpf_platform_linux when parsing Call instructions
32
// so we do the same here.
33

34
static EbpfProgramType ebpf_get_program_type(const string& section, const string& path) {
×
UNCOV
35
    return g_ebpf_platform_linux.get_program_type(section, path);
×
36
}
37

38
static EbpfMapType ebpf_get_map_type(const uint32_t platform_specific_type) {
20✔
39
    return g_ebpf_platform_linux.get_map_type(platform_specific_type);
20✔
40
}
41

42
static EbpfHelperPrototype ebpf_get_helper_prototype(const int32_t n) {
68✔
43
    return g_ebpf_platform_linux.get_helper_prototype(n);
68✔
44
}
45

46
static bool ebpf_is_helper_usable(const int32_t n) { return g_ebpf_platform_linux.is_helper_usable(n); }
68✔
47

48
static void ebpf_parse_maps_section(vector<EbpfMapDescriptor>&, const char*, size_t, int, const ebpf_platform_t*,
×
UNCOV
49
                                    ebpf_verifier_options_t) {}
×
50

51
static EbpfMapDescriptor test_map_descriptor = {.original_fd = 0,
52
                                                .type = 0,
53
                                                .key_size = sizeof(uint32_t),
54
                                                .value_size = sizeof(uint32_t),
55
                                                .max_entries = 4,
56
                                                .inner_map_fd = 0};
57

58
static EbpfMapDescriptor& ebpf_get_map_descriptor(int) { return test_map_descriptor; }
200✔
59

60
ebpf_platform_t g_platform_test = {.get_program_type = ebpf_get_program_type,
61
                                   .get_helper_prototype = ebpf_get_helper_prototype,
62
                                   .is_helper_usable = ebpf_is_helper_usable,
63
                                   .map_record_size = 0,
64
                                   .parse_maps_section = ebpf_parse_maps_section,
65
                                   .get_map_descriptor = ebpf_get_map_descriptor,
66
                                   .get_map_type = ebpf_get_map_type,
67
                                   .supported_conformance_groups = bpf_conformance_groups_t::default_groups |
68
                                                                   bpf_conformance_groups_t::packet |
69
                                                                   bpf_conformance_groups_t::callx};
70

71
static EbpfProgramType make_program_type(const string& name, const ebpf_context_descriptor_t* context_descriptor) {
2,068✔
72
    return EbpfProgramType{.name = name,
1,347✔
73
                           .context_descriptor = context_descriptor,
74
                           .platform_specific_data = 0,
75
                           .section_prefixes = {},
76
                           .is_privileged = false};
1,034✔
77
}
78

79
static std::set<string> vector_to_set(const vector<string>& s) {
3,706✔
80
    std::set<string> res;
3,706✔
81
    for (const auto& item : s) {
16,832✔
82
        res.insert(item);
13,126✔
83
    }
84
    return res;
3,706✔
UNCOV
85
}
×
86

87
std::set<string> operator-(const std::set<string>& a, const std::set<string>& b) {
×
88
    std::set<string> res;
×
89
    std::ranges::set_difference(a, b, std::inserter(res, res.begin()));
×
90
    return res;
×
UNCOV
91
}
×
92

93
static StringInvariant read_invariant(const vector<string>& raw_invariant) {
2,958✔
94
    std::set<string> res = vector_to_set(raw_invariant);
2,958✔
95
    if (res == std::set<string>{"_|_"}) {
7,395✔
UNCOV
96
        return StringInvariant{};
×
97
    }
98
    return StringInvariant{std::move(res)};
5,916✔
99
}
10,353✔
100

101
static Label parse_label_scalar(const YAML::Node& node) {
20✔
102
    if (!node.IsDefined() || node.IsNull() || !node.IsScalar()) {
40✔
UNCOV
103
        throw std::runtime_error("Invalid observation label; expected scalar 'entry'/'exit' or instruction index");
×
104
    }
105

106
    const auto s = node.as<string>();
20✔
107
    if (s == "entry") {
20✔
UNCOV
108
        return Label::entry;
×
109
    }
110
    if (s == "exit") {
20✔
111
        return Label::exit;
16✔
112
    }
113

114
    try {
2✔
115
        size_t pos = 0;
4✔
116
        const int index = std::stoi(s, &pos);
4✔
117
        if (pos != s.size()) {
4✔
UNCOV
118
            throw std::runtime_error("Invalid observation label: " + s);
×
119
        }
120
        if (index < 0) {
4✔
121
            throw std::runtime_error("Invalid observation label: " + s);
3✔
122
        }
123
        return Label{index};
2✔
124
    } catch (const std::exception&) {
2✔
125
        throw std::runtime_error("Invalid observation label: " + s);
3✔
126
    }
2✔
127
}
19✔
128

129
static InvariantPoint parse_point(const YAML::Node& node) {
18✔
130
    if (!node.IsDefined() || node.IsNull()) {
25✔
131
        return InvariantPoint::pre;
4✔
132
    }
133
    const auto s = node.as<string>();
14✔
134
    if (s == "pre") {
14✔
135
        return InvariantPoint::pre;
1✔
136
    }
137
    if (s == "post") {
12✔
138
        return InvariantPoint::post;
6✔
139
    }
UNCOV
140
    throw std::runtime_error("Invalid observation point: " + s);
×
141
}
14✔
142

143
static ObservationCheckMode parse_mode(const YAML::Node& node) {
18✔
144
    if (!node.IsDefined() || node.IsNull()) {
25✔
145
        return ObservationCheckMode::consistent;
4✔
146
    }
147
    const auto s = node.as<string>();
14✔
148
    if (s == "consistent") {
14✔
149
        return ObservationCheckMode::consistent;
5✔
150
    }
151
    if (s == "entailed") {
4✔
152
        return ObservationCheckMode::entailed;
2✔
153
    }
UNCOV
154
    throw std::runtime_error("Invalid observation mode: " + s);
×
155
}
14✔
156

157
static std::vector<TestCase::Observation> parse_observations(const YAML::Node& observe_node) {
1,472✔
158
    std::vector<TestCase::Observation> res;
1,472✔
159
    if (!observe_node.IsDefined() || observe_node.IsNull()) {
1,491✔
160
        return res;
724✔
161
    }
162
    if (!observe_node.IsSequence()) {
24✔
163
        throw std::runtime_error("observe must be a sequence");
2✔
164
    }
165
    for (const auto& item : observe_node) {
79✔
166
        if (!item.IsMap()) {
22✔
167
            throw std::runtime_error("observe item must be a map");
2✔
168
        }
169
        const Label label = parse_label_scalar(item["at"]);
21✔
170
        const InvariantPoint point = parse_point(item["point"]);
18✔
171
        const ObservationCheckMode mode = parse_mode(item["mode"]);
20✔
172
        const YAML::Node constraints_node = item["constraints"];
18✔
173
        if (!constraints_node.IsDefined() || constraints_node.IsNull()) {
26✔
174
            throw std::runtime_error("observe item missing required 'constraints' field");
2✔
175
        }
176
        if (!constraints_node.IsSequence()) {
16✔
177
            throw std::runtime_error("observe.constraints must be a sequence of strings");
2✔
178
        }
179
        const auto constraints_vec = constraints_node.as<vector<string>>();
14✔
180
        TestCase::Observation obs;
14✔
181
        obs.label = label;
14✔
182
        obs.point = point;
14✔
183
        obs.mode = mode;
14✔
184
        obs.constraints = read_invariant(constraints_vec);
21✔
185
        res.push_back(std::move(obs));
14✔
186
    }
65✔
187
    return res;
14✔
188
}
10✔
189

190
struct RawTestCase {
191
    string test_case;
192
    std::optional<string> expected_exception;
193
    std::set<string> options;
194
    vector<string> pre;
195
    vector<std::tuple<string, vector<string>>> raw_blocks;
196
    vector<string> post;
197
    std::set<string> messages;
198
    YAML::Node observe;
199
};
200

201
static vector<string> parse_block(const YAML::Node& block_node) {
1,768✔
202
    vector<string> block;
1,768✔
203
    std::istringstream is{block_node.as<string>()};
1,768✔
204
    string line;
1,768✔
205
    while (std::getline(is, line)) {
4,154✔
206
        block.emplace_back(line);
2,386✔
207
    }
208
    return block;
3,536✔
209
}
1,768✔
210

211
static auto parse_code(const YAML::Node& code_node) {
1,472✔
212
    vector<std::tuple<string, vector<string>>> res;
1,472✔
213
    for (const auto& item : code_node) {
7,364✔
214
        res.emplace_back(item.first.as<string>(), parse_block(item.second));
2,652✔
215
    }
3,240✔
216
    return res;
1,472✔
UNCOV
217
}
×
218

219
static std::set<string> as_set_empty_default(const YAML::Node& optional_node) {
2,944✔
220
    if (!optional_node.IsDefined() || optional_node.IsNull()) {
3,318✔
221
        return {};
2,196✔
222
    }
223
    return vector_to_set(optional_node.as<vector<string>>());
748✔
224
}
225

226
static std::optional<string> as_optional_string(const YAML::Node& optional_node) {
1,472✔
227
    if (!optional_node.IsDefined() || optional_node.IsNull()) {
1,477✔
228
        return std::nullopt;
1,462✔
229
    }
230
    return optional_node.as<string>();
15✔
231
}
232

233
static RawTestCase parse_case(const YAML::Node& case_node) {
1,472✔
234
    return RawTestCase{
2,208✔
235
        .test_case = case_node["test-case"].as<string>(),
236
        .expected_exception = as_optional_string(case_node["expected-exception"]),
237
        .options = as_set_empty_default(case_node["options"]),
238
        .pre = case_node["pre"].as<vector<string>>(),
239
        .raw_blocks = parse_code(case_node["code"]),
240
        .post = case_node["post"].as<vector<string>>(),
241
        .messages = as_set_empty_default(case_node["messages"]),
242
        .observe = case_node["observe"],
243
    };
2,208✔
244
}
245

246
static InstructionSeq raw_cfg_to_instruction_seq(const vector<std::tuple<string, vector<string>>>& raw_blocks) {
1,472✔
247
    std::map<string, Label> label_name_to_label;
1,472✔
248

249
    int label_index = 0;
1,472✔
250
    for (const auto& [label_name, raw_block] : raw_blocks) {
3,240✔
251
        label_name_to_label.emplace(label_name, label_index);
1,768✔
252
        // don't count large instructions as 2
253
        label_index += gsl::narrow<int>(raw_block.size());
1,768✔
254
    }
255

256
    InstructionSeq res;
1,472✔
257
    label_index = 0;
1,472✔
258
    for (const auto& [label_name, raw_block] : raw_blocks) {
3,240✔
259
        for (const string& line : raw_block) {
4,154✔
260
            try {
1,193✔
261
                const Instruction& ins = parse_instruction(line, label_name_to_label);
2,386✔
262
                if (std::holds_alternative<Undefined>(ins)) {
2,386✔
UNCOV
263
                    std::cout << "text:" << line << "; ins: " << ins << "\n";
×
264
                }
265
                res.emplace_back(label_index, ins, std::optional<btf_line_info_t>());
3,579✔
266
            } catch (const std::exception& e) {
2,386✔
267
                std::cout << "text:" << line << "; error: " << e.what() << "\n";
×
268
                res.emplace_back(label_index, Undefined{0}, std::optional<btf_line_info_t>());
×
UNCOV
269
            }
×
270
            label_index++;
2,386✔
271
        }
272
    }
273
    return res;
2,208✔
274
}
1,472✔
275

276
static ebpf_verifier_options_t raw_options_to_options(const std::set<string>& raw_options) {
1,472✔
277
    ebpf_verifier_options_t options{};
1,472✔
278

279
    // Use ~simplify for YAML tests unless otherwise specified.
280
    options.verbosity_opts.simplify = false;
1,472✔
281

282
    // All YAML tests use !setup_constraints.
283
    options.setup_constraints = false;
1,472✔
284

285
    // Default to the machine's native endianness.
286
    options.big_endian = std::endian::native == std::endian::big;
1,472✔
287

288
    // Permit test cases to not have an exit instruction.
289
    options.cfg_opts.must_have_exit = false;
1,472✔
290

291
    for (const string& name : raw_options) {
1,656✔
292
        if (name == "!allow_division_by_zero") {
184✔
293
            options.allow_division_by_zero = false;
32✔
294
        } else if (name == "termination") {
120✔
295
            options.cfg_opts.check_for_termination = true;
21✔
296
        } else if (name == "strict") {
78✔
297
            options.strict = true;
298
        } else if (name == "simplify") {
78✔
299
            options.verbosity_opts.simplify = true;
1✔
300
        } else if (name == "big_endian") {
76✔
301
            options.big_endian = true;
17✔
302
        } else if (name == "!big_endian") {
42✔
303
            options.big_endian = false;
21✔
304
        } else {
UNCOV
305
            throw std::runtime_error("Unknown option: " + name);
×
306
        }
307
    }
308
    return options;
1,472✔
309
}
310

311
static TestCase read_case(const RawTestCase& raw_case) {
1,472✔
312
    return TestCase{.name = raw_case.test_case,
1,527✔
313
                    .options = raw_options_to_options(raw_case.options),
1,472✔
314
                    .assumed_pre_invariant = read_invariant(raw_case.pre),
1,472✔
315
                    .instruction_seq = raw_cfg_to_instruction_seq(raw_case.raw_blocks),
1,472✔
316
                    .expected_post_invariant = read_invariant(raw_case.post),
1,472✔
317
                    .expected_messages = raw_case.messages,
1,472✔
318
                    .observations = parse_observations(raw_case.observe)};
1,472✔
319
}
320

321
static vector<TestCase> read_suite(const string& path) {
54✔
322
    std::ifstream f{path};
54✔
323
    vector<TestCase> res;
54✔
324
    for (const YAML::Node& config : YAML::LoadAll(f)) {
1,526✔
325
        const RawTestCase raw_case = parse_case(config);
1,472✔
326
        if (raw_case.expected_exception.has_value()) {
1,472✔
327
            TestCase tc;
10✔
328
            tc.name = raw_case.test_case;
10✔
329
            tc.expected_exception = raw_case.expected_exception;
10✔
330

331
            try {
5✔
332
                (void)read_case(raw_case);
10✔
UNCOV
333
                tc.actual_exception = std::nullopt;
×
334
            } catch (const std::exception& ex) {
10✔
335
                tc.actual_exception = ex.what();
10✔
336
            }
10✔
337

338
            res.push_back(std::move(tc));
10✔
339
        } else {
10✔
340
            res.push_back(read_case(raw_case));
2,193✔
341
        }
342
    }
1,526✔
343
    return res;
81✔
344
}
54✔
345

346
template <typename T>
UNCOV
347
static Diff<T> make_diff(const T& actual, const T& expected) {
×
348
    return Diff<T>{
349
        .unexpected = actual - expected,
350
        .unseen = expected - actual,
351
    };
×
UNCOV
352
}
×
353

354
std::optional<Failure> run_yaml_test_case(TestCase test_case, bool debug) {
1,452✔
355
    if (test_case.expected_exception.has_value()) {
1,452✔
356
        const std::set<string> expected_messages{"Exception: " + *test_case.expected_exception};
25✔
357
        std::set<string> actual_messages;
10✔
358
        if (test_case.actual_exception.has_value()) {
10✔
359
            actual_messages.insert("Exception: " + *test_case.actual_exception);
15✔
360
        }
361
        if (actual_messages == expected_messages) {
10✔
362
            return {};
10✔
363
        }
364
        return Failure{
×
UNCOV
365
            .invariant = make_diff(StringInvariant::top(), StringInvariant::top()),
×
366
            .messages = make_diff(actual_messages, expected_messages),
UNCOV
367
        };
×
368
    }
10✔
369

370
    thread_local_options = {};
1,442✔
371
    ThreadLocalGuard clear_thread_local_state;
721✔
372
    test_case.options.verbosity_opts.print_failures = true;
1,442✔
373
    if (debug) {
1,442✔
UNCOV
374
        test_case.options.verbosity_opts.print_invariants = true;
×
375
    }
376

377
    ebpf_context_descriptor_t context_descriptor{64, 0, 4, -1};
1,442✔
378
    EbpfProgramType program_type = make_program_type(test_case.name, &context_descriptor);
1,442✔
379

380
    ProgramInfo info{&g_platform_test, {test_map_descriptor}, program_type};
2,163✔
381
    thread_local_options = test_case.options;
1,442✔
382
    try {
721✔
383
        const Program prog = Program::from_sequence(test_case.instruction_seq, info, test_case.options);
1,442✔
384
        const AnalysisResult result = analyze(prog, test_case.assumed_pre_invariant);
1,432✔
385
        const StringInvariant actual_last_invariant = result.invariant_at(Label::exit);
1,432✔
386
        std::set<string> actual_messages;
1,432✔
387
        if (auto error = result.find_first_error()) {
1,432✔
388
            actual_messages.insert(to_string(*error));
474✔
389
        }
716✔
390
        for (const auto& [label, msgs] : result.find_unreachable(prog)) {
1,614✔
391
            for (const auto& msg : msgs) {
364✔
392
                actual_messages.insert(msg);
182✔
393
            }
394
        }
716✔
395

396
        // Evaluate optional observation checks.
397
        for (const auto& obs : test_case.observations) {
1,446✔
398
            const ObservationCheckResult check =
7✔
399
                result.check_observation_at_label(obs.label, obs.point, obs.constraints, obs.mode);
14✔
400
            if (!check.ok) {
14✔
401
                const std::string point_s = (obs.point == InvariantPoint::pre) ? "pre" : "post";
8✔
402
                const std::string mode_s = (obs.mode == ObservationCheckMode::consistent) ? "consistent" : "entailed";
5✔
403
                // Keep the message stable for YAML expectations; details are available via debug logging.
404
                actual_messages.insert(to_string(obs.label) + ": observation " + mode_s + " failed at " + point_s);
12✔
405
                if (debug && !check.message.empty()) {
4✔
406
                    std::cout << "Observation check failed at " << obs.label << " (" << point_s << ", " << mode_s
×
UNCOV
407
                              << "): " << check.message << "\n";
×
408
                }
409
            }
4✔
410
        }
14✔
411

412
        if (actual_last_invariant == test_case.expected_post_invariant &&
2,864✔
413
            actual_messages == test_case.expected_messages) {
1,432✔
414
            return {};
1,432✔
415
        }
416
        return Failure{
×
417
            .invariant = make_diff(actual_last_invariant, test_case.expected_post_invariant),
×
418
            .messages = make_diff(actual_messages, test_case.expected_messages),
×
UNCOV
419
        };
×
420
    } catch (InvalidControlFlow& ex) {
2,158✔
421
        const std::set<string> actual_messages{ex.what()};
25✔
422
        if (test_case.expected_post_invariant == StringInvariant::top() &&
30✔
423
            actual_messages == test_case.expected_messages) {
10✔
424
            return {};
10✔
425
        }
426
        return Failure{
×
427
            .invariant = make_diff(StringInvariant::top(), test_case.expected_post_invariant),
×
428
            .messages = make_diff(actual_messages, test_case.expected_messages),
×
UNCOV
429
        };
×
430
    } catch (const std::exception& ex) {
10✔
431
        const std::set<string> actual_messages{std::string{"Exception: "} + ex.what()};
×
432
        return Failure{
×
433
            .invariant = make_diff(StringInvariant::top(), test_case.expected_post_invariant),
×
434
            .messages = make_diff(actual_messages, test_case.expected_messages),
×
435
        };
×
UNCOV
436
    }
×
437
}
2,198✔
438

439
template <typename T>
440
    requires std::is_trivially_copyable_v<T>
441
static vector<T> vector_of(const std::vector<std::byte>& bytes) {
442
    auto data = bytes.data();
443
    const auto size = bytes.size();
444
    if (size % sizeof(T) != 0 || size > std::numeric_limits<uint32_t>::max() || !data) {
445
        throw std::runtime_error("Invalid argument to vector_of");
446
    }
447
    return {reinterpret_cast<const T*>(data), reinterpret_cast<const T*>(data + size)};
448
}
449

450
template <std::signed_integral TS>
451
void add_stack_variable(std::set<std::string>& more, int& offset, const std::vector<std::byte>& memory_bytes) {
138✔
452
    using TU = std::make_unsigned_t<TS>;
453
    constexpr size_t size = sizeof(TS);
138✔
454
    static_assert(sizeof(TU) == size);
455
    const auto src = memory_bytes.data() + offset + memory_bytes.size() - EBPF_TOTAL_STACK_SIZE;
138✔
456
    TS svalue;
457
    std::memcpy(&svalue, src, size);
138✔
458
    TU uvalue;
459
    std::memcpy(&uvalue, src, size);
138✔
460
    const auto range = "s[" + std::to_string(offset) + "..." + std::to_string(offset + size - 1) + "]";
345✔
461
    more.insert(range + ".svalue=" + std::to_string(svalue));
207✔
462
    more.insert(range + ".uvalue=" + std::to_string(uvalue));
207✔
463
    offset += size;
138✔
464
}
138✔
465

466
StringInvariant stack_contents_invariant(const std::vector<std::byte>& memory_bytes) {
80✔
467
    std::set<std::string> more = {"r1.type=stack",
40✔
468
                                  "r1.stack_offset=" + std::to_string(EBPF_TOTAL_STACK_SIZE - memory_bytes.size()),
120✔
469
                                  "r1.stack_numeric_size=" + std::to_string(memory_bytes.size()),
160✔
470
                                  "r10.type=stack",
471
                                  "r10.stack_offset=" + std::to_string(EBPF_TOTAL_STACK_SIZE),
120✔
472
                                  "s[" + std::to_string(EBPF_TOTAL_STACK_SIZE - memory_bytes.size()) + "..." +
240✔
473
                                      std::to_string(EBPF_TOTAL_STACK_SIZE - 1) + "].type=number"};
760✔
474

475
    int offset = EBPF_TOTAL_STACK_SIZE - gsl::narrow<int>(memory_bytes.size());
120✔
476
    if (offset % 2 != 0) {
80✔
477
        add_stack_variable<int8_t>(more, offset, memory_bytes);
8✔
478
    }
479
    if (offset % 4 != 0) {
80✔
480
        add_stack_variable<int16_t>(more, offset, memory_bytes);
20✔
481
    }
482
    if (offset % 8 != 0) {
80✔
483
        add_stack_variable<int32_t>(more, offset, memory_bytes);
26✔
484
    }
485
    while (offset < EBPF_TOTAL_STACK_SIZE) {
164✔
486
        add_stack_variable<int64_t>(more, offset, memory_bytes);
84✔
487
    }
488

489
    return StringInvariant(std::move(more));
200✔
490
}
560✔
491

492
// Helper to convert uint8_t memory to stack invariant
493
static StringInvariant stack_contents_invariant(const std::vector<uint8_t>& memory_bytes) {
80✔
494
    std::vector<std::byte> bytes(memory_bytes.size());
80✔
495
    std::transform(memory_bytes.begin(), memory_bytes.end(), bytes.begin(),
80✔
496
                   [](uint8_t b) { return static_cast<std::byte>(b); });
412✔
497
    return stack_contents_invariant(bytes);
120✔
498
}
80✔
499

500
ConformanceTestResult run_conformance_test_case(const std::vector<uint8_t>& memory_bytes,
626✔
501
                                                std::span<const EbpfInst> instructions, bool debug) {
502
    ebpf_context_descriptor_t context_descriptor{64, -1, -1, -1};
626✔
503
    EbpfProgramType program_type = make_program_type("conformance_check", &context_descriptor);
939✔
504

505
    ProgramInfo info{&g_platform_test, {}, program_type};
626✔
506

507
    // Copy instructions into a local vector for RawProgram.
508
    std::vector<EbpfInst> insts(instructions.begin(), instructions.end());
626✔
509

510
    StringInvariant pre_invariant = StringInvariant::top();
626✔
511

512
    if (!memory_bytes.empty()) {
626✔
513
        if (memory_bytes.size() > EBPF_TOTAL_STACK_SIZE) {
80✔
UNCOV
514
            std::cerr << "memory size overflow\n";
×
UNCOV
515
            return {};
×
516
        }
517
        pre_invariant = pre_invariant + stack_contents_invariant(memory_bytes);
200✔
518
    }
519
    RawProgram raw_prog{.prog = insts};
626✔
520
    ebpf_platform_t platform = g_ebpf_platform_linux;
626✔
521
    platform.supported_conformance_groups |= bpf_conformance_groups_t::callx;
626✔
522
    raw_prog.info.platform = &platform;
626✔
523

524
    // Convert the raw program section to a set of instructions.
525
    std::variant<InstructionSeq, std::string> prog_or_error = unmarshal(raw_prog, {});
626✔
526
    if (auto prog = std::get_if<std::string>(&prog_or_error)) {
626✔
527
        std::cerr << "unmarshaling error at " << *prog << "\n";
×
528
        return ConformanceTestResult{.success = false, .r0_value = Interval::top(), .error_reason = *prog};
313✔
529
    }
530

531
    const InstructionSeq& inst_seq = std::get<InstructionSeq>(prog_or_error);
626✔
532

533
    ebpf_verifier_options_t options{};
626✔
534
    if (debug) {
626✔
UNCOV
535
        print(inst_seq, std::cout, {});
×
536
        options.verbosity_opts.print_failures = true;
×
537
        options.verbosity_opts.print_invariants = true;
×
UNCOV
538
        options.verbosity_opts.simplify = false;
×
539
    }
540

541
    try {
313✔
542
        const Program prog = Program::from_sequence(inst_seq, info, options);
626✔
543
        const AnalysisResult result = analyze(prog, pre_invariant);
626✔
544
        return ConformanceTestResult{.success = !result.failed, .r0_value = result.exit_value};
626✔
545
    } catch (const std::exception& ex) {
626✔
546
        // Catch exceptions thrown in ebpf_domain.cpp.
547
        return ConformanceTestResult{.success = false, .r0_value = Interval::top(), .error_reason = ex.what()};
×
548
    }
×
549
}
1,252✔
550

UNCOV
551
void print_failure(const Failure& failure, std::ostream& os) {
×
UNCOV
552
    constexpr auto INDENT = "  ";
×
553
    if (!failure.invariant.unexpected.empty()) {
×
554
        os << "Unexpected properties:\n" << INDENT << failure.invariant.unexpected << "\n";
×
555
    } else {
556
        os << "Unexpected properties: None\n";
×
557
    }
UNCOV
558
    if (!failure.invariant.unseen.empty()) {
×
559
        os << "Unseen properties:\n" << INDENT << failure.invariant.unseen << "\n";
×
560
    } else {
UNCOV
561
        os << "Unseen properties: None\n";
×
562
    }
563

564
    if (!failure.messages.unexpected.empty()) {
×
565
        os << "Unexpected messages:\n";
×
UNCOV
566
        for (const auto& item : failure.messages.unexpected) {
×
UNCOV
567
            os << INDENT << item << "\n";
×
568
        }
569
    } else {
570
        os << "Unexpected messages: None\n";
×
571
    }
572

UNCOV
573
    if (!failure.messages.unseen.empty()) {
×
UNCOV
574
        os << "Unseen messages:\n";
×
UNCOV
575
        for (const auto& item : failure.messages.unseen) {
×
UNCOV
576
            os << INDENT << item << "\n";
×
577
        }
578
    } else {
UNCOV
579
        os << "Unseen messages: None\n";
×
580
    }
UNCOV
581
}
×
582

583
void foreach_suite(const string& path, const std::function<void(const TestCase&)>& f) {
1,452✔
584
    static std::map<string, vector<TestCase>> cache;
1,452✔
585
    auto [it, inserted] = cache.try_emplace(path);
1,452✔
586
    if (inserted) {
1,452✔
587
        try {
27✔
588
            it->second = read_suite(path);
54✔
UNCOV
589
        } catch (...) {
×
UNCOV
590
            cache.erase(it);
×
UNCOV
591
            throw;
×
UNCOV
592
        }
×
593
    }
594
    for (const TestCase& test_case : it->second) {
86,726✔
595
        f(test_case);
127,911✔
596
    }
597
}
1,452✔
598
} // namespace prevail
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