]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/lldb-perf/lib/TestCase.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / tools / lldb-perf / lib / TestCase.h
1 //===-- TestCase.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef __PerfTestDriver__TestCase__
11 #define __PerfTestDriver__TestCase__
12
13 #include "Measurement.h"
14 #include "lldb/API/LLDB.h"
15 #include <getopt.h>
16
17 namespace lldb_perf {
18
19 class Results;
20
21 class TestCase {
22 public:
23   TestCase();
24
25   struct ActionWanted {
26     enum class Type {
27       eStepOver,
28       eContinue,
29       eStepOut,
30       eRelaunch,
31       eCallNext,
32       eNone,
33       eKill
34     } type;
35     lldb::SBThread thread;
36     lldb::SBLaunchInfo launch_info;
37
38     ActionWanted() : type(Type::eContinue), thread(), launch_info(NULL) {}
39
40     void None() {
41       type = Type::eNone;
42       thread = lldb::SBThread();
43     }
44
45     void Continue() {
46       type = Type::eContinue;
47       thread = lldb::SBThread();
48     }
49
50     void StepOver(lldb::SBThread t) {
51       type = Type::eStepOver;
52       thread = t;
53     }
54
55     void StepOut(lldb::SBThread t) {
56       type = Type::eStepOut;
57       thread = t;
58     }
59
60     void Relaunch(lldb::SBLaunchInfo l) {
61       type = Type::eRelaunch;
62       thread = lldb::SBThread();
63       launch_info = l;
64     }
65
66     void Kill() {
67       type = Type::eKill;
68       thread = lldb::SBThread();
69     }
70
71     void CallNext() {
72       type = Type::eCallNext;
73       thread = lldb::SBThread();
74     }
75   };
76
77   virtual ~TestCase() {}
78
79   virtual bool Setup(int &argc, const char **&argv);
80
81   virtual void TestStep(int counter, ActionWanted &next_action) = 0;
82
83   bool Launch(lldb::SBLaunchInfo &launch_info);
84
85   bool Launch(std::initializer_list<const char *> args = {});
86
87   void Loop();
88
89   void SetVerbose(bool);
90
91   bool GetVerbose();
92
93   virtual void WriteResults(Results &results) = 0;
94
95   template <typename G, typename A>
96   Measurement<G, A> CreateMeasurement(A a, const char *name = NULL,
97                                       const char *description = NULL) {
98     return Measurement<G, A>(a, name, description);
99   }
100
101   template <typename A>
102   TimeMeasurement<A> CreateTimeMeasurement(A a, const char *name = NULL,
103                                            const char *description = NULL) {
104     return TimeMeasurement<A>(a, name, description);
105   }
106
107   template <typename A>
108   MemoryMeasurement<A> CreateMemoryMeasurement(A a, const char *name = NULL,
109                                                const char *description = NULL) {
110     return MemoryMeasurement<A>(a, name, description);
111   }
112
113   static int Run(TestCase &test, int argc, const char **argv);
114
115   virtual bool ParseOption(int short_option, const char *optarg) {
116     return false;
117   }
118
119   virtual struct option *GetLongOptions() { return NULL; }
120
121   lldb::SBDebugger &GetDebugger() { return m_debugger; }
122
123   lldb::SBTarget &GetTarget() { return m_target; }
124
125   lldb::SBProcess &GetProcess() { return m_process; }
126
127   lldb::SBThread &GetThread() { return m_thread; }
128
129   int GetStep() { return m_step; }
130
131   static const int RUN_SUCCESS = 0;
132   static const int RUN_SETUP_ERROR = 100;
133
134 protected:
135   lldb::SBDebugger m_debugger;
136   lldb::SBTarget m_target;
137   lldb::SBProcess m_process;
138   lldb::SBThread m_thread;
139   lldb::SBListener m_listener;
140   bool m_verbose;
141   int m_step;
142 };
143 }
144
145 #endif /* defined(__PerfTestDriver__TestCase__) */