• 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 #include "ecmascript/ecma_vm.h"
16 #include "ecmascript/js_runtime_options.h"
17 #include "ecmascript/tests/test_helper.h"
18 
19 using namespace panda::ecmascript;
20 
21 namespace panda::test {
22 class EcmaVMTest : public testing::Test {
23 public:
SetUpTestCase()24     static void SetUpTestCase()
25     {
26         GTEST_LOG_(INFO) << "SetUpTestCase";
27     }
28 
TearDownTestCase()29     static void TearDownTestCase()
30     {
31         GTEST_LOG_(INFO) << "TearDownCase";
32     }
33 
SetUp()34     void SetUp() override
35     {
36     }
37 
TearDown()38     void TearDown() override
39     {
40     }
41 };
42 
43 /*
44  * @tc.name: CreateEcmaVMInTwoWays
45  * @tc.desc: Create EcmaVM in 2 ways, check the Options state
46  * @tc.type: FUNC
47  * @tc.require:
48  */
HWTEST_F_L0(EcmaVMTest,CreateEcmaVMInTwoWays)49 HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays)
50 {
51     RuntimeOption options;
52     options.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
53     EcmaVM *ecmaVm1 = JSNApi::CreateJSVM(options);
54 
55     JSRuntimeOptions options2;
56     options2.SetEnableArkTools(false);
57     options2.SetEnableForceGC(false);
58     options2.SetForceFullGC(false);
59     options2.SetArkProperties(ArkProperties::GC_STATS_PRINT);
60     // A non-production gc strategy. Prohibit stw-gc 10 times.
61     EcmaVM *ecmaVm2 = JSNApi::CreateEcmaVM(options2);
62 
63     EXPECT_TRUE(ecmaVm1 != ecmaVm2);
64 
65     JSRuntimeOptions options1Out = ecmaVm1->GetJSOptions();
66     JSRuntimeOptions options2Out = ecmaVm2->GetJSOptions();
67 
68     EXPECT_TRUE(&options1Out != &options2Out);
69 
70     EXPECT_TRUE(options1Out.EnableArkTools() != options2Out.EnableArkTools());
71     EXPECT_TRUE(options1Out.EnableForceGC() != options2Out.EnableForceGC());
72     EXPECT_TRUE(options1Out.ForceFullGC() != options2Out.ForceFullGC());
73     EXPECT_TRUE(options1Out.GetArkProperties() != options2Out.GetArkProperties());
74 
75     JSNApi::DestroyJSVM(ecmaVm2);
76     JSNApi::DestroyJSVM(ecmaVm1);
77 }
78 }  // namespace panda::ecmascript
79