diff options
author | 2015-02-25 08:36:40 -0800 | |
---|---|---|
committer | 2015-02-25 08:36:40 -0800 | |
commit | 8ad8a41a84bf7e17c6e9a5fd8d975370a222c0fe (patch) | |
tree | 257d00e77bda0bc5e53b770ba9fa7cc300c449bb /test/core/json | |
parent | 517aa0c5358f860582e6143a29522699f61fba15 (diff) |
Introduce slowdown factor for unit test deadlines
Dramatically lowers (eliminates maybe?) false negatives from ?SAN runs.
Diffstat (limited to 'test/core/json')
-rw-r--r-- | test/core/json/json_rewrite.c | 31 | ||||
-rw-r--r-- | test/core/json/json_rewrite_test.c | 63 | ||||
-rw-r--r-- | test/core/json/json_test.c | 153 |
3 files changed, 108 insertions, 139 deletions
diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index 203e75c7d5..02f60a3163 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -40,9 +40,7 @@ #include "src/core/json/json_reader.h" #include "src/core/json/json_writer.h" -typedef struct json_writer_userdata { - FILE* out; -} json_writer_userdata; +typedef struct json_writer_userdata { FILE* out; } json_writer_userdata; typedef struct stacked_container { grpc_json_type type; @@ -76,11 +74,9 @@ static void json_writer_output_string_with_len(void* userdata, const char* str, fwrite(str, len, 1, state->out); } -grpc_json_writer_vtable writer_vtable = { - json_writer_output_char, - json_writer_output_string, - json_writer_output_string_with_len -}; +grpc_json_writer_vtable writer_vtable = {json_writer_output_char, + json_writer_output_string, + json_writer_output_string_with_len}; static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; @@ -202,19 +198,12 @@ static void json_reader_set_null(void* userdata) { } static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, - json_reader_string_add_char, - json_reader_string_add_utf32, - json_reader_read_char, - json_reader_container_begins, - json_reader_container_ends, - json_reader_set_key, - json_reader_set_string, - json_reader_set_number, - json_reader_set_true, - json_reader_set_false, - json_reader_set_null -}; + json_reader_string_clear, json_reader_string_add_char, + json_reader_string_add_utf32, json_reader_read_char, + json_reader_container_begins, json_reader_container_ends, + json_reader_set_key, json_reader_set_string, + json_reader_set_number, json_reader_set_true, + json_reader_set_false, json_reader_set_null}; int rewrite(FILE* in, FILE* out, int indent) { grpc_json_writer writer; diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c index 78dff92a77..ec6deebe76 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.c @@ -42,9 +42,7 @@ #include "src/core/json/json_reader.h" #include "src/core/json/json_writer.h" -typedef struct json_writer_userdata { - FILE* cmp; -} json_writer_userdata; +typedef struct json_writer_userdata { FILE* cmp; } json_writer_userdata; typedef struct stacked_container { grpc_json_type type; @@ -83,11 +81,9 @@ static void json_writer_output_string_with_len(void* userdata, const char* str, } } -grpc_json_writer_vtable writer_vtable = { - json_writer_output_char, - json_writer_output_string, - json_writer_output_string_with_len -}; +grpc_json_writer_vtable writer_vtable = {json_writer_output_char, + json_writer_output_string, + json_writer_output_string_with_len}; static void check_string(json_reader_userdata* state, size_t needed) { if (state->free_space >= needed) return; @@ -216,19 +212,12 @@ static void json_reader_set_null(void* userdata) { } static grpc_json_reader_vtable reader_vtable = { - json_reader_string_clear, - json_reader_string_add_char, - json_reader_string_add_utf32, - json_reader_read_char, - json_reader_container_begins, - json_reader_container_ends, - json_reader_set_key, - json_reader_set_string, - json_reader_set_number, - json_reader_set_true, - json_reader_set_false, - json_reader_set_null -}; + json_reader_string_clear, json_reader_string_add_char, + json_reader_string_add_utf32, json_reader_read_char, + json_reader_container_begins, json_reader_container_ends, + json_reader_set_key, json_reader_set_string, + json_reader_set_number, json_reader_set_true, + json_reader_set_false, json_reader_set_null}; int rewrite_and_compare(FILE* in, FILE* cmp, int indent) { grpc_json_writer writer; @@ -275,26 +264,14 @@ typedef struct test_file { } test_file; static test_file test_files[] = { - { - "test/core/json/rewrite_test_input.json", - "test/core/json/rewrite_test_output_condensed.json", - 0 - }, - { - "test/core/json/rewrite_test_input.json", - "test/core/json/rewrite_test_output_indented.json", - 2 - }, - { - "test/core/json/rewrite_test_output_indented.json", - "test/core/json/rewrite_test_output_condensed.json", - 0 - }, - { - "test/core/json/rewrite_test_output_condensed.json", - "test/core/json/rewrite_test_output_indented.json", - 2 - }, + {"test/core/json/rewrite_test_input.json", + "test/core/json/rewrite_test_output_condensed.json", 0}, + {"test/core/json/rewrite_test_input.json", + "test/core/json/rewrite_test_output_indented.json", 2}, + {"test/core/json/rewrite_test_output_indented.json", + "test/core/json/rewrite_test_output_condensed.json", 0}, + {"test/core/json/rewrite_test_output_condensed.json", + "test/core/json/rewrite_test_output_indented.json", 2}, }; void test_rewrites() { @@ -305,8 +282,8 @@ void test_rewrites() { FILE* input = fopen(test->input, "rb"); FILE* cmp = fopen(test->cmp, "rb"); int status; - gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", - test->input, test->cmp, test->indent); + gpr_log(GPR_INFO, "Testing file %s against %s using indent=%i", test->input, + test->cmp, test->indent); status = rewrite_and_compare(input, cmp, test->indent); GPR_ASSERT(status); fclose(input); diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c index bc3c7a3da8..9a50a6929e 100644 --- a/test/core/json/json_test.c +++ b/test/core/json/json_test.c @@ -47,80 +47,83 @@ typedef struct testing_pair { } testing_pair; static testing_pair testing_pairs[] = { - /* Testing valid parsing. */ - - /* Testing trivial parses, with de-indentation. */ - { " 0 ", "0" }, - { " 1 ", "1" }, - { " \"a\" ", "\"a\"" }, - { " true ", "true" }, - /* Testing the parser's ability to decode trivial UTF-16. */ - { "\"\\u0020\\\\\\u0010\\u000a\\u000D\"", "\" \\\\\\u0010\\n\\r\"" }, - /* Testing various UTF-8 sequences. */ - { "\"ßâñć௵⇒\"", "\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\"" }, - { "\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\"", "\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\"" }, - /* Testing UTF-8 character "𝄞", U+11D1E. */ - { "\"\xf0\x9d\x84\x9e\"", "\"\\ud834\\udd1e\"" }, - { "\"\\ud834\\udd1e\"", "\"\\ud834\\udd1e\"" }, - /* Testing nested empty containers. */ - { " [ [ ] , { } , [ ] ] ", "[[],{},[]]", }, - /* Testing escapes and control chars in key strings. */ - { " { \"\x7f\\n\\\\a , b\": 1, \"\": 0 } ", "{\"\\u007f\\n\\\\a , b\":1,\"\":0}" }, - /* Testing the writer's ability to cut off invalid UTF-8 sequences. */ - { "\"abc\xf0\x9d\x24\"", "\"abc\"" }, - { "\"\xff\"", "\"\"" }, - /* Testing valid number parsing. */ - { "[0, 42 , 0.0123, 123.456]", "[0,42,0.0123,123.456]"}, - { "[1e4,-53.235e-31, 0.3e+3]", "[1e4,-53.235e-31,0.3e+3]" }, - /* Testing keywords parsing. */ - { "[true, false, null]", "[true,false,null]" }, - - - /* Testing invalid parsing. */ - - /* Testing plain invalid things, exercising the state machine. */ - { "\\", NULL }, - { "nu ll", NULL }, - { "fals", NULL }, - /* Testing unterminated string. */ - { "\"\\x", NULL }, - /* Testing invalid UTF-16 number. */ - { "\"\\u123x", NULL }, - /* Testing imbalanced surrogate pairs. */ - { "\"\\ud834f", NULL }, - { "\"\\ud834\\n", NULL }, - { "\"\\udd1ef", NULL }, - { "\"\\ud834\\ud834\"", NULL }, - { "\"\\ud834\\u1234\"", NULL }, - /* Testing embedded invalid whitechars. */ - { "\"\n\"", NULL }, - { "\"\t\"", NULL }, - /* Testing empty json data. */ - { "", NULL }, - /* Testing extra characters after end of parsing. */ - { "{},", NULL }, - /* Testing imbalanced containers. */ - { "{}}", NULL }, - { "[]]", NULL }, - { "{{}", NULL }, - { "[[]", NULL }, - { "[}", NULL }, - { "{]", NULL }, - /*Testing trailing comma. */ - { "{,}", NULL }, - { "[1,2,3,4,]", NULL }, - /* Testing having a key syntax in an array. */ - { "[\"x\":0]", NULL }, - /* Testing invalid numbers. */ - { "1.", NULL }, - { "1e", NULL }, - { ".12", NULL }, - { "1.x", NULL }, - { "1.12x", NULL }, - { "1ex", NULL }, - { "1e12x", NULL }, - { ".12x", NULL }, - { "000", NULL }, + /* Testing valid parsing. */ + + /* Testing trivial parses, with de-indentation. */ + {" 0 ", "0"}, + {" 1 ", "1"}, + {" \"a\" ", "\"a\""}, + {" true ", "true"}, + /* Testing the parser's ability to decode trivial UTF-16. */ + {"\"\\u0020\\\\\\u0010\\u000a\\u000D\"", "\" \\\\\\u0010\\n\\r\""}, + /* Testing various UTF-8 sequences. */ + {"\"ßâñć௵⇒\"", "\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\""}, + {"\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\"", + "\"\\u00df\\u00e2\\u00f1\\u0107\\u0bf5\\u21d2\""}, + /* Testing UTF-8 character "𝄞", U+11D1E. */ + {"\"\xf0\x9d\x84\x9e\"", "\"\\ud834\\udd1e\""}, + {"\"\\ud834\\udd1e\"", "\"\\ud834\\udd1e\""}, + /* Testing nested empty containers. */ + { + " [ [ ] , { } , [ ] ] ", "[[],{},[]]", + }, + /* Testing escapes and control chars in key strings. */ + {" { \"\x7f\\n\\\\a , b\": 1, \"\": 0 } ", + "{\"\\u007f\\n\\\\a , b\":1,\"\":0}"}, + /* Testing the writer's ability to cut off invalid UTF-8 sequences. */ + {"\"abc\xf0\x9d\x24\"", "\"abc\""}, + {"\"\xff\"", "\"\""}, + /* Testing valid number parsing. */ + {"[0, 42 , 0.0123, 123.456]", "[0,42,0.0123,123.456]"}, + {"[1e4,-53.235e-31, 0.3e+3]", "[1e4,-53.235e-31,0.3e+3]"}, + /* Testing keywords parsing. */ + {"[true, false, null]", "[true,false,null]"}, + + /* Testing invalid parsing. */ + + /* Testing plain invalid things, exercising the state machine. */ + {"\\", NULL}, + {"nu ll", NULL}, + {"fals", NULL}, + /* Testing unterminated string. */ + {"\"\\x", NULL}, + /* Testing invalid UTF-16 number. */ + {"\"\\u123x", NULL}, + /* Testing imbalanced surrogate pairs. */ + {"\"\\ud834f", NULL}, + {"\"\\ud834\\n", NULL}, + {"\"\\udd1ef", NULL}, + {"\"\\ud834\\ud834\"", NULL}, + {"\"\\ud834\\u1234\"", NULL}, + /* Testing embedded invalid whitechars. */ + {"\"\n\"", NULL}, + {"\"\t\"", NULL}, + /* Testing empty json data. */ + {"", NULL}, + /* Testing extra characters after end of parsing. */ + {"{},", NULL}, + /* Testing imbalanced containers. */ + {"{}}", NULL}, + {"[]]", NULL}, + {"{{}", NULL}, + {"[[]", NULL}, + {"[}", NULL}, + {"{]", NULL}, + /*Testing trailing comma. */ + {"{,}", NULL}, + {"[1,2,3,4,]", NULL}, + /* Testing having a key syntax in an array. */ + {"[\"x\":0]", NULL}, + /* Testing invalid numbers. */ + {"1.", NULL}, + {"1e", NULL}, + {".12", NULL}, + {"1.x", NULL}, + {"1.12x", NULL}, + {"1ex", NULL}, + {"1e12x", NULL}, + {".12x", NULL}, + {"000", NULL}, }; static void test_pairs() { @@ -169,7 +172,7 @@ static void test_atypical() { gpr_free(scratchpad); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_test_init(argc, argv); test_pairs(); test_atypical(); |