1//===-- TestCase.h ----------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef __PerfTestDriver__TestCase__
11#define __PerfTestDriver__TestCase__
12
13#include "lldb/API/LLDB.h"
14#include "Measurement.h"
15#include <getopt.h>
16
17namespace lldb_perf {
18
19class Results;
20
21class TestCase
22{
23public:
24    TestCase();
25
26    struct ActionWanted
27	{
28		enum class Type
29		{
30			eStepOver,
31			eContinue,
32            eStepOut,
33            eRelaunch,
34            eCallNext,
35			eKill
36		} type;
37		lldb::SBThread thread;
38        lldb::SBLaunchInfo launch_info;
39
40        ActionWanted () :
41            type (Type::eContinue),
42            thread (),
43            launch_info (NULL)
44        {
45        }
46
47        void
48        Continue()
49        {
50            type = Type::eContinue;
51            thread = lldb::SBThread();
52        }
53
54        void
55        StepOver (lldb::SBThread t)
56        {
57            type = Type::eStepOver;
58            thread = t;
59        }
60
61        void
62        StepOut (lldb::SBThread t)
63        {
64            type = Type::eStepOut;
65            thread = t;
66        }
67
68        void
69        Relaunch (lldb::SBLaunchInfo l)
70        {
71            type = Type::eRelaunch;
72            thread = lldb::SBThread();
73            launch_info = l;
74        }
75
76        void
77        Kill ()
78        {
79            type = Type::eKill;
80            thread = lldb::SBThread();
81        }
82
83        void
84        CallNext ()
85        {
86            type = Type::eCallNext;
87            thread = lldb::SBThread();
88        }
89	};
90
91    virtual
92    ~TestCase ()
93    {
94    }
95
96	virtual bool
97	Setup (int& argc, const char**& argv);
98
99	virtual void
100	TestStep (int counter, ActionWanted &next_action) = 0;
101
102	bool
103	Launch (lldb::SBLaunchInfo &launch_info);
104
105    bool
106	Launch (std::initializer_list<const char*> args = {});
107
108	void
109	Loop();
110
111    void
112    SetVerbose (bool);
113
114    bool
115    GetVerbose ();
116
117    virtual void
118    WriteResults (Results &results) = 0;
119
120    template <typename G,typename A>
121    Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
122    {
123        return Measurement<G,A> (a,name, description);
124    }
125
126    template <typename A>
127    TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
128    {
129        return TimeMeasurement<A> (a,name, description);
130    }
131
132    template <typename A>
133    MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
134    {
135        return MemoryMeasurement<A> (a,name, description);
136    }
137
138    static int
139    Run (TestCase& test, int argc, const char** argv);
140
141    virtual bool
142    ParseOption (int short_option, const char* optarg)
143    {
144        return false;
145    }
146
147    virtual struct option*
148    GetLongOptions ()
149    {
150        return NULL;
151    }
152
153    lldb::SBDebugger &
154    GetDebugger()
155    {
156        return m_debugger;
157    }
158
159    lldb::SBTarget &
160    GetTarget()
161    {
162        return m_target;
163    }
164
165    lldb::SBProcess &
166    GetProcess ()
167    {
168        return m_process;
169    }
170
171    lldb::SBThread &
172    GetThread ()
173    {
174        return m_thread;
175    }
176
177    int
178    GetStep ()
179    {
180        return m_step;
181    }
182
183    static const int RUN_SUCCESS = 0;
184    static const int RUN_SETUP_ERROR = 100;
185
186protected:
187    lldb::SBDebugger m_debugger;
188	lldb::SBTarget m_target;
189	lldb::SBProcess m_process;
190	lldb::SBThread m_thread;
191	lldb::SBListener m_listener;
192    bool m_verbose;
193    int m_step;
194};
195}
196
197#endif /* defined(__PerfTestDriver__TestCase__) */
198