forked from OSchip/llvm-project
[llvm][TextAPI/MachO] Extract common code into unittest helper (NFC)
This extract common code between the 4 TBD formats in a header that can be shared. Differential revision: https://reviews.llvm.org/D73332
This commit is contained in:
parent
c6e8bfe7c9
commit
5810ed5186
|
@ -0,0 +1,41 @@
|
|||
//===-- TextStubHelpers.cpp -------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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/TextAPI/MachO/InterfaceFile.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#ifndef TEXT_STUB_HELPERS_H
|
||||
#define TEXT_STUB_HELPERS_H
|
||||
|
||||
namespace llvm {
|
||||
struct ExportedSymbol {
|
||||
llvm::MachO::SymbolKind Kind;
|
||||
std::string Name;
|
||||
bool WeakDefined;
|
||||
bool ThreadLocalValue;
|
||||
};
|
||||
|
||||
using ExportedSymbolSeq = std::vector<ExportedSymbol>;
|
||||
using UUIDs = std::vector<std::pair<llvm::MachO::Target, std::string>>;
|
||||
|
||||
inline bool operator<(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
|
||||
return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
|
||||
}
|
||||
|
||||
inline bool operator==(const ExportedSymbol &LHS, const ExportedSymbol &RHS) {
|
||||
return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
|
||||
std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
|
||||
}
|
||||
|
||||
inline std::string stripWhitespace(std::string S) {
|
||||
S.erase(std::remove_if(S.begin(), S.end(), ::isspace), S.end());
|
||||
return S;
|
||||
}
|
||||
} // namespace llvm
|
||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||
//
|
||||
//===-----------------------------------------------------------------------===/
|
||||
|
||||
#include "TextStubHelpers.h"
|
||||
#include "llvm/TextAPI/MachO/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIReader.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
|
||||
|
@ -16,23 +17,6 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
|
||||
struct ExportedSymbol {
|
||||
SymbolKind Kind;
|
||||
std::string Name;
|
||||
bool WeakDefined;
|
||||
bool ThreadLocalValue;
|
||||
};
|
||||
using ExportedSymbolSeq = std::vector<ExportedSymbol>;
|
||||
|
||||
inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
|
||||
}
|
||||
|
||||
inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
|
||||
std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
|
||||
}
|
||||
|
||||
static ExportedSymbol TBDv1Symbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
|
||||
{SymbolKind::GlobalSymbol, "_sym1", false, false},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===-----------------------------------------------------------------------===/
|
||||
|
||||
#include "TextStubHelpers.h"
|
||||
#include "llvm/TextAPI/MachO/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIReader.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
|
||||
|
@ -16,23 +16,6 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
|
||||
struct ExportedSymbol {
|
||||
SymbolKind Kind;
|
||||
std::string Name;
|
||||
bool WeakDefined;
|
||||
bool ThreadLocalValue;
|
||||
};
|
||||
using ExportedSymbolSeq = std::vector<ExportedSymbol>;
|
||||
|
||||
inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
|
||||
}
|
||||
|
||||
inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
|
||||
std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
|
||||
}
|
||||
|
||||
static ExportedSymbol TBDv2Symbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
|
||||
{SymbolKind::GlobalSymbol, "_sym1", false, false},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===-----------------------------------------------------------------------===/
|
||||
|
||||
#include "TextStubHelpers.h"
|
||||
#include "llvm/TextAPI/MachO/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIReader.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
|
||||
|
@ -16,29 +16,6 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
|
||||
struct ExportedSymbol {
|
||||
SymbolKind Kind;
|
||||
std::string Name;
|
||||
bool WeakDefined;
|
||||
bool ThreadLocalValue;
|
||||
};
|
||||
using ExportedSymbolSeq = std::vector<ExportedSymbol>;
|
||||
using UUIDs = std::vector<std::pair<Target, std::string>>;
|
||||
|
||||
inline bool operator<(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name) < std::tie(rhs.Kind, rhs.Name);
|
||||
}
|
||||
|
||||
inline bool operator==(const ExportedSymbol &lhs, const ExportedSymbol &rhs) {
|
||||
return std::tie(lhs.Kind, lhs.Name, lhs.WeakDefined, lhs.ThreadLocalValue) ==
|
||||
std::tie(rhs.Kind, rhs.Name, rhs.WeakDefined, rhs.ThreadLocalValue);
|
||||
}
|
||||
|
||||
inline std::string stripWhitespace(std::string s) {
|
||||
s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
static ExportedSymbol TBDv3Symbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "$ld$hide$os9.0$_sym1", false, false},
|
||||
{SymbolKind::GlobalSymbol, "_sym1", false, false},
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===-----------------------------------------------------------------------===/
|
||||
|
||||
#include "TextStubHelpers.h"
|
||||
#include "llvm/TextAPI/MachO/InterfaceFile.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIReader.h"
|
||||
#include "llvm/TextAPI/MachO/TextAPIWriter.h"
|
||||
|
@ -15,40 +17,17 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::MachO;
|
||||
|
||||
struct ExampleSymbol {
|
||||
SymbolKind Kind;
|
||||
std::string Name;
|
||||
bool WeakDefined;
|
||||
bool ThreadLocalValue;
|
||||
};
|
||||
using ExampleSymbolSeq = std::vector<ExampleSymbol>;
|
||||
using UUIDs = std::vector<std::pair<Target, std::string>>;
|
||||
|
||||
inline bool operator<(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
|
||||
return std::tie(LHS.Kind, LHS.Name) < std::tie(RHS.Kind, RHS.Name);
|
||||
}
|
||||
|
||||
inline bool operator==(const ExampleSymbol &LHS, const ExampleSymbol &RHS) {
|
||||
return std::tie(LHS.Kind, LHS.Name, LHS.WeakDefined, LHS.ThreadLocalValue) ==
|
||||
std::tie(RHS.Kind, RHS.Name, RHS.WeakDefined, RHS.ThreadLocalValue);
|
||||
}
|
||||
|
||||
inline std::string stripWhitespace(std::string s) {
|
||||
s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
static ExampleSymbol TBDv4ExportedSymbols[] = {
|
||||
static ExportedSymbol TBDv4ExportedSymbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "_symA", false, false},
|
||||
{SymbolKind::GlobalSymbol, "_symAB", false, false},
|
||||
{SymbolKind::GlobalSymbol, "_symB", false, false},
|
||||
};
|
||||
|
||||
static ExampleSymbol TBDv4ReexportedSymbols[] = {
|
||||
static ExportedSymbol TBDv4ReexportedSymbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "_symC", false, false},
|
||||
};
|
||||
|
||||
static ExampleSymbol TBDv4UndefinedSymbols[] = {
|
||||
static ExportedSymbol TBDv4UndefinedSymbols[] = {
|
||||
{SymbolKind::GlobalSymbol, "_symD", false, false},
|
||||
};
|
||||
|
||||
|
@ -146,11 +125,11 @@ TEST(TBDv4, ReadFile) {
|
|||
EXPECT_EQ(1U, File->reexportedLibraries().size());
|
||||
EXPECT_EQ(reexport, File->reexportedLibraries().front());
|
||||
|
||||
ExampleSymbolSeq Exports, Reexports, Undefineds;
|
||||
ExampleSymbol temp;
|
||||
ExportedSymbolSeq Exports, Reexports, Undefineds;
|
||||
ExportedSymbol temp;
|
||||
for (const auto *Sym : File->symbols()) {
|
||||
temp = ExampleSymbol{Sym->getKind(), std::string(Sym->getName()),
|
||||
Sym->isWeakDefined(), Sym->isThreadLocalValue()};
|
||||
temp = ExportedSymbol{Sym->getKind(), std::string(Sym->getName()),
|
||||
Sym->isWeakDefined(), Sym->isThreadLocalValue()};
|
||||
EXPECT_FALSE(Sym->isWeakReferenced());
|
||||
if (Sym->isUndefined())
|
||||
Undefineds.emplace_back(std::move(temp));
|
||||
|
@ -162,11 +141,11 @@ TEST(TBDv4, ReadFile) {
|
|||
llvm::sort(Reexports.begin(), Reexports.end());
|
||||
llvm::sort(Undefineds.begin(), Undefineds.end());
|
||||
|
||||
EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExampleSymbol),
|
||||
EXPECT_EQ(sizeof(TBDv4ExportedSymbols) / sizeof(ExportedSymbol),
|
||||
Exports.size());
|
||||
EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExampleSymbol),
|
||||
EXPECT_EQ(sizeof(TBDv4ReexportedSymbols) / sizeof(ExportedSymbol),
|
||||
Reexports.size());
|
||||
EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExampleSymbol),
|
||||
EXPECT_EQ(sizeof(TBDv4UndefinedSymbols) / sizeof(ExportedSymbol),
|
||||
Undefineds.size());
|
||||
EXPECT_TRUE(std::equal(Exports.begin(), Exports.end(),
|
||||
std::begin(TBDv4ExportedSymbols)));
|
||||
|
|
Loading…
Reference in New Issue