1 /**
2 * Copyright (c) 2021-2023 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 panda::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()
59 + Separator() + ".."
60 + Separator() + ".."
61 + Separator() + ".."
62 + Separator() + "pandastdlib" + Separator() + "arkstdlib.abc";
63 // clang-format on
64
65 auto pfile = GetDirName() + Separator() + "pfile.abc";
66 auto app = GetDirName() + Separator() + "app.abc";
67 std::string_view main_class = "Test";
68 std::string_view main_function = "main";
69 std::string entrypoint = std::string(main_class) + "::" + std::string(main_function);
70
71 int64_t exp_res = 9;
72 auto res = RunPandaFile("--boot-panda-files", boot.data(), "--panda-files", pfile.data(), app.data(),
73 entrypoint.data());
74 ASSERT_TRUE(res) << "Exec failed with the error: " << res.Error().ToString();
75 ASSERT_EQ(res.Value(), exp_res) << "Panda must fail";
76 }
77 }
78
79 } // namespace panda::cli::test
80
main(int argc,char ** argv)81 int main(int argc, char **argv)
82 {
83 panda::cli::test::glob_argv0 = argv[0];
84 // CHECKER_IGNORE_NEXTLINE(AF0010)
85 ::testing::InitGoogleTest(&argc, argv);
86 return RUN_ALL_TESTS();
87 }
88
89 // NOLINTEND