• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PANDA_RUNTIME_TESTS_TOOLING_API_TEST_H
17 #define PANDA_RUNTIME_TESTS_TOOLING_API_TEST_H
18 
19 #include <array>
20 #include <utility>
21 #include "runtime/include/tooling/debug_interface.h"
22 
23 namespace ark::tooling::test {
24 using BreakpointCallback = std::function<bool(PtThread, Method *, const PtLocation &)>;
25 using LoadModuleCallback = std::function<bool(std::string_view)>;
26 using PausedCallback = std::function<bool(PauseReason)>;
27 using ExceptionCallback =
28     std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, Method *, const PtLocation &)>;
29 using ExceptionCatchCallback = std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *)>;
30 using PropertyAccessCallback = std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, PtProperty)>;
31 using PropertyModificationCallback =
32     std::function<bool(PtThread, Method *, const PtLocation &, ObjectHeader *, PtProperty, VRegValue)>;
33 using FramePopCallback = std::function<bool(PtThread, Method *, bool)>;
34 using GarbageCollectionStartCallback = std::function<bool()>;
35 using GarbageCollectionFinishCallback = std::function<bool()>;
36 using ObjectAllocCallback = std::function<bool(BaseClass *, ObjectHeader *, PtThread, size_t)>;
37 using MethodEntryCallback = std::function<bool(PtThread, Method *)>;
38 using MethodExitCallback = std::function<bool(PtThread, Method *, bool, VRegValue)>;
39 using SingleStepCallback = std::function<bool(PtThread, Method *, const PtLocation &)>;
40 using ThreadStartCallback = std::function<bool(PtThread)>;
41 using ThreadEndCallback = std::function<bool(PtThread)>;
42 using VmStartCallback = std::function<bool()>;
43 using VmInitializationCallback = std::function<bool(PtThread)>;
44 using VmDeathCallback = std::function<bool()>;
45 using ExceptionRevokedCallback = std::function<bool(ExceptionWrapper, ExceptionID)>;
46 using ExecutionContextCreatedCallback = std::function<bool(ExecutionContextWrapper)>;
47 using ExecutionContextDestroyedCallback = std::function<bool(ExecutionContextWrapper)>;
48 using ExecutionContextsClearedCallback = std::function<bool()>;
49 using InspectRequestedCallback = std::function<bool(PtObject, PtObject)>;
50 using ClassLoadCallback = std::function<bool(PtThread, BaseClass *)>;
51 using ClassPrepareCallback = std::function<bool(PtThread, BaseClass *)>;
52 using MonitorWaitCallback = std::function<bool(PtThread, ObjectHeader *, int64_t)>;
53 using MonitorWaitedCallback = std::function<bool(PtThread, ObjectHeader *, bool)>;
54 using MonitorContendedEnterCallback = std::function<bool(PtThread, ObjectHeader *)>;
55 using MonitorContendedEnteredCallback = std::function<bool(PtThread, ObjectHeader *)>;
56 
57 using Scenario = std::function<bool()>;
58 
59 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
60 #define DEBUG_EVENTS_LIST(_)       \
61     _(BREAKPOINT)                  \
62     _(LOAD_MODULE)                 \
63     _(PAUSED)                      \
64     _(EXCEPTION)                   \
65     _(EXCEPTION_CATCH)             \
66     _(FIELD_ACCESS)                \
67     _(FIELD_MODIFICATION)          \
68     _(FRAME_POP)                   \
69     _(GARBAGE_COLLECTIION_START)   \
70     _(GARBAGE_COLLECTIION_FINISH)  \
71     _(METHOD_ENTRY)                \
72     _(METHOD_EXIT)                 \
73     _(SINGLE_STEP)                 \
74     _(THREAD_START)                \
75     _(THREAD_END)                  \
76     _(VM_START)                    \
77     _(VM_INITIALIZATION)           \
78     _(VM_DEATH)                    \
79     _(EXCEPTION_REVOKED)           \
80     _(EXECUTION_CONTEXT_CREATED)   \
81     _(EXECUTION_CONTEXT_DESTROYED) \
82     _(EXECUTION_CONTEXT_CLEARED)   \
83     _(INSPECT_REQUESTED)           \
84     _(CLASS_LOAD)                  \
85     _(CLASS_PREPARE)               \
86     _(MONITOR_WAIT)                \
87     _(MONITOR_WAITED)              \
88     _(MONITOR_CONTENDED_ENTER)     \
89     _(MONITOR_CONTENDED_ENTERED)   \
90     _(UNINITIALIZED)
91 
92 enum class DebugEvent {
93 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
94 #define DEFINE_EVENT_DEF(NAME) NAME,
95     DEBUG_EVENTS_LIST(DEFINE_EVENT_DEF)
96 #undef DEFINE_EVENT_DEF
97 };
98 
99 namespace internal {
100 inline constexpr std::array<const char *, static_cast<size_t>(DebugEvent::UNINITIALIZED) + 1> DEBUG_EVENT_NAMES = {
101 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
102 #define DEFINE_EVENT_NAME(NAME) #NAME,
103     DEBUG_EVENTS_LIST(DEFINE_EVENT_NAME)
104 #undef DEFINE_EVENT_NAME
105 };
106 }  // namespace internal
107 
108 inline std::ostream &operator<<(std::ostream &out, DebugEvent value)
109 {
110     ASSERT(static_cast<size_t>(value) < internal::DEBUG_EVENT_NAMES.size());
111     return out << internal::DEBUG_EVENT_NAMES[static_cast<size_t>(value)];
112 }
113 
114 struct ApiTest {
115     NO_COPY_SEMANTIC(ApiTest);
116     NO_MOVE_SEMANTIC(ApiTest);
117     // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
118     BreakpointCallback breakpoint;
119     LoadModuleCallback loadModule;
120     PausedCallback paused;
121     ExceptionCallback exception;
122     ExceptionCatchCallback exceptionCatch;
123     PropertyAccessCallback propertyAccess;
124     PropertyModificationCallback propertyModification;
125     FramePopCallback framePop;
126     GarbageCollectionStartCallback garbageCollectionStart;
127     GarbageCollectionFinishCallback garbageCollectionFinish;
128     ObjectAllocCallback objectAlloc;
129     MethodEntryCallback methodEntry;
130     MethodExitCallback methodExit;
131     SingleStepCallback singleStep;
132     ThreadStartCallback threadStart;
133     ThreadEndCallback threadEnd;
134     VmStartCallback vmStart;
135     VmInitializationCallback vmInit;
136     VmDeathCallback vmDeath;
137     ExceptionRevokedCallback exceptionRevoked;
138     ExecutionContextCreatedCallback executionContextCreated;
139     ExecutionContextDestroyedCallback executionContextDestroyed;
140     ExecutionContextsClearedCallback executionContextCleared;
141     InspectRequestedCallback inspectRequested;
142     ClassLoadCallback classLoad;
143     ClassPrepareCallback classPrepare;
144     MonitorWaitCallback monitorWait;
145     MonitorWaitedCallback monitorWaited;
146     MonitorContendedEnterCallback monitorContendedEnter;
147     MonitorContendedEnteredCallback monitorContendedEntered;
148 
149     Scenario scenario;
150     DebugInterface *debugInterface {nullptr};
151     // NOLINTEND(misc-non-private-member-variables-in-classes)
152 
153     ApiTest();
154     virtual ~ApiTest() = default;
155 
156     virtual std::pair<const char *, const char *> GetEntryPoint() = 0;
157 };
158 }  // namespace ark::tooling::test
159 
160 #endif  // PANDA_RUNTIME_TESTS_TOOLING_API_TEST_H
161