Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 94 additions & 37 deletions test/storage/slab_pmem/check_slab_pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,43 @@ START_TEST(test_expire_truncated)
}
END_TEST

START_TEST(test_freeq)
{
#define KEY "key"
#define VAL "val"
struct bstring key, val;
item_rstatus_e status;
struct item *it;

test_reset(1);

key = str2bstr(KEY);
val = str2bstr(VAL);

time_update();

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

it = item_get(&key);
ck_assert_msg(it != NULL, "item_get could not find key %.*s", key.len, key.data);

ck_assert_msg(item_delete(&key), "item_delete for key %.*s not successful", key.len, key.data);

test_reset(0);

struct slabclass *p = &slabclass[id];
ck_assert_msg(p->nfree_itemq == 1, "Slabclass %u has %u item(s) in freeq", id, p->nfree_itemq);
it = SLIST_FIRST(&p->free_itemq);
ck_assert_msg(it->in_freeq == 1, "Item not flagged as in freeq");

#undef KEY
#undef VAL
}
END_TEST

/**
* Tests check lruq state after restart
*/
Expand Down Expand Up @@ -1136,6 +1173,7 @@ START_TEST(test_metrics_append_basic)
#define KEY "key"
#define VAL "val"
#define APPEND "append"

struct bstring key, val, append;
item_rstatus_e status;
struct item *it;
Expand Down Expand Up @@ -1178,6 +1216,61 @@ START_TEST(test_metrics_append_basic)
}
END_TEST

START_TEST(test_metrics_flush_basic)
{
#define KEY1 "key1"
#define VAL1 "val1"
#define KEY2 "key2"
#define VAL2 "val2"

struct bstring key1, val1, key2, val2;
item_rstatus_e status;
struct item *it;

test_reset(1);

key1 = str2bstr(KEY1);
val1 = str2bstr(VAL1);

key2 = str2bstr(KEY2);
val2 = str2bstr(VAL2);

time_update();
status = item_reserve(&it, &key1, &val1, val1.len, 0, INT32_MAX);
ck_assert_msg(status == ITEM_OK, "item_reserve not OK - return status %d", status);
item_insert(it, &key1);

time_update();
status = item_reserve(&it, &key2, &val2, val2.len, 0, INT32_MAX);
ck_assert_msg(status == ITEM_OK, "item_reserve not OK - return status %d", status);
item_insert(it, &key2);

item_flush();

it = item_get(&key1);
ck_assert_msg(it == NULL, "item with key %.*s still exists after flush", key1.len, key1.data);
it = item_get(&key2);
ck_assert_msg(it == NULL, "item with key %.*s still exists after flush", key2.len, key2.data);

slab_metrics_st copy = metrics;

metric_reset((struct metric *)&metrics, METRIC_CARDINALITY(metrics));
test_reset(0);

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

it = item_get(&key1);
ck_assert_msg(it == NULL, "item with key %.*s still exists after flush", key1.len, key1.data);
it = item_get(&key2);
ck_assert_msg(it == NULL, "item with key %.*s still exists after flush", key2.len, key2.data);

#undef KEY1
#undef VAL1
#undef KEY2
#undef VAL2
}
END_TEST

START_TEST(test_metrics_lruq_rebuild)
{
#define NUM_ITEMS 3
Expand Down Expand Up @@ -1260,43 +1353,6 @@ START_TEST(test_metrics_lruq_rebuild)
}
END_TEST

START_TEST(test_freeq)
{
#define KEY "key"
#define VAL "val"
struct bstring key, val;
item_rstatus_e status;
struct item *it;

test_reset(1);

key = str2bstr(KEY);
val = str2bstr(VAL);

time_update();

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

it = item_get(&key);
ck_assert_msg(it != NULL, "item_get could not find key %.*s", key.len, key.data);

ck_assert_msg(item_delete(&key), "item_delete for key %.*s not successful", key.len, key.data);

test_reset(0);

struct slabclass *p = &slabclass[id];
ck_assert_msg(p->nfree_itemq == 1, "Slabclass %u has %u item(s) in freeq", id, p->nfree_itemq);
it = SLIST_FIRST(&p->free_itemq);
ck_assert_msg(it->in_freeq == 1, "Item not flagged as in freeq");

#undef KEY
#undef VAL
}
END_TEST

/*
* test suite
*/
Expand Down Expand Up @@ -1338,6 +1394,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_append_basic);
tcase_add_test(tc_smetrics, test_metrics_flush_basic);
tcase_add_test(tc_smetrics, test_metrics_lruq_rebuild);

return s;
Expand Down