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 "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h" 13 #include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h" 14 #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" 15 #include "TestingSupport/SubsystemRAII.h" 16 #include "lldb/Host/FileSystem.h" 17 #include "lldb/Host/HostInfo.h" 18 #include "lldb/Target/Platform.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 class PlatformAppleSimulatorTest : public ::testing::Test { 24 SubsystemRAII<FileSystem, HostInfo, PlatformAppleSimulator, PlatformRemoteiOS, 25 PlatformRemoteAppleTV, PlatformRemoteAppleWatch> 26 subsystems; 27 }; 28 29 #ifdef __APPLE__ 30 31 static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) { 32 auto platform_sp = Platform::Create(name); 33 ASSERT_TRUE(platform_sp); 34 int num_arches = 0; 35 36 for (auto arch : platform_sp->GetSupportedArchitectures({})) { 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 PlatformList list; 62 ArchSpec arch = platform_arch; 63 arch.GetTriple().setOS(sim); 64 arch.GetTriple().setEnvironment(llvm::Triple::Simulator); 65 66 auto platform_sp = list.GetOrCreate(arch, {}, nullptr); 67 EXPECT_TRUE(platform_sp); 68 } 69 } 70 71 TEST_F(PlatformAppleSimulatorTest, TestPlatformSelectionOrder) { 72 static const ArchSpec platform_arch( 73 HostInfo::GetArchitecture(HostInfo::eArchKindDefault)); 74 75 const llvm::Triple::OSType sim_platforms[] = { 76 llvm::Triple::IOS, 77 llvm::Triple::TvOS, 78 llvm::Triple::WatchOS, 79 }; 80 81 PlatformList list; 82 list.GetOrCreate("remote-ios"); 83 list.GetOrCreate("remote-tvos"); 84 list.GetOrCreate("remote-watchos"); 85 86 for (auto sim : sim_platforms) { 87 ArchSpec arch = platform_arch; 88 arch.GetTriple().setOS(sim); 89 arch.GetTriple().setEnvironment(llvm::Triple::Simulator); 90 91 Status error; 92 auto platform_sp = list.GetOrCreate(arch, {}, nullptr, error); 93 EXPECT_TRUE(platform_sp); 94 EXPECT_TRUE(platform_sp->GetName().contains("simulator")); 95 } 96 } 97 98 #endif 99