ability to run tests in evented I/O mode

This adds `--test-evented-io` as a CLI parameter.

see #3117
master
Andrew Kelley 2020-02-05 16:53:29 -05:00
parent 84323504ac
commit 704cd977bd
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,8 @@ const std = @import("std");
const io = std.io;
const builtin = @import("builtin");
pub const io_mode = builtin.test_io_mode;
pub fn main() anyerror!void {
const test_fn_list = builtin.test_functions;
var ok_count: usize = 0;

View File

@ -2244,6 +2244,7 @@ struct CodeGen {
bool enable_dump_analysis;
bool enable_doc_generation;
bool disable_bin_generation;
bool test_is_evented;
CodeModel code_model;
Buf *mmacosx_version_min;

View File

@ -8602,6 +8602,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents,
"pub var test_functions: []TestFn = undefined; // overwritten later\n"
);
buf_appendf(contents, "pub const test_io_mode = %s;\n",
g->test_is_evented ? ".evented" : ".blocking");
}
return contents;
@ -8635,6 +8638,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
cache_bool(&cache_hash, g->is_dynamic);
cache_bool(&cache_hash, g->is_test_build);
cache_bool(&cache_hash, g->is_single_threaded);
cache_bool(&cache_hash, g->test_is_evented);
cache_int(&cache_hash, g->code_model);
cache_int(&cache_hash, g->zig_target->is_native);
cache_int(&cache_hash, g->zig_target->arch);
@ -10350,6 +10354,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
if (g->is_test_build) {
cache_buf_opt(ch, g->test_filter);
cache_buf_opt(ch, g->test_name_prefix);
cache_bool(ch, g->test_is_evented);
}
cache_bool(ch, g->link_eh_frame_hdr);
cache_bool(ch, g->is_single_threaded);

View File

@ -135,6 +135,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
" --test-name-prefix [text] add prefix to all tests\n"
" --test-cmd [arg] specify test execution command one arg at a time\n"
" --test-cmd-bin appends test binary path to test cmd args\n"
" --test-evented-io runs the test in evented I/O mode\n"
, arg0);
return return_code;
}
@ -428,6 +429,7 @@ int main(int argc, char **argv) {
ZigList<CFile *> c_source_files = {0};
const char *test_filter = nullptr;
const char *test_name_prefix = nullptr;
bool test_evented_io = false;
size_t ver_major = 0;
size_t ver_minor = 0;
size_t ver_patch = 0;
@ -709,6 +711,8 @@ int main(int argc, char **argv) {
cur_pkg = cur_pkg->parent;
} else if (strcmp(arg, "-ffunction-sections") == 0) {
function_sections = true;
} else if (strcmp(arg, "--test-evented-io") == 0) {
test_evented_io = true;
} else if (i + 1 >= argc) {
fprintf(stderr, "Expected another argument after %s\n", arg);
return print_error_usage(arg0);
@ -1059,6 +1063,7 @@ int main(int argc, char **argv) {
g->want_stack_check = want_stack_check;
g->want_sanitize_c = want_sanitize_c;
g->want_single_threaded = want_single_threaded;
g->test_is_evented = test_evented_io;
Buf *builtin_source = codegen_generate_builtin_source(g);
if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
@ -1232,6 +1237,7 @@ int main(int argc, char **argv) {
if (test_filter) {
codegen_set_test_filter(g, buf_create_from_str(test_filter));
}
g->test_is_evented = test_evented_io;
if (test_name_prefix) {
codegen_set_test_name_prefix(g, buf_create_from_str(test_name_prefix));