diff options
author | Hongyu Chen <hongyu@google.com> | 2015-02-04 10:36:04 -0800 |
---|---|---|
committer | Hongyu Chen <hongyu@google.com> | 2015-02-04 10:36:04 -0800 |
commit | 1ef06e6285364a16517cb9d7ac8ce6ab6c1d35c4 (patch) | |
tree | b004b6b8f86c1bf159d5ad37ac6354827792e7b6 /test | |
parent | 484bc53582ee89a5412bab46ddb21d2cb5acabf2 (diff) |
V0 implementation of census_get_active_ops().
Diffstat (limited to 'test')
-rw-r--r-- | test/core/statistics/trace_test.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/core/statistics/trace_test.c b/test/core/statistics/trace_test.c index 6eafcf1456..18edfb433a 100644 --- a/test/core/statistics/trace_test.c +++ b/test/core/statistics/trace_test.c @@ -32,10 +32,12 @@ */ #include <string.h> +#include <stdio.h> #include "src/core/statistics/census_interface.h" #include "src/core/statistics/census_tracing.h" #include "src/core/statistics/census_tracing.h" +#include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/port_platform.h> #include <grpc/support/sync.h> @@ -172,6 +174,74 @@ static void test_trace_print(void) { census_tracing_shutdown(); } +/* Returns 1 if two ids are equal, otherwise returns 0. */ +static int ids_equal(census_op_id id1, census_op_id id2) { + return (id1.upper == id2.upper) && (id1.lower == id2.lower); +} + +static void test_get_active_ops(void) { + census_op_id id_1, id_2, id_3; + trace_obj** active_ops; + const char* annotation_txt[] = {"annotation 1", "a2"}; + int i = 0; + int n = 0; + + gpr_log(GPR_INFO, "test_get_active_ops"); + census_tracing_init(); + /* No active ops before calling start_op(). */ + active_ops = census_get_active_ops(&n); + GPR_ASSERT(active_ops == NULL); + GPR_ASSERT(n == 0); + + /* Starts one op */ + id_1 = census_tracing_start_op(); + census_add_method_tag(id_1, "foo_1"); + active_ops = census_get_active_ops(&n); + GPR_ASSERT(active_ops != NULL); + GPR_ASSERT(n == 1); + GPR_ASSERT(ids_equal(active_ops[0]->id, id_1)); + trace_obj_destroy(active_ops[0]); + gpr_free(active_ops); + active_ops = NULL; + + /* Start the second and the third ops */ + id_2 = census_tracing_start_op(); + census_add_method_tag(id_2, "foo_2"); + id_3 = census_tracing_start_op(); + census_add_method_tag(id_3, "foo_3"); + + active_ops = census_get_active_ops(&n); + GPR_ASSERT(n == 3); + for (i = 0; i < 3; i++) { + trace_obj_destroy(active_ops[i]); + } + gpr_free(active_ops); + active_ops = NULL; + + /* End the second op and add annotations to the third ops*/ + census_tracing_end_op(id_2); + census_tracing_print(id_3, annotation_txt[0]); + census_tracing_print(id_3, annotation_txt[1]); + + active_ops = census_get_active_ops(&n); + GPR_ASSERT(active_ops != NULL); + GPR_ASSERT(n == 2); + for (i = 0; i < 2; i++) { + trace_obj_destroy(active_ops[i]); + } + gpr_free(active_ops); + active_ops = NULL; + + /* End all ops. */ + census_tracing_end_op(id_1); + census_tracing_end_op(id_3); + active_ops = census_get_active_ops(&n); + GPR_ASSERT(active_ops == NULL); + GPR_ASSERT(n == 0); + + census_tracing_shutdown(); +} + int main(int argc, char** argv) { grpc_test_init(argc, argv); test_init_shutdown(); @@ -180,5 +250,6 @@ int main(int argc, char** argv) { test_concurrency(); test_add_method_tag_to_unknown_op_id(); test_trace_print(); + test_get_active_ops(); return 0; } |