gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
fifo_rp.test.cc
Go to the documentation of this file.
1
28
29#include <gtest/gtest-spi.h>
30#include <gtest/gtest.h>
31
32#include <cassert>
33
35#include "params/FIFORP.hh"
36
38class FIFORPTestF : public ::testing::Test
39{
40 public:
41 std::shared_ptr<gem5::replacement_policy::FIFO> rp;
42
44 {
45 gem5::FIFORPParams params;
46 params.eventq_index = 0;
47 rp = std::make_shared<gem5::replacement_policy::FIFO>(params);
48 }
49};
50
52TEST_F(FIFORPTestF, InstantiatedEntry)
53{
54 const auto repl_data = rp->instantiateEntry();
55
56 // instantiateEntry must return a valid pointer
57 ASSERT_NE(repl_data, nullptr);
58}
59
62TEST_F(FIFORPTestF, GetVictim1Candidate)
63{
65 entry.replacementData = rp->instantiateEntry();
67 candidates.push_back(&entry);
68 ASSERT_EQ(rp->getVictim(candidates), &entry);
69
70 rp->invalidate(entry.replacementData);
71 ASSERT_EQ(rp->getVictim(candidates), &entry);
72
73 rp->reset(entry.replacementData);
74 ASSERT_EQ(rp->getVictim(candidates), &entry);
75
76 rp->touch(entry.replacementData);
77 ASSERT_EQ(rp->getVictim(candidates), &entry);
78}
79
82{
83 protected:
84 // The entries being victimized
86
87 // The entries, in candidate form
89
90 public:
91 // The number of entries is arbitrary. It does not need to be high, since
92 // having more entries is not expected to increase coverage
94 {
95 for (auto &entry : entries) {
96 entry.replacementData = rp->instantiateEntry();
97 candidates.push_back(&entry);
98 }
99 }
100};
101
104TEST_F(FIFORPVictimizationTestF, GetVictimAllInvalid)
105{
106 auto expected_victim = &entries.front();
107
108 // At this point all candidates are considered to be first, since
109 // no entries have ever been reset
110 ASSERT_EQ(rp->getVictim(candidates), expected_victim);
111
112 // Since all candidates are already invalid, nothing changes if we
113 // invalidate all of them again. Do it with a reversed invalidation
114 // order to show that we always pick the front candidate, even if it
115 // was invalidated last
116 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) {
117 rp->invalidate((*it)->replacementData);
118 }
119 ASSERT_EQ(rp->getVictim(candidates), expected_victim);
120}
121
125TEST_F(FIFORPVictimizationTestF, GetVictimAllInvalid2)
126{
127 auto expected_victim = &entries.front();
128
129 // At this point all candidates are considered to be first, since
130 // no entries have ever been reset
131 ASSERT_EQ(rp->getVictim(candidates), expected_victim);
132
133 // Since all candidates are already invalid, nothing changes if we
134 // invalidate all of them again.
135 for (auto it = candidates.rbegin(); it != candidates.rend(); ++it) {
136 rp->invalidate((*it)->replacementData);
137 }
138 ASSERT_EQ(rp->getVictim(candidates), expected_victim);
139}
140
143TEST_F(FIFORPVictimizationTestF, GetVictimOneInvalid)
144{
145 for (auto &entry : entries) {
146 // Validate all entries to start from a clean state
147 for (auto &entry : entries) {
148 rp->reset(entry.replacementData);
149 }
150
151 // Set one of the entries as invalid
152 rp->invalidate(entry.replacementData);
153
154 ASSERT_EQ(rp->getVictim(candidates), &entry);
155 }
156}
157
160{
161 for (size_t i = 0; i < entries.size(); ++i) {
162 SCOPED_TRACE(i);
163 auto &entry = entries[i];
164
165 // Reset one of the entries to make it become the single first entry
166 rp->reset(entry.replacementData);
167
168 // Now change ticks and validate all other entries to make them not
169 // tie for first entry
170 for (size_t j = 0; j < entries.size(); ++j) {
171 if (i != j) {
172 rp->reset(entries[j].replacementData);
173 }
174 }
175
176 ASSERT_EQ(rp->getVictim(candidates), &entry);
177 }
178}
179
182TEST_F(FIFORPVictimizationTestF, GetVictimAfterTouch)
183{
184 for (size_t i = 0; i < entries.size(); ++i) {
185 SCOPED_TRACE(i);
186 auto &entry = entries[i];
187
188 // Reset one of the entries to make it become first entry
189 rp->reset(entry.replacementData);
190
191 // Now change ticks and validate all other entries to make them not
192 // tie for first entry
193 for (size_t j = 0; j < entries.size(); ++j) {
194 if (i != j) {
195 rp->reset(entries[j].replacementData);
196 }
197 }
198
199 // Even if we touch the first entry, it will not stop being the
200 // first entry, so it will be selected for victimization
201 rp->touch(entry.replacementData);
202
203 ASSERT_EQ(rp->getVictim(candidates), &entry);
204 }
205}
206
208
209TEST_F(FIFORPFDeathTest, InvalidateNull)
210{
211 ASSERT_DEATH(rp->invalidate(nullptr), "");
212}
213
215{
216 ASSERT_DEATH(rp->reset(nullptr), "");
217}
218
220{
221#ifdef NDEBUG
222 GTEST_SKIP() << "Skipping as assertions are "
223 "stripped out of fast builds";
224#endif
225 ASSERT_DEATH(rp->touch(nullptr), "");
226}
227
229{
231 ASSERT_DEATH(rp->getVictim(candidates), "");
232}
Copyright (c) 2025 Daniel R.
std::shared_ptr< gem5::replacement_policy::FIFO > rp
Fixture that tests victimization.
gem5::ReplacementCandidates candidates
std::vector< gem5::ReplaceableEntry > entries
A replaceable entry is a basic entry in a 2d table-like structure that needs to have replacement func...
std::shared_ptr< replacement_policy::ReplacementData > replacementData
Replacement data associated to this entry.
STL vector class.
Definition stl.hh:37
Copyright (c) 2018-2020 Inria All rights reserved.
TEST_F(FIFORPTestF, InstantiatedEntry)
Test that instantiating an entry generates a non-null replacement data.
FIFORPTestF FIFORPFDeathTest
std::vector< ReplaceableEntry * > ReplacementCandidates
Replacement candidates as chosen by the indexing policy.
Definition base.hh:46

Generated on Mon Oct 27 2025 04:13:03 for gem5 by doxygen 1.14.0