From a22d79c1e777efb646f160953203c24544fc229a Mon Sep 17 00:00:00 2001 From: Tomek Date: Thu, 11 Jul 2019 11:37:58 +0200 Subject: [PATCH] test_metrics_evict_refcount --- test/storage/slab_pmem/check_slab_pmem.c | 73 ++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/test/storage/slab_pmem/check_slab_pmem.c b/test/storage/slab_pmem/check_slab_pmem.c index d5cc5425f..c8bd00dcc 100644 --- a/test/storage/slab_pmem/check_slab_pmem.c +++ b/test/storage/slab_pmem/check_slab_pmem.c @@ -986,6 +986,19 @@ START_TEST(test_evict_refcount) } END_TEST +START_TEST(test_setup_wrong_path) +{ +#define DATAPOOL_PATH_WRONG "./" + + option_load_default((struct option *)&options, OPTION_CARDINALITY(options)); + options.slab_datapool.val.vstr = DATAPOOL_PATH_WRONG; + + slab_setup(&options, &metrics); + +#undef DATAPOOL_PATH_WRONG +} +END_TEST + START_TEST(test_metrics_insert_basic) { #define KEY "key" @@ -1200,21 +1213,68 @@ START_TEST(test_metrics_lruq_rebuild) } END_TEST - -START_TEST(test_setup_wrong_path) +START_TEST(test_metrics_evict_refcount) { -#define DATAPOOL_PATH_WRONG "./" +#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_datapool.val.vstr = DATAPOOL_PATH_WRONG; + 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); -#undef DATAPOOL_PATH_WRONG + 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 *)©, (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 *)©, (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 */ @@ -1255,6 +1315,7 @@ slab_suite(void) tcase_add_test(tc_smetrics, test_metrics_insert_large); tcase_add_test(tc_smetrics, test_metrics_reserve_backfill_link); tcase_add_test(tc_smetrics, test_metrics_lruq_rebuild); + tcase_add_test(tc_smetrics, test_metrics_evict_refcount); return s; }