This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ed16edfa2d Convert CacheVol regression tests into unit tests (#10649)
ed16edfa2d is described below
commit ed16edfa2d50e2cbd75b8455b9d4ba48ff7d1e01
Author: Masaori Koshiba <[email protected]>
AuthorDate: Tue Oct 24 08:59:15 2023 +0900
Convert CacheVol regression tests into unit tests (#10649)
---
src/iocore/cache/CacheHosting.cc | 330 ----------------------
src/iocore/cache/Makefile.am | 8 +
src/iocore/cache/unit_tests/storage.config | 2 +-
src/iocore/cache/unit_tests/test_CacheVol.cc | 396 +++++++++++++++++++++++++++
src/tests/CMakeLists.txt | 1 +
5 files changed, 406 insertions(+), 331 deletions(-)
diff --git a/src/iocore/cache/CacheHosting.cc b/src/iocore/cache/CacheHosting.cc
index ac28fcd1d5..e2c0ccbf79 100644
--- a/src/iocore/cache/CacheHosting.cc
+++ b/src/iocore/cache/CacheHosting.cc
@@ -27,11 +27,8 @@
#include "tscore/Layout.h"
#include "tscore/HostLookup.h"
#include "tscore/Tokenizer.h"
-#include "tscore/Regression.h"
#include "tscore/Filenames.h"
-extern int gndisks;
-
namespace
{
@@ -797,330 +794,3 @@ ConfigVolumes::BuildListFromString(char
*config_file_path, char *file_buf)
return;
}
-
-/* Test the cache volume with different configurations */
-#define MEGS_128 (128 * 1024 * 1024)
-#define ROUND_TO_VOL_SIZE(_x) (((_x) + (MEGS_128 - 1)) & ~(MEGS_128 - 1))
-extern CacheDisk **gdisks;
-extern Queue<CacheVol> cp_list;
-extern int cp_list_len;
-extern ConfigVolumes config_volumes;
-
-extern void cplist_init();
-extern int cplist_reconfigure();
-static int configs = 4;
-
-Queue<CacheVol> saved_cp_list;
-int saved_cp_list_len;
-ConfigVolumes saved_config_volumes;
-int saved_gnvol;
-
-static int ClearConfigVol(ConfigVolumes *configp);
-static int ClearCacheVolList(Queue<CacheVol> *cpl, int len);
-static int create_config(RegressionTest *t, int i);
-static int execute_and_verify(RegressionTest *t);
-static void save_state();
-static void restore_state();
-
-EXCLUSIVE_REGRESSION_TEST(Cache_vol)(RegressionTest *t, int /* atype
ATS_UNUSED */, int *status)
-{
- save_state();
- srand48(time(nullptr));
- *status = REGRESSION_TEST_PASSED;
- for (int i = 0; i < configs; i++) {
- if (create_config(t, i)) {
- if (execute_and_verify(t) == REGRESSION_TEST_FAILED) {
- *status = REGRESSION_TEST_FAILED;
- }
- }
- }
- restore_state();
- return;
-}
-
-int
-create_config(RegressionTest *t, int num)
-{
- int i = 0;
- int vol_num = 1;
- // clear all old configurations before adding new test cases
- config_volumes.clear_all();
- switch (num) {
- case 0:
- for (i = 0; i < gndisks; i++) {
- CacheDisk *d = gdisks[i];
- int blocks = d->num_usable_blocks;
- if (blocks < STORE_BLOCKS_PER_VOL) {
- rprintf(t, "Cannot run Cache_vol regression: not enough disk space\n");
- return 0;
- }
- /* create 128 MB volumes */
- for (; blocks >= STORE_BLOCKS_PER_VOL; blocks -= STORE_BLOCKS_PER_VOL) {
- if (vol_num > 255) {
- break;
- }
- ConfigVol *cp = new ConfigVol();
- cp->number = vol_num++;
- cp->scheme = CACHE_HTTP_TYPE;
- cp->size = 128;
- cp->in_percent = false;
- cp->cachep = nullptr;
- config_volumes.cp_queue.enqueue(cp);
- config_volumes.num_volumes++;
- config_volumes.num_http_volumes++;
- }
- }
- rprintf(t, "%d 128 Megabyte Volumes\n", vol_num - 1);
- break;
-
- case 1: {
- for (i = 0; i < gndisks; i++) {
- gdisks[i]->delete_all_volumes();
- }
-
- // calculate the total free space
- off_t total_space = 0;
- for (i = 0; i < gndisks; i++) {
- off_t vol_blocks = gdisks[i]->num_usable_blocks;
- /* round down the blocks to the nearest
- multiple of STORE_BLOCKS_PER_VOL */
- vol_blocks = (vol_blocks / STORE_BLOCKS_PER_VOL) *
STORE_BLOCKS_PER_VOL;
- total_space += vol_blocks;
- }
-
- // make sure we have at least 1280 M bytes
- if (total_space < ((10 << 27) >> STORE_BLOCK_SHIFT)) {
- rprintf(t, "Not enough space for 10 volume\n");
- return 0;
- }
-
- vol_num = 1;
- rprintf(t, "Cleared disk\n");
- for (i = 0; i < 10; i++) {
- ConfigVol *cp = new ConfigVol();
- cp->number = vol_num++;
- cp->scheme = CACHE_HTTP_TYPE;
- cp->size = 10;
- cp->percent = 10;
- cp->in_percent = true;
- cp->cachep = nullptr;
- config_volumes.cp_queue.enqueue(cp);
- config_volumes.num_volumes++;
- config_volumes.num_http_volumes++;
- }
- rprintf(t, "10 volume, 10 percent each\n");
- } break;
-
- case 2:
- case 3:
-
- {
- /* calculate the total disk space */
- InkRand *gen = &this_ethread()->generator;
- off_t total_space = 0;
- vol_num = 1;
- if (num == 2) {
- rprintf(t, "Random Volumes after clearing the disks\n");
- } else {
- rprintf(t, "Random Volumes without clearing the disks\n");
- }
-
- for (i = 0; i < gndisks; i++) {
- off_t vol_blocks = gdisks[i]->num_usable_blocks;
- /* round down the blocks to the nearest
- multiple of STORE_BLOCKS_PER_VOL */
- vol_blocks = (vol_blocks / STORE_BLOCKS_PER_VOL) *
STORE_BLOCKS_PER_VOL;
- total_space += vol_blocks;
-
- if (num == 2) {
- gdisks[i]->delete_all_volumes();
- } else {
- gdisks[i]->cleared = 0;
- }
- }
- while (total_space > 0) {
- if (vol_num > 255) {
- break;
- }
- off_t modu = MAX_VOL_SIZE;
- if (total_space < (MAX_VOL_SIZE >> STORE_BLOCK_SHIFT)) {
- modu = total_space * STORE_BLOCK_SIZE;
- }
-
- off_t random_size = (gen->random() % modu) + 1;
- /* convert to 128 megs multiple */
- CacheType scheme = (random_size % 2) ? CACHE_HTTP_TYPE : CACHE_RTSP_TYPE;
- random_size = ROUND_TO_VOL_SIZE(random_size);
- off_t blocks = random_size / STORE_BLOCK_SIZE;
- ink_assert(blocks <= (int)total_space);
- total_space -= blocks;
-
- ConfigVol *cp = new ConfigVol();
-
- cp->number = vol_num++;
- cp->scheme = scheme;
- cp->size = random_size >> 20;
- cp->percent = 0;
- cp->in_percent = false;
- cp->cachep = nullptr;
- config_volumes.cp_queue.enqueue(cp);
- config_volumes.num_volumes++;
- if (cp->scheme == CACHE_HTTP_TYPE) {
- config_volumes.num_http_volumes++;
- rprintf(t, "volume=%d scheme=http size=%d\n", cp->number, cp->size);
- } else {
- // ToDo: Assert ?
- }
- }
- } break;
-
- default:
- return 1;
- }
- return 1;
-}
-
-int
-execute_and_verify(RegressionTest *t)
-{
- cplist_init();
- cplist_reconfigure();
-
- /* compare the volumes */
- if (cp_list_len != config_volumes.num_volumes) {
- return REGRESSION_TEST_FAILED;
- }
-
- /* check that the volumes and sizes
- match the configuration */
- int matched = 0;
- ConfigVol *cp = config_volumes.cp_queue.head;
- CacheVol *cachep;
-
- for (int i = 0; i < config_volumes.num_volumes; i++) {
- cachep = cp_list.head;
- while (cachep) {
- if (cachep->vol_number == cp->number) {
- if ((cachep->scheme != cp->scheme) || (cachep->size != (cp->size <<
(20 - STORE_BLOCK_SHIFT))) || (cachep != cp->cachep)) {
- rprintf(t, "Configuration and Actual volumes don't match\n");
- return REGRESSION_TEST_FAILED;
- }
-
- /* check that the number of volumes match the ones
- on disk */
- int d_no;
- int m_vols = 0;
- for (d_no = 0; d_no < gndisks; d_no++) {
- if (cachep->disk_vols[d_no]) {
- DiskVol *dp = cachep->disk_vols[d_no];
- if (dp->vol_number != cachep->vol_number) {
- rprintf(t, "DiskVols and CacheVols don't match\n");
- return REGRESSION_TEST_FAILED;
- }
-
- /* check the diskvolblock queue */
- DiskVolBlockQueue *dpbq = dp->dpb_queue.head;
- while (dpbq) {
- if (dpbq->b->number != cachep->vol_number) {
- rprintf(t, "DiskVol and DiskVolBlocks don't match\n");
- return REGRESSION_TEST_FAILED;
- }
- dpbq = dpbq->link.next;
- }
-
- m_vols += dp->num_volblocks;
- }
- }
- if (m_vols != cachep->num_vols) {
- rprintf(t, "Num volumes in CacheVol and DiskVol don't match\n");
- return REGRESSION_TEST_FAILED;
- }
- matched++;
- break;
- }
- cachep = cachep->link.next;
- }
- }
-
- if (matched != config_volumes.num_volumes) {
- rprintf(t, "Num of Volumes created and configured don't match\n");
- return REGRESSION_TEST_FAILED;
- }
-
- ClearConfigVol(&config_volumes);
-
- ClearCacheVolList(&cp_list, cp_list_len);
-
- for (int i = 0; i < gndisks; i++) {
- CacheDisk *d = gdisks[i];
- if (dbg_ctl_cache_hosting.on()) {
- Dbg(dbg_ctl_cache_hosting, "Disk: %d: Vol Blocks: %u: Free space: %"
PRIu64, i, d->header->num_diskvol_blks, d->free_space);
- for (int j = 0; j < static_cast<int>(d->header->num_volumes); j++) {
- Dbg(dbg_ctl_cache_hosting, "\tVol: %d Size: %" PRIu64,
d->disk_vols[j]->vol_number, d->disk_vols[j]->size);
- }
- for (int j = 0; j < static_cast<int>(d->header->num_diskvol_blks); j++) {
- Dbg(dbg_ctl_cache_hosting, "\tBlock No: %d Size: %" PRIu64 " Free:
%u", d->header->vol_info[j].number,
- d->header->vol_info[j].len, d->header->vol_info[j].free);
- }
- }
- }
- return REGRESSION_TEST_PASSED;
-}
-
-int
-ClearConfigVol(ConfigVolumes *configp)
-{
- int i = 0;
- ConfigVol *cp = nullptr;
- while ((cp = configp->cp_queue.dequeue())) {
- delete cp;
- i++;
- }
- if (i != configp->num_volumes) {
- Warning("failed");
- return 0;
- }
- configp->num_volumes = 0;
- configp->num_http_volumes = 0;
- return 1;
-}
-
-int
-ClearCacheVolList(Queue<CacheVol> *cpl, int len)
-{
- int i = 0;
- CacheVol *cp = nullptr;
- while ((cp = cpl->dequeue())) {
- ats_free(cp->disk_vols);
- ats_free(cp->vols);
- delete (cp);
- i++;
- }
-
- if (i != len) {
- Warning("Failed");
- return 0;
- }
- return 1;
-}
-
-void
-save_state()
-{
- saved_cp_list = cp_list;
- saved_cp_list_len = cp_list_len;
- memcpy(&saved_config_volumes, &config_volumes, sizeof(ConfigVolumes));
- saved_gnvol = gnvol;
- memset(static_cast<void *>(&cp_list), 0, sizeof(Queue<CacheVol>));
- memset(static_cast<void *>(&config_volumes), 0, sizeof(ConfigVolumes));
- gnvol = 0;
-}
-
-void
-restore_state()
-{
- cp_list = saved_cp_list;
- cp_list_len = saved_cp_list_len;
- memcpy(&config_volumes, &saved_config_volumes, sizeof(ConfigVolumes));
- gnvol = saved_gnvol;
-}
diff --git a/src/iocore/cache/Makefile.am b/src/iocore/cache/Makefile.am
index ac8190f883..9085de7949 100644
--- a/src/iocore/cache/Makefile.am
+++ b/src/iocore/cache/Makefile.am
@@ -132,6 +132,7 @@ endif
check_PROGRAMS = \
test_Cache \
test_CacheDir \
+ test_CacheVol \
test_RWW \
test_Alternate_L_to_S \
test_Alternate_S_to_L \
@@ -319,6 +320,13 @@ test_CacheDir_SOURCES = \
$(test_main_SOURCES) \
./test/test_CacheDir.cc
+test_CacheVol_CPPFLAGS = $(test_CPPFLAGS)
+test_CacheVol_LDFLAGS = @AM_LDFLAGS@
+test_CacheVol_LDADD = $(test_LDADD)
+test_CacheVol_SOURCES = \
+ $(test_main_SOURCES) \
+ ./test/test_CacheVol.cc
+
test_RWW_CPPFLAGS = $(test_CPPFLAGS)
test_RWW_LDFLAGS = @AM_LDFLAGS@
test_RWW_LDADD = $(test_LDADD)
diff --git a/src/iocore/cache/unit_tests/storage.config
b/src/iocore/cache/unit_tests/storage.config
index e3c34e9153..c10a663b1d 100644
--- a/src/iocore/cache/unit_tests/storage.config
+++ b/src/iocore/cache/unit_tests/storage.config
@@ -1,2 +1,2 @@
-var/trafficserver 32M
+var/trafficserver 256M
var/trafficserver2 32M
diff --git a/src/iocore/cache/unit_tests/test_CacheVol.cc
b/src/iocore/cache/unit_tests/test_CacheVol.cc
new file mode 100644
index 0000000000..b85cdd081f
--- /dev/null
+++ b/src/iocore/cache/unit_tests/test_CacheVol.cc
@@ -0,0 +1,396 @@
+/** @file
+
+ A brief file description
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "main.h"
+
+#include "P_Cache.h"
+#include "P_CacheHosting.h"
+
+#include "tscore/Diags.h"
+#include "tscpp/util/PostScript.h"
+
+// Required by main.h
+int cache_vols = 1;
+bool reuse_existing_cache = false;
+
+extern int gndisks;
+extern CacheDisk **gdisks;
+extern Queue<CacheVol> cp_list;
+extern int cp_list_len;
+extern ConfigVolumes config_volumes;
+
+extern void cplist_init();
+extern int cplist_reconfigure();
+
+namespace
+{
+
+DbgCtl dbg_ctl_cache_hosting{"cache_hosting"};
+DbgCtl dbg_ctl_matcher{"matcher"};
+DbgCtl dbg_ctl_cache_vol_test{"cache_vol_test"};
+
+/* Test the cache volume with different configurations */
+#define MEGS_128 (128 * 1024 * 1024)
+#define ROUND_TO_VOL_SIZE(_x) (((_x) + (MEGS_128 - 1)) & ~(MEGS_128 - 1))
+static int configs = 4;
+
+Queue<CacheVol> saved_cp_list;
+int saved_cp_list_len;
+ConfigVolumes saved_config_volumes;
+int saved_gnvol;
+
+int ClearConfigVol(ConfigVolumes *configp);
+int ClearCacheVolList(Queue<CacheVol> *cpl, int len);
+int create_config(int i);
+void execute_and_verify();
+void save_state();
+void restore_state();
+
+int
+create_config(int num)
+{
+ int i = 0;
+ int vol_num = 1;
+ // clear all old configurations before adding new test cases
+ config_volumes.clear_all();
+ switch (num) {
+ case 0:
+ for (i = 0; i < gndisks; i++) {
+ CacheDisk *d = gdisks[i];
+ int blocks = d->num_usable_blocks;
+ if (blocks < STORE_BLOCKS_PER_VOL) {
+ Warning("Cannot run Cache_vol regression: not enough disk space");
+ return 0;
+ }
+ /* create 128 MB volumes */
+ for (; blocks >= STORE_BLOCKS_PER_VOL; blocks -= STORE_BLOCKS_PER_VOL) {
+ if (vol_num > 255) {
+ break;
+ }
+ ConfigVol *cp = new ConfigVol();
+ cp->number = vol_num++;
+ cp->scheme = CACHE_HTTP_TYPE;
+ cp->size = 128;
+ cp->in_percent = false;
+ cp->cachep = nullptr;
+ config_volumes.cp_queue.enqueue(cp);
+ config_volumes.num_volumes++;
+ config_volumes.num_http_volumes++;
+ }
+ }
+ Dbg(dbg_ctl_cache_vol_test, "%d 128 Megabyte Volumes", vol_num - 1);
+ break;
+
+ case 1: {
+ for (i = 0; i < gndisks; i++) {
+ gdisks[i]->delete_all_volumes();
+ }
+
+ // calculate the total free space
+ off_t total_space = 0;
+ for (i = 0; i < gndisks; i++) {
+ off_t vol_blocks = gdisks[i]->num_usable_blocks;
+ /* round down the blocks to the nearest
+ multiple of STORE_BLOCKS_PER_VOL */
+ vol_blocks = (vol_blocks / STORE_BLOCKS_PER_VOL) *
STORE_BLOCKS_PER_VOL;
+ total_space += vol_blocks;
+ }
+
+ // make sure we have at least 1280 M bytes
+ if (total_space < ((10 << 27) >> STORE_BLOCK_SHIFT)) {
+ // Skip this test case due to small space
+ Warning("Not enough space for 10 volume");
+ return 0;
+ }
+
+ vol_num = 1;
+ Dbg(dbg_ctl_cache_vol_test, "Cleared disk");
+ for (i = 0; i < 10; i++) {
+ ConfigVol *cp = new ConfigVol();
+ cp->number = vol_num++;
+ cp->scheme = CACHE_HTTP_TYPE;
+ cp->size = 10;
+ cp->percent = 10;
+ cp->in_percent = true;
+ cp->cachep = nullptr;
+ config_volumes.cp_queue.enqueue(cp);
+ config_volumes.num_volumes++;
+ config_volumes.num_http_volumes++;
+ }
+ Dbg(dbg_ctl_cache_vol_test, "10 volume, 10 percent each");
+ } break;
+
+ case 2:
+ case 3:
+
+ {
+ /* calculate the total disk space */
+ InkRand *gen = &this_ethread()->generator;
+ off_t total_space = 0;
+ vol_num = 1;
+ if (num == 2) {
+ Dbg(dbg_ctl_cache_vol_test, "Random Volumes after clearing the disks");
+ } else {
+ Dbg(dbg_ctl_cache_vol_test, "Random Volumes without clearing the disks");
+ }
+
+ for (i = 0; i < gndisks; i++) {
+ off_t vol_blocks = gdisks[i]->num_usable_blocks;
+ /* round down the blocks to the nearest
+ multiple of STORE_BLOCKS_PER_VOL */
+ vol_blocks = (vol_blocks / STORE_BLOCKS_PER_VOL) *
STORE_BLOCKS_PER_VOL;
+ total_space += vol_blocks;
+
+ if (num == 2) {
+ gdisks[i]->delete_all_volumes();
+ } else {
+ gdisks[i]->cleared = 0;
+ }
+ }
+
+ if (total_space == 0) {
+ Warning("Not enough space to test");
+ return 0;
+ }
+
+ while (total_space > 0) {
+ if (vol_num > 255) {
+ break;
+ }
+ off_t modu = MAX_VOL_SIZE;
+ if (total_space < (MAX_VOL_SIZE >> STORE_BLOCK_SHIFT)) {
+ modu = total_space * STORE_BLOCK_SIZE;
+ }
+
+ off_t random_size = (gen->random() % modu) + 1;
+ /* convert to 128 megs multiple */
+ CacheType scheme = (random_size % 2) ? CACHE_HTTP_TYPE : CACHE_RTSP_TYPE;
+ random_size = ROUND_TO_VOL_SIZE(random_size);
+ off_t blocks = random_size / STORE_BLOCK_SIZE;
+ ink_assert(blocks <= (int)total_space);
+ total_space -= blocks;
+
+ ConfigVol *cp = new ConfigVol();
+
+ cp->number = vol_num++;
+ cp->scheme = scheme;
+ cp->size = random_size >> 20;
+ cp->percent = 0;
+ cp->in_percent = false;
+ cp->cachep = nullptr;
+ config_volumes.cp_queue.enqueue(cp);
+ config_volumes.num_volumes++;
+ if (cp->scheme == CACHE_HTTP_TYPE) {
+ config_volumes.num_http_volumes++;
+ Dbg(dbg_ctl_cache_vol_test, "volume=%d scheme=http size=%zd",
cp->number, static_cast<size_t>(cp->size));
+ } else {
+ // ToDo: Assert ?
+ }
+ }
+ } break;
+
+ default:
+ return 1;
+ }
+ return 1;
+}
+
+void
+execute_and_verify()
+{
+ ts::PostScript clear([&]() -> void {
+ ClearConfigVol(&config_volumes);
+ ClearCacheVolList(&cp_list, cp_list_len);
+ });
+
+ cplist_init();
+
+ if (cplist_reconfigure() < 0) {
+ Warning("reconfigure failed");
+ return;
+ }
+
+ /* compare the volumes */
+ REQUIRE(cp_list_len == config_volumes.num_volumes);
+
+ /* check that the volumes and sizes
+ match the configuration */
+ int matched = 0;
+ ConfigVol *cp = config_volumes.cp_queue.head;
+ CacheVol *cachep;
+
+ for (int i = 0; i < config_volumes.num_volumes; i++) {
+ cachep = cp_list.head;
+ while (cachep) {
+ if (cachep->vol_number == cp->number) {
+ // Configuration and Actual volumes should match
+ REQUIRE(cachep->scheme == cp->scheme);
+ REQUIRE(cachep->size == (cp->size << (20 - STORE_BLOCK_SHIFT)));
+ REQUIRE(cachep == cp->cachep);
+
+ /* check that the number of volumes match the ones
+ on disk */
+ int d_no;
+ int m_vols = 0;
+ for (d_no = 0; d_no < gndisks; d_no++) {
+ if (cachep->disk_vols[d_no]) {
+ DiskVol *dp = cachep->disk_vols[d_no];
+ // DiskVols and CacheVols should match
+ REQUIRE(dp->vol_number == cachep->vol_number);
+
+ /* check the diskvolblock queue */
+ DiskVolBlockQueue *dpbq = dp->dpb_queue.head;
+ while (dpbq) {
+ // DiskVol and DiskVolBlocks should match
+ REQUIRE(dpbq->b->number == cachep->vol_number);
+ dpbq = dpbq->link.next;
+ }
+
+ m_vols += dp->num_volblocks;
+ }
+ }
+ // Num volumes in CacheVol and DiskVol should match
+ REQUIRE(m_vols == cachep->num_vols);
+
+ matched++;
+ break;
+ }
+ cachep = cachep->link.next;
+ }
+ }
+
+ // Num of Volumes created and configured should match
+ REQUIRE(matched == config_volumes.num_volumes);
+
+ for (int i = 0; i < gndisks; i++) {
+ CacheDisk *d = gdisks[i];
+ if (dbg_ctl_cache_hosting.on()) {
+ Dbg(dbg_ctl_cache_hosting, "Disk: %d: Vol Blocks: %u: Free space: %"
PRIu64, i, d->header->num_diskvol_blks, d->free_space);
+ for (int j = 0; j < static_cast<int>(d->header->num_volumes); j++) {
+ Dbg(dbg_ctl_cache_hosting, "\tVol: %d Size: %" PRIu64,
d->disk_vols[j]->vol_number, d->disk_vols[j]->size);
+ }
+ for (int j = 0; j < static_cast<int>(d->header->num_diskvol_blks); j++) {
+ Dbg(dbg_ctl_cache_hosting, "\tBlock No: %d Size: %" PRIu64 " Free:
%u", d->header->vol_info[j].number,
+ d->header->vol_info[j].len, d->header->vol_info[j].free);
+ }
+ }
+ }
+}
+
+int
+ClearConfigVol(ConfigVolumes *configp)
+{
+ int i = 0;
+ ConfigVol *cp = nullptr;
+ while ((cp = configp->cp_queue.dequeue())) {
+ delete cp;
+ i++;
+ }
+ if (i != configp->num_volumes) {
+ Warning("failed");
+ return 0;
+ }
+ configp->num_volumes = 0;
+ configp->num_http_volumes = 0;
+ return 1;
+}
+
+int
+ClearCacheVolList(Queue<CacheVol> *cpl, int len)
+{
+ int i = 0;
+ CacheVol *cp = nullptr;
+ while ((cp = cpl->dequeue())) {
+ ats_free(cp->disk_vols);
+ ats_free(cp->vols);
+ delete (cp);
+ i++;
+ }
+
+ if (i != len) {
+ Warning("Failed");
+ return 0;
+ }
+ return 1;
+}
+
+void
+save_state()
+{
+ saved_cp_list = cp_list;
+ saved_cp_list_len = cp_list_len;
+ memcpy(&saved_config_volumes, &config_volumes, sizeof(ConfigVolumes));
+ saved_gnvol = gnvol;
+ memset(static_cast<void *>(&cp_list), 0, sizeof(Queue<CacheVol>));
+ memset(static_cast<void *>(&config_volumes), 0, sizeof(ConfigVolumes));
+ gnvol = 0;
+}
+
+void
+restore_state()
+{
+ cp_list = saved_cp_list;
+ cp_list_len = saved_cp_list_len;
+ memcpy(&config_volumes, &saved_config_volumes, sizeof(ConfigVolumes));
+ gnvol = saved_gnvol;
+}
+} // end anonymous namespace
+
+class CacheVolTest : public CacheInit
+{
+public:
+ int
+ cache_init_success_callback(int event, void *e) override
+ {
+ // Test
+ save_state();
+ srand48(time(nullptr));
+
+ for (int i = 0; i < configs; i++) {
+ Dbg(dbg_ctl_cache_vol_test, "config case = %d", i);
+
+ if (create_config(i)) {
+ execute_and_verify();
+ }
+ }
+ restore_state();
+
+ // Teardown
+ test_done();
+ delete this;
+
+ return 0;
+ }
+};
+
+TEST_CASE("CacheVol")
+{
+ init_cache(0);
+
+ CacheVolTest *init = new CacheVolTest;
+
+ this_ethread()->schedule_imm(init);
+ this_thread()->execute();
+
+ return;
+}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 7c146b9b0d..9f07dad2a9 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -103,6 +103,7 @@ if(ENABLE_DISK_FAILURE_TESTS)
)
endif()
add_cache_test(CacheDir
${CMAKE_SOURCE_DIR}/src/iocore/cache/unit_tests/test_CacheDir.cc)
+add_cache_test(CacheVol
${CMAKE_SOURCE_DIR}/src/iocore/cache/unit_tests/test_CacheVol.cc)
add_cache_test(RWW ${CMAKE_SOURCE_DIR}/src/iocore/cache/unit_tests/test_RWW.cc)
add_cache_test(Alternate_L_to_S
${CMAKE_SOURCE_DIR}/src/iocore/cache/unit_tests/test_Alternate_L_to_S.cc)
add_cache_test(Alternate_S_to_L
${CMAKE_SOURCE_DIR}/src/iocore/cache/unit_tests/test_Alternate_S_to_L.cc)