blob: e882ff3c9b39b0693678c587925b265b88bd1750 [file] [log] [blame]
Greg Clayton5dbe5d42013-03-21 03:39:51 +00001//===-- TestCase.h ----------------------------------------------*- C++ -*-===//
Enrico Granataf58cece2013-03-08 20:29:13 +00002//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00003// The LLVM Compiler Infrastructure
Enrico Granataf58cece2013-03-08 20:29:13 +00004//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Enrico Granataf58cece2013-03-08 20:29:13 +00007//
Greg Clayton5dbe5d42013-03-21 03:39:51 +00008//===----------------------------------------------------------------------===//
Enrico Granataf58cece2013-03-08 20:29:13 +00009
10#ifndef __PerfTestDriver__TestCase__
11#define __PerfTestDriver__TestCase__
12
13#include "lldb/API/LLDB.h"
14#include "Measurement.h"
Enrico Granata8fab9fd2013-04-01 18:02:25 +000015#include <getopt.h>
Enrico Granataf58cece2013-03-08 20:29:13 +000016
Greg Clayton880afc52013-03-22 02:31:35 +000017namespace lldb_perf {
18
19class Results;
20
Enrico Granataf58cece2013-03-08 20:29:13 +000021class TestCase
22{
23public:
24 TestCase();
25
26 struct ActionWanted
27 {
28 enum class Type
29 {
Greg Clayton880afc52013-03-22 02:31:35 +000030 eStepOver,
Greg Clayton7b8f7382013-03-18 22:34:00 +000031 eContinue,
Greg Claytone0b924e2013-03-19 04:41:22 +000032 eStepOut,
Enrico Granataa571e212013-04-15 19:07:38 +000033 eRelaunch,
Enrico Granata6f2b4802013-04-15 23:52:53 +000034 eCallNext,
Greg Clayton7b8f7382013-03-18 22:34:00 +000035 eKill
Enrico Granataf58cece2013-03-08 20:29:13 +000036 } type;
Greg Clayton7b8f7382013-03-18 22:34:00 +000037 lldb::SBThread thread;
Enrico Granataa571e212013-04-15 19:07:38 +000038 lldb::SBLaunchInfo launch_info;
Greg Clayton7b8f7382013-03-18 22:34:00 +000039
40 ActionWanted () :
41 type (Type::eContinue),
Enrico Granataa571e212013-04-15 19:07:38 +000042 thread (),
43 launch_info (NULL)
Greg Clayton7b8f7382013-03-18 22:34:00 +000044 {
45 }
46
47 void
48 Continue()
49 {
50 type = Type::eContinue;
51 thread = lldb::SBThread();
52 }
53
54 void
Greg Claytone0b924e2013-03-19 04:41:22 +000055 StepOver (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000056 {
Greg Clayton880afc52013-03-22 02:31:35 +000057 type = Type::eStepOver;
Greg Clayton7b8f7382013-03-18 22:34:00 +000058 thread = t;
59 }
60
61 void
Greg Claytone0b924e2013-03-19 04:41:22 +000062 StepOut (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000063 {
Greg Claytone0b924e2013-03-19 04:41:22 +000064 type = Type::eStepOut;
Greg Clayton7b8f7382013-03-18 22:34:00 +000065 thread = t;
66 }
67
68 void
Enrico Granataa571e212013-04-15 19:07:38 +000069 Relaunch (lldb::SBLaunchInfo l)
70 {
71 type = Type::eRelaunch;
72 thread = lldb::SBThread();
73 launch_info = l;
74 }
75
76 void
Greg Clayton7b8f7382013-03-18 22:34:00 +000077 Kill ()
78 {
79 type = Type::eKill;
80 thread = lldb::SBThread();
81 }
Enrico Granata6f2b4802013-04-15 23:52:53 +000082
83 void
84 CallNext ()
85 {
86 type = Type::eCallNext;
87 thread = lldb::SBThread();
88 }
Enrico Granataf58cece2013-03-08 20:29:13 +000089 };
90
91 virtual
92 ~TestCase ()
Greg Claytonef0d2142013-03-21 03:32:24 +000093 {
94 }
Enrico Granataf58cece2013-03-08 20:29:13 +000095
Greg Claytone0b924e2013-03-19 04:41:22 +000096 virtual bool
Enrico Granata8fab9fd2013-04-01 18:02:25 +000097 Setup (int& argc, const char**& argv);
Enrico Granataf58cece2013-03-08 20:29:13 +000098
Greg Clayton7b8f7382013-03-18 22:34:00 +000099 virtual void
100 TestStep (int counter, ActionWanted &next_action) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000101
102 bool
Greg Claytone0b924e2013-03-19 04:41:22 +0000103 Launch (lldb::SBLaunchInfo &launch_info);
Enrico Granataf58cece2013-03-08 20:29:13 +0000104
Enrico Granata4e969282013-04-02 21:31:18 +0000105 bool
106 Launch (std::initializer_list<const char*> args = {});
107
Enrico Granataf58cece2013-03-08 20:29:13 +0000108 void
109 Loop();
110
111 void
112 SetVerbose (bool);
113
114 bool
115 GetVerbose ();
116
117 virtual void
Greg Clayton880afc52013-03-22 02:31:35 +0000118 WriteResults (Results &results) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000119
120 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +0000121 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +0000122 {
Enrico Granata86910572013-03-14 19:00:42 +0000123 return Measurement<G,A> (a,name, description);
124 }
125
126 template <typename A>
127 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
128 {
129 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000130 }
131
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000132 template <typename A>
133 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
134 {
135 return MemoryMeasurement<A> (a,name, description);
136 }
137
Enrico Granata4e969282013-04-02 21:31:18 +0000138 static int
Enrico Granataf58cece2013-03-08 20:29:13 +0000139 Run (TestCase& test, int argc, const char** argv);
140
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000141 virtual bool
142 ParseOption (int short_option, const char* optarg)
143 {
144 return false;
145 }
146
147 virtual struct option*
148 GetLongOptions ()
149 {
150 return NULL;
151 }
152
Greg Clayton1080faf2013-03-19 19:30:33 +0000153 lldb::SBDebugger &
154 GetDebugger()
155 {
156 return m_debugger;
157 }
158
159 lldb::SBTarget &
160 GetTarget()
161 {
162 return m_target;
163 }
164
165 lldb::SBProcess &
166 GetProcess ()
167 {
168 return m_process;
169 }
170
171 lldb::SBThread &
172 GetThread ()
173 {
174 return m_thread;
175 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000176
177 int
178 GetStep ()
179 {
180 return m_step;
181 }
182
Enrico Granata4e969282013-04-02 21:31:18 +0000183 static const int RUN_SUCCESS = 0;
184 static const int RUN_SETUP_ERROR = 100;
185
Enrico Granataf58cece2013-03-08 20:29:13 +0000186protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000187 lldb::SBDebugger m_debugger;
188 lldb::SBTarget m_target;
189 lldb::SBProcess m_process;
190 lldb::SBThread m_thread;
191 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000192 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000193 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000194};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000195}
Enrico Granataf58cece2013-03-08 20:29:13 +0000196
197#endif /* defined(__PerfTestDriver__TestCase__) */