blob: 811d0432b58a1f4d931ae96d21079a0baed27a58 [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 Clayton46822c72014-02-27 21:35:49 +000035 eNone,
Greg Clayton7b8f7382013-03-18 22:34:00 +000036 eKill
Enrico Granataf58cece2013-03-08 20:29:13 +000037 } type;
Greg Clayton7b8f7382013-03-18 22:34:00 +000038 lldb::SBThread thread;
Enrico Granataa571e212013-04-15 19:07:38 +000039 lldb::SBLaunchInfo launch_info;
Greg Clayton7b8f7382013-03-18 22:34:00 +000040
41 ActionWanted () :
42 type (Type::eContinue),
Enrico Granataa571e212013-04-15 19:07:38 +000043 thread (),
44 launch_info (NULL)
Greg Clayton7b8f7382013-03-18 22:34:00 +000045 {
46 }
47
48 void
Greg Clayton46822c72014-02-27 21:35:49 +000049 None ()
50 {
51 type = Type::eNone;
52 thread = lldb::SBThread();
53 }
54
55 void
Greg Clayton7b8f7382013-03-18 22:34:00 +000056 Continue()
57 {
58 type = Type::eContinue;
59 thread = lldb::SBThread();
60 }
61
62 void
Greg Claytone0b924e2013-03-19 04:41:22 +000063 StepOver (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000064 {
Greg Clayton880afc52013-03-22 02:31:35 +000065 type = Type::eStepOver;
Greg Clayton7b8f7382013-03-18 22:34:00 +000066 thread = t;
67 }
68
69 void
Greg Claytone0b924e2013-03-19 04:41:22 +000070 StepOut (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000071 {
Greg Claytone0b924e2013-03-19 04:41:22 +000072 type = Type::eStepOut;
Greg Clayton7b8f7382013-03-18 22:34:00 +000073 thread = t;
74 }
75
76 void
Enrico Granataa571e212013-04-15 19:07:38 +000077 Relaunch (lldb::SBLaunchInfo l)
78 {
79 type = Type::eRelaunch;
80 thread = lldb::SBThread();
81 launch_info = l;
82 }
83
84 void
Greg Clayton7b8f7382013-03-18 22:34:00 +000085 Kill ()
86 {
87 type = Type::eKill;
88 thread = lldb::SBThread();
89 }
Enrico Granata6f2b4802013-04-15 23:52:53 +000090
91 void
92 CallNext ()
93 {
94 type = Type::eCallNext;
95 thread = lldb::SBThread();
96 }
Enrico Granataf58cece2013-03-08 20:29:13 +000097 };
98
99 virtual
100 ~TestCase ()
Greg Claytonef0d2142013-03-21 03:32:24 +0000101 {
102 }
Enrico Granataf58cece2013-03-08 20:29:13 +0000103
Greg Claytone0b924e2013-03-19 04:41:22 +0000104 virtual bool
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000105 Setup (int& argc, const char**& argv);
Enrico Granataf58cece2013-03-08 20:29:13 +0000106
Greg Clayton7b8f7382013-03-18 22:34:00 +0000107 virtual void
108 TestStep (int counter, ActionWanted &next_action) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000109
110 bool
Greg Claytone0b924e2013-03-19 04:41:22 +0000111 Launch (lldb::SBLaunchInfo &launch_info);
Enrico Granataf58cece2013-03-08 20:29:13 +0000112
Enrico Granata4e969282013-04-02 21:31:18 +0000113 bool
114 Launch (std::initializer_list<const char*> args = {});
115
Enrico Granataf58cece2013-03-08 20:29:13 +0000116 void
117 Loop();
118
119 void
120 SetVerbose (bool);
121
122 bool
123 GetVerbose ();
124
125 virtual void
Greg Clayton880afc52013-03-22 02:31:35 +0000126 WriteResults (Results &results) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000127
128 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +0000129 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +0000130 {
Enrico Granata86910572013-03-14 19:00:42 +0000131 return Measurement<G,A> (a,name, description);
132 }
133
134 template <typename A>
135 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
136 {
137 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000138 }
139
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000140 template <typename A>
141 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
142 {
143 return MemoryMeasurement<A> (a,name, description);
144 }
145
Enrico Granata4e969282013-04-02 21:31:18 +0000146 static int
Enrico Granataf58cece2013-03-08 20:29:13 +0000147 Run (TestCase& test, int argc, const char** argv);
148
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000149 virtual bool
150 ParseOption (int short_option, const char* optarg)
151 {
152 return false;
153 }
154
155 virtual struct option*
156 GetLongOptions ()
157 {
158 return NULL;
159 }
160
Greg Clayton1080faf2013-03-19 19:30:33 +0000161 lldb::SBDebugger &
162 GetDebugger()
163 {
164 return m_debugger;
165 }
166
167 lldb::SBTarget &
168 GetTarget()
169 {
170 return m_target;
171 }
172
173 lldb::SBProcess &
174 GetProcess ()
175 {
176 return m_process;
177 }
178
179 lldb::SBThread &
180 GetThread ()
181 {
182 return m_thread;
183 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000184
185 int
186 GetStep ()
187 {
188 return m_step;
189 }
190
Enrico Granata4e969282013-04-02 21:31:18 +0000191 static const int RUN_SUCCESS = 0;
192 static const int RUN_SETUP_ERROR = 100;
193
Enrico Granataf58cece2013-03-08 20:29:13 +0000194protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000195 lldb::SBDebugger m_debugger;
196 lldb::SBTarget m_target;
197 lldb::SBProcess m_process;
198 lldb::SBThread m_thread;
199 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000200 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000201 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000202};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000203}
Enrico Granataf58cece2013-03-08 20:29:13 +0000204
205#endif /* defined(__PerfTestDriver__TestCase__) */