diff options
author | ncteisen <ncteisen@gmail.com> | 2017-03-10 14:58:43 -0800 |
---|---|---|
committer | ncteisen <ncteisen@gmail.com> | 2017-03-10 22:25:25 -0800 |
commit | bbb3801e480674695d5f60950724a432f264f170 (patch) | |
tree | 3233995f3667592c92981a6f2d99ab1cf5fe421d /test | |
parent | 5dc79eb5aab791dd707c210dd29379a46626f8e8 (diff) |
Change error get/set API to grpc_slice
Diffstat (limited to 'test')
-rw-r--r-- | test/core/iomgr/error_test.c | 62 | ||||
-rw-r--r-- | test/cpp/microbenchmarks/bm_error.cc | 8 |
2 files changed, 33 insertions, 37 deletions
diff --git a/test/core/iomgr/error_test.c b/test/core/iomgr/error_test.c index 2a6b1b17fd..48a7aa0b3f 100644 --- a/test/core/iomgr/error_test.c +++ b/test/core/iomgr/error_test.c @@ -68,24 +68,22 @@ static void test_set_get_int() { static void test_set_get_str() { grpc_error* error = GRPC_ERROR_CREATE("Test"); - GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL)); - GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_TSI_ERROR)); + grpc_slice str; + GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL, &str)); + GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_TSI_ERROR, &str)); - const char* c = grpc_error_get_str(error, GRPC_ERROR_STR_FILE); - GPR_ASSERT(c); - GPR_ASSERT(strstr(c, "error_test.c")); // __FILE__ expands differently on + GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_FILE, &str)); + GPR_ASSERT(strstr((char*)GRPC_SLICE_START_PTR(str), "error_test.c")); // __FILE__ expands differently on // Windows. All should at least // contain error_test.c - c = grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, "Test")); + GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "Test", GRPC_SLICE_LENGTH(str))); error = - grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, "longer message"); - c = grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, "longer message")); + grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("longer message")); + GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "longer message", GRPC_SLICE_LENGTH(str))); GRPC_ERROR_UNREF(error); } @@ -93,26 +91,24 @@ static void test_set_get_str() { static void test_copy_and_unref() { // error1 has one ref grpc_error* error1 = grpc_error_set_str( - GRPC_ERROR_CREATE("Test"), GRPC_ERROR_STR_GRPC_MESSAGE, "message"); - const char* c = grpc_error_get_str(error1, GRPC_ERROR_STR_GRPC_MESSAGE); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, "message")); + GRPC_ERROR_CREATE("Test"), GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message")); + grpc_slice str; + GPR_ASSERT(grpc_error_get_str(error1, GRPC_ERROR_STR_GRPC_MESSAGE, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "message", GRPC_SLICE_LENGTH(str))); // error 1 has two refs GRPC_ERROR_REF(error1); // this gives error3 a ref to the new error, and decrements error1 to one ref grpc_error* error3 = - grpc_error_set_str(error1, GRPC_ERROR_STR_SYSCALL, "syscall"); + grpc_error_set_str(error1, GRPC_ERROR_STR_SYSCALL, grpc_slice_from_static_string("syscall")); GPR_ASSERT(error3 != error1); // should not be the same because of extra ref - c = grpc_error_get_str(error3, GRPC_ERROR_STR_GRPC_MESSAGE); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, "message")); + GPR_ASSERT(grpc_error_get_str(error3, GRPC_ERROR_STR_GRPC_MESSAGE, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "message", GRPC_SLICE_LENGTH(str))); // error 1 should not have a syscall but 3 should - GPR_ASSERT(!grpc_error_get_str(error1, GRPC_ERROR_STR_SYSCALL)); - c = grpc_error_get_str(error3, GRPC_ERROR_STR_SYSCALL); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, "syscall")); + GPR_ASSERT(!grpc_error_get_str(error1, GRPC_ERROR_STR_SYSCALL, &str)); + GPR_ASSERT(grpc_error_get_str(error3, GRPC_ERROR_STR_SYSCALL, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "syscall", GRPC_SLICE_LENGTH(str))); GRPC_ERROR_UNREF(error1); GRPC_ERROR_UNREF(error3); @@ -120,7 +116,7 @@ static void test_copy_and_unref() { static void test_create_referencing() { grpc_error* child = grpc_error_set_str( - GRPC_ERROR_CREATE("Child"), GRPC_ERROR_STR_GRPC_MESSAGE, "message"); + GRPC_ERROR_CREATE("Child"), GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message")); grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", &child, 1); GPR_ASSERT(parent); @@ -131,11 +127,11 @@ static void test_create_referencing() { static void test_create_referencing_many() { grpc_error* children[3]; children[0] = grpc_error_set_str(GRPC_ERROR_CREATE("Child1"), - GRPC_ERROR_STR_GRPC_MESSAGE, "message"); + GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message")); children[1] = grpc_error_set_int(GRPC_ERROR_CREATE("Child2"), GRPC_ERROR_INT_HTTP2_ERROR, 5); children[2] = grpc_error_set_str(GRPC_ERROR_CREATE("Child3"), - GRPC_ERROR_STR_GRPC_MESSAGE, "message 3"); + GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message 3")); grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", children, 3); GPR_ASSERT(parent); @@ -151,7 +147,7 @@ static void print_error_string() { grpc_error_set_int(GRPC_ERROR_CREATE("Error"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNIMPLEMENTED); error = grpc_error_set_int(error, GRPC_ERROR_INT_SIZE, 666); - error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, "message"); + error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message")); // gpr_log(GPR_DEBUG, "%s", grpc_error_string(error)); GRPC_ERROR_UNREF(error); } @@ -161,11 +157,11 @@ static void print_error_string_reference() { children[0] = grpc_error_set_str( grpc_error_set_int(GRPC_ERROR_CREATE("1"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNIMPLEMENTED), - GRPC_ERROR_STR_GRPC_MESSAGE, "message for child 1"); + GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message for child 1")); children[1] = grpc_error_set_str( grpc_error_set_int(GRPC_ERROR_CREATE("2sd"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL), - GRPC_ERROR_STR_GRPC_MESSAGE, "message for child 2"); + GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message for child 2")); grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", children, 2); @@ -186,9 +182,9 @@ static void test_os_error() { GPR_ASSERT(grpc_error_get_int(error, GRPC_ERROR_INT_ERRNO, &i)); GPR_ASSERT(i == fake_errno); - const char* c = grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL); - GPR_ASSERT(c); - GPR_ASSERT(!strcmp(c, syscall)); + grpc_slice str; + GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL, &str)); + GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), syscall, GRPC_SLICE_LENGTH(str))); GRPC_ERROR_UNREF(error); } diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc index c4f6aa19d5..0f9e3c49db 100644 --- a/test/cpp/microbenchmarks/bm_error.cc +++ b/test/cpp/microbenchmarks/bm_error.cc @@ -77,7 +77,7 @@ static void BM_ErrorCreateAndSetIntAndStr(benchmark::State& state) { GRPC_ERROR_UNREF(grpc_error_set_str( grpc_error_set_int(GRPC_ERROR_CREATE("GOAWAY received"), GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)0), - GRPC_ERROR_STR_RAW_BYTES, "raw bytes")); + GRPC_ERROR_STR_RAW_BYTES, grpc_slice_from_static_string("raw bytes"))); } track_counters.Finish(state); } @@ -100,7 +100,7 @@ static void BM_ErrorCreateAndSetStrLoop(benchmark::State& state) { grpc_error* error = GRPC_ERROR_CREATE("Error"); const char* str = "hello"; while (state.KeepRunning()) { - error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, str); + error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string(str)); } GRPC_ERROR_UNREF(error); track_counters.Finish(state); @@ -253,8 +253,8 @@ static void BM_ErrorGetStatus(benchmark::State& state) { Fixture fixture; while (state.KeepRunning()) { grpc_status_code status; - const char* msg; - grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &msg, + grpc_slice slice; + grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice, NULL); } track_counters.Finish(state); |