ROSE 0.11.145.192
Rose/BinaryAnalysis/Concolic/Database.h
1#ifndef ROSE_BinaryAnalysis_Concolic_Database_H
2#define ROSE_BinaryAnalysis_Concolic_Database_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_CONCOLIC_TESTING
5#include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
8#include <Rose/Constants.h>
9#include <rose_strtoull.h>
10
11#include <Sawyer/BiMap.h>
12#include <Sawyer/Database.h>
13#include <Sawyer/Optional.h>
14
15#include <boost/numeric/conversion/cast.hpp>
16
17#include <ctype.h>
18#include <string>
19
20namespace Rose {
21namespace BinaryAnalysis {
22namespace Concolic {
23
36class Database: public Sawyer::SharedObject, public Sawyer::SharedFromThis<Database>, boost::noncopyable {
37public:
40
41private:
42 Sawyer::Database::Connection connection_;
43
44 // Memoization of ID to object mappings
49
50 TestSuiteId testSuiteId_; // database scope is restricted to this single test suite
51
52protected:
53 Database();
54
55public:
56 ~Database();
57
64 static Ptr instance(const std::string &url);
65
67 Sawyer::Database::Connection connection() {
68 return connection_;
69 }
70
81 static Ptr create(const std::string &url);
82 static Ptr create(const std::string &url, const std::string &testSuiteName);
85 //------------------------------------------------------------------------------------------------------------------------
86 // Test suites
87 //------------------------------------------------------------------------------------------------------------------------
88
93 std::vector<TestSuiteId> testSuites();
94
102 TestSuitePtr testSuite();
103 TestSuiteId testSuite(const TestSuitePtr&);
106 //------------------------------------------------------------------------------------------------------------------------
107 // Specimens
108 //------------------------------------------------------------------------------------------------------------------------
109
114 std::vector<SpecimenId> specimens();
115
117 std::vector<SpecimenId> specimens(TestSuiteId);
118
120 void eraseSpecimens(TestSuiteId);
121
122 //------------------------------------------------------------------------------------------------------------------------
123 // Test cases
124 //------------------------------------------------------------------------------------------------------------------------
125
130 std::vector<TestCaseId> testCases();
131
133 std::vector<TestCaseId> testCases(SpecimenId);
134
136 void eraseTestCases(SpecimenId);
137
138 //------------------------------------------------------------------------------------------------------------------------
139 // Execution events
140 //------------------------------------------------------------------------------------------------------------------------
141
146 std::vector<ExecutionEventId> executionEvents();
147
151 std::vector<ExecutionEventId> executionEvents(TestCaseId);
152
154 size_t nExecutionEvents(TestCaseId);
155
160 std::vector<ExecutionEventId> executionEvents(TestCaseId, uint64_t primaryKey);
161
165 std::vector<ExecutionEventId> executionEventsSince(TestCaseId, ExecutionEventId startingAt);
166
170 std::vector<uint64_t> executionEventKeyFrames(TestCaseId);
171
173 void eraseExecutionEvents(TestCaseId);
174
175 //------------------------------------------------------------------------------------------------------------------------
176 // Overloaded methods for all objects.
177 //------------------------------------------------------------------------------------------------------------------------
178
185 TestSuitePtr object(TestSuiteId, Update update = Update::YES);
186 TestCasePtr object(TestCaseId, Update update = Update::YES);
187 SpecimenPtr object(SpecimenId, Update update = Update::YES);
188 ExecutionEventPtr object(ExecutionEventId, Update update = Update::YES);
199 TestSuiteId id(const TestSuitePtr&, Update update = Update::YES);
200 TestCaseId id(const TestCasePtr&, Update update = Update::YES);
201 SpecimenId id(const SpecimenPtr&, Update update = Update::YES);
202 ExecutionEventId id(const ExecutionEventPtr&, Update update = Update::YES);
208 TestSuiteId erase(TestSuiteId);
209 TestCaseId erase(TestCaseId);
210 SpecimenId erase(SpecimenId);
211 ExecutionEventId erase(ExecutionEventId);
218 template<class ObjectPointer>
219 typename ObjectTraits<typename ObjectPointer::Pointee>::Id
220 save(const ObjectPointer &obj) {
221 return id(obj);
222 }
223
227 template<class ObjectPointer>
228 void save(const std::vector<ObjectPointer> &objects) {
229 for (auto object: objects)
230 save(object);
231 }
232
236 template<class Id>
237 std::vector<typename Id::Pointer>
238 objects(const std::vector<Id> &ids, Update update = Update::YES) {
239 std::vector<typename Id::Pointer> retval;
240 for (auto id: ids)
241 retval.push_back(object(id, update));
242 return retval;
243 }
244
248 template<class ObjectPointer>
249 std::vector<typename ObjectTraits<ObjectPointer>::Id>
250 ids(const std::vector<ObjectPointer> &objects, Update update = Update::YES) {
251 std::vector<typename ObjectTraits<ObjectPointer>::Id> retval;
252 for (auto object: objects)
253 retval.push_back(id(object, update));
254 return retval;
255 }
256
263 TestSuitePtr findTestSuite(const std::string &nameOrId);
264
269 std::vector<SpecimenId> findSpecimensByName(const std::string &name);
270
271 //------------------------------------------------------------------------------------------------------------------------
272 // Cached info about disassembly. This is large data. Each specimen has zero or one associated RBA data blob.
273 //------------------------------------------------------------------------------------------------------------------------
274
281 bool rbaExists(SpecimenId);
282
291 void saveRbaFile(const boost::filesystem::path&, SpecimenId);
292
301 void extractRbaFile(const boost::filesystem::path&, SpecimenId);
302
308 void eraseRba(SpecimenId);
309
310 //------------------------------------------------------------------------------------------------------------------------
311 // Cached symbolic state.
312 //------------------------------------------------------------------------------------------------------------------------
313
317 bool symbolicStateExists(TestCaseId);
318
323 void saveSymbolicState(TestCaseId, const InstructionSemantics::BaseSemantics::StatePtr&);
324
328 InstructionSemantics::BaseSemantics::StatePtr extractSymbolicState(TestCaseId);
329
333 void eraseSymbolicState(TestCaseId);
334
335 //------------------------------------------------------------------------------------------------------------------------
336 // Cached concrete execution results. This is large data. Each test case has zero or one associated concrete results.
337 //------------------------------------------------------------------------------------------------------------------------
338
343 bool concreteResultExists(TestCaseId);
344
352 void saveConcreteResult(const TestCasePtr&, const ConcreteResultPtr&);
353
358 ConcreteResultPtr readConcreteResult(TestCaseId);
359
364 std::vector<TestCaseId> needConcreteTesting(size_t n = UNLIMITED);
365
367
368
369
378 void assocTestCaseWithTestSuite(TestCaseId, TestSuiteId);
379
384 std::vector<TestCaseId> needConcolicTesting(size_t n = UNLIMITED);
385
386#if 0 // [Robb Matzke 2020-07-15]
387 // Use saveConcreteResults instead, which allows concrete results to also be removed.
395 void insertConcreteResults(const TestCasePtr &testCase, const ConcreteResult& details);
396#endif
397
402 bool hasUntested();
403
405 static std::string timestamp();
406
407private:
408 static Ptr create(const std::string &url, const Sawyer::Optional<std::string> &testSuiteName);
409};
410
411} // namespace
412} // namespace
413} // namespace
414
415#endif
416#endif
One-to-one mapping between source and target values.
Definition BiMap.h:26
Holds a value or nothing.
Definition Optional.h:56
Creates SharedPointer from this.
Base class for reference counted objects.
Reference-counting intrusive smart pointer.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
void erase(GlobalVariables &, const AddressInterval &toErase)
Erase some global variables.
The ROSE library.
Id id(const std::string &name)
Returns the ID for an attribute name.