blob: 707806bf1575b5e8dba1a6fefa3d8477154c7693 [file] [log] [blame]
Enrico Granataf58cece2013-03-08 20:29:13 +00001//
2// TestCase.h
3// PerfTestDriver
4//
5// Created by Enrico Granata on 3/7/13.
6// Copyright (c) 2013 Apple Inc. All rights reserved.
7//
8
9#ifndef __PerfTestDriver__TestCase__
10#define __PerfTestDriver__TestCase__
11
12#include "lldb/API/LLDB.h"
13#include "Measurement.h"
14
Greg Clayton7b8f7382013-03-18 22:34:00 +000015namespace lldb_perf
Enrico Granataf58cece2013-03-08 20:29:13 +000016{
17class TestCase
18{
19public:
20 TestCase();
21
22 struct ActionWanted
23 {
24 enum class Type
25 {
Greg Clayton7b8f7382013-03-18 22:34:00 +000026 eNext,
27 eContinue,
Greg Claytone0b924e2013-03-19 04:41:22 +000028 eStepOut,
Greg Clayton7b8f7382013-03-18 22:34:00 +000029 eKill
Enrico Granataf58cece2013-03-08 20:29:13 +000030 } type;
Greg Clayton7b8f7382013-03-18 22:34:00 +000031 lldb::SBThread thread;
32
33 ActionWanted () :
34 type (Type::eContinue),
35 thread ()
36 {
37 }
38
39 void
40 Continue()
41 {
42 type = Type::eContinue;
43 thread = lldb::SBThread();
44 }
45
46 void
Greg Claytone0b924e2013-03-19 04:41:22 +000047 StepOver (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000048 {
49 type = Type::eNext;
50 thread = t;
51 }
52
53 void
Greg Claytone0b924e2013-03-19 04:41:22 +000054 StepOut (lldb::SBThread t)
Greg Clayton7b8f7382013-03-18 22:34:00 +000055 {
Greg Claytone0b924e2013-03-19 04:41:22 +000056 type = Type::eStepOut;
Greg Clayton7b8f7382013-03-18 22:34:00 +000057 thread = t;
58 }
59
60 void
61 Kill ()
62 {
63 type = Type::eKill;
64 thread = lldb::SBThread();
65 }
Enrico Granataf58cece2013-03-08 20:29:13 +000066 };
67
68 virtual
69 ~TestCase ()
Greg Claytonef0d2142013-03-21 03:32:24 +000070 {
71 }
Enrico Granataf58cece2013-03-08 20:29:13 +000072
Greg Claytone0b924e2013-03-19 04:41:22 +000073 virtual bool
Enrico Granataf58cece2013-03-08 20:29:13 +000074 Setup (int argc, const char** argv);
75
Greg Clayton7b8f7382013-03-18 22:34:00 +000076 virtual void
77 TestStep (int counter, ActionWanted &next_action) = 0;
Enrico Granataf58cece2013-03-08 20:29:13 +000078
79 bool
Greg Claytone0b924e2013-03-19 04:41:22 +000080 Launch (lldb::SBLaunchInfo &launch_info);
Enrico Granataf58cece2013-03-08 20:29:13 +000081
82 void
83 Loop();
84
85 void
86 SetVerbose (bool);
87
88 bool
89 GetVerbose ();
90
91 virtual void
92 Results () = 0;
93
94 template <typename G,typename A>
Enrico Granata86910572013-03-14 19:00:42 +000095 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
Enrico Granataf58cece2013-03-08 20:29:13 +000096 {
Enrico Granata86910572013-03-14 19:00:42 +000097 return Measurement<G,A> (a,name, description);
98 }
99
100 template <typename A>
101 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
102 {
103 return TimeMeasurement<A> (a,name, description);
Enrico Granataf58cece2013-03-08 20:29:13 +0000104 }
105
Enrico Granataf3fb83a2013-03-20 21:18:20 +0000106 template <typename A>
107 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
108 {
109 return MemoryMeasurement<A> (a,name, description);
110 }
111
Enrico Granataf58cece2013-03-08 20:29:13 +0000112 static void
113 Run (TestCase& test, int argc, const char** argv);
114
Greg Clayton1080faf2013-03-19 19:30:33 +0000115 lldb::SBDebugger &
116 GetDebugger()
117 {
118 return m_debugger;
119 }
120
121 lldb::SBTarget &
122 GetTarget()
123 {
124 return m_target;
125 }
126
127 lldb::SBProcess &
128 GetProcess ()
129 {
130 return m_process;
131 }
132
133 lldb::SBThread &
134 GetThread ()
135 {
136 return m_thread;
137 }
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000138
139 int
140 GetStep ()
141 {
142 return m_step;
143 }
144
Enrico Granataf58cece2013-03-08 20:29:13 +0000145protected:
Greg Clayton7b8f7382013-03-18 22:34:00 +0000146 lldb::SBDebugger m_debugger;
147 lldb::SBTarget m_target;
148 lldb::SBProcess m_process;
149 lldb::SBThread m_thread;
150 lldb::SBListener m_listener;
Enrico Granataf58cece2013-03-08 20:29:13 +0000151 bool m_verbose;
Enrico Granatae16dfcd2013-03-20 22:42:34 +0000152 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000153};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000154}
Enrico Granataf58cece2013-03-08 20:29:13 +0000155
156#endif /* defined(__PerfTestDriver__TestCase__) */