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