blob: 3d2e0e94fbc4c4c011cff537f93c46fb34c89307 [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,
Greg Clayton7b8f7382013-03-18 22:34:00 +000033 eKill
Enrico Granataf58cece2013-03-08 20:29:13 +000034 } type;
Greg Clayton7b8f7382013-03-18 22:34:00 +000035 lldb::SBThread thread;
36
37 ActionWanted () :
38 type (Type::eContinue),
39 thread ()
40 {
41 }
42
43 void
44 Continue()
45 {
46 type = Type::eContinue;
47 thread = lldb::SBThread();
48 }
49
50 void
Greg Claytone0b924e2013-03-19 04:41:22 +000051 StepOver (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000052 {
Greg Clayton880afc52013-03-22 02:31:35 +000053 type = Type::eStepOver;
Greg Clayton7b8f7382013-03-18 22:34:00 +000054 thread = t;
55 }
56
57 void
Greg Claytone0b924e2013-03-19 04:41:22 +000058 StepOut (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000059 {
Greg Claytone0b924e2013-03-19 04:41:22 +000060 type = Type::eStepOut;
Greg Clayton7b8f7382013-03-18 22:34:00 +000061 thread = t;
62 }
63
64 void
65 Kill ()
66 {
67 type = Type::eKill;
68 thread = lldb::SBThread();
69 }
Enrico Granataf58cece2013-03-08 20:29:13 +000070 };
71
72 virtual
73 ~TestCase ()
Greg Claytonef0d2142013-03-21 03:32:24 +000074 {
75 }
Enrico Granataf58cece2013-03-08 20:29:13 +000076
Greg Claytone0b924e2013-03-19 04:41:22 +000077 virtual bool
Enrico Granata8fab9fd2013-04-01 18:02:25 +000078 Setup (int& argc, const char**& argv);
Enrico Granataf58cece2013-03-08 20:29:13 +000079
Greg Clayton7b8f7382013-03-18 22:34:00 +000080 virtual void
81 TestStep (int counter, ActionWanted &next_action) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +000082
83 bool
Greg Claytone0b924e2013-03-19 04:41:22 +000084 Launch (lldb::SBLaunchInfo &launch_info);
Enrico Granataf58cece2013-03-08 20:29:13 +000085
Enrico Granata4e969282013-04-02 21:31:18 +000086 bool
87 Launch (std::initializer_list<const char*> args = {});
88
Enrico Granataf58cece2013-03-08 20:29:13 +000089 void
90 Loop();
91
92 void
93 SetVerbose (bool);
94
95 bool
96 GetVerbose ();
97
98 virtual void
Greg Clayton880afc52013-03-22 02:31:35 +000099 WriteResults (Results &results) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +0000100
101 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +0000102 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +0000103 {
Enrico Granata86910572013-03-14 19:00:42 +0000104 return Measurement<G,A> (a,name, description);
105 }
106
107 template <typename A>
108 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
109 {
110 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000111 }
112
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000113 template <typename A>
114 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
115 {
116 return MemoryMeasurement<A> (a,name, description);
117 }
118
Enrico Granata4e969282013-04-02 21:31:18 +0000119 static int
Enrico Granataf58cece2013-03-08 20:29:13 +0000120 Run (TestCase& test, int argc, const char** argv);
121
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000122 virtual bool
123 ParseOption (int short_option, const char* optarg)
124 {
125 return false;
126 }
127
128 virtual struct option*
129 GetLongOptions ()
130 {
131 return NULL;
132 }
133
Greg Clayton1080faf2013-03-19 19:30:33 +0000134 lldb::SBDebugger &
135 GetDebugger()
136 {
137 return m_debugger;
138 }
139
140 lldb::SBTarget &
141 GetTarget()
142 {
143 return m_target;
144 }
145
146 lldb::SBProcess &
147 GetProcess ()
148 {
149 return m_process;
150 }
151
152 lldb::SBThread &
153 GetThread ()
154 {
155 return m_thread;
156 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000157
158 int
159 GetStep ()
160 {
161 return m_step;
162 }
163
Enrico Granata4e969282013-04-02 21:31:18 +0000164 static const int RUN_SUCCESS = 0;
165 static const int RUN_SETUP_ERROR = 100;
166
Enrico Granataf58cece2013-03-08 20:29:13 +0000167protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000168 lldb::SBDebugger m_debugger;
169 lldb::SBTarget m_target;
170 lldb::SBProcess m_process;
171 lldb::SBThread m_thread;
172 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000173 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000174 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000175};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000176}
Enrico Granataf58cece2013-03-08 20:29:13 +0000177
178#endif /* defined(__PerfTestDriver__TestCase__) */