• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // NOLINTBEGIN
17 
18 #include "common.h"
19 
20 #include "libpandabase/utils/arch.h"
21 
22 #include <gtest/gtest.h>
23 
24 namespace ark::cli::test {
25 
26 std::string glob_argv0 = "";
27 
28 class PandaOptionsTest : public PandaTest {
29 public:
PandaOptionsTest()30     PandaOptionsTest()
31     {
32         SetEnv(glob_argv0);
33         dir_name_ = GetBinPath();
34     }
35 
36 public:
GetDirName() const37     inline virtual std::string GetDirName() const final
38     {
39         return dir_name_;
40     }
41 
42 private:
43     std::string dir_name_;
44 };
45 
46 // NOTE(mgonopolskiy): add tests for all possible cases
TEST_F(PandaOptionsTest,PandaFiles)47 TEST_F(PandaOptionsTest, PandaFiles)
48 {
49     // Test basic functionality only in host mode.
50     // NOTE(mgonopolskiy): add support for all modes
51     if (RUNTIME_ARCH != Arch::X86_64) {
52         return;
53     }
54 
55     {
56         auto boot = GetDirName() + Separator() + "boot.abc";
57         // clang-format off
58         boot += ":" + GetDirName() + Separator() + ".." + Separator() + ".." + Separator() + ".."
59                     + Separator() + "pandastdlib" + Separator() + "arkstdlib.abc";
60         // clang-format on
61 
62         auto pfile = GetDirName() + Separator() + "pfile.abc";
63         auto app = GetDirName() + Separator() + "app.abc";
64         std::string_view main_class = "Test";
65         std::string_view main_function = "main";
66         std::string entrypoint = std::string(main_class) + "::" + std::string(main_function);
67 
68         int64_t exp_res = 9;
69         auto res = RunPandaFile("--boot-panda-files", boot.data(), "--panda-files", pfile.data(), app.data(),
70                                 entrypoint.data());
71         ASSERT_TRUE(res) << "Exec failed with the error: " << res.Error().ToString();
72         ASSERT_EQ(res.Value(), exp_res) << "Panda must fail";
73     }
74 }
75 
76 }  // namespace ark::cli::test
77 
main(int argc,char ** argv)78 int main(int argc, char **argv)
79 {
80     ark::cli::test::glob_argv0 = argv[0];
81     // CHECKER_IGNORE_NEXTLINE(AF0010)
82     ::testing::InitGoogleTest(&argc, argv);
83     return RUN_ALL_TESTS();
84 }
85 
86 // NOLINTEND