╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ tests.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3222 if (target.cpu.arch.isPowerPC()) { 3223 test_step.root_module.stack_protector = false; 3224 } 3225 3226 // This test is intentionally trying to check if the external ABI is 3227 // done properly. LTO would be a hindrance to this. 3228 test_step.lto = .none; 3229 3230 const run = b.addRunArtifact(test_step); 3231 run.skip_foreign_checks = true; 3232 step.dependOn(&run.step); 3233 } 3234 } 3235 return step; 3236 } 3237 3238 const LinkTestOptions = struct { 3239 test_target_filters: []const []const u8, 3240 test_filters: []const []const u8, 3241 optimize_modes: []const OptimizeMode, 3242 skip_non_native: bool, 3243 skip_freebsd: bool, 3244 skip_netbsd: bool, 3245 skip_openbsd: bool, 3246 skip_windows: bool, 3247 skip_darwin: bool, 3248 skip_linux: bool, 3249 skip_llvm: bool, 3250 skip_libc: bool, 3251 max_rss: usize, 3252 }; 3253 3254 pub fn addLinkTests(b: *std.Build, options: LinkTestOptions) *Step { 3255 const step = b.step("test-link", "Run the linker tests"); 3256 const update_snapshots = b.option( 3257 bool, 3258 "link-snapshot-update", 3259 "Update linker test snapshots in-place instead of testing against them", 3260 ) orelse false; 3261 3262 for (link_targets) |link_target| { 3263 const resolved_target = b.resolveTargetQuery(link_target.target); 3264 3265 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) 3266 continue; 3267 3268 const target = &resolved_target.result; 3269 3270 if (options.skip_freebsd and target.os.tag == .freebsd) continue; 3271 if (options.skip_netbsd and target.os.tag == .netbsd) continue; 3272 if (options.skip_openbsd and target.os.tag == .openbsd) continue; 3273 if (options.skip_windows and target.os.tag == .windows) continue; 3274 if (options.skip_darwin and target.os.tag.isDarwin()) continue; 3275 if (options.skip_linux and target.os.tag == .linux) continue; 3276 3277 const triple_txt = resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"); 3278 3279 if (options.test_target_filters.len > 0) { 3280 for (options.test_target_filters) |filter| { 3281 if (std.mem.find(u8, triple_txt, filter) != null) break; 3282 } else continue; 3283 } 3284 3285 if (options.skip_libc and (link_target.link_libc == true or std.os.targetRequiresLibC(target))) 3286 continue; 3287 3288 // We can't provide MSVC libc when cross-compiling. 3289 if (target.abi == .msvc and link_target.link_libc == true and builtin.os.tag != .windows) 3290 continue; 3291 3292 for (options.optimize_modes) |optimize_mode| { 3293 if (link_target.optimize_mode != optimize_mode) continue; 3294 const would_use_llvm = wouldUseLlvm(link_target.use_llvm, link_target.target, optimize_mode); 3295 if (options.skip_llvm and would_use_llvm) continue; 3296 3297 const opt_update_step = if (update_snapshots) update: { 3298 const update_step = Step.UpdateSourceFiles.create(b); 3299 step.dependOn(&update_step.step); 3300 break :update update_step; 3301 } else null; 3302 3303 var context: LinkContext = .{ 3304 .b = b, 3305 .step = step, 3306 .optimize = optimize_mode, 3307 .target = resolved_target, 3308 .target_desc = std.fmt.allocPrint(b.allocator, "{s}-{t}{s}{s}{s}", .{ 3309 target.zigTriple(b.allocator) catch @panic("OOM"), 3310 optimize_mode, 3311 if (link_target.use_llvm) "-llvm" else "", 3312 if (link_target.use_lld) "-lld" else "", 3313 if (link_target.link_libc) "-libc" else "", 3314 }) catch @panic("OOM"), 3315 .use_llvm = link_target.use_llvm, 3316 .use_lld = link_target.use_lld, 3317 .link_libc = link_target.link_libc, 3318 .test_filters = options.test_filters, 3319 .update_step = opt_update_step, 3320 .updated_snapshots = .empty, 3321 .max_rss = options.max_rss, 3322 }; 3323 3324 link.addCases(&context); 3325 } 3326 } 3327 return step; 3328 } 3329 3330 pub fn addCases( 3331 b: *std.Build, 3332 parent_step: *Step, 3333 case_test_options: @import("src/Cases.zig").CaseTestOptions, 3334 build_options: @import("cases.zig").BuildOptions, 3335 ) !void { 3336 const arena = b.allocator; 3337 const gpa = b.allocator; 3338 const io = b.graph.io; 3339 3340 var cases = @import("src/Cases.zig").init(gpa, arena, io); 3341 3342 b.dependOnDirectoryContents(b.path("test/cases")); 3343 3344 var dir = try b.root.openDir(io, "test/cases", .{ .iterate = true }); 3345 defer dir.close(io); 3346 3347 cases.addFromDir(dir, "test/cases", b); 3348 try @import("cases.zig").addCases(&cases, build_options, b); 3349 3350 cases.lowerToBuildSteps( 3351 b, 3352 parent_step, 3353 case_test_options, 3354 ); 3355 } 3356 3357 pub fn addDebuggerTests(b: *std.Build, options: DebuggerContext.Options) ?*Step { 3358 const step = b.step("test-debugger", "Run the debugger tests"); 3359 if (options.gdb == null and options.lldb == null) { 3360 step.dependOn(&b.addFail("test-debugger requires -Dgdb and/or -Dlldb").step); 3361 return null; 3362 } 3363 3364 var context: DebuggerContext = .{ 3365 .b = b, 3366 .options = options, 3367 .root_step = step, 3368 .test_matrix = debugger_matrix, 3369 }; 3370 context.addTests(); 3371 return step; 3372 } 3373 3374 const IncrementalTestOptions = struct { 3375 test_filters: []const []const u8, 3376 test_target_filters: []const []const u8, 3377 skip_non_native: bool, 3378 skip_wasm: bool, 3379 skip_freebsd: bool, 3380 skip_netbsd: bool, 3381 skip_openbsd: bool, 3382 skip_windows: bool, 3383 skip_darwin: bool, 3384 skip_linux: bool, 3385 skip_llvm: bool, 3386 }; 3387 3388 pub fn addIncrementalTests( 3389 b: *std.Build, 3390 test_step: *Step, 3391 options: IncrementalTestOptions, 3392 ) !void { 3393 const io = b.graph.io; 3394 3395 const incr_check = b.addExecutable(.{ 3396 .name = "incr-check", 3397 .root_module = b.createModule(.{ 3398 .root_source_file = b.path("tools/incr-check.zig"), 3399 .target = b.graph.host, 3400 .optimize = .debug, 3401 }), 3402 }); 3403 3404 b.dependOnDirectoryContents(b.path("test/incremental")); 3405 3406 var dir = try b.root.openDir(io, "test/incremental", .{ .iterate = true }); 3407 defer dir.close(io); 3408 3409 var it = try dir.walk(b.graph.arena); 3410 while (try it.next(io)) |entry| { 3411 if (std.mem.endsWith(u8, entry.basename, ".swp")) continue; 3412 3413 for (options.test_filters) |test_filter| { 3414 if (std.mem.find(u8, entry.path, test_filter)) |_| break; 3415 } else if (options.test_filters.len > 0) continue; 3416 3417 switch (entry.kind) { 3418 .file => {}, 3419 .directory => { 3420 b.dependOnDirectoryContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path }))); 3421 }, 3422 else => continue, 3423 } 3424 b.dependOnFileContents(b.path(b.pathJoin(&.{ "test", "incremental", entry.path }))); 3425 3426 for (incremental_targets) |test_target| { 3427 const resolved_target = b.resolveTargetQuery(test_target.target); 3428 3429 if (options.skip_non_native and !isNative(&resolved_target, &b.graph.host.result)) 3430 continue; 3431 3432 const target = &resolved_target.result; 3433 3434 if (options.skip_wasm and target.cpu.arch.isWasm()) continue; 3435 3436 if (options.skip_freebsd and target.os.tag == .freebsd) continue; 3437 if (options.skip_netbsd and target.os.tag == .netbsd) continue; 3438 if (options.skip_openbsd and target.os.tag == .openbsd) continue; 3439 if (options.skip_windows and target.os.tag == .windows) continue; 3440 if (options.skip_darwin and target.os.tag.isDarwin()) continue; 3441 if (options.skip_linux and target.os.tag == .linux) continue; 3442 3443 if (options.skip_llvm and test_target.backend == .llvm) continue; 3444 3445 const target_str = b.fmt("{s}-{t}", .{ 3446 resolved_target.query.zigTriple(b.allocator) catch @panic("OOM"), 3447 test_target.backend, 3448 }); 3449 3450 if (options.test_target_filters.len > 0) { 3451 for (options.test_target_filters) |filter| { 3452 if (std.mem.find(u8, target_str, filter) != null) break; 3453 } else continue; 3454 } 3455 3456 const run = b.addRunArtifact(incr_check); 3457 run.setName(b.fmt("incr-check {s} '{s}'", .{ target_str, entry.basename })); 3458 3459 run.addArg(b.graph.zig_exe); 3460 run.addFileArg(b.path("test/incremental/").path(b, entry.path)); 3461 3462 run.addArg("--zig-lib-dir"); 3463 run.addDirectoryArg(.zig_lib); 3464 3465 run.addArgs(&.{ "--target", target_str }); 3466 3467 run.addArg("--quiet"); // don't fill stderr telling us about skipped tests etc 3468 3469 run.addThirdPartyEnabledArgDarling(.{ .enabled = "-fdarling" }); 3470 run.addThirdPartyEnabledArgQemu(.{ .enabled = "-fqemu" }); 3471 run.addThirdPartyEnabledArgRosetta(.{ .enabled = "-frosetta" }); 3472 run.addThirdPartyEnabledArgWasmtime(.{ .enabled = "-fwasmtime" }); 3473 run.addThirdPartyEnabledArgWine(.{ .enabled = "-fwine" }); 3474 3475 run.addCheck(.{ .expect_term = .{ .exited = 0 } }); 3476 test_step.dependOn(&run.step); 3477 } 3478 } 3479 } 3480 3481 pub fn addLlvmIrTests(b: *std.Build, options: LlvmIrContext.Options) ?*Step { 3482 const step = b.step("test-llvm-ir", "Run the LLVM IR tests"); 3483 3484 if (!options.enable_llvm) { 3485 step.dependOn(&b.addFail("test-llvm-ir requires -Denable-llvm").step); 3486 return null; 3487 } 3488 3489 var context: LlvmIrContext = .{ 3490 .b = b, 3491 .options = options, 3492 .root_step = step, 3493 }; 3494 3495 llvm_ir.addCases(&context); 3496 3497 return step; 3498 } 3499 3500 const libc_test_nsz_targets: []const std.Target.Query = &.{ 3501 .{ 3502 .cpu_arch = .arm, 3503 .os_tag = .linux, 3504 .abi = .musleabi, 3505 }, 3506 .{ 3507 .cpu_arch = .arm, 3508 .os_tag = .linux, 3509 .abi = .musleabihf, 3510 }, 3511 .{ 3512 .cpu_arch = .armeb, 3513 .os_tag = .linux, 3514 .abi = .musleabi, 3515 }, 3516 .{ 3517 .cpu_arch = .armeb, 3518 .os_tag = .linux, 3519 .abi = .musleabihf, 3520 }, 3521 .{ 3522 .cpu_arch = .thumb, 3523 .os_tag = .linux, 3524 .abi = .musleabi, 3525 }, 3526 .{ 3527 .cpu_arch = .thumb, 3528 .os_tag = .linux, 3529 .abi = .musleabihf, 3530 }, 3531 .{ 3532 .cpu_arch = .thumbeb, 3533 .os_tag = .linux, 3534 .abi = .musleabi, 3535 }, 3536 .{ 3537 .cpu_arch = .thumbeb, 3538 .os_tag = .linux, 3539 .abi = .musleabihf, 3540 }, 3541 .{ 3542 .cpu_arch = .aarch64, 3543 .os_tag = .linux, 3544 .abi = .musl, 3545 }, 3546 .{ 3547 .cpu_arch = .aarch64_be, 3548 .os_tag = .linux, 3549 .abi = .musl, 3550 }, 3551 // .{ 3552 // .cpu_arch = .hexagon, 3553 // .os_tag = .linux, 3554 // .abi = .musl, 3555 // }, 3556 .{ 3557 .cpu_arch = .loongarch64, 3558 .os_tag = .linux, 3559 .abi = .musl, 3560 }, 3561 .{ 3562 .cpu_arch = .loongarch64, 3563 .os_tag = .linux, 3564 .abi = .muslsf, 3565 }, 3566 // .{ 3567 // .cpu_arch = .mips, 3568 // .os_tag = .linux, 3569 // .abi = .musleabi, 3570 // }, 3571 // .{ 3572 // .cpu_arch = .mips, 3573 // .os_tag = .linux, 3574 // .abi = .musleabihf, 3575 // }, 3576 // .{ 3577 // .cpu_arch = .mipsel, 3578 // .os_tag = .linux, 3579 // .abi = .musleabi, 3580 // }, 3581 // .{ 3582 // .cpu_arch = .mipsel, 3583 // .os_tag = .linux, 3584 // .abi = .musleabihf, 3585 // }, 3586 // .{ 3587 // .cpu_arch = .mips64, 3588 // .os_tag = .linux, 3589 // .abi = .muslabi64, 3590 // }, 3591 // .{ 3592 // .cpu_arch = .mips64, 3593 // .os_tag = .linux, 3594 // .abi = .muslabin32, 3595 // }, 3596 // .{ 3597 // .cpu_arch = .mips64el, 3598 // .os_tag = .linux, 3599 // .abi = .muslabi64, 3600 // }, 3601 // .{ 3602 // .cpu_arch = .mips64el, 3603 // .os_tag = .linux, 3604 // .abi = .muslabin32, 3605 // }, 3606 .{ 3607 .cpu_arch = .powerpc, 3608 .os_tag = .linux, 3609 .abi = .musleabi, 3610 }, 3611 .{ 3612 .cpu_arch = .powerpc, 3613 .os_tag = .linux, 3614 .abi = .musleabihf, 3615 }, 3616 .{ 3617 .cpu_arch = .powerpc64, 3618 .os_tag = .linux, 3619 .abi = .musl, 3620 }, 3621 .{ 3622 .cpu_arch = .powerpc64le, 3623 .os_tag = .linux, 3624 .abi = .musl, 3625 }, 3626 .{ 3627 .cpu_arch = .riscv32, 3628 .os_tag = .linux, 3629 .abi = .musl, 3630 }, 3631 .{ 3632 .cpu_arch = .riscv64, 3633 .os_tag = .linux, 3634 .abi = .musl, 3635 }, 3636 .{ 3637 .cpu_arch = .s390x, 3638 .os_tag = .linux, 3639 .abi = .musl, 3640 }, 3641 .{ 3642 .cpu_arch = .wasm32, 3643 .os_tag = .wasi, 3644 .abi = .musl, 3645 }, 3646 .{ 3647 .cpu_arch = .x86, 3648 .os_tag = .linux, 3649 .abi = .musl, 3650 }, 3651 .{ 3652 .cpu_arch = .x86_64, 3653 .os_tag = .linux, 3654 .abi = .musl, 3655 }, 3656 .{ 3657 .cpu_arch = .x86_64, 3658 .os_tag = .linux, 3659 .abi = .muslx32, 3660 }, 3661 }; 3662 3663 pub fn addLibcTestNszTests(b: *std.Build, options: LibcContext.Options) ?*Step { 3664 const step = b.step("test-libc-nsz", "Run external libc-test test cases"); 3665 const opt_libc_test_path = b.option(std.Build.LazyPath, "libc-test-path", "path to libc-test source directory"); 3666 if (opt_libc_test_path) |libc_test_path| { 3667 var context: LibcContext = .{ 3668 .b = b, 3669 .options = options, 3670 .root_step = step, 3671 .libc_test_src_path = libc_test_path.path(b, "src"), 3672 }; 3673 3674 libc.addCases(&context); 3675 3676 for (libc_test_nsz_targets) |target_query| { 3677 const target = b.resolveTargetQuery(target_query); 3678 context.addTarget(target); 3679 } 3680 3681 return step; 3682 } else { 3683 step.dependOn(&b.addFail("The -Dlibc-test-path=... option is required for this step").step); 3684 return null; 3685 } 3686 } 3687