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 "unwinder_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 } // namespace HiviewDFX 40 } // namespace OHOS 41 namespace { 42 /** 43 * @tc.name: ArchUtilTest001 44 * @tc.desc: test ArchUtil functions 45 * @tc.type: FUNC 46 */ 47 HWTEST_F(ArchUtilTest, ArchUtilTest001, TestSize.Level2) 48 { 49 GTEST_LOG_(INFO) << "ArchUtilTest001: start."; 50 utsname systemName; 51 #if defined(__arm__) 52 if ((uname(&systemName)) != 0) { 53 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_ARM); 54 } 55 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_ARM); 56 #elif defined(__aarch64__) 57 if ((uname(&systemName)) != 0) { 58 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_ARM64); 59 } 60 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_ARM64); 61 #elif defined(__i386__) 62 if ((uname(&systemName)) != 0) { 63 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_X86); 64 } 65 ASSERT_EQ(GetCurrentArch(), ArchType::ARCH_X86); 66 #elif defined(__x86_64__) 67 if ((uname(&systemName)) != 0) { 68 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_X86_64); 69 } 70 ASSER_EQ(GetCurrentArch(), ArchType::ARCH_X86_64); 71 #else 72 if ((uname(&systemName)) != 0) { 73 ASSERT_EQ(GetArchFromUname(systemName.machine), ArchType::ARCH_UNKNOWN); 74 } 75 ASSER_EQ(GetCurrentArch(), ArchType::ARCH_UNKNOWN); 76 #endif 77 ASSERT_EQ(GetArchName(ArchType::ARCH_X86), "X86_32"); 78 ASSERT_EQ(GetArchName(ArchType::ARCH_X86_64), "X86_64"); 79 ASSERT_EQ(GetArchName(ArchType::ARCH_ARM), "ARM"); 80 ASSERT_EQ(GetArchName(ArchType::ARCH_ARM64), "ARM64"); 81 ASSERT_EQ(GetArchName(ArchType::ARCH_UNKNOWN), "Unsupport"); 82 GTEST_LOG_(INFO) << "ArchUtilTest001: end."; 83 } 84 85 } 86