Greg Clayton | 5dbe5d4 | 2013-03-21 03:39:51 +0000 | [diff] [blame] | 1 | //===-- TestCase.h ----------------------------------------------*- C++ -*-===// |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 2 | // |
Greg Clayton | 5dbe5d4 | 2013-03-21 03:39:51 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 4 | // |
Greg Clayton | 5dbe5d4 | 2013-03-21 03:39:51 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 7 | // |
Greg Clayton | 5dbe5d4 | 2013-03-21 03:39:51 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef __PerfTestDriver__TestCase__ |
| 11 | #define __PerfTestDriver__TestCase__ |
| 12 | |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 13 | #include "Measurement.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/API/LLDB.h" |
Enrico Granata | 8fab9fd | 2013-04-01 18:02:25 +0000 | [diff] [blame] | 15 | #include <getopt.h> |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 16 | |
Greg Clayton | 880afc5 | 2013-03-22 02:31:35 +0000 | [diff] [blame] | 17 | namespace lldb_perf { |
| 18 | |
| 19 | class Results; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | |
| 21 | class TestCase { |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 22 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | TestCase(); |
Greg Clayton | 46822c7 | 2014-02-27 21:35:49 +0000 | [diff] [blame] | 24 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | 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 Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | ActionWanted() : type(Type::eContinue), thread(), launch_info(NULL) {} |
| 39 | |
| 40 | void None() { |
| 41 | type = Type::eNone; |
| 42 | thread = lldb::SBThread(); |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | void Continue() { |
| 46 | type = Type::eContinue; |
| 47 | thread = lldb::SBThread(); |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 48 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | |
| 50 | void StepOver(lldb::SBThread t) { |
| 51 | type = Type::eStepOver; |
| 52 | thread = t; |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 53 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | |
| 55 | void StepOut(lldb::SBThread t) { |
| 56 | type = Type::eStepOut; |
| 57 | thread = t; |
Greg Clayton | 1080faf | 2013-03-19 19:30:33 +0000 | [diff] [blame] | 58 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | |
| 60 | void Relaunch(lldb::SBLaunchInfo l) { |
| 61 | type = Type::eRelaunch; |
| 62 | thread = lldb::SBThread(); |
| 63 | launch_info = l; |
Enrico Granata | e16dfcd | 2013-03-20 22:42:34 +0000 | [diff] [blame] | 64 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | |
| 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 Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 134 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 135 | 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 Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 142 | }; |
Greg Clayton | 7b8f738 | 2013-03-18 22:34:00 +0000 | [diff] [blame] | 143 | } |
Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame] | 144 | |
| 145 | #endif /* defined(__PerfTestDriver__TestCase__) */ |