diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c29815e..4825d9bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,13 +32,19 @@ jobs: - uses: actions/checkout@v2 - name: Prepare run: bash scripts/install_dependency.sh - - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Configure CMake with LSan + run: | + cmake -B ${{github.workspace}}/build \ + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ + -DCMAKE_C_FLAGS="-fsanitize=leak" \ + -DCMAKE_CXX_FLAGS="-fsanitize=leak" - name: Build run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} - - name: Test + - name: Test with LSan working-directory: ${{github.workspace}}/build - run: ctest -C ${{env.BUILD_TYPE}} + run: | + export ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:verbosity=1" + ctest -C ${{env.BUILD_TYPE}} --output-on-failure selfhosted: runs-on: self-hosted diff --git a/libCacheSim/cache/eviction/LFUDA.c b/libCacheSim/cache/eviction/LFUDA.c index e1506cac..974af3c3 100644 --- a/libCacheSim/cache/eviction/LFUDA.c +++ b/libCacheSim/cache/eviction/LFUDA.c @@ -58,7 +58,8 @@ static void free_list_node(void *list_node); */ cache_t *LFUDA_init(const common_cache_params_t ccache_params, const char *cache_specific_params) { - cache_t *cache = cache_struct_init("LFUDA", ccache_params, cache_specific_params); + cache_t *cache = + cache_struct_init("LFUDA", ccache_params, cache_specific_params); cache->cache_init = LFUDA_init; cache->cache_free = LFUDA_free; cache->get = LFUDA_get; @@ -102,6 +103,7 @@ cache_t *LFUDA_init(const common_cache_params_t ccache_params, static void LFUDA_free(cache_t *cache) { LFUDA_params_t *params = (LFUDA_params_t *)(cache->eviction_params); g_hash_table_destroy(params->freq_map); + free(params); cache_struct_free(cache); } @@ -216,7 +218,9 @@ static cache_obj_t *LFUDA_insert(cache_t *cache, const request_t *req) { memset(new_node, 0, sizeof(freq_node_t)); new_node->freq = cache_obj->lfu.freq; g_hash_table_insert(params->freq_map, key, new_node); - params->max_freq = params->max_freq < cache_obj->lfu.freq ? cache_obj->lfu.freq : params->max_freq; + params->max_freq = params->max_freq < cache_obj->lfu.freq + ? cache_obj->lfu.freq + : params->max_freq; } else { DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq); } @@ -354,7 +358,7 @@ static void update_min_freq(LFUDA_params_t *params) { break; } } - // If cache is empty, min_freq will be unchanged. + // If cache is empty, min_freq will be unchanged. DEBUG_ASSERT(params->min_freq >= old_min_freq); } diff --git a/libCacheSim/cache/eviction/LIRS.c b/libCacheSim/cache/eviction/LIRS.c index 9e0ba80a..5a6c21e3 100644 --- a/libCacheSim/cache/eviction/LIRS.c +++ b/libCacheSim/cache/eviction/LIRS.c @@ -27,6 +27,13 @@ typedef struct LIRS_params { uint64_t nonresident; } LIRS_params_t; +/** + * @brief local request for thread local storage + */ +static __thread request_t *req_local_hit_RD_HIRinQ = NULL; +static __thread request_t *req_local_evictLIR = NULL; +static __thread request_t *req_local_evictHIR = NULL; + // *********************************************************************** // **** **** // **** function declarations **** @@ -125,6 +132,20 @@ static void LIRS_free(cache_t *cache) { params->LRU_s->cache_free(params->LRU_s); params->LRU_q->cache_free(params->LRU_q); params->LRU_nh->cache_free(params->LRU_nh); + + if (req_local_hit_RD_HIRinQ != NULL) { + free_request(req_local_hit_RD_HIRinQ); + req_local_hit_RD_HIRinQ = NULL; + } + if (req_local_evictLIR != NULL) { + free_request(req_local_evictLIR); + req_local_evictLIR = NULL; + } + if (req_local_evictHIR != NULL) { + free_request(req_local_evictHIR); + req_local_evictHIR = NULL; + } + my_free(sizeof(LIRS_params_t), params); cache_struct_free(cache); } @@ -553,9 +574,10 @@ static cache_obj_t *hit_RD_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s, LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params); if (cache_obj_q != NULL) { - params->hirs_count -= cache_obj_q->obj_size; + int64_t obj_size = cache_obj_q->obj_size; + params->hirs_count -= obj_size; params->LRU_q->remove(params->LRU_q, cache_obj_q->obj_id); - cache->occupied_byte -= cache_obj_q->obj_size; + cache->occupied_byte -= obj_size; cache->n_obj--; } @@ -583,19 +605,17 @@ static cache_obj_t *hit_NR_HIRinS(cache_t *cache, cache_obj_t *cache_obj_s) { static cache_obj_t *hit_RD_HIRinQ(cache_t *cache, cache_obj_t *cache_obj_q) { LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params); - - static __thread request_t *req_local = NULL; - if (req_local == NULL) { - req_local = new_request(); + if (req_local_hit_RD_HIRinQ == NULL) { + req_local_hit_RD_HIRinQ = new_request(); } - copy_cache_obj_to_request(req_local, cache_obj_q); + copy_cache_obj_to_request(req_local_hit_RD_HIRinQ, cache_obj_q); while (params->lirs_count + cache_obj_q->obj_size > params->lirs_limit) { evictLIR(cache); } - params->LRU_s->insert(params->LRU_s, req_local); + params->LRU_s->insert(params->LRU_s, req_local_hit_RD_HIRinQ); cache_obj_t *obj_to_update = - params->LRU_s->find(params->LRU_s, req_local, false); + params->LRU_s->find(params->LRU_s, req_local_hit_RD_HIRinQ, false); obj_to_update->LIRS.is_LIR = false; obj_to_update->LIRS.in_cache = true; @@ -606,30 +626,30 @@ static void evictLIR(cache_t *cache) { LIRS_params_t *params = (LIRS_params_t *)(cache->eviction_params); cache_obj_t *obj_to_evict = params->LRU_s->to_evict(params->LRU_s, NULL); - static __thread request_t *req_local = NULL; - if (req_local == NULL) { - req_local = new_request(); + if (req_local_evictLIR == NULL) { + req_local_evictLIR = new_request(); } - copy_cache_obj_to_request(req_local, obj_to_evict); + copy_cache_obj_to_request(req_local_evictLIR, obj_to_evict); params->lirs_count -= obj_to_evict->obj_size; params->LRU_s->evict(params->LRU_s, NULL); - cache->occupied_byte -= (req_local->obj_size + cache->obj_md_size); + cache->occupied_byte -= (req_local_evictLIR->obj_size + cache->obj_md_size); cache->n_obj -= 1; - if ((uint64_t)req_local->obj_size <= params->hirs_limit) { - while ((uint64_t)params->hirs_count + req_local->obj_size > params->hirs_limit) { + if ((uint64_t)req_local_evictLIR->obj_size <= params->hirs_limit) { + while ((uint64_t)params->hirs_count + req_local_evictLIR->obj_size > + params->hirs_limit) { evictHIR(cache); } - params->LRU_q->insert(params->LRU_q, req_local); + params->LRU_q->insert(params->LRU_q, req_local_evictLIR); cache_obj_t *obj_to_update = - params->LRU_q->find(params->LRU_q, req_local, false); + params->LRU_q->find(params->LRU_q, req_local_evictLIR, false); obj_to_update->LIRS.is_LIR = false; obj_to_update->LIRS.in_cache = true; - params->hirs_count += req_local->obj_size; - cache->occupied_byte += (req_local->obj_size + cache->obj_md_size); + params->hirs_count += req_local_evictLIR->obj_size; + cache->occupied_byte += (req_local_evictLIR->obj_size + cache->obj_md_size); cache->n_obj += 1; } @@ -642,24 +662,23 @@ static bool evictHIR(cache_t *cache) { cache_obj_t *obj_to_evict = params->LRU_q->to_evict(params->LRU_q, NULL); // update the corresponding block in S to be non-resident - static __thread request_t *req_local = NULL; - if (req_local == NULL) { - req_local = new_request(); + if (req_local_evictHIR == NULL) { + req_local_evictHIR = new_request(); } - copy_cache_obj_to_request(req_local, obj_to_evict); + copy_cache_obj_to_request(req_local_evictHIR, obj_to_evict); params->hirs_count -= obj_to_evict->obj_size; params->LRU_q->evict(params->LRU_q, NULL); cache_obj_t *obj_to_update = - params->LRU_s->find(params->LRU_s, req_local, false); + params->LRU_s->find(params->LRU_s, req_local_evictHIR, false); if (obj_to_update != NULL) { obj_to_update->LIRS.in_cache = false; - params->LRU_nh->insert(params->LRU_nh, req_local); + params->LRU_nh->insert(params->LRU_nh, req_local_evictHIR); params->nonresident += obj_to_update->obj_size; } - cache->occupied_byte -= (req_local->obj_size + cache->obj_md_size); + cache->occupied_byte -= (req_local_evictHIR->obj_size + cache->obj_md_size); cache->n_obj -= 1; return true; diff --git a/libCacheSim/cache/eviction/LRU.c b/libCacheSim/cache/eviction/LRU.c index 95dc2de6..7684731d 100644 --- a/libCacheSim/cache/eviction/LRU.c +++ b/libCacheSim/cache/eviction/LRU.c @@ -86,7 +86,11 @@ cache_t *LRU_init(const common_cache_params_t ccache_params, * * @param cache */ -static void LRU_free(cache_t *cache) { cache_struct_free(cache); } +static void LRU_free(cache_t *cache) { + LRU_params_t *params = (LRU_params_t *)cache->eviction_params; + free(params); + cache_struct_free(cache); +} /** * @brief this function is the user facing API diff --git a/libCacheSim/cache/eviction/SLRU.c b/libCacheSim/cache/eviction/SLRU.c index ba9748fe..f3d71a16 100644 --- a/libCacheSim/cache/eviction/SLRU.c +++ b/libCacheSim/cache/eviction/SLRU.c @@ -202,6 +202,7 @@ static void SLRU_free(cache_t *cache) { free(params->lru_tails); free(params->lru_n_objs); free(params->lru_n_bytes); + free(params); cache_struct_free(cache); } @@ -450,8 +451,9 @@ static void SLRU_parse_params(cache_t *cache, params->n_seg = n_seg; params->lru_max_n_bytes = calloc(params->n_seg, sizeof(int64_t)); for (int i = 0; i < n_seg; i++) { - params->lru_max_n_bytes[i] = (int64_t)( - (double)seg_size_array[i] / seg_size_sum * cache->cache_size); + params->lru_max_n_bytes[i] = + (int64_t)((double)seg_size_array[i] / seg_size_sum * + cache->cache_size); } } else if (strcasecmp(key, "print") == 0) { printf("current parameters: %s\n", SLRU_current_params(cache, params)); diff --git a/libCacheSim/mrcProfiler/mrcProfiler.cpp b/libCacheSim/mrcProfiler/mrcProfiler.cpp index 2ccc86ed..29f05d9a 100644 --- a/libCacheSim/mrcProfiler/mrcProfiler.cpp +++ b/libCacheSim/mrcProfiler/mrcProfiler.cpp @@ -324,4 +324,7 @@ void mrcProfiler::MRCProfilerMINISIM::run() { hit_size_vec[i] = sum_obj_size_req - result[i].n_miss_byte; } } + // clean up + my_free(sizeof(cache_stat_t) * mrc_size_vec.size(), result); + free_request(req); } \ No newline at end of file diff --git a/libCacheSim/traceReader/reader.c b/libCacheSim/traceReader/reader.c index 11a4a474..ff919ed9 100644 --- a/libCacheSim/traceReader/reader.c +++ b/libCacheSim/traceReader/reader.c @@ -39,7 +39,8 @@ extern "C" { // ssize_t getline(char **lineptr, size_t *n, FILE *stream); // #endif -reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_type, +reader_t *setup_reader(const char *const trace_path, + const trace_type_e trace_type, const reader_init_param_t *const init_params) { static bool _info_printed = false; @@ -84,7 +85,8 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty if (init_params != NULL) { memcpy(&reader->init_params, init_params, sizeof(reader_init_param_t)); - if (init_params->binary_fmt_str != NULL) reader->init_params.binary_fmt_str = strdup(init_params->binary_fmt_str); + if (init_params->binary_fmt_str != NULL) + reader->init_params.binary_fmt_str = strdup(init_params->binary_fmt_str); reader->ignore_obj_size = init_params->ignore_obj_size; reader->ignore_size_zero_req = init_params->ignore_size_zero_req; @@ -94,7 +96,8 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty reader->mmap_offset = init_params->trace_start_offset; reader->cap_at_n_req = init_params->cap_at_n_req; reader->block_size = init_params->block_size; - if (init_params->sampler != NULL) reader->sampler = init_params->sampler->clone(init_params->sampler); + if (init_params->sampler != NULL) + reader->sampler = init_params->sampler->clone(init_params->sampler); } else { memset(&reader->init_params, 0, sizeof(reader_init_param_t)); } @@ -114,7 +117,8 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty } reader->file_size = st.st_size; - if (reader->trace_type == CSV_TRACE || reader->trace_type == PLAIN_TXT_TRACE) { + if (reader->trace_type == CSV_TRACE || + reader->trace_type == PLAIN_TXT_TRACE) { reader->file = fopen(reader->trace_path, "rb"); if (reader->file == 0) { ERROR("Failed to open %s: %s\n", reader->trace_path, strerror(errno)); @@ -137,7 +141,8 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty if ((reader->mapped_file) == MAP_FAILED) { close(fd); reader->mapped_file = NULL; - ERROR("Unable to allocate %llu bytes of memory, %s\n", (unsigned long long)st.st_size, strerror(errno)); + ERROR("Unable to allocate %llu bytes of memory, %s\n", + (unsigned long long)st.st_size, strerror(errno)); abort(); } } @@ -147,7 +152,8 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty reader->trace_format = TXT_TRACE_FORMAT; csv_setup_reader(reader); if (!check_delimiter(reader, init_params->delimiter)) { - ERROR("The trace does not use delimiter '%c', please check\n", init_params->delimiter); + ERROR("The trace does not use delimiter '%c', please check\n", + init_params->delimiter); } break; case PLAIN_TXT_TRACE: @@ -194,7 +200,9 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty WARN( "trace file size %lu - %lu is not multiple of item size %lu, mod " "%lu\n", - (unsigned long)reader->file_size, (unsigned long)reader->trace_start_offset, (unsigned long)reader->item_size, + (unsigned long)reader->file_size, + (unsigned long)reader->trace_start_offset, + (unsigned long)reader->item_size, (unsigned long)reader->file_size % reader->item_size); } @@ -227,14 +235,15 @@ reader_t *setup_reader(const char *const trace_path, const trace_type_e trace_ty */ int read_one_req(reader_t *const reader, request_t *const req) { if (reader->mmap_offset >= reader->file_size) { - DEBUG("read_one_req: end of file, current mmap_offset %zu, file size %zu\n", reader->mmap_offset, - reader->file_size); + DEBUG("read_one_req: end of file, current mmap_offset %zu, file size %zu\n", + reader->mmap_offset, reader->file_size); req->valid = false; return 1; } if (reader->cap_at_n_req > 1 && reader->n_read_req >= reader->cap_at_n_req) { - DEBUG("read_one_req: processed %ld requests capped by the user\n", (long)reader->n_read_req); + DEBUG("read_one_req: processed %ld requests capped by the user\n", + (long)reader->n_read_req); req->valid = false; return 1; } @@ -305,8 +314,8 @@ int read_one_req(reader_t *const reader, request_t *const req) { sampler_t *sampler = reader->sampler; reader->sampler = NULL; while (!sampler->sample(sampler, req)) { - VVERBOSE("skip one req: time %lu, obj_id %lu, size %lu at offset %zu\n", req->clock_time, req->obj_id, - req->obj_size, offset_before_read); + VVERBOSE("skip one req: time %lu, obj_id %lu, size %lu at offset %zu\n", + req->clock_time, req->obj_id, req->obj_size, offset_before_read); if (reader->read_direction == READ_FORWARD) { status = read_one_req(reader, req); } else { @@ -324,8 +333,8 @@ int read_one_req(reader_t *const reader, request_t *const req) { req->obj_size = 1; } - VVERBOSE("read one req: time %lu, obj_id %lu, size %lu at offset %zu\n", req->clock_time, req->obj_id, req->obj_size, - offset_before_read); + VVERBOSE("read one req: time %lu, obj_id %lu, size %lu at offset %zu\n", + req->clock_time, req->obj_id, req->obj_size, offset_before_read); return status; } @@ -354,7 +363,8 @@ int go_back_one_req(reader_t *const reader) { seek_size = MIN(PER_SEEK_SIZE, max_seek_size - total_seek_size); total_seek_size += seek_size; fseek(reader->file, -seek_size, SEEK_CUR); - ssize_t read_size = fread(reader->line_buf, 1, seek_size - 1, reader->file); + ssize_t read_size = + fread(reader->line_buf, 1, seek_size - 1, reader->file); reader->line_buf[read_size - 1] = 0; char *last_line_end = strrchr(reader->line_buf, '\n'); @@ -385,7 +395,8 @@ int go_back_one_req(reader_t *const reader) { } break; case BINARY_TRACE_FORMAT: - if (reader->mmap_offset >= reader->trace_start_offset + reader->item_size) { + if (reader->mmap_offset >= + reader->trace_start_offset + reader->item_size) { reader->mmap_offset -= (reader->item_size); return 0; } else { @@ -512,6 +523,8 @@ int64_t get_num_of_req(reader_t *const reader) { while (read_one_req(reader_copy, req) == 0) { n_req++; } + free_request(req); + close_reader(reader_copy); } else { ERROR("should not reach here\n"); abort(); @@ -521,7 +534,8 @@ int64_t get_num_of_req(reader_t *const reader) { } reader_t *clone_reader(const reader_t *const reader_in) { - reader_t *reader = setup_reader(reader_in->trace_path, reader_in->trace_type, &reader_in->init_params); + reader_t *reader = setup_reader(reader_in->trace_path, reader_in->trace_type, + &reader_in->init_params); reader->n_total_req = reader_in->n_total_req; if (reader->trace_format != TXT_TRACE_FORMAT) { @@ -636,7 +650,9 @@ void read_last_req(reader_t *reader, request_t *req) { bool is_str_num(const char *str, size_t len) { for (size_t i = 0; i < len; i++) { - if (!(isdigit(str[i]) || (str[i] >= 'a' && str[i] <= 'f') || (str[i] >= 'A' && str[i] <= 'F'))) return false; + if (!(isdigit(str[i]) || (str[i] >= 'a' && str[i] <= 'f') || + (str[i] >= 'A' && str[i] <= 'F'))) + return false; } return true; } diff --git a/test/test_3lcache.c b/test/test_3lcache.c index d80587d2..9c983800 100644 --- a/test/test_3lcache.c +++ b/test/test_3lcache.c @@ -7,7 +7,9 @@ #define ThreeLCache_CACHE_SIZE (4 * GiB) #define ThreeLCache_STEP_SIZE GiB -static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_sizes, uint64_t req_cnt_true, +static void _verify_profiler_results(const cache_stat_t *res, + uint64_t num_of_sizes, + uint64_t req_cnt_true, const uint64_t *miss_cnt_true) { for (uint64_t i = 0; i < num_of_sizes; i++) { g_assert_cmpuint(req_cnt_true, ==, res[i].n_req); @@ -22,10 +24,12 @@ static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_si } static void print_results(const cache_t *cache, const cache_stat_t *res) { - for (uint64_t i = 0; i < ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE; i++) { - printf("%s cache size %8.4lf GB, req %" PRIu64 " miss %8" PRIu64 " req_bytes %" PRIu64 " miss_bytes %" PRIu64 "\n", - cache->cache_name, (double)res[i].cache_size / (double)GiB, res[i].n_req, res[i].n_miss, res[i].n_req_byte, - res[i].n_miss_byte); + for (uint64_t i = 0; i < ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE; + i++) { + printf("%s cache size %8.4lf GB, req %" PRIu64 " miss %8" PRIu64 + " req_bytes %" PRIu64 " miss_bytes %" PRIu64 "\n", + cache->cache_name, (double)res[i].cache_size / (double)GiB, + res[i].n_req, res[i].n_miss, res[i].n_req_byte, res[i].n_miss_byte); } } @@ -34,13 +38,18 @@ static void test_3LCache_OBJECT_MISS_RATIO(gconstpointer user_data) { uint64_t miss_cnt_true[] = {4779140, 4619176, 4099469, 4070435}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = ThreeLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = ThreeLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("3LCache-object-miss-ratio", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("3LCache-object-miss-ratio", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, ThreeLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, ThreeLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -51,14 +60,19 @@ static void test_3LCache_BYTE_MISS_RATIO(gconstpointer user_data) { uint64_t miss_cnt_true[] = {4821107, 4476524, 4374172, 4350448}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = ThreeLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = ThreeLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("3LCache-byte-miss-ratio", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("3LCache-byte-miss-ratio", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, ThreeLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, ThreeLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, ThreeLCache_CACHE_SIZE / ThreeLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -72,10 +86,13 @@ int main(int argc, char *argv[]) { #if defined(ENABLE_3L_CACHE) && ENABLE_3L_CACHE == 1 reader = setup_3LCacheTestData_reader(); - g_test_add_data_func("/libCacheSim/cacheAlgo_3LCache_OBJECT_MISS_RATIO", reader, test_3LCache_OBJECT_MISS_RATIO); - g_test_add_data_func("/libCacheSim/cacheAlgo_3LCache_BYTE_MISS_RATIO", reader, test_3LCache_BYTE_MISS_RATIO); + g_test_add_data_func("/libCacheSim/cacheAlgo_3LCache_OBJECT_MISS_RATIO", + reader, test_3LCache_OBJECT_MISS_RATIO); + g_test_add_data_func("/libCacheSim/cacheAlgo_3LCache_BYTE_MISS_RATIO", reader, + test_3LCache_BYTE_MISS_RATIO); - g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, test_teardown); + g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, + test_teardown); #endif /* ENABLE_3L_CACHE */ return g_test_run(); diff --git a/test/test_MRC.c b/test/test_MRC.c index 2a6e0dc5..64e3e4ee 100644 --- a/test/test_MRC.c +++ b/test/test_MRC.c @@ -5,13 +5,11 @@ * * For SHARDS: * The command run is: - * ../_build/bin/MRC SHARDS ../histograms/histogram_test.csv ../data/cloudPhysicsIO.vscsi vscsi 0.1 + * ../_build/bin/MRC SHARDS ../histograms/histogram_test.csv + * ../data/cloudPhysicsIO.vscsi vscsi 0.1 * - * The output CSV (../histograms/histogram_test.csv) is expected to have the header: - * Distance,Frequency - * and data rows such as: - * ColdMiss,4826 - * 14829,1 + * The output CSV (../histograms/histogram_test.csv) is expected to have the + * header: Distance,Frequency and data rows such as: ColdMiss,4826 14829,1 * 29659,1 * 24099,2 * 7419,3 @@ -35,7 +33,8 @@ * * In this test we select a few rows (by line number) and check: * - Row 2 (line index 1): "ColdMiss,4826" - * - Row 3 (line index 2): "14829,1" (numeric distance compared with ±3 tolerance) + * - Row 3 (line index 2): "14829,1" (numeric distance compared with ±3 + * tolerance) * - Row 11 (line index 10): "9279,2" * - Row 18 (line index 17): "0,749" * - Row 21 (line index 20): "9,555" @@ -45,92 +44,102 @@ * * For MINI: * The command run is: - * ../_build/bin/MRC MINI ../data/cloudPhysicsIO.vscsi vscsi s3fifo 1000,2000,5000,10000 0.1 ../histograms-mini/histogram_test.csv --ignore-obj-size 1 + * ../_build/bin/MRC MINI ../data/cloudPhysicsIO.vscsi vscsi s3fifo + * 1000,2000,5000,10000 0.1 ../histograms-mini/histogram_test.csv + * --ignore-obj-size 1 * - * The output CSV is compared (as in previous tests) against exact expected values. + * The output CSV is compared (as in previous tests) against exact expected + * values. */ #include -#include +#include #include +#include #include -#include + #include "common.h" #define DISTANCE_TOLERANCE 3 #define FLOAT_TOLERANCE 0.00001 typedef struct { - int line_index; - const char* expected_distance_str; // if not NULL, compare string exactly - int expected_distance_num; // if expected_distance_str == NULL, use numeric comparison - int expected_frequency; + int line_index; + const char *expected_distance_str; // if not NULL, compare string exactly + int expected_distance_num; // if expected_distance_str == NULL, use numeric + // comparison + int expected_frequency; } ExpectedRow; /* Integration test for SHARDS. * Runs the SHARDS command and then checks selected rows from the output CSV. */ static void test_shards_csv_integration(void) { - const char *cmd = "../_build/bin/MRC SHARDS ../histograms/histogram_test.csv ../data/cloudPhysicsIO.vscsi vscsi 0.1"; - int ret = system(cmd); - g_assert_cmpint(ret, ==, 0); - - // Read the output CSV file. - gchar *contents = NULL; - gsize length = 0; - GError *error = NULL; - gboolean success = g_file_get_contents("../histograms/histogram_test.csv", &contents, &length, &error); - g_assert_true(success); - g_assert_nonnull(contents); - - // Split the file into lines. - gchar **lines = g_strsplit(contents, "\n", -1); - // Check header (line index 0) - gchar *header = g_strstrip(lines[0]); - g_assert_cmpstr(header, ==, "Distance,Frequency"); - - // Define selected expected rows. - ExpectedRow expected_rows[] = { - {1, "ColdMiss", 0, 4826}, // Line 1: "ColdMiss,4826" - {2, NULL, 14829, 1}, // Line 2: "14829,1" - {10, NULL, 9279, 2}, // Line 10: "9279,2" - {17, NULL, 0, 749}, // Line 17: "0,749" - {20, NULL, 9, 555}, // Line 20: "9,555" - {21, NULL, 31529, 4} // Line 21: "31529,4" - }; - int n_expected = sizeof(expected_rows) / sizeof(expected_rows[0]); - - for (int i = 0; i < n_expected; i++) { - int index = expected_rows[i].line_index; - g_assert_nonnull(lines[index]); // ensure the line exists - gchar *line = g_strstrip(lines[index]); - // Split the line into two tokens. - gchar **tokens = g_strsplit(line, ",", 0); - int n_tokens = g_strv_length(tokens); - g_assert_cmpint(n_tokens, ==, 2); // Expect two columns: Distance and Frequency - - gchar *distance_token = g_strstrip(tokens[0]); - gchar *frequency_token = g_strstrip(tokens[1]); - - // Compare frequency exactly. - int freq = atoi(frequency_token); - g_assert_cmpint(freq, ==, expected_rows[i].expected_frequency); - - // Compare distance. - if (expected_rows[i].expected_distance_str != NULL) { - // Check string equality. - g_assert_cmpstr(distance_token, ==, expected_rows[i].expected_distance_str); - } else { - // Parse as integer and compare within tolerance. - int distance_val = atoi(distance_token); - int diff = abs(distance_val - expected_rows[i].expected_distance_num); - g_assert_cmpint(diff, <=, DISTANCE_TOLERANCE); - } - g_strfreev(tokens); + const char *cmd = + "../_build/bin/MRC SHARDS ../histograms/histogram_test.csv " + "../data/cloudPhysicsIO.vscsi vscsi 0.1"; + int ret = system(cmd); + g_assert_cmpint(ret, ==, 0); + + // Read the output CSV file. + gchar *contents = NULL; + gsize length = 0; + GError *error = NULL; + gboolean success = g_file_get_contents("../histograms/histogram_test.csv", + &contents, &length, &error); + g_assert_true(success); + g_assert_nonnull(contents); + + // Split the file into lines. + gchar **lines = g_strsplit(contents, "\n", -1); + // Check header (line index 0) + gchar *header = g_strstrip(lines[0]); + g_assert_cmpstr(header, ==, "Distance,Frequency"); + + // Define selected expected rows. + ExpectedRow expected_rows[] = { + {1, "ColdMiss", 0, 4826}, // Line 1: "ColdMiss,4826" + {2, NULL, 14829, 1}, // Line 2: "14829,1" + {10, NULL, 9279, 2}, // Line 10: "9279,2" + {17, NULL, 0, 749}, // Line 17: "0,749" + {20, NULL, 9, 555}, // Line 20: "9,555" + {21, NULL, 31529, 4} // Line 21: "31529,4" + }; + int n_expected = sizeof(expected_rows) / sizeof(expected_rows[0]); + + for (int i = 0; i < n_expected; i++) { + int index = expected_rows[i].line_index; + g_assert_nonnull(lines[index]); // ensure the line exists + gchar *line = g_strstrip(lines[index]); + // Split the line into two tokens. + gchar **tokens = g_strsplit(line, ",", 0); + int n_tokens = g_strv_length(tokens); + g_assert_cmpint(n_tokens, ==, + 2); // Expect two columns: Distance and Frequency + + gchar *distance_token = g_strstrip(tokens[0]); + gchar *frequency_token = g_strstrip(tokens[1]); + + // Compare frequency exactly. + int freq = atoi(frequency_token); + g_assert_cmpint(freq, ==, expected_rows[i].expected_frequency); + + // Compare distance. + if (expected_rows[i].expected_distance_str != NULL) { + // Check string equality. + g_assert_cmpstr(distance_token, ==, + expected_rows[i].expected_distance_str); + } else { + // Parse as integer and compare within tolerance. + int distance_val = atoi(distance_token); + int diff = abs(distance_val - expected_rows[i].expected_distance_num); + g_assert_cmpint(diff, <=, DISTANCE_TOLERANCE); } + g_strfreev(tokens); + } - g_strfreev(lines); - g_free(contents); + g_strfreev(lines); + g_free(contents); } /* Integration test for Miniatures. @@ -145,61 +154,70 @@ static void test_shards_csv_integration(void) { * 10000,0.616263, 0.616263 */ static void test_miniatures_integration(void) { - const char *cmd = "../_build/bin/MRC MINI ../data/cloudPhysicsIO.vscsi vscsi s3fifo 1000,2000,5000,10000 0.1 ../histograms-mini/histogram_test.csv --ignore-obj-size 1"; - int ret = system(cmd); - g_assert_cmpint(ret, ==, 0); - - // Open the CSV file. - gchar *contents = NULL; - gsize length = 0; - GError *error = NULL; - gboolean success = g_file_get_contents("../histograms-mini/histogram_test.csv", &contents, &length, &error); - g_assert_true(success); - g_assert_nonnull(contents); - - // Split file into lines. - gchar **lines = g_strsplit(contents, "\n", -1); - // Check header. - gchar *header = g_strstrip(lines[0]); - g_assert_cmpstr(header, ==, "Cache Size,Miss Ratio, Miss Ratio Byte"); - - // Expected values. - const int expected_cache_sizes[4] = {1000, 2000, 5000, 10000}; - const gdouble expected_miss_ratios[4] = {0.774473, 0.764392, 0.699658, 0.616263}; - const gdouble expected_miss_ratios_byte[4] = {0.774473, 0.764392, 0.699658, 0.616263}; - - // There should be exactly 4 non-empty data lines. - int data_line_count = 0; - for (int i = 1; lines[i] != NULL && lines[i][0] != '\0'; i++) { - gchar **tokens = g_strsplit(lines[i], ",", 0); - g_assert_cmpint(g_strv_length(tokens), ==, 3); - - gchar *cache_size_str = g_strstrip(tokens[0]); - gchar *miss_ratio_str = g_strstrip(tokens[1]); - gchar *miss_ratio_byte_str = g_strstrip(tokens[2]); - - int cache_size = atoi(cache_size_str); - gdouble miss_ratio = g_strtod(miss_ratio_str, NULL); - gdouble miss_ratio_byte = g_strtod(miss_ratio_byte_str, NULL); - - g_assert_cmpint(cache_size, ==, expected_cache_sizes[data_line_count]); - g_assert_cmpfloat(fabs(miss_ratio - expected_miss_ratios[data_line_count]), <, FLOAT_TOLERANCE); - g_assert_cmpfloat(fabs(miss_ratio_byte - expected_miss_ratios_byte[data_line_count]), <, FLOAT_TOLERANCE); - - data_line_count++; - g_strfreev(tokens); - } - g_assert_cmpint(data_line_count, ==, 4); - - g_strfreev(lines); - g_free(contents); + const char *cmd = + "../_build/bin/MRC MINI ../data/cloudPhysicsIO.vscsi vscsi s3fifo " + "1000,2000,5000,10000 0.1 ../histograms-mini/histogram_test.csv " + "--ignore-obj-size 1"; + int ret = system(cmd); + g_assert_cmpint(ret, ==, 0); + + // Open the CSV file. + gchar *contents = NULL; + gsize length = 0; + GError *error = NULL; + gboolean success = g_file_get_contents( + "../histograms-mini/histogram_test.csv", &contents, &length, &error); + g_assert_true(success); + g_assert_nonnull(contents); + + // Split file into lines. + gchar **lines = g_strsplit(contents, "\n", -1); + // Check header. + gchar *header = g_strstrip(lines[0]); + g_assert_cmpstr(header, ==, "Cache Size,Miss Ratio, Miss Ratio Byte"); + + // Expected values. + const int expected_cache_sizes[4] = {1000, 2000, 5000, 10000}; + const gdouble expected_miss_ratios[4] = {0.774473, 0.764392, 0.699658, + 0.616263}; + const gdouble expected_miss_ratios_byte[4] = {0.774473, 0.764392, 0.699658, + 0.616263}; + + // There should be exactly 4 non-empty data lines. + int data_line_count = 0; + for (int i = 1; lines[i] != NULL && lines[i][0] != '\0'; i++) { + gchar **tokens = g_strsplit(lines[i], ",", 0); + g_assert_cmpint(g_strv_length(tokens), ==, 3); + + gchar *cache_size_str = g_strstrip(tokens[0]); + gchar *miss_ratio_str = g_strstrip(tokens[1]); + gchar *miss_ratio_byte_str = g_strstrip(tokens[2]); + + int cache_size = atoi(cache_size_str); + gdouble miss_ratio = g_strtod(miss_ratio_str, NULL); + gdouble miss_ratio_byte = g_strtod(miss_ratio_byte_str, NULL); + + g_assert_cmpint(cache_size, ==, expected_cache_sizes[data_line_count]); + g_assert_cmpfloat(fabs(miss_ratio - expected_miss_ratios[data_line_count]), + <, FLOAT_TOLERANCE); + g_assert_cmpfloat( + fabs(miss_ratio_byte - expected_miss_ratios_byte[data_line_count]), <, + FLOAT_TOLERANCE); + + data_line_count++; + g_strfreev(tokens); + } + g_assert_cmpint(data_line_count, ==, 4); + + g_strfreev(lines); + g_free(contents); } int main(int argc, char **argv) { - g_test_init(&argc, &argv, NULL); + g_test_init(&argc, &argv, NULL); - g_test_add_func("/integration/test_shards_csv", test_shards_csv_integration); - g_test_add_func("/integration/test_miniatures", test_miniatures_integration); + g_test_add_func("/integration/test_shards_csv", test_shards_csv_integration); + g_test_add_func("/integration/test_miniatures", test_miniatures_integration); - return g_test_run(); + return g_test_run(); } diff --git a/test/test_admissionAlgo.c b/test/test_admissionAlgo.c index 6e2373a1..f6f596b7 100644 --- a/test/test_admissionAlgo.c +++ b/test/test_admissionAlgo.c @@ -3,8 +3,11 @@ static const uint64_t g_req_cnt_true = 113872, g_req_byte_true = 4368040448; -static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_sizes, uint64_t req_cnt_true, - const uint64_t *miss_cnt_true, uint64_t req_byte_true, +static void _verify_profiler_results(const cache_stat_t *res, + uint64_t num_of_sizes, + uint64_t req_cnt_true, + const uint64_t *miss_cnt_true, + uint64_t req_byte_true, const uint64_t *miss_byte_true) { for (uint64_t i = 0; i < num_of_sizes; i++) { g_assert_cmpuint(req_cnt_true, ==, res[i].n_req); @@ -38,65 +41,85 @@ static void print_results(const cache_t *cache, const cache_stat_t *res) { } static void test_AdaptSize(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {83204, 80907, 77835, 77086, 76173, 76158, 76158, 76158}; - uint64_t miss_byte_true[] = {3996894720, 3916923392, 3790021120, 3751927808, 3695680512, 3695609344, 3695609344, 3695609344}; + uint64_t miss_cnt_true[] = {83204, 80907, 77835, 77086, + 76173, 76158, 76158, 76158}; + uint64_t miss_byte_true[] = {3996894720, 3916923392, 3790021120, 3751927808, + 3695680512, 3695609344, 3695609344, 3695609344}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("AdaptSize", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Size(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93374, 89783, 83572, 81722, 72494, 72104, 71972, 71704}; - uint64_t miss_byte_true[] = {4214303232, 4061242368, 3778040320, 3660569600, 3100927488, 3078128640, 3075403776, 3061662720}; + uint64_t miss_cnt_true[] = {93374, 89783, 83572, 81722, + 72494, 72104, 71972, 71704}; + uint64_t miss_byte_true[] = {4214303232, 4061242368, 3778040320, 3660569600, + 3100927488, 3078128640, 3075403776, 3061662720}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Size", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_SizeProb(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93371, 89122, 83635, 81935, 73293, 72963, 72737, 71949}; - uint64_t miss_byte_true[] = {4214365696, 4030683648, 3781775872, 3671897088, 3151684096, 3133195264, 3123936256, 3078763520}; + uint64_t miss_cnt_true[] = {93371, 89122, 83635, 81935, + 73293, 72963, 72737, 71949}; + uint64_t miss_byte_true[] = {4214365696, 4030683648, 3781775872, 3671897088, + 3151684096, 3133195264, 3123936256, 3078763520}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("SizeProb", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_BloomFilter(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {94816, 90386, 88417, 85744, 82344, 79504, 77058, 76979}; - uint64_t miss_byte_true[] = {4193502720, 3979631104, 3877562880, 3716727296, 3503820288, 3323299328, 3257762304, 3254848512}; + uint64_t miss_cnt_true[] = {94816, 90386, 88417, 85744, + 82344, 79504, 77058, 76979}; + uint64_t miss_byte_true[] = {4193502720, 3979631104, 3877562880, 3716727296, + 3503820288, 3323299328, 3257762304, 3254848512}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("BloomFilter", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -117,10 +140,13 @@ int main(int argc, char *argv[]) { reader = setup_oracleGeneralBin_reader(); - g_test_add_data_func("/libCacheSim/admissionAlgo_AdaptSize", reader, test_AdaptSize); + g_test_add_data_func("/libCacheSim/admissionAlgo_AdaptSize", reader, + test_AdaptSize); g_test_add_data_func("/libCacheSim/admissionAlgo_Size", reader, test_Size); - g_test_add_data_func("/libCacheSim/admissionAlgo_SizeProb", reader, test_SizeProb); - g_test_add_data_func("/libCacheSim/admissionAlgo_BloomFilter", reader, test_BloomFilter); + g_test_add_data_func("/libCacheSim/admissionAlgo_SizeProb", reader, + test_SizeProb); + g_test_add_data_func_full("/libCacheSim/admissionAlgo_BloomFilter", reader, + test_BloomFilter, test_teardown); return g_test_run(); } diff --git a/test/test_dataStructure.c b/test/test_dataStructure.c index 27c2e06c..4b4cfc42 100644 --- a/test/test_dataStructure.c +++ b/test/test_dataStructure.c @@ -27,14 +27,17 @@ void test_chained_hashtable_v2(gconstpointer user_data) { print_chained_hashtable_v2(hashtable); // cache_obj_t *obj = chained_hashtable_rand_obj_v2(hashtable); // printf("random object %lu\n", obj->obj_id); + + // clean up + free_request(req); + free_chained_hashtable_v2(hashtable); } int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); - reader_t *reader; - reader = setup_plaintxt_reader_num(); - g_test_add_data_func("/libCacheSim/test_chained_hashtable_v2", NULL, test_chained_hashtable_v2); + g_test_add_data_func("/libCacheSim/test_chained_hashtable_v2", NULL, + test_chained_hashtable_v2); return g_test_run(); } diff --git a/test/test_dist.c b/test/test_dist.c index 22578054..98537536 100644 --- a/test/test_dist.c +++ b/test/test_dist.c @@ -22,23 +22,26 @@ void test_distUtils_basic(gconstpointer user_data) { for (i = (long)get_num_of_req(reader) - 1, j = 0; j < N_TEST; i--, j++) { g_assert_cmpint(dist[i], ==, rd_true[j]); } + free(dist); dist = get_stack_dist(reader, FUTURE_STACK_DIST, &array_size); g_assert_cmpint(array_size, ==, get_num_of_req(reader)); for (i = 6, j = 0; j < N_TEST; i++, j++) { g_assert_cmpint(dist[i], ==, frd_true[j]); } + free(dist); dist = get_access_dist(reader, DIST_SINCE_LAST_ACCESS, &array_size); g_assert_cmpint(array_size, ==, get_num_of_req(reader)); for (i = (long)get_num_of_req(reader) - 1, j = 0; j < N_TEST; i--, j++) { g_assert_cmpint(dist[i], ==, last_dist_true[j]); } - + free(dist); // dist = get_next_access_dist(reader); // for (i = 6, j = 0; j < N_TEST; i++, j++) { // g_assert_cmpint(dist[i], ==, next_dist_true[j]); // } + // free(dist); } void test_distUtils_more1(gconstpointer user_data) { @@ -66,28 +69,40 @@ int main(int argc, char* argv[]) { reader_t* reader; reader = setup_plaintxt_reader_num(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_plain_num", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_plain_num", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_plain_num", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_plain_num", + reader, test_distUtils_more1, test_teardown); reader = setup_plaintxt_reader_str(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_plain_str", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_plain_str", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_plain_str", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_plain_str", + reader, test_distUtils_more1, test_teardown); reader = setup_csv_reader_obj_num(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_csv_num", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_csv_num", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_csv_num", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_csv_num", reader, + test_distUtils_more1, test_teardown); reader = setup_csv_reader_obj_str(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_csv_str", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_csv_str", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_csv_str", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_csv_str", reader, + test_distUtils_more1, test_teardown); reader = setup_binary_reader(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_binary", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_binary", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_binary", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_binary", reader, + test_distUtils_more1, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func("/libCacheSim/test_distUtils_basic_vscsi", reader, test_distUtils_basic); - g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_vscsi", reader, test_distUtils_more1, test_teardown); + g_test_add_data_func("/libCacheSim/test_distUtils_basic_vscsi", reader, + test_distUtils_basic); + g_test_add_data_func_full("/libCacheSim/test_distUtils_more1_vscsi", reader, + test_distUtils_more1, test_teardown); return g_test_run(); } diff --git a/test/test_evictionAlgo.c b/test/test_evictionAlgo.c index b6e1d174..c9922b96 100644 --- a/test/test_evictionAlgo.c +++ b/test/test_evictionAlgo.c @@ -7,8 +7,11 @@ static const uint64_t g_req_cnt_true = 113872, g_req_byte_true = 4368040448; -static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_sizes, uint64_t req_cnt_true, - const uint64_t *miss_cnt_true, uint64_t req_byte_true, +static void _verify_profiler_results(const cache_stat_t *res, + uint64_t num_of_sizes, + uint64_t req_cnt_true, + const uint64_t *miss_cnt_true, + uint64_t req_byte_true, const uint64_t *miss_byte_true) { for (uint64_t i = 0; i < num_of_sizes; i++) { g_assert_cmpuint(req_cnt_true, ==, res[i].n_req); @@ -42,70 +45,87 @@ static void print_results(const cache_t *cache, const cache_stat_t *res) { } static void test_LRU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93374, 89783, 83572, 81722, 72494, 72104, 71972, 71704}; + uint64_t miss_cnt_true[] = {93374, 89783, 83572, 81722, + 72494, 72104, 71972, 71704}; uint64_t miss_byte_true[] = {4214303232, 4061242368, 3778040320, 3660569600, 3100927488, 3078128640, 3075403776, 3061662720}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LRU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Clock(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93313, 89775, 83411, 81328, 74815, 72283, 71927, 64456}; + uint64_t miss_cnt_true[] = {93313, 89775, 83411, 81328, + 74815, 72283, 71927, 64456}; uint64_t miss_byte_true[] = {4213887488, 4064512000, 3762650624, 3644467200, 3256760832, 3091688448, 3074241024, 2697378816}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Clock", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_ClockPro(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {96390, 92614, 88911, 85894, 82276, 73203, 63728, 57544}; + uint64_t miss_cnt_true[] = {96390, 92614, 88911, 85894, + 82276, 73203, 63728, 57544}; uint64_t miss_byte_true[] = {4163599360, 3922361856, 3700721152, 3491452416, - 3245322240, 2653708288, 2413087744, 2293678592}; + 3245322240, 2653708288, 2413087744, 2293678592}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("ClockPro", cc_params, reader, NULL); g_assert_true(cache != NULL); - // cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + // cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, + // STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_FIFO(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93403, 89386, 84387, 84025, 72498, 72228, 72182, 72140}; + uint64_t miss_cnt_true[] = {93403, 89386, 84387, 84025, + 72498, 72228, 72182, 72140}; uint64_t miss_byte_true[] = {4213112832, 4052646400, 3829170176, 3807412736, 3093146112, 3079525888, 3079210496, 3077547520}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("FIFO", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -115,18 +135,22 @@ static void test_Belady(gconstpointer user_data) { * trace removes all object size changes (and use the size of last appearance * of an object as the object size throughout the trace */ uint64_t req_cnt_true = 113872, req_byte_true = 4368040448; - uint64_t miss_cnt_true[] = {79256, 70724, 65481, 61594, 59645, 57599, 50873, 48974}; + uint64_t miss_cnt_true[] = {79256, 70724, 65481, 61594, + 59645, 57599, 50873, 48974}; uint64_t miss_byte_true[] = {3472532480, 2995165696, 2726689792, 2537648128, 2403427840, 2269212672, 2134992896, 2029769728}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Belady", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -136,340 +160,421 @@ static void test_BeladySize(gconstpointer user_data) { * trace removes all object size changes (and use the size of last appearance * of an object as the object size throughout the trace */ uint64_t req_cnt_true = 113872, req_byte_true = 4368040448; - uint64_t miss_cnt_true[] = {74276, 64559, 60307, 56523, 54546, 52621, 50580, 48974}; + uint64_t miss_cnt_true[] = {74276, 64559, 60307, 56523, + 54546, 52621, 50580, 48974}; uint64_t miss_byte_true[] = {3510420480, 3046959616, 2774180352, 2537695744, 2403428864, 2269255168, 2135001088, 2029769728}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("BeladySize", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Random(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92457, 88582, 84459, 80277, 76132, 72134, 68230, 64225}; + uint64_t miss_cnt_true[] = {92457, 88582, 84459, 80277, + 76132, 72134, 68230, 64225}; uint64_t miss_byte_true[] = {4170166272, 3975292416, 3757524992, 3539850752, 3321110016, 3113551360, 2917275648, 2725705216}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 12, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 12, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Random", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_LFU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, 69945, 66221, 64445, 64376}; + uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, + 69945, 66221, 64445, 64376}; uint64_t miss_byte_true[] = {4158632960, 3917211648, 3536227840, 3455379968, 3035580416, 2801699328, 2699456000, 2696345600}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LFU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); g_free(res); } static void test_LFUCpp(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, 69945, 66221, 64445, 64376}; + uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, + 69945, 66221, 64445, 64376}; uint64_t miss_byte_true[] = {4158632960, 3917211648, 3536227840, 3455379968, 3035580416, 2801699328, 2699456000, 2696345600}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LFU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_GDSF(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {89070, 84750, 74850, 70490, 67923, 64180, 61027, 58721}; + uint64_t miss_cnt_true[] = {89070, 84750, 74850, 70490, + 67923, 64180, 61027, 58721}; uint64_t miss_byte_true[] = {4210726912, 4057058816, 3719176192, 3436855296, 3271648256, 3029728768, 2828456448, 2677800448}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("GDSF", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_LHD(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {90534, 86891, 82334, 77339, 71355, 66938, 63677, 61116}; + uint64_t miss_cnt_true[] = {90534, 86891, 82334, 77339, + 71355, 66938, 63677, 61116}; uint64_t miss_byte_true[] = {4211037696, 4059153920, 3834546176, 3596945408, 3326034944, 3115964416, 2951718912, 2804600832}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LHD", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Hyperbolic(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92924, 89470, 83452, 81234, 74544, 71234, 69356, 65338}; + uint64_t miss_cnt_true[] = {92924, 89470, 83452, 81234, + 74544, 71234, 69356, 65338}; uint64_t miss_byte_true[] = {4213586432, 4064826368, 3766646272, 3644941824, 3245021184, 3035783168, 2939981312, 2754100224}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 18, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 18, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Hyperbolic", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_LeCaR(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {93374, 89067, 80230, 81526, 72159, 67712, 65206, 64541}; + uint64_t miss_cnt_true[] = {93374, 89067, 80230, 81526, + 72159, 67712, 65206, 64541}; uint64_t miss_byte_true[] = {4214303232, 4021100032, 3593971712, 3652036096, 3075125760, 2886052864, 2735856128, 2698478080}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LeCaR", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Cacheus(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {89776, 82725, 78839, 73048, 69329, 69184, 69117, 66048}; + uint64_t miss_cnt_true[] = {89776, 82725, 78839, 73048, + 69329, 69184, 69117, 66048}; uint64_t miss_byte_true[] = {4048868864, 3727920128, 3489738752, 3184179200, 2981198336, 2968055296, 2925565440, 2789046784}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Cacheus", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_SR_LRU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {90043, 83978, 81482, 77727, 72611, 72059, 67836, 65739}; + uint64_t miss_cnt_true[] = {90043, 83978, 81482, 77727, + 72611, 72059, 67836, 65739}; uint64_t miss_byte_true[] = {4068758016, 3792818176, 3639756288, 3379609600, 3165339648, 3058814976, 2862775296, 2774183936}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("SR_LRU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_CR_LFU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92095, 88257, 84839, 81885, 78348, 69281, 61350, 54894}; + uint64_t miss_cnt_true[] = {92095, 88257, 84839, 81885, + 78348, 69281, 61350, 54894}; uint64_t miss_byte_true[] = {4141293056, 3900042240, 3686207488, 3481216000, 3238197760, 2646171648, 2408963072, 2289538048}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("CR_LFU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_LFUDA(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92637, 88601, 82001, 80240, 73214, 71386, 70415, 71128}; + uint64_t miss_cnt_true[] = {92637, 88601, 82001, 80240, + 73214, 71386, 70415, 71128}; uint64_t miss_byte_true[] = {4200012288, 3993467904, 3673375232, 3579174400, 3164476928, 3046658048, 2998682624, 3027994112}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LFUDA", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_MRU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {100738, 95058, 89580, 85544, 81725, 77038, 71070, 66919}; + uint64_t miss_cnt_true[] = {100738, 95058, 89580, 85544, + 81725, 77038, 71070, 66919}; uint64_t miss_byte_true[] = {4105477120, 3784799744, 3493475840, 3280475648, 3069635072, 2856241152, 2673937408, 2539762688}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("MRU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_ARC(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {90252, 85861, 78168, 74297, 67381, 65685, 64439, 64772}; + uint64_t miss_cnt_true[] = {90252, 85861, 78168, 74297, + 67381, 65685, 64439, 64772}; uint64_t miss_byte_true[] = {4068098560, 3821026816, 3525644800, 3296890368, 2868538880, 2771180032, 2699484672, 2712971264}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("ARC", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_CAR(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {90522, 83605, 78063, 75772, 67384, 65687, 64439, 64376}; - uint64_t miss_byte_true[] = {4084188160, 3769425920, 3525660160, 3394717696, 2868551168, 2771188224, 2699423232, 2696345600}; + uint64_t miss_cnt_true[] = {90522, 83605, 78063, 75772, + 67384, 65687, 64439, 64376}; + uint64_t miss_byte_true[] = {4084188160, 3769425920, 3525660160, 3394717696, + 2868551168, 2771188224, 2699423232, 2696345600}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("CAR", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_SLRU(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {89624, 86725, 82781, 80203, 75388, 65645, 59035, 56063}; + uint64_t miss_cnt_true[] = {89624, 86725, 82781, 80203, + 75388, 65645, 59035, 56063}; uint64_t miss_byte_true[] = {4123085312, 3915534848, 3690704896, 3493027840, 3174708736, 2661464064, 2507604992, 2439981056}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("SLRU", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_QDLP_FIFO(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {88746, 80630, 76450, 71638, 67380, 65680, 66125, 64417}; + uint64_t miss_cnt_true[] = {88746, 80630, 76450, 71638, + 67380, 65680, 66125, 64417}; uint64_t miss_byte_true[] = {4008265728, 3625704960, 3330610176, 3099731456, 2868538880, 2771098112, 2734977024, 2697751552}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("QDLP-FIFO", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_S3FIFOv0(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {89307, 82387, 77041, 76791, 71300, 70343, 70455, 70355}; + uint64_t miss_cnt_true[] = {89307, 82387, 77041, 76791, + 71300, 70343, 70455, 70355}; uint64_t miss_byte_true[] = {4040718336, 3703628800, 3353047552, 3282235904, 3038256128, 2980646912, 2984458752, 2979649536}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("S3-FIFOv0", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_S3FIFO(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {90117, 80915, 75060, 72191, 69815, 65542, 60799, 56045}; + uint64_t miss_cnt_true[] = {90117, 80915, 75060, 72191, + 69815, 65542, 60799, 56045}; uint64_t miss_byte_true[] = {4058576896, 3573827584, 3244417024, 3061737984, 2898109952, 2628363776, 2425027072, 2327934464}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("S3-FIFO", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_Sieve(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, 69945, 66221, 64445, 64376}; + uint64_t miss_cnt_true[] = {91699, 86720, 78578, 76707, + 69945, 66221, 64445, 64376}; uint64_t miss_byte_true[] = {4158632960, 3917211648, 3536227840, 3455379968, 3035580416, 2801699328, 2699456000, 2696345600}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Sieve", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -479,18 +584,22 @@ static void test_WTinyLFU(gconstpointer user_data) { } static void test_LIRS(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {89819, 79237, 73143, 70363, 68405, 64494, 58640, 53924}; + uint64_t miss_cnt_true[] = {89819, 79237, 73143, 70363, + 68405, 64494, 58640, 53924}; uint64_t miss_byte_true[] = {4060558336, 3525952512, 3199406080, 3011810816, 2848310272, 2580918784, 2361375744, 2288325120}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("LIRS", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -513,8 +622,10 @@ int main(int argc, char *argv[]) { g_test_add_data_func("/libCacheSim/cacheAlgo_Sieve", reader, test_Sieve); g_test_add_data_func("/libCacheSim/cacheAlgo_S3FIFO", reader, test_S3FIFO); - g_test_add_data_func("/libCacheSim/cacheAlgo_S3FIFOv0", reader, test_S3FIFOv0); - g_test_add_data_func("/libCacheSim/cacheAlgo_QDLP_FIFO", reader, test_QDLP_FIFO); + g_test_add_data_func("/libCacheSim/cacheAlgo_S3FIFOv0", reader, + test_S3FIFOv0); + g_test_add_data_func("/libCacheSim/cacheAlgo_QDLP_FIFO", reader, + test_QDLP_FIFO); g_test_add_data_func("/libCacheSim/cacheAlgo_LRU", reader, test_LRU); g_test_add_data_func("/libCacheSim/cacheAlgo_SLRU", reader, test_SLRU); @@ -524,11 +635,13 @@ int main(int argc, char *argv[]) { g_test_add_data_func("/libCacheSim/cacheAlgo_SR_LRU", reader, test_SR_LRU); g_test_add_data_func("/libCacheSim/cacheAlgo_CR_LFU", reader, test_CR_LFU); g_test_add_data_func("/libCacheSim/cacheAlgo_Cacheus", reader, test_Cacheus); - g_test_add_data_func("/libCacheSim/cacheAlgo_Hyperbolic", reader, test_Hyperbolic); + g_test_add_data_func("/libCacheSim/cacheAlgo_Hyperbolic", reader, + test_Hyperbolic); g_test_add_data_func("/libCacheSim/cacheAlgo_LIRS", reader, test_LIRS); g_test_add_data_func("/libCacheSim/cacheAlgo_Clock", reader, test_Clock); - g_test_add_data_func("/libCacheSim/cacheAlgo_ClockPro", reader, test_ClockPro); + g_test_add_data_func("/libCacheSim/cacheAlgo_ClockPro", reader, + test_ClockPro); g_test_add_data_func("/libCacheSim/cacheAlgo_FIFO", reader, test_FIFO); g_test_add_data_func("/libCacheSim/cacheAlgo_MRU", reader, test_MRU); g_test_add_data_func("/libCacheSim/cacheAlgo_Random", reader, test_Random); @@ -542,9 +655,11 @@ int main(int argc, char *argv[]) { // /* Belady requires reader that has next access information and can only use // * oracleGeneral trace */ // g_test_add_data_func("/libCacheSim/cacheAlgo_Belady", reader, test_Belady); - // g_test_add_data_func("/libCacheSim/cacheAlgo_BeladySize", reader, test_BeladySize); + // g_test_add_data_func("/libCacheSim/cacheAlgo_BeladySize", reader, + // test_BeladySize); - // g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, test_teardown); + g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, + test_teardown); return g_test_run(); } diff --git a/test/test_glcache.c b/test/test_glcache.c index 76c23f96..7a91cb52 100644 --- a/test/test_glcache.c +++ b/test/test_glcache.c @@ -7,7 +7,9 @@ #define GLCache_CACHE_SIZE (4 * GiB) #define GLCache_STEP_SIZE GiB -static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_sizes, uint64_t req_cnt_true, +static void _verify_profiler_results(const cache_stat_t *res, + uint64_t num_of_sizes, + uint64_t req_cnt_true, const uint64_t *miss_cnt_true) { for (uint64_t i = 0; i < num_of_sizes; i++) { g_assert_cmpuint(req_cnt_true, ==, res[i].n_req); @@ -23,9 +25,10 @@ static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_si static void print_results(const cache_t *cache, const cache_stat_t *res) { for (uint64_t i = 0; i < GLCache_CACHE_SIZE / GLCache_STEP_SIZE; i++) { - printf("%s cache size %8.4lf GB, req %" PRIu64 " miss %8" PRIu64 " req_bytes %" PRIu64 " miss_bytes %" PRIu64 "\n", - cache->cache_name, (double)res[i].cache_size / (double)GiB, res[i].n_req, res[i].n_miss, res[i].n_req_byte, - res[i].n_miss_byte); + printf("%s cache size %8.4lf GB, req %" PRIu64 " miss %8" PRIu64 + " req_bytes %" PRIu64 " miss_bytes %" PRIu64 "\n", + cache->cache_name, (double)res[i].cache_size / (double)GiB, + res[i].n_req, res[i].n_miss, res[i].n_req_byte, res[i].n_miss_byte); } } @@ -34,13 +37,18 @@ static void test_GLCache_ORACLE_LOG(gconstpointer user_data) { uint64_t miss_cnt_true[] = {1630908, 1126212, 979809, 922256}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("GLCache-OracleLog", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("GLCache-OracleLog", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -50,31 +58,42 @@ static void test_GLCache_ORACLE_ITEM(gconstpointer user_data) { uint64_t miss_cnt_true[] = {1966381, 1310825, 1198366, 1127507}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("GLCache-OracleItem", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("GLCache-OracleItem", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_GLCache_ORACLE_BOTH(gconstpointer user_data) { uint64_t req_cnt_true = 8875971, req_byte_true = 160011631104; - uint64_t miss_cnt_true[] = {1476768, 1091173, 1027426, 1004396}; // do not consider retain + uint64_t miss_cnt_true[] = {1476768, 1091173, 1027426, + 1004396}; // do not consider retain reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("GLCache-OracleBoth", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("GLCache-OracleBoth", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -84,14 +103,19 @@ static void test_GLCache_LEARNED_TRUE_Y(gconstpointer user_data) { uint64_t miss_cnt_true[] = {2021753, 1314854, 1093074, 1034222}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("GLCache-LearnedTrueY", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("GLCache-LearnedTrueY", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -102,14 +126,19 @@ static void test_GLCache_LEARNED_ONLINE(gconstpointer user_data) { uint64_t miss_cnt_true[] = {2187591, 1375970, 1113121, 1046752}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, .hashpower = 24, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = {.cache_size = GLCache_CACHE_SIZE, + .hashpower = 24, + .default_ttl = DEFAULT_TTL}; - cache_t *cache = create_test_cache("GLCache-LearnedOnline", cc_params, reader, NULL); + cache_t *cache = + create_test_cache("GLCache-LearnedOnline", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, GLCache_STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, req_cnt_true, miss_cnt_true); + _verify_profiler_results(res, GLCache_CACHE_SIZE / GLCache_STEP_SIZE, + req_cnt_true, miss_cnt_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -123,13 +152,19 @@ int main(int argc, char *argv[]) { #if defined(ENABLE_GLCACHE) && ENABLE_GLCACHE == 1 reader = setup_GLCacheTestData_reader(); - g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_LEARNED_TRUE_Y", reader, test_GLCache_LEARNED_TRUE_Y); - g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_LEARNED_ONLINE", reader, test_GLCache_LEARNED_ONLINE); - g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_LOG", reader, test_GLCache_ORACLE_LOG); - g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_ITEM", reader, test_GLCache_ORACLE_ITEM); - g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_BOTH", reader, test_GLCache_ORACLE_BOTH); - - g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, test_teardown); + g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_LEARNED_TRUE_Y", reader, + test_GLCache_LEARNED_TRUE_Y); + g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_LEARNED_ONLINE", reader, + test_GLCache_LEARNED_ONLINE); + g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_LOG", reader, + test_GLCache_ORACLE_LOG); + g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_ITEM", reader, + test_GLCache_ORACLE_ITEM); + g_test_add_data_func("/libCacheSim/cacheAlgo_GLCache_ORACLE_BOTH", reader, + test_GLCache_ORACLE_BOTH); + + g_test_add_data_func_full("/libCacheSim/empty", reader, empty_test, + test_teardown); #endif /* ENABLE_GLCACHE */ return g_test_run(); diff --git a/test/test_mrcProfiler.cpp b/test/test_mrcProfiler.cpp index 0bbad866..dffbb7ff 100644 --- a/test/test_mrcProfiler.cpp +++ b/test/test_mrcProfiler.cpp @@ -2,28 +2,29 @@ // Created by Xiaojun Guo on 02/28/25. // -#include "common.h" #include "../libCacheSim/mrcProfiler/mrcProfiler.h" +#include "common.h" /** * this one for testing with the SHARDS profiler with fiexd sample rate * @param user_data */ -static void test_shards_profiler_with_fixed_sample_rate(gconstpointer user_data) { - reader_t * reader = setup_vscsi_reader(); +static void test_shards_profiler_with_fixed_sample_rate( + gconstpointer user_data) { + reader_t *reader = setup_vscsi_reader(); mrcProfiler::mrc_profiler_params_t params; mrcProfiler::mrc_profiler_e mrc_profiler_type = mrcProfiler::SHARDS_PROFILER; - params.cache_algorithm_str = "LRU"; params.shards_params.parse_params("FIX_RATE,0.01,10"); uint64_t step_size = 202976972; int test_steps = 10; - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { params.profile_size.push_back(step_size * (i + 1)); } - mrcProfiler::MRCProfilerBase * profiler = create_mrc_profiler(mrc_profiler_type, reader, "", params); + mrcProfiler::MRCProfilerBase *profiler = + create_mrc_profiler(mrc_profiler_type, reader, "", params); g_assert_true(profiler != NULL); profiler->run(); @@ -37,9 +38,7 @@ static void test_shards_profiler_with_fixed_sample_rate(gconstpointer user_data) g_assert_cmpuint(hit_cnt_vec.size(), ==, test_steps); g_assert_cmpuint(hit_size_vec.size(), ==, test_steps); - - - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { g_assert_cmpuint(mrc_size_vec[i], ==, step_size * (i + 1)); } @@ -65,7 +64,6 @@ static void test_shards_profiler_with_fixed_sample_rate(gconstpointer user_data) g_assert_cmpuint(hit_size_vec[8], ==, 2151475712); g_assert_cmpuint(hit_size_vec[9], ==, 2151475712); - delete profiler; close_reader(reader); @@ -75,21 +73,22 @@ static void test_shards_profiler_with_fixed_sample_rate(gconstpointer user_data) * this one for testing with the SHARDS profiler with fiexd sample size * @param user_data */ -static void test_shards_profiler_with_fixed_sample_size(gconstpointer user_data) { - reader_t * reader = setup_vscsi_reader(); +static void test_shards_profiler_with_fixed_sample_size( + gconstpointer user_data) { + reader_t *reader = setup_vscsi_reader(); mrcProfiler::mrc_profiler_params_t params; mrcProfiler::mrc_profiler_e mrc_profiler_type = mrcProfiler::SHARDS_PROFILER; - params.cache_algorithm_str = "LRU"; params.shards_params.parse_params("FIX_SIZE,8192,10"); uint64_t step_size = 202976972; int test_steps = 10; - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { params.profile_size.push_back(step_size * (i + 1)); } - mrcProfiler::MRCProfilerBase * profiler = create_mrc_profiler(mrc_profiler_type, reader, "", params); + mrcProfiler::MRCProfilerBase *profiler = + create_mrc_profiler(mrc_profiler_type, reader, "", params); g_assert_true(profiler != NULL); profiler->run(); @@ -103,9 +102,7 @@ static void test_shards_profiler_with_fixed_sample_size(gconstpointer user_data) g_assert_cmpuint(hit_cnt_vec.size(), ==, test_steps); g_assert_cmpuint(hit_size_vec.size(), ==, test_steps); - - - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { g_assert_cmpuint(mrc_size_vec[i], ==, step_size * (i + 1)); } @@ -131,7 +128,6 @@ static void test_shards_profiler_with_fixed_sample_size(gconstpointer user_data) g_assert_cmpuint(hit_size_vec[8], ==, 2178659536); g_assert_cmpuint(hit_size_vec[9], ==, 2178825309); - delete profiler; close_reader(reader); @@ -141,22 +137,22 @@ static void test_shards_profiler_with_fixed_sample_size(gconstpointer user_data) * this one for testing with the minisim profiler with fiexd sample rate * @param user_data */ -static void test_minisim_profiler_with_fixed_sample_rate(gconstpointer user_data) { - reader_t * reader = setup_vscsi_reader(); +static void test_minisim_profiler_with_fixed_sample_rate( + gconstpointer user_data) { + reader_t *reader = setup_vscsi_reader(); mrcProfiler::mrc_profiler_params_t params; mrcProfiler::mrc_profiler_e mrc_profiler_type = mrcProfiler::MINISIM_PROFILER; - params.cache_algorithm_str = "FIFO"; params.minisim_params.parse_params("FIX_RATE,0.01,1"); uint64_t step_size = 202976972; int test_steps = 10; - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { params.profile_size.push_back(step_size * (i + 1)); } - - mrcProfiler::MRCProfilerBase * profiler = create_mrc_profiler(mrc_profiler_type, reader, "", params); + mrcProfiler::MRCProfilerBase *profiler = + create_mrc_profiler(mrc_profiler_type, reader, "", params); g_assert_true(profiler != NULL); profiler->run(); @@ -170,9 +166,7 @@ static void test_minisim_profiler_with_fixed_sample_rate(gconstpointer user_data g_assert_cmpuint(hit_cnt_vec.size(), ==, test_steps); g_assert_cmpuint(hit_size_vec.size(), ==, test_steps); - - - for(int i = 0; i < test_steps; i++){ + for (int i = 0; i < test_steps; i++) { g_assert_cmpuint(mrc_size_vec[i], ==, step_size * (i + 1)); } @@ -198,23 +192,26 @@ static void test_minisim_profiler_with_fixed_sample_rate(gconstpointer user_data g_assert_cmpuint(hit_size_vec[8], ==, 2044774912); g_assert_cmpuint(hit_size_vec[9], ==, 2046822912); - delete profiler; close_reader(reader); } - int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); g_test_set_nonfatal_assertions(); - g_test_add_data_func("/libCacheSim/test_shards_profiler_with_fixed_sample_rate", NULL, test_shards_profiler_with_fixed_sample_rate); - - g_test_add_data_func("/libCacheSim/test_shards_profiler_with_fixed_sample_size", NULL, test_shards_profiler_with_fixed_sample_size); + g_test_add_data_func( + "/libCacheSim/test_shards_profiler_with_fixed_sample_rate", NULL, + test_shards_profiler_with_fixed_sample_rate); - g_test_add_data_func("/libCacheSim/test_minisim_profiler_with_fixed_sample_rate", NULL, test_minisim_profiler_with_fixed_sample_rate); + g_test_add_data_func( + "/libCacheSim/test_shards_profiler_with_fixed_sample_size", NULL, + test_shards_profiler_with_fixed_sample_size); + g_test_add_data_func( + "/libCacheSim/test_minisim_profiler_with_fixed_sample_rate", NULL, + test_minisim_profiler_with_fixed_sample_rate); return g_test_run(); } \ No newline at end of file diff --git a/test/test_prefetchAlgo.c b/test/test_prefetchAlgo.c index c454382b..1c26e44a 100644 --- a/test/test_prefetchAlgo.c +++ b/test/test_prefetchAlgo.c @@ -6,8 +6,11 @@ static const uint64_t g_req_cnt_true = 113872, g_req_byte_true = 4368040448; -static void _verify_profiler_results(const cache_stat_t *res, uint64_t num_of_sizes, uint64_t req_cnt_true, - const uint64_t *miss_cnt_true, uint64_t req_byte_true, +static void _verify_profiler_results(const cache_stat_t *res, + uint64_t num_of_sizes, + uint64_t req_cnt_true, + const uint64_t *miss_cnt_true, + uint64_t req_byte_true, const uint64_t *miss_byte_true) { for (uint64_t i = 0; i < num_of_sizes; i++) { g_assert_cmpuint(req_cnt_true, ==, res[i].n_req); @@ -41,52 +44,64 @@ static void print_results(const cache_t *cache, const cache_stat_t *res) { } static void test_Mithril(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {79796, 78480, 76126, 75256, 72336, 72062, 71936, 71667}; + uint64_t miss_cnt_true[] = {79796, 78480, 76126, 75256, + 72336, 72062, 71936, 71667}; uint64_t miss_byte_true[] = {3471357440, 3399726080, 3285093888, 3245231616, 3092759040, 3077801472, 3075234816, 3061489664}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("Mithril", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_OBL(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92139, 88548, 82337, 80487, 71259, 70869, 70737, 70469}; + uint64_t miss_cnt_true[] = {92139, 88548, 82337, 80487, + 71259, 70869, 70737, 70469}; uint64_t miss_byte_true[] = {4213140480, 4060079616, 3776877568, 3659406848, 3099764736, 3076965888, 3074241024, 3060499968}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("OBL", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } static void test_PG(gconstpointer user_data) { - uint64_t miss_cnt_true[] = {92786, 89494, 83403, 81564, 72360, 71973, 71842, 71574}; + uint64_t miss_cnt_true[] = {92786, 89494, 83403, 81564, + 72360, 71973, 71842, 71574}; uint64_t miss_byte_true[] = {4195964416, 4054977024, 3776220672, 3659069952, 3100251136, 3077595648, 3074874880, 3061133824}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; + common_cache_params_t cc_params = { + .cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL}; cache_t *cache = create_test_cache("PG", cc_params, reader, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); print_results(cache, res); - _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, miss_cnt_true, g_req_byte_true, miss_byte_true); + _verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true, + miss_cnt_true, g_req_byte_true, miss_byte_true); cache->cache_free(cache); my_free(sizeof(cache_stat_t), res); } @@ -107,7 +122,8 @@ int main(int argc, char *argv[]) { // reader = setup_vscsi_reader_with_ignored_obj_size(); g_test_add_data_func("/libCacheSim/cacheAlgo_Mithril", reader, test_Mithril); g_test_add_data_func("/libCacheSim/cacheAlgo_OBL", reader, test_OBL); - g_test_add_data_func("/libCacheSim/cacheAlgo_PG", reader, test_PG); + g_test_add_data_func_full("/libCacheSim/cacheAlgo_PG", reader, test_PG, + test_teardown); return g_test_run(); } \ No newline at end of file diff --git a/test/test_profilerLRU.c b/test/test_profilerLRU.c index 3431041d..2be1f765 100644 --- a/test/test_profilerLRU.c +++ b/test/test_profilerLRU.c @@ -14,7 +14,8 @@ void test_profilerLRU_basic(gconstpointer user_data) { // double mr_last_true = 1 - 0.569921; // guint64 hc_true[N_TEST] = {0, 2685, 3347, 3908, 4666, 4904}; - double omr_true[N_TEST] = {1, 0.976421, 0.970607, 0.965681, 0.959024, 0.956934}; + double omr_true[N_TEST] = {1, 0.976421, 0.970607, + 0.965681, 0.959024, 0.956934}; // double bmr_true[N_TEST] = {}; mr = get_lru_obj_miss_ratio(reader, get_num_of_req(reader)); @@ -33,22 +34,28 @@ int main(int argc, char *argv[]) { reader_t *reader; reader = setup_plaintxt_reader_num(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_plain_num", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_plain_num", + reader, test_profilerLRU_basic, test_teardown); reader = setup_plaintxt_reader_str(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_plain_str", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_plain_str", + reader, test_profilerLRU_basic, test_teardown); reader = setup_csv_reader_obj_num(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_csv_num", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_csv_num", + reader, test_profilerLRU_basic, test_teardown); reader = setup_csv_reader_obj_str(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_csv_str", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_csv_str", + reader, test_profilerLRU_basic, test_teardown); reader = setup_binary_reader(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_binary", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_binary", + reader, test_profilerLRU_basic, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func("/libCacheSim/test_profilerLRU_basic_vscsi", reader, test_profilerLRU_basic); + g_test_add_data_func_full("/libCacheSim/test_profilerLRU_basic_vscsi", reader, + test_profilerLRU_basic, test_teardown); return g_test_run(); } diff --git a/test/test_simulator.c b/test/test_simulator.c index f53571d4..f8eba214 100644 --- a/test/test_simulator.c +++ b/test/test_simulator.c @@ -14,13 +14,16 @@ static void test_simulator_no_size(gconstpointer user_data) { uint64_t step_size = STEP_SIZE / CACHE_SIZE_UNIT; uint64_t req_cnt_true = 113872; - uint64_t miss_cnt_true[] = {99411, 96397, 95652, 95370, 95182, 94997, 94891, 94816}; + uint64_t miss_cnt_true[] = {99411, 96397, 95652, 95370, + 95182, 94997, 94891, 94816}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = cache_size, .default_ttl = 0}; + common_cache_params_t cc_params = {.cache_size = cache_size, + .default_ttl = 0}; cache_t *cache = LRU_init(cc_params, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, step_size, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, step_size, NULL, 0, 0, _n_cores(), false); // uint64_t* mc = _get_lru_miss_cnt(reader, get_num_of_req(reader)); @@ -51,17 +54,21 @@ static void test_simulator(gconstpointer user_data) { // 3060711936}; // result when LRU DOES NOT considers object size change over time - uint64_t miss_cnt_true[] = {93151, 87793, 83135, 81609, 72481, 72106, 71973, 71702}; + uint64_t miss_cnt_true[] = {93151, 87793, 83135, 81609, + 72481, 72106, 71973, 71702}; uint64_t miss_byte_true[] = {4035348480, 3841399808, 3660518400, 3613104640, 3087721984, 3080147456, 3075377664, 3059534336}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = { - .cache_size = CACHE_SIZE, .default_ttl = 0, .hashpower = 16, .consider_obj_metadata = false}; + common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, + .default_ttl = 0, + .hashpower = 16, + .consider_obj_metadata = false}; cache_t *cache = LRU_init(cc_params, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); // for (uint64_t i = 0; i < CACHE_SIZE / STEP_SIZE; i++) { // printf( // "cache size: %lu, n_req: %lu, n_req_byte: %lu, n_miss: %8lu %16lu\n @@ -78,8 +85,10 @@ static void test_simulator(gconstpointer user_data) { } g_free(res); - uint64_t cache_sizes[] = {STEP_SIZE, STEP_SIZE * 2, STEP_SIZE * 4, STEP_SIZE * 7}; - res = simulate_at_multi_sizes(reader, cache, 4, cache_sizes, NULL, 0, 0, _n_cores(), false); + uint64_t cache_sizes[] = {STEP_SIZE, STEP_SIZE * 2, STEP_SIZE * 4, + STEP_SIZE * 7}; + res = simulate_at_multi_sizes(reader, cache, 4, cache_sizes, NULL, 0, 0, + _n_cores(), false); g_assert_cmpuint(res[0].cache_size, ==, STEP_SIZE); g_assert_cmpuint(res[1].n_req_byte, ==, req_byte_true); g_assert_cmpuint(res[3].n_req, ==, req_cnt_true); @@ -97,7 +106,8 @@ static void test_simulator(gconstpointer user_data) { g_assert_true(caches[i] != NULL); } - res = simulate_with_multi_caches(reader, caches, 4, NULL, 0, 0, _n_cores(), false, false); + res = simulate_with_multi_caches(reader, caches, 4, NULL, 0, 0, _n_cores(), + false, false); g_assert_cmpuint(res[0].cache_size, ==, STEP_SIZE); g_assert_cmpuint(res[1].n_req_byte, ==, req_byte_true); g_assert_cmpuint(res[3].n_req, ==, req_cnt_true); @@ -117,16 +127,19 @@ static void test_simulator(gconstpointer user_data) { */ static void test_simulator_with_warmup1(gconstpointer user_data) { uint64_t req_cnt_true = 113872, req_byte_true = 4205978112; - uint64_t miss_cnt_true[] = {92999, 87632, 82972, 81443, 72316, 71934, 71766, 71307}; + uint64_t miss_cnt_true[] = {92999, 87632, 82972, 81443, + 72316, 71934, 71766, 71307}; uint64_t miss_byte_true[] = {4033582080, 3839580160, 3658690560, 3611252224, 3085914624, 3078132736, 3071579648, 3043186176}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .default_ttl = 0}; + common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, + .default_ttl = 0}; cache_t *cache = LRU_init(cc_params, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, reader, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, reader, 0, 0, _n_cores(), false); for (uint64_t i = 0; i < CACHE_SIZE / STEP_SIZE; i++) { // printf("cache size: %lu, n_req: %lu, n_req_byte: %lu, n_miss: %8lu @@ -146,16 +159,19 @@ static void test_simulator_with_warmup1(gconstpointer user_data) { static void test_simulator_with_warmup2(gconstpointer user_data) { uint64_t req_cnt_true = 91098, req_byte_true = 3180282368; - uint64_t miss_cnt_true[] = {75018, 69709, 65274, 63750, 57484, 57124, 56991, 56720}; + uint64_t miss_cnt_true[] = {75018, 69709, 65274, 63750, + 57484, 57124, 56991, 56720}; uint64_t miss_byte_true[] = {3035036672, 2842572288, 2672791552, 2625385984, 2269361664, 2261869056, 2257099264, 2241255936}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .default_ttl = 0}; + common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, + .default_ttl = 0}; cache_t *cache = LRU_init(cc_params, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0.2, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0.2, 0, _n_cores(), false); for (uint64_t i = 0; i < CACHE_SIZE / STEP_SIZE; i++) { // printf("cache size: %lu, n_req: %lu, n_req_byte: %lu, n_miss: %8lu @@ -175,20 +191,25 @@ static void test_simulator_with_warmup2(gconstpointer user_data) { static void test_simulator_with_ttl(gconstpointer user_data) { uint64_t req_cnt_true = 113872, req_byte_true = 4205978112; - uint64_t miss_cnt_true[] = {93240, 87890, 83268, 81743, 72649, 72284, 72165, 72086}; + uint64_t miss_cnt_true[] = {93240, 87890, 83268, 81743, + 72649, 72284, 72165, 72086}; uint64_t miss_byte_true[] = {4035856384, 3842041344, 3662972928, 3615563264, 3090454016, 3082932736, 3078236672, 3075259904}; reader_t *reader = (reader_t *)user_data; - common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, .default_ttl = 2400}; + common_cache_params_t cc_params = {.cache_size = CACHE_SIZE, + .default_ttl = 2400}; cache_t *cache = LRU_init(cc_params, NULL); g_assert_true(cache != NULL); - cache_stat_t *res = simulate_at_multi_sizes_with_step_size(reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); + cache_stat_t *res = simulate_at_multi_sizes_with_step_size( + reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false); for (uint64_t i = 0; i < CACHE_SIZE / STEP_SIZE; i++) { - printf("cache size: %lu, n_req: %ld, n_req_byte: %ld, n_miss: %8ld %16ld\n", (unsigned long)res[i].cache_size, - (long)res[i].n_req, (long)res[i].n_req_byte, (long)res[i].n_miss, (long)res[i].n_miss_byte); + printf("cache size: %lu, n_req: %ld, n_req_byte: %ld, n_miss: %8ld %16ld\n", + (unsigned long)res[i].cache_size, (long)res[i].n_req, + (long)res[i].n_req_byte, (long)res[i].n_miss, + (long)res[i].n_miss_byte); g_assert_cmpuint(res[i].cache_size, ==, STEP_SIZE * (i + 1)); g_assert_cmpuint(res[i].n_req, ==, req_cnt_true); g_assert_cmpuint(res[i].n_req_byte, ==, req_byte_true); @@ -205,32 +226,41 @@ int main(int argc, char *argv[]) { reader_t *reader; reader = setup_plaintxt_reader_num(); - g_test_add_data_func_full("/libCacheSim/simulator_no_size_plain_num", reader, test_simulator_no_size, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_no_size_plain_num", reader, + test_simulator_no_size, test_teardown); reader = setup_plaintxt_reader_str(); - g_test_add_data_func_full("/libCacheSim/simulator_no_size_plain_str", reader, test_simulator_no_size, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_no_size_plain_str", reader, + test_simulator_no_size, test_teardown); reader = setup_csv_reader_obj_num(); - g_test_add_data_func_full("/libCacheSim/simulator_csv_num", reader, test_simulator, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_csv_num", reader, + test_simulator, test_teardown); reader = setup_csv_reader_obj_str(); - g_test_add_data_func_full("/libCacheSim/simulator_csv_str", reader, test_simulator, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_csv_str", reader, + test_simulator, test_teardown); reader = setup_binary_reader(); - g_test_add_data_func_full("/libCacheSim/simulator_binary", reader, test_simulator, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_binary", reader, + test_simulator, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func_full("/libCacheSim/simulator_vscsi", reader, test_simulator, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_vscsi", reader, + test_simulator, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func_full("/libCacheSim/simulator_warmup1", reader, test_simulator_with_warmup1, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_warmup1", reader, + test_simulator_with_warmup1, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func_full("/libCacheSim/simulator_warmup2", reader, test_simulator_with_warmup2, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_warmup2", reader, + test_simulator_with_warmup2, test_teardown); #ifdef SUPPORT_TTL reader = setup_vscsi_reader(); - g_test_add_data_func_full("/libCacheSim/simulator_with_ttl", reader, test_simulator_with_ttl, test_teardown); + g_test_add_data_func_full("/libCacheSim/simulator_with_ttl", reader, + test_simulator_with_ttl, test_teardown); #endif return g_test_run(); diff --git a/test/test_traceReader.c b/test/test_traceReader.c index 8adc9233..8c0b2768 100644 --- a/test/test_traceReader.c +++ b/test/test_traceReader.c @@ -15,9 +15,11 @@ static const size_t trace_start_req_d[N_TEST_REQ] = { static const char *trace_start_req_s[N_TEST_REQ] = { "42932745", "42932746", "42932747", "40409911", "31954535", "6238199", }; -static const int64_t trace_start_req_time[N_TEST_REQ] = {5633898368802, 5633898611441, 5633898745540, - 5633898967708, 5633899967748, 5633899967980}; -static const size_t trace_start_req_size[N_TEST_REQ] = {512, 512, 512, 6656, 6144, 57344}; +static const int64_t trace_start_req_time[N_TEST_REQ] = { + 5633898368802, 5633898611441, 5633898745540, + 5633898967708, 5633899967748, 5633899967980}; +static const size_t trace_start_req_size[N_TEST_REQ] = {512, 512, 512, + 6656, 6144, 57344}; static const size_t trace_end_req_d = 42936150; static const char *trace_end_req_s = "42936150"; @@ -27,13 +29,15 @@ static void verify_req(reader_t *reader, request_t *req, int req_idx) { return; } - if (obj_id_is_num(reader)) g_assert_true(req->obj_id == trace_start_req_d[req_idx]); + if (obj_id_is_num(reader)) + g_assert_true(req->obj_id == trace_start_req_d[req_idx]); // we do not use g_quark_to_string() because it uses too much memory // else // g_assert_cmpstr(g_quark_to_string(req->obj_id), ==, // trace_start_req_s[req_idx]); - if (get_trace_type(reader) == CSV_TRACE || get_trace_type(reader) == BIN_TRACE || + if (get_trace_type(reader) == CSV_TRACE || + get_trace_type(reader) == BIN_TRACE || get_trace_type(reader) == VSCSI_TRACE) { g_assert_true(req->clock_time == trace_start_req_time[req_idx] || req->clock_time == trace_start_req_time[req_idx] / 1000000); @@ -140,7 +144,8 @@ void test_twr(gconstpointer user_data) { // (unsigned long long) req->obj_id, (long) req->obj_size, // (long) req->ttl, req->op); } - printf("%llu req %llu obj\n", (unsigned long long)n_req, (unsigned long long)n_obj); + printf("%llu req %llu obj\n", (unsigned long long)n_req, + (unsigned long long)n_obj); } int main(int argc, char *argv[]) { @@ -148,39 +153,60 @@ int main(int argc, char *argv[]) { reader_t *reader; reader = setup_plaintxt_reader_num(); - g_test_add_data_func("/libCacheSim/reader_basic_plain_num", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_plain_num", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_plain_num", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_plain_num", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_plain_num", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_plain_num", reader, + test_reader_more2, test_teardown); reader = setup_plaintxt_reader_str(); - g_test_add_data_func("/libCacheSim/reader_basic_plain_str", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_plain_str", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_plain_str", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_plain_str", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_plain_str", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_plain_str", reader, + test_reader_more2, test_teardown); reader = setup_csv_reader_obj_num(); - g_test_add_data_func("/libCacheSim/reader_basic_csv_num", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_csv_num", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_csv_num", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_csv_num", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_csv_num", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_csv_num", reader, + test_reader_more2, test_teardown); reader = setup_csv_reader_obj_str(); - g_test_add_data_func("/libCacheSim/reader_basic_csv_str", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_csv_str", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_csv_str", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_csv_str", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_csv_str", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_csv_str", reader, + test_reader_more2, test_teardown); reader = setup_binary_reader(); - g_test_add_data_func("/libCacheSim/reader_basic_binary", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_binary", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_binary", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_binary", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_binary", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_binary", reader, + test_reader_more2, test_teardown); reader = setup_vscsi_reader(); - g_test_add_data_func("/libCacheSim/reader_basic_vscsi", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_vscsi", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_vscsi", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_vscsi", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_vscsi", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_vscsi", reader, + test_reader_more2, test_teardown); reader = setup_oracleGeneralBin_reader(); - g_test_add_data_func("/libCacheSim/reader_basic_oracleGeneral", reader, test_reader_basic); - g_test_add_data_func("/libCacheSim/reader_more1_oracleGeneral", reader, test_reader_more1); - g_test_add_data_func_full("/libCacheSim/reader_more2_oracleGeneral", reader, test_reader_more2, test_teardown); + g_test_add_data_func("/libCacheSim/reader_basic_oracleGeneral", reader, + test_reader_basic); + g_test_add_data_func("/libCacheSim/reader_more1_oracleGeneral", reader, + test_reader_more1); + g_test_add_data_func_full("/libCacheSim/reader_more2_oracleGeneral", reader, + test_reader_more2, test_teardown); // g_test_add_data_func("/libCacheSim/test_twr", NULL, test_twr); return g_test_run(); diff --git a/test/test_utils.c b/test/test_utils.c index c3cf7b06..3c498b2f 100644 --- a/test/test_utils.c +++ b/test/test_utils.c @@ -6,47 +6,46 @@ #include "common.h" bool directory_exists(const char *path) { - struct stat info; - return (stat(path, &info) == 0 && (info.st_mode & S_IFDIR)); + struct stat info; + return (stat(path, &info) == 0 && (info.st_mode & S_IFDIR)); } void test_create_dir(gconstpointer user_data) { - char base_dir[] = "/tmp/gtest_dir_test"; - - if (directory_exists(base_dir)) { - if(system("rm -rf /tmp/gtest_dir_test") != 0) { - perror("Failed to delete file"); - } + char base_dir[] = "/tmp/gtest_dir_test"; + if (directory_exists(base_dir)) { + if (system("rm -rf /tmp/gtest_dir_test") != 0) { + perror("Failed to delete file"); } - - // case 1: single dir - char single_dir[1024]; - snprintf(single_dir, sizeof(single_dir), "%s/single", base_dir); - create_dir(single_dir); - g_assert_true(directory_exists(single_dir)); - - // case 2: multi dir - char multi_dir[1024]; - snprintf(multi_dir, sizeof(multi_dir), "%s/multi/level/directory", base_dir); - create_dir(multi_dir); - g_assert_true(directory_exists(multi_dir)); - - // case 3: dir exists - create_dir(single_dir); - g_assert_true(directory_exists(single_dir)); - - // case 4: tail / - char slash_dir[1024]; - snprintf(slash_dir, sizeof(slash_dir), "%s/with_slash/", base_dir); - create_dir(slash_dir); - g_assert_true(directory_exists(slash_dir)); - - // printf("All create_dir tests passed!\n"); + } + + // case 1: single dir + char single_dir[1024]; + snprintf(single_dir, sizeof(single_dir), "%s/single", base_dir); + create_dir(single_dir); + g_assert_true(directory_exists(single_dir)); + + // case 2: multi dir + char multi_dir[1024]; + snprintf(multi_dir, sizeof(multi_dir), "%s/multi/level/directory", base_dir); + create_dir(multi_dir); + g_assert_true(directory_exists(multi_dir)); + + // case 3: dir exists + create_dir(single_dir); + g_assert_true(directory_exists(single_dir)); + + // case 4: tail / + char slash_dir[1024]; + snprintf(slash_dir, sizeof(slash_dir), "%s/with_slash/", base_dir); + create_dir(slash_dir); + g_assert_true(directory_exists(slash_dir)); + + // printf("All create_dir tests passed!\n"); } int main(int argc, char *argv[]) { - g_test_init(&argc, &argv, NULL); - g_test_add_data_func("/test_create_dir", NULL, test_create_dir); - return g_test_run(); + g_test_init(&argc, &argv, NULL); + g_test_add_data_func("/test_create_dir", NULL, test_create_dir); + return g_test_run(); }