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