• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include <cstdio>
23 #include <cstdlib>
24 #include <dlfcn.h>
25 #include <algorithm>
26 #include <fstream>
27 #include <string>
28 #include <iostream>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <sys/mman.h>
32 #include <gtest/gtest.h>
33 #include <pthread.h>
34 #include "hook.h"
35 
36 using namespace testing::ext;
37 using namespace std;
38 
39 extern "C"{
40     bool get_transparent_hugepages_supported(void);
41     int open(const char *filename, int flags, ...);
42     ssize_t read(int fd, void *buf, size_t count);
43 }
44 
45 namespace OHOS {
46 namespace {
47 
48 class DynlinkTest : public testing::Test {
49 public:
50     static void TearDownTestCase(void);
51 };
52 
TearDownTestCase(void)53 void DynlinkTest::TearDownTestCase(void)
54 {
55 }
56 
57 /**
58  * @tc.name: get_transparent_hugepages_supported_test001
59  * @tc.desc: open failed
60  * @tc.type: FUNC
61  */
62 HWTEST_F(DynlinkTest, get_transparent_hugepages_supported_test_001, TestSize.Level0)
63 {
64     bool b = get_transparent_hugepages_supported();
65     EXPECT_TRUE(b == false);
66 }
67 
68 
69 /**
70  * @tc.name: get_transparent_hugepages_supported_test002
71  * @tc.desc: open failed
72  * @tc.type: FUNC
73  */
74 HWTEST_F(DynlinkTest, get_transparent_hugepages_supported_test_002, TestSize.Level0)
75 {
76     set_hook_flag(OPEN_FLAG, true);
77     bool b = get_transparent_hugepages_supported();
78     set_hook_flag(OPEN_FLAG, false);
79     EXPECT_TRUE(b == true);
80 }
81 
82 
83 /**
84  * @tc.name: get_transparent_hugepages_supported_test003
85  * @tc.desc: read failed
86  * @tc.type: FUNC
87  */
88 HWTEST_F(DynlinkTest, get_transparent_hugepages_supported_test_003, TestSize.Level0)
89 {
90     set_hook_flag(OPEN_FLAG, true);
91     set_hook_flag(READ_FLAG_3, true);
92     bool b = get_transparent_hugepages_supported();
93     set_hook_flag(READ_FLAG_3, false);
94     set_hook_flag(OPEN_FLAG, false);
95 
96     EXPECT_TRUE(b == false);
97 }
98 
99 
100 /**
101  * @tc.name: get_transparent_hugepages_supported_test004
102  * @tc.desc: read failed
103  * @tc.type: FUNC
104  */
105 HWTEST_F(DynlinkTest, get_transparent_hugepages_supported_test_004, TestSize.Level0)
106 {
107     set_hook_flag(OPEN_FLAG, true);
108     set_hook_flag(STRSTR_FLAG, true);
109     bool b = get_transparent_hugepages_supported();
110     set_hook_flag(STRSTR_FLAG, false);
111     set_hook_flag(OPEN_FLAG, false);
112     EXPECT_TRUE(b == false);
113 }
114 
115 } //namespace
116 
117 } //namespace OHOS
118