aboutsummaryrefslogtreecommitdiff
path: root/lib/std/special
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-06 17:56:40 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-06 18:05:50 -0500
commit0b5bcd2f56a84e66d5c700744ec1838381893667 (patch)
tree5b640a57055e50636fe7a9f782915b2126395ef3 /lib/std/special
parent704cd977bdcdfa8cff4e70aaad93857d9b622fc7 (diff)
downloadzig-0b5bcd2f56a84e66d5c700744ec1838381893667.tar.gz
zig-0b5bcd2f56a84e66d5c700744ec1838381893667.zip
more std lib async I/O integration
* `zig test` gainst `--test-evented-io` parameter and gains the ability to seamlessly run async tests. * `std.ChildProcess` opens its child process pipe with O_NONBLOCK when using evented I/O * `std.io.getStdErr()` gives a File that is blocking even in evented I/O mode. * Delete `std.event.fs`. The functionality is now merged into `std.fs` and async file system access (using a dedicated thread) is automatically handled. * `std.fs.File` can be configured to specify whether its handle is expected to block, and whether that is OK to block even when in async I/O mode. This makes async I/O work correctly for e.g. the file system as well as network. * `std.fs.File` has some deprecated functions removed. * Missing readv,writev,pread,pwrite,preadv,pwritev functions are added to `std.os` and `std.fs.File`. They are all integrated with async I/O. * `std.fs.Watch` is still bit rotted and needs to be audited in light of the new async/await syntax. * `std.io.OutStream` integrates with async I/O * linked list nodes in the std lib have default `null` values for `prev` and `next`. * Windows async I/O integration is enabled for reading/writing file handles. * Added `std.os.mode_t`. Integer sizes need to be audited. * Fixed #4403 which was causing compiler to crash. This is working towards: ./zig test ../test/stage1/behavior.zig --test-evented-io Which does not successfully build yet. I'd like to enable behavioral tests and std lib tests with --test-evented-io in the test matrix in the future, to prevent regressions.
Diffstat (limited to 'lib/std/special')
-rw-r--r--lib/std/special/test_runner.zig26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index 4ba2e3aa7e..6dd208e3b4 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -2,7 +2,7 @@ const std = @import("std");
const io = std.io;
const builtin = @import("builtin");
-pub const io_mode = builtin.test_io_mode;
+pub const io_mode: io.Mode = builtin.test_io_mode;
pub fn main() anyerror!void {
const test_fn_list = builtin.test_functions;
@@ -14,6 +14,11 @@ pub fn main() anyerror!void {
error.TimerUnsupported => @panic("timer unsupported"),
};
+ var async_frame_buffer: []align(std.Target.stack_align) u8 = undefined;
+ // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
+ // ignores the alignment of the slice.
+ async_frame_buffer = &[_]u8{};
+
for (test_fn_list) |test_fn, i| {
std.testing.base_allocator_instance.reset();
@@ -23,7 +28,24 @@ pub fn main() anyerror!void {
if (progress.terminal == null) {
std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name });
}
- if (test_fn.func()) |_| {
+ const result = if (test_fn.async_frame_size) |size| switch (io_mode) {
+ .evented => blk: {
+ if (async_frame_buffer.len < size) {
+ std.heap.page_allocator.free(async_frame_buffer);
+ async_frame_buffer = try std.heap.page_allocator.alignedAlloc(u8, std.Target.stack_align, size);
+ }
+ const casted_fn = @ptrCast(async fn () anyerror!void, test_fn.func);
+ break :blk await @asyncCall(async_frame_buffer, {}, casted_fn);
+ },
+ .blocking => {
+ skip_count += 1;
+ test_node.end();
+ progress.log("{}...SKIP (async test)\n", .{test_fn.name});
+ if (progress.terminal == null) std.debug.warn("SKIP (async test)\n", .{});
+ continue;
+ },
+ } else test_fn.func();
+ if (result) |_| {
ok_count += 1;
test_node.end();
std.testing.allocator_instance.validate() catch |err| switch (err) {