aboutsummaryrefslogtreecommitdiff
path: root/src/test.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-05-18 20:20:46 -0400
committerGitHub <noreply@github.com>2021-05-18 20:20:46 -0400
commit6435750c99e705eb40bbdf75e51a3493d683e951 (patch)
tree2f1ab1dc537ba8804ae6d1e0bdd094d646625e53 /src/test.zig
parentd228d86059cf16f4b37b2853cc1323bf98d242cf (diff)
parent667236668f865de4c854a047d65017140317e7e9 (diff)
downloadzig-6435750c99e705eb40bbdf75e51a3493d683e951.tar.gz
zig-6435750c99e705eb40bbdf75e51a3493d683e951.zip
Merge pull request #8554 from ziglang/stage2-whole-file-astgen
Stage2 whole file astgen
Diffstat (limited to 'src/test.zig')
-rw-r--r--src/test.zig153
1 files changed, 22 insertions, 131 deletions
diff --git a/src/test.zig b/src/test.zig
index 5a8adca3c7..a5f5b8c2b0 100644
--- a/src/test.zig
+++ b/src/test.zig
@@ -2,7 +2,6 @@ const std = @import("std");
const link = @import("link.zig");
const Compilation = @import("Compilation.zig");
const Allocator = std.mem.Allocator;
-const zir = @import("zir.zig");
const Package = @import("Package.zig");
const introspect = @import("introspect.zig");
const build_options = @import("build_options");
@@ -16,7 +15,7 @@ const CrossTarget = std.zig.CrossTarget;
const zig_h = link.File.C.zig_h;
-const hr = "=" ** 40;
+const hr = "=" ** 80;
test "self-hosted" {
var ctx = TestContext.init();
@@ -137,7 +136,7 @@ pub const TestContext = struct {
/// to Executable.
output_mode: std.builtin.OutputMode,
updates: std.ArrayList(Update),
- object_format: ?std.builtin.ObjectFormat = null,
+ object_format: ?std.Target.ObjectFormat = null,
emit_h: bool = false,
llvm_backend: bool = false,
@@ -543,6 +542,8 @@ pub const TestContext = struct {
};
defer std.testing.allocator.free(global_cache_directory.path.?);
+ var fail_count: usize = 0;
+
for (self.cases.items) |case| {
if (build_options.skip_non_native and case.target.getCpuArch() != std.Target.current.cpu.arch)
continue;
@@ -560,14 +561,21 @@ pub const TestContext = struct {
progress.initial_delay_ns = 0;
progress.refresh_rate_ns = 0;
- try self.runOneCase(
+ self.runOneCase(
std.testing.allocator,
&prg_node,
case,
zig_lib_directory,
&thread_pool,
global_cache_directory,
- );
+ ) catch |err| {
+ fail_count += 1;
+ std.debug.print("test '{s}' failed: {s}\n\n", .{ case.name, @errorName(err) });
+ };
+ }
+ if (fail_count != 0) {
+ std.debug.print("{d} tests failed\n", .{fail_count});
+ return error.TestFailed;
}
}
@@ -603,7 +611,6 @@ pub const TestContext = struct {
var root_pkg: Package = .{
.root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir },
.root_src_path = tmp_src_path,
- .namespace_hash = Package.root_namespace_hash,
};
defer root_pkg.table.deinit(allocator);
@@ -695,8 +702,7 @@ pub const TestContext = struct {
}
}
// TODO print generated C code
- std.debug.print("Test failed.\n", .{});
- std.process.exit(1);
+ return error.UnexpectedCompileErrors;
}
}
@@ -819,10 +825,8 @@ pub const TestContext = struct {
}
if (any_failed) {
- std.debug.print("\nTest case '{s}' failed, update_index={d}.\n", .{
- case.name, update_index,
- });
- std.process.exit(1);
+ std.debug.print("\nupdate_index={d} ", .{update_index});
+ return error.WrongCompileErrors;
}
},
.Execution => |expected_stdout| {
@@ -858,10 +862,7 @@ pub const TestContext = struct {
});
} else switch (case.target.getExternalExecutor()) {
.native => try argv.append(exe_path),
- .unavailable => {
- try self.runInterpreterIfAvailable(allocator, &exec_node, case, tmp.dir, bin_name);
- return; // Pass test.
- },
+ .unavailable => return, // Pass test.
.qemu => |qemu_bin_name| if (enable_qemu) {
// TODO Ability for test cases to specify whether to link libc.
@@ -920,11 +921,11 @@ pub const TestContext = struct {
.cwd_dir = tmp.dir,
.cwd = tmp_dir_path,
}) catch |err| {
- std.debug.print("\nThe following command failed with {s}:\n", .{
- @errorName(err),
+ std.debug.print("\nupdate_index={d} The following command failed with {s}:\n", .{
+ update_index, @errorName(err),
});
dumpArgs(argv.items);
- return error.ZigTestFailed;
+ return error.ChildProcessExecution;
};
};
var test_node = update_node.start("test", 0);
@@ -939,7 +940,7 @@ pub const TestContext = struct {
exec_result.stderr, case.name, code,
});
dumpArgs(argv.items);
- return error.ZigTestFailed;
+ return error.ChildProcessExecution;
}
},
else => {
@@ -947,7 +948,7 @@ pub const TestContext = struct {
exec_result.stderr, case.name,
});
dumpArgs(argv.items);
- return error.ZigTestFailed;
+ return error.ChildProcessExecution;
},
}
try std.testing.expectEqualStrings(expected_stdout, exec_result.stdout);
@@ -959,116 +960,6 @@ pub const TestContext = struct {
}
}
- fn runInterpreterIfAvailable(
- self: *TestContext,
- gpa: *Allocator,
- node: *std.Progress.Node,
- case: Case,
- tmp_dir: std.fs.Dir,
- bin_name: []const u8,
- ) !void {
- const arch = case.target.cpu_arch orelse return;
- switch (arch) {
- .spu_2 => return self.runSpu2Interpreter(gpa, node, case, tmp_dir, bin_name),
- else => return,
- }
- }
-
- fn runSpu2Interpreter(
- self: *TestContext,
- gpa: *Allocator,
- update_node: *std.Progress.Node,
- case: Case,
- tmp_dir: std.fs.Dir,
- bin_name: []const u8,
- ) !void {
- const spu = @import("codegen/spu-mk2.zig");
- if (case.target.os_tag) |os| {
- if (os != .freestanding) {
- std.debug.panic("Only freestanding makes sense for SPU-II tests!", .{});
- }
- } else {
- std.debug.panic("SPU_2 has no native OS, check the test!", .{});
- }
-
- var interpreter = spu.Interpreter(struct {
- RAM: [0x10000]u8 = undefined,
-
- pub fn read8(bus: @This(), addr: u16) u8 {
- return bus.RAM[addr];
- }
- pub fn read16(bus: @This(), addr: u16) u16 {
- return std.mem.readIntLittle(u16, bus.RAM[addr..][0..2]);
- }
-
- pub fn write8(bus: *@This(), addr: u16, val: u8) void {
- bus.RAM[addr] = val;
- }
-
- pub fn write16(bus: *@This(), addr: u16, val: u16) void {
- std.mem.writeIntLittle(u16, bus.RAM[addr..][0..2], val);
- }
- }){
- .bus = .{},
- };
-
- {
- var load_node = update_node.start("load", 0);
- load_node.activate();
- defer load_node.end();
-
- var file = try tmp_dir.openFile(bin_name, .{ .read = true });
- defer file.close();
-
- const header = try std.elf.Header.read(&file);
- var iterator = header.program_header_iterator(&file);
-
- var none_loaded = true;
-
- while (try iterator.next()) |phdr| {
- if (phdr.p_type != std.elf.PT_LOAD) {
- std.debug.print("Encountered unexpected ELF program header: type {}\n", .{phdr.p_type});
- std.process.exit(1);
- }
- if (phdr.p_paddr != phdr.p_vaddr) {
- std.debug.print("Physical address does not match virtual address in ELF header!\n", .{});
- std.process.exit(1);
- }
- if (phdr.p_filesz != phdr.p_memsz) {
- std.debug.print("Physical size does not match virtual size in ELF header!\n", .{});
- std.process.exit(1);
- }
- if ((try file.pread(interpreter.bus.RAM[phdr.p_paddr .. phdr.p_paddr + phdr.p_filesz], phdr.p_offset)) != phdr.p_filesz) {
- std.debug.print("Read less than expected from ELF file!", .{});
- std.process.exit(1);
- }
- std.log.scoped(.spu2_test).debug("Loaded 0x{x} bytes to 0x{x:0<4}\n", .{ phdr.p_filesz, phdr.p_paddr });
- none_loaded = false;
- }
- if (none_loaded) {
- std.debug.print("No data found in ELF file!\n", .{});
- std.process.exit(1);
- }
- }
-
- var exec_node = update_node.start("execute", 0);
- exec_node.activate();
- defer exec_node.end();
-
- var blocks: u16 = 1000;
- const block_size = 1000;
- while (!interpreter.undefined0) {
- const pre_ip = interpreter.ip;
- if (blocks > 0) {
- blocks -= 1;
- try interpreter.ExecuteBlock(block_size);
- if (pre_ip == interpreter.ip) {
- std.debug.print("Infinite loop detected in SPU II test!\n", .{});
- std.process.exit(1);
- }
- }
- }
- }
};
fn dumpArgs(argv: []const []const u8) void {