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;...@@ -14,7 +14,7 @@ const CrossTarget = std.zig.CrossTarget;
1414
15const zig_h = link.File.C.zig_h;15const zig_h = link.File.C.zig_h;
1616
17const hr = "=" ** 40;17const hr = "=" ** 80;
1818
19test "self-hosted" {19test "self-hosted" {
20 var ctx = TestContext.init();20 var ctx = TestContext.init();
...@@ -541,6 +541,8 @@ pub const TestContext = struct {...@@ -541,6 +541,8 @@ pub const TestContext = struct {
541 };541 };
542 defer std.testing.allocator.free(global_cache_directory.path.?);542 defer std.testing.allocator.free(global_cache_directory.path.?);
543543
544 var fail_count: usize = 0;
545
544 for (self.cases.items) |case| {546 for (self.cases.items) |case| {
545 if (build_options.skip_non_native and case.target.getCpuArch() != std.Target.current.cpu.arch)547 if (build_options.skip_non_native and case.target.getCpuArch() != std.Target.current.cpu.arch)
546 continue;548 continue;
...@@ -558,14 +560,21 @@ pub const TestContext = struct {...@@ -558,14 +560,21 @@ pub const TestContext = struct {
558 progress.initial_delay_ns = 0;560 progress.initial_delay_ns = 0;
559 progress.refresh_rate_ns = 0;561 progress.refresh_rate_ns = 0;
560562
561 try self.runOneCase(563 self.runOneCase(
562 std.testing.allocator,564 std.testing.allocator,
563 &prg_node,565 &prg_node,
564 case,566 case,
565 zig_lib_directory,567 zig_lib_directory,
566 &thread_pool,568 &thread_pool,
567 global_cache_directory,569 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;
569 }578 }
570 }579 }
571580
...@@ -693,8 +702,7 @@ pub const TestContext = struct {...@@ -693,8 +702,7 @@ pub const TestContext = struct {
693 }702 }
694 }703 }
695 // TODO print generated C code704 // TODO print generated C code
696 std.debug.print("Test failed.\n", .{});705 return error.UnexpectedCompileErrors;
697 std.process.exit(1);
698 }706 }
699 }707 }
700708
...@@ -817,10 +825,8 @@ pub const TestContext = struct {...@@ -817,10 +825,8 @@ pub const TestContext = struct {
817 }825 }
818826
819 if (any_failed) {827 if (any_failed) {
820 std.debug.print("\nTest case '{s}' failed, update_index={d}.\n", .{828 std.debug.print("\nupdate_index={d} ", .{update_index});
821 case.name, update_index,829 return error.WrongCompileErrors;
822 });
823 std.process.exit(1);
824 }830 }
825 },831 },
826 .Execution => |expected_stdout| {832 .Execution => |expected_stdout| {
...@@ -908,11 +914,11 @@ pub const TestContext = struct {...@@ -908,11 +914,11 @@ pub const TestContext = struct {
908 .cwd_dir = tmp.dir,914 .cwd_dir = tmp.dir,
909 .cwd = tmp_dir_path,915 .cwd = tmp_dir_path,
910 }) catch |err| {916 }) catch |err| {
911 std.debug.print("\nThe following command failed with {s}:\n", .{917 std.debug.print("\nupdate_index={d} The following command failed with {s}:\n", .{
912 @errorName(err),918 update_index, @errorName(err),
913 });919 });
914 dumpArgs(argv.items);920 dumpArgs(argv.items);
915 return error.ZigTestFailed;921 return error.ChildProcessExecution;
916 };922 };
917 };923 };
918 var test_node = update_node.start("test", 0);924 var test_node = update_node.start("test", 0);
...@@ -927,7 +933,7 @@ pub const TestContext = struct {...@@ -927,7 +933,7 @@ pub const TestContext = struct {
927 exec_result.stderr, case.name, code,933 exec_result.stderr, case.name, code,
928 });934 });
929 dumpArgs(argv.items);935 dumpArgs(argv.items);
930 return error.ZigTestFailed;936 return error.ChildProcessExecution;
931 }937 }
932 },938 },
933 else => {939 else => {
...@@ -935,7 +941,7 @@ pub const TestContext = struct {...@@ -935,7 +941,7 @@ pub const TestContext = struct {
935 exec_result.stderr, case.name,941 exec_result.stderr, case.name,
936 });942 });
937 dumpArgs(argv.items);943 dumpArgs(argv.items);
938 return error.ZigTestFailed;944 return error.ChildProcessExecution;
939 },945 },
940 }946 }
941 try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);947 try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
...@@ -1016,26 +1022,26 @@ pub const TestContext = struct {...@@ -1016,26 +1022,26 @@ pub const TestContext = struct {
1016 while (try iterator.next()) |phdr| {1022 while (try iterator.next()) |phdr| {
1017 if (phdr.p_type != std.elf.PT_LOAD) {1023 if (phdr.p_type != std.elf.PT_LOAD) {
1018 std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type});1024 std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type});
1019 std.process.exit(1);1025 return error.UnexpectedElfProgramHeader;
1020 }1026 }
1021 if (phdr.p_paddr != phdr.p_vaddr) {1027 if (phdr.p_paddr != phdr.p_vaddr) {
1022 std.debug.print("Physical address does not match virtual address in ELF header!\n", .{});1028 std.debug.print("Physical address does not match virtual address in ELF header!\n", .{});
1023 std.process.exit(1);1029 return error.PhysicalAddressMismatchVirt;
1024 }1030 }
1025 if (phdr.p_filesz != phdr.p_memsz) {1031 if (phdr.p_filesz != phdr.p_memsz) {
1026 std.debug.print("Physical size does not match virtual size in ELF header!\n", .{});1032 std.debug.print("Physical size does not match virtual size in ELF header!\n", .{});
1027 std.process.exit(1);1033 return error.PhysicalSizeMismatchVirt;
1028 }1034 }
1029 if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) {1035 if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) {
1030 std.debug.print("Read less than expected from ELF file!", .{});1036 std.debug.print("Read less than expected from ELF file!", .{});
1031 std.process.exit(1);1037 return error.ElfFileEof;
1032 }1038 }
1033 std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr });1039 std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr });
1034 none_loaded = false;1040 none_loaded = false;
1035 }1041 }
1036 if (none_loaded) {1042 if (none_loaded) {
1037 std.debug.print("No data found in ELF file!\n", .{});1043 std.debug.print("No data found in ELF file!\n", .{});
1038 std.process.exit(1);1044 return error.EmptyElfFile;
1039 }1045 }
1040 }1046 }
10411047
...@@ -1052,7 +1058,7 @@ pub const TestContext = struct {...@@ -1052,7 +1058,7 @@ pub const TestContext = struct {
1052 try interpreter.ExecuteBlock(block_size);1058 try interpreter.ExecuteBlock(block_size);
1053 if (pre_ip == interpreter.ip) {1059 if (pre_ip == interpreter.ip) {
1054 std.debug.print("Infinite loop detected in SPU II test!\n", .{});1060 std.debug.print("Infinite loop detected in SPU II test!\n", .{});
1055 std.process.exit(1);1061 return error.InfiniteLoop;
1056 }1062 }
1057 }1063 }
1058 }1064 }