TestCase.h revision e62d448f4b663edfac26b9071323606b1b5fdc1d
1//
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
15namespace lldb_perf
16{
17class TestCase
18{
19public:
20    TestCase();
21
22    struct ActionWanted
23	{
24		enum class Type
25		{
26			eNext,
27			eContinue,
28            eStepOut,
29			eKill
30		} type;
31		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
47        StepOver (lldb::SBThread t)
48        {
49            type = Type::eNext;
50            thread = t;
51        }
52
53        void
54        StepOut (lldb::SBThread t)
55        {
56            type = Type::eStepOut;
57            thread = t;
58        }
59
60        void
61        Kill ()
62        {
63            type = Type::eKill;
64            thread = lldb::SBThread();
65        }
66	};
67
68    virtual
69    ~TestCase ()
70    {}
71
72	virtual bool
73	Setup (int argc, const char** argv);
74
75	virtual void
76	TestStep (int counter, ActionWanted &next_action) = 0;
77
78	bool
79	Launch (lldb::SBLaunchInfo &launch_info);
80
81	void
82	Loop();
83
84    void
85    SetVerbose (bool);
86
87    bool
88    GetVerbose ();
89
90    virtual void
91    Results () = 0;
92
93    template <typename G,typename A>
94    Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL)
95    {
96        return Measurement<G,A> (a,name, description);
97    }
98
99    template <typename A>
100    TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL)
101    {
102        return TimeMeasurement<A> (a,name, description);
103    }
104
105    template <typename A>
106    MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL)
107    {
108        return MemoryMeasurement<A> (a,name, description);
109    }
110
111    static void
112    Run (TestCase& test, int argc, const char** argv);
113
114    lldb::SBDebugger &
115    GetDebugger()
116    {
117        return m_debugger;
118    }
119
120    lldb::SBTarget &
121    GetTarget()
122    {
123        return m_target;
124    }
125
126    lldb::SBProcess &
127    GetProcess ()
128    {
129        return m_process;
130    }
131
132    lldb::SBThread &
133    GetThread ()
134    {
135        return m_thread;
136    }
137
138    int
139    GetStep ()
140    {
141        return m_step;
142    }
143
144protected:
145    lldb::SBDebugger m_debugger;
146	lldb::SBTarget m_target;
147	lldb::SBProcess m_process;
148	lldb::SBThread m_thread;
149	lldb::SBListener m_listener;
150    bool m_verbose;
151    int m_step;
152};
153}
154
155#endif /* defined(__PerfTestDriver__TestCase__) */
156