mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
ae65e281f3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
62 lines
2.0 KiB
C++
62 lines
2.0 KiB
C++
//===- unittests/Passes/Plugins/PluginsTest.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 "llvm/Analysis/CGSCCPassManager.h"
|
|
#include "llvm/Config/config.h"
|
|
#include "llvm/IR/PassManager.h"
|
|
#include "llvm/Passes/PassBuilder.h"
|
|
#include "llvm/Passes/PassPlugin.h"
|
|
#include "llvm/Support/FileSystem.h"
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
#include "llvm/Support/Path.h"
|
|
#include "llvm/Testing/Support/Error.h"
|
|
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "TestPlugin.h"
|
|
|
|
#include <cstdint>
|
|
|
|
using namespace llvm;
|
|
|
|
void anchor() {}
|
|
|
|
static std::string LibPath(const std::string Name = "TestPlugin") {
|
|
const std::vector<testing::internal::string> &Argvs =
|
|
testing::internal::GetArgvs();
|
|
const char *Argv0 = Argvs.size() > 0 ? Argvs[0].c_str() : "PluginsTests";
|
|
void *Ptr = (void *)(intptr_t)anchor;
|
|
std::string Path = sys::fs::getMainExecutable(Argv0, Ptr);
|
|
llvm::SmallString<256> Buf{sys::path::parent_path(Path)};
|
|
sys::path::append(Buf, (Name + LTDL_SHLIB_EXT).c_str());
|
|
return Buf.str();
|
|
}
|
|
|
|
TEST(PluginsTests, LoadPlugin) {
|
|
#if !defined(LLVM_ENABLE_PLUGINS)
|
|
// Disable the test if plugins are disabled.
|
|
return;
|
|
#endif
|
|
|
|
auto PluginPath = LibPath();
|
|
ASSERT_NE("", PluginPath);
|
|
|
|
Expected<PassPlugin> Plugin = PassPlugin::Load(PluginPath);
|
|
ASSERT_TRUE(!!Plugin) << "Plugin path: " << PluginPath;
|
|
|
|
ASSERT_EQ(TEST_PLUGIN_NAME, Plugin->getPluginName());
|
|
ASSERT_EQ(TEST_PLUGIN_VERSION, Plugin->getPluginVersion());
|
|
|
|
PassBuilder PB;
|
|
ModulePassManager PM;
|
|
ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, "plugin-pass"), Failed());
|
|
|
|
Plugin->registerPassBuilderCallbacks(PB);
|
|
ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, "plugin-pass"), Succeeded());
|
|
}
|