• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             runtime_->Enable();
36             // 18: breakpointer line
37             location_ = TestUtil::GetLocation(sourceFile_.c_str(), 18, 0, pandaFile_.c_str());
38             ASSERT_TRUE(location_.GetMethodId().IsValid());
39             TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE);
40             ASSERT_EQ(moduleName, pandaFile_);
41             ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_));
42             auto condFuncRef = FunctionRef::Undefined(vm_);
43             auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef);
44             ASSERT_TRUE(ret);
45             return true;
46         };
47 
48         scenario = [this]() {
49             TestUtil::WaitForLoadModule();
50             TestUtil::Continue();
51             TestUtil::WaitForBreakpoint(location_);
52             TestUtil::Continue();
53             TestUtil::WaitForBreakpoint(location_);
54             TestUtil::Continue();
55             auto ret = debugInterface_->RemoveBreakpoint(location_);
56             ASSERT_TRUE(ret);
57             ASSERT_EXITED();
58             return true;
59         };
60 
61         vmDeath = [this]() {
62             ASSERT_EQ(breakpointCounter_, 2U);  // 2: break point counter
63             return true;
64         };
65     }
66 
GetEntryPoint()67     std::pair<std::string, std::string> GetEntryPoint() override
68     {
69         return {pandaFile_, entryPoint_};
70     }
71     ~JsBreakpointAsyncTest() = default;
72 
73 private:
74     std::string pandaFile_ = DEBUGGER_ABC_DIR "async_func.abc";
75     std::string sourceFile_ = DEBUGGER_JS_DIR "async_func.js";
76     std::string entryPoint_ = "_GLOBAL::func_main_0";
77     JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0};
78     size_t breakpointCounter_ = 0;
79 };
80 
GetJsBreakpointAsyncTest()81 std::unique_ptr<TestEvents> GetJsBreakpointAsyncTest()
82 {
83     return std::make_unique<JsBreakpointAsyncTest>();
84 }
85 }  // namespace panda::ecmascript::tooling::test
86 
87 #endif  // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ASYNC_TEST_H
88