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_TESTCASES_JS_BREAKPOINT_ASYNC_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ASYNC_TEST_H
18
19 #include "test/utils/test_util.h"
20
21 namespace panda::ecmascript::tooling::test {
22 class JsBreakpointAsyncTest : public TestEvents {
23 public:
JsBreakpointAsyncTest()24 JsBreakpointAsyncTest()
25 {
26 breakpoint = [this](const JSPtLocation &location) {
27 ASSERT_TRUE(location.GetMethodId().IsValid());
28 ASSERT_LOCATION_EQ(location, location_);
29 ++breakpointCounter_;
30 TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location);
31 return true;
32 };
33
34 loadModule = [this](std::string_view moduleName) {
35 location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line
36 ASSERT_TRUE(location_.GetMethodId().IsValid());
37 TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE);
38 ASSERT_EQ(moduleName, pandaFile_);
39 ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_));
40 auto condFuncRef = FunctionRef::Undefined(vm_);
41 auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef);
42 ASSERT_TRUE(ret);
43 return true;
44 };
45
46 scenario = [this]() {
47 TestUtil::WaitForLoadModule();
48 TestUtil::Continue();
49 TestUtil::WaitForBreakpoint(location_);
50 TestUtil::Continue();
51 TestUtil::WaitForBreakpoint(location_);
52 TestUtil::Continue();
53 auto ret = debugInterface_->RemoveBreakpoint(location_);
54 ASSERT_TRUE(ret);
55 ASSERT_EXITED();
56 return true;
57 };
58
59 vmDeath = [this]() {
60 ASSERT_EQ(breakpointCounter_, 2U); // 2: break point counter
61 return true;
62 };
63 }
64
GetEntryPoint()65 std::pair<std::string, std::string> GetEntryPoint() override
66 {
67 return {pandaFile_, entryPoint_};
68 }
69 ~JsBreakpointAsyncTest() = default;
70
71 private:
72 std::string pandaFile_ = DEBUGGER_ABC_DIR "async_func.abc";
73 std::string entryPoint_ = "_GLOBAL::func_main_0";
74 JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0};
75 size_t breakpointCounter_ = 0;
76 };
77
GetJsBreakpointAsyncTest()78 std::unique_ptr<TestEvents> GetJsBreakpointAsyncTest()
79 {
80 return std::make_unique<JsBreakpointAsyncTest>();
81 }
82 } // namespace panda::ecmascript::tooling::test
83
84 #endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ASYNC_TEST_H
85