ROSE  0.11.50.0
TestCase.h
1 #ifndef ROSE_BinaryAnalysis_Concolic_TestCase_H
2 #define ROSE_BinaryAnalysis_Concolic_TestCase_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_CONCOLIC_TESTING
5 #include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
6 
7 #include <Rose/BinaryAnalysis/SymbolicExpr.h>
8 
9 #include <Sawyer/Optional.h>
10 #include <Sawyer/SharedObject.h>
11 #include <Sawyer/SharedPointer.h>
12 
13 #include <string>
14 #include <vector>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 namespace Concolic {
19 
21 typedef std::pair<std::string /*name*/, std::string /*value*/> EnvValue;
22 
26 class TestCase: public Sawyer::SharedObject, public Sawyer::SharedFromThis<TestCase> {
27 public:
30 
31 private:
32  mutable SAWYER_THREAD_TRAITS::Mutex mutex_; // protects the following data members
33  std::string name_; // name for debugging
34  std::string timestamp_; // time of creation
35  std::string executor_; // name of execution environment
36  SpecimenPtr specimen_; // the thing to run
37  std::vector<std::string> args_; // command line arguments
38  std::vector<EnvValue> env_; // environment variables
39  Sawyer::Optional<size_t> concolicResult_; // non-empty if concolically tested
40  Sawyer::Optional<double> concreteRank_; // rank after testing
41  bool concreteIsInteresting_; // concrete results present and interesting?
42  TestCaseId parent_; // test case from which this one was created, if any
43  std::vector<SymbolicExpr::Ptr> assertions_; // assertions for the SMT solver
44 
45 protected:
46  TestCase();
47 
48 public:
49  ~TestCase();
50 
52  static Ptr instance() {
53  return Ptr(new TestCase);
54  }
55 
57  static Ptr instance(const SpecimenPtr &specimen);
58 
64  TestCaseId parent() const;
65  void parent(TestCaseId);
76  std::string name() const; // value return is intentional for thread safety
77  void name(const std::string&);
85  std::string printableName(const DatabasePtr &db = DatabasePtr());
86 
88  void toYaml(std::ostream&, const DatabasePtr&, std::string prefix, ShowEvents, ShowAssertions);
89 
100  std::string timestamp() const;
101  void timestamp(const std::string&);
111  SpecimenPtr specimen() const;
112  void specimen(const SpecimenPtr&);
120  std::vector<std::string> args() const;
121  void args(std::vector<std::string> arguments);
126  std::vector<EnvValue> env() const;
127  void env(std::vector<EnvValue> envvars);
135  Sawyer::Optional<size_t> concolicResult() const {
136  return concolicResult_;
137  }
138  void concolicResult(const Sawyer::Optional<size_t> &x) {
139  concolicResult_ = x;
140  }
144  bool hasConcolicTest() const;
145 
151  Sawyer::Optional<double> concreteRank() const;
152  void concreteRank(Sawyer::Optional<double> val);
163  bool concreteIsInteresting() const;
164  void concreteIsInteresting(bool);
170  bool hasConcreteTest() const;
171 
175  const std::string& executor() const {
176  return executor_;
177  }
178  void executor(const std::string &x) {
179  executor_ = x;
180  }
186  const std::vector<SymbolicExpr::Ptr>& assertions() const {
187  return assertions_;
188  }
189  std::vector<SymbolicExpr::Ptr>& assertions() {
190  return assertions_;
191  }
192  void assertions(const std::vector<SymbolicExpr::Ptr> &v) {
193  assertions_ = v;
194  }
197  // We'll need to add additional information about how to run the specimen:
198  // 3. Auxilliary vector (auxv)
199  // 4. System calls that provide input (e.g., virtual file system, network, etc.)
200  // Some of this information might need to be separated into subclasses that support different architectures since the
201  // info for testing a Linux ELF executable is different from a Windows PE executable, which is different from how one
202  // would run firmware.
203 };
204 
205 } // namespace
206 } // namespace
207 } // namespace
208 
209 #endif
210 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:156
Main namespace for the ROSE library.
Reference-counting intrusive smart pointer.
Definition: SharedPointer.h:68
Creates SharedPointer from this.
Base class for reference counted objects.
Definition: SharedObject.h:64