test: flesh out test_env implementation for mempools

Some modules rely on accurate memory buffer counts.
For example, bdev checks that all of its buffer pools
are back to original capacity during spdk_bdev_finish().

So flesh out the mempool implementation in test_env.c
to keep accurate counts of the number of buffers "available"
in the test mempool.  Note that test_env is only designed
for unit tests, so this functionality is not multi-thread
safe.

Still allow for NULL mempool pointers and just default
to old behavior in that case - some unit tests such as
the blobfs cache tree tests still rely on that behavior.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I1d0ab49e16741c92d777d76f35e60271e4ad943a

Reviewed-on: https://review.gerrithub.io/377969
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Jim Harris 2017-09-11 11:53:21 -07:00
parent b1bebb506d
commit 372df452a4

View File

@ -153,43 +153,75 @@ spdk_memzone_free(const char *name)
return 0;
}
struct test_mempool {
size_t count;
};
struct spdk_mempool *
spdk_mempool_create(const char *name, size_t count,
size_t ele_size, size_t cache_size, int socket_id)
{
static int mp = 0;
struct test_mempool *mp;
return (struct spdk_mempool *)&mp;
mp = calloc(1, sizeof(*mp));
if (mp == NULL) {
return NULL;
}
mp->count = count;
return (struct spdk_mempool *)mp;
}
void
spdk_mempool_free(struct spdk_mempool *mp)
spdk_mempool_free(struct spdk_mempool *_mp)
{
struct test_mempool *mp = (struct test_mempool *)_mp;
free(mp);
}
void *
spdk_mempool_get(struct spdk_mempool *mp)
spdk_mempool_get(struct spdk_mempool *_mp)
{
struct test_mempool *mp = (struct test_mempool *)_mp;
void *buf;
if (posix_memalign(&buf, 64, 0x1000)) {
buf = NULL;
if (mp && mp->count == 0) {
return NULL;
}
return buf;
if (posix_memalign(&buf, 64, 0x1000)) {
return NULL;
} else {
if (mp) {
mp->count--;
}
return buf;
}
}
void
spdk_mempool_put(struct spdk_mempool *mp, void *ele)
spdk_mempool_put(struct spdk_mempool *_mp, void *ele)
{
struct test_mempool *mp = (struct test_mempool *)_mp;
if (mp) {
mp->count++;
}
free(ele);
}
size_t
spdk_mempool_count(const struct spdk_mempool *mp)
spdk_mempool_count(const struct spdk_mempool *_mp)
{
return 1024;
struct test_mempool *mp = (struct test_mempool *)_mp;
if (mp) {
return mp->count;
} else {
return 1024;
}
}
uint64_t ut_tsc = 0;