1 //===-- PlatformAppleSimulatorTest.cpp ------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "gtest/gtest.h" 10 11 #include "Plugins/Platform/MacOSX/PlatformAppleSimulator.h" 12 #include "TestingSupport/SubsystemRAII.h" 13 #include "lldb/Host/FileSystem.h" 14 #include "lldb/Host/HostInfo.h" 15 #include "lldb/Target/Platform.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 class PlatformAppleSimulatorTest : public ::testing::Test { 21 SubsystemRAII<FileSystem, HostInfo, PlatformAppleSimulator> 22 subsystems; 23 }; 24 25 #ifdef __APPLE__ 26 27 static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) { 28 Status error; 29 auto platform_sp = Platform::Create(ConstString(name), error); 30 ASSERT_TRUE(platform_sp); 31 int num_arches = 0; 32 33 while (true) { 34 ArchSpec arch; 35 if (!platform_sp->GetSupportedArchitectureAtIndex(num_arches, arch)) 36 break; 37 EXPECT_EQ(arch.GetTriple().getEnvironment(), llvm::Triple::Simulator); 38 num_arches++; 39 } 40 41 EXPECT_GT(num_arches, 0); 42 } 43 44 TEST_F(PlatformAppleSimulatorTest, TestSimHasSimEnvionament) { 45 testSimPlatformArchHasSimEnvironment("ios-simulator"); 46 testSimPlatformArchHasSimEnvironment("tvos-simulator"); 47 testSimPlatformArchHasSimEnvironment("watchos-simulator"); 48 } 49 50 TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) { 51 static const ArchSpec platform_arch( 52 HostInfo::GetArchitecture(HostInfo::eArchKindDefault)); 53 54 const llvm::Triple::OSType sim_platforms[] = { 55 llvm::Triple::IOS, 56 llvm::Triple::TvOS, 57 llvm::Triple::WatchOS, 58 }; 59 60 for (auto sim : sim_platforms) { 61 ArchSpec arch = platform_arch; 62 arch.GetTriple().setOS(sim); 63 arch.GetTriple().setEnvironment(llvm::Triple::Simulator); 64 65 Status error; 66 auto platform_sp = Platform::Create(arch, nullptr, error); 67 EXPECT_TRUE(platform_sp); 68 } 69 } 70 71 #endif 72