TestCase.h revision b8158c8227c34b0fde91cf8602003f250bead007
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 eKill 35 } type; 36 lldb::SBThread thread; 37 lldb::SBLaunchInfo launch_info; 38 39 ActionWanted () : 40 type (Type::eContinue), 41 thread (), 42 launch_info (NULL) 43 { 44 } 45 46 void 47 Continue() 48 { 49 type = Type::eContinue; 50 thread = lldb::SBThread(); 51 } 52 53 void 54 StepOver (lldb::SBThread t) 55 { 56 type = Type::eStepOver; 57 thread = t; 58 } 59 60 void 61 StepOut (lldb::SBThread t) 62 { 63 type = Type::eStepOut; 64 thread = t; 65 } 66 67 void 68 Relaunch (lldb::SBLaunchInfo l) 69 { 70 type = Type::eRelaunch; 71 thread = lldb::SBThread(); 72 launch_info = l; 73 } 74 75 void 76 Kill () 77 { 78 type = Type::eKill; 79 thread = lldb::SBThread(); 80 } 81 }; 82 83 virtual 84 ~TestCase () 85 { 86 } 87 88 virtual bool 89 Setup (int& argc, const char**& argv); 90 91 virtual void 92 TestStep (int counter, ActionWanted &next_action) = 0; 93 94 bool 95 Launch (lldb::SBLaunchInfo &launch_info); 96 97 bool 98 Launch (std::initializer_list<const char*> args = {}); 99 100 void 101 Loop(); 102 103 void 104 SetVerbose (bool); 105 106 bool 107 GetVerbose (); 108 109 virtual void 110 WriteResults (Results &results) = 0; 111 112 template <typename G,typename A> 113 Measurement<G,A> CreateMeasurement (A a, const char* name = NULL, const char* description = NULL) 114 { 115 return Measurement<G,A> (a,name, description); 116 } 117 118 template <typename A> 119 TimeMeasurement<A> CreateTimeMeasurement (A a, const char* name = NULL, const char* description = NULL) 120 { 121 return TimeMeasurement<A> (a,name, description); 122 } 123 124 template <typename A> 125 MemoryMeasurement<A> CreateMemoryMeasurement (A a, const char* name = NULL, const char* description = NULL) 126 { 127 return MemoryMeasurement<A> (a,name, description); 128 } 129 130 static int 131 Run (TestCase& test, int argc, const char** argv); 132 133 virtual bool 134 ParseOption (int short_option, const char* optarg) 135 { 136 return false; 137 } 138 139 virtual struct option* 140 GetLongOptions () 141 { 142 return NULL; 143 } 144 145 lldb::SBDebugger & 146 GetDebugger() 147 { 148 return m_debugger; 149 } 150 151 lldb::SBTarget & 152 GetTarget() 153 { 154 return m_target; 155 } 156 157 lldb::SBProcess & 158 GetProcess () 159 { 160 return m_process; 161 } 162 163 lldb::SBThread & 164 GetThread () 165 { 166 return m_thread; 167 } 168 169 int 170 GetStep () 171 { 172 return m_step; 173 } 174 175 static const int RUN_SUCCESS = 0; 176 static const int RUN_SETUP_ERROR = 100; 177 178protected: 179 lldb::SBDebugger m_debugger; 180 lldb::SBTarget m_target; 181 lldb::SBProcess m_process; 182 lldb::SBThread m_thread; 183 lldb::SBListener m_listener; 184 bool m_verbose; 185 int m_step; 186}; 187} 188 189#endif /* defined(__PerfTestDriver__TestCase__) */ 190