Skip to content

Commit

Permalink
test_metrics_evict_refcount
Browse files Browse the repository at this point in the history
  • Loading branch information
TomekIdczak97 authored and TomekIdczak97 committed Aug 20, 2019
1 parent b28aa9c commit be4402f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/storage/slab_pmem/check_slab_pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,68 @@ START_TEST(test_metrics_lruq_rebuild)
}
END_TEST

START_TEST(test_metrics_evict_refcount)
{
#define MY_SLAB_SIZE 96
#define MY_SLAB_MAXBYTES 96
#define KEY "key"
#define VAL "val"
/**
* The slab will be created with these parameters:
* slab size 96, slab hdr size 36, item hdr size 40
* Given that cas 8,
* we know: key + val < 12
*
**/
struct bstring key, val;
item_rstatus_e status;
struct item *it, *nit;

option_load_default((struct option *)&options, OPTION_CARDINALITY(options));
options.slab_size.val.vuint = MY_SLAB_SIZE;
options.slab_mem.val.vuint = MY_SLAB_MAXBYTES;
options.slab_evict_opt.val.vuint = EVICT_CS;
options.slab_item_max.val.vuint = MY_SLAB_SIZE - SLAB_HDR_SIZE;
options.slab_datapool.val.vstr = DATAPOOL_PATH;

test_teardown(1);
slab_setup(&options, &metrics);
key = str2bstr(KEY);
val = str2bstr(VAL);

status = item_reserve(&it, &key, &val, val.len, 0, INT32_MAX);
ck_assert_msg(status == ITEM_OK, "item_reserve not OK - return status %d", status);

slab_metrics_st copy = metrics;

metric_reset((struct metric *)&metrics, METRIC_CARDINALITY(metrics));
test_teardown(0);
slab_setup(&options, &metrics);

test_assert_metrics((struct metric *)&copy, (struct metric *)&metrics, METRIC_CARDINALITY(metrics));

status = item_reserve(&nit, &key, &val, val.len, 0, INT32_MAX);
ck_assert_msg(status == ITEM_ENOMEM, "item_reserve should fail - return status %d", status);

item_insert(it, &key); /* clears slab refcount, can be evicted */

copy = metrics;

metric_reset((struct metric *)&metrics, METRIC_CARDINALITY(metrics));
test_teardown(0);
slab_setup(&options, &metrics);

test_assert_metrics((struct metric *)&copy, (struct metric *)&metrics, METRIC_CARDINALITY(metrics));

status = item_reserve(&nit, &key, &val, val.len, 0, INT32_MAX);
ck_assert_msg(status == ITEM_OK, "item_reserve not OK - return status %d", status);
#undef KEY
#undef VAL
#undef MY_SLAB_SIZE
#undef MY_SLAB_MAXBYTES
}
END_TEST

/*
* test suite
*/
Expand Down Expand Up @@ -1339,6 +1401,7 @@ slab_suite(void)
tcase_add_test(tc_smetrics, test_metrics_reserve_backfill_link);
tcase_add_test(tc_smetrics, test_metrics_append_basic);
tcase_add_test(tc_smetrics, test_metrics_lruq_rebuild);
tcase_add_test(tc_smetrics, test_metrics_evict_refcount);

return s;
}
Expand Down

0 comments on commit be4402f

Please sign in to comment.