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 #include <csignal>
17
18 #include "ecmascript/ecma_vm.h"
19 #include "ecmascript/napi/include/jsnapi.h"
20 #include "ecmascript/tests/test_helper.h"
21 #include "tooling/test/client_utils/test_list.h"
22 #include "tooling/test/client_utils/test_util.h"
23
24 namespace panda::ecmascript::tooling::test {
25 using panda::test::TestHelper;
26 static int g_port = 9002; // 9002: socket port
27 class DebuggerClientTest : public testing::TestWithParam<const char *> {
28 public:
SetUpTestCase()29 static void SetUpTestCase()
30 {
31 GTEST_LOG_(INFO) << "SetUpTestCase";
32 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
33 GTEST_LOG_(ERROR) << "Reset SIGPIPE failed.";
34 }
35 }
36
TearDownTestCase()37 static void TearDownTestCase()
38 {
39 GTEST_LOG_(INFO) << "TearDownCase";
40 }
41
42 void SetUp() override
43 {
44 g_port -= 1;
45 SetCurrentTestName(GetParam());
46 TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
47 TestUtil::ForkSocketClient(g_port, GetParam());
48 JSNApi::DebugOption debugOption = {DEBUGGER_LIBRARY, true, g_port};
49 JSNApi::StartDebugger(instance, debugOption);
50 if (instance->GetJsDebuggerManager() != nullptr) {
51 instance->GetJsDebuggerManager()->DisableObjectHashDisplay();
52 }
53 }
54
55 void TearDown() override
56 {
57 std::this_thread::sleep_for(std::chrono::microseconds(500000)); // 500000: 500ms
58 JSNApi::StopDebugger(instance);
59 TestHelper::DestroyEcmaVMWithScope(instance, scope);
60 }
61
62 EcmaVM *instance {nullptr};
63 EcmaHandleScope *scope {nullptr};
64 JSThread *thread {nullptr};
65 };
66
67 //NOTE: enable (issue 18042)
HWTEST_P_L0(DebuggerClientTest, DebuggerSuite)68 HWTEST_P_L0(DebuggerClientTest, DebuggerSuite)
69 {
70 std::string testName = GetCurrentTestName();
71 std::cout << "Running " << testName << std::endl;
72 ASSERT_NE(instance, nullptr);
73 auto [pandaFile, entryPoint] = GetTestEntryPoint(testName);
74 auto res = JSNApi::Execute(instance, pandaFile.c_str(), entryPoint.c_str());
75 ASSERT_TRUE(res);
76 }
77
78 INSTANTIATE_TEST_SUITE_P(DebugClientAbcTest, DebuggerClientTest, testing::ValuesIn(GetTestList()));
79 } // namespace panda::ecmascript::tooling::test
80