llvm-project/lldb/unittests/Platform/PlatformAppleSimulatorTest.cpp
Jonas Devlieghere dde487e547
[lldb] Plumb process host architecture through platform selection
To allow us to select a different platform based on where the process is
running, plumb the process host architecture through platform selection.

This patch is in preparation for D121444 which needs this functionality
to tell apart iOS binaries running on Apple Silicon vs on a remote iOS
device.

Differential revision: https://reviews.llvm.org/D121484
2022-03-14 12:17:01 -07:00

69 lines
2.0 KiB
C++

//===-- PlatformAppleSimulatorTest.cpp ------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "Plugins/Platform/MacOSX/PlatformAppleSimulator.h"
#include "TestingSupport/SubsystemRAII.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Target/Platform.h"
using namespace lldb;
using namespace lldb_private;
class PlatformAppleSimulatorTest : public ::testing::Test {
SubsystemRAII<FileSystem, HostInfo, PlatformAppleSimulator>
subsystems;
};
#ifdef __APPLE__
static void testSimPlatformArchHasSimEnvironment(llvm::StringRef name) {
Status error;
auto platform_sp = Platform::Create(ConstString(name), error);
ASSERT_TRUE(platform_sp);
int num_arches = 0;
for (auto arch : platform_sp->GetSupportedArchitectures({})) {
EXPECT_EQ(arch.GetTriple().getEnvironment(), llvm::Triple::Simulator);
num_arches++;
}
EXPECT_GT(num_arches, 0);
}
TEST_F(PlatformAppleSimulatorTest, TestSimHasSimEnvionament) {
testSimPlatformArchHasSimEnvironment("ios-simulator");
testSimPlatformArchHasSimEnvironment("tvos-simulator");
testSimPlatformArchHasSimEnvironment("watchos-simulator");
}
TEST_F(PlatformAppleSimulatorTest, TestHostPlatformToSim) {
static const ArchSpec platform_arch(
HostInfo::GetArchitecture(HostInfo::eArchKindDefault));
const llvm::Triple::OSType sim_platforms[] = {
llvm::Triple::IOS,
llvm::Triple::TvOS,
llvm::Triple::WatchOS,
};
for (auto sim : sim_platforms) {
ArchSpec arch = platform_arch;
arch.GetTriple().setOS(sim);
arch.GetTriple().setEnvironment(llvm::Triple::Simulator);
Status error;
auto platform_sp = Platform::Create(arch, {}, nullptr, error);
EXPECT_TRUE(platform_sp);
}
}
#endif