From 7536af02cf218f8dcb1368bec6d86c65db95c9b4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Dec 2015 13:49:30 -0800 Subject: Eliminate gpr_ int types - and insist on C99 variants instead --- test/core/statistics/census_log_tests.c | 64 ++++++++++++++++----------------- test/core/statistics/hash_table_test.c | 20 +++++------ 2 files changed, 42 insertions(+), 42 deletions(-) (limited to 'test/core/statistics') diff --git a/test/core/statistics/census_log_tests.c b/test/core/statistics/census_log_tests.c index 6968a5646d..aac20fd96a 100644 --- a/test/core/statistics/census_log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -47,22 +47,22 @@ /* Fills in 'record' of size 'size'. Each byte in record is filled in with the same value. The value is extracted from 'record' pointer. */ static void write_record(char *record, size_t size) { - char data = (gpr_uintptr)record % 255; + char data = (uintptr_t)record % 255; memset(record, data, size); } /* Reads fixed size records. Returns the number of records read in 'num_records'. */ static void read_records(size_t record_size, const char *buffer, - size_t buffer_size, gpr_int32 *num_records) { - gpr_int32 ix; + size_t buffer_size, int32_t *num_records) { + int32_t ix; GPR_ASSERT(buffer_size >= record_size); GPR_ASSERT(buffer_size % record_size == 0); *num_records = buffer_size / record_size; for (ix = 0; ix < *num_records; ++ix) { size_t jx; const char *record = buffer + (record_size * ix); - char data = (gpr_uintptr)record % 255; + char data = (uintptr_t)record % 255; for (jx = 0; jx < record_size; ++jx) { GPR_ASSERT(data == record[jx]); } @@ -72,14 +72,14 @@ static void read_records(size_t record_size, const char *buffer, /* Tries to write the specified number of records. Stops when the log gets full. Returns the number of records written. Spins for random number of times, up to 'max_spin_count', between writes. */ -static size_t write_records_to_log(int writer_id, gpr_int32 record_size, - gpr_int32 num_records, - gpr_int32 max_spin_count) { - gpr_int32 ix; +static size_t write_records_to_log(int writer_id, int32_t record_size, + int32_t num_records, + int32_t max_spin_count) { + int32_t ix; int counter = 0; for (ix = 0; ix < num_records; ++ix) { - gpr_int32 jx; - gpr_int32 spin_count = max_spin_count ? rand() % max_spin_count : 0; + int32_t jx; + int32_t spin_count = max_spin_count ? rand() % max_spin_count : 0; char *record; if (counter++ == num_records / 10) { printf(" Writer %d: %d out of %d written\n", writer_id, ix, @@ -106,7 +106,7 @@ static size_t perform_read_iteration(size_t record_size) { size_t records_read = 0; census_log_init_reader(); while ((read_buffer = census_log_read_next(&bytes_available))) { - gpr_int32 num_records = 0; + int32_t num_records = 0; read_records(record_size, (const char *)read_buffer, bytes_available, &num_records); records_read += num_records; @@ -122,14 +122,14 @@ static void assert_log_empty(void) { } /* Given log size and record size, computes the minimum usable space. */ -static gpr_int32 min_usable_space(size_t log_size, size_t record_size) { - gpr_int32 usable_space; - gpr_int32 num_blocks = +static int32_t min_usable_space(size_t log_size, size_t record_size) { + int32_t usable_space; + int32_t num_blocks = GPR_MAX(log_size / CENSUS_LOG_MAX_RECORD_SIZE, gpr_cpu_num_cores()); - gpr_int32 waste_per_block = CENSUS_LOG_MAX_RECORD_SIZE % record_size; + int32_t waste_per_block = CENSUS_LOG_MAX_RECORD_SIZE % record_size; /* In the worst case, all except one core-local block is full. */ - gpr_int32 num_full_blocks = num_blocks - 1; - usable_space = (gpr_int32)log_size - + int32_t num_full_blocks = num_blocks - 1; + usable_space = (int32_t)log_size - (num_full_blocks * CENSUS_LOG_MAX_RECORD_SIZE) - ((num_blocks - num_full_blocks) * waste_per_block); GPR_ASSERT(usable_space > 0); @@ -142,9 +142,9 @@ static gpr_int32 min_usable_space(size_t log_size, size_t record_size) { match the number of records read. */ static void fill_log(size_t log_size, int no_fragmentation, int circular_log) { int size; - gpr_int32 records_written; - gpr_int32 usable_space; - gpr_int32 records_read; + int32_t records_written; + int32_t usable_space; + int32_t records_read; if (no_fragmentation) { int log2size = rand() % (CENSUS_LOG_2_MAX_RECORD_SIZE + 1); size = (1 << log2size); @@ -175,7 +175,7 @@ typedef struct writer_thread_args { /* Record size. */ size_t record_size; /* Number of records to write. */ - gpr_int32 num_records; + int32_t num_records; /* Used to signal when writer is complete */ gpr_cv *done; gpr_mu *mu; @@ -187,7 +187,7 @@ typedef struct writer_thread_args { static void writer_thread(void *arg) { writer_thread_args *args = (writer_thread_args *)arg; /* Maximum number of times to spin between writes. */ - static const gpr_int32 MAX_SPIN_COUNT = 50; + static const int32_t MAX_SPIN_COUNT = 50; int records_written = 0; printf(" Writer: %d\n", args->index); while (records_written < args->num_records) { @@ -215,9 +215,9 @@ typedef struct reader_thread_args { /* Record size. */ size_t record_size; /* Interval between read iterations. */ - gpr_int32 read_iteration_interval_in_msec; + int32_t read_iteration_interval_in_msec; /* Total number of records. */ - gpr_int32 total_records; + int32_t total_records; /* Signalled when reader should stop. */ gpr_cv stop; int stop_flag; @@ -231,9 +231,9 @@ typedef struct reader_thread_args { stopped via gpr_cv_signal(&args->stop). Sleeps for 'read_interval_in_msec' between read iterations. */ static void reader_thread(void *arg) { - gpr_int32 records_read = 0; + int32_t records_read = 0; reader_thread_args *args = (reader_thread_args *)arg; - gpr_int32 num_iterations = 0; + int32_t num_iterations = 0; gpr_timespec interval; int counter = 0; printf(" Reader starting\n"); @@ -268,9 +268,9 @@ static void reader_thread(void *arg) { #define NUM_WRITERS 5 static void multiple_writers_single_reader(int circular_log) { /* Sleep interval between read iterations. */ - static const gpr_int32 READ_ITERATION_INTERVAL_IN_MSEC = 10; + static const int32_t READ_ITERATION_INTERVAL_IN_MSEC = 10; /* Number of records written by each writer. */ - static const gpr_int32 NUM_RECORDS_PER_WRITER = 10 * 1024 * 1024; + static const int32_t NUM_RECORDS_PER_WRITER = 10 * 1024 * 1024; /* Maximum record size. */ static const size_t MAX_RECORD_SIZE = 10; int ix; @@ -282,7 +282,7 @@ static void multiple_writers_single_reader(int circular_log) { gpr_cv reader_done; gpr_mu reader_mu; /* protects reader_done and reader.running */ reader_thread_args reader; - gpr_int32 record_size = 1 + rand() % MAX_RECORD_SIZE; + int32_t record_size = 1 + rand() % MAX_RECORD_SIZE; printf(" Record size: %d\n", record_size); /* Create and start writers. */ gpr_cv_init(&writers_done); @@ -417,8 +417,8 @@ void test_read_pending_record(void) { /* Tries reading beyond pending write. */ void test_read_beyond_pending_record(void) { /* Start a write. */ - gpr_uint32 incomplete_record_size = 10; - gpr_uint32 complete_record_size = 20; + uint32_t incomplete_record_size = 10; + uint32_t complete_record_size = 20; size_t bytes_available; void *complete_record; const void *record_read; @@ -459,7 +459,7 @@ void test_detached_while_reading(void) { size_t bytes_available; const void *record_read; void *record_written; - gpr_uint32 block_read = 0; + uint32_t block_read = 0; printf("Starting test: detached while reading\n"); setup_test(0); /* Start a write. */ diff --git a/test/core/statistics/hash_table_test.c b/test/core/statistics/hash_table_test.c index efebd790f2..3b119dbc0c 100644 --- a/test/core/statistics/hash_table_test.c +++ b/test/core/statistics/hash_table_test.c @@ -44,9 +44,9 @@ #include #include "test/core/util/test_config.h" -static gpr_uint64 hash64(const void *k) { +static uint64_t hash64(const void *k) { size_t len = strlen(k); - gpr_uint64 higher = gpr_murmur_hash3((const char *)k, len / 2, 0); + uint64_t higher = gpr_murmur_hash3((const char *)k, len / 2, 0); return higher << 32 | gpr_murmur_hash3((const char *)(k) + len / 2, len - len / 2, 0); } @@ -55,7 +55,7 @@ static int cmp_str_keys(const void *k1, const void *k2) { return strcmp((const char *)k1, (const char *)k2); } -static gpr_uint64 force_collision(const void *k) { +static uint64_t force_collision(const void *k) { return (1997 + hash64(k) % 3); } @@ -85,8 +85,8 @@ static void test_create_table(void) { static void test_table_with_int_key(void) { census_ht_option opt = {CENSUS_HT_UINT64, 7, NULL, NULL, NULL, NULL}; census_ht *ht = census_ht_create(&opt); - gpr_uint64 i = 0; - gpr_uint64 sum_of_keys = 0; + uint64_t i = 0; + uint64_t sum_of_keys = 0; size_t num_elements; census_ht_kv *elements = NULL; GPR_ASSERT(ht != NULL); @@ -97,15 +97,15 @@ static void test_table_with_int_key(void) { for (i = 0; i < 20; ++i) { census_ht_key key; key.val = i; - census_ht_insert(ht, key, (void *)(gpr_intptr)i); + census_ht_insert(ht, key, (void *)(intptr_t)i); GPR_ASSERT(census_ht_get_size(ht) == i + 1); } for (i = 0; i < 20; i++) { - gpr_uint64 *val = NULL; + uint64_t *val = NULL; census_ht_key key; key.val = i; val = census_ht_find(ht, key); - GPR_ASSERT(val == (void *)(gpr_intptr)i); + GPR_ASSERT(val == (void *)(intptr_t)i); } elements = census_ht_get_all_elements(ht, &num_elements); GPR_ASSERT(elements != NULL); @@ -189,7 +189,7 @@ static void test_insertion_and_deletion_with_high_collision_rate(void) { &cmp_str_keys, NULL, NULL}; census_ht *ht = census_ht_create(&opt); char key_str[1000][GPR_LTOA_MIN_BUFSIZE]; - gpr_uint64 val = 0; + uint64_t val = 0; unsigned i = 0; for (i = 0; i < 1000; i++) { census_ht_key key; @@ -246,7 +246,7 @@ static void test_table_with_string_key(void) { for (i = 0; i < 9; i++) { census_ht_key key; int *val_ptr; - gpr_uint32 expected_tbl_sz = 9 - i; + uint32_t expected_tbl_sz = 9 - i; GPR_ASSERT(census_ht_get_size(ht) == expected_tbl_sz); key.ptr = (void *)(keys[i]); val_ptr = census_ht_find(ht, key); -- cgit v1.2.3