authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-05 16:53:29-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-05 16:53:29-05:00
log704cd977bdcdfa8cff4e70aaad93857d9b622fc7
tree028ddaa40366b2a3b487751926f8d8d81cde88c4
parent84323504acc2c872a55d0b59ff2c54b60b809405
signaturelock-open Commit is signed but in an unrecognized format.

ability to run tests in evented I/O mode

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

4 files changed, 14 insertions(+), 0 deletions(-)

lib/std/special/test_runner.zig+2
...@@ -2,6 +2,8 @@ const std = @import("std");...@@ -2,6 +2,8 @@ const std = @import("std");
2const io = std.io;2const io = std.io;
3const builtin = @import("builtin");3const builtin = @import("builtin");
44
5pub const io_mode = builtin.test_io_mode;
6
5pub fn main() anyerror!void {7pub fn main() anyerror!void {
6 const test_fn_list = builtin.test_functions;8 const test_fn_list = builtin.test_functions;
7 var ok_count: usize = 0;9 var ok_count: usize = 0;
src/all_types.hpp+1
...@@ -2244,6 +2244,7 @@ struct CodeGen {...@@ -2244,6 +2244,7 @@ struct CodeGen {
2244 bool enable_dump_analysis;2244 bool enable_dump_analysis;
2245 bool enable_doc_generation;2245 bool enable_doc_generation;
2246 bool disable_bin_generation;2246 bool disable_bin_generation;
2247 bool test_is_evented;
2247 CodeModel code_model;2248 CodeModel code_model;
22482249
2249 Buf *mmacosx_version_min;2250 Buf *mmacosx_version_min;
src/codegen.cpp+5
...@@ -8602,6 +8602,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8602,6 +8602,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8602 buf_appendf(contents,8602 buf_appendf(contents,
8603 "pub var test_functions: []TestFn = undefined; // overwritten later\n"8603 "pub var test_functions: []TestFn = undefined; // overwritten later\n"
8604 );8604 );
8605
8606 buf_appendf(contents, "pub const test_io_mode = %s;\n",
8607 g->test_is_evented ? ".evented" : ".blocking");
8605 }8608 }
86068609
8607 return contents;8610 return contents;
...@@ -8635,6 +8638,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {...@@ -8635,6 +8638,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
8635 cache_bool(&cache_hash, g->is_dynamic);8638 cache_bool(&cache_hash, g->is_dynamic);
8636 cache_bool(&cache_hash, g->is_test_build);8639 cache_bool(&cache_hash, g->is_test_build);
8637 cache_bool(&cache_hash, g->is_single_threaded);8640 cache_bool(&cache_hash, g->is_single_threaded);
8641 cache_bool(&cache_hash, g->test_is_evented);
8638 cache_int(&cache_hash, g->code_model);8642 cache_int(&cache_hash, g->code_model);
8639 cache_int(&cache_hash, g->zig_target->is_native);8643 cache_int(&cache_hash, g->zig_target->is_native);
8640 cache_int(&cache_hash, g->zig_target->arch);8644 cache_int(&cache_hash, g->zig_target->arch);
...@@ -10350,6 +10354,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -10350,6 +10354,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10350 if (g->is_test_build) {10354 if (g->is_test_build) {
10351 cache_buf_opt(ch, g->test_filter);10355 cache_buf_opt(ch, g->test_filter);
10352 cache_buf_opt(ch, g->test_name_prefix);10356 cache_buf_opt(ch, g->test_name_prefix);
10357 cache_bool(ch, g->test_is_evented);
10353 }10358 }
10354 cache_bool(ch, g->link_eh_frame_hdr);10359 cache_bool(ch, g->link_eh_frame_hdr);
10355 cache_bool(ch, g->is_single_threaded);10360 cache_bool(ch, g->is_single_threaded);
src/main.cpp+6
...@@ -135,6 +135,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {...@@ -135,6 +135,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
135 " --test-name-prefix [text] add prefix to all tests\n"135 " --test-name-prefix [text] add prefix to all tests\n"
136 " --test-cmd [arg] specify test execution command one arg at a time\n"136 " --test-cmd [arg] specify test execution command one arg at a time\n"
137 " --test-cmd-bin appends test binary path to test cmd args\n"137 " --test-cmd-bin appends test binary path to test cmd args\n"
138 " --test-evented-io runs the test in evented I/O mode\n"
138 , arg0);139 , arg0);
139 return return_code;140 return return_code;
140}141}
...@@ -428,6 +429,7 @@ int main(int argc, char **argv) {...@@ -428,6 +429,7 @@ int main(int argc, char **argv) {
428 ZigList<CFile *> c_source_files = {0};429 ZigList<CFile *> c_source_files = {0};
429 const char *test_filter = nullptr;430 const char *test_filter = nullptr;
430 const char *test_name_prefix = nullptr;431 const char *test_name_prefix = nullptr;
432 bool test_evented_io = false;
431 size_t ver_major = 0;433 size_t ver_major = 0;
432 size_t ver_minor = 0;434 size_t ver_minor = 0;
433 size_t ver_patch = 0;435 size_t ver_patch = 0;
...@@ -709,6 +711,8 @@ int main(int argc, char **argv) {...@@ -709,6 +711,8 @@ int main(int argc, char **argv) {
709 cur_pkg = cur_pkg->parent;711 cur_pkg = cur_pkg->parent;
710 } else if (strcmp(arg, "-ffunction-sections") == 0) {712 } else if (strcmp(arg, "-ffunction-sections") == 0) {
711 function_sections = true;713 function_sections = true;
714 } else if (strcmp(arg, "--test-evented-io") == 0) {
715 test_evented_io = true;
712 } else if (i + 1 >= argc) {716 } else if (i + 1 >= argc) {
713 fprintf(stderr, "Expected another argument after %s\n", arg);717 fprintf(stderr, "Expected another argument after %s\n", arg);
714 return print_error_usage(arg0);718 return print_error_usage(arg0);
...@@ -1059,6 +1063,7 @@ int main(int argc, char **argv) {...@@ -1059,6 +1063,7 @@ int main(int argc, char **argv) {
1059 g->want_stack_check = want_stack_check;1063 g->want_stack_check = want_stack_check;
1060 g->want_sanitize_c = want_sanitize_c;1064 g->want_sanitize_c = want_sanitize_c;
1061 g->want_single_threaded = want_single_threaded;1065 g->want_single_threaded = want_single_threaded;
1066 g->test_is_evented = test_evented_io;
1062 Buf *builtin_source = codegen_generate_builtin_source(g);1067 Buf *builtin_source = codegen_generate_builtin_source(g);
1063 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {1068 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
1064 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));1069 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
...@@ -1232,6 +1237,7 @@ int main(int argc, char **argv) {...@@ -1232,6 +1237,7 @@ int main(int argc, char **argv) {
1232 if (test_filter) {1237 if (test_filter) {
1233 codegen_set_test_filter(g, buf_create_from_str(test_filter));1238 codegen_set_test_filter(g, buf_create_from_str(test_filter));
1234 }1239 }
1240 g->test_is_evented = test_evented_io;
12351241
1236 if (test_name_prefix) {1242 if (test_name_prefix) {
1237 codegen_set_test_name_prefix(g, buf_create_from_str(test_name_prefix));1243 codegen_set_test_name_prefix(g, buf_create_from_str(test_name_prefix));