ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
test_gen_guard.h
Go to the documentation of this file.
1#ifndef CPROVER_GOTO_SYMEX_TEST_GEN_GUARD_H
2#define CPROVER_GOTO_SYMEX_TEST_GEN_GUARD_H
3
5
6#include <filesystem>
7#include <fstream>
8#include <string>
9#include <vector>
10
14inline constexpr char ESBMC_GENERATED_MARKER[] = "Auto-generated by ESBMC";
15
22
26inline overwrite_verdict classify_existing(const std::filesystem::path &path)
27{
28 std::ifstream in(path);
29 if (!in)
31 std::string first_line;
32 if (!std::getline(in, first_line))
34 return first_line.find(ESBMC_GENERATED_MARKER) != std::string::npos
37}
38
49inline bool can_write_all(
50 const std::vector<std::filesystem::path> &paths,
51 const std::string &option_name)
52{
53 for (const auto &path : paths)
54 {
55 std::error_code ec;
56 if (!std::filesystem::exists(path, ec))
57 continue;
58
59 switch (classify_existing(path))
60 {
62 break;
65 "{} was not generated by ESBMC; refusing to overwrite it. Pass "
66 "{} <dir> to generate elsewhere.",
67 path.string(),
68 option_name);
69 return false;
72 "cannot read {} to check whether it is safe to overwrite; refusing. "
73 "Pass {} <dir> to generate elsewhere.",
74 path.string(),
75 option_name);
76 return false;
77 }
78 }
79 return true;
80}
81
82#endif
#define log_error(fmt,...)
Definition message.h:83
Definition path.py:1
overwrite_verdict
Definition test_gen_guard.h:17
@ foreign
Definition test_gen_guard.h:19
@ safe
Definition test_gen_guard.h:18
@ unreadable
Definition test_gen_guard.h:20
overwrite_verdict classify_existing(const std::filesystem::path &path)
An empty file is safe: a run killed mid-write leaves exactly that, and refusing it would wedge genera...
Definition test_gen_guard.h:26
constexpr char ESBMC_GENERATED_MARKER[]
Shared no-clobber guard for the test-case generators (CTest, pytest, ...): every file they write carr...
Definition test_gen_guard.h:14
bool can_write_all(const std::vector< std::filesystem::path > &paths, const std::string &option_name)
Checked up-front for every target path rather than per-file: refusing halfway through would leave a h...
Definition test_gen_guard.h:49