Skip to content

Commit 0a210a7

Browse files
authored
[refactor] refactor test (#227)
* Update CI workflow to enable parallel testing in build jobs * refactor eviction test * Refactor prefetch algorithm tests to use a unified test function and update expected values in eviction tests * fix BeladySize eviction test * fix Belady memory leak
1 parent 17fc4ec commit 0a210a7

5 files changed

Lines changed: 418 additions & 639 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Test
2525
working-directory: ${{github.workspace}}/build
2626
run: |
27-
ctest -C ${{env.BUILD_TYPE}} --output-on-failure
27+
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
2828
2929
ubuntu:
3030
runs-on: ubuntu-latest
@@ -44,7 +44,7 @@ jobs:
4444
working-directory: ${{github.workspace}}/build
4545
run: |
4646
export ASAN_OPTIONS="detect_leaks=1:halt_on_error=1:verbosity=1"
47-
ctest -C ${{env.BUILD_TYPE}} --output-on-failure
47+
ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
4848
4949
selfhosted:
5050
runs-on: self-hosted
@@ -56,7 +56,7 @@ jobs:
5656
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
5757
- name: Test
5858
working-directory: ${{github.workspace}}/build
59-
run: ctest -C ${{env.BUILD_TYPE}} -j
59+
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure --parallel
6060

6161

6262

libCacheSim/cache/eviction/Belady.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static void Belady_free(cache_t *cache) {
8787
node = pqueue_pop(params->pq);
8888
}
8989
pqueue_free(params->pq);
90+
my_free(sizeof(Belady_params_t), params);
9091

9192
cache_struct_free(cache);
9293
}

test/test_admissionAlgo.c

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
#include "common.h"
22

3-
static const uint64_t g_req_cnt_true = 113872, g_req_byte_true = 4368040448;
3+
// Constants
4+
static const uint64_t g_req_cnt_true = 113872;
5+
static const uint64_t g_req_byte_true = 4368040448;
6+
static const uint64_t NUM_TEST_SIZES = 8;
7+
8+
// Test data structure
9+
typedef struct {
10+
const char *cache_name;
11+
uint64_t hashpower;
12+
uint64_t req_cnt_true;
13+
uint64_t req_byte_true;
14+
uint64_t miss_cnt_true[8];
15+
uint64_t miss_byte_true[8];
16+
} admission_test_data_t;
17+
18+
// Test data definitions (ordered alphabetically by algorithm name)
19+
static const admission_test_data_t test_data_truth[] = {
20+
{.cache_name = "AdaptSize",
21+
.hashpower = 20,
22+
.req_cnt_true = 113872,
23+
.req_byte_true = 4368040448,
24+
.miss_cnt_true = {83204, 80907, 77835, 77086, 76173, 76158, 76158, 76158},
25+
.miss_byte_true = {3996894720, 3916923392, 3790021120, 3751927808,
26+
3695680512, 3695609344, 3695609344, 3695609344}},
27+
{.cache_name = "BloomFilter",
28+
.hashpower = 20,
29+
.req_cnt_true = 113872,
30+
.req_byte_true = 4368040448,
31+
.miss_cnt_true = {94816, 90386, 88417, 85744, 82344, 79504, 77058, 76979},
32+
.miss_byte_true = {4193502720, 3979631104, 3877562880, 3716727296,
33+
3503820288, 3323299328, 3257762304, 3254848512}},
34+
{.cache_name = "Size",
35+
.hashpower = 20,
36+
.req_cnt_true = 113872,
37+
.req_byte_true = 4368040448,
38+
.miss_cnt_true = {93374, 89783, 83572, 81722, 72494, 72104, 71972, 71704},
39+
.miss_byte_true = {4214303232, 4061242368, 3778040320, 3660569600,
40+
3100927488, 3078128640, 3075403776, 3061662720}},
41+
{.cache_name = "SizeProb",
42+
.hashpower = 20,
43+
.req_cnt_true = 113872,
44+
.req_byte_true = 4368040448,
45+
.miss_cnt_true = {93371, 89122, 83635, 81935, 73293, 72963, 72737, 71949},
46+
.miss_byte_true = {4214365696, 4030683648, 3781775872, 3671897088,
47+
3151684096, 3133195264, 3123936256, 3078763520}}};
448

