forked from OSchip/llvm-project
Fix Driver tests to check return value of parse(), simplify subclassing, and remove unneeded instance variables
llvm-svn: 186440
This commit is contained in:
parent
cadc611e93
commit
2a709eaa83
|
@ -24,66 +24,63 @@ namespace {
|
|||
|
||||
class DarwinLdParserTest : public ParserTest<DarwinLdDriver, MachOTargetInfo> {
|
||||
protected:
|
||||
virtual MachOTargetInfo* doParse(int argc, const char **argv,
|
||||
raw_ostream &diag) {
|
||||
auto *info = new MachOTargetInfo();
|
||||
DarwinLdDriver::parse(argc, argv, *info, diag);
|
||||
return info;
|
||||
virtual const TargetInfo *targetInfo() {
|
||||
return &_info;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(DarwinLdParserTest, Basic) {
|
||||
parse("ld", "foo.o", "bar.o", nullptr);
|
||||
EXPECT_FALSE(info->allowRemainingUndefines());
|
||||
EXPECT_FALSE(info->deadStrip());
|
||||
EXPECT_EQ(2, (int)inputFiles.size());
|
||||
EXPECT_EQ("foo.o", inputFiles[0]);
|
||||
EXPECT_EQ("bar.o", inputFiles[1]);
|
||||
EXPECT_FALSE(parse("ld", "foo.o", "bar.o", nullptr));
|
||||
EXPECT_FALSE(_info.allowRemainingUndefines());
|
||||
EXPECT_FALSE(_info.deadStrip());
|
||||
EXPECT_EQ(2, inputFileCount());
|
||||
EXPECT_EQ("foo.o", inputFile(0));
|
||||
EXPECT_EQ("bar.o", inputFile(1));
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Dylib) {
|
||||
parse("ld", "-dylib", "foo.o", nullptr);
|
||||
EXPECT_EQ(mach_o::MH_DYLIB, info->outputFileType());
|
||||
EXPECT_FALSE(parse("ld", "-dylib", "foo.o", nullptr));
|
||||
EXPECT_EQ(mach_o::MH_DYLIB, _info.outputFileType());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Relocatable) {
|
||||
parse("ld", "-r", "foo.o", nullptr);
|
||||
EXPECT_EQ(mach_o::MH_OBJECT, info->outputFileType());
|
||||
EXPECT_FALSE(parse("ld", "-r", "foo.o", nullptr));
|
||||
EXPECT_EQ(mach_o::MH_OBJECT, _info.outputFileType());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Bundle) {
|
||||
parse("ld", "-bundle", "foo.o", nullptr);
|
||||
EXPECT_EQ(mach_o::MH_BUNDLE, info->outputFileType());
|
||||
EXPECT_FALSE(parse("ld", "-bundle", "foo.o", nullptr));
|
||||
EXPECT_EQ(mach_o::MH_BUNDLE, _info.outputFileType());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Preload) {
|
||||
parse("ld", "-preload", "foo.o", nullptr);
|
||||
EXPECT_EQ(mach_o::MH_PRELOAD, info->outputFileType());
|
||||
EXPECT_FALSE(parse("ld", "-preload", "foo.o", nullptr));
|
||||
EXPECT_EQ(mach_o::MH_PRELOAD, _info.outputFileType());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Static) {
|
||||
parse("ld", "-static", "foo.o", nullptr);
|
||||
EXPECT_EQ(mach_o::MH_EXECUTE, info->outputFileType());
|
||||
EXPECT_FALSE(parse("ld", "-static", "foo.o", nullptr));
|
||||
EXPECT_EQ(mach_o::MH_EXECUTE, _info.outputFileType());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Entry) {
|
||||
parse("ld", "-e", "entryFunc", "foo.o", nullptr);
|
||||
EXPECT_EQ("entryFunc", info->entrySymbolName());
|
||||
EXPECT_FALSE(parse("ld", "-e", "entryFunc", "foo.o", nullptr));
|
||||
EXPECT_EQ("entryFunc", _info.entrySymbolName());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, OutputPath) {
|
||||
parse("ld", "-o", "foo", "foo.o", nullptr);
|
||||
EXPECT_EQ("foo", info->outputPath());
|
||||
EXPECT_FALSE(parse("ld", "-o", "foo", "foo.o", nullptr));
|
||||
EXPECT_EQ("foo", _info.outputPath());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, DeadStrip) {
|
||||
parse("ld", "-dead_strip", "foo.o", nullptr);
|
||||
EXPECT_TRUE(info->deadStrip());
|
||||
EXPECT_FALSE(parse("ld", "-dead_strip", "foo.o", nullptr));
|
||||
EXPECT_TRUE(_info.deadStrip());
|
||||
}
|
||||
|
||||
TEST_F(DarwinLdParserTest, Arch) {
|
||||
parse("ld", "-arch", "x86_64", "foo.o", nullptr);
|
||||
EXPECT_EQ(MachOTargetInfo::arch_x86_64, info->arch());
|
||||
EXPECT_FALSE(parse("ld", "-arch", "x86_64", "foo.o", nullptr));
|
||||
EXPECT_EQ(MachOTargetInfo::arch_x86_64, _info.arch());
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
|
|
@ -21,17 +21,26 @@ namespace {
|
|||
using namespace llvm;
|
||||
using namespace lld;
|
||||
|
||||
template<typename Driver, typename TargetInfo>
|
||||
template<typename D, typename T>
|
||||
class ParserTest : public testing::Test {
|
||||
protected:
|
||||
void SetUp() {
|
||||
os.reset(new raw_string_ostream(diags));
|
||||
|
||||
virtual const TargetInfo *targetInfo() = 0;
|
||||
|
||||
std::string &errorMessage() { return _errorMessage; }
|
||||
|
||||
// Convenience method for getting number of input files.
|
||||
int inputFileCount() {
|
||||
return targetInfo()->inputFiles().size();
|
||||
}
|
||||
|
||||
virtual TargetInfo *doParse(int argc, const char **argv,
|
||||
raw_ostream &diag) = 0;
|
||||
// Convenience method for getting i'th input files name.
|
||||
std::string inputFile(unsigned index) {
|
||||
return targetInfo()->inputFiles()[index].getPath().str();
|
||||
}
|
||||
|
||||
void parse(const char *args, ...) {
|
||||
// For unit tests to call driver with various command lines.
|
||||
bool parse(const char *args, ...) {
|
||||
// Construct command line options from varargs.
|
||||
std::vector<const char *> vec;
|
||||
vec.push_back(args);
|
||||
|
@ -42,18 +51,12 @@ protected:
|
|||
va_end(ap);
|
||||
|
||||
// Call the parser.
|
||||
info.reset(doParse(vec.size(), &vec[0], *os));
|
||||
|
||||
// Copy the output file name for the sake of convenience.
|
||||
if (info)
|
||||
for (const LinkerInput &input : info->inputFiles())
|
||||
inputFiles.push_back(input.getPath().str());
|
||||
raw_string_ostream os(_errorMessage);
|
||||
return D::parse(vec.size(), &vec[0], _info, os);
|
||||
}
|
||||
|
||||
std::unique_ptr<TargetInfo> info;
|
||||
std::string diags;
|
||||
std::unique_ptr<raw_string_ostream> os;
|
||||
std::vector<std::string> inputFiles;
|
||||
T _info;
|
||||
std::string _errorMessage;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,32 +21,36 @@ using namespace lld;
|
|||
|
||||
namespace {
|
||||
|
||||
class GnuLdParserTest : public ParserTest<GnuLdDriver, ELFTargetInfo> {
|
||||
class GnuLdParserTest : public ParserTest<
|
||||
GnuLdDriver, std::unique_ptr<ELFTargetInfo> > {
|
||||
protected:
|
||||
virtual ELFTargetInfo* doParse(int argc, const char **argv,
|
||||
raw_ostream &diag) {
|
||||
std::unique_ptr<ELFTargetInfo> info;
|
||||
GnuLdDriver::parse(argc, argv, info, diag);
|
||||
return info.release();
|
||||
virtual const TargetInfo *targetInfo() {
|
||||
return _info.get();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(GnuLdParserTest, Empty) {
|
||||
EXPECT_TRUE(parse("ld", nullptr));
|
||||
EXPECT_EQ(targetInfo(), nullptr);
|
||||
EXPECT_EQ("No input files\n", errorMessage());
|
||||
}
|
||||
|
||||
TEST_F(GnuLdParserTest, Basic) {
|
||||
parse("ld", "infile.o", nullptr);
|
||||
ASSERT_TRUE(!!info);
|
||||
EXPECT_EQ("a.out", info->outputPath());
|
||||
EXPECT_EQ(1, (int)inputFiles.size());
|
||||
EXPECT_EQ("infile.o", inputFiles[0]);
|
||||
EXPECT_FALSE(info->outputYAML());
|
||||
EXPECT_FALSE(parse("ld", "infile.o", nullptr));
|
||||
EXPECT_NE(targetInfo(), nullptr);
|
||||
EXPECT_EQ("a.out", targetInfo()->outputPath());
|
||||
EXPECT_EQ(1, inputFileCount());
|
||||
EXPECT_EQ("infile.o", inputFile(0));
|
||||
EXPECT_FALSE(_info->outputYAML());
|
||||
}
|
||||
|
||||
TEST_F(GnuLdParserTest, ManyOptions) {
|
||||
parse("ld", "-entry", "_start", "-o", "outfile",
|
||||
"-emit-yaml", "infile.o", nullptr);
|
||||
ASSERT_TRUE(!!info);
|
||||
EXPECT_EQ("outfile", info->outputPath());
|
||||
EXPECT_EQ("_start", info->entrySymbolName());
|
||||
EXPECT_TRUE(info->outputYAML());
|
||||
EXPECT_FALSE(parse("ld", "-entry", "_start", "-o", "outfile",
|
||||
"-emit-yaml", "infile.o", nullptr));
|
||||
EXPECT_NE(targetInfo(), nullptr);
|
||||
EXPECT_EQ("outfile", targetInfo()->outputPath());
|
||||
EXPECT_EQ("_start", targetInfo()->entrySymbolName());
|
||||
EXPECT_TRUE(_info->outputYAML());
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
|
|
@ -24,112 +24,110 @@ namespace {
|
|||
|
||||
class WinLinkParserTest : public ParserTest<WinLinkDriver, PECOFFTargetInfo> {
|
||||
protected:
|
||||
virtual PECOFFTargetInfo *doParse(int argc, const char **argv,
|
||||
raw_ostream &diag) {
|
||||
PECOFFTargetInfo *info = new PECOFFTargetInfo();
|
||||
EXPECT_FALSE(WinLinkDriver::parse(argc, argv, *info, diag));
|
||||
return info;
|
||||
virtual const TargetInfo *targetInfo() {
|
||||
return &_info;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(WinLinkParserTest, Basic) {
|
||||
parse("link.exe", "-subsystem", "console", "-out", "a.exe",
|
||||
"-entry", "_start", "a.obj", "b.obj", "c.obj", nullptr);
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, info->getSubsystem());
|
||||
EXPECT_EQ("a.exe", info->outputPath());
|
||||
EXPECT_EQ("_start", info->entrySymbolName());
|
||||
EXPECT_EQ(3, (int)inputFiles.size());
|
||||
EXPECT_EQ("a.obj", inputFiles[0]);
|
||||
EXPECT_EQ("b.obj", inputFiles[1]);
|
||||
EXPECT_EQ("c.obj", inputFiles[2]);
|
||||
EXPECT_EQ(6, info->getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(0, info->getMinOSVersion().minorVersion);
|
||||
EXPECT_EQ(1024 * 1024, info->getStackReserve());
|
||||
EXPECT_EQ(4096, info->getStackCommit());
|
||||
EXPECT_FALSE(info->allowRemainingUndefines());
|
||||
EXPECT_TRUE(info->getNxCompat());
|
||||
EXPECT_FALSE(info->getLargeAddressAware());
|
||||
EXPECT_FALSE(parse("link.exe", "-subsystem", "console", "-out", "a.exe",
|
||||
"-entry", "_start", "a.obj", "b.obj", "c.obj", nullptr));
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
|
||||
EXPECT_EQ("a.exe", _info.outputPath());
|
||||
EXPECT_EQ("_start", _info.entrySymbolName());
|
||||
EXPECT_EQ(3, inputFileCount());
|
||||
EXPECT_EQ("a.obj", inputFile(0));
|
||||
EXPECT_EQ("b.obj", inputFile(1));
|
||||
EXPECT_EQ("c.obj", inputFile(2));
|
||||
EXPECT_EQ(6, _info.getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
|
||||
EXPECT_EQ(1024 * 1024ULL, _info.getStackReserve());
|
||||
EXPECT_EQ(4096ULL, _info.getStackCommit());
|
||||
EXPECT_FALSE(_info.allowRemainingUndefines());
|
||||
EXPECT_TRUE(_info.getNxCompat());
|
||||
EXPECT_FALSE(_info.getLargeAddressAware());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, WindowsStyleOption) {
|
||||
parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj", nullptr);
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, info->getSubsystem());
|
||||
EXPECT_EQ("a.exe", info->outputPath());
|
||||
EXPECT_EQ(1, (int)inputFiles.size());
|
||||
EXPECT_EQ("a.obj", inputFiles[0]);
|
||||
EXPECT_FALSE(parse("link.exe", "/subsystem:console", "/out:a.exe", "a.obj",
|
||||
nullptr));
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _info.getSubsystem());
|
||||
EXPECT_EQ("a.exe", _info.outputPath());
|
||||
EXPECT_EQ(1, inputFileCount());
|
||||
EXPECT_EQ("a.obj", inputFile(0));
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NoFileExtension) {
|
||||
parse("link.exe", "foo", "bar", nullptr);
|
||||
EXPECT_EQ("foo.exe", info->outputPath());
|
||||
EXPECT_EQ(2, (int)inputFiles.size());
|
||||
EXPECT_EQ("foo.obj", inputFiles[0]);
|
||||
EXPECT_EQ("bar.obj", inputFiles[1]);
|
||||
EXPECT_FALSE(parse("link.exe", "foo", "bar", nullptr));
|
||||
EXPECT_EQ("foo.exe", _info.outputPath());
|
||||
EXPECT_EQ(2, inputFileCount());
|
||||
EXPECT_EQ("foo.obj", inputFile(0));
|
||||
EXPECT_EQ("bar.obj", inputFile(1));
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NonStandardFileExtension) {
|
||||
parse("link.exe", "foo.o", nullptr);
|
||||
EXPECT_EQ("foo.exe", info->outputPath());
|
||||
EXPECT_EQ(1, (int)inputFiles.size());
|
||||
EXPECT_EQ("foo.o", inputFiles[0]);
|
||||
EXPECT_FALSE(parse("link.exe", "foo.o", nullptr));
|
||||
EXPECT_EQ("foo.exe", _info.outputPath());
|
||||
EXPECT_EQ(1, inputFileCount());
|
||||
EXPECT_EQ("foo.o", inputFile(0));
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, MinMajorOSVersion) {
|
||||
parse("link.exe", "-subsystem", "windows,3", "foo.o", nullptr);
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, info->getSubsystem());
|
||||
EXPECT_EQ(3, info->getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(0, info->getMinOSVersion().minorVersion);
|
||||
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3", "foo.o", nullptr));
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
|
||||
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(0, _info.getMinOSVersion().minorVersion);
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, MinMajorMinorOSVersion) {
|
||||
parse("link.exe", "-subsystem", "windows,3.1", "foo.o", nullptr);
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, info->getSubsystem());
|
||||
EXPECT_EQ(3, info->getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(1, info->getMinOSVersion().minorVersion);
|
||||
EXPECT_FALSE(parse("link.exe", "-subsystem", "windows,3.1", "foo.o", nullptr));
|
||||
EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI, _info.getSubsystem());
|
||||
EXPECT_EQ(3, _info.getMinOSVersion().majorVersion);
|
||||
EXPECT_EQ(1, _info.getMinOSVersion().minorVersion);
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, StackReserve) {
|
||||
parse("link.exe", "-stack", "8192", nullptr);
|
||||
EXPECT_EQ(8192, info->getStackReserve());
|
||||
EXPECT_EQ(4096, info->getStackCommit());
|
||||
EXPECT_FALSE(parse("link.exe", "-stack", "8192", nullptr));
|
||||
EXPECT_EQ(8192ULL, _info.getStackReserve());
|
||||
EXPECT_EQ(4096ULL, _info.getStackCommit());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, StackReserveAndCommit) {
|
||||
parse("link.exe", "-stack", "16384,8192", nullptr);
|
||||
EXPECT_EQ(16384, info->getStackReserve());
|
||||
EXPECT_EQ(8192, info->getStackCommit());
|
||||
EXPECT_FALSE(parse("link.exe", "-stack", "16384,8192", nullptr));
|
||||
EXPECT_EQ(16384ULL, _info.getStackReserve());
|
||||
EXPECT_EQ(8192ULL, _info.getStackCommit());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, HeapReserve) {
|
||||
parse("link.exe", "-heap", "8192", nullptr);
|
||||
EXPECT_EQ(8192, info->getHeapReserve());
|
||||
EXPECT_EQ(4096, info->getHeapCommit());
|
||||
EXPECT_FALSE(parse("link.exe", "-heap", "8192", nullptr));
|
||||
EXPECT_EQ(8192ULL, _info.getHeapReserve());
|
||||
EXPECT_EQ(4096ULL, _info.getHeapCommit());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, HeapReserveAndCommit) {
|
||||
parse("link.exe", "-heap", "16384,8192", nullptr);
|
||||
EXPECT_EQ(16384, info->getHeapReserve());
|
||||
EXPECT_EQ(8192, info->getHeapCommit());
|
||||
EXPECT_FALSE(parse("link.exe", "-heap", "16384,8192", nullptr));
|
||||
EXPECT_EQ(16384ULL, _info.getHeapReserve());
|
||||
EXPECT_EQ(8192ULL, _info.getHeapCommit());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, Force) {
|
||||
parse("link.exe", "-force", nullptr);
|
||||
EXPECT_TRUE(info->allowRemainingUndefines());
|
||||
EXPECT_FALSE(parse("link.exe", "-force", nullptr));
|
||||
EXPECT_TRUE(_info.allowRemainingUndefines());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NoNxCompat) {
|
||||
parse("link.exe", "-nxcompat:no", nullptr);
|
||||
EXPECT_FALSE(info->getNxCompat());
|
||||
EXPECT_FALSE(parse("link.exe", "-nxcompat:no", nullptr));
|
||||
EXPECT_FALSE(_info.getNxCompat());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, LargeAddressAware) {
|
||||
parse("link.exe", "-largeaddressaware", nullptr);
|
||||
EXPECT_TRUE(info->getLargeAddressAware());
|
||||
EXPECT_TRUE(_info.getLargeAddressAware());
|
||||
}
|
||||
|
||||
TEST_F(WinLinkParserTest, NoLargeAddressAware) {
|
||||
parse("link.exe", "-largeaddressaware:no", nullptr);
|
||||
EXPECT_FALSE(info->getLargeAddressAware());
|
||||
EXPECT_FALSE(_info.getLargeAddressAware());
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
|
Loading…
Reference in New Issue