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 tidczak committed Aug 8, 2019
1 parent 2ffaa62 commit 66cdc82
Showing 1 changed file with 67 additions and 6 deletions.
73 changes: 67 additions & 6 deletions test/storage/slab_pmem/check_slab_pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 *)&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 @@ -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;
}
Expand Down

0 comments on commit 66cdc82

Please sign in to comment.