1/* 2 * Copyright (c) 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#include <gtest/gtest.h> 16#include <ctime> 17#include <string> 18#include <vector> 19#include "dfx_elf.h" 20#include "dfx_xz_utils.h" 21#include "unwinder_config.h" 22 23using namespace OHOS::HiviewDFX; 24using namespace testing::ext; 25using namespace std; 26 27#define DUMPCATCHER_ELF_FILE "/system/bin/dumpcatcher" 28 29namespace OHOS { 30namespace HiviewDFX { 31 32class DfxXzUtilTest : public testing::Test { 33public: 34 static void SetUpTestCase(void) {} 35 static void TearDownTestCase(void) {} 36 void SetUp() {} 37 void TearDonw() {} 38}; 39 40namespace { 41/** 42 * @tc.name: DfxXzUtilTest001 43 * @tc.desc: test XzUtil functions 44 * @tc.type: FUNC 45 */ 46#ifndef __x86_64__ 47HWTEST_F(DfxXzUtilTest, DfxXzUtilTest001, TestSize.Level2) 48{ 49 GTEST_LOG_(INFO) << "DfxXzUtilTest001: start."; 50 UnwinderConfig::SetEnableMiniDebugInfo(true); 51 DfxElf elf(DUMPCATCHER_ELF_FILE); 52 ASSERT_TRUE(elf.IsValid()); 53 auto minidebugInfo = elf.GetMiniDebugInfo(); 54 ASSERT_TRUE(minidebugInfo != nullptr); 55 uint8_t *addr = minidebugInfo->offset + const_cast<uint8_t*>(elf.GetMmapPtr()); 56 std::shared_ptr<std::vector<uint8_t>> decompressedElf = std::make_shared<std::vector<uint8_t>>();; 57 ASSERT_TRUE(XzDecompress(addr, minidebugInfo->size, decompressedElf)); 58 ASSERT_TRUE(decompressedElf->size() > minidebugInfo->size); 59 GTEST_LOG_(INFO) << "DfxXzUtilTest001: end."; 60} 61#endif 62} 63} // namespace HiviewDFX 64} // namespace OHOS