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 16 #include <gtest/gtest.h> 17 #include <ctime> 18 #include <securec.h> 19 #include <string> 20 #include <sys/utsname.h> 21 #include <vector> 22 23 #include "arch_util.h" 24 #include "unwind_define.h" 25 26 using namespace OHOS::HiviewDFX; 27 using namespace testing::ext; 28 using namespace std; 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 class ArchUtilTest : 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 /** 41 * @tc.name: ArchUtilTest001 42 * @tc.desc: test ArchUtil functions 43 * @tc.type: FUNC 44 */ 45 HWTEST_F(ArchUtilTest, ArchUtilTest001, TestSize.Level2) 46 { 47 GTEST_LOG_(INFO) << "ArchUtilTest001: start."; 48 utsname systemName; 49 #if defined(__arm__) 50 if ((uname(&systemName)) != 0) { 51 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_ARM); 52 } 53 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_ARM); 54 #elif defined(__aarch64__) 55 if ((uname(&systemName)) != 0) { 56 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_ARM64); 57 } 58 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_ARM64); 59 #elif defined(__i386__) 60 if ((uname(&systemName)) != 0) { 61 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_X86); 62 } 63 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_X86); 64 #elif defined(__x86_64__) 65 if ((uname(&systemName)) != 0) { 66 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_X86_64); 67 } 68 ASSER_EQ(GetCurrentArch(), ArchType::ARCH_X86_64); 69 #else 70 if ((uname(&systemName)) != 0) { 71 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_UNKNOWN); 72 } 73 ASSER_EQ(GetCurrentArch(), ArchType::ARCH_UNKNOWN); 74 #endif 75 ASSERT_EQ(GetArchName(ArchType::ARCH_X86), "X86_32"); 76 ASSERT_EQ(GetArchName(ArchType::ARCH_X86_64), "X86_64"); 77 ASSERT_EQ(GetArchName(ArchType::ARCH_ARM), "ARM"); 78 ASSERT_EQ(GetArchName(ArchType::ARCH_ARM64), "ARM64"); 79 ASSERT_EQ(GetArchName(ArchType::ARCH_UNKNOWN), "Unsupport"); 80 GTEST_LOG_(INFO) << "ArchUtilTest001: end."; 81 } 82 } // namespace HiviewDFX 83 } // namespace OHOS