Skip to content

Commit

Permalink
no higher-order timed_execution()
Browse files Browse the repository at this point in the history
Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Nov 17, 2024
1 parent 835e315 commit 03ca56c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/crab_verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Invariants final {

public:
explicit Invariants(crab::invariant_table_t&& invariants) : invariants(std::move(invariants)) {}
explicit Invariants(Invariants&& invariants) = default;
explicit Invariants(const Invariants& invariants) = default;

bool is_valid_after(const label_t& label, const string_invariant& state) const;
void print_invariants(std::ostream& os, const cfg_t& cfg) const;
Expand Down
7 changes: 5 additions & 2 deletions src/main/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "memsize_linux.hpp"
#endif
#include "linux_verifier.hpp"
#include "utils.hpp"

// Avoid affecting other headers by macros.
#include "CLI11/CLI11.hpp"
Expand Down Expand Up @@ -245,7 +244,11 @@ int main(int argc, char** argv) {
std::cout << "\n";
return 0;
}
const auto [invariants, seconds] = timed_execution([&] { return analyze(cfg); });
const auto begin = std::chrono::steady_clock::now();
auto invariants = analyze(cfg);
const auto end = std::chrono::steady_clock::now();
const auto seconds = std::chrono::duration<double>(end - begin).count();

if (ebpf_verifier_options.verbosity_opts.print_invariants) {
invariants.print_invariants(std::cout, cfg);
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/linux_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// SPDX-License-Identifier: MIT
#if __linux__

#include <ctime>
#include <linux/bpf.h>
#include <tuple>
#include <unistd.h>

#include "config.hpp"
#include "linux_verifier.hpp"
#include "spec_type_descriptors.hpp"
#include "utils.hpp"

static int do_bpf(const bpf_cmd cmd, union bpf_attr& attr) { return syscall(321, cmd, &attr, sizeof(attr)); }

Expand All @@ -25,7 +23,7 @@ std::tuple<bool, double> bpf_verify_program(const EbpfProgramType& type, const s
buf[0] = 0;
memset(buf.data(), '\0', buf.size());

union bpf_attr attr{};
union bpf_attr attr {};
memset(&attr, '\0', sizeof(attr));
attr.prog_type = gsl::narrow<__u32>(type.platform_specific_data);
attr.insn_cnt = gsl::narrow<__u32>(raw_prog.size());
Expand All @@ -39,14 +37,18 @@ std::tuple<bool, double> bpf_verify_program(const EbpfProgramType& type, const s
attr.kern_version = 0x041800;
attr.prog_flags = 0;

const auto [res, elapsed_secs] = timed_execution([&] { return do_bpf(BPF_PROG_LOAD, attr); });
const auto begin = std::chrono::steady_clock::now();
const int res = do_bpf(BPF_PROG_LOAD, attr);
const auto end = std::chrono::steady_clock::now();
const auto seconds = std::chrono::duration<double>(end - begin).count();

if (res < 0) {
if (options->verbosity_opts.print_failures) {
std::cerr << "Failed to verify program: " << strerror(errno) << " (" << errno << ")\n";
std::cerr << "LOG: " << reinterpret_cast<char*>(attr.log_buf);
}
return {false, elapsed_secs};
return {false, seconds};
}
return {true, elapsed_secs};
return {true, seconds};
}
#endif
15 changes: 0 additions & 15 deletions src/main/utils.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/ebpf_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ std::optional<Failure> run_yaml_test_case(TestCase test_case, bool debug) {
thread_local_options = test_case.options;
try {
const cfg_t cfg = prepare_cfg(test_case.instruction_seq, info, test_case.options.cfg_opts);
auto invariants = analyze(cfg, test_case.assumed_pre_invariant);
const Invariants invariants = analyze(cfg, test_case.assumed_pre_invariant);
const string_invariant actual_last_invariant = invariants.invariant_at(label_t::exit);
const std::set<string> actual_messages = invariants.check_assertions(cfg).all_messages();

Expand Down Expand Up @@ -366,7 +366,7 @@ ConformanceTestResult run_conformance_test_case(const std::vector<std::byte>& me

try {
const cfg_t cfg = prepare_cfg(prog, info, options.cfg_opts);
auto invariants = analyze(cfg, pre_invariant);
const Invariants invariants = analyze(cfg, pre_invariant);
return ConformanceTestResult{.success = invariants.verified(cfg), .r0_value = invariants.exit_value()};
} catch (const std::exception&) {
// Catch exceptions thrown in ebpf_domain.cpp.
Expand Down

0 comments on commit 03ca56c

Please sign in to comment.