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 auto platform_sp = Platform::Create(name); 29 ASSERT_TRUE(platform_sp); 30 int num_arches = 0; 31 32 for (auto arch : platform_sp->GetSupportedArchitectures({})) { 33 EXPECT_EQ(arch.GetTriple().getEnvironment(), llvm::Triple::Simulator); 34 num_arches++; 35 } 36 37 EXPECT_GT(num_arches, 0); 38 } 39 40 TEST_F(PlatformAppleSimulatorTest, TestSimHasSimEnvionament) { 41 testSimPlatformArchHasSimEnvironment("ios-simulator"); 42 testSimPlatformArchHasSimEnvironment("tvos-simulator"); 43 testSimPlatformArchHasSimEnvironment("watchos-simulator"); 44 } 45 46 TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) { 47 static const ArchSpec platform_arch( 48 HostInfo::GetArchitecture(HostInfo::eArchKindDefault)); 49 50 const llvm::Triple::OSType sim_platforms[] = { 51 llvm::Triple::IOS, 52 llvm::Triple::TvOS, 53 llvm::Triple::WatchOS, 54 }; 55 56 for (auto sim : sim_platforms) { 57 PlatformList list; 58 ArchSpec arch = platform_arch; 59 arch.GetTriple().setOS(sim); 60 arch.GetTriple().setEnvironment(llvm::Triple::Simulator); 61 62 auto platform_sp = list.GetOrCreate(arch, {}, nullptr); 63 EXPECT_TRUE(platform_sp); 64 } 65 } 66 67 #endif 68