aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/transport/chttp2/stream_map_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/transport/chttp2/stream_map_test.c')
-rw-r--r--test/core/transport/chttp2/stream_map_test.c275
1 files changed, 155 insertions, 120 deletions
diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c
index 81fb80f84f..87efab5fa5 100644
--- a/test/core/transport/chttp2/stream_map_test.c
+++ b/test/core/transport/chttp2/stream_map_test.c
@@ -38,193 +38,228 @@
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x)
/* test creation & destruction */
-static void test_no_op(void) {
+static void
+test_no_op (void)
+{
grpc_chttp2_stream_map map;
- LOG_TEST("test_no_op");
+ LOG_TEST ("test_no_op");
- grpc_chttp2_stream_map_init(&map, 8);
- grpc_chttp2_stream_map_destroy(&map);
+ grpc_chttp2_stream_map_init (&map, 8);
+ grpc_chttp2_stream_map_destroy (&map);
}
/* test lookup on an empty map */
-static void test_empty_find(void) {
+static void
+test_empty_find (void)
+{
grpc_chttp2_stream_map map;
- LOG_TEST("test_empty_find");
+ LOG_TEST ("test_empty_find");
- grpc_chttp2_stream_map_init(&map, 8);
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 39128));
- grpc_chttp2_stream_map_destroy(&map);
+ grpc_chttp2_stream_map_init (&map, 8);
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 39128));
+ grpc_chttp2_stream_map_destroy (&map);
}
/* test it's safe to delete twice */
-static void test_double_deletion(void) {
+static void
+test_double_deletion (void)
+{
grpc_chttp2_stream_map map;
- LOG_TEST("test_double_deletion");
-
- grpc_chttp2_stream_map_init(&map, 8);
- GPR_ASSERT(0 == grpc_chttp2_stream_map_size(&map));
- grpc_chttp2_stream_map_add(&map, 1, (void *)1);
- GPR_ASSERT((void *)1 == grpc_chttp2_stream_map_find(&map, 1));
- GPR_ASSERT(1 == grpc_chttp2_stream_map_size(&map));
- GPR_ASSERT((void *)1 == grpc_chttp2_stream_map_delete(&map, 1));
- GPR_ASSERT(0 == grpc_chttp2_stream_map_size(&map));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_delete(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_delete(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_delete(&map, 1));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 1));
- grpc_chttp2_stream_map_destroy(&map);
+ LOG_TEST ("test_double_deletion");
+
+ grpc_chttp2_stream_map_init (&map, 8);
+ GPR_ASSERT (0 == grpc_chttp2_stream_map_size (&map));
+ grpc_chttp2_stream_map_add (&map, 1, (void *) 1);
+ GPR_ASSERT ((void *) 1 == grpc_chttp2_stream_map_find (&map, 1));
+ GPR_ASSERT (1 == grpc_chttp2_stream_map_size (&map));
+ GPR_ASSERT ((void *) 1 == grpc_chttp2_stream_map_delete (&map, 1));
+ GPR_ASSERT (0 == grpc_chttp2_stream_map_size (&map));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_delete (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_delete (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_delete (&map, 1));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 1));
+ grpc_chttp2_stream_map_destroy (&map);
}
/* test add & lookup */
-static void test_basic_add_find(gpr_uint32 n) {
+static void
+test_basic_add_find (gpr_uint32 n)
+{
grpc_chttp2_stream_map map;
gpr_uint32 i;
size_t got;
- LOG_TEST("test_basic_add_find");
- gpr_log(GPR_INFO, "n = %d", n);
-
- grpc_chttp2_stream_map_init(&map, 8);
- GPR_ASSERT(0 == grpc_chttp2_stream_map_size(&map));
- for (i = 1; i <= n; i++) {
- grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i);
- }
- GPR_ASSERT(n == grpc_chttp2_stream_map_size(&map));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, 0));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(&map, n + 1));
- for (i = 1; i <= n; i++) {
- got = (gpr_uintptr)grpc_chttp2_stream_map_find(&map, i);
- GPR_ASSERT(i == got);
- }
- grpc_chttp2_stream_map_destroy(&map);
+ LOG_TEST ("test_basic_add_find");
+ gpr_log (GPR_INFO, "n = %d", n);
+
+ grpc_chttp2_stream_map_init (&map, 8);
+ GPR_ASSERT (0 == grpc_chttp2_stream_map_size (&map));
+ for (i = 1; i <= n; i++)
+ {
+ grpc_chttp2_stream_map_add (&map, i, (void *) (gpr_uintptr) i);
+ }
+ GPR_ASSERT (n == grpc_chttp2_stream_map_size (&map));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, 0));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (&map, n + 1));
+ for (i = 1; i <= n; i++)
+ {
+ got = (gpr_uintptr) grpc_chttp2_stream_map_find (&map, i);
+ GPR_ASSERT (i == got);
+ }
+ grpc_chttp2_stream_map_destroy (&map);
}
/* verify that for_each gets the right values during test_delete_evens_XXX */
-static void verify_for_each(void *user_data, gpr_uint32 stream_id, void *ptr) {
+static void
+verify_for_each (void *user_data, gpr_uint32 stream_id, void *ptr)
+{
gpr_uint32 *for_each_check = user_data;
- GPR_ASSERT(ptr);
- GPR_ASSERT(*for_each_check == stream_id);
+ GPR_ASSERT (ptr);
+ GPR_ASSERT (*for_each_check == stream_id);
*for_each_check += 2;
}
-static void check_delete_evens(grpc_chttp2_stream_map *map, gpr_uint32 n) {
+static void
+check_delete_evens (grpc_chttp2_stream_map * map, gpr_uint32 n)
+{
gpr_uint32 for_each_check = 1;
gpr_uint32 i;
size_t got;
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, 0));
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, n + 1));
- for (i = 1; i <= n; i++) {
- if (i & 1) {
- got = (gpr_uintptr)grpc_chttp2_stream_map_find(map, i);
- GPR_ASSERT(i == got);
- } else {
- GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, i));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (map, 0));
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (map, n + 1));
+ for (i = 1; i <= n; i++)
+ {
+ if (i & 1)
+ {
+ got = (gpr_uintptr) grpc_chttp2_stream_map_find (map, i);
+ GPR_ASSERT (i == got);
+ }
+ else
+ {
+ GPR_ASSERT (NULL == grpc_chttp2_stream_map_find (map, i));
+ }
+ }
+
+ grpc_chttp2_stream_map_for_each (map, verify_for_each, &for_each_check);
+ if (n & 1)
+ {
+ GPR_ASSERT (for_each_check == n + 2);
+ }
+ else
+ {
+ GPR_ASSERT (for_each_check == n + 1);
}
- }
-
- grpc_chttp2_stream_map_for_each(map, verify_for_each, &for_each_check);
- if (n & 1) {
- GPR_ASSERT(for_each_check == n + 2);
- } else {
- GPR_ASSERT(for_each_check == n + 1);
- }
}
/* add a bunch of keys, delete the even ones, and make sure the map is
consistent */
-static void test_delete_evens_sweep(gpr_uint32 n) {
+static void
+test_delete_evens_sweep (gpr_uint32 n)
+{
grpc_chttp2_stream_map map;
gpr_uint32 i;
- LOG_TEST("test_delete_evens_sweep");
- gpr_log(GPR_INFO, "n = %d", n);
-
- grpc_chttp2_stream_map_init(&map, 8);
- for (i = 1; i <= n; i++) {
- grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i);
- }
- for (i = 1; i <= n; i++) {
- if ((i & 1) == 0) {
- GPR_ASSERT((void *)(gpr_uintptr)i ==
- grpc_chttp2_stream_map_delete(&map, i));
+ LOG_TEST ("test_delete_evens_sweep");
+ gpr_log (GPR_INFO, "n = %d", n);
+
+ grpc_chttp2_stream_map_init (&map, 8);
+ for (i = 1; i <= n; i++)
+ {
+ grpc_chttp2_stream_map_add (&map, i, (void *) (gpr_uintptr) i);
+ }
+ for (i = 1; i <= n; i++)
+ {
+ if ((i & 1) == 0)
+ {
+ GPR_ASSERT ((void *) (gpr_uintptr) i == grpc_chttp2_stream_map_delete (&map, i));
+ }
}
- }
- check_delete_evens(&map, n);
- grpc_chttp2_stream_map_destroy(&map);
+ check_delete_evens (&map, n);
+ grpc_chttp2_stream_map_destroy (&map);
}
/* add a bunch of keys, delete the even ones immediately, and make sure the map
is consistent */
-static void test_delete_evens_incremental(gpr_uint32 n) {
+static void
+test_delete_evens_incremental (gpr_uint32 n)
+{
grpc_chttp2_stream_map map;
gpr_uint32 i;
- LOG_TEST("test_delete_evens_incremental");
- gpr_log(GPR_INFO, "n = %d", n);
-
- grpc_chttp2_stream_map_init(&map, 8);
- for (i = 1; i <= n; i++) {
- grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i);
- if ((i & 1) == 0) {
- grpc_chttp2_stream_map_delete(&map, i);
+ LOG_TEST ("test_delete_evens_incremental");
+ gpr_log (GPR_INFO, "n = %d", n);
+
+ grpc_chttp2_stream_map_init (&map, 8);
+ for (i = 1; i <= n; i++)
+ {
+ grpc_chttp2_stream_map_add (&map, i, (void *) (gpr_uintptr) i);
+ if ((i & 1) == 0)
+ {
+ grpc_chttp2_stream_map_delete (&map, i);
+ }
}
- }
- check_delete_evens(&map, n);
- grpc_chttp2_stream_map_destroy(&map);
+ check_delete_evens (&map, n);
+ grpc_chttp2_stream_map_destroy (&map);
}
/* add a bunch of keys, delete old ones after some time, ensure the
backing array does not grow */
-static void test_periodic_compaction(gpr_uint32 n) {
+static void
+test_periodic_compaction (gpr_uint32 n)
+{
grpc_chttp2_stream_map map;
gpr_uint32 i;
gpr_uint32 del;
- LOG_TEST("test_periodic_compaction");
- gpr_log(GPR_INFO, "n = %d", n);
-
- grpc_chttp2_stream_map_init(&map, 16);
- GPR_ASSERT(map.capacity == 16);
- for (i = 1; i <= n; i++) {
- grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i);
- if (i > 8) {
- del = i - 8;
- GPR_ASSERT((void *)(gpr_uintptr)del ==
- grpc_chttp2_stream_map_delete(&map, del));
+ LOG_TEST ("test_periodic_compaction");
+ gpr_log (GPR_INFO, "n = %d", n);
+
+ grpc_chttp2_stream_map_init (&map, 16);
+ GPR_ASSERT (map.capacity == 16);
+ for (i = 1; i <= n; i++)
+ {
+ grpc_chttp2_stream_map_add (&map, i, (void *) (gpr_uintptr) i);
+ if (i > 8)
+ {
+ del = i - 8;
+ GPR_ASSERT ((void *) (gpr_uintptr) del == grpc_chttp2_stream_map_delete (&map, del));
+ }
}
- }
- GPR_ASSERT(map.capacity == 16);
- grpc_chttp2_stream_map_destroy(&map);
+ GPR_ASSERT (map.capacity == 16);
+ grpc_chttp2_stream_map_destroy (&map);
}
-int main(int argc, char **argv) {
+int
+main (int argc, char **argv)
+{
gpr_uint32 n = 1;
gpr_uint32 prev = 1;
gpr_uint32 tmp;
- grpc_test_init(argc, argv);
+ grpc_test_init (argc, argv);
- test_no_op();
- test_empty_find();
- test_double_deletion();
+ test_no_op ();
+ test_empty_find ();
+ test_double_deletion ();
- while (n < 100000) {
- test_basic_add_find(n);
- test_delete_evens_sweep(n);
- test_delete_evens_incremental(n);
- test_periodic_compaction(n);
+ while (n < 100000)
+ {
+ test_basic_add_find (n);
+ test_delete_evens_sweep (n);
+ test_delete_evens_incremental (n);
+ test_periodic_compaction (n);
- tmp = n;
- n += prev;
- prev = tmp;
- }
+ tmp = n;
+ n += prev;
+ prev = tmp;
+ }
return 0;
}