authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 16:11:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-08 16:11:07-07:00
log6361d7a92824ff2b883625d133fec4fccfb3eef7
treed51d7f3fa9c698949734c9a4cebde0c31bb8211b
parent5619ce2406a545e177882415195575463989066d

stage2 test harness: report multiple failures

so you can debug more than one thing at a time

1 files changed, 26 insertions(+), 20 deletions(-)

src/test.zig+26-20
......@@ -14,7 +14,7 @@ const CrossTarget = std.zig.CrossTarget;
1414
1515const zig_h = link.File.C.zig_h;
1616
17const hr = "=" ** 40;
17const hr = "=" ** 80;
1818
1919test "self-hosted" {
2020 var ctx = TestContext.init();
......@@ -541,6 +541,8 @@ pub const TestContext = struct {
541541 };
542542 defer std.testing.allocator.free(global_cache_directory.path.?);
543543
544 var fail_count: usize = 0;
545
544546 for (self.cases.items) |case| {
545547 if (build_options.skip_non_native and case.target.getCpuArch() != std.Target.current.cpu.arch)
546548 continue;
......@@ -558,14 +560,21 @@ pub const TestContext = struct {
558560 progress.initial_delay_ns = 0;
559561 progress.refresh_rate_ns = 0;
560562
561 try self.runOneCase(
563 self.runOneCase(
562564 std.testing.allocator,
563565 &prg_node,
564566 case,
565567 zig_lib_directory,
566568 &thread_pool,
567569 global_cache_directory,
568 );
570 ) catch |err| {
571 fail_count += 1;
572 std.debug.print("test '{s}' failed: {s}\n\n", .{ case.name, @errorName(err) });
573 };
574 }
575 if (fail_count != 0) {
576 std.debug.print("{d} tests failed\n", .{fail_count});
577 return error.TestFailed;
569578 }
570579 }
571580
......@@ -693,8 +702,7 @@ pub const TestContext = struct {
693702 }
694703 }
695704 // TODO print generated C code
696 std.debug.print("Test failed.\n", .{});
697 std.process.exit(1);
705 return error.UnexpectedCompileErrors;
698706 }
699707 }
700708
......@@ -817,10 +825,8 @@ pub const TestContext = struct {
817825 }
818826
819827 if (any_failed) {
820 std.debug.print("\nTest case '{s}' failed, update_index={d}.\n", .{
821 case.name, update_index,
822 });
823 std.process.exit(1);
828 std.debug.print("\nupdate_index={d} ", .{update_index});
829 return error.WrongCompileErrors;
824830 }
825831 },
826832 .Execution => |expected_stdout| {
......@@ -908,11 +914,11 @@ pub const TestContext = struct {
908914 .cwd_dir = tmp.dir,
909915 .cwd = tmp_dir_path,
910916 }) catch |err| {
911 std.debug.print("\nThe following command failed with {s}:\n", .{
912 @errorName(err),
917 std.debug.print("\nupdate_index={d} The following command failed with {s}:\n", .{
918 update_index, @errorName(err),
913919 });
914920 dumpArgs(argv.items);
915 return error.ZigTestFailed;
921 return error.ChildProcessExecution;
916922 };
917923 };
918924 var test_node = update_node.start("test", 0);
......@@ -927,7 +933,7 @@ pub const TestContext = struct {
927933 exec_result.stderr, case.name, code,
928934 });
929935 dumpArgs(argv.items);
930 return error.ZigTestFailed;
936 return error.ChildProcessExecution;
931937 }
932938 },
933939 else => {
......@@ -935,7 +941,7 @@ pub const TestContext = struct {
935941 exec_result.stderr, case.name,
936942 });
937943 dumpArgs(argv.items);
938 return error.ZigTestFailed;
944 return error.ChildProcessExecution;
939945 },
940946 }
941947 try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
......@@ -1016,26 +1022,26 @@ pub const TestContext = struct {
10161022 while (try iterator.next()) |phdr| {
10171023 if (phdr.p_type != std.elf.PT_LOAD) {
10181024 std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type});
1019 std.process.exit(1);
1025 return error.UnexpectedElfProgramHeader;
10201026 }
10211027 if (phdr.p_paddr != phdr.p_vaddr) {
10221028 std.debug.print("Physical address does not match virtual address in ELF header!\n", .{});
1023 std.process.exit(1);
1029 return error.PhysicalAddressMismatchVirt;
10241030 }
10251031 if (phdr.p_filesz != phdr.p_memsz) {
10261032 std.debug.print("Physical size does not match virtual size in ELF header!\n", .{});
1027 std.process.exit(1);
1033 return error.PhysicalSizeMismatchVirt;
10281034 }
10291035 if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) {
10301036 std.debug.print("Read less than expected from ELF file!", .{});
1031 std.process.exit(1);
1037 return error.ElfFileEof;
10321038 }
10331039 std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr });
10341040 none_loaded = false;
10351041 }
10361042 if (none_loaded) {
10371043 std.debug.print("No data found in ELF file!\n", .{});
1038 std.process.exit(1);
1044 return error.EmptyElfFile;
10391045 }
10401046 }
10411047
......@@ -1052,7 +1058,7 @@ pub const TestContext = struct {
10521058 try interpreter.ExecuteBlock(block_size);
10531059 if (pre_ip == interpreter.ip) {
10541060 std.debug.print("Infinite loop detected in SPU II test!\n", .{});
1055 std.process.exit(1);
1061 return error.InfiniteLoop;
10561062 }
10571063 }
10581064 }