1 /**
2 * Copyright (c) 2021-2024 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 <gtest/gtest.h>
17 #include <vector>
18
19 #include "runtime/include/runtime_options.h"
20 #include "libpandabase/utils/pandargs.h"
21 #include "options_test_base.h"
22
23 namespace ark::test {
24
25 class RuntimeOptionsTest : public RuntimeOptionsTestBase {
26 public:
27 NO_COPY_SEMANTIC(RuntimeOptionsTest);
28 NO_MOVE_SEMANTIC(RuntimeOptionsTest);
29
30 RuntimeOptionsTest() = default;
31 ~RuntimeOptionsTest() override = default;
32
33 private:
34 void LoadCorrectOptionsList() override;
35 };
36
LoadCorrectOptionsList()37 void RuntimeOptionsTest::LoadCorrectOptionsList()
38 {
39 AddTestingOption("runtime-compressed-strings-enabled", "true");
40 AddTestingOption("compiler-enable-jit", "true");
41 AddTestingOption("sigquit-flag", "1234");
42 AddTestingOption("dfx-log", "1234");
43 AddTestingOption("start-as-zygote", "true");
44 AddTestingOption("gc-trigger-type", "no-gc-for-start-up");
45 }
46
47 // Testing that generator correctly generate options for different languages
TEST_F(RuntimeOptionsTest,TestCorrectOptions)48 TEST_F(RuntimeOptionsTest, TestCorrectOptions)
49 {
50 ASSERT_TRUE(GetParser()->Parse(GetCorrectOptionsList()));
51 }
52
53 // Testing that ark::PandArgParser detect invalid options and types
TEST_F(RuntimeOptionsTest,TestIncorrectOptions)54 TEST_F(RuntimeOptionsTest, TestIncorrectOptions)
55 {
56 std::vector<std::string> invalidOptions;
57 invalidOptions.emplace_back("--InvalidOptionThatNotExistAndNeverWillBeAdded=true");
58 ASSERT_FALSE(GetParser()->Parse(invalidOptions));
59 ASSERT_EQ(GetParser()->GetErrorString(),
60 "pandargs: Invalid option \"InvalidOptionThatNotExistAndNeverWillBeAdded\"\n");
61 }
62
TEST_F(RuntimeOptionsTest,TestTailArgumets)63 TEST_F(RuntimeOptionsTest, TestTailArgumets)
64 {
65 GetParser()->EnableTail();
66 std::vector<std::string> optionsVector = GetCorrectOptionsList();
67 ark::PandArg<std::string> file("file", "", "path to pandafile");
68
69 optionsVector.emplace_back("tail1");
70 GetParser()->PushBackTail(&file);
71 ASSERT_TRUE(GetParser()->Parse(optionsVector));
72
73 optionsVector.emplace_back("tail2");
74 ASSERT_FALSE(GetParser()->Parse(optionsVector));
75 ASSERT_EQ(GetParser()->GetErrorString(), "pandargs: Too many tail arguments given\n");
76
77 GetParser()->DisableTail();
78 optionsVector.pop_back();
79 ASSERT_FALSE(GetParser()->Parse(optionsVector));
80 ASSERT_EQ(GetParser()->GetErrorString(),
81 "pandargs: Tail arguments are not enabled\npandargs: Tail found at literal \"tail1\"\n");
82 }
83
TEST_F(RuntimeOptionsTest,TestLangSpecificOptions)84 TEST_F(RuntimeOptionsTest, TestLangSpecificOptions)
85 {
86 ASSERT_TRUE(GetParser()->Parse(GetCorrectOptionsList()));
87 ASSERT_EQ(GetRuntimeOptions()->GetGcTriggerType("core"), "no-gc-for-start-up");
88 }
89
90 } // namespace ark::test
91