1 /* 2 * Copyright (c) 2021 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 ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H 17 #define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H 18 19 #include <utility> 20 21 #include "agent/runtime_impl.h" 22 #include "backend/js_pt_hooks.h" 23 #include "test/utils/test_channel.h" 24 25 namespace panda::ecmascript::tooling::test { 26 using DebuggerStmtCallback = std::function<bool(const JSPtLocation &)>; 27 using BreakpointCallback = std::function<bool(const JSPtLocation &)>; 28 using LoadModuleCallback = std::function<bool(std::string_view)>; 29 using ExceptionCallback = std::function<bool(const JSPtLocation &)>; 30 using SingleStepCallback = std::function<bool(const JSPtLocation &)>; 31 using VmStartCallback = std::function<bool()>; 32 using VmDeathCallback = std::function<bool()>; 33 using Scenario = std::function<bool()>; 34 35 enum class DebugEvent { 36 BREAKPOINT, 37 LOAD_MODULE, 38 PAUSED, 39 STEP_COMPLETE, 40 EXCEPTION, 41 METHOD_ENTRY, 42 SINGLE_STEP, 43 VM_START, 44 VM_INITIALIZATION, 45 VM_DEATH, 46 UNINITIALIZED, 47 DROPFRAME, 48 CHECK_COMPLETE 49 }; 50 51 std::ostream &operator<<(std::ostream &out, DebugEvent value); 52 53 struct TestEvents { 54 DebuggerStmtCallback debuggerStmt; 55 BreakpointCallback breakpoint; 56 LoadModuleCallback loadModule; 57 ExceptionCallback exception; 58 SingleStepCallback singleStep; 59 VmStartCallback vmStart; 60 VmDeathCallback vmDeath; 61 62 Scenario scenario; 63 const EcmaVM *vm_ {nullptr}; 64 JSDebugger *debugInterface_ {nullptr}; 65 DebuggerImpl *debugger_ {nullptr}; 66 RuntimeImpl *runtime_ {nullptr}; 67 TestChannel *channel_ {nullptr}; 68 TestEvents(); 69 virtual ~TestEvents() = default; 70 71 virtual std::pair<std::string, std::string> GetEntryPoint() = 0; 72 }; 73 } // namespace panda::ecmascript::tooling::test 74 75 #endif // ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H 76