blob: 8ec1a47d7b42d4127404bb48f58466c0d4e5be63 [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
Enrico Granataf58cece2013-03-08 20:29:13 +000013#include "Measurement.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "lldb/API/LLDB.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;
Kate Stoneb9c1b512016-09-06 20:57:50 +000020
21class TestCase {
Enrico Granataf58cece2013-03-08 20:29:13 +000022public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000023 TestCase();
Greg Clayton46822c72014-02-27 21:35:49 +000024
Kate Stoneb9c1b512016-09-06 20:57:50 +000025 struct ActionWanted {
26 enum class Type {
27 eStepOver,
28 eContinue,
29 eStepOut,
30 eRelaunch,
31 eCallNext,
32 eNone,
33 eKill
34 } type;
35 lldb::SBThread thread;
36 lldb::SBLaunchInfo launch_info;
Greg Clayton7b8f7382013-03-18 22:34:00 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 ActionWanted() : type(Type::eContinue), thread(), launch_info(NULL) {}
39
40 void None() {
41 type = Type::eNone;
42 thread = lldb::SBThread();
Greg Clayton1080faf2013-03-19 19:30:33 +000043 }
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 void Continue() {
46 type = Type::eContinue;
47 thread = lldb::SBThread();
Greg Clayton1080faf2013-03-19 19:30:33 +000048 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000049
50 void StepOver(lldb::SBThread t) {
51 type = Type::eStepOver;
52 thread = t;
Greg Clayton1080faf2013-03-19 19:30:33 +000053 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000054
55 void StepOut(lldb::SBThread t) {
56 type = Type::eStepOut;
57 thread = t;
Greg Clayton1080faf2013-03-19 19:30:33 +000058 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000059
60 void Relaunch(lldb::SBLaunchInfo l) {
61 type = Type::eRelaunch;
62 thread = lldb::SBThread();
63 launch_info = l;
Enrico Granatae16dfcd2013-03-20 22:42:34 +000064 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000065
66 void Kill() {
67 type = Type::eKill;
68 thread = lldb::SBThread();
69 }
70
71 void CallNext() {
72 type = Type::eCallNext;
73 thread = lldb::SBThread();
74 }
75 };
76
77 virtual ~TestCase() {}
78
79 virtual bool Setup(int &argc, const char **&argv);
80
81 virtual void TestStep(int counter, ActionWanted &next_action) = 0;
82
83 bool Launch(lldb::SBLaunchInfo &launch_info);
84
85 bool Launch(std::initializer_list<const char *> args = {});
86
87 void Loop();
88
89 void SetVerbose(bool);
90
91 bool GetVerbose();
92
93 virtual void WriteResults(Results &results) = 0;
94
95 template <typename G, typename A>
96 Measurement<G, A> CreateMeasurement(A a, const char *name = NULL,
97 const char *description = NULL) {
98 return Measurement<G, A>(a, name, description);
99 }
100
101 template <typename A>
102 TimeMeasurement<A> CreateTimeMeasurement(A a, const char *name = NULL,
103 const char *description = NULL) {
104 return TimeMeasurement<A>(a, name, description);
105 }
106
107 template <typename A>
108 MemoryMeasurement<A> CreateMemoryMeasurement(A a, const char *name = NULL,
109 const char *description = NULL) {
110 return MemoryMeasurement<A>(a, name, description);
111 }
112
113 static int Run(TestCase &test, int argc, const char **argv);
114
115 virtual bool ParseOption(int short_option, const char *optarg) {
116 return false;
117 }
118
119 virtual struct option *GetLongOptions() { return NULL; }
120
121 lldb::SBDebugger &GetDebugger() { return m_debugger; }
122
123 lldb::SBTarget &GetTarget() { return m_target; }
124
125 lldb::SBProcess &GetProcess() { return m_process; }
126
127 lldb::SBThread &GetThread() { return m_thread; }
128
129 int GetStep() { return m_step; }
130
131 static const int RUN_SUCCESS = 0;
132 static const int RUN_SETUP_ERROR = 100;
133
Enrico Granataf58cece2013-03-08 20:29:13 +0000134protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +0000135 lldb::SBDebugger m_debugger;
136 lldb::SBTarget m_target;
137 lldb::SBProcess m_process;
138 lldb::SBThread m_thread;
139 lldb::SBListener m_listener;
140 bool m_verbose;
141 int m_step;
Enrico Granataf58cece2013-03-08 20:29:13 +0000142};
Greg Clayton7b8f7382013-03-18 22:34:00 +0000143}
Enrico Granataf58cece2013-03-08 20:29:13 +0000144
145#endif /* defined(__PerfTestDriver__TestCase__) */