44
55#include "common.h"
66
7- static const uint64_t g_req_cnt_true = 113872 , g_req_byte_true = 4368040448 ;
7+ // Constants
8+ static const uint64_t g_req_cnt_true = 113872 ;
9+ static const uint64_t g_req_byte_true = 4368040448 ;
10+ static const uint64_t NUM_TEST_SIZES = 8 ;
11+
12+ // Test data structure
13+ typedef struct {
14+ const char * cache_name ;
15+ uint64_t hashpower ;
16+ uint64_t req_cnt_true ;
17+ uint64_t req_byte_true ;
18+ uint64_t miss_cnt_true [8 ];
19+ uint64_t miss_byte_true [8 ];
20+ } prefetch_test_data_t ;
21+
22+ // Test data definitions (ordered alphabetically by algorithm name)
23+ static const prefetch_test_data_t test_data_truth [] = {
24+ {.cache_name = "Mithril" ,
25+ .hashpower = 20 ,
26+ .req_cnt_true = 113872 ,
27+ .req_byte_true = 4368040448 ,
28+ .miss_cnt_true = {79796 , 78480 , 76126 , 75256 , 72336 , 72062 , 71936 , 71667 },
29+ .miss_byte_true = {3471357440 , 3399726080 , 3285093888 , 3245231616 ,
30+ 3092759040 , 3077801472 , 3075234816 , 3061489664 }},
31+ {.cache_name = "OBL" ,
32+ .hashpower = 20 ,
33+ .req_cnt_true = 113872 ,
34+ .req_byte_true = 4368040448 ,
35+ .miss_cnt_true = {92139 , 88548 , 82337 , 80487 , 71259 , 70869 , 70737 , 70469 },
36+ .miss_byte_true = {4213140480 , 4060079616 , 3776877568 , 3659406848 ,
37+ 3099764736 , 3076965888 , 3074241024 , 3060499968 }},
38+ {.cache_name = "PG" ,
39+ .hashpower = 20 ,
40+ .req_cnt_true = 113872 ,
41+ .req_byte_true = 4368040448 ,
42+ .miss_cnt_true = {92786 , 89494 , 83403 , 81564 , 72360 , 71973 , 71842 , 71574 },
43+ .miss_byte_true = {4195964416 , 4054977024 , 3776220672 , 3659069952 ,
44+ 3100251136 , 3077595648 , 3074874880 , 3061133824 }}};
845
946static void _verify_profiler_results (const cache_stat_t * res ,
1047 uint64_t num_of_sizes ,
@@ -43,67 +80,41 @@ static void print_results(const cache_t *cache, const cache_stat_t *res) {
4380 printf ("};\n" );
4481}
4582
46- static void test_Mithril (gconstpointer user_data ) {
47- uint64_t miss_cnt_true [] = {79796 , 78480 , 76126 , 75256 ,
48- 72336 , 72062 , 71936 , 71667 };
49- uint64_t miss_byte_true [] = {3471357440 , 3399726080 , 3285093888 , 3245231616 ,
50- 3092759040 , 3077801472 , 3075234816 , 3061489664 };
51-
83+ // Generic test function that works for all prefetch algorithms
84+ static void test_prefetch_algorithm (gconstpointer user_data ,
85+ const prefetch_test_data_t * test_data ) {
5286 reader_t * reader = (reader_t * )user_data ;
53- common_cache_params_t cc_params = {
54- .cache_size = CACHE_SIZE , .hashpower = 20 , .default_ttl = DEFAULT_TTL };
55- cache_t * cache = create_test_cache ("Mithril" , cc_params , reader , NULL );
87+ common_cache_params_t cc_params = {.cache_size = CACHE_SIZE ,
88+ .hashpower = test_data -> hashpower ,
89+ .default_ttl = DEFAULT_TTL };
90+
91+ cache_t * cache =
92+ create_test_cache (test_data -> cache_name , cc_params , reader , NULL );
5693 g_assert_true (cache != NULL );
94+
5795 cache_stat_t * res = simulate_at_multi_sizes_with_step_size (
5896 reader , cache , STEP_SIZE , NULL , 0 , 0 , _n_cores (), false);
5997
6098 print_results (cache , res );
61- _verify_profiler_results (res , CACHE_SIZE / STEP_SIZE , g_req_cnt_true ,
62- miss_cnt_true , g_req_byte_true , miss_byte_true );
99+ _verify_profiler_results (res , CACHE_SIZE / STEP_SIZE , test_data -> req_cnt_true ,
100+ test_data -> miss_cnt_true , test_data -> req_byte_true ,
101+ test_data -> miss_byte_true );
102+
63103 cache -> cache_free (cache );
64104 my_free (sizeof (cache_stat_t ), res );
65105}
66106
67- static void test_OBL (gconstpointer user_data ) {
68- uint64_t miss_cnt_true [] = {92139 , 88548 , 82337 , 80487 ,
69- 71259 , 70869 , 70737 , 70469 };
70- uint64_t miss_byte_true [] = {4213140480 , 4060079616 , 3776877568 , 3659406848 ,
71- 3099764736 , 3076965888 , 3074241024 , 3060499968 };
72-
73- reader_t * reader = (reader_t * )user_data ;
74- common_cache_params_t cc_params = {
75- .cache_size = CACHE_SIZE , .hashpower = 20 , .default_ttl = DEFAULT_TTL };
76- cache_t * cache = create_test_cache ("OBL" , cc_params , reader , NULL );
77- g_assert_true (cache != NULL );
78- cache_stat_t * res = simulate_at_multi_sizes_with_step_size (
79- reader , cache , STEP_SIZE , NULL , 0 , 0 , _n_cores (), false);
107+ // Individual test functions (ordered alphabetically)
108+ static void test_Mithril (gconstpointer user_data ) {
109+ test_prefetch_algorithm (user_data , & test_data_truth [0 ]);
110+ }
80111
81- print_results (cache , res );
82- _verify_profiler_results (res , CACHE_SIZE / STEP_SIZE , g_req_cnt_true ,
83- miss_cnt_true , g_req_byte_true , miss_byte_true );
84- cache -> cache_free (cache );
85- my_free (sizeof (cache_stat_t ), res );
112+ static void test_OBL (gconstpointer user_data ) {
113+ test_prefetch_algorithm (user_data , & test_data_truth [1 ]);
86114}
87115
88116static void test_PG (gconstpointer user_data ) {
89- uint64_t miss_cnt_true [] = {92786 , 89494 , 83403 , 81564 ,
90- 72360 , 71973 , 71842 , 71574 };
91- uint64_t miss_byte_true [] = {4195964416 , 4054977024 , 3776220672 , 3659069952 ,
92- 3100251136 , 3077595648 , 3074874880 , 3061133824 };
93-
94- reader_t * reader = (reader_t * )user_data ;
95- common_cache_params_t cc_params = {
96- .cache_size = CACHE_SIZE , .hashpower = 20 , .default_ttl = DEFAULT_TTL };
97- cache_t * cache = create_test_cache ("PG" , cc_params , reader , NULL );
98- g_assert_true (cache != NULL );
99- cache_stat_t * res = simulate_at_multi_sizes_with_step_size (
100- reader , cache , STEP_SIZE , NULL , 0 , 0 , _n_cores (), false);
101-
102- print_results (cache , res );
103- _verify_profiler_results (res , CACHE_SIZE / STEP_SIZE , g_req_cnt_true ,
104- miss_cnt_true , g_req_byte_true , miss_byte_true );
105- cache -> cache_free (cache );
106- my_free (sizeof (cache_stat_t ), res );
117+ test_prefetch_algorithm (user_data , & test_data_truth [2 ]);
107118}
108119
109120int main (int argc , char * argv []) {
@@ -120,6 +131,8 @@ int main(int argc, char *argv[]) {
120131
121132 reader = setup_oracleGeneralBin_reader ();
122133 // reader = setup_vscsi_reader_with_ignored_obj_size();
134+
135+ // Test registrations (ordered alphabetically)
123136 g_test_add_data_func ("/libCacheSim/cacheAlgo_Mithril" , reader , test_Mithril );
124137 g_test_add_data_func ("/libCacheSim/cacheAlgo_OBL" , reader , test_OBL );
125138 g_test_add_data_func_full ("/libCacheSim/cacheAlgo_PG" , reader , test_PG ,
0 commit comments