549
static void _verify_profiler_results(const cache_stat_t *res,
650
uint64_t num_of_sizes,
@@ -39,88 +83,45 @@ static void print_results(const cache_t *cache, const cache_stat_t *res) {
3983
printf("};\n");
4084
}
4185

42-
static void test_AdaptSize(gconstpointer user_data) {
43-
uint64_t miss_cnt_true[] = {83204, 80907, 77835, 77086,
44-
76173, 76158, 76158, 76158};
45-
uint64_t miss_byte_true[] = {3996894720, 3916923392, 3790021120, 3751927808,
46-
3695680512, 3695609344, 3695609344, 3695609344};
47-
86+
// Generic test function that works for all admission algorithms
87+
static void test_admission_algorithm(gconstpointer user_data,
88+
const admission_test_data_t *test_data) {
4889
reader_t *reader = (reader_t *)user_data;
49-
common_cache_params_t cc_params = {
50-
.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
51-
cache_t *cache = create_test_cache("AdaptSize", cc_params, reader, NULL);
52-
g_assert_true(cache != NULL);
53-
cache_stat_t *res = simulate_at_multi_sizes_with_step_size(
54-
reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false);
55-
56-
print_results(cache, res);
57-
_verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true,
58-
miss_cnt_true, g_req_byte_true, miss_byte_true);
59-
cache->cache_free(cache);
60-
my_free(sizeof(cache_stat_t), res);
61-
}
90+
common_cache_params_t cc_params = {.cache_size = CACHE_SIZE,
91+
.hashpower = test_data->hashpower,
92+
.default_ttl = DEFAULT_TTL};
6293

63-
static void test_Size(gconstpointer user_data) {
64-
uint64_t miss_cnt_true[] = {93374, 89783, 83572, 81722,
65-
72494, 72104, 71972, 71704};
66-
uint64_t miss_byte_true[] = {4214303232, 4061242368, 3778040320, 3660569600,
67-
3100927488, 3078128640, 3075403776, 3061662720};
68-
69-
reader_t *reader = (reader_t *)user_data;
70-
common_cache_params_t cc_params = {
71-
.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
72-
cache_t *cache = create_test_cache("Size", cc_params, reader, NULL);
94+
cache_t *cache =
95+
create_test_cache(test_data->cache_name, cc_params, reader, NULL);
7396
g_assert_true(cache != NULL);
97+
7498
cache_stat_t *res = simulate_at_multi_sizes_with_step_size(
7599
reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false);
76100

77101
print_results(cache, res);
78-
_verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true,
79-
miss_cnt_true, g_req_byte_true, miss_byte_true);
102+
_verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, test_data->req_cnt_true,
103+
test_data->miss_cnt_true, test_data->req_byte_true,
104+
test_data->miss_byte_true);
105+
80106
cache->cache_free(cache);
81107
my_free(sizeof(cache_stat_t), res);
82108
}
83109

84-
static void test_SizeProb(gconstpointer user_data) {
85-
uint64_t miss_cnt_true[] = {93371, 89122, 83635, 81935,
86-
73293, 72963, 72737, 71949};
87-
uint64_t miss_byte_true[] = {4214365696, 4030683648, 3781775872, 3671897088,
88-
3151684096, 3133195264, 3123936256, 3078763520};
89-
90-
reader_t *reader = (reader_t *)user_data;
91-
common_cache_params_t cc_params = {
92-
.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
93-
cache_t *cache = create_test_cache("SizeProb", cc_params, reader, NULL);
94-
g_assert_true(cache != NULL);
95-
cache_stat_t *res = simulate_at_multi_sizes_with_step_size(
96-
reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false);
97-
98-
print_results(cache, res);
99-
_verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true,
100-
miss_cnt_true, g_req_byte_true, miss_byte_true);
101-
cache->cache_free(cache);
102-
my_free(sizeof(cache_stat_t), res);
110+
// Individual test functions (ordered alphabetically)
111+
static void test_AdaptSize(gconstpointer user_data) {
112+
test_admission_algorithm(user_data, &test_data_truth[0]);
103113
}
104114

105115
static void test_BloomFilter(gconstpointer user_data) {
106-
uint64_t miss_cnt_true[] = {94816, 90386, 88417, 85744,
107-
82344, 79504, 77058, 76979};
108-
uint64_t miss_byte_true[] = {4193502720, 3979631104, 3877562880, 3716727296,
109-
3503820288, 3323299328, 3257762304, 3254848512};
116+
test_admission_algorithm(user_data, &test_data_truth[1]);
117+
}
110118

111-
reader_t *reader = (reader_t *)user_data;
112-
common_cache_params_t cc_params = {
113-
.cache_size = CACHE_SIZE, .hashpower = 20, .default_ttl = DEFAULT_TTL};
114-
cache_t *cache = create_test_cache("BloomFilter", cc_params, reader, NULL);
115-
g_assert_true(cache != NULL);
116-
cache_stat_t *res = simulate_at_multi_sizes_with_step_size(
117-
reader, cache, STEP_SIZE, NULL, 0, 0, _n_cores(), false);
119+
static void test_Size(gconstpointer user_data) {
120+
test_admission_algorithm(user_data, &test_data_truth[2]);
121+
}
118122

119-
print_results(cache, res);
120-
_verify_profiler_results(res, CACHE_SIZE / STEP_SIZE, g_req_cnt_true,
121-
miss_cnt_true, g_req_byte_true, miss_byte_true);
122-
cache->cache_free(cache);
123-
my_free(sizeof(cache_stat_t), res);
123+
static void test_SizeProb(gconstpointer user_data) {
124+
test_admission_algorithm(user_data, &test_data_truth[3]);
124125
}
125126

126127
static void empty_test(gconstpointer user_data) { ; }
@@ -139,13 +140,14 @@ int main(int argc, char *argv[]) {
139140

140141
reader = setup_oracleGeneralBin_reader();
141142

143+
// Test registrations (ordered alphabetically)
142144
g_test_add_data_func("/libCacheSim/admissionAlgo_AdaptSize", reader,
143145
test_AdaptSize);
146+
g_test_add_data_func("/libCacheSim/admissionAlgo_BloomFilter", reader,
147+
test_BloomFilter);
144148
g_test_add_data_func("/libCacheSim/admissionAlgo_Size", reader, test_Size);
145-
g_test_add_data_func("/libCacheSim/admissionAlgo_SizeProb", reader,
146-
test_SizeProb);
147-
g_test_add_data_func_full("/libCacheSim/admissionAlgo_BloomFilter", reader,
148-
test_BloomFilter, test_teardown);
149+
g_test_add_data_func_full("/libCacheSim/admissionAlgo_SizeProb", reader,
150+
test_SizeProb, test_teardown);
149151

150152
return g_test_run();
151153
}

0 commit comments

Comments
 (0)