• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <ctime>
18 #include <securec.h>
19 #include <string>
20 #include <vector>
21 
22 #include "dfx_memory_file.h"
23 
24 using namespace OHOS::HiviewDFX;
25 using namespace testing::ext;
26 using namespace std;
27 
28 static const char DUMPCATCHER_ELF_FILE[] = "/system/bin/dumpcatcher";
29 
30 namespace OHOS {
31 namespace HiviewDFX {
32 class DfxMemoryTest : public testing::Test {
33 public:
SetUpTestCase(void)34     static void SetUpTestCase(void) {}
TearDownTestCase(void)35     static void TearDownTestCase(void) {}
SetUp()36     void SetUp() {}
TearDown()37     void TearDown() {}
38 };
39 
40 namespace {
41 /**
42  * @tc.name: DfxMemoryTest001
43  * @tc.desc: test DfxMemory class CreateFileMemory
44  * @tc.type: FUNC
45  */
46 HWTEST_F(DfxMemoryTest, DfxMemoryTest001, TestSize.Level2)
47 {
48     GTEST_LOG_(INFO) << "DfxMemoryTest001: start.";
49     auto memory = DfxMemoryFile::CreateFileMemory(DUMPCATCHER_ELF_FILE, 0);
50     if (memory == nullptr) {
51         GTEST_LOG_(INFO) << "DfxMemoryTest001: create memory failed.";
52         FAIL();
53     }
54     int tmp;
55     bool ret = memory->ReadFully(0, &tmp, sizeof(tmp));
56     EXPECT_EQ(true, ret) << "DfxMemoryTest001: failed";
57     GTEST_LOG_(INFO) << "DfxMemoryTest001: end.";
58 }
59 }
60 } // namespace HiviewDFX
61 } // namespace OHOS
62