14c6eebf8SFred Riss //===-- PlatformAppleSimulatorTest.cpp ------------------------------------===//
24c6eebf8SFred Riss //
34c6eebf8SFred Riss // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44c6eebf8SFred Riss // See https://llvm.org/LICENSE.txt for license information.
54c6eebf8SFred Riss // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64c6eebf8SFred Riss //
74c6eebf8SFred Riss //===----------------------------------------------------------------------===//
84c6eebf8SFred Riss
94c6eebf8SFred Riss #include "gtest/gtest.h"
104c6eebf8SFred Riss
11243903f3SAdrian Prantl #include "Plugins/Platform/MacOSX/PlatformAppleSimulator.h"
129097920eSJonas Devlieghere #include "Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h"
139097920eSJonas Devlieghere #include "Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h"
149097920eSJonas Devlieghere #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
154c6eebf8SFred Riss #include "TestingSupport/SubsystemRAII.h"
164c6eebf8SFred Riss #include "lldb/Host/FileSystem.h"
174c6eebf8SFred Riss #include "lldb/Host/HostInfo.h"
184c6eebf8SFred Riss #include "lldb/Target/Platform.h"
194c6eebf8SFred Riss
204c6eebf8SFred Riss using namespace lldb;
214c6eebf8SFred Riss using namespace lldb_private;
224c6eebf8SFred Riss
234c6eebf8SFred Riss class PlatformAppleSimulatorTest : public ::testing::Test {
249097920eSJonas Devlieghere SubsystemRAII<FileSystem, HostInfo, PlatformAppleSimulator, PlatformRemoteiOS,
259097920eSJonas Devlieghere PlatformRemoteAppleTV, PlatformRemoteAppleWatch>
264c6eebf8SFred Riss subsystems;
274c6eebf8SFred Riss };
284c6eebf8SFred Riss
294c6eebf8SFred Riss #ifdef __APPLE__
304c6eebf8SFred Riss
testSimPlatformArchHasSimEnvironment(llvm::StringRef name)314c6eebf8SFred Riss static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) {
32*d6678404SMed Ismail Bennani auto platform_sp = Platform::Create(name);
334c6eebf8SFred Riss ASSERT_TRUE(platform_sp);
344c6eebf8SFred Riss int num_arches = 0;
354c6eebf8SFred Riss
36dde487e5SJonas Devlieghere for (auto arch : platform_sp->GetSupportedArchitectures({})) {
374c6eebf8SFred Riss EXPECT_EQ(arch.GetTriple().getEnvironment(), llvm::Triple::Simulator);
384c6eebf8SFred Riss num_arches++;
394c6eebf8SFred Riss }
404c6eebf8SFred Riss
414c6eebf8SFred Riss EXPECT_GT(num_arches, 0);
424c6eebf8SFred Riss }
434c6eebf8SFred Riss
TEST_F(PlatformAppleSimulatorTest,TestSimHasSimEnvionament)444c6eebf8SFred Riss TEST_F(PlatformAppleSimulatorTest, TestSimHasSimEnvionament) {
454c6eebf8SFred Riss testSimPlatformArchHasSimEnvironment("ios-simulator");
464c6eebf8SFred Riss testSimPlatformArchHasSimEnvironment("tvos-simulator");
474c6eebf8SFred Riss testSimPlatformArchHasSimEnvironment("watchos-simulator");
484c6eebf8SFred Riss }
494c6eebf8SFred Riss
TEST_F(PlatformAppleSimulatorTest,TestHostPlatformToSim)504c6eebf8SFred Riss TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) {
514c6eebf8SFred Riss static const ArchSpec platform_arch(
524c6eebf8SFred Riss HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
534c6eebf8SFred Riss
544c6eebf8SFred Riss const llvm::Triple::OSType sim_platforms[] = {
554c6eebf8SFred Riss llvm::Triple::IOS,
564c6eebf8SFred Riss llvm::Triple::TvOS,
574c6eebf8SFred Riss llvm::Triple::WatchOS,
584c6eebf8SFred Riss };
594c6eebf8SFred Riss
604c6eebf8SFred Riss for (auto sim : sim_platforms) {
61*d6678404SMed Ismail Bennani PlatformList list;
624c6eebf8SFred Riss ArchSpec arch = platform_arch;
634c6eebf8SFred Riss arch.GetTriple().setOS(sim);
644c6eebf8SFred Riss arch.GetTriple().setEnvironment(llvm::Triple::Simulator);
654c6eebf8SFred Riss
66*d6678404SMed Ismail Bennani auto platform_sp = list.GetOrCreate(arch, {}, nullptr);
674c6eebf8SFred Riss EXPECT_TRUE(platform_sp);
684c6eebf8SFred Riss }
694c6eebf8SFred Riss }
704c6eebf8SFred Riss
TEST_F(PlatformAppleSimulatorTest,TestPlatformSelectionOrder)719097920eSJonas Devlieghere TEST_F(PlatformAppleSimulatorTest, TestPlatformSelectionOrder) {
729097920eSJonas Devlieghere static const ArchSpec platform_arch(
739097920eSJonas Devlieghere HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
749097920eSJonas Devlieghere
759097920eSJonas Devlieghere const llvm::Triple::OSType sim_platforms[] = {
769097920eSJonas Devlieghere llvm::Triple::IOS,
779097920eSJonas Devlieghere llvm::Triple::TvOS,
789097920eSJonas Devlieghere llvm::Triple::WatchOS,
799097920eSJonas Devlieghere };
809097920eSJonas Devlieghere
81*d6678404SMed Ismail Bennani PlatformList list;
82*d6678404SMed Ismail Bennani list.GetOrCreate("remote-ios");
83*d6678404SMed Ismail Bennani list.GetOrCreate("remote-tvos");
84*d6678404SMed Ismail Bennani list.GetOrCreate("remote-watchos");
859097920eSJonas Devlieghere
869097920eSJonas Devlieghere for (auto sim : sim_platforms) {
879097920eSJonas Devlieghere ArchSpec arch = platform_arch;
889097920eSJonas Devlieghere arch.GetTriple().setOS(sim);
899097920eSJonas Devlieghere arch.GetTriple().setEnvironment(llvm::Triple::Simulator);
909097920eSJonas Devlieghere
919097920eSJonas Devlieghere Status error;
92*d6678404SMed Ismail Bennani auto platform_sp = list.GetOrCreate(arch, {}, nullptr, error);
939097920eSJonas Devlieghere EXPECT_TRUE(platform_sp);
949097920eSJonas Devlieghere EXPECT_TRUE(platform_sp->GetName().contains("simulator"));
959097920eSJonas Devlieghere }
969097920eSJonas Devlieghere }
979097920eSJonas Devlieghere
984c6eebf8SFred Riss #endif
99