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/PlatformAppleTVSimulator.h" 12 #include "Plugins/Platform/MacOSX/PlatformAppleWatchSimulator.h" 13 #include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h" 14 #include "TestingSupport/SubsystemRAII.h" 15 #include "lldb/Host/FileSystem.h" 16 #include "lldb/Host/HostInfo.h" 17 #include "lldb/Target/Platform.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 class PlatformAppleSimulatorTest : public ::testing::Test { 23 SubsystemRAII<FileSystem, HostInfo, PlatformAppleTVSimulator, 24 PlatformiOSSimulator, PlatformAppleWatchSimulator> 25 subsystems; 26 }; 27 28 #ifdef __APPLE__ 29 30 static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) { 31 Status error; 32 auto platform_sp = Platform::Create(ConstString(name), error); 33 ASSERT_TRUE(platform_sp); 34 int num_arches = 0; 35 36 while (true) { 37 ArchSpec arch; 38 if (!platform_sp->GetSupportedArchitectureAtIndex(num_arches, arch)) 39 break; 40 EXPECT_EQ(arch.GetTriple().getEnvironment(), llvm::Triple::Simulator); 41 num_arches++; 42 } 43 44 EXPECT_GT(num_arches, 0); 45 } 46 47 TEST_F(PlatformAppleSimulatorTest, TestSimHasSimEnvionament) { 48 testSimPlatformArchHasSimEnvironment("ios-simulator"); 49 testSimPlatformArchHasSimEnvironment("tvos-simulator"); 50 testSimPlatformArchHasSimEnvironment("watchos-simulator"); 51 } 52 53 TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) { 54 static const ArchSpec platform_arch( 55 HostInfo::GetArchitecture(HostInfo::eArchKindDefault)); 56 57 const llvm::Triple::OSType sim_platforms[] = { 58 llvm::Triple::IOS, 59 llvm::Triple::TvOS, 60 llvm::Triple::WatchOS, 61 }; 62 63 for (auto sim : sim_platforms) { 64 ArchSpec arch = platform_arch; 65 arch.GetTriple().setOS(sim); 66 arch.GetTriple().setEnvironment(llvm::Triple::Simulator); 67 68 Status error; 69 auto platform_sp = Platform::Create(arch, nullptr, error); 70 EXPECT_TRUE(platform_sp); 71 } 72 } 73 74 #endif 75