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