blob: d9a7c9fa8a0ded45ca5a7750e0480d351b22d682 [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
86 void
87 Loop();
88
89 void
90 SetVerbose (bool);
91
92 bool
93 GetVerbose ();
94
95 virtual void
Greg Clayton880afc52013-03-22 02:31:35 +000096 WriteResults (Results &results) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +000097
98 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +000099 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +0000100 {
Enrico Granata86910572013-03-14 19:00:42 +0000101 return Measurement<G,A> (a,name, description);
102 }
103
104 template <typename A>
105 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
106 {
107 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000108 }
109
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000110 template <typename A>
111 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
112 {
113 return MemoryMeasurement<A> (a,name, description);
114 }
115
Enrico Granataf58cece2013-03-08 20:29:13 +0000116 static void
117 Run (TestCase& test, int argc, const char** argv);
118
Enrico Granata8fab9fd2013-04-01 18:02:25 +0000119 virtual bool
120 ParseOption (int short_option, const char* optarg)
121 {
122 return false;
123 }
124
125 virtual struct option*
126 GetLongOptions ()
127 {
128 return NULL;
129 }
130
Greg Clayton1080faf2013-03-19 19:30:33 +0000131 lldb::SBDebugger &
132 GetDebugger()
133 {
134 return m_debugger;
135 }
136
137 lldb::SBTarget &
138 GetTarget()
139 {
140 return m_target;
141 }
142
143 lldb::SBProcess &
144 GetProcess ()
145 {
146 return m_process;
147 }
148
149 lldb::SBThread &
150 GetThread ()
151 {
152 return m_thread;
153 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000154
155 int
156 GetStep ()
157 {
158 return m_step;
159 }
160
Enrico Granataf58cece2013-03-08 20:29:13 +0000161protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000162 lldb::SBDebugger m_debugger;
163 lldb::SBTarget m_target;
164 lldb::SBProcess m_process;
165 lldb::SBThread m_thread;
166 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000167 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000168 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000169};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000170}
Enrico Granataf58cece2013-03-08 20:29:13 +0000171
172#endif /* defined(__PerfTestDriver__TestCase__) */