Skip to content

Commit

Permalink
build/test: Add -Dtest-slow-targets and move mips module tests behind…
Browse files Browse the repository at this point in the history
… it.

The idea is that these tests are just too slow to include by default on a
contributor's local machine. If they want to run these, they need to opt in.
  • Loading branch information
alexrp committed Aug 14, 2024
1 parent 3b51b43 commit b6009a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub fn build(b: *std.Build) !void {

const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match any filter") orelse &[0][]const u8{};
const test_target_filters = b.option([]const []const u8, "test-target-filter", "Skip tests whose target triple do not match any filter") orelse &[0][]const u8{};
const test_slow_targets = b.option(bool, "test-slow-targets", "Enable running module tests for targets that have a slow compiler backend") orelse false;

const test_cases_options = b.addOptions();

Expand Down Expand Up @@ -459,6 +460,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "test/behavior.zig",
.name = "behavior",
.desc = "Run the behavior tests",
Expand All @@ -473,6 +475,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "test/c_import.zig",
.name = "c-import",
.desc = "Run the @cImport tests",
Expand All @@ -486,6 +489,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "lib/compiler_rt.zig",
.name = "compiler-rt",
.desc = "Run the compiler_rt tests",
Expand All @@ -500,6 +504,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "lib/c.zig",
.name = "universal-libc",
.desc = "Run the universal libc tests",
Expand Down Expand Up @@ -527,6 +532,7 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(tests.addModuleTests(b, .{
.test_filters = test_filters,
.test_target_filters = test_target_filters,
.test_slow_targets = test_slow_targets,
.root_src = "lib/std/std.zig",
.name = "std",
.desc = "Run the standard library tests",
Expand Down
21 changes: 19 additions & 2 deletions test/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ const TestTarget = struct {
use_lld: ?bool = null,
pic: ?bool = null,
strip: ?bool = null,

// This is intended for targets that are known to be slow to compile. These are acceptable to
// run in CI, but should not be run on developer machines by default. As an example, at the time
// of writing, this includes LLVM's MIPS backend which takes upwards of 20 minutes longer to
// compile tests than other backends.
slow_backend: bool = false,
};

const test_targets = blk: {
Expand Down Expand Up @@ -310,6 +316,7 @@ const test_targets = blk: {
.os_tag = .linux,
.abi = .none,
},
.slow_backend = true,
},
.{
.target = .{
Expand All @@ -318,6 +325,7 @@ const test_targets = blk: {
.abi = .musl,
},
.link_libc = true,
.slow_backend = true,
},
.{
.target = .{
Expand All @@ -326,6 +334,7 @@ const test_targets = blk: {
.abi = .gnueabihf,
},
.link_libc = true,
.slow_backend = true,
},

.{
Expand All @@ -334,6 +343,7 @@ const test_targets = blk: {
.os_tag = .linux,
.abi = .none,
},
.slow_backend = true,
},
.{
.target = .{
Expand All @@ -342,6 +352,7 @@ const test_targets = blk: {
.abi = .musl,
},
.link_libc = true,
.slow_backend = true,
},
.{
.target = .{
Expand All @@ -350,6 +361,7 @@ const test_targets = blk: {
.abi = .gnueabihf,
},
.link_libc = true,
.slow_backend = true,
},

.{
Expand Down Expand Up @@ -401,7 +413,8 @@ const test_targets = blk: {
.link_libc = true,
},

// Disabled until LLVM fixes their O(N^2) codegen.
// Disabled until LLVM fixes their O(N^2) codegen. Note that this is so bad that we don't
// even want to include this in CI with `slow_backend`.
// https://github.com/ziglang/zig/issues/18872
//.{
// .target = .{
Expand All @@ -412,7 +425,8 @@ const test_targets = blk: {
// .use_llvm = true,
//},

// Disabled until LLVM fixes their O(N^2) codegen.
// Disabled until LLVM fixes their O(N^2) codegen. Note that this is so bad that we don't
// even want to include this in CI with `slow_backend`.
// https://github.com/ziglang/zig/issues/18872
//.{
// .target = .{
Expand Down Expand Up @@ -966,6 +980,7 @@ pub fn addRunTranslatedCTests(
const ModuleTestOptions = struct {
test_filters: []const []const u8,
test_target_filters: []const []const u8,
test_slow_targets: bool,
root_src: []const u8,
name: []const u8,
desc: []const u8,
Expand All @@ -982,6 +997,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
const step = b.step(b.fmt("test-{s}", .{options.name}), options.desc);

for (test_targets) |test_target| {
if (!options.test_slow_targets and test_target.slow_backend) continue;

if (options.skip_non_native and !test_target.target.isNative())
continue;

Expand Down

0 comments on commit b6009a7

Please sign in to comment.