-
Notifications
You must be signed in to change notification settings - Fork 2
/
lru_test.cpp
executable file
·72 lines (62 loc) · 1.58 KB
/
lru_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdlib.h>
#include "SACache.h"
#include "GenericCache.h"
#include "CacheMemory.h"
#include "RP_LRU.h"
int main()
{
unsigned P = 1;
srand(time(0));
//test hits for exact set fit
for (unsigned way_bits = 1; way_bits < 6; way_bits++)
{
unsigned ways = 1 << way_bits;
CacheConfig config = {way_bits, way_bits, 1, 0};
RP_LRU policy(config);
RMapper R(config, P, 0);
Cache *cache = new GenericCache(config, policy, R, P);
//preload set
for (unsigned i = 0; i < ways; i++)
{
size_t addr = i;
cache->access({addr, 0, false, false});
}
//test it (not expecting a surprise here)
for (unsigned i = 0; i < 5; i++)
{
for (unsigned j = 0; j < ways; j++)
{
size_t addr = j;
if (!cache->access({addr, 0, false, false}).hit)
{
printf("unexpected miss, ways: %u, addr: %lx\n", ways, addr);
return -1;
}
}
}
delete cache;
}
//test missing for overfull set
for (unsigned way_bits = 0; way_bits < 6; way_bits++)
{
unsigned ways = 1 << way_bits;
CacheConfig config = {way_bits, way_bits, 1, 0};
RP_LRU policy(config);
RMapper R(config, P, 0);
Cache *cache = new GenericCache(config, policy, R, P);
for (unsigned i = 0; i < 100; i++)
{
for (unsigned j = 0; j < ways+1; j++)
{
size_t addr = j;
if (cache->access({addr, 0, false, false}).hit)
{
printf("unexpected hit, ways: %u, addr: %lx\n", ways, addr);
return -1;
}
}
}
delete cache;
}
return 0;
}