fellow_cache_test: Introduce fc init/fini wrappers

parent d0c6d754
...@@ -7351,13 +7351,56 @@ t_busyobj(unsigned chksum, struct fellow_cache *fc, uint16_t limit_ldsegs, unsig ...@@ -7351,13 +7351,56 @@ t_busyobj(unsigned chksum, struct fellow_cache *fc, uint16_t limit_ldsegs, unsig
fellow_cache_obj_delete(fc, fco, hash); fellow_cache_obj_delete(fc, fco, hash);
} }
/*
* ============================================================
* infrastructure for running test cases on fellow_cache with-
* out fellow_storage: We need a thread to watch the disk buddy
* and trigger log flushes to make (faster) progress
* */
struct t_fc {
unsigned magic;
#define TFC_MAGIC 0x8956a01b
unsigned shutdown;
struct fellow_cache *fc;
uint64_t g_mem_obj;
pthread_t thr;
};
static struct t_fc *
t_fc_init(struct fellow_fd *ffd, buddy_t *membuddy, struct stvfe_tune *tune)
{
struct t_fc *tfc;
ALLOC_OBJ(tfc, TFC_MAGIC);
AN(tfc);
tfc->fc = fellow_cache_init(ffd, membuddy, tune, fellow_simple_task_run,
&tfc->g_mem_obj);
AN(tfc->fc);
return (tfc);
}
static void
t_fc_fini(struct t_fc **tfcp)
{
struct t_fc *tfc;
TAKE_OBJ_NOTNULL(tfc, tfcp, TFC_MAGIC);
fellow_cache_fini(&tfc->fc);
AZ(tfc->fc);
AZ(tfc->g_mem_obj);
FREE_OBJ(tfc);
}
static void static void
t_cache(const char *fn, unsigned chksum) t_cache(const char *fn, unsigned chksum)
{ {
size_t sz; size_t sz;
struct fellow_fd *ffd; struct fellow_fd *ffd;
buddy_t mb, *membuddy = &mb; buddy_t mb, *membuddy = &mb;
struct fellow_cache *fc; struct t_fc *tfc;
struct fellow_cache_obj *fco; struct fellow_cache_obj *fco;
struct fellow_busy *fbo; struct fellow_busy *fbo;
uintptr_t priv2; uintptr_t priv2;
...@@ -7374,7 +7417,6 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7374,7 +7417,6 @@ t_cache(const char *fn, unsigned chksum)
struct fellow_cache_res fcr; struct fellow_cache_res fcr;
int injcount; int injcount;
char *ptr; char *ptr;
uint64_t g_mem_obj = 0;
DBGSZ(fellow_disk_seg); DBGSZ(fellow_disk_seg);
DBGSZ(fellow_disk_seglist); DBGSZ(fellow_disk_seglist);
...@@ -7408,21 +7450,21 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7408,21 +7450,21 @@ t_cache(const char *fn, unsigned chksum)
XXXAN(ffd); XXXAN(ffd);
fellow_log_open(ffd, resurrect_discard, &resur_priv); fellow_log_open(ffd, resurrect_discard, &resur_priv);
fc = fellow_cache_init(ffd, membuddy, tune, fellow_simple_task_run, tfc = t_fc_init(ffd, membuddy, tune);
&g_mem_obj); AN(tfc);
t_lcb(fc); t_lcb(tfc->fc);
// === empty obj, loop sizes // === empty obj, loop sizes
for (sz = 0; sz < 4096 ; sz += 8) { for (sz = 0; sz < 4096 ; sz += 8) {
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, sz).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, sz).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
} }
// === max out region alloc // === max out region alloc
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
u = 0; u = 0;
...@@ -7484,7 +7526,7 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7484,7 +7526,7 @@ t_cache(const char *fn, unsigned chksum)
for (u = 0; u < OA__MAX; u++) { for (u = 0; u < OA__MAX; u++) {
AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u])); AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u]));
} }
t_getattr(fc, fco); t_getattr(tfc->fc, fco);
/* /*
* #39 * #39
...@@ -7498,20 +7540,20 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7498,20 +7540,20 @@ t_cache(const char *fn, unsigned chksum)
assert(fbo->nregion == FCO_MAX_REGIONS); assert(fbo->nregion == FCO_MAX_REGIONS);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_delete(fc, fco, hash); fellow_cache_obj_delete(tfc->fc, fco, hash);
// === alloc space, dont use // === alloc space, dont use
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
{ {
sz = dsksz; sz = dsksz;
AZ(fellow_busy_obj_getspace(fbo, &sz, (uint8_t **)&ptr).status); AZ(fellow_busy_obj_getspace(fbo, &sz, (uint8_t **)&ptr).status);
} }
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
// === alloc space, trim // === alloc space, trim
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
{ {
sz = 1234; sz = 1234;
...@@ -7520,10 +7562,10 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7520,10 +7562,10 @@ t_cache(const char *fn, unsigned chksum)
fellow_busy_obj_trimstore(fbo); fellow_busy_obj_trimstore(fbo);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
(void)fellow_cache_obj_lru_touch(fco); (void)fellow_cache_obj_lru_touch(fco);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
// === alloc space error inject // === alloc space error inject
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
fc_inj_reset(); fc_inj_reset();
injcount = -1; injcount = -1;
...@@ -7546,10 +7588,10 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7546,10 +7588,10 @@ t_cache(const char *fn, unsigned chksum)
fellow_busy_obj_trimstore(fbo); fellow_busy_obj_trimstore(fbo);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
// === hit objsize_max // === hit objsize_max
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
do { do {
sz = 1234; sz = 1234;
...@@ -7564,10 +7606,10 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7564,10 +7606,10 @@ t_cache(const char *fn, unsigned chksum)
fellow_busy_obj_trimstore(fbo); fellow_busy_obj_trimstore(fbo);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
// === hit objsize_max with big chunks // === hit objsize_max with big chunks
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
do { do {
sz = dsksz; sz = dsksz;
...@@ -7582,10 +7624,10 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7582,10 +7624,10 @@ t_cache(const char *fn, unsigned chksum)
fellow_busy_obj_trimstore(fbo); fellow_busy_obj_trimstore(fbo);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
// === hit objsize_max under memory pressure // === hit objsize_max under memory pressure
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
do { do {
if (fbo->nregion < FCO_MAX_REGIONS - FCO_REGIONS_RESERVE) if (fbo->nregion < FCO_MAX_REGIONS - FCO_REGIONS_RESERVE)
...@@ -7603,22 +7645,22 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7603,22 +7645,22 @@ t_cache(const char *fn, unsigned chksum)
AN(fellow_busy_setattr(fbo, u, AN(fellow_busy_setattr(fbo, u,
strlen(oatest[u]), oatest[u])); strlen(oatest[u]), oatest[u]));
} }
t_getattr(fc, fco); t_getattr(tfc->fc, fco);
} while (fcr.status == fcr_ok); } while (fcr.status == fcr_ok);
fellow_busy_obj_trimstore(fbo); fellow_busy_obj_trimstore(fbo);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
test_fellow_cache_unbusy_inject(fc); test_fellow_cache_unbusy_inject(tfc->fc);
for (u = 0; u < 10; u++) for (u = 0; u < 10; u++)
for (v = MIN_FELLOW_BITS; v < MIN_FELLOW_BITS + 8; v++) for (v = MIN_FELLOW_BITS; v < MIN_FELLOW_BITS + 8; v++)
t_busyobj(chksum, fc, u, v); t_busyobj(chksum, tfc->fc, u, v);
// === alloc, then evict // === alloc, then evict
VSHA256_Init(&sha256ctx); VSHA256_Init(&sha256ctx);
fbo = fellow_busy_obj_alloc(fc, &fco, &priv2, 1234).r.ptr; fbo = fellow_busy_obj_alloc(tfc->fc, &fco, &priv2, 1234).r.ptr;
CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC); CHECK_OBJ_NOTNULL(fbo, FELLOW_BUSY_MAGIC);
u = fco->fcsl->fdsl->lsegs + 72 * 2; u = fco->fcsl->fdsl->lsegs + 72 * 2;
while (u-- > 0) { while (u-- > 0) {
...@@ -7640,48 +7682,49 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7640,48 +7682,49 @@ t_cache(const char *fn, unsigned chksum)
AN(fco->fcsl->next); AN(fco->fcsl->next);
// fixattr always return a pointer // fixattr always return a pointer
for (u = OA_VARY; u < OA__MAX; u++) for (u = OA_VARY; u < OA__MAX; u++)
AZ(fellow_cache_obj_getattr(fc, fco, u, &sz).r.ptr); AZ(fellow_cache_obj_getattr(tfc->fc, fco, u, &sz).r.ptr);
for (u = 0; u < OA__MAX; u++) for (u = 0; u < OA__MAX; u++)
AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u])); AN(fellow_busy_setattr(fbo, u, strlen(oatest[u]), oatest[u]));
t_getattr(fc, fco); t_getattr(tfc->fc, fco);
test_bocdone(fbo, TRUST_ME(hash), 1); test_bocdone(fbo, TRUST_ME(hash), 1);
priv2 = fco->fdb.fdb; priv2 = fco->fdb.fdb;
/* dumb wait until writes are complete */ /* dumb wait until writes are complete */
while (FCO_REFCNT(fco) > 1) while (FCO_REFCNT(fco) > 1)
usleep(1000); usleep(1000);
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
/* get back object without and with close/open */ /* get back object without and with close/open */
for (u = 0; u < 2; u++) { for (u = 0; u < 2; u++) {
fco = test_fellow_cache_obj_get(fc, priv2, notincache); fco = test_fellow_cache_obj_get(tfc->fc, priv2, notincache);
assert_cache_seg_consistency(FCO_FCS(fco)); assert_cache_seg_consistency(FCO_FCS(fco));
DBG("fco1 %p ref %u", fco, FCO_REFCNT(fco)); DBG("fco1 %p ref %u", fco, FCO_REFCNT(fco));
// second access does not assign the oc // second access does not assign the oc
AN(fco == test_fellow_cache_obj_get(fc, priv2, incache)); AN(fco == test_fellow_cache_obj_get(tfc->fc, priv2, incache));
assert_cache_seg_consistency(FCO_FCS(fco)); assert_cache_seg_consistency(FCO_FCS(fco));
DBG("fco2 %p ref %u", fco, FCO_REFCNT(fco)); DBG("fco2 %p ref %u", fco, FCO_REFCNT(fco));
// get attrs and compare // get attrs and compare
t_getattr(fc, fco); t_getattr(tfc->fc, fco);
// get segments and compare // get segments and compare
test_fellow_cache_obj_iter(fc, &fco, h1); test_fellow_cache_obj_iter(tfc->fc, &fco, h1);
assert_cache_seg_consistency(FCO_FCS(fco)); assert_cache_seg_consistency(FCO_FCS(fco));
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
DBG("fco3 %p ref %u", fco, FCO_REFCNT(fco)); DBG("fco3 %p ref %u", fco, FCO_REFCNT(fco));
if (u == 0) if (u == 0)
fellow_cache_obj_deref(fc, fco); fellow_cache_obj_deref(tfc->fc, fco);
else else
fellow_cache_obj_delete(fc, fco, hash); fellow_cache_obj_delete(tfc->fc, fco, hash);
t_fc_fini(&tfc);
AZ(tfc);
fellow_cache_fini(&fc);
AZ(fc);
fellow_log_close(&ffd); fellow_log_close(&ffd);
BWIT_ISEMPTY(membuddy->witness); BWIT_ISEMPTY(membuddy->witness);
buddy_fini(&membuddy, BUDDYF(unmap), NULL, NULL, NULL); buddy_fini(&membuddy, BUDDYF(unmap), NULL, NULL, NULL);
...@@ -7698,9 +7741,8 @@ t_cache(const char *fn, unsigned chksum) ...@@ -7698,9 +7741,8 @@ t_cache(const char *fn, unsigned chksum)
XXXAN(ffd); XXXAN(ffd);
fellow_log_open(ffd, resurrect_keep, &resur_priv); fellow_log_open(ffd, resurrect_keep, &resur_priv);
AZ(g_mem_obj); tfc = t_fc_init(ffd, membuddy, tune);
fc = fellow_cache_init(ffd, membuddy, tune, AN(tfc);
fellow_simple_task_run, &g_mem_obj);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment