mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-30 13:47:32 +00:00
[BOLT] Prepare BOLT for unit-testing
This patch adds unit testing support for BOLT. In order to do this we will need at least do this changes on the code level: * Make createMCPlusBuilder accessible externally * Remove positional InputFilename argument to bolt utlity sources And prepare the cmake and lit for the new tests. Vladislav Khmelevsky, Advanced Software Technology Lab, Huawei Reviewed By: maksfb, Amir Differential Revision: https://reviews.llvm.org/D118271
This commit is contained in:
parent
0606817d0b
commit
20e9d4caf0
@ -91,6 +91,10 @@ add_subdirectory(lib)
|
||||
add_subdirectory(tools)
|
||||
|
||||
if (BOLT_INCLUDE_TESTS)
|
||||
if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
|
||||
add_subdirectory(unittests)
|
||||
list(APPEND BOLT_TEST_DEPS BoltUnitTests)
|
||||
endif()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
|
@ -1898,6 +1898,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
|
||||
const MCInstrInfo *,
|
||||
const MCRegisterInfo *);
|
||||
|
||||
MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
|
||||
const MCInstrInfo *,
|
||||
const MCRegisterInfo *);
|
||||
|
||||
} // namespace bolt
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -545,6 +545,11 @@ private:
|
||||
friend class RewriteInstanceDiff;
|
||||
};
|
||||
|
||||
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
|
||||
const MCInstrAnalysis *Analysis,
|
||||
const MCInstrInfo *Info,
|
||||
const MCRegisterInfo *RegInfo);
|
||||
|
||||
} // namespace bolt
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -44,7 +44,6 @@ extern llvm::cl::opt<unsigned long long> HeatmapMinAddress;
|
||||
extern llvm::cl::opt<bool> HotData;
|
||||
extern llvm::cl::opt<bool> HotFunctionsAtEnd;
|
||||
extern llvm::cl::opt<bool> HotText;
|
||||
extern llvm::cl::opt<std::string> InputFilename;
|
||||
extern llvm::cl::opt<bool> Instrument;
|
||||
extern llvm::cl::opt<std::string> OutputFilename;
|
||||
extern llvm::cl::opt<std::string> PerfData;
|
||||
|
@ -319,27 +319,6 @@ namespace bolt {
|
||||
|
||||
extern const char *BoltRevision;
|
||||
|
||||
extern MCPlusBuilder *createX86MCPlusBuilder(const MCInstrAnalysis *,
|
||||
const MCInstrInfo *,
|
||||
const MCRegisterInfo *);
|
||||
extern MCPlusBuilder *createAArch64MCPlusBuilder(const MCInstrAnalysis *,
|
||||
const MCInstrInfo *,
|
||||
const MCRegisterInfo *);
|
||||
|
||||
} // namespace bolt
|
||||
} // namespace llvm
|
||||
|
||||
namespace {
|
||||
|
||||
bool refersToReorderedSection(ErrorOr<BinarySection &> Section) {
|
||||
auto Itr =
|
||||
std::find_if(opts::ReorderData.begin(), opts::ReorderData.end(),
|
||||
[&](const std::string &SectionName) {
|
||||
return (Section && Section->getName() == SectionName);
|
||||
});
|
||||
return Itr != opts::ReorderData.end();
|
||||
}
|
||||
|
||||
MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
|
||||
const MCInstrAnalysis *Analysis,
|
||||
const MCInstrInfo *Info,
|
||||
@ -357,6 +336,20 @@ MCPlusBuilder *createMCPlusBuilder(const Triple::ArchType Arch,
|
||||
llvm_unreachable("architecture unsupported by MCPlusBuilder");
|
||||
}
|
||||
|
||||
} // namespace bolt
|
||||
} // namespace llvm
|
||||
|
||||
namespace {
|
||||
|
||||
bool refersToReorderedSection(ErrorOr<BinarySection &> Section) {
|
||||
auto Itr =
|
||||
std::find_if(opts::ReorderData.begin(), opts::ReorderData.end(),
|
||||
[&](const std::string &SectionName) {
|
||||
return (Section && Section->getName() == SectionName);
|
||||
});
|
||||
return Itr != opts::ReorderData.end();
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
RewriteInstance::RewriteInstance(ELFObjectFileBase *File, const int Argc,
|
||||
|
@ -131,14 +131,6 @@ cl::opt<bool> HotText(
|
||||
"will put hot code into 2M pages. This requires relocation."),
|
||||
cl::ZeroOrMore, cl::cat(BoltCategory));
|
||||
|
||||
cl::opt<std::string>
|
||||
InputFilename(
|
||||
cl::Positional,
|
||||
cl::desc("<executable>"),
|
||||
cl::Required,
|
||||
cl::cat(BoltCategory),
|
||||
cl::sub(*cl::AllSubCommands));
|
||||
|
||||
cl::opt<bool>
|
||||
Instrument("instrument",
|
||||
cl::desc("instrument code to generate accurate profile data"),
|
||||
|
@ -8,6 +8,12 @@ configure_lit_site_cfg(
|
||||
MAIN_CONFIG
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
|
||||
)
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
|
||||
MAIN_CONFIG
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.cfg.py
|
||||
)
|
||||
|
||||
set(BOLT_TEST_PARAMS
|
||||
bolt_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
|
||||
|
17
bolt/test/Unit/CMakeLists.txt
Normal file
17
bolt/test/Unit/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
add_custom_target(bolt-unit-test-deps)
|
||||
add_dependencies(bolt-unit-test-deps bolt-test-depends)
|
||||
|
||||
add_lit_testsuites(BOLT-UNIT
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS bolt-unit-test-deps)
|
||||
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
|
||||
MAIN_CONFIG
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py)
|
||||
|
||||
add_lit_testsuite(check-bolt-unit "Running bolt unit test suite"
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
EXCLUDE_FROM_CHECK_ALL
|
||||
DEPENDS bolt-unit-test-deps)
|
22
bolt/test/Unit/lit.cfg.py
Normal file
22
bolt/test/Unit/lit.cfg.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- Python -*-
|
||||
|
||||
# Configuration file for the 'lit' test runner.
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
import lit.formats
|
||||
|
||||
# name: The name of this test suite.
|
||||
config.name = 'BOLT-Unit'
|
||||
|
||||
# suffixes: A list of file extensions to treat as test files.
|
||||
config.suffixes = []
|
||||
|
||||
# test_source_root: The root path where tests are located.
|
||||
# test_exec_root: The root path where tests should be run.
|
||||
config.test_exec_root = os.path.join(config.bolt_obj_root, 'unittests')
|
||||
config.test_source_root = config.test_exec_root
|
||||
|
||||
# testFormat: The test format to use to interpret tests.
|
||||
config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, 'Tests')
|
28
bolt/test/Unit/lit.site.cfg.py.in
Normal file
28
bolt/test/Unit/lit.site.cfg.py.in
Normal file
@ -0,0 +1,28 @@
|
||||
@LIT_SITE_CFG_IN_HEADER@
|
||||
|
||||
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
|
||||
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
|
||||
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
|
||||
config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
|
||||
config.llvm_build_mode = "@LLVM_BUILD_MODE@"
|
||||
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
|
||||
config.bolt_obj_root = "@BOLT_BINARY_DIR@"
|
||||
config.bolt_src_root = "@BOLT_SOURCE_DIR@"
|
||||
config.target_triple = "@TARGET_TRIPLE@"
|
||||
config.python_executable = "@Python3_EXECUTABLE@"
|
||||
|
||||
# Support substitution of the tools and libs dirs with user parameters. This is
|
||||
# used when we can't determine the tool dir at configuration time.
|
||||
try:
|
||||
config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
|
||||
config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
|
||||
config.llvm_build_mode = config.llvm_build_mode % lit_config.params
|
||||
except KeyError as e:
|
||||
key, = e.args
|
||||
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
|
||||
|
||||
import lit.llvm
|
||||
lit.llvm.initialize(lit_config, config)
|
||||
|
||||
# Let the main config do the real work.
|
||||
lit_config.load_config(config, "@BOLT_SOURCE_DIR@/test/Unit/lit.cfg.py")
|
@ -45,6 +45,11 @@ static cl::OptionCategory *BoltDiffCategories[] = {&BoltDiffCategory};
|
||||
static cl::OptionCategory *Perf2BoltCategories[] = {&AggregatorCategory,
|
||||
&BoltOutputCategory};
|
||||
|
||||
static cl::opt<std::string> InputFilename(cl::Positional,
|
||||
cl::desc("<executable>"),
|
||||
cl::Required, cl::cat(BoltCategory),
|
||||
cl::sub(*cl::AllSubCommands));
|
||||
|
||||
static cl::opt<std::string>
|
||||
InputDataFilename("data",
|
||||
cl::desc("<data file>"),
|
||||
|
6
bolt/unittests/CMakeLists.txt
Normal file
6
bolt/unittests/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
add_custom_target(BoltUnitTests)
|
||||
set_target_properties(BoltUnitTests PROPERTIES FOLDER "BOLT tests")
|
||||
|
||||
function(add_bolt_unittest test_dirname)
|
||||
add_unittest(BoltUnitTests ${test_dirname} ${ARGN})
|
||||
endfunction()
|
Loading…
x
Reference in New Issue
Block a user