blob: 89557982e5f49eabff1b92b7532c6599d3b1b7d5 [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,
Greg Clayton7b8f7382013-03-18 22:34:00 +000034 eKill
Enrico Granataf58cece2013-03-08 20:29:13 +000035 } type;
Greg Clayton7b8f7382013-03-18 22:34:00 +000036 lldb::SBThread thread;
Enrico Granataa571e212013-04-15 19:07:38 +000037 lldb::SBLaunchInfo launch_info;
Greg Clayton7b8f7382013-03-18 22:34:00 +000038
39 ActionWanted () :
40 type (Type::eContinue),
Enrico Granataa571e212013-04-15 19:07:38 +000041 thread (),
42 launch_info (NULL)
Greg Clayton7b8f7382013-03-18 22:34:00 +000043 {
44 }
45
46 void
47 Continue()
48 {
49 type = Type::eContinue;
50 thread = lldb::SBThread();
51 }
52
53 void
Greg Claytone0b924e2013-03-19 04:41:22 +000054 StepOver (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000055 {
Greg Clayton880afc52013-03-22 02:31:35 +000056 type = Type::eStepOver;
Greg Clayton7b8f7382013-03-18 22:34:00 +000057 thread = t;
58 }
59
60 void
Greg Claytone0b924e2013-03-19 04:41:22 +000061 StepOut (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000062 {
Greg Claytone0b924e2013-03-19 04:41:22 +000063 type = Type::eStepOut;
Greg Clayton7b8f7382013-03-18 22:34:00 +000064 thread = t;
65 }
66
67 void
Enrico Granataa571e212013-04-15 19:07:38 +000068 Relaunch (lldb::SBLaunchInfo l)
69 {
70 type = Type::eRelaunch;
71 thread = lldb::SBThread();
72 launch_info = l;
73 }
74
75 void
Greg Clayton7b8f7382013-03-18 22:34:00 +000076 Kill ()
77 {
78 type = Type::eKill;
79 thread = lldb::SBThread();
80 }
Enrico Granataf58cece2013-03-08 20:29:13 +000081 };
82
83 virtual
84 ~TestCase ()
Greg Claytonef0d2142013-03-21 03:32:24 +000085 {
86 }
Enrico Granataf58cece2013-03-08 20:29:13 +000087
Greg Claytone0b924e2013-03-19 04:41:22 +000088 virtual bool
Enrico Granata8fab9fd2013-04-01 18:02:25 +000089 Setup (int& argc, const char**& argv);
Enrico Granataf58cece2013-03-08 20:29:13 +000090
Greg Clayton7b8f7382013-03-18 22:34:00 +000091 virtual void
92 TestStep (int counter, ActionWanted &next_action) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +000093
94 bool
Greg Claytone0b924e2013-03-19 04:41:22 +000095 Launch (lldb::SBLaunchInfo &launch_info);
Enrico Granataf58cece2013-03-08 20:29:13 +000096
Enrico Granata4e969282013-04-02 21:31:18 +000097 bool
98 Launch (std::initializer_list<const char*> args = {});
99
Enrico Granataf58cece2013-03-08 20:29:13 +0000100 void
101 Loop();
102
103 void
104 SetVerbose (bool);
105
106 bool
107 GetVerbose ();
108
109 virtual void
Greg Clayton880afc52013-03-22 02:31:35 +0000110 WriteResults (Results &results) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000111
112 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +0000113 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +0000114 {
Enrico Granata86910572013-03-14 19:00:42 +0000115 return Measurement<G,A> (a,name, description);
116 }
117
118 template <typename A>
119 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
120 {
121 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000122 }
123
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000124 template <typename A>
125 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
126 {
127 return MemoryMeasurement<A> (a,name, description);
128 }
129
Enrico Granata4e969282013-04-02 21:31:18 +0000130 static int
Enrico Granataf58cece2013-03-08 20:29:13 +0000131 Run (TestCase& test, int argc, const char** argv);
132
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000133 virtual bool
134 ParseOption (int short_option, const char* optarg)
135 {
136 return false;
137 }
138
139 virtual struct option*
140 GetLongOptions ()
141 {
142 return NULL;
143 }
144
Greg Clayton1080faf2013-03-19 19:30:33 +0000145 lldb::SBDebugger &
146 GetDebugger()
147 {
148 return m_debugger;
149 }
150
151 lldb::SBTarget &
152 GetTarget()
153 {
154 return m_target;
155 }
156
157 lldb::SBProcess &
158 GetProcess ()
159 {
160 return m_process;
161 }
162
163 lldb::SBThread &
164 GetThread ()
165 {
166 return m_thread;
167 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000168
169 int
170 GetStep ()
171 {
172 return m_step;
173 }
174
Enrico Granata4e969282013-04-02 21:31:18 +0000175 static const int RUN_SUCCESS = 0;
176 static const int RUN_SETUP_ERROR = 100;
177
Enrico Granataf58cece2013-03-08 20:29:13 +0000178protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000179 lldb::SBDebugger m_debugger;
180 lldb::SBTarget m_target;
181 lldb::SBProcess m_process;
182 lldb::SBThread m_thread;
183 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000184 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000185 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000186};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000187}
Enrico Granataf58cece2013-03-08 20:29:13 +0000188
189#endif /* defined(__PerfTestDriver__TestCase__) */