testStore.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#include "squid.h"
10#include "Store.h"
11#include "store/SwapMeta.h"
12#include "testStore.h"
13#include "unitTestMain.h"
14
15#include <limits>
16
18
19int
21{
22 return 1;
23}
24
27{
28 return nullptr;
29}
30
31void
32StoreControllerStub::get(String, void (*)(StoreEntry*, void*), void*)
33{}
34
35void
37{}
38
39uint64_t
41{
42 return 3;
43}
44
45uint64_t
47{
48 return 1;
49}
50
51uint64_t
53{
54 return 2;
55}
56
57uint64_t
59{
60 return 2;
61}
62
63int64_t
65{
66 return 1;
67}
68
69void
71{
72}
73
74void
76{
77 const_cast<StoreControllerStub *>(this)->statsCalled = true;
78}
79
82{
83 return nullptr;
84}
85
86void
88{
90 Store::Init(aStore);
91
92 CPPUNIT_ASSERT_EQUAL(&Store::Root(), aStore);
94}
95
96void
98{
101 Store::Init(aStore);
103 Store::Init(aStore2);
104 CPPUNIT_ASSERT_EQUAL(&Store::Root(),aStore2);
106}
107
108void
110{
112 Store::Init(aStore);
113 CPPUNIT_ASSERT_EQUAL(false, aStore->statsCalled);
114 StoreEntry entry;
115 Store::Stats(&entry);
116 CPPUNIT_ASSERT_EQUAL(true, aStore->statsCalled);
118}
119
120void
122{
124 Store::Init(aStore);
125 CPPUNIT_ASSERT_EQUAL(static_cast<uint64_t>(3), aStore->maxSize());
127}
128
129namespace Store {
130
132static void
134{
135 if (IgnoredSwapMetaType(rawType)) {
136 // an ignored raw type is either deprecated or reserved
137 CPPUNIT_ASSERT(DeprecatedSwapMetaType(rawType) || ReservedSwapMetaType(rawType));
138 CPPUNIT_ASSERT(!(DeprecatedSwapMetaType(rawType) && ReservedSwapMetaType(rawType)));
139 } else {
140 // all other raw types are neither deprecated nor reserved
141 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType) && !ReservedSwapMetaType(rawType));
142 }
143}
144
146static void
148{
149 // RawSwapMetaTypeBottom and smaller values are unrelated to any named
150 // SwapMetaDataType values, including past, current, and future ones
151 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType)); // current
152 CPPUNIT_ASSERT(!IgnoredSwapMetaType(rawType)); // past and future
153 CPPUNIT_ASSERT(!DeprecatedSwapMetaType(rawType)); // past
154 CPPUNIT_ASSERT(!ReservedSwapMetaType(rawType)); // future
155}
156
158static void
160{
161 // an in-range rawType other than STORE_META_VOID is either honored or ignored
162 CPPUNIT_ASSERT(HonoredSwapMetaType(rawType) || IgnoredSwapMetaType(rawType));
163 CPPUNIT_ASSERT(!(HonoredSwapMetaType(rawType) && IgnoredSwapMetaType(rawType)));
165}
166
168static void
170{
171 // values beyond RawSwapMetaTypeTop() cannot be honored but may be ignored
172 CPPUNIT_ASSERT(!HonoredSwapMetaType(rawType));
174}
175
177static void
179{
180 if (rawType <= RawSwapMetaTypeBottom)
182 else if (rawType > RawSwapMetaTypeTop())
184 else
186}
187
188} // namespace Store
189
190void
192{
193 using limits = std::numeric_limits<Store::RawSwapMetaType>;
194 for (auto rawType = limits::min(); true; ++rawType) {
195
197
198 if (rawType == limits::max())
199 break;
200 }
201
202 // Store::RawSwapMetaTypeTop() is documented as an honored type value
204}
205
207class MyTestProgram: public TestProgram
208{
209public:
210 /* TestProgram API */
211 void startup() override { Mem::Init(); }
212};
213
214int
215main(int argc, char *argv[])
216{
217 return MyTestProgram().run(argc, argv);
218}
219
customizes our test setup
void startup() override
Definition: testStore.cc:211
allows testing of methods without having all the other components live
Definition: testStore.h:43
uint64_t maxSize() const override
Definition: testStore.cc:40
void init() override
Definition: testStore.cc:36
uint64_t currentCount() const override
the total number of objects stored right now
Definition: testStore.cc:58
uint64_t currentSize() const override
current size
Definition: testStore.cc:52
int callback() override
called once every main loop iteration; TODO: Move to UFS code.
Definition: testStore.cc:20
virtual StoreEntry * get(const cache_key *)
Definition: testStore.cc:26
int64_t maxObjectSize() const override
the maximum size of a storable object; -1 if unlimited
Definition: testStore.cc:64
virtual StoreSearch * search()
Definition: testStore.cc:81
void getStats(StoreInfoStats &) const override
collect statistics
Definition: testStore.cc:70
uint64_t minSize() const override
the minimum size the store will shrink to via normal housekeeping
Definition: testStore.cc:46
void stat(StoreEntry &) const override
Definition: testStore.cc:75
High-level store statistics used by mgr:info action. Used inside PODs!
Definition: StoreStats.h:14
uint64_t maxSize() const override
Definition: Controller.cc:159
implements test program's main() function while enabling customization
Definition: unitTestMain.h:26
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
void testMaxSize()
Definition: testStore.cc:121
void testSwapMetaTypeClassification()
Definition: testStore.cc:191
void testStats()
Definition: testStore.cc:109
void testSetRoot()
Definition: testStore.cc:87
void testUnsetRoot()
Definition: testStore.cc:97
A const & max(A const &lhs, A const &rhs)
A const & min(A const &lhs, A const &rhs)
void Init()
Definition: old_api.cc:425
Controller & Root()
safely access controller singleton
Definition: Controller.cc:938
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
static void checkKnownSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type within SwapMetaType range, excluding STORE_META_VOID
Definition: testStore.cc:159
char RawSwapMetaType
Definition: SwapMeta.h:95
constexpr RawSwapMetaType RawSwapMetaTypeTop()
Definition: SwapMeta.h:131
constexpr bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:219
static void checkSwapMetaRawType(const RawSwapMetaType rawType)
check a given raw swap meta field type
Definition: testStore.cc:178
constexpr bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:197
constexpr bool ReservedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:180
static void checkIgnorableSwapMetaRawType(const RawSwapMetaType rawType)
check rawType that may be ignored
Definition: testStore.cc:133
static void checkTooSmallSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type below SwapMetaType range or STORE_META_VOID
Definition: testStore.cc:147
constexpr bool DeprecatedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:158
void FreeMemory()
undo Init()
Definition: Controller.cc:951
void Stats(StoreEntry *output)
Definition: store.cc:125
void Init(Controller *root=nullptr)
initialize the storage module; a custom root is used by unit tests only
Definition: Controller.cc:945
static void checkTooBigSwapMetaRawType(const RawSwapMetaType rawType)
check a raw swap meta field type exceeding RawSwapMetaTypeTop()
Definition: testStore.cc:169
unsigned char cache_key
Store key.
Definition: forward.h:29
int main(int argc, char *argv[])
Definition: testStore.cc:215
CPPUNIT_TEST_SUITE_REGISTRATION(TestStore)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors