ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
pytest.h
Go to the documentation of this file.
1#ifndef CPROVER_GOTO_SYMEX_PYTEST_H
2#define CPROVER_GOTO_SYMEX_PYTEST_H
3
6#include <mutex>
7#include <string>
8#include <vector>
9#include <fstream>
10
11class smt_convt;
12
15{
16private:
17 std::vector<std::vector<std::string>> test_cases;
18 std::vector<std::string> param_names;
19 std::string function_name;
20 mutable std::mutex data_mutex;
21
23 bool values_only = false;
24
26 std::string clean_variable_name(const std::string &name) const;
27
29 void write_test_body(
30 std::ofstream &file,
31 const std::string &module_name,
32 const std::string &func_name,
33 const std::vector<std::string> &param_names,
34 const std::vector<std::vector<std::string>> &test_data) const;
35
37 void write_witness(
38 std::ofstream &file,
39 const std::vector<std::string> &param_names,
40 const std::vector<std::vector<std::string>> &test_data) const;
41
43 std::string extract_function_name(
44 const symex_target_equationt &target,
45 smt_convt &smt_conv) const;
46
48 std::string convert_float_to_python(const std::string &c_float) const;
49
51 std::string escape_python_string(const std::string &str) const;
52
54 std::string convert_array_to_python_list(const expr2tc &array_expr) const;
55
57 std::string convert_struct_to_python_dict(const expr2tc &struct_expr) const;
58
60 bool is_char_array(const expr2tc &array_expr) const;
61
63 std::string convert_char_array_to_string(const expr2tc &array_expr) const;
64
66 void write_file_header(std::ofstream &file, const std::string &original_file)
67 const;
68
70 void write_imports(std::ofstream &file, const std::string &module_name) const;
71
73 static std::string build_param_list(const std::vector<std::string> &params);
74
76 static std::string fingerprint(const std::vector<std::string> &test_case);
77
79 void write_test_data(
80 std::ofstream &file,
81 const std::vector<std::string> &param_names,
82 const std::vector<std::vector<std::string>> &test_data) const;
83
85 void write_test_function(
86 std::ofstream &file,
87 const std::string &func_name,
88 const std::vector<std::string> &param_names) const;
89
90public:
91 pytest_generator() = default;
92
95 static constexpr const char *default_output_dir = "esbmc-pytest";
96
99 static std::string extract_module_name(const std::string &input_file);
100
102 static std::string generate_pytest_filename(const std::string &module_name);
103
105 void clear();
106
109 void collect(const symex_target_equationt &target, smt_convt &smt_conv);
110
114 void
115 generate(const std::string &output_dir, const std::string &file_name) const;
116
120 void set_values_only(bool enabled)
121 {
122 values_only = enabled;
123 }
124
125 void generate_single(
126 const std::string &output_dir,
127 const std::string &file_name,
128 const symex_target_equationt &target,
129 smt_convt &smt_conv,
130 const namespacet &ns);
131
133 bool has_tests() const;
134};
135
136#endif
Definition namespace.h:10
pytest_generator()=default
bool has_tests() const
Check if any test cases have been collected.
Definition pytest.cpp:1231
void generate(const std::string &output_dir, const std::string &file_name) const
Generate pytest file from collected data (called at end of coverage mode).
Definition pytest.cpp:1175
void collect(const symex_target_equationt &target, smt_convt &smt_conv)
Collect test data from a counterexample (called for each CEX in coverage mode).
Definition pytest.cpp:727
void set_values_only(bool enabled)
Single-shot generation for non-coverage mode.
Definition pytest.h:120
void clear()
Clear collected data (called at start of coverage run).
Definition pytest.cpp:719
static constexpr const char * default_output_dir
Default directory for –generate-pytest-testcase output, overridable with –pytest-output-dir (github #...
Definition pytest.h:95
static std::string extract_module_name(const std::string &input_file)
Extract module name from input file path and removes .py extension and directory.
Definition pytest.cpp:32
void generate_single(const std::string &output_dir, const std::string &file_name, const symex_target_equationt &target, smt_convt &smt_conv, const namespacet &ns)
Definition pytest.cpp:1237
static std::string generate_pytest_filename(const std::string &module_name)
Generate pytest filename from module name.
Definition pytest.cpp:50
Slim, frontend-facing SMT interface.
Definition smt_conv.h:30
Definition symex_target_equation.h:21
irep_container< expr2t > expr2tc
Definition irep2.h:431