Skip to content

Commit cc35384

Browse files
committed
tests: add support for dynamically skipping tests based on llvm version
Some tests are useful but are either broken on individual LLVM versions or before/after an LLVM version. Add new options to the test TOML that let us skip tests dynamically based on too old/too new/explicitly skipped LLVM major versions. Test plan: - CI - Used in stacked PRs
1 parent 8518fda commit cc35384

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

oi/OICompiler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,4 +738,8 @@ std::optional<OICompiler::RelocResult> OICompiler::applyRelocs(
738738
return res;
739739
}
740740

741+
int OICompiler::getLLVMVersionMajor() {
742+
return LLVM_VERSION_MAJOR;
743+
}
744+
741745
} // namespace oi::detail

oi/OICompiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class OICompiler {
183183
static std::optional<std::string> decodeInst(const std::vector<std::byte>&,
184184
uintptr_t);
185185

186+
/**
187+
* @return the major version of LLVM this was compiled with
188+
*/
189+
static int getLLVMVersionMajor();
190+
186191
private:
187192
std::shared_ptr<SymbolService> symbols;
188193
Config config;

test/integration/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ target_link_libraries(integration_test_runner PRIVATE
5959
Boost::headers
6060
${Boost_LIBRARIES}
6161
toml
62+
oicore
6263
)
6364
target_compile_definitions(integration_test_runner PRIVATE
6465
TARGET_EXE_PATH="${CMAKE_CURRENT_BINARY_DIR}/integration_test_target"

test/integration/gen_tests.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ def generate_skip(case, specific):
415415
possibly_skip = ""
416416
skip_reason = case.get("skip", False)
417417
specific_skip_reason = case.get(f"{specific}_skip", False)
418+
419+
# Handle LLVM version constraints
420+
min_llvm = case.get("min_llvm_version")
421+
max_llvm = case.get("max_llvm_version")
422+
skip_llvm = case.get("skip_llvm_version")
423+
424+
# Check if test should be skipped due to regular skip reasons
418425
if specific_skip_reason or skip_reason:
419426
possibly_skip += " if (!run_skipped_tests) {\n"
420427
possibly_skip += " GTEST_SKIP()"
@@ -425,6 +432,32 @@ def generate_skip(case, specific):
425432
possibly_skip += ";\n"
426433
possibly_skip += " }\n"
427434

435+
# Check LLVM version constraints
436+
if min_llvm is not None:
437+
possibly_skip += f" if (llvm_version_major < {min_llvm}) {{\n"
438+
possibly_skip += f' GTEST_SKIP() << "Requires LLVM {min_llvm} or newer, but running with LLVM " << llvm_version_major;\n'
439+
possibly_skip += " }\n"
440+
441+
if max_llvm is not None:
442+
possibly_skip += f" if (llvm_version_major > {max_llvm}) {{\n"
443+
possibly_skip += f' GTEST_SKIP() << "Requires LLVM {max_llvm} or older, but running with LLVM " << llvm_version_major;\n'
444+
possibly_skip += " }\n"
445+
446+
if skip_llvm is not None:
447+
if isinstance(skip_llvm, list):
448+
for version in skip_llvm:
449+
possibly_skip += f" if (llvm_version_major == {version}) {{\n"
450+
possibly_skip += (
451+
f' GTEST_SKIP() << "Test skipped for LLVM {version}";\n'
452+
)
453+
possibly_skip += " }\n"
454+
else:
455+
possibly_skip += f" if (llvm_version_major == {skip_llvm}) {{\n"
456+
possibly_skip += (
457+
f' GTEST_SKIP() << "Test skipped for LLVM {skip_llvm}";\n'
458+
)
459+
possibly_skip += " }\n"
460+
428461
return possibly_skip
429462

430463

@@ -448,6 +481,7 @@ def gen_runner(output_runner_name, test_configs):
448481
"using ::testing::MatchesRegex;\n"
449482
"\n"
450483
"extern bool run_skipped_tests;\n"
484+
"extern int llvm_version_major;\n"
451485
)
452486
for config in test_configs:
453487
add_tests(f, config)

test/integration/runner_common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <utility>
1414

15+
#include "oi/OICompiler.h"
1516
#include "oi/OIOpts.h"
1617
#include "oi/support/Toml.h"
1718

@@ -22,6 +23,7 @@ namespace bpt = boost::property_tree;
2223
namespace fs = std::filesystem;
2324

2425
bool run_skipped_tests = false;
26+
int llvm_version_major = oi::detail::OICompiler::getLLVMVersionMajor();
2527

2628
namespace {
2729

0 commit comments

Comments
 (0)