| author | |
| committer | |
| log | 33b8fdb6bc68fc6eb2c401070d062d153d780a6e |
| tree | 2ec8ea9315b8a3d4303b9915527caa9f220ec666 |
| parent | c3ecc6972ea25707f93fc84f98a262efbff66904 |
5 files changed, 182 insertions(+), 120 deletions(-)
test/standalone.zig deleted-69| ... | @@ -1,69 +0,0 @@ | ||
| 1 | pub const SimpleCase = struct { | ||
| 2 | src_path: []const u8, | ||
| 3 | link_libc: bool = false, | ||
| 4 | all_modes: bool = false, | ||
| 5 | target: std.Target.Query = .{}, | ||
| 6 | is_test: bool = false, | ||
| 7 | is_exe: bool = true, | ||
| 8 | /// Run only on this OS. | ||
| 9 | os_filter: ?std.Target.Os.Tag = null, | ||
| 10 | }; | ||
| 11 | |||
| 12 | pub const simple_cases = [_]SimpleCase{ | ||
| 13 | .{ | ||
| 14 | .src_path = "test/standalone/simple/hello_world/hello.zig", | ||
| 15 | .all_modes = true, | ||
| 16 | }, | ||
| 17 | .{ | ||
| 18 | .src_path = "test/standalone/simple/hello_world/hello_libc.zig", | ||
| 19 | .link_libc = true, | ||
| 20 | .all_modes = true, | ||
| 21 | }, | ||
| 22 | .{ | ||
| 23 | .src_path = "test/standalone/simple/cat/main.zig", | ||
| 24 | }, | ||
| 25 | // https://github.com/ziglang/zig/issues/6025 | ||
| 26 | //.{ | ||
| 27 | // .src_path = "test/standalone/simple/issue_9693/main.zig", | ||
| 28 | //}, | ||
| 29 | .{ | ||
| 30 | .src_path = "test/standalone/simple/brace_expansion.zig", | ||
| 31 | .is_test = true, | ||
| 32 | }, | ||
| 33 | .{ | ||
| 34 | .src_path = "test/standalone/simple/issue_7030.zig", | ||
| 35 | .target = .{ | ||
| 36 | .cpu_arch = .wasm32, | ||
| 37 | .os_tag = .freestanding, | ||
| 38 | }, | ||
| 39 | }, | ||
| 40 | |||
| 41 | .{ .src_path = "test/standalone/simple/issue_12471/main.zig" }, | ||
| 42 | .{ .src_path = "test/standalone/simple/guess_number/main.zig" }, | ||
| 43 | .{ .src_path = "test/standalone/simple/main_return_error/error_u8.zig" }, | ||
| 44 | .{ .src_path = "test/standalone/simple/main_return_error/error_u8_non_zero.zig" }, | ||
| 45 | .{ .src_path = "test/standalone/simple/noreturn_call/inline.zig" }, | ||
| 46 | .{ .src_path = "test/standalone/simple/noreturn_call/as_arg.zig" }, | ||
| 47 | .{ .src_path = "test/standalone/simple/std_enums_big_enums.zig" }, | ||
| 48 | |||
| 49 | .{ | ||
| 50 | .src_path = "test/standalone/simple/issue_9402/main.zig", | ||
| 51 | .os_filter = .windows, | ||
| 52 | .link_libc = true, | ||
| 53 | }, | ||
| 54 | |||
| 55 | // Ensure the development tools are buildable. Alphabetically sorted. | ||
| 56 | // No need to build `tools/spirv/grammar.zig`. | ||
| 57 | .{ .src_path = "tools/gen_outline_atomics.zig" }, | ||
| 58 | .{ .src_path = "tools/gen_spirv_spec.zig" }, | ||
| 59 | .{ .src_path = "tools/gen_stubs.zig" }, | ||
| 60 | .{ .src_path = "tools/generate_linux_syscalls.zig" }, | ||
| 61 | .{ .src_path = "tools/process_headers.zig" }, | ||
| 62 | .{ .src_path = "tools/update-linux-headers.zig" }, | ||
| 63 | .{ .src_path = "tools/update_clang_options.zig" }, | ||
| 64 | .{ .src_path = "tools/update_cpu_features.zig" }, | ||
| 65 | .{ .src_path = "tools/update_glibc.zig" }, | ||
| 66 | .{ .src_path = "tools/update_spirv_features.zig" }, | ||
| 67 | }; | ||
| 68 | |||
| 69 | const std = @import("std"); | ||
test/standalone/build.zig+49-6| ... | @@ -5,23 +5,66 @@ pub fn build(b: *std.Build) void { | ... | @@ -5,23 +5,66 @@ pub fn build(b: *std.Build) void { |
| 5 | const step = b.step("test", "Run standalone test cases"); | 5 | const step = b.step("test", "Run standalone test cases"); |
| 6 | b.default_step = step; | 6 | b.default_step = step; |
| 7 | 7 | ||
| 8 | const enable_ios_sdk = b.option(bool, "enable-ios-sdk", "Run tests requiring presence of iOS SDK and frameworks") orelse false; | 8 | const enable_ios_sdk = b.option(bool, "enable_ios_sdk", "Run tests requiring presence of iOS SDK and frameworks") orelse false; |
| 9 | const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk; | 9 | const enable_macos_sdk = b.option(bool, "enable_macos_sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk; |
| 10 | const enable_symlinks_windows = b.option(bool, "enable-symlinks-windows", "Run tests requiring presence of symlinks on Windows") orelse false; | 10 | const enable_symlinks_windows = b.option(bool, "enable_symlinks_windows", "Run tests requiring presence of symlinks on Windows") orelse false; |
| 11 | |||
| 12 | const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows; | 11 | const omit_symlinks = builtin.os.tag == .windows and !enable_symlinks_windows; |
| 13 | 12 | ||
| 13 | const simple_skip_debug = b.option(bool, "simple_skip_debug", "Simple tests skip debug builds") orelse false; | ||
| 14 | const simple_skip_release_safe = b.option(bool, "simple_skip_release_safe", "Simple tests skip release-safe builds") orelse false; | ||
| 15 | const simple_skip_release_fast = b.option(bool, "simple_skip_release_fast", "Simple tests skip release-fast builds") orelse false; | ||
| 16 | const simple_skip_release_small = b.option(bool, "simple_skip_release_small", "Simple tests skip release-small builds") orelse false; | ||
| 17 | |||
| 18 | const simple_dep = b.dependency("simple", .{ | ||
| 19 | .skip_debug = simple_skip_debug, | ||
| 20 | .skip_release_safe = simple_skip_release_safe, | ||
| 21 | .skip_release_fast = simple_skip_release_fast, | ||
| 22 | .skip_release_small = simple_skip_release_small, | ||
| 23 | }); | ||
| 24 | const simple_dep_step = simple_dep.builder.default_step; | ||
| 25 | simple_dep_step.name = "standalone_test_cases.simple"; | ||
| 26 | step.dependOn(simple_dep_step); | ||
| 27 | |||
| 28 | // Ensure the development tools are buildable. | ||
| 29 | const tools_tests_step = b.step("standalone_test_cases.tools", "Test tools"); | ||
| 30 | step.dependOn(tools_tests_step); | ||
| 31 | const tools_target = b.resolveTargetQuery(.{}); | ||
| 32 | for ([_][]const u8{ | ||
| 33 | // Alphabetically sorted. No need to build `tools/spirv/grammar.zig`. | ||
| 34 | "../../tools/gen_outline_atomics.zig", | ||
| 35 | "../../tools/gen_spirv_spec.zig", | ||
| 36 | "../../tools/gen_stubs.zig", | ||
| 37 | "../../tools/generate_linux_syscalls.zig", | ||
| 38 | "../../tools/process_headers.zig", | ||
| 39 | "../../tools/update-linux-headers.zig", | ||
| 40 | "../../tools/update_clang_options.zig", | ||
| 41 | "../../tools/update_cpu_features.zig", | ||
| 42 | "../../tools/update_glibc.zig", | ||
| 43 | "../../tools/update_spirv_features.zig", | ||
| 44 | }) |tool_src_path| { | ||
| 45 | const tool = b.addTest(.{ | ||
| 46 | .name = std.fs.path.stem(tool_src_path), | ||
| 47 | .root_source_file = .{ .path = tool_src_path }, | ||
| 48 | .optimize = .Debug, | ||
| 49 | .target = tools_target, | ||
| 50 | }); | ||
| 51 | const run = b.addRunArtifact(tool); | ||
| 52 | tools_tests_step.dependOn(&run.step); | ||
| 53 | } | ||
| 54 | |||
| 14 | add_dep_steps: for (b.available_deps) |available_dep| { | 55 | add_dep_steps: for (b.available_deps) |available_dep| { |
| 15 | const dep_name, const dep_hash = available_dep; | 56 | const dep_name, const dep_hash = available_dep; |
| 16 | 57 | ||
| 58 | // The 'simple' dependency was already handled manually above. | ||
| 59 | if (std.mem.eql(u8, dep_name, "simple")) continue; | ||
| 60 | |||
| 17 | const all_pkgs = @import("root").dependencies.packages; | 61 | const all_pkgs = @import("root").dependencies.packages; |
| 18 | inline for (@typeInfo(all_pkgs).Struct.decls) |decl| { | 62 | inline for (@typeInfo(all_pkgs).Struct.decls) |decl| { |
| 19 | const pkg_hash = decl.name; | 63 | const pkg_hash = decl.name; |
| 20 | if (std.mem.eql(u8, dep_hash, pkg_hash)) { | 64 | if (std.mem.eql(u8, dep_hash, pkg_hash)) { |
| 21 | const pkg = @field(all_pkgs, pkg_hash); | 65 | const pkg = @field(all_pkgs, pkg_hash); |
| 22 | if (!@hasDecl(pkg, "build_zig")) { | 66 | if (!@hasDecl(pkg, "build_zig")) { |
| 23 | std.debug.print("standalone test case '{s}' is missing a 'build.zig' file\n", .{dep_name}); | 67 | std.debug.panic("standalone test case '{s}' is missing a 'build.zig' file", .{dep_name}); |
| 24 | std.process.exit(1); | ||
| 25 | } | 68 | } |
| 26 | const requires_ios_sdk = @hasDecl(pkg.build_zig, "requires_ios_sdk") and | 69 | const requires_ios_sdk = @hasDecl(pkg.build_zig, "requires_ios_sdk") and |
| 27 | pkg.build_zig.requires_ios_sdk; | 70 | pkg.build_zig.requires_ios_sdk; |
test/standalone/build.zig.zon+3-3| ... | @@ -2,9 +2,9 @@ | ... | @@ -2,9 +2,9 @@ |
| 2 | .name = "standalone_test_cases", | 2 | .name = "standalone_test_cases", |
| 3 | .version = "0.0.0", | 3 | .version = "0.0.0", |
| 4 | .dependencies = .{ | 4 | .dependencies = .{ |
| 5 | // "Simple" test cases (those in the 'simple' directory) are configured by the root build | 5 | .simple = .{ |
| 6 | // script, outside of this package. | 6 | .path = "simple", |
| 7 | 7 | }, | |
| 8 | .test_runner_path = .{ | 8 | .test_runner_path = .{ |
| 9 | .path = "test_runner_path", | 9 | .path = "test_runner_path", |
| 10 | }, | 10 | }, |
test/standalone/simple/build.zig created+123| ... | @@ -0,0 +1,123 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | |||
| 4 | pub fn build(b: *std.Build) void { | ||
| 5 | const step = b.step("test", "Run simple standalone test cases"); | ||
| 6 | b.default_step = step; | ||
| 7 | |||
| 8 | const skip_debug = b.option(bool, "skip_debug", "Skip debug builds") orelse false; | ||
| 9 | const skip_release_safe = b.option(bool, "skip_release_safe", "Skip release-safe builds") orelse false; | ||
| 10 | const skip_release_fast = b.option(bool, "skip_release_fast", "Skip release-fast builds") orelse false; | ||
| 11 | const skip_release_small = b.option(bool, "skip_release_small", "Skip release-small builds") orelse false; | ||
| 12 | |||
| 13 | var optimize_modes_buf: [4]std.builtin.OptimizeMode = undefined; | ||
| 14 | var optimize_modes_len: usize = 0; | ||
| 15 | if (!skip_debug) { | ||
| 16 | optimize_modes_buf[optimize_modes_len] = .Debug; | ||
| 17 | optimize_modes_len += 1; | ||
| 18 | } | ||
| 19 | if (!skip_release_safe) { | ||
| 20 | optimize_modes_buf[optimize_modes_len] = .ReleaseSafe; | ||
| 21 | optimize_modes_len += 1; | ||
| 22 | } | ||
| 23 | if (!skip_release_fast) { | ||
| 24 | optimize_modes_buf[optimize_modes_len] = .ReleaseFast; | ||
| 25 | optimize_modes_len += 1; | ||
| 26 | } | ||
| 27 | if (!skip_release_small) { | ||
| 28 | optimize_modes_buf[optimize_modes_len] = .ReleaseSmall; | ||
| 29 | optimize_modes_len += 1; | ||
| 30 | } | ||
| 31 | const optimize_modes = optimize_modes_buf[0..optimize_modes_len]; | ||
| 32 | |||
| 33 | for (cases) |case| { | ||
| 34 | for (optimize_modes) |optimize| { | ||
| 35 | if (!case.all_modes and optimize != .Debug) continue; | ||
| 36 | if (case.os_filter) |os_tag| { | ||
| 37 | if (os_tag != builtin.os.tag) continue; | ||
| 38 | } | ||
| 39 | |||
| 40 | const resolved_target = b.resolveTargetQuery(case.target); | ||
| 41 | |||
| 42 | if (case.is_exe) { | ||
| 43 | const exe = b.addExecutable(.{ | ||
| 44 | .name = std.fs.path.stem(case.src_path), | ||
| 45 | .root_source_file = .{ .path = case.src_path }, | ||
| 46 | .optimize = optimize, | ||
| 47 | .target = resolved_target, | ||
| 48 | }); | ||
| 49 | if (case.link_libc) exe.linkLibC(); | ||
| 50 | |||
| 51 | _ = exe.getEmittedBin(); | ||
| 52 | |||
| 53 | step.dependOn(&exe.step); | ||
| 54 | } | ||
| 55 | |||
| 56 | if (case.is_test) { | ||
| 57 | const exe = b.addTest(.{ | ||
| 58 | .name = std.fs.path.stem(case.src_path), | ||
| 59 | .root_source_file = .{ .path = case.src_path }, | ||
| 60 | .optimize = optimize, | ||
| 61 | .target = resolved_target, | ||
| 62 | }); | ||
| 63 | if (case.link_libc) exe.linkLibC(); | ||
| 64 | |||
| 65 | const run = b.addRunArtifact(exe); | ||
| 66 | step.dependOn(&run.step); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | const Case = struct { | ||
| 73 | src_path: []const u8, | ||
| 74 | link_libc: bool = false, | ||
| 75 | all_modes: bool = false, | ||
| 76 | target: std.Target.Query = .{}, | ||
| 77 | is_test: bool = false, | ||
| 78 | is_exe: bool = true, | ||
| 79 | /// Run only on this OS. | ||
| 80 | os_filter: ?std.Target.Os.Tag = null, | ||
| 81 | }; | ||
| 82 | |||
| 83 | const cases = [_]Case{ | ||
| 84 | .{ | ||
| 85 | .src_path = "hello_world/hello.zig", | ||
| 86 | .all_modes = true, | ||
| 87 | }, | ||
| 88 | .{ | ||
| 89 | .src_path = "hello_world/hello_libc.zig", | ||
| 90 | .link_libc = true, | ||
| 91 | .all_modes = true, | ||
| 92 | }, | ||
| 93 | .{ | ||
| 94 | .src_path = "cat/main.zig", | ||
| 95 | }, | ||
| 96 | // https://github.com/ziglang/zig/issues/6025 | ||
| 97 | //.{ | ||
| 98 | // .src_path = "issue_9693/main.zig", | ||
| 99 | //}, | ||
| 100 | .{ | ||
| 101 | .src_path = "brace_expansion.zig", | ||
| 102 | .is_test = true, | ||
| 103 | }, | ||
| 104 | .{ | ||
| 105 | .src_path = "issue_7030.zig", | ||
| 106 | .target = .{ | ||
| 107 | .cpu_arch = .wasm32, | ||
| 108 | .os_tag = .freestanding, | ||
| 109 | }, | ||
| 110 | }, | ||
| 111 | .{ .src_path = "issue_12471/main.zig" }, | ||
| 112 | .{ .src_path = "guess_number/main.zig" }, | ||
| 113 | .{ .src_path = "main_return_error/error_u8.zig" }, | ||
| 114 | .{ .src_path = "main_return_error/error_u8_non_zero.zig" }, | ||
| 115 | .{ .src_path = "noreturn_call/inline.zig" }, | ||
| 116 | .{ .src_path = "noreturn_call/as_arg.zig" }, | ||
| 117 | .{ .src_path = "std_enums_big_enums.zig" }, | ||
| 118 | .{ | ||
| 119 | .src_path = "issue_9402/main.zig", | ||
| 120 | .os_filter = .windows, | ||
| 121 | .link_libc = true, | ||
| 122 | }, | ||
| 123 | }; | ||
test/tests.zig+7-42| ... | @@ -7,7 +7,6 @@ const Step = std.Build.Step; | ... | @@ -7,7 +7,6 @@ const Step = std.Build.Step; |
| 7 | 7 | ||
| 8 | // Cases | 8 | // Cases |
| 9 | const compare_output = @import("compare_output.zig"); | 9 | const compare_output = @import("compare_output.zig"); |
| 10 | const standalone = @import("standalone.zig"); | ||
| 11 | const stack_traces = @import("stack_traces.zig"); | 10 | const stack_traces = @import("stack_traces.zig"); |
| 12 | const assemble_and_link = @import("assemble_and_link.zig"); | 11 | const assemble_and_link = @import("assemble_and_link.zig"); |
| 13 | const translate_c = @import("translate_c.zig"); | 12 | const translate_c = @import("translate_c.zig"); |
| ... | @@ -672,44 +671,6 @@ pub fn addStandaloneTests( | ... | @@ -672,44 +671,6 @@ pub fn addStandaloneTests( |
| 672 | ) *Step { | 671 | ) *Step { |
| 673 | const step = b.step("test-standalone", "Run the standalone tests"); | 672 | const step = b.step("test-standalone", "Run the standalone tests"); |
| 674 | 673 | ||
| 675 | for (standalone.simple_cases) |case| { | ||
| 676 | for (optimize_modes) |optimize| { | ||
| 677 | if (!case.all_modes and optimize != .Debug) continue; | ||
| 678 | if (case.os_filter) |os_tag| { | ||
| 679 | if (os_tag != builtin.os.tag) continue; | ||
| 680 | } | ||
| 681 | |||
| 682 | const resolved_target = b.resolveTargetQuery(case.target); | ||
| 683 | |||
| 684 | if (case.is_exe) { | ||
| 685 | const exe = b.addExecutable(.{ | ||
| 686 | .name = std.fs.path.stem(case.src_path), | ||
| 687 | .root_source_file = .{ .path = case.src_path }, | ||
| 688 | .optimize = optimize, | ||
| 689 | .target = resolved_target, | ||
| 690 | }); | ||
| 691 | if (case.link_libc) exe.linkLibC(); | ||
| 692 | |||
| 693 | _ = exe.getEmittedBin(); | ||
| 694 | |||
| 695 | step.dependOn(&exe.step); | ||
| 696 | } | ||
| 697 | |||
| 698 | if (case.is_test) { | ||
| 699 | const exe = b.addTest(.{ | ||
| 700 | .name = std.fs.path.stem(case.src_path), | ||
| 701 | .root_source_file = .{ .path = case.src_path }, | ||
| 702 | .optimize = optimize, | ||
| 703 | .target = resolved_target, | ||
| 704 | }); | ||
| 705 | if (case.link_libc) exe.linkLibC(); | ||
| 706 | |||
| 707 | const run = b.addRunArtifact(exe); | ||
| 708 | step.dependOn(&run.step); | ||
| 709 | } | ||
| 710 | } | ||
| 711 | } | ||
| 712 | |||
| 713 | // We can only use dependencies if the compiler was built with support for package management. | 674 | // We can only use dependencies if the compiler was built with support for package management. |
| 714 | // (zig2 doesn't support it, but we still need to construct a build graph to build stage3.) | 675 | // (zig2 doesn't support it, but we still need to construct a build graph to build stage3.) |
| 715 | const package_management_available = b.available_deps.len != 0; | 676 | const package_management_available = b.available_deps.len != 0; |
| ... | @@ -717,9 +678,13 @@ pub fn addStandaloneTests( | ... | @@ -717,9 +678,13 @@ pub fn addStandaloneTests( |
| 717 | if (package_management_available) { | 678 | if (package_management_available) { |
| 718 | const test_cases_dep_name = "standalone_test_cases"; | 679 | const test_cases_dep_name = "standalone_test_cases"; |
| 719 | const test_cases_dep = b.dependency(test_cases_dep_name, .{ | 680 | const test_cases_dep = b.dependency(test_cases_dep_name, .{ |
| 720 | .@"enable-ios-sdk" = enable_ios_sdk, | 681 | .enable_ios_sdk = enable_ios_sdk, |
| 721 | .@"enable-macos-sdk" = enable_macos_sdk, | 682 | .enable_macos_sdk = enable_macos_sdk, |
| 722 | .@"enable-symlinks-windows" = enable_symlinks_windows, | 683 | .enable_symlinks_windows = enable_symlinks_windows, |
| 684 | .simple_skip_debug = mem.indexOfScalar(OptimizeMode, optimize_modes, .Debug) == null, | ||
| 685 | .simple_skip_release_safe = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSafe) == null, | ||
| 686 | .simple_skip_release_fast = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseFast) == null, | ||
| 687 | .simple_skip_release_small = mem.indexOfScalar(OptimizeMode, optimize_modes, .ReleaseSmall) == null, | ||
| 723 | }); | 688 | }); |
| 724 | const test_cases_dep_step = test_cases_dep.builder.default_step; | 689 | const test_cases_dep_step = test_cases_dep.builder.default_step; |
| 725 | test_cases_dep_step.name = b.dupe(test_cases_dep_name); | 690 | test_cases_dep_step.name = b.dupe(test_cases_dep_name); |