repo
stringlengths 1
152
⌀ | file
stringlengths 14
221
| code
stringlengths 501
25k
| file_length
int64 501
25k
| avg_line_length
float64 20
99.5
| max_line_length
int64 21
134
| extension_type
stringclasses 2
values |
---|---|---|---|---|---|---|
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset_foreach/util_poolset_foreach.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_poolset_foreach.c -- unit test for util_poolset_foreach_part()
*
* usage: util_poolset_foreach file...
*/
#include "unittest.h"
#include "set.h"
#include "pmemcommon.h"
#include <errno.h>
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
static int
cb(struct part_file *pf, void *arg)
{
if (pf->is_remote) {
/* remote replica */
const char *node_addr = pf->remote->node_addr;
const char *pool_desc = pf->remote->pool_desc;
char *set_name = (char *)arg;
UT_OUT("%s: %s %s", set_name, node_addr, pool_desc);
} else {
const char *name = pf->part->path;
char *set_name = (char *)arg;
UT_OUT("%s: %s", set_name, name);
}
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_poolset_foreach");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 2)
UT_FATAL("usage: %s file...",
argv[0]);
for (int i = 1; i < argc; i++) {
char *fname = argv[i];
int ret = util_poolset_foreach_part(fname, cb, fname);
UT_OUT("util_poolset_foreach_part(%s): %d", fname, ret);
}
common_fini();
DONE(NULL);
}
| 2,808 | 30.211111 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_reopen/cto_reopen.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_reopen -- unit test for cto_reopen
*
* usage: cto_reopen filename nrep
*/
#include "unittest.h"
#define ALLOC_SIZE (1024L)
#define NALLOCS 16
#define POOL_SIZE (2 * PMEMCTO_MIN_POOL)
/* buffer for all allocation pointers */
static char *ptrs[NALLOCS];
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_reopen");
if (argc != 3)
UT_FATAL("usage: %s filename nrep", argv[0]);
int nrep = atoi(argv[2]);
PMEMctopool *pcp;
for (int r = 0; r < nrep; r++) {
if (r == 0) {
pcp = pmemcto_create(argv[1], "test",
POOL_SIZE, 0666);
} else {
pcp = pmemcto_open(argv[1], "test");
}
UT_ASSERTne(pcp, NULL);
memset(ptrs, 0, sizeof(ptrs));
int i;
for (i = 0; i < NALLOCS; ++i) {
ptrs[i] = pmemcto_malloc(pcp, ALLOC_SIZE);
if (ptrs[i] == NULL) {
/* out of memory in pool */
break;
}
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
/* fill each allocation with a unique value */
memset(ptrs[i], (char)i, ALLOC_SIZE);
}
UT_OUT("rep %d cnt %d", r, i);
UT_ASSERTeq(i, NALLOCS);
for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i)
pmemcto_free(pcp, ptrs[i]);
pmemcto_close(pcp);
}
DONE(NULL);
}
| 2,821 | 28.395833 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_aligned_alloc/vmem_aligned_alloc.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_aligned_alloc.c -- unit test for vmem_aligned_alloc
*
* usage: vmem_aligned_alloc [directory]
*/
#include "unittest.h"
#define MAX_ALLOCS (100)
static int custom_allocs;
static int custom_alloc_calls;
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
VMEM *vmp;
size_t alignment;
unsigned i;
int *ptr;
int *ptrs[MAX_ALLOCS];
START(argc, argv, "vmem_aligned_alloc");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
/* allocate memory for function vmem_create_in_region() */
void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
/* use custom alloc functions to check for memory leaks */
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
/* test with address alignment from 2B to 4MB */
for (alignment = 2; alignment <= 4 * 1024 * 1024; alignment *= 2) {
if (dir == NULL) {
vmp = vmem_create_in_region(mem_pool,
VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
memset(ptrs, 0, MAX_ALLOCS * sizeof(ptrs[0]));
for (i = 0; i < MAX_ALLOCS; ++i) {
ptr = vmem_aligned_alloc(vmp, alignment, sizeof(int));
ptrs[i] = ptr;
/* at least one allocation must succeed */
UT_ASSERT(i != 0 || ptr != NULL);
if (ptr == NULL)
break;
/* ptr should be usable */
*ptr = test_value;
UT_ASSERTeq(*ptr, test_value);
/* check for correct address alignment */
UT_ASSERTeq((uintptr_t)(ptr) & (alignment - 1), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(ptr, mem_pool, VMEM_MIN_POOL);
}
}
for (i = 0; i < MAX_ALLOCS; ++i) {
if (ptrs[i] == NULL)
break;
vmem_free(vmp, ptrs[i]);
}
vmem_delete(vmp);
}
/* check memory leaks */
UT_ASSERTne(custom_alloc_calls, 0);
UT_ASSERTeq(custom_allocs, 0);
DONE(NULL);
}
| 4,662 | 24.905556 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_pages_purging/vmem_pages_purging.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_pages_purging.c -- unit test for vmem_pages_purging
*
* usage: vmem_pages_purging [-z] directory
*/
#include <getopt.h>
#include "unittest.h"
#include "jemalloc/internal/jemalloc_internal.h"
#include "jemalloc/internal/size_classes.h"
#define DEFAULT_COUNT (SMALL_MAXCLASS / 4)
#define DEFAULT_N 100
static void
usage(char *appname)
{
UT_FATAL("usage: %s <z - use calloc | \
n - do not use calloc> directory ", appname);
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
int count = DEFAULT_COUNT;
int n = DEFAULT_N;
VMEM *vmp;
int i, j;
int use_calloc = 0;
START(argc, argv, "vmem_pages_purging");
switch (argv[1][0]) {
case 'z':
use_calloc = 1;
break;
case 'n':
break;
default:
usage(argv[0]);
}
if (argv[2]) {
dir = argv[2];
} else {
usage(argv[0]);
}
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
for (i = 0; i < n; i++) {
int *test = NULL;
if (use_calloc)
test = vmem_calloc(vmp, 1, count * sizeof(int));
else
test = vmem_malloc(vmp, count * sizeof(int));
UT_ASSERTne(test, NULL);
if (use_calloc) {
/* vmem_calloc should return zeroed memory */
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], 0);
}
for (j = 0; j < count; j++)
test[j] = test_value;
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], test_value);
vmem_free(vmp, test);
}
vmem_delete(vmp);
DONE(NULL);
}
| 3,052 | 26.504505 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_layout/obj_layout.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_layout.c -- unit test for layout
*
* This test should be modified after every layout change. It's here to prevent
* any accidental layout changes.
*/
#include "util.h"
#include "unittest.h"
#include "sync.h"
#include "heap_layout.h"
#include "lane.h"
#include "tx.h"
#include "ulog.h"
#include "list.h"
#define SIZEOF_CHUNK_HEADER_V3 (8)
#define MAX_CHUNK_V3 (65535 - 7)
#define SIZEOF_CHUNK_V3 (1024ULL * 256)
#define SIZEOF_CHUNK_RUN_HEADER_V3 (16)
#define SIZEOF_ZONE_HEADER_V3 (64)
#define SIZEOF_ZONE_METADATA_V3 (SIZEOF_ZONE_HEADER_V3 +\
SIZEOF_CHUNK_HEADER_V3 * MAX_CHUNK_V3)
#define SIZEOF_HEAP_HDR_V3 (1024)
#define SIZEOF_LEGACY_ALLOCATION_HEADER_V3 (64)
#define SIZEOF_COMPACT_ALLOCATION_HEADER_V3 (16)
#define SIZEOF_LOCK_V3 (64)
#define SIZEOF_PMEMOID_V3 (16)
#define SIZEOF_LIST_ENTRY_V3 (SIZEOF_PMEMOID_V3 * 2)
#define SIZEOF_LIST_HEAD_V3 (SIZEOF_PMEMOID_V3 + SIZEOF_LOCK_V3)
#define SIZEOF_LANE_SECTION_V3 (1024)
#define SIZEOF_LANE_V3 (3 * SIZEOF_LANE_SECTION_V3)
#define SIZEOF_ULOG_V4 (64)
#define SIZEOF_ULOG_BASE_ENTRY_V4 (8)
#define SIZEOF_ULOG_VAL_ENTRY_V4 (16)
#define SIZEOF_ULOG_BUF_ENTRY_V4 (24)
POBJ_LAYOUT_BEGIN(layout);
POBJ_LAYOUT_ROOT(layout, struct foo);
POBJ_LAYOUT_END(layout);
struct foo {
POBJ_LIST_ENTRY(struct foo) f;
};
POBJ_LIST_HEAD(foo_head, struct foo);
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_layout");
UT_COMPILE_ERROR_ON(CHUNKSIZE != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk);
ASSERT_ALIGNED_FIELD(struct chunk, data);
ASSERT_ALIGNED_CHECK(struct chunk);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run) != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_run_header);
ASSERT_ALIGNED_FIELD(struct chunk_run_header, block_size);
ASSERT_ALIGNED_FIELD(struct chunk_run_header, alignment);
ASSERT_ALIGNED_CHECK(struct chunk_run_header);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run_header) !=
SIZEOF_CHUNK_RUN_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_run);
ASSERT_ALIGNED_FIELD(struct chunk_run, hdr);
ASSERT_ALIGNED_FIELD(struct chunk_run, content);
ASSERT_ALIGNED_CHECK(struct chunk_run);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run) != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_header);
ASSERT_ALIGNED_FIELD(struct chunk_header, type);
ASSERT_ALIGNED_FIELD(struct chunk_header, flags);
ASSERT_ALIGNED_FIELD(struct chunk_header, size_idx);
ASSERT_ALIGNED_CHECK(struct chunk_header);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_header) !=
SIZEOF_CHUNK_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct zone_header);
ASSERT_ALIGNED_FIELD(struct zone_header, magic);
ASSERT_ALIGNED_FIELD(struct zone_header, size_idx);
ASSERT_ALIGNED_FIELD(struct zone_header, reserved);
ASSERT_ALIGNED_CHECK(struct zone_header);
UT_COMPILE_ERROR_ON(sizeof(struct zone_header) !=
SIZEOF_ZONE_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct zone);
ASSERT_ALIGNED_FIELD(struct zone, header);
ASSERT_ALIGNED_FIELD(struct zone, chunk_headers);
ASSERT_ALIGNED_CHECK(struct zone);
UT_COMPILE_ERROR_ON(sizeof(struct zone) !=
SIZEOF_ZONE_METADATA_V3);
ASSERT_ALIGNED_BEGIN(struct heap_header);
ASSERT_ALIGNED_FIELD(struct heap_header, signature);
ASSERT_ALIGNED_FIELD(struct heap_header, major);
ASSERT_ALIGNED_FIELD(struct heap_header, minor);
ASSERT_ALIGNED_FIELD(struct heap_header, unused);
ASSERT_ALIGNED_FIELD(struct heap_header, chunksize);
ASSERT_ALIGNED_FIELD(struct heap_header, chunks_per_zone);
ASSERT_ALIGNED_FIELD(struct heap_header, reserved);
ASSERT_ALIGNED_FIELD(struct heap_header, checksum);
ASSERT_ALIGNED_CHECK(struct heap_header);
UT_COMPILE_ERROR_ON(sizeof(struct heap_header) !=
SIZEOF_HEAP_HDR_V3);
ASSERT_ALIGNED_BEGIN(struct allocation_header_legacy);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, unused);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, size);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, unused2);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, root_size);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, type_num);
ASSERT_ALIGNED_CHECK(struct allocation_header_legacy);
UT_COMPILE_ERROR_ON(sizeof(struct allocation_header_legacy) !=
SIZEOF_LEGACY_ALLOCATION_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct allocation_header_compact);
ASSERT_ALIGNED_FIELD(struct allocation_header_compact, size);
ASSERT_ALIGNED_FIELD(struct allocation_header_compact, extra);
ASSERT_ALIGNED_CHECK(struct allocation_header_compact);
UT_COMPILE_ERROR_ON(sizeof(struct allocation_header_compact) !=
SIZEOF_COMPACT_ALLOCATION_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct ulog);
ASSERT_ALIGNED_FIELD(struct ulog, checksum);
ASSERT_ALIGNED_FIELD(struct ulog, next);
ASSERT_ALIGNED_FIELD(struct ulog, capacity);
ASSERT_ALIGNED_FIELD(struct ulog, unused);
ASSERT_ALIGNED_CHECK(struct ulog);
UT_COMPILE_ERROR_ON(sizeof(struct ulog) !=
SIZEOF_ULOG_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_base, offset);
ASSERT_ALIGNED_CHECK(struct ulog_entry_base);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_base) !=
SIZEOF_ULOG_BASE_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_val);
ASSERT_ALIGNED_FIELD(struct ulog_entry_val, base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_val, value);
ASSERT_ALIGNED_CHECK(struct ulog_entry_val);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_val) !=
SIZEOF_ULOG_VAL_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_buf);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, checksum);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, size);
ASSERT_ALIGNED_CHECK(struct ulog_entry_buf);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_buf) !=
SIZEOF_ULOG_BUF_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(PMEMoid);
ASSERT_ALIGNED_FIELD(PMEMoid, pool_uuid_lo);
ASSERT_ALIGNED_FIELD(PMEMoid, off);
ASSERT_ALIGNED_CHECK(PMEMoid);
UT_COMPILE_ERROR_ON(sizeof(PMEMoid) !=
SIZEOF_PMEMOID_V3);
UT_COMPILE_ERROR_ON(sizeof(PMEMmutex) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(sizeof(PMEMmutex) != sizeof(PMEMmutex_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(PMEMmutex_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(os_mutex_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(PMEMrwlock) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(PMEMrwlock_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(os_rwlock_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(PMEMcond) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(PMEMcond_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(os_cond_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(struct foo) != SIZEOF_LIST_ENTRY_V3);
UT_COMPILE_ERROR_ON(sizeof(struct list_entry) != SIZEOF_LIST_ENTRY_V3);
UT_COMPILE_ERROR_ON(sizeof(struct foo_head) != SIZEOF_LIST_HEAD_V3);
UT_COMPILE_ERROR_ON(sizeof(struct list_head) != SIZEOF_LIST_HEAD_V3);
ASSERT_ALIGNED_BEGIN(struct lane_layout);
ASSERT_ALIGNED_FIELD(struct lane_layout, internal);
ASSERT_ALIGNED_FIELD(struct lane_layout, external);
ASSERT_ALIGNED_FIELD(struct lane_layout, undo);
ASSERT_ALIGNED_CHECK(struct lane_layout);
UT_COMPILE_ERROR_ON(sizeof(struct lane_layout) !=
SIZEOF_LANE_V3);
DONE(NULL);
}
| 9,082 | 37.487288 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_add_range_direct/obj_tx_add_range_direct.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_add_range_direct.c -- unit test for pmemobj_tx_add_range_direct
*/
#include <string.h>
#include <stddef.h>
#include "tx.h"
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "tx_add_range_direct"
#define OBJ_SIZE 1024
enum type_number {
TYPE_OBJ,
TYPE_OBJ_ABORT,
};
TOID_DECLARE(struct object, 0);
struct object {
size_t value;
unsigned char data[OBJ_SIZE - sizeof(size_t)];
};
#define VALUE_OFF (offsetof(struct object, value))
#define VALUE_SIZE (sizeof(size_t))
#define DATA_OFF (offsetof(struct object, data))
#define DATA_SIZE (OBJ_SIZE - sizeof(size_t))
#define TEST_VALUE_1 1
#define TEST_VALUE_2 2
/*
* do_tx_alloc -- do tx allocation with specified type number
*/
static PMEMoid
do_tx_zalloc(PMEMobjpool *pop, unsigned type_num)
{
PMEMoid ret = OID_NULL;
TX_BEGIN(pop) {
ret = pmemobj_tx_zalloc(sizeof(struct object), type_num);
} TX_END
return ret;
}
/*
* do_tx_add_range_alloc_commit -- call add_range_direct on object allocated
* within the same transaction and commit the transaction
*/
static void
do_tx_add_range_alloc_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj)->data, TEST_VALUE_2,
DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj)->data[i], TEST_VALUE_2);
}
/*
* do_tx_add_range_alloc_abort -- call add_range_direct on object allocated
* within the same transaction and abort the transaction
*/
static void
do_tx_add_range_alloc_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj)->data, TEST_VALUE_2,
DATA_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_OBJ_ABORT));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_add_range_twice_commit -- call add_range_direct one the same area
* twice and commit the transaction
*/
static void
do_tx_add_range_twice_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_2;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_2);
}
/*
* do_tx_add_range_twice_abort -- call add_range_direct one the same area
* twice and abort the transaction
*/
static void
do_tx_add_range_twice_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_2;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, 0);
}
/*
* do_tx_add_range_abort_after_nested -- call add_range_direct and
* commit the tx
*/
static void
do_tx_add_range_abort_after_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, 0);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], 0);
}
/*
* do_tx_add_range_abort_nested -- call add_range_direct and
* commit the tx
*/
static void
do_tx_add_range_abort_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, 0);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], 0);
}
/*
* do_tx_add_range_commit_nested -- call add_range_direct and commit the tx
*/
static void
do_tx_add_range_commit_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], TEST_VALUE_2);
}
/*
* do_tx_add_range_abort -- call add_range_direct and abort the tx
*/
static void
do_tx_add_range_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, 0);
}
/*
* do_tx_add_range_commit -- call add_range_direct and commit tx
*/
static void
do_tx_add_range_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* do_tx_xadd_range_commit -- call xadd_range_direct and commit tx
*/
static void
do_tx_xadd_range_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_xadd_range_direct(ptr + VALUE_OFF,
VALUE_SIZE, POBJ_XADD_NO_FLUSH);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
/* let pmemcheck find we didn't flush it */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* do_tx_commit_and_abort -- use range cache, commit and then abort to make
* sure that it won't affect previously modified data.
*/
static void
do_tx_commit_and_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
TX_SET(obj, value, TEST_VALUE_1); /* this will land in cache */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* test_add_direct_macros -- test TX_ADD_DIRECT, TX_ADD_FIELD_DIRECT and
* TX_SET_DIRECT
*/
static void
test_add_direct_macros(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_SET_DIRECT(o, value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_ADD_DIRECT(o);
o->value = TEST_VALUE_2;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_2);
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_ADD_FIELD_DIRECT(o, value);
o->value = TEST_VALUE_1;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
#define MAX_CACHED_RANGES 100
/*
* test_tx_corruption_bug -- test whether tx_adds for small objects from one
* transaction does NOT leak to the next transaction
*/
static void
test_tx_corruption_bug(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
struct object *o = D_RW(obj);
unsigned char i;
UT_COMPILE_ERROR_ON(1.5 * MAX_CACHED_RANGES > 255);
TX_BEGIN(pop) {
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i) {
TX_ADD_DIRECT(&o->data[i]);
o->data[i] = i;
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i)
UT_ASSERTeq((unsigned char)o->data[i], i);
TX_BEGIN(pop) {
for (i = 0; i < 0.1 * MAX_CACHED_RANGES; ++i) {
TX_ADD_DIRECT(&o->data[i]);
o->data[i] = i + 10;
}
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i)
UT_ASSERTeq((unsigned char)o->data[i], i);
pmemobj_free(&obj.oid);
}
static void
do_tx_add_range_too_large(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
pmemobj_tx_add_range_direct(pmemobj_direct(obj.oid),
PMEMOBJ_MAX_ALLOC_SIZE + 1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTne(errno, 0);
errno = 0;
}
static void
do_tx_add_range_lots_of_small_snapshots(PMEMobjpool *pop)
{
size_t s = TX_DEFAULT_RANGE_CACHE_SIZE * 2;
size_t snapshot_s = 8;
PMEMoid obj;
int ret = pmemobj_zalloc(pop, &obj, s, 0);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
for (size_t n = 0; n < s; n += snapshot_s) {
void *addr = (void *)((size_t)pmemobj_direct(obj) + n);
pmemobj_tx_add_range_direct(addr, snapshot_s);
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
static void
do_tx_add_cache_overflowing_range(PMEMobjpool *pop)
{
/*
* This test adds snapshot to the cache, but in way that results in
* one of the add_range being split into two caches.
*/
size_t s = TX_DEFAULT_RANGE_CACHE_SIZE * 2;
size_t snapshot_s = TX_DEFAULT_RANGE_CACHE_THRESHOLD - 8;
PMEMoid obj;
int ret = pmemobj_zalloc(pop, &obj, s, 0);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
size_t n = 0;
while (n != s) {
if (n + snapshot_s > s)
snapshot_s = s - n;
void *addr = (void *)((size_t)pmemobj_direct(obj) + n);
pmemobj_tx_add_range_direct(addr, snapshot_s);
memset(addr, 0xc, snapshot_s);
n += snapshot_s;
}
pmemobj_tx_abort(0);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(pmemobj_direct(obj), s));
UT_ASSERTne(errno, 0);
errno = 0;
pmemobj_free(&obj);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_add_range_direct");
util_init();
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL * 4,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_add_range_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_commit_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort_after_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_twice_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_twice_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_alloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_alloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_commit_and_abort(pop);
VALGRIND_WRITE_STATS;
test_add_direct_macros(pop);
VALGRIND_WRITE_STATS;
test_tx_corruption_bug(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_too_large(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_lots_of_small_snapshots(pop);
VALGRIND_WRITE_STATS;
do_tx_add_cache_overflowing_range(pop);
VALGRIND_WRITE_STATS;
do_tx_xadd_range_commit(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 15,389 | 22.353566 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_many_size_allocs/obj_many_size_allocs.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_many_size_allocs.c -- allocation of many objects with different sizes
*
*/
#include <stddef.h>
#include "unittest.h"
#include "heap.h"
#define LAYOUT_NAME "many_size_allocs"
#define TEST_ALLOC_SIZE 2048
#define LAZY_LOAD_SIZE 10
#define LAZY_LOAD_BIG_SIZE 150
struct cargs {
size_t size;
};
static int
test_constructor(PMEMobjpool *pop, void *addr, void *args)
{
struct cargs *a = args;
/* do not use pmem_memset_persit() here */
pmemobj_memset_persist(pop, addr, a->size % 256, a->size);
return 0;
}
static PMEMobjpool *
test_allocs(PMEMobjpool *pop, const char *path)
{
PMEMoid *oid = MALLOC(sizeof(PMEMoid) * TEST_ALLOC_SIZE);
if (pmemobj_alloc(pop, &oid[0], 0, 0, NULL, NULL) == 0)
UT_FATAL("pmemobj_alloc(0) succeeded");
for (unsigned i = 1; i < TEST_ALLOC_SIZE; ++i) {
struct cargs args = { i };
if (pmemobj_alloc(pop, &oid[i], i, 0,
test_constructor, &args) != 0)
UT_FATAL("!pmemobj_alloc");
UT_ASSERT(!OID_IS_NULL(oid[i]));
}
pmemobj_close(pop);
UT_ASSERT(pmemobj_check(path, LAYOUT_NAME) == 1);
UT_ASSERT((pop = pmemobj_open(path, LAYOUT_NAME)) != NULL);
for (int i = 1; i < TEST_ALLOC_SIZE; ++i) {
pmemobj_free(&oid[i]);
UT_ASSERT(OID_IS_NULL(oid[i]));
}
FREE(oid);
return pop;
}
static PMEMobjpool *
test_lazy_load(PMEMobjpool *pop, const char *path)
{
PMEMoid oid[3];
int ret = pmemobj_alloc(pop, &oid[0], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, &oid[1], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, &oid[2], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
pmemobj_close(pop);
UT_ASSERT((pop = pmemobj_open(path, LAYOUT_NAME)) != NULL);
pmemobj_free(&oid[1]);
ret = pmemobj_alloc(pop, &oid[1], LAZY_LOAD_BIG_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
return pop;
}
#define ALLOC_BLOCK_SIZE 64
#define MAX_BUCKET_MAP_ENTRIES (RUN_DEFAULT_SIZE / ALLOC_BLOCK_SIZE)
static void
test_all_classes(PMEMobjpool *pop)
{
for (unsigned i = 1; i <= MAX_BUCKET_MAP_ENTRIES; ++i) {
int err;
int nallocs = 0;
while ((err = pmemobj_alloc(pop, NULL, i * ALLOC_BLOCK_SIZE, 0,
NULL, NULL)) == 0) {
nallocs++;
}
UT_ASSERT(nallocs > 0);
PMEMoid iter, niter;
POBJ_FOREACH_SAFE(pop, iter, niter) {
pmemobj_free(&iter);
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_many_size_allocs");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
pop = test_lazy_load(pop, path);
pop = test_allocs(pop, path);
test_all_classes(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 4,352 | 25.705521 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_alloc_class_config/obj_ctl_alloc_class_config.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_alloc_class_config.c -- tests for the ctl alloc class config
*/
#include "unittest.h"
#define LAYOUT "obj_ctl_alloc_class_config"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_alloc_class_config");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
struct pobj_alloc_class_desc alloc_class;
int ret;
ret = pmemobj_ctl_get(pop, "heap.alloc_class.128.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
ret = pmemobj_ctl_get(pop, "heap.alloc_class.129.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
ret = pmemobj_ctl_get(pop, "heap.alloc_class.130.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
pmemobj_close(pop);
DONE(NULL);
}
| 2,757 | 32.634146 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_action/obj_action.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_action.c -- test the action API
*/
#include <stdlib.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_action"
struct macro_reserve_s {
PMEMoid oid;
uint64_t value;
};
TOID_DECLARE(struct macro_reserve_s, 1);
struct foo {
int bar;
};
struct root {
struct {
PMEMoid oid;
uint64_t value;
} reserved;
struct {
PMEMoid oid;
uint64_t value;
} published;
struct {
PMEMoid oid;
} tx_reserved;
struct {
PMEMoid oid;
} tx_reserved_fulfilled;
struct {
PMEMoid oid;
} tx_published;
};
#define HUGE_ALLOC_SIZE ((1 << 20) * 3)
#define MAX_ACTS 10
static void
test_resv_cancel_huge(PMEMobjpool *pop)
{
PMEMoid oid;
unsigned nallocs = 0;
struct pobj_action *act = (struct pobj_action *)
ZALLOC(sizeof(struct pobj_action) * MAX_ACTS);
do {
oid = pmemobj_reserve(pop, &act[nallocs++], HUGE_ALLOC_SIZE, 0);
} while (!OID_IS_NULL(oid));
pmemobj_cancel(pop, act, nallocs - 1);
unsigned nallocs2 = 0;
do {
oid = pmemobj_reserve(pop, &act[nallocs2++],
HUGE_ALLOC_SIZE, 0);
} while (!OID_IS_NULL(oid));
pmemobj_cancel(pop, act, nallocs2 - 1);
UT_ASSERTeq(nallocs, nallocs2);
FREE(act);
}
static void
test_defer_free(PMEMobjpool *pop)
{
PMEMoid oid;
int ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
struct pobj_action act;
pmemobj_defer_free(pop, oid, &act);
pmemobj_publish(pop, &act, 1);
struct foo *f = (struct foo *)pmemobj_direct(oid);
f->bar = 5; /* should trigger memcheck error */
ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
pmemobj_defer_free(pop, oid, &act);
pmemobj_cancel(pop, &act, 1);
f = (struct foo *)pmemobj_direct(oid);
f->bar = 5; /* should NOT trigger memcheck error */
}
/*
* This function tests if macros included in action.h api compile and
* allocate memory.
*/
static void
test_api_macros(PMEMobjpool *pop)
{
struct pobj_action macro_reserve_act[1];
TOID(struct macro_reserve_s) macro_reserve_p = POBJ_RESERVE_NEW(pop,
struct macro_reserve_s, ¯o_reserve_act[0]);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_RESERVE_ALLOC(pop, struct macro_reserve_s,
sizeof(struct macro_reserve_s), ¯o_reserve_act[0]);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_XRESERVE_NEW(pop, struct macro_reserve_s,
¯o_reserve_act[0], 0);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_XRESERVE_ALLOC(pop, struct macro_reserve_s,
sizeof(struct macro_reserve_s), ¯o_reserve_act[0], 0);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
}
#define POBJ_MAX_ACTIONS 60
static void
test_many(PMEMobjpool *pop, size_t n)
{
struct pobj_action *act = (struct pobj_action *)
MALLOC(sizeof(struct pobj_action) * n);
PMEMoid *oid = (PMEMoid *)
MALLOC(sizeof(PMEMoid) * n);
for (int i = 0; i < n; ++i) {
oid[i] = pmemobj_reserve(pop, &act[i], 1, 0);
UT_ASSERT(!OID_IS_NULL(oid[i]));
}
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
for (int i = 0; i < n; ++i) {
pmemobj_defer_free(pop, oid[i], &act[i]);
}
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
FREE(oid);
FREE(act);
}
static void
test_many_sets(PMEMobjpool *pop, size_t n)
{
struct pobj_action *act = (struct pobj_action *)
MALLOC(sizeof(struct pobj_action) * n);
PMEMoid oid;
pmemobj_alloc(pop, &oid, sizeof(uint64_t) * n, 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(oid));
uint64_t *values = (uint64_t *)pmemobj_direct(oid);
for (uint64_t i = 0; i < n; ++i)
pmemobj_set_value(pop, &act[i], values + i, i);
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
for (uint64_t i = 0; i < n; ++i)
UT_ASSERTeq(*(values + i), i);
pmemobj_free(&oid);
FREE(act);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_action");
if (argc < 2)
UT_FATAL("usage: %s filename", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid root = pmemobj_root(pop, sizeof(struct root));
struct root *rootp = (struct root *)pmemobj_direct(root);
struct pobj_action reserved[2];
struct pobj_action published[2];
struct pobj_action tx_reserved;
struct pobj_action tx_reserved_fulfilled;
struct pobj_action tx_published;
rootp->reserved.oid =
pmemobj_reserve(pop, &reserved[0], sizeof(struct foo), 0);
pmemobj_set_value(pop, &reserved[1], &rootp->reserved.value, 1);
rootp->published.oid =
pmemobj_reserve(pop, &published[0], sizeof(struct foo), 0);
pmemobj_set_value(pop, &published[1], &rootp->published.value, 1);
pmemobj_publish(pop, published, 2);
rootp->tx_reserved.oid =
pmemobj_reserve(pop, &tx_reserved, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_reserved, 1);
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
rootp->tx_reserved_fulfilled.oid =
pmemobj_reserve(pop,
&tx_reserved_fulfilled, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_reserved_fulfilled, 1);
pmemobj_tx_publish(NULL, 0); /* this is to force resv fulfill */
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
rootp->tx_published.oid =
pmemobj_reserve(pop, &tx_published, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_published, 1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_persist(pop, rootp, sizeof(*rootp));
pmemobj_close(pop);
UT_ASSERTeq(pmemobj_check(path, LAYOUT_NAME), 1);
UT_ASSERTne(pop = pmemobj_open(path, LAYOUT_NAME), NULL);
root = pmemobj_root(pop, sizeof(struct root));
rootp = (struct root *)pmemobj_direct(root);
struct foo *reserved_foop =
(struct foo *)pmemobj_direct(rootp->reserved.oid);
reserved_foop->bar = 1; /* should trigger memcheck error */
UT_ASSERTeq(rootp->reserved.value, 0);
struct foo *published_foop =
(struct foo *)pmemobj_direct(rootp->published.oid);
published_foop->bar = 1; /* should NOT trigger memcheck error */
UT_ASSERTeq(rootp->published.value, 1);
struct foo *tx_reserved_foop =
(struct foo *)pmemobj_direct(rootp->tx_reserved.oid);
tx_reserved_foop->bar = 1; /* should trigger memcheck error */
struct foo *tx_reserved_fulfilled_foop =
(struct foo *)pmemobj_direct(rootp->tx_reserved_fulfilled.oid);
tx_reserved_fulfilled_foop->bar = 1; /* should trigger memcheck error */
struct foo *tx_published_foop =
(struct foo *)pmemobj_direct(rootp->tx_published.oid);
tx_published_foop->bar = 1; /* should NOT trigger memcheck error */
test_resv_cancel_huge(pop);
test_defer_free(pop);
test_api_macros(pop);
test_many(pop, POBJ_MAX_ACTIONS * 2);
test_many_sets(pop, POBJ_MAX_ACTIONS * 2);
pmemobj_close(pop);
DONE(NULL);
}
| 8,634 | 25.166667 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_vecq/util_vecq.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_vecq.c -- unit test for vecq implementation
*/
#include "unittest.h"
#include "vecq.h"
struct test {
int foo;
int bar;
};
static void
vecq_test()
{
VECQ(testvec, struct test) v;
VECQ_INIT(&v);
struct test t = {5, 10};
struct test t2 = {10, 15};
int ret;
ret = VECQ_ENQUEUE(&v, t);
UT_ASSERTeq(ret, 0);
ret = VECQ_ENQUEUE(&v, t2);
UT_ASSERTeq(ret, 0);
struct test res = VECQ_FRONT(&v);
UT_ASSERTeq(res.bar, t.bar);
size_t s = VECQ_SIZE(&v);
UT_ASSERTeq(s, 2);
size_t c = VECQ_CAPACITY(&v);
UT_ASSERTeq(c, 64);
res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res.bar, t.bar);
res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res.bar, t2.bar);
VECQ_DELETE(&v);
}
static void
vecq_test_grow()
{
VECQ(testvec, int) v;
VECQ_INIT(&v);
for (int i = 1; i < 1000; ++i) {
int ret = VECQ_ENQUEUE(&v, i);
UT_ASSERTeq(ret, 0);
}
for (int i = 1; i < 1000; ++i) {
int res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res, i);
}
VECQ_DELETE(&v);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_vecq");
vecq_test();
vecq_test_grow();
DONE(NULL);
}
| 2,673 | 23.990654 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/ex_linkedlist/ex_linkedlist.c | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ex_linkedlist.c - test of linkedlist example
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pmemobj_list.h"
#include "unittest.h"
#define ELEMENT_NO 10
#define PRINT_RES(res, struct_name) do {\
if ((res) == 0) {\
UT_OUT("Outcome for " #struct_name " is correct!");\
} else {\
UT_ERR("Outcome for " #struct_name\
" does not match expected result!!!");\
}\
} while (0)
POBJ_LAYOUT_BEGIN(list);
POBJ_LAYOUT_ROOT(list, struct base);
POBJ_LAYOUT_TOID(list, struct tqueuehead);
POBJ_LAYOUT_TOID(list, struct slisthead);
POBJ_LAYOUT_TOID(list, struct tqnode);
POBJ_LAYOUT_TOID(list, struct snode);
POBJ_LAYOUT_END(list);
POBJ_TAILQ_HEAD(tqueuehead, struct tqnode);
struct tqnode {
int data;
POBJ_TAILQ_ENTRY(struct tqnode) tnd;
};
POBJ_SLIST_HEAD(slisthead, struct snode);
struct snode {
int data;
POBJ_SLIST_ENTRY(struct snode) snd;
};
struct base {
struct tqueuehead tqueue;
struct slisthead slist;
};
static const int expectedResTQ[] = { 111, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 222 };
static const int expectedResSL[] = { 111, 8, 222, 6, 5, 4, 3, 2, 1, 0, 333 };
/*
* dump_tq -- dumps list on standard output
*/
static void
dump_tq(struct tqueuehead *head, const char *str)
{
TOID(struct tqnode) var;
UT_OUT("%s start", str);
POBJ_TAILQ_FOREACH(var, head, tnd)
UT_OUT("%d", D_RW(var)->data);
UT_OUT("%s end", str);
}
/*
* init_tqueue -- initialize tail queue
*/
static void
init_tqueue(PMEMobjpool *pop, struct tqueuehead *head)
{
if (!POBJ_TAILQ_EMPTY(head))
return;
TOID(struct tqnode) node;
TOID(struct tqnode) middleNode;
TOID(struct tqnode) node888;
TOID(struct tqnode) tempNode;
int i = 0;
TX_BEGIN(pop) {
POBJ_TAILQ_INIT(head);
dump_tq(head, "after init");
for (i = 0; i < ELEMENT_NO; ++i) {
node = TX_NEW(struct tqnode);
D_RW(node)->data = i;
if (0 == i) {
middleNode = node;
}
POBJ_TAILQ_INSERT_HEAD(head, node, tnd);
node = TX_NEW(struct tqnode);
D_RW(node)->data = i;
POBJ_TAILQ_INSERT_TAIL(head, node, tnd);
}
dump_tq(head, "after insert[head|tail]");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 666;
POBJ_TAILQ_INSERT_AFTER(middleNode, node, tnd);
dump_tq(head, "after insert_after1");
middleNode = POBJ_TAILQ_NEXT(middleNode, tnd);
node = TX_NEW(struct tqnode);
D_RW(node)->data = 888;
node888 = node;
POBJ_TAILQ_INSERT_BEFORE(middleNode, node, tnd);
dump_tq(head, "after insert_before1");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 555;
POBJ_TAILQ_INSERT_BEFORE(middleNode, node, tnd);
dump_tq(head, "after insert_before2");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 111;
tempNode = POBJ_TAILQ_FIRST(head);
POBJ_TAILQ_INSERT_BEFORE(tempNode, node, tnd);
dump_tq(head, "after insert_before3");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 222;
tempNode = POBJ_TAILQ_LAST(head);
POBJ_TAILQ_INSERT_AFTER(tempNode, node, tnd);
dump_tq(head, "after insert_after2");
tempNode = middleNode;
middleNode = POBJ_TAILQ_PREV(tempNode, tnd);
POBJ_TAILQ_MOVE_ELEMENT_TAIL(head, middleNode, tnd);
dump_tq(head, "after move_element_tail");
POBJ_TAILQ_MOVE_ELEMENT_HEAD(head, tempNode, tnd);
dump_tq(head, "after move_element_head");
tempNode = POBJ_TAILQ_FIRST(head);
POBJ_TAILQ_REMOVE(head, tempNode, tnd);
dump_tq(head, "after remove1");
tempNode = POBJ_TAILQ_LAST(head);
POBJ_TAILQ_REMOVE(head, tempNode, tnd);
dump_tq(head, "after remove2");
POBJ_TAILQ_REMOVE(head, node888, tnd);
dump_tq(head, "after remove3");
} TX_ONABORT {
abort();
} TX_END
}
/*
* dump_sl -- dumps list on standard output
*/
static void
dump_sl(struct slisthead *head, const char *str)
{
TOID(struct snode) var;
UT_OUT("%s start", str);
POBJ_SLIST_FOREACH(var, head, snd)
UT_OUT("%d", D_RW(var)->data);
UT_OUT("%s end", str);
}
/*
* init_slist -- initialize SLIST
*/
static void
init_slist(PMEMobjpool *pop, struct slisthead *head)
{
if (!POBJ_SLIST_EMPTY(head))
return;
TOID(struct snode) node;
TOID(struct snode) tempNode;
int i = 0;
TX_BEGIN(pop) {
POBJ_SLIST_INIT(head);
dump_sl(head, "after init");
for (i = 0; i < ELEMENT_NO; ++i) {
node = TX_NEW(struct snode);
D_RW(node)->data = i;
POBJ_SLIST_INSERT_HEAD(head, node, snd);
}
dump_sl(head, "after insert_head");
tempNode = POBJ_SLIST_FIRST(head);
node = TX_NEW(struct snode);
D_RW(node)->data = 111;
POBJ_SLIST_INSERT_AFTER(tempNode, node, snd);
dump_sl(head, "after insert_after1");
tempNode = POBJ_SLIST_NEXT(node, snd);
node = TX_NEW(struct snode);
D_RW(node)->data = 222;
POBJ_SLIST_INSERT_AFTER(tempNode, node, snd);
dump_sl(head, "after insert_after2");
tempNode = POBJ_SLIST_NEXT(node, snd);
POBJ_SLIST_REMOVE_FREE(head, tempNode, snd);
dump_sl(head, "after remove_free1");
POBJ_SLIST_REMOVE_HEAD(head, snd);
dump_sl(head, "after remove_head");
TOID(struct snode) element = POBJ_SLIST_FIRST(head);
while (!TOID_IS_NULL(D_RO(element)->snd.pe_next)) {
element = D_RO(element)->snd.pe_next;
}
node = TX_NEW(struct snode);
D_RW(node)->data = 333;
POBJ_SLIST_INSERT_AFTER(element, node, snd);
dump_sl(head, "after insert_after3");
element = node;
node = TX_NEW(struct snode);
D_RW(node)->data = 123;
POBJ_SLIST_INSERT_AFTER(element, node, snd);
dump_sl(head, "after insert_after4");
tempNode = POBJ_SLIST_NEXT(node, snd);
POBJ_SLIST_REMOVE_FREE(head, node, snd);
dump_sl(head, "after remove_free2");
} TX_ONABORT {
abort();
} TX_END
}
int
main(int argc, char *argv[])
{
unsigned res = 0;
PMEMobjpool *pop;
const char *path;
START(argc, argv, "ex_linkedlist");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(list) != 4);
if (argc != 2) {
UT_FATAL("usage: %s file-name", argv[0]);
}
path = argv[1];
if (os_access(path, F_OK) != 0) {
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(list),
PMEMOBJ_MIN_POOL, 0666)) == NULL) {
UT_FATAL("!pmemobj_create: %s", path);
}
} else {
if ((pop = pmemobj_open(path,
POBJ_LAYOUT_NAME(list))) == NULL) {
UT_FATAL("!pmemobj_open: %s", path);
}
}
TOID(struct base) base = POBJ_ROOT(pop, struct base);
struct tqueuehead *tqhead = &D_RW(base)->tqueue;
struct slisthead *slhead = &D_RW(base)->slist;
init_tqueue(pop, tqhead);
init_slist(pop, slhead);
int i = 0;
TOID(struct tqnode) tqelement;
POBJ_TAILQ_FOREACH(tqelement, tqhead, tnd) {
if (D_RO(tqelement)->data != expectedResTQ[i]) {
res = 1;
break;
}
i++;
}
PRINT_RES(res, tail queue);
i = 0;
res = 0;
TOID(struct snode) slelement;
POBJ_SLIST_FOREACH(slelement, slhead, snd) {
if (D_RO(slelement)->data != expectedResSL[i]) {
res = 1;
break;
}
i++;
}
PRINT_RES(res, singly linked list);
pmemobj_close(pop);
DONE(NULL);
}
| 8,434 | 25.442006 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_persist_count/mocks_windows.h | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of pmem functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_persist_count test.
* It would replace default implementation with mocked functions defined
* in obj_persist_count.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define pmem_persist __wrap_pmem_persist
#define pmem_flush __wrap_pmem_flush
#define pmem_drain __wrap_pmem_drain
#define pmem_msync __wrap_pmem_msync
#define pmem_memcpy_persist __wrap_pmem_memcpy_persist
#define pmem_memcpy_nodrain __wrap_pmem_memcpy_nodrain
#define pmem_memcpy __wrap_pmem_memcpy
#define pmem_memmove_persist __wrap_pmem_memmove_persist
#define pmem_memmove_nodrain __wrap_pmem_memmove_nodrain
#define pmem_memmove __wrap_pmem_memmove
#define pmem_memset_persist __wrap_pmem_memset_persist
#define pmem_memset_nodrain __wrap_pmem_memset_nodrain
#define pmem_memset __wrap_pmem_memset
#endif
| 2,645 | 42.377049 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_persist_count/obj_persist_count.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_persist_count.c -- counting number of persists
*/
#define _GNU_SOURCE
#include "obj.h"
#include "pmalloc.h"
#include "unittest.h"
struct ops_counter {
unsigned n_cl_stores;
unsigned n_drain;
unsigned n_pmem_persist;
unsigned n_pmem_msync;
unsigned n_pmem_flush;
unsigned n_pmem_drain;
unsigned n_flush_from_pmem_memcpy;
unsigned n_flush_from_pmem_memset;
unsigned n_drain_from_pmem_memcpy;
unsigned n_drain_from_pmem_memset;
unsigned n_pot_cache_misses;
};
static struct ops_counter ops_counter;
static struct ops_counter tx_counter;
#define FLUSH_ALIGN ((uintptr_t)64)
#define MOVNT_THRESHOLD 256
static unsigned
cl_flushed(const void *addr, size_t len, uintptr_t alignment)
{
uintptr_t start = (uintptr_t)addr & ~(alignment - 1);
uintptr_t end = ((uintptr_t)addr + len + alignment - 1) &
~(alignment - 1);
return (unsigned)(end - start) / FLUSH_ALIGN;
}
#define PMEM_F_MEM_MOVNT (PMEM_F_MEM_WC | PMEM_F_MEM_NONTEMPORAL)
#define PMEM_F_MEM_MOV (PMEM_F_MEM_WB | PMEM_F_MEM_TEMPORAL)
static unsigned
bulk_cl_changed(const void *addr, size_t len, unsigned flags)
{
uintptr_t start = (uintptr_t)addr & ~(FLUSH_ALIGN - 1);
uintptr_t end = ((uintptr_t)addr + len + FLUSH_ALIGN - 1) &
~(FLUSH_ALIGN - 1);
unsigned cl_changed = (unsigned)(end - start) / FLUSH_ALIGN;
int wc; /* write combining */
if (flags & PMEM_F_MEM_NOFLUSH)
wc = 0; /* NOFLUSH always uses temporal instructions */
else if (flags & PMEM_F_MEM_MOVNT)
wc = 1;
else if (flags & PMEM_F_MEM_MOV)
wc = 0;
else if (len < MOVNT_THRESHOLD)
wc = 0;
else
wc = 1;
/* count number of potential cache misses */
if (!wc) {
/*
* When we don't use write combining, it means all
* cache lines may be missing.
*/
ops_counter.n_pot_cache_misses += cl_changed;
} else {
/*
* When we use write combining there won't be any cache misses,
* with an exception of unaligned beginning or end.
*/
if (start != (uintptr_t)addr)
ops_counter.n_pot_cache_misses++;
if (end != ((uintptr_t)addr + len) &&
start + FLUSH_ALIGN != end)
ops_counter.n_pot_cache_misses++;
}
return cl_changed;
}
static void
flush_cl(const void *addr, size_t len)
{
unsigned flushed = cl_flushed(addr, len, FLUSH_ALIGN);
ops_counter.n_cl_stores += flushed;
ops_counter.n_pot_cache_misses += flushed;
}
static void
flush_msync(const void *addr, size_t len)
{
unsigned flushed = cl_flushed(addr, len, Pagesize);
ops_counter.n_cl_stores += flushed;
ops_counter.n_pot_cache_misses += flushed;
}
FUNC_MOCK(pmem_persist, void, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_persist++;
flush_cl(addr, len);
ops_counter.n_drain++;
_FUNC_REAL(pmem_persist)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_msync, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_msync++;
flush_msync(addr, len);
ops_counter.n_drain++;
return _FUNC_REAL(pmem_msync)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_flush, void, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_flush++;
flush_cl(addr, len);
_FUNC_REAL(pmem_flush)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_drain, void, void)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_drain++;
ops_counter.n_drain++;
_FUNC_REAL(pmem_drain)();
}
FUNC_MOCK_END
static void
memcpy_nodrain_count(void *dest, const void *src, size_t len, unsigned flags)
{
unsigned cl_stores = bulk_cl_changed(dest, len, flags);
if (!(flags & PMEM_F_MEM_NOFLUSH))
ops_counter.n_flush_from_pmem_memcpy += cl_stores;
ops_counter.n_cl_stores += cl_stores;
}
static void
memcpy_persist_count(void *dest, const void *src, size_t len, unsigned flags)
{
memcpy_nodrain_count(dest, src, len, flags);
ops_counter.n_drain_from_pmem_memcpy++;
ops_counter.n_drain++;
}
FUNC_MOCK(pmem_memcpy_persist, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_persist_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memcpy_persist)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memcpy_nodrain, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_nodrain_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memcpy_nodrain)(dest, src, len);
}
FUNC_MOCK_END
static unsigned
sanitize_flags(unsigned flags)
{
if (flags & PMEM_F_MEM_NOFLUSH) {
/* NOFLUSH implies NODRAIN */
flags |= PMEM_F_MEM_NODRAIN;
}
return flags;
}
FUNC_MOCK(pmem_memcpy, void *, void *dest, const void *src, size_t len,
unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memcpy_nodrain_count(dest, src, len, flags);
else
memcpy_persist_count(dest, src, len, flags);
return _FUNC_REAL(pmem_memcpy)(dest, src, len, flags);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove_persist, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_persist_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memmove_persist)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove_nodrain, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_nodrain_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memmove_nodrain)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove, void *, void *dest, const void *src, size_t len,
unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memcpy_nodrain_count(dest, src, len, flags);
else
memcpy_persist_count(dest, src, len, flags);
return _FUNC_REAL(pmem_memmove)(dest, src, len, flags);
}
FUNC_MOCK_END
static void
memset_nodrain_count(void *dest, size_t len, unsigned flags)
{
unsigned cl_set = bulk_cl_changed(dest, len, flags);
if (!(flags & PMEM_F_MEM_NOFLUSH))
ops_counter.n_flush_from_pmem_memset += cl_set;
ops_counter.n_cl_stores += cl_set;
}
static void
memset_persist_count(void *dest, size_t len, unsigned flags)
{
memset_nodrain_count(dest, len, flags);
ops_counter.n_drain_from_pmem_memset++;
ops_counter.n_drain++;
}
FUNC_MOCK(pmem_memset_persist, void *, void *dest, int c, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memset_persist_count(dest, len, 0);
return _FUNC_REAL(pmem_memset_persist)(dest, c, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memset_nodrain, void *, void *dest, int c, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memset_nodrain_count(dest, len, 0);
return _FUNC_REAL(pmem_memset_nodrain)(dest, c, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memset, void *, void *dest, int c, size_t len, unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memset_nodrain_count(dest, len, flags);
else
memset_persist_count(dest, len, flags);
return _FUNC_REAL(pmem_memset)(dest, c, len, flags);
}
FUNC_MOCK_END
/*
* reset_counters -- zero all counters
*/
static void
reset_counters(void)
{
memset(&ops_counter, 0, sizeof(ops_counter));
}
/*
* print_reset_counters -- print and then zero all counters
*/
static void
print_reset_counters(const char *task, unsigned tx)
{
#define CNT(name) (ops_counter.name - tx * tx_counter.name)
UT_OUT(
"%-14s %-7d %-10d %-12d %-10d %-10d %-10d %-15d %-17d %-15d %-17d %-23d",
task,
CNT(n_cl_stores),
CNT(n_drain),
CNT(n_pmem_persist),
CNT(n_pmem_msync),
CNT(n_pmem_flush),
CNT(n_pmem_drain),
CNT(n_flush_from_pmem_memcpy),
CNT(n_drain_from_pmem_memcpy),
CNT(n_flush_from_pmem_memset),
CNT(n_drain_from_pmem_memset),
CNT(n_pot_cache_misses));
#undef CNT
reset_counters();
}
#define LARGE_SNAPSHOT ((1 << 10) * 10)
struct foo_large {
uint8_t snapshot[LARGE_SNAPSHOT];
};
struct foo {
int val;
uint64_t dest;
PMEMoid bar;
PMEMoid bar2;
};
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_persist_count");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, "persist_count",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
UT_OUT(
"%-14s %-7s %-10s %-12s %-10s %-10s %-10s %-15s %-17s %-15s %-17s %-23s",
"task",
"cl(all)",
"drain(all)",
"pmem_persist",
"pmem_msync",
"pmem_flush",
"pmem_drain",
"pmem_memcpy_cls",
"pmem_memcpy_drain",
"pmem_memset_cls",
"pmem_memset_drain",
"potential_cache_misses");
print_reset_counters("pool_create", 0);
/* allocate one structure to create a run */
pmemobj_alloc(pop, NULL, sizeof(struct foo), 0, NULL, NULL);
reset_counters();
PMEMoid root = pmemobj_root(pop, sizeof(struct foo));
UT_ASSERT(!OID_IS_NULL(root));
print_reset_counters("root_alloc", 0);
PMEMoid oid;
int ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
print_reset_counters("atomic_alloc", 0);
pmemobj_free(&oid);
print_reset_counters("atomic_free", 0);
struct foo *f = pmemobj_direct(root);
TX_BEGIN(pop) {
} TX_END
memcpy(&tx_counter, &ops_counter, sizeof(ops_counter));
print_reset_counters("tx_begin_end", 0);
TX_BEGIN(pop) {
f->bar = pmemobj_tx_alloc(sizeof(struct foo), 0);
UT_ASSERT(!OID_IS_NULL(f->bar));
} TX_END
print_reset_counters("tx_alloc", 1);
TX_BEGIN(pop) {
f->bar2 = pmemobj_tx_alloc(sizeof(struct foo), 0);
UT_ASSERT(!OID_IS_NULL(f->bar2));
} TX_END
print_reset_counters("tx_alloc_next", 1);
TX_BEGIN(pop) {
pmemobj_tx_free(f->bar);
} TX_END
print_reset_counters("tx_free", 1);
TX_BEGIN(pop) {
pmemobj_tx_free(f->bar2);
} TX_END
print_reset_counters("tx_free_next", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&f->val, sizeof(f->val),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&f->val, sizeof(f->val),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_next", 1);
PMEMoid large_foo;
pmemobj_alloc(pop, &large_foo, sizeof(struct foo_large), 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(large_foo));
reset_counters();
struct foo_large *flarge = pmemobj_direct(large_foo);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&flarge->snapshot,
sizeof(flarge->snapshot),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_large", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&flarge->snapshot,
sizeof(flarge->snapshot),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_lnext", 1);
pmalloc(pop, &f->dest, sizeof(f->val), 0, 0);
print_reset_counters("pmalloc", 0);
pfree(pop, &f->dest);
print_reset_counters("pfree", 0);
uint64_t stack_var;
pmalloc(pop, &stack_var, sizeof(f->val), 0, 0);
print_reset_counters("pmalloc_stack", 0);
pfree(pop, &stack_var);
print_reset_counters("pfree_stack", 0);
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 12,490 | 24.439919 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_proto/rpmem_proto.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_proto.c -- unit test for rpmem_proto header
*
* The purpose of this test is to make sure the structures which describe
* rpmem protocol messages does not have any padding.
*/
#include "unittest.h"
#include "librpmem.h"
#include "rpmem_proto.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmem_proto");
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr, type);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_hdr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_hdr_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, status);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, type);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_hdr_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_pool_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, signature);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, major);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, incompat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, ro_compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, poolset_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, next_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, prev_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, user_flags);
ASSERT_ALIGNED_CHECK(struct rpmem_pool_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_pool_attr_packed);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, signature);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, major);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, incompat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, ro_compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, poolset_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, next_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, prev_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, user_flags);
ASSERT_ALIGNED_CHECK(struct rpmem_pool_attr_packed);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_ibc_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, port);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, persist_method);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, rkey);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, raddr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, nlanes);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_ibc_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_common);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, major);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, minor);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, pool_size);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, nlanes);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, provider);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, buff_size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_common);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_pool_desc);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_pool_desc, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_pool_desc);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_create);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, c);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, pool_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, pool_desc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_create);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_create_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create_resp, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create_resp, ibc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_create_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_open);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, c);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, pool_desc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_open);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_open_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, ibc);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, pool_attr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_open_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_close);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close, flags);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_close);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_close_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close_resp, hdr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_close_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_persist);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, flags);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, lane);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, addr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_persist);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_persist_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist_resp, flags);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist_resp, lane);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_persist_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_set_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr, pool_attr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_set_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_set_attr_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr_resp, hdr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_set_attr_resp);
DONE(NULL);
}
| 7,248 | 43.20122 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/signal_handle/signal_handle.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* signal_handle.c -- unit test for signal_handle
*
*
* operations are: 's', 'a', 'a', 'i', 'v'
* s: testing SIGSEGV with signal_handler_2
* a: testing SIGABRT with signal_handler_1
* a: testing second occurrence of SIGABRT with signal_handler_1
* i: testing SIGILL with signal_handler_2
* v: testing third occurrence of SIGABRT with other signal_handler_3
*
*/
#include "unittest.h"
ut_jmp_buf_t Jmp;
static void
signal_handler_1(int sig)
{
UT_OUT("\tsignal_handler_1: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
static void
signal_handler_2(int sig)
{
UT_OUT("\tsignal_handler_2: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
static void
signal_handler_3(int sig)
{
UT_OUT("\tsignal_handler_3: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "signal_handle");
if (argc < 2)
UT_FATAL("usage: %s op:s|a|a|i|v", argv[0]);
struct sigaction v1, v2, v3;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
v1.sa_handler = signal_handler_1;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
v2.sa_handler = signal_handler_2;
SIGACTION(SIGSEGV, &v2, NULL);
SIGACTION(SIGABRT, &v1, NULL);
SIGACTION(SIGABRT, &v2, NULL);
SIGACTION(SIGABRT, &v1, NULL);
SIGACTION(SIGILL, &v2, NULL);
for (int arg = 1; arg < argc; arg++) {
if (strchr("sabiv", argv[arg][0]) == NULL ||
argv[arg][1] != '\0')
UT_FATAL("op must be one of: s, a, a, i, v");
switch (argv[arg][0]) {
case 's':
UT_OUT("Testing SIGSEGV...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGSEGV)) {
UT_OUT("\t SIGSEGV occurrence");
} else {
UT_OUT("\t Issue with SIGSEGV raise");
}
}
break;
case 'a':
UT_OUT("Testing SIGABRT...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGABRT)) {
UT_OUT("\t SIGABRT occurrence");
} else {
UT_OUT("\t Issue with SIGABRT raise");
}
}
break;
case 'i':
UT_OUT("Testing SIGILL...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGILL)) {
UT_OUT("\t SIGILL occurrence");
} else {
UT_OUT("\t Issue with SIGILL raise");
}
}
break;
case 'v':
if (!ut_sigsetjmp(Jmp)) {
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
v3.sa_handler = signal_handler_3;
UT_OUT("Testing SIGABRT...");
SIGACTION(SIGABRT, &v3, NULL);
if (!raise(SIGABRT)) {
UT_OUT("\t SIGABRT occurrence");
} else {
UT_OUT("\t Issue with SIGABRT raise");
}
}
break;
}
}
DONE(NULL);
}
| 4,064 | 25.225806 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_multiple_pools/cto_multiple_pools.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_multiple_pools.c -- unit test for cto_multiple_pools
*
* usage: cto_multiple_pools directory mode npools nthreads
*/
#include "unittest.h"
#define NREPEATS 10
static PMEMctopool **Pools;
static unsigned Npools;
static const char *Dir;
static unsigned *Pool_idx;
static os_thread_t *Threads;
static void *
thread_func_open(void *arg)
{
unsigned start_idx = *(unsigned *)arg;
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
for (int repeat = 0; repeat < NREPEATS; ++repeat) {
for (unsigned idx = 0; idx < Npools; ++idx) {
unsigned pool_id = start_idx + idx;
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
Pools[pool_id] = pmemcto_open(filename, "test");
UT_ASSERTne(Pools[pool_id], NULL);
void *ptr = pmemcto_malloc(Pools[pool_id], sizeof(int));
UT_OUT("pcp %p ptr %p", Pools[pool_id], ptr);
UT_ASSERTne(ptr, NULL);
pmemcto_free(Pools[pool_id], ptr);
pmemcto_close(Pools[pool_id]);
}
}
FREE(filename);
return NULL;
}
static void *
thread_func_create(void *arg)
{
unsigned start_idx = *(unsigned *)arg;
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
for (int repeat = 0; repeat < NREPEATS; ++repeat) {
for (unsigned idx = 0; idx < Npools; ++idx) {
unsigned pool_id = start_idx + idx;
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
/* delete old pool with the same id if exists */
if (Pools[pool_id] != NULL) {
pmemcto_close(Pools[pool_id]);
Pools[pool_id] = NULL;
UNLINK(filename);
}
Pools[pool_id] = pmemcto_create(filename, "test",
PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(Pools[pool_id], NULL);
void *ptr = pmemcto_malloc(Pools[pool_id], sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_free(Pools[pool_id], ptr);
}
}
FREE(filename);
return NULL;
}
static void
test_open(unsigned nthreads)
{
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
/* create all the pools */
for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id) {
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
Pools[pool_id] = pmemcto_create(filename, "test",
PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(Pools[pool_id], NULL);
}
for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id)
pmemcto_close(Pools[pool_id]);
for (unsigned t = 0; t < nthreads; t++) {
Pool_idx[t] = Npools * t;
PTHREAD_CREATE(&Threads[t], NULL, thread_func_open,
&Pool_idx[t]);
}
for (unsigned t = 0; t < nthreads; t++)
PTHREAD_JOIN(&Threads[t], NULL);
FREE(filename);
}
static void
test_create(unsigned nthreads)
{
/* create and destroy pools multiple times */
for (unsigned t = 0; t < nthreads; t++) {
Pool_idx[t] = Npools * t;
PTHREAD_CREATE(&Threads[t], NULL, thread_func_create,
&Pool_idx[t]);
}
for (unsigned t = 0; t < nthreads; t++)
PTHREAD_JOIN(&Threads[t], NULL);
for (unsigned i = 0; i < Npools * nthreads; ++i) {
if (Pools[i] != NULL) {
pmemcto_close(Pools[i]);
Pools[i] = NULL;
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_multiple_pools");
if (argc < 4)
UT_FATAL("usage: %s directory mode npools nthreads", argv[0]);
Dir = argv[1];
char mode = argv[2][0];
Npools = ATOU(argv[3]);
unsigned nthreads = ATOU(argv[4]);
UT_OUT("create %d pools in %d thread(s)", Npools, nthreads);
Pools = CALLOC(Npools * nthreads, sizeof(Pools[0]));
Threads = CALLOC(nthreads, sizeof(Threads[0]));
Pool_idx = CALLOC(nthreads, sizeof(Pool_idx[0]));
switch (mode) {
case 'o':
test_open(nthreads);
break;
case 'c':
test_create(nthreads);
break;
default:
UT_FATAL("unknown mode");
}
FREE(Pools);
FREE(Threads);
FREE(Pool_idx);
DONE(NULL);
}
| 5,600 | 25.545024 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_toid/obj_toid.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_toid.c -- unit test for TOID_VALID, DIRECT_RO, DIRECT_RW macros
*/
#include <sys/param.h>
#include "unittest.h"
#define LAYOUT_NAME "toid"
#define TEST_NUM 5
TOID_DECLARE(struct obj, 0);
struct obj {
int id;
};
/*
* do_toid_valid -- validates if type number is equal to object's metadata
*/
static void
do_toid_valid(PMEMobjpool *pop)
{
TOID(struct obj) obj;
POBJ_NEW(pop, &obj, struct obj, NULL, NULL);
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(TOID_VALID(obj));
POBJ_FREE(&obj);
}
/*
* do_toid_no_valid -- validates if type number is not equal to
* object's metadata
*/
static void
do_toid_no_valid(PMEMobjpool *pop)
{
TOID(struct obj) obj;
int ret = pmemobj_alloc(pop, &obj.oid, sizeof(struct obj), TEST_NUM,
NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERT(!TOID_VALID(obj));
POBJ_FREE(&obj);
}
/*
* do_direct_simple - checks if DIRECT_RW and DIRECT_RO macros correctly
* write and read from member of structure represented by TOID
*/
static void
do_direct_simple(PMEMobjpool *pop)
{
TOID(struct obj) obj;
POBJ_NEW(pop, &obj, struct obj, NULL, NULL);
D_RW(obj)->id = TEST_NUM;
pmemobj_persist(pop, &D_RW(obj)->id, sizeof(D_RW(obj)->id));
UT_ASSERTeq(D_RO(obj)->id, TEST_NUM);
POBJ_FREE(&obj);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_toid");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_toid_valid(pop);
do_toid_no_valid(pop);
do_direct_simple(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 3,231 | 27.857143 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_check/obj_check.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_check.c -- unit tests for pmemobj_check
*/
#include <stddef.h>
#include "unittest.h"
#include "libpmemobj.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_check");
if (argc < 2 || argc > 5)
UT_FATAL("usage: obj_check <file> [-l <layout>] [-o]");
const char *path = argv[1];
const char *layout = NULL;
PMEMobjpool *pop = NULL;
int open = 0;
for (int i = 2; i < argc; ++i) {
if (strcmp(argv[i], "-o") == 0)
open = 1;
else if (strcmp(argv[i], "-l") == 0) {
layout = argv[i + 1];
i++;
} else
UT_FATAL("Unrecognized argument: %s", argv[i]);
}
if (open) {
pop = pmemobj_open(path, layout);
if (pop == NULL)
UT_OUT("!%s: pmemobj_open", path);
else
UT_OUT("%s: pmemobj_open: Success", path);
}
int ret = pmemobj_check(path, layout);
switch (ret) {
case 1:
UT_OUT("consistent");
break;
case 0:
UT_OUT("not consistent: %s", pmemobj_errormsg());
break;
default:
UT_OUT("error: %s", pmemobj_errormsg());
break;
}
if (pop != NULL)
pmemobj_close(pop);
DONE(NULL);
}
| 2,651 | 28.142857 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/compat_incompat_features/pool_open.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pool_open.c -- a tool for verifying that an obj/blk/log pool opens correctly
*
* usage: pool_open <path> <obj|blk|log> <layout>
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "compat_incompat_features");
if (argc < 3)
UT_FATAL("usage: %s <obj|blk|log|cto> <path>", argv[0]);
char *type = argv[1];
char *path = argv[2];
if (strcmp(type, "obj") == 0) {
PMEMobjpool *pop = pmemobj_open(path, "");
if (pop == NULL) {
UT_FATAL("!%s: pmemobj_open failed", path);
} else {
UT_OUT("%s: pmemobj_open succeeded", path);
pmemobj_close(pop);
}
} else if (strcmp(type, "blk") == 0) {
PMEMblkpool *pop = pmemblk_open(path, 0);
if (pop == NULL) {
UT_FATAL("!%s: pmemblk_open failed", path);
} else {
UT_OUT("%s: pmemblk_open succeeded", path);
pmemblk_close(pop);
}
} else if (strcmp(type, "log") == 0) {
PMEMlogpool *pop = pmemlog_open(path);
if (pop == NULL) {
UT_FATAL("!%s: pmemlog_open failed", path);
} else {
UT_OUT("%s: pmemlog_open succeeded", path);
pmemlog_close(pop);
}
} else if (strcmp(type, "cto") == 0) {
PMEMctopool *pop = pmemcto_open(path, "");
if (pop == NULL) {
UT_FATAL("!%s: pmemcto_open failed", path);
} else {
UT_OUT("%s: pmemcto_open succeeded", path);
pmemcto_close(pop);
}
} else {
UT_FATAL("usage: %s <obj|blk|log|cto> <path>", argv[0]);
}
DONE(NULL);
}
| 2,998 | 33.079545 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset/mocks_windows.h | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of libc functions used in util_poolset
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of util_poolset test.
* It would replace default implementation with mocked functions defined
* in util_poolset.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL_OPEN
#define os_open __wrap_os_open
#endif
#ifndef WRAP_REAL_FALLOCATE
#define os_posix_fallocate __wrap_os_posix_fallocate
#endif
#ifndef WRAP_REAL_PMEM
#define pmem_is_pmem __wrap_pmem_is_pmem
#endif
| 2,245 | 38.403509 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset/util_poolset.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_poolset.c -- unit test for util_pool_create() / util_pool_open()
*
* usage: util_poolset cmd minlen hdrsize [mockopts] setfile ...
*/
#include <stdbool.h>
#include "unittest.h"
#include "pmemcommon.h"
#include "set.h"
#include <errno.h>
#include "mocks.h"
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define SIG "PMEMXXX"
#define MIN_PART ((size_t)(1024 * 1024 * 2)) /* 2 MiB */
#define TEST_FORMAT_INCOMPAT_DEFAULT POOL_FEAT_CKSUM_2K
#define TEST_FORMAT_INCOMPAT_CHECK POOL_FEAT_INCOMPAT_VALID
static size_t Extend_size = MIN_PART * 2;
const char *Open_path = "";
os_off_t Fallocate_len = -1;
size_t Is_pmem_len = 0;
/*
* poolset_info -- (internal) dumps poolset info and checks its integrity
*
* Performs the following checks:
* - part_size[i] == rounddown(file_size - pool_hdr_size, Mmap_align)
* - replica_size == sum(part_size)
* - pool_size == min(replica_size)
*/
static void
poolset_info(const char *fname, struct pool_set *set, int o)
{
if (o)
UT_OUT("%s: opened: nreps %d poolsize %zu rdonly %d",
fname, set->nreplicas, set->poolsize,
set->rdonly);
else
UT_OUT("%s: created: nreps %d poolsize %zu zeroed %d",
fname, set->nreplicas, set->poolsize,
set->zeroed);
size_t poolsize = SIZE_MAX;
for (unsigned r = 0; r < set->nreplicas; r++) {
struct pool_replica *rep = set->replica[r];
size_t repsize = 0;
UT_OUT(" replica[%d]: nparts %d nhdrs %d repsize %zu "
"is_pmem %d",
r, rep->nparts, rep->nhdrs, rep->repsize, rep->is_pmem);
for (unsigned i = 0; i < rep->nparts; i++) {
struct pool_set_part *part = &rep->part[i];
UT_OUT(" part[%d] path %s filesize %zu size %zu",
i, part->path, part->filesize, part->size);
size_t partsize =
(part->filesize & ~(Ut_mmap_align - 1));
repsize += partsize;
if (i > 0 && (set->options & OPTION_SINGLEHDR) == 0)
UT_ASSERTeq(part->size,
partsize - Ut_mmap_align); /* XXX */
}
repsize -= (rep->nhdrs - 1) * Ut_mmap_align;
UT_ASSERTeq(rep->repsize, repsize);
UT_ASSERT(rep->resvsize >= repsize);
if (rep->repsize < poolsize)
poolsize = rep->repsize;
}
UT_ASSERTeq(set->poolsize, poolsize);
}
/*
* mock_options -- (internal) parse mock options and enable mocked functions
*/
static int
mock_options(const char *arg)
{
/* reset to defaults */
Open_path = "";
Fallocate_len = -1;
Is_pmem_len = 0;
if (arg[0] != '-' || arg[1] != 'm')
return 0;
switch (arg[2]) {
case 'n':
/* do nothing */
break;
case 'o':
/* open */
Open_path = &arg[4];
break;
case 'f':
/* fallocate */
Fallocate_len = ATOLL(&arg[4]);
break;
case 'p':
/* is_pmem */
Is_pmem_len = ATOULL(&arg[4]);
break;
default:
UT_FATAL("unknown mock option: %c", arg[2]);
}
return 1;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_poolset");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 3)
UT_FATAL("usage: %s cmd minsize [mockopts] "
"setfile ...", argv[0]);
char *fname;
struct pool_set *set;
int ret;
size_t minsize = strtoul(argv[2], &fname, 0);
for (int arg = 3; arg < argc; arg++) {
arg += mock_options(argv[arg]);
fname = argv[arg];
struct pool_attr attr;
memset(&attr, 0, sizeof(attr));
memcpy(attr.signature, SIG, sizeof(SIG));
attr.major = 1;
switch (argv[1][0]) {
case 'c':
attr.features.incompat = TEST_FORMAT_INCOMPAT_DEFAULT;
ret = util_pool_create(&set, fname, 0, minsize,
MIN_PART, &attr, NULL, REPLICAS_ENABLED);
if (ret == -1)
UT_OUT("!%s: util_pool_create", fname);
else {
/*
* XXX: On Windows pool files are created with
* R/W permissions, so no need for chmod().
*/
#ifndef _WIN32
util_poolset_chmod(set, S_IWUSR | S_IRUSR);
#endif
poolset_info(fname, set, 0);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
break;
case 'o':
attr.features.incompat = TEST_FORMAT_INCOMPAT_CHECK;
ret = util_pool_open(&set, fname, MIN_PART, &attr,
NULL, NULL, 0 /* flags */);
if (ret == -1)
UT_OUT("!%s: util_pool_open", fname);
else {
poolset_info(fname, set, 1);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
break;
case 'e':
attr.features.incompat = TEST_FORMAT_INCOMPAT_CHECK;
ret = util_pool_open(&set, fname, MIN_PART, &attr,
NULL, NULL, 0 /* flags */);
UT_ASSERTeq(ret, 0);
size_t esize = Extend_size;
void *nptr = util_pool_extend(set, &esize, MIN_PART);
if (nptr == NULL)
UT_OUT("!%s: util_pool_extend", fname);
else {
poolset_info(fname, set, 1);
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
break;
}
}
common_fini();
DONE(NULL);
}
| 6,359 | 26.772926 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset/mocks.h | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MOCKS_H
#define MOCKS_H
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
#endif
| 1,731 | 41.243902 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset/mocks_windows.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in util_poolset.c
*/
#include "pmem.h"
#include "util.h"
#include "unittest.h"
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
/*
* os_open -- open mock
*
* due to diffrences in function mocking on linux we are wraping os_open
* but on linux we just wrap open syscall
*/
FUNC_MOCK(os_open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
if (strcmp(Open_path, path) == 0) {
UT_OUT("mocked open: %s", path);
errno = EACCES;
return -1;
}
va_list ap;
va_start(ap, flags);
int mode = va_arg(ap, int);
va_end(ap);
return _FUNC_REAL(os_open)(path, flags, mode);
}
FUNC_MOCK_END
/*
* posix_fallocate -- posix_fallocate mock
*/
FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Fallocate_len == len) {
UT_OUT("mocked fallocate: %ju", len);
return ENOSPC;
}
return _FUNC_REAL(os_posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* pmem_is_pmem -- pmem_is_pmem mock
*/
FUNC_MOCK(pmem_is_pmem, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Is_pmem_len == len) {
UT_OUT("mocked pmem_is_pmem: %zu", len);
return 1;
}
return _FUNC_REAL(pmem_is_pmem)(addr, len);
}
FUNC_MOCK_END
/*
* On Windows libpmem is statically linked to util_poolset test, but we
* don't want its ctor to initialize 'out' module.
*/
/*
* libpmem_init -- load-time initialization for libpmem
*
* Called automatically by the run-time loader.
*/
CONSTRUCTOR(libpmem_init)
void
libpmem_init(void)
{
pmem_init();
}
| 3,200 | 27.837838 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset/mocks_posix.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_posix.c -- mocked functions used in util_poolset.c (Posix version)
*/
#include "unittest.h"
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
/*
* open -- open mock
*/
FUNC_MOCK(open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
if (strcmp(Open_path, path) == 0) {
UT_OUT("mocked open: %s", path);
errno = EACCES;
return -1;
}
va_list ap;
va_start(ap, flags);
int mode = va_arg(ap, int);
va_end(ap);
return _FUNC_REAL(open)(path, flags, mode);
}
FUNC_MOCK_END
/*
* posix_fallocate -- posix_fallocate mock
*/
FUNC_MOCK(posix_fallocate, int, int fd, os_off_t offset, off_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Fallocate_len == len) {
UT_OUT("mocked fallocate: %ju", len);
return ENOSPC;
}
return _FUNC_REAL(posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* pmem_is_pmem -- pmem_is_pmem mock
*/
FUNC_MOCK(pmem_is_pmem, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Is_pmem_len == len) {
UT_OUT("mocked pmem_is_pmem: %zu", len);
return 1;
}
return _FUNC_REAL(pmem_is_pmem)(addr, len);
}
FUNC_MOCK_END
| 2,727 | 30 | 75 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_include/cto_include.c | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log_include.c -- include test for libpmemlog
*
* this is only a compilation test - do not run this program
*/
#include <libpmemlog.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,795 | 38.043478 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_realloc_inplace/cto_realloc_inplace.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_realloc_inplace -- unit test for pmemcto_realloc
*
* usage: cto_realloc_inplace filename
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_realloc_inplace");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
PMEMCTO_MIN_POOL, 0666);
UT_ASSERTne(pcp, NULL);
int *test1 = pmemcto_malloc(pcp, 12 * 1024 * 1024);
UT_ASSERTne(test1, NULL);
int *test1r = pmemcto_realloc(pcp, test1, 6 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = pmemcto_realloc(pcp, test1, 12 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = pmemcto_realloc(pcp, test1, 8 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
int *test2 = pmemcto_malloc(pcp, 4 * 1024 * 1024);
UT_ASSERTne(test2, NULL);
/* 4MB => 16B */
int *test2r = pmemcto_realloc(pcp, test2, 16);
UT_ASSERTeq(test2r, NULL);
/* ... but the usable size is still 4MB. */
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, test2), 4 * 1024 * 1024);
/* 8MB => 16B */
test1r = pmemcto_realloc(pcp, test1, 16);
/*
* If the old size of the allocation is larger than
* the chunk size (4MB), we can reallocate it to 4MB first (in place),
* releasing some space, which makes it possible to do the actual
* shrinking...
*/
UT_ASSERTne(test1r, NULL);
UT_ASSERTne(test1r, test1);
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, test1r), 16);
/* ... and leaves some memory for new allocations. */
int *test3 = pmemcto_malloc(pcp, 3 * 1024 * 1024);
UT_ASSERTne(test3, NULL);
pmemcto_free(pcp, test1r);
pmemcto_free(pcp, test2r);
pmemcto_free(pcp, test3);
pmemcto_close(pcp);
DONE(NULL);
}
| 3,265 | 31.989899 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/out_err_win/out_err_win.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out_err_win.c -- unit test for error messages
*/
#define LOG_PREFIX "trace"
#define LOG_LEVEL_VAR "TRACE_LOG_LEVEL"
#define LOG_FILE_VAR "TRACE_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#include <sys/types.h>
#include <stdarg.h>
#include "unittest.h"
#include "pmemcommon.h"
int
wmain(int argc, wchar_t *argv[])
{
char buff[UT_MAX_ERR_MSG];
STARTW(argc, argv, "out_err_win");
/* Execute test */
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
errno = 0;
ERR("ERR #%d", 1);
UT_OUT("%S", out_get_errormsgW());
errno = 0;
ERR("!ERR #%d", 2);
UT_OUT("%S", out_get_errormsgW());
errno = EINVAL;
ERR("!ERR #%d", 3);
UT_OUT("%S", out_get_errormsgW());
errno = EBADF;
ut_strerror(errno, buff, UT_MAX_ERR_MSG);
out_err(__FILE__, 100, __func__,
"ERR1: %s:%d", buff, 1234);
UT_OUT("%S", out_get_errormsgW());
errno = EBADF;
ut_strerror(errno, buff, UT_MAX_ERR_MSG);
out_err(NULL, 0, NULL,
"ERR2: %s:%d", buff, 1234);
UT_OUT("%S", out_get_errormsgW());
/* Cleanup */
common_fini();
DONEW(NULL);
}
| 2,689 | 29.568182 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_realloc/vmmalloc_realloc.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_realloc -- unit test for libvmmalloc realloc
*
* usage: vmmalloc_realloc
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
START(argc, argv, "vmmalloc_realloc");
int *test = realloc(NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = test_value;
UT_ASSERTeq(test[0], test_value);
test = realloc(test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], test_value);
test[1] = test_value;
test[9] = test_value;
free(test);
DONE(NULL);
}
| 2,134 | 32.359375 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_include/pmem_include.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_include.c -- include test for libpmem
*
* this is only a compilation test - do not run this program
*/
#include <libpmem.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,786 | 37.021277 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_memset/pmem_memset.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_memset.c -- unit test for doing a memset
*
* usage: pmem_memset file offset length
*/
#include "unittest.h"
#include "util_pmem.h"
#include "file.h"
typedef void *pmem_memset_fn(void *pmemdest, int c, size_t len, unsigned flags);
static void *
pmem_memset_persist_wrapper(void *pmemdest, int c, size_t len, unsigned flags)
{
(void) flags;
return pmem_memset_persist(pmemdest, c, len);
}
static void *
pmem_memset_nodrain_wrapper(void *pmemdest, int c, size_t len, unsigned flags)
{
(void) flags;
return pmem_memset_nodrain(pmemdest, c, len);
}
static void
do_memset(int fd, char *dest, const char *file_name, size_t dest_off,
size_t bytes, pmem_memset_fn fn, unsigned flags)
{
char *buf = MALLOC(bytes);
char *dest1;
char *ret;
enum file_type type = util_fd_get_type(fd);
if (type < 0)
UT_FATAL("cannot check type of file with fd %d", fd);
memset(dest, 0, bytes);
util_persist_auto(type == TYPE_DEVDAX, dest, bytes);
dest1 = MALLOC(bytes);
memset(dest1, 0, bytes);
/*
* This is used to verify that the value of what a non persistent
* memset matches the outcome of the persistent memset. The
* persistent memset will match the file but may not be the
* correct or expected value.
*/
memset(dest1 + dest_off, 0x5A, bytes / 4);
memset(dest1 + dest_off + (bytes / 4), 0x46, bytes / 4);
/* Test the corner cases */
ret = fn(dest + dest_off, 0x5A, 0, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
/*
* Do the actual memset with persistence.
*/
ret = fn(dest + dest_off, 0x5A, bytes / 4, flags);
UT_ASSERTeq(ret, dest + dest_off);
ret = fn(dest + dest_off + (bytes / 4), 0x46, bytes / 4, flags);
UT_ASSERTeq(ret, dest + dest_off + (bytes / 4));
if (memcmp(dest, dest1, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
LSEEK(fd, 0, SEEK_SET);
if (READ(fd, buf, bytes / 2) == bytes / 2) {
if (memcmp(buf, dest, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
}
FREE(dest1);
FREE(buf);
}
static unsigned Flags[] = {
0,
PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_NONTEMPORAL,
PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_WC,
PMEM_F_MEM_WB,
PMEM_F_MEM_NOFLUSH,
/* all possible flags */
PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH |
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL |
PMEM_F_MEM_WC | PMEM_F_MEM_WB,
};
static void
do_memset_variants(int fd, char *dest, const char *file_name, size_t dest_off,
size_t bytes)
{
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset_persist_wrapper, 0);
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset, Flags[i]);
if (Flags[i] & PMEMOBJ_F_MEM_NOFLUSH)
pmem_persist(dest, bytes);
}
}
int
main(int argc, char *argv[])
{
int fd;
size_t mapped_len;
char *dest;
if (argc != 4)
UT_FATAL("usage: %s file offset length", argv[0]);
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_memset %s %s %s %savx %savx512f",
argv[2], argv[3],
thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
fd = OPEN(argv[1], O_RDWR);
/* open a pmem file and memory map it */
if ((dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL)) == NULL)
UT_FATAL("!Could not mmap %s\n", argv[1]);
size_t dest_off = strtoul(argv[2], NULL, 0);
size_t bytes = strtoul(argv[3], NULL, 0);
do_memset_variants(fd, dest, argv[1], dest_off, bytes);
UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);
CLOSE(fd);
DONE(NULL);
}
| 5,428 | 28.505435 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pool_win/obj_pool_win.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pool.c -- unit test for pmemobj_create() and pmemobj_open()
*
* usage: obj_pool op path layout [poolsize mode]
*
* op can be:
* c - create
* o - open
*
* "poolsize" and "mode" arguments are ignored for "open"
*/
#include "unittest.h"
#define MB ((size_t)1 << 20)
static void
pool_create(const wchar_t *path, const wchar_t *layout, size_t poolsize,
unsigned mode)
{
char *upath = ut_toUTF8(path);
PMEMobjpool *pop = pmemobj_createW(path, layout, poolsize, mode);
if (pop == NULL)
UT_OUT("!%s: pmemobj_create", upath);
else {
os_stat_t stbuf;
STATW(path, &stbuf);
UT_OUT("%s: file size %zu mode 0%o",
upath, stbuf.st_size,
stbuf.st_mode & 0777);
pmemobj_close(pop);
int result = pmemobj_checkW(path, layout);
if (result < 0)
UT_OUT("!%s: pmemobj_check", upath);
else if (result == 0)
UT_OUT("%s: pmemobj_check: not consistent", upath);
}
free(upath);
}
static void
pool_open(const wchar_t *path, const wchar_t *layout)
{
char *upath = ut_toUTF8(path);
PMEMobjpool *pop = pmemobj_openW(path, layout);
if (pop == NULL) {
UT_OUT("!%s: pmemobj_open", upath);
} else {
UT_OUT("%s: pmemobj_open: Success", upath);
pmemobj_close(pop);
}
free(upath);
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "obj_pool_win");
if (argc < 4)
UT_FATAL("usage: %s op path layout [poolsize mode]",
ut_toUTF8(argv[0]));
wchar_t *layout = NULL;
size_t poolsize;
unsigned mode;
if (wcscmp(argv[3], L"EMPTY") == 0)
layout = L"";
else if (wcscmp(argv[3], L"NULL") != 0)
layout = argv[3];
switch (argv[1][0]) {
case 'c':
poolsize = wcstoul(argv[4], NULL, 0) * MB; /* in megabytes */
mode = wcstoul(argv[5], NULL, 8);
pool_create(argv[2], layout, poolsize, mode);
break;
case 'o':
pool_open(argv[2], layout);
break;
default:
UT_FATAL("unknown operation");
}
DONEW(NULL);
}
| 3,480 | 26.195313 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/checksum/checksum.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* checksum.c -- unit test for library internal checksum routine
*
* usage: checksum files...
*/
#include <endian.h>
#include "unittest.h"
#include "util.h"
#include <inttypes.h>
/*
* fletcher64 -- compute a Fletcher64 checksum
*
* Gold standard implementation used to compare to the
* util_checksum() being unit tested.
*/
static uint64_t
fletcher64(void *addr, size_t len)
{
UT_ASSERT(len % 4 == 0);
uint32_t *p32 = addr;
uint32_t *p32end = (uint32_t *)((char *)addr + len);
uint32_t lo32 = 0;
uint32_t hi32 = 0;
while (p32 < p32end) {
lo32 += le32toh(*p32);
p32++;
hi32 += lo32;
}
return htole64((uint64_t)hi32 << 32 | lo32);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "checksum");
if (argc < 2)
UT_FATAL("usage: %s files...", argv[0]);
for (int arg = 1; arg < argc; arg++) {
int fd = OPEN(argv[arg], O_RDONLY);
os_stat_t stbuf;
FSTAT(fd, &stbuf);
size_t size = (size_t)stbuf.st_size;
void *addr =
MMAP(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0);
uint64_t *ptr = addr;
/*
* Loop through, selecting successive locations
* where the checksum lives in this block, and
* let util_checksum() insert it so it can be
* verified against the gold standard fletcher64
* routine in this file.
*/
while ((char *)(ptr + 1) < (char *)addr + size) {
/* save whatever was at *ptr */
uint64_t oldval = *ptr;
/* mess with it */
*ptr = htole64(0x123);
/*
* calculate a checksum and have it installed
*/
util_checksum(addr, size, ptr, 1, 0);
uint64_t csum = *ptr;
/*
* verify inserted checksum checks out
*/
UT_ASSERT(util_checksum(addr, size, ptr, 0, 0));
/* put a zero where the checksum was installed */
*ptr = 0;
/* calculate a checksum */
uint64_t gold_csum = fletcher64(addr, size);
/* put the old value back */
*ptr = oldval;
/*
* verify checksum now fails
*/
UT_ASSERT(!util_checksum(addr, size, ptr,
0, 0));
/*
* verify the checksum matched the gold version
*/
UT_ASSERTeq(csum, gold_csum);
UT_OUT("%s:%" PRIu64 " 0x%" PRIx64, argv[arg],
(char *)ptr - (char *)addr, csum);
ptr++;
}
uint64_t *addr2 =
MMAP(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0);
uint64_t *csum = (uint64_t *)addr;
/*
* put a zero where the checksum will be installed
* in the second map
*/
*addr2 = 0;
for (size_t i = size / 8 - 1; i > 0; i -= 1) {
/* calculate a checksum and have it installed */
util_checksum(addr, size, csum, 1, i * 8);
/*
* put a zero in the second map where an ignored part is
*/
*(addr2 + i) = 0;
/* calculate a checksum */
uint64_t gold_csum = fletcher64(addr2, size);
/*
* verify the checksum matched the gold version
*/
UT_ASSERTeq(*csum, gold_csum);
}
CLOSE(fd);
MUNMAP(addr, size);
MUNMAP(addr2, size);
}
DONE(NULL);
}
| 4,529 | 24.738636 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_fragmentation/obj_fragmentation.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_fragmentation.c -- measures average heap fragmentation
*
* A pretty simplistic test that measures internal fragmentation of the
* allocator for the given size.
*/
#include <stdlib.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_fragmentation"
#define OBJECT_OVERHEAD 64 /* account for the header added to each object */
#define MAX_OVERALL_OVERHEAD 0.10f
/*
* For the best accuracy fragmentation should be measured for one full zone
* because the metadata is preallocated. For reasonable test duration a smaller
* size must be used.
*/
#define DEFAULT_FILE_SIZE ((size_t)(1ULL << 28)) /* 256 megabytes */
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_fragmentation");
if (argc < 3)
UT_FATAL("usage: %s allocsize filename [filesize]", argv[0]);
size_t file_size;
if (argc == 4)
file_size = ATOUL(argv[3]);
else
file_size = DEFAULT_FILE_SIZE;
size_t alloc_size = ATOUL(argv[1]);
const char *path = argv[2];
PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, file_size,
S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
size_t allocated = 0;
int err = 0;
do {
PMEMoid oid;
err = pmemobj_alloc(pop, &oid, alloc_size, 0, NULL, NULL);
if (err == 0)
allocated += pmemobj_alloc_usable_size(oid) +
OBJECT_OVERHEAD;
} while (err == 0);
float allocated_pct = ((float)allocated / file_size);
float overhead_pct = 1.f - allocated_pct;
UT_ASSERT(overhead_pct <= MAX_OVERALL_OVERHEAD);
pmemobj_close(pop);
DONE(NULL);
}
| 3,122 | 32.223404 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/traces/traces.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* traces.c -- unit test for traces
*/
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "UT_LOG_LEVEL"
#define LOG_FILE_VAR "UT_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#include <sys/types.h>
#include <stdarg.h>
#include "pmemcommon.h"
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "traces");
/* Execute test */
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
LOG(0, "Log level NONE");
LOG(1, "Log level ERROR");
LOG(2, "Log level WARNING");
LOG(3, "Log level INFO");
LOG(4, "Log level DEBUG");
/* Cleanup */
common_fini();
DONE(NULL);
}
| 2,243 | 32.492537 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_stats/vmem_stats.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_stats.c -- unit test for vmem_stats
*
* usage: vmem_stats 0|1 [opts]
*/
#include "unittest.h"
static int custom_allocs;
static int custom_alloc_calls;
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
int
main(int argc, char *argv[])
{
int expect_custom_alloc = 0;
char *opts = "";
void *mem_pool;
VMEM *vmp_unused;
VMEM *vmp_used;
START(argc, argv, "vmem_stats");
if (argc > 3 || argc < 2) {
UT_FATAL("usage: %s 0|1 [opts]", argv[0]);
} else {
expect_custom_alloc = atoi(argv[1]);
if (argc > 2)
opts = argv[2];
}
if (expect_custom_alloc)
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp_unused = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp_unused == NULL)
UT_FATAL("!vmem_create_in_region");
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp_used = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp_used == NULL)
UT_FATAL("!vmem_create_in_region");
int *test = vmem_malloc(vmp_used, sizeof(int)*100);
UT_ASSERTne(test, NULL);
vmem_stats_print(vmp_unused, opts);
vmem_stats_print(vmp_used, opts);
vmem_free(vmp_used, test);
vmem_delete(vmp_unused);
vmem_delete(vmp_used);
/* check memory leak in custom allocator */
UT_ASSERTeq(custom_allocs, 0);
if (expect_custom_alloc == 0) {
UT_ASSERTeq(custom_alloc_calls, 0);
} else {
UT_ASSERTne(custom_alloc_calls, 0);
}
DONE(NULL);
}
| 4,076 | 25.303226 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_first_next/obj_first_next.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_first_next.c -- unit tests for POBJ_FIRST macro
*/
#include <stddef.h>
#include "libpmemobj.h"
#include "unittest.h"
#define LAYOUT_NAME "obj_first_next"
TOID_DECLARE(struct type, 0);
TOID_DECLARE(struct type_sec, 1);
struct type {
int id;
};
struct type_sec {
int id;
};
static PMEMobjpool *pop;
typedef void (*fn_op)(int id);
typedef void (*fn_void)();
#define FATAL_USAGE()\
UT_FATAL("usage: obj_first_next <file> [Parfn]")
/*
* get_item_type -- get nth item from list
*/
static TOID(struct type)
get_item_type(int n)
{
TOID(struct type) item;
POBJ_FOREACH_TYPE(pop, item) {
if (n == 0)
return item;
n--;
}
return TOID_NULL(struct type);
}
/*
* get_item_type_sec -- get nth item from list
*/
static TOID(struct type_sec)
get_item_type_sec(int n)
{
TOID(struct type_sec) item;
POBJ_FOREACH_TYPE(pop, item) {
if (n == 0)
return item;
n--;
}
return TOID_NULL(struct type_sec);
}
/*
* do_print_type -- print list elements from type collection
*/
static void
do_print_type(void)
{
TOID(struct type) item;
UT_OUT("type:");
POBJ_FOREACH_TYPE(pop, item) {
UT_OUT("id = %d", D_RO(item)->id);
}
}
/*
* do_print_type_sec -- print list elements from type_sec collection
*/
static void
do_print_type_sec(void)
{
TOID(struct type_sec) item;
UT_OUT("type_sec:");
POBJ_FOREACH_TYPE(pop, item) {
UT_OUT("id = %d", D_RO(item)->id);
}
}
static fn_void do_print[] = {do_print_type, do_print_type_sec};
/*
* type_constructor -- constructor which sets the item's id to
* new value
*/
static int
type_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
int id = *(int *)arg;
struct type *item = (struct type *)ptr;
item->id = id;
UT_OUT("constructor(id = %d)", id);
pmemobj_persist(pop, item, sizeof(*item));
return 0;
}
/*
* type_sec_constructor -- constructor which sets the item's id to
* new value
*/
static int
type_sec_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
int id = *(int *)arg;
struct type_sec *item = (struct type_sec *)ptr;
item->id = id;
UT_OUT("constructor(id = %d)", id);
pmemobj_persist(pop, item, sizeof(*item));
return 0;
}
/*
* do_alloc_type -- allocates new element to type collection
*/
static void
do_alloc_type(int id)
{
TOID(struct type) item;
POBJ_NEW(pop, &item, struct type, type_constructor, &id);
if (TOID_IS_NULL(item))
UT_FATAL("POBJ_NEW");
}
/*
* do_alloc_type_sec -- allocates new element to type_sec collection
*/
static void
do_alloc_type_sec(int id)
{
TOID(struct type_sec) item;
POBJ_NEW(pop, &item, struct type_sec, type_sec_constructor, &id);
if (TOID_IS_NULL(item))
UT_FATAL("POBJ_NEW");
}
static fn_op do_alloc[] = {do_alloc_type, do_alloc_type_sec};
/*
* do_free_type -- remove and free element from type collection
*/
static void
do_free_type(int n)
{
TOID(struct type) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type)))
return;
item = get_item_type(n);
UT_ASSERT(!TOID_IS_NULL(item));
POBJ_FREE(&item);
}
/*
* do_free_type_sec -- remove and free element from type_sec collection
*/
static void
do_free_type_sec(int n)
{
TOID(struct type_sec) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type_sec)))
return;
item = get_item_type_sec(n);
UT_ASSERT(!TOID_IS_NULL(item));
POBJ_FREE(&item);
}
static fn_op do_free[] = {do_free_type, do_free_type_sec};
/*
* do_first_type -- prints id of first object in type collection
*/
static void
do_first_type(void)
{
TOID(struct type) first = POBJ_FIRST(pop, struct type);
UT_OUT("first id = %d", D_RO(first)->id);
}
/*
* do_first_type_sec -- prints id of first object in type_sec collection
*/
static void
do_first_type_sec(void)
{
TOID(struct type_sec) first = POBJ_FIRST(pop, struct type_sec);
UT_OUT("first id = %d", D_RO(first)->id);
}
static fn_void do_first[] = {do_first_type, do_first_type_sec};
/*
* do_next_type -- finds next element from type collection
*/
static void
do_next_type(int n)
{
TOID(struct type) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type)))
return;
item = get_item_type(n);
UT_ASSERT(!TOID_IS_NULL(item));
item = POBJ_NEXT(item);
UT_OUT("next id = %d", D_RO(item)->id);
}
/*
* do_next_type_sec -- finds next element from type_sec collection
*/
static void
do_next_type_sec(int n)
{
TOID(struct type_sec) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type_sec)))
return;
item = get_item_type_sec(n);
UT_ASSERT(!TOID_IS_NULL(item));
item = POBJ_NEXT(item);
UT_OUT("next id = %d", D_RO(item)->id);
}
static fn_op do_next[] = {do_next_type, do_next_type_sec};
/*
* do_cleanup -- de-initialization function
*/
static void
do_cleanup(void)
{
PMEMoid oid, oid_tmp;
POBJ_FOREACH_SAFE(pop, oid, oid_tmp)
pmemobj_free(&oid);
}
static void
test_internal_object_mask(PMEMobjpool *pop)
{
/* allocate root object */
PMEMoid root = pmemobj_root(pop, sizeof(struct type));
TX_BEGIN(pop) {
/* trigger creation of a range cache */
pmemobj_tx_add_range(root, 0, 8);
} TX_END
PMEMoid oid;
pmemobj_alloc(pop, &oid, sizeof(struct type), 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(oid));
/* verify that there's no root object nor range cache anywhere */
for (PMEMoid iter = pmemobj_first(pop); !OID_IS_NULL(iter);
iter = pmemobj_next(iter)) {
UT_ASSERT(OID_EQUALS(iter, oid));
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_first_next");
if (argc < 2)
FATAL_USAGE();
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
for (int i = 2; i < argc; i++) {
int list_num;
int id;
char type;
if (sscanf(argv[i], "%c:%d:%d", &type, &list_num, &id) == EOF)
UT_FATAL("!sscanf");
switch (type) {
case 'P':
do_print[list_num]();
break;
case 'a':
do_alloc[list_num](id);
break;
case 'r':
do_free[list_num](id);
break;
case 'f':
do_first[list_num]();
break;
case 'n':
do_next[list_num](id);
break;
default:
FATAL_USAGE();
}
}
do_cleanup();
test_internal_object_mask(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 7,669 | 21.426901 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_transform_win/libpmempool_transform_win.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_transform_win -- a unittest for libpmempool transform.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "unittest.h"
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "libpmempool_transform_win");
if (argc != 4)
UT_FATAL("usage: %s poolset_in poolset_out flags",
ut_toUTF8(argv[0]));
int ret = pmempool_transformW(argv[1], argv[2],
(unsigned)wcstoul(argv[3], NULL, 0));
if (ret)
UT_OUT("result: %d, errno: %d", ret, errno);
else
UT_OUT("result: 0");
DONEW(NULL);
}
| 2,162 | 33.887097 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_recovery/obj_recovery.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_recovery.c -- unit test for pool recovery
*/
#include "unittest.h"
#include "valgrind_internal.h"
#if VG_PMEMCHECK_ENABLED
#define VALGRIND_PMEMCHECK_END_TX VALGRIND_PMC_END_TX
#else
#define VALGRIND_PMEMCHECK_END_TX
#endif
POBJ_LAYOUT_BEGIN(recovery);
POBJ_LAYOUT_ROOT(recovery, struct root);
POBJ_LAYOUT_TOID(recovery, struct foo);
POBJ_LAYOUT_END(recovery);
struct foo {
int bar;
};
struct root {
PMEMmutex lock;
TOID(struct foo) foo;
};
#define BAR_VALUE 5
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_recovery");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(recovery) != 1);
if (argc != 5)
UT_FATAL("usage: %s [file] [lock: y/n] "
"[cmd: c/o] [type: n/f/s]",
argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
int exists = argv[3][0] == 'o';
enum { TEST_NEW, TEST_FREE, TEST_SET } type;
if (argv[4][0] == 'n')
type = TEST_NEW;
else if (argv[4][0] == 'f')
type = TEST_FREE;
else if (argv[4][0] == 's')
type = TEST_SET;
else
UT_FATAL("invalid type");
if (!exists) {
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(recovery),
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_FATAL("failed to create pool\n");
}
} else {
if ((pop = pmemobj_open(path, POBJ_LAYOUT_NAME(recovery)))
== NULL) {
UT_FATAL("failed to open pool\n");
}
}
TOID(struct root) root = POBJ_ROOT(pop, struct root);
int lock_type = TX_PARAM_NONE;
void *lock = NULL;
if (argv[2][0] == 'y') {
lock_type = TX_PARAM_MUTEX;
lock = &D_RW(root)->lock;
}
if (type == TEST_SET) {
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TOID(struct foo) f = TX_NEW(struct foo);
D_RW(root)->foo = f;
D_RW(f)->bar = BAR_VALUE;
} TX_END
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD_FIELD(D_RW(root)->foo, bar);
D_RW(D_RW(root)->foo)->bar = BAR_VALUE * 2;
/*
* Even though flushes are not required inside
* of a transaction, this is done here to
* suppress irrelevant pmemcheck issues, because
* we exit the program before the data is
* flushed, while preserving any real ones.
*/
pmemobj_persist(pop,
&D_RW(D_RW(root)->foo)->bar,
sizeof(int));
/*
* We also need to cleanup the transaction state
* of pmemcheck.
*/
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(D_RW(D_RW(root)->foo)->bar == BAR_VALUE);
}
} else if (type == TEST_NEW) {
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TOID(struct foo) f = TX_NEW(struct foo);
TX_SET(root, foo, f);
pmemobj_persist(pop,
&D_RW(root)->foo,
sizeof(PMEMoid));
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(TOID_IS_NULL(D_RW(root)->foo));
}
} else { /* TEST_FREE */
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TOID(struct foo) f = TX_NEW(struct foo);
D_RW(root)->foo = f;
D_RW(f)->bar = BAR_VALUE;
} TX_END
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TX_FREE(D_RW(root)->foo);
D_RW(root)->foo = TOID_NULL(struct foo);
pmemobj_persist(pop,
&D_RW(root)->foo,
sizeof(PMEMoid));
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(!TOID_IS_NULL(D_RW(root)->foo));
}
}
UT_ASSERT(pmemobj_check(path, POBJ_LAYOUT_NAME(recovery)));
pmemobj_close(pop);
DONE(NULL);
}
| 5,112 | 25.220513 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_is_pmem_posix.c -- Posix specific unit test for pmem_is_pmem()
*
* usage: pmem_is_pmem_posix op addr len [op addr len ...]
* where op can be: 'a' (add), 'r' (remove), 't' (test)
*/
#include <stdlib.h>
#include "unittest.h"
#include "mmap.h"
static enum pmem_map_type
str2type(char *str)
{
if (strcmp(str, "DEV_DAX") == 0)
return PMEM_DEV_DAX;
if (strcmp(str, "MAP_SYNC") == 0)
return PMEM_MAP_SYNC;
FATAL("unknown type '%s'", str);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_is_pmem_posix");
if (argc < 4)
UT_FATAL("usage: %s op addr len type [op addr len type ...]",
argv[0]);
/* insert memory regions to the list */
int i;
for (i = 1; i < argc; ) {
UT_ASSERT(i + 2 < argc);
errno = 0;
void *addr = (void *)strtoull(argv[i + 1], NULL, 0);
UT_ASSERTeq(errno, 0);
size_t len = strtoull(argv[i + 2], NULL, 0);
UT_ASSERTeq(errno, 0);
int ret;
switch (argv[i][0]) {
case 'a':
ret = util_range_register(addr, len, "",
str2type(argv[i + 3]));
if (ret != 0)
UT_OUT("%s", pmem_errormsg());
i += 4;
break;
case 'r':
ret = util_range_unregister(addr, len);
UT_ASSERTeq(ret, 0);
i += 3;
break;
case 't':
UT_OUT("addr %p len %zu is_pmem %d",
addr, len, pmem_is_pmem(addr, len));
i += 3;
break;
default:
FATAL("invalid op '%c'", argv[i][0]);
}
}
DONE(NULL);
}
| 2,990 | 27.759615 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_direct_volatile/obj_direct_volatile.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_volatile.c -- unit test for pmemobj_direct_volatile()
*/
#include "unittest.h"
static PMEMobjpool *pop;
struct test {
PMEMvlt(int) count;
};
#define TEST_OBJECTS 100
#define TEST_WORKERS 10
static struct test *tests[TEST_OBJECTS];
static int
test_constructor(void *ptr, void *arg)
{
int *count = ptr;
util_fetch_and_add32(count, 1);
return 0;
}
static void *
test_worker(void *arg)
{
for (int i = 0; i < TEST_OBJECTS; ++i) {
int *count = pmemobj_volatile(pop, &tests[i]->count.vlt,
&tests[i]->count.value, sizeof(tests[i]->count.value),
test_constructor, NULL);
UT_ASSERTne(count, NULL);
UT_ASSERTeq(*count, 1);
}
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_direct_volatile");
if (argc != 2)
UT_FATAL("usage: %s file", argv[0]);
char *path = argv[1];
pop = pmemobj_create(path, "obj_direct_volatile",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
for (int i = 0; i < TEST_OBJECTS; ++i) {
PMEMoid oid;
pmemobj_zalloc(pop, &oid, sizeof(struct test), 1);
UT_ASSERT(!OID_IS_NULL(oid));
tests[i] = pmemobj_direct(oid);
}
os_thread_t t[TEST_WORKERS];
for (int i = 0; i < TEST_WORKERS; ++i) {
PTHREAD_CREATE(&t[i], NULL, test_worker, NULL);
}
for (int i = 0; i < TEST_WORKERS; ++i) {
PTHREAD_JOIN(&t[i], NULL);
}
for (int i = 0; i < TEST_OBJECTS; ++i) {
UT_ASSERTeq(tests[i]->count.value, 1);
}
pmemobj_close(pop);
DONE(NULL);
}
| 3,075 | 27.220183 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_parse_size/util_parse_size.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_parse_size.c -- unit test for parsing a size
*/
#include "unittest.h"
#include "util.h"
#include <inttypes.h>
int
main(int argc, char *argv[])
{
int ret = 0;
uint64_t size = 0;
START(argc, argv, "util_parse_size");
for (int arg = 1; arg < argc; ++arg) {
ret = util_parse_size(argv[arg], &size);
if (ret == 0) {
UT_OUT("%s - correct %"PRIu64, argv[arg], size);
} else {
UT_OUT("%s - incorrect", argv[arg]);
}
}
DONE(NULL);
}
| 2,058 | 33.316667 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_unmap/pmem_unmap.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_unmap.c -- unit tests for pmem_unmap
*/
#include "unittest.h"
#define KILOBYTE (1 << 10)
#define MEGABYTE (1 << 20)
#define PAGE_4K (4 * KILOBYTE)
#define PAGE_2M (2 * MEGABYTE)
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_unmap");
const char *path;
unsigned long long len;
int flags;
mode_t mode;
size_t mlenp;
size_t size;
int is_pmem;
char *ret;
os_stat_t stbuf;
if (argc != 2)
UT_FATAL("usage: %s path", argv[0]);
path = argv[1];
len = 0;
flags = 0;
mode = S_IWUSR | S_IRUSR;
STAT(path, &stbuf);
size = (size_t)stbuf.st_size;
UT_ASSERTeq(size, 20 * MEGABYTE);
ret = pmem_map_file(path, len, flags, mode, &mlenp, &is_pmem);
UT_ASSERTeq(pmem_unmap(ret, PAGE_4K), 0);
ret += PAGE_2M;
UT_ASSERTeq(pmem_unmap(ret, PAGE_2M), 0);
ret += PAGE_2M;
UT_ASSERTeq(pmem_unmap(ret, PAGE_2M - 1), 0);
ret += PAGE_2M;
UT_ASSERTne(pmem_unmap(ret, 0), 0);
ret += PAGE_2M - 1;
UT_ASSERTne(pmem_unmap(ret, PAGE_4K), 0);
DONE(NULL);
}
| 2,584 | 28.375 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_util/rpmemd_util_test.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_util_test.c -- unit tests for rpmemd_util module
*/
#include "unittest.h"
#include "rpmem_common.h"
#include "rpmemd_log.h"
#include "rpmemd_util.h"
#include "util.h"
/* structure to store results */
struct result {
int ret;
enum rpmem_persist_method persist_method;
int (*persist)(const void *addr, size_t len);
void *(*memcpy_persist)(void *pmemdest, const void *src, size_t len);
};
/* all values to test */
static const enum rpmem_persist_method pms[] =
{RPMEM_PM_GPSPM, RPMEM_PM_APM, MAX_RPMEM_PM};
static const int is_pmems[] = {0, 1};
enum mode {
MODE_VALID,
MODE_INVALID,
MODE_MAX
};
static const int ranges[2][2][2] = {
[MODE_VALID] = {
{0, ARRAY_SIZE(pms) - 1},
{0, ARRAY_SIZE(is_pmems)}
},
[MODE_INVALID] = {
{ARRAY_SIZE(pms) - 1, ARRAY_SIZE(pms)},
{0, ARRAY_SIZE(is_pmems)}
}
};
/* expected results */
static const struct result exp_results[3][2] = {
{
/* GPSPM and is_pmem == false */
{0, RPMEM_PM_GPSPM, pmem_msync, memcpy},
/* GPSPM and is_pmem == true */
{0, RPMEM_PM_GPSPM, rpmemd_pmem_persist,
pmem_memcpy_persist}
}, {
/* APM and is_pmem == false */
{0, RPMEM_PM_GPSPM, pmem_msync, memcpy},
/* APM and is_pmem == true */
{0, RPMEM_PM_APM, rpmemd_flush_fatal,
pmem_memcpy_persist}
}, {
/* persistency method outside of the range */
{1, 0, 0, 0},
{1, 0, 0, 0}
}
};
static void
test_apply_pm_policy(struct result *result, int is_pmem)
{
if (rpmemd_apply_pm_policy(&result->persist_method, &result->persist,
&result->memcpy_persist, is_pmem)) {
goto err;
}
result->ret = 0;
return;
err:
result->ret = 1;
}
#define USAGE() do {\
UT_ERR("usage: %s valid|invalid", argv[0]);\
} while (0)
static void
test(const int pm_range[2], const int is_pmem_range[2])
{
rpmemd_log_level = RPD_LOG_NOTICE;
int ret = rpmemd_log_init("rpmemd_log", NULL, 0);
UT_ASSERTeq(ret, 0);
struct result result;
const struct result *exp_result;
for (int pm_ind = pm_range[0]; pm_ind < pm_range[1]; ++pm_ind) {
for (int is_pmem_ind = is_pmem_range[0];
is_pmem_ind < is_pmem_range[1]; ++is_pmem_ind) {
result.persist_method = pms[pm_ind];
exp_result = &exp_results[pm_ind][is_pmem_ind];
test_apply_pm_policy(&result, is_pmems[is_pmem_ind]);
UT_ASSERTeq(result.ret, exp_result->ret);
if (exp_result->ret == 0) {
UT_ASSERTeq(result.persist_method,
exp_result->persist_method);
UT_ASSERTeq(result.persist,
exp_result->persist);
}
}
}
rpmemd_log_close();
}
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmemd_util");
if (argc < 2) {
USAGE();
return 1;
}
const char *mode_str = argv[1];
enum mode mode = MODE_MAX;
if (strcmp(mode_str, "valid") == 0) {
mode = MODE_VALID;
} else if (strcmp(mode_str, "invalid") == 0) {
mode = MODE_INVALID;
} else {
USAGE();
return 1;
}
UT_ASSERTne(mode, MODE_MAX);
test(ranges[mode][0], ranges[mode][1]);
DONE(NULL);
}
| 4,542 | 25.260116 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_malloc_usable_size/vmem_malloc_usable_size.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_malloc_usable_size.c -- unit test for vmem_malloc_usable_size
*
* usage: vmem_malloc_usable_size [directory]
*/
#include "unittest.h"
#define POOL_SIZE (VMEM_MIN_POOL * 2)
static const struct {
size_t size;
size_t spacing;
} Check_sizes[] = {
{.size = 10, .spacing = 8},
{.size = 100, .spacing = 16},
{.size = 200, .spacing = 32},
{.size = 500, .spacing = 64},
{.size = 1000, .spacing = 128},
{.size = 2000, .spacing = 256},
{.size = 3000, .spacing = 512},
{.size = 1 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 2 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 3 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 4 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 5 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 6 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 7 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 8 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 9 * 1024 * 1024, .spacing = 4 * 1024 * 1024}
};
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
void *alloc;
size_t usable_size;
size_t size;
unsigned i;
START(argc, argv, "vmem_malloc_usable_size");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20);
vmp = vmem_create_in_region(mem_pool, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
UT_ASSERTeq(vmem_malloc_usable_size(vmp, NULL), 0);
for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) {
size = Check_sizes[i].size;
alloc = vmem_malloc(vmp, size);
UT_ASSERTne(alloc, NULL);
usable_size = vmem_malloc_usable_size(vmp, alloc);
UT_ASSERT(usable_size >= size);
if (usable_size - size > Check_sizes[i].spacing) {
UT_FATAL("Size %zu: spacing %zu is bigger"
"than expected: %zu", size,
(usable_size - size), Check_sizes[i].spacing);
}
memset(alloc, 0xEE, usable_size);
vmem_free(vmp, alloc);
}
UT_ASSERTeq(vmem_check(vmp), 1);
vmem_delete(vmp);
DONE(NULL);
}
| 3,888 | 31.408333 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_direct/obj_direct_non_inline.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_inline.c -- unit test for direct
*/
#define PMEMOBJ_DIRECT_NON_INLINE
#include "unittest.h"
#include "obj_direct.h"
void *
obj_direct_non_inline(PMEMoid oid)
{
UT_OUT("pmemobj_direct non-inlined");
return pmemobj_direct(oid);
}
| 1,847 | 38.319149 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_direct/obj_direct.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct.c -- unit test for pmemobj_direct()
*/
#include "obj.h"
#include "unittest.h"
#include "obj_direct.h"
#define MAX_PATH_LEN 255
#define LAYOUT_NAME "direct"
static os_mutex_t lock1;
static os_mutex_t lock2;
static os_cond_t sync_cond1;
static os_cond_t sync_cond2;
static int cond1;
static int cond2;
static PMEMoid thread_oid;
static void *
obj_direct(PMEMoid oid)
{
void *ptr1 = obj_direct_inline(oid);
void *ptr2 = obj_direct_non_inline(oid);
UT_ASSERTeq(ptr1, ptr2);
return ptr1;
}
static void *
test_worker(void *arg)
{
/* check before pool is closed, then let main continue */
UT_ASSERTne(obj_direct(thread_oid), NULL);
os_mutex_lock(&lock1);
cond1 = 1;
os_cond_signal(&sync_cond1);
os_mutex_unlock(&lock1);
/* wait for main thread to free & close, then check */
os_mutex_lock(&lock2);
while (!cond2)
os_cond_wait(&sync_cond2, &lock2);
os_mutex_unlock(&lock2);
UT_ASSERTeq(obj_direct(thread_oid), NULL);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_direct");
if (argc != 3)
UT_FATAL("usage: %s [directory] [# of pools]", argv[0]);
unsigned npools = ATOU(argv[2]);
const char *dir = argv[1];
int r;
os_mutex_init(&lock1);
os_mutex_init(&lock2);
os_cond_init(&sync_cond1);
os_cond_init(&sync_cond2);
cond1 = cond2 = 0;
PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMobjpool *));
UT_ASSERTne(pops, NULL);
size_t length = strlen(dir) + MAX_PATH_LEN;
char *path = MALLOC(length);
for (unsigned i = 0; i < npools; ++i) {
int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d",
dir, i);
if (ret < 0 || ret >= length)
UT_FATAL("snprintf: %d", ret);
pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (pops[i] == NULL)
UT_FATAL("!pmemobj_create");
}
PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid));
UT_ASSERTne(oids, NULL);
PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid));
UT_ASSERTne(tmpoids, NULL);
oids[0] = OID_NULL;
UT_ASSERTeq(obj_direct(oids[0]), NULL);
for (unsigned i = 0; i < npools; ++i) {
oids[i] = (PMEMoid) {pops[i]->uuid_lo, 0};
UT_ASSERTeq(obj_direct(oids[i]), NULL);
uint64_t off = pops[i]->heap_offset;
oids[i] = (PMEMoid) {pops[i]->uuid_lo, off};
UT_ASSERTeq((char *)obj_direct(oids[i]) - off,
(char *)pops[i]);
r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL);
UT_ASSERTeq(r, 0);
}
r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL);
UT_ASSERTeq(r, 0);
UT_ASSERTne(obj_direct(thread_oid), NULL);
os_thread_t t;
PTHREAD_CREATE(&t, NULL, test_worker, NULL);
/* wait for the worker thread to perform the first check */
os_mutex_lock(&lock1);
while (!cond1)
os_cond_wait(&sync_cond1, &lock1);
os_mutex_unlock(&lock1);
for (unsigned i = 0; i < npools; ++i) {
UT_ASSERTne(obj_direct(tmpoids[i]), NULL);
pmemobj_free(&tmpoids[i]);
UT_ASSERTeq(obj_direct(tmpoids[i]), NULL);
pmemobj_close(pops[i]);
UT_ASSERTeq(obj_direct(oids[i]), NULL);
}
/* signal the worker that we're free and closed */
os_mutex_lock(&lock2);
cond2 = 1;
os_cond_signal(&sync_cond2);
os_mutex_unlock(&lock2);
PTHREAD_JOIN(&t, NULL);
os_cond_destroy(&sync_cond1);
os_cond_destroy(&sync_cond2);
os_mutex_destroy(&lock1);
os_mutex_destroy(&lock2);
FREE(pops);
FREE(tmpoids);
FREE(oids);
DONE(NULL);
}
| 4,939 | 27.228571 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_direct/obj_direct_inline.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_inline.c -- unit test for direct
*/
#include "unittest.h"
#include "obj_direct.h"
void *
obj_direct_inline(PMEMoid oid)
{
UT_OUT("pmemobj_direct inlined");
return pmemobj_direct(oid);
}
| 1,804 | 39.111111 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_direct/obj_direct.h | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct.h -- unit test for pmemobj_direct()
*/
#ifndef OBJ_DIRECT_H
#define OBJ_DIRECT_H 1
#include "libpmemobj.h"
void *obj_direct_inline(PMEMoid oid);
void *obj_direct_non_inline(PMEMoid oid);
#endif /* OBJ_DIRECT_H */
| 1,831 | 39.711111 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_memcheck/obj_memcheck.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "unittest.h"
#include "valgrind_internal.h"
/*
* Layout definition
*/
POBJ_LAYOUT_BEGIN(mc);
POBJ_LAYOUT_ROOT(mc, struct root);
POBJ_LAYOUT_TOID(mc, struct struct1);
POBJ_LAYOUT_END(mc);
struct struct1 {
int fld;
int dyn[];
};
struct root {
TOID(struct struct1) s1;
TOID(struct struct1) s2;
};
static void
test_memcheck_bug(void)
{
#if VG_MEMCHECK_ENABLED
volatile char tmp[100];
VALGRIND_CREATE_MEMPOOL(tmp, 0, 0);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 8, 16);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 8);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 8, 16);
VALGRIND_MAKE_MEM_NOACCESS(tmp, 8);
tmp[7] = 0x66;
#endif
}
static void
test_memcheck_bug2(void)
{
#if VG_MEMCHECK_ENABLED
volatile char tmp[1000];
VALGRIND_CREATE_MEMPOOL(tmp, 0, 0);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 128, 128);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 128);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 256, 128);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 256);
/*
* This should produce warning:
* Address ... is 0 bytes inside a block of size 128 bytes freed.
* instead, it produces a warning:
* Address ... is 0 bytes after a block of size 128 freed
*/
int *data = (int *)(tmp + 256);
*data = 0x66;
#endif
}
static void
test_everything(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(mc),
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
struct root *rt = D_RW(POBJ_ROOT(pop, struct root));
POBJ_ALLOC(pop, &rt->s1, struct struct1, sizeof(struct struct1),
NULL, NULL);
struct struct1 *s1 = D_RW(rt->s1);
struct struct1 *s2;
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
s2 = D_RW(rt->s2);
POBJ_FREE(&rt->s2);
/* read of uninitialized variable */
if (s1->fld)
UT_OUT("%d", 1);
/* write to freed object */
s2->fld = 7;
pmemobj_persist(pop, s2, sizeof(*s2));
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
s2 = D_RW(rt->s2);
memset(s2, 0, pmemobj_alloc_usable_size(rt->s2.oid));
s2->fld = 12; /* ok */
/* invalid write */
s2->dyn[100000] = 9;
/* invalid write */
s2->dyn[1000] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1));
POBJ_REALLOC(pop, &rt->s2, struct struct1,
sizeof(struct struct1) + 100 * sizeof(int));
s2 = D_RW(rt->s2);
s2->dyn[0] = 9; /* ok */
pmemobj_persist(pop, s2, sizeof(struct struct1) + 100 * sizeof(int));
POBJ_FREE(&rt->s2);
/* invalid write to REALLOCated and FREEd object */
s2->dyn[0] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 100 * sizeof(int));
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
POBJ_REALLOC(pop, &rt->s2, struct struct1,
sizeof(struct struct1) + 30 * sizeof(int));
s2 = D_RW(rt->s2);
s2->dyn[0] = 0;
s2->dyn[29] = 29;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 30 * sizeof(int));
POBJ_FREE(&rt->s2);
s2->dyn[0] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 30 * sizeof(int));
pmemobj_close(pop);
}
static void usage(const char *a)
{
UT_FATAL("usage: %s [m|t] file-name", a);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memcheck");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(mc) != 1);
if (argc < 2)
usage(argv[0]);
if (strcmp(argv[1], "m") == 0)
test_memcheck_bug();
else if (strcmp(argv[1], "t") == 0) {
if (argc < 3)
usage(argv[0]);
test_everything(argv[2]);
} else
usage(argv[0]);
test_memcheck_bug2();
DONE(NULL);
}
| 5,106 | 25.324742 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_valgrind/cto_valgrind.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_valgrind.c -- unit test for Valgrind instrumentation in libpmemcto
*
* usage: cto_valgrind filename <test-number>
*
* test-number can be a number from 0 to 6
*/
#include "unittest.h"
#include "set.h"
#include "cto.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_valgrind");
if (argc != 3)
UT_FATAL("usage: %s filename <test-number>", argv[0]);
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
2 * PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(pcp, NULL);
int test_case = atoi(argv[2]);
int *ptr;
switch (test_case) {
case 0: {
UT_OUT("remove all allocations and close pool");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
break;
}
case 1: {
UT_OUT("free after close");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_close(pcp);
pmemcto_free(pcp, ptr);
break;
}
case 2: {
UT_OUT("only close pool");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_close(pcp);
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
break;
}
case 3: {
UT_OUT("memory leaks");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
/* prevent reporting memory leaks in set */
util_poolset_free(pcp->set);
break;
}
case 4: {
UT_OUT("heap block overrun");
ptr = pmemcto_malloc(pcp, 12 * sizeof(int));
UT_ASSERTne(ptr, NULL);
/* heap block overrun */
ptr[12] = 7;
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
break;
}
case 5: {
UT_OUT("close & re-open");
int *ptrs[5];
ptrs[0] = pmemcto_malloc(pcp, sizeof(int));
ptrs[1] = pmemcto_malloc(pcp, 256 * sizeof(int));
ptrs[2] = pmemcto_malloc(pcp, 16384);
ptrs[3] = pmemcto_malloc(pcp, 3 * 1024 * 1024);
ptrs[4] = pmemcto_malloc(pcp, 8 * 1024 * 1024);
UT_ASSERTne(ptrs[0], NULL);
UT_ASSERTne(ptrs[1], NULL);
UT_ASSERTne(ptrs[2], NULL);
UT_ASSERTne(ptrs[3], NULL);
UT_ASSERTne(ptrs[4], NULL);
*ptrs[0] = 55;
*ptrs[1] = 55;
*ptrs[2] = 55;
*ptrs[3] = 55;
*ptrs[4] = 55;
pmemcto_close(pcp);
pcp = pmemcto_open(argv[1], "test");
UT_ASSERTne(pcp, NULL);
*ptrs[0] = 77;
*ptrs[1] = 77;
*ptrs[2] = 77;
*ptrs[3] = 77;
*ptrs[4] = 77;
pmemcto_free(pcp, ptrs[0]);
pmemcto_free(pcp, ptrs[1]);
pmemcto_free(pcp, ptrs[2]);
pmemcto_free(pcp, ptrs[3]);
pmemcto_free(pcp, ptrs[4]);
*ptrs[0] = 99; /* XXX not detected */
*ptrs[1] = 99; /* XXX not detected */
*ptrs[2] = 99; /* XXX not detected */
*ptrs[3] = 99;
*ptrs[4] = 99;
pmemcto_close(pcp);
break;
}
default: {
UT_FATAL("unknown test-number");
}
}
DONE(NULL);
}
| 4,421 | 26.465839 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_extend/obj_extend.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_extend.c -- pool extension tests
*
*/
#include <stddef.h>
#include "unittest.h"
#define ALLOC_SIZE (((1 << 20) * 2) - 16) /* 2 megabytes - 16 bytes (hdr) */
#define RESV_SIZE ((1 << 29) + ((1 << 20) * 8)) /* 512 + 8 megabytes */
#define FRAG 0.9
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_extend");
if (argc < 2)
UT_FATAL("usage: %s file-name [alloc-size] [opath]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "obj_extend",
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_ERR("pmemobj_create: %s", pmemobj_errormsg());
exit(0);
}
size_t alloc_size;
if (argc > 2)
alloc_size = ATOUL(argv[2]);
else
alloc_size = ALLOC_SIZE;
const char *opath = path;
if (argc > 3)
opath = argv[3];
size_t allocated = 0;
PMEMoid oid;
while (pmemobj_alloc(pop, &oid, alloc_size, 0, NULL, NULL) == 0) {
allocated += pmemobj_alloc_usable_size(oid);
}
UT_ASSERT(allocated > (RESV_SIZE * FRAG));
pmemobj_close(pop);
if ((pop = pmemobj_open(opath, "obj_extend")) != NULL) {
pmemobj_close(pop);
int result = pmemobj_check(opath, "obj_extend");
UT_ASSERTeq(result, 1);
} else {
UT_ERR("pmemobj_open: %s", pmemobj_errormsg());
}
DONE(NULL);
}
| 2,845 | 28.957895 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_badblock/util_badblock.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_badblock.c -- unit test for the linux bad block API
*
*/
#include "unittest.h"
#include "util.h"
#include "out.h"
#include "set.h"
#include "os_dimm.h"
#include "os_badblock.h"
#include "badblock.h"
#define MIN_POOL ((size_t)(1024 * 1024 * 8)) /* 8 MiB */
#define MIN_PART ((size_t)(1024 * 1024 * 2)) /* 2 MiB */
/*
* do_list -- (internal) list bad blocks in the file
*/
static void
do_list(const char *path)
{
int ret;
struct badblocks *bbs = badblocks_new();
if (bbs == NULL)
UT_FATAL("!badblocks_new");
ret = os_badblocks_get(path, bbs);
if (ret)
UT_FATAL("!os_badblocks_get");
if (bbs->bb_cnt == 0 || bbs->bbv == NULL) {
UT_OUT("No bad blocks found.");
goto exit_free;
}
UT_OUT("Found %u bad block(s):", bbs->bb_cnt);
unsigned b;
for (b = 0; b < bbs->bb_cnt; b++) {
UT_OUT("%llu %u",
bbs->bbv[b].offset >> 9,
bbs->bbv[b].length >> 9);
}
exit_free:
badblocks_delete(bbs);
}
/*
* do_clear -- (internal) clear bad blocks in the file
*/
static void
do_clear(const char *path)
{
if (os_badblocks_clear_all(path))
UT_FATAL("!os_badblocks_clear_all: %s", path);
}
/*
* do_create -- (internal) create a pool
*/
static void
do_create(const char *path)
{
struct pool_set *set;
struct pool_attr attr;
unsigned nlanes = 1;
memset(&attr, 0, sizeof(attr));
if (util_pool_create(&set, path, 0, MIN_POOL, MIN_PART,
&attr, &nlanes, REPLICAS_ENABLED) != 0)
UT_FATAL("!util_pool_create: %s", path);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
/*
* do_open -- (internal) open a pool
*/
static void
do_open(const char *path)
{
struct pool_set *set;
const struct pool_attr attr;
unsigned nlanes = 1;
if (util_pool_open(&set, path, MIN_PART,
&attr, &nlanes, NULL, 0) != 0) {
UT_FATAL("!util_pool_open: %s", path);
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_badblock");
util_init();
out_init("UTIL_BADBLOCK", "UTIL_BADBLOCK", "", 1, 0);
if (argc < 3)
UT_FATAL("usage: %s file op:l|c|r|o", argv[0]);
const char *path = argv[1];
/* go through all arguments one by one */
for (int arg = 2; arg < argc; arg++) {
if (argv[arg][1] != '\0')
UT_FATAL(
"op must be l, c, r or o (l=list, c=clear, r=create, o=open)");
switch (argv[arg][0]) {
case 'l':
do_list(path);
break;
case 'c':
do_clear(path);
break;
case 'r':
do_create(path);
break;
case 'o':
do_open(path);
break;
default:
UT_FATAL(
"op must be l, c, r or o (l=list, c=clear, r=create, o=open)");
break;
}
}
out_fini();
DONE(NULL);
}
| 4,202 | 23.017143 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_mem/obj_mem.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_mem.c -- simple test for pmemobj_memcpy, pmemobj_memmove and
* pmemobj_memset that verifies nothing blows up on pmemobj side.
* Real consistency tests are for libpmem.
*/
#include "unittest.h"
static unsigned Flags[] = {
0,
PMEMOBJ_F_MEM_NODRAIN,
PMEMOBJ_F_MEM_NONTEMPORAL,
PMEMOBJ_F_MEM_TEMPORAL,
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_TEMPORAL,
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_NODRAIN,
PMEMOBJ_F_MEM_WC,
PMEMOBJ_F_MEM_WB,
PMEMOBJ_F_MEM_NOFLUSH,
/* all possible flags */
PMEMOBJ_F_MEM_NODRAIN | PMEMOBJ_F_MEM_NOFLUSH |
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_TEMPORAL |
PMEMOBJ_F_MEM_WC | PMEMOBJ_F_MEM_WB,
};
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_mem");
if (argc != 2)
UT_FATAL("usage: %s [directory]", argv[0]);
PMEMobjpool *pop = pmemobj_create(argv[1], "obj_mem", 0,
S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!pmemobj_create");
struct root {
char c[4096];
};
struct root *r = pmemobj_direct(pmemobj_root(pop, sizeof(struct root)));
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
unsigned f = Flags[i];
pmemobj_memset(pop, &r->c[0], 0x77, 2048, f);
pmemobj_memset(pop, &r->c[2048], 0xff, 2048, f);
pmemobj_memcpy(pop, &r->c[2048 + 7], &r->c[0], 100, f);
pmemobj_memcpy(pop, &r->c[2048 + 1024], &r->c[0] + 17, 128, f);
pmemobj_memmove(pop, &r->c[125], &r->c[150], 100, f);
pmemobj_memmove(pop, &r->c[350], &r->c[325], 100, f);
if (f & PMEMOBJ_F_MEM_NOFLUSH)
pmemobj_persist(pop, r, sizeof(*r));
}
pmemobj_close(pop);
DONE(NULL);
}
| 3,159 | 31.244898 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_valgr_simple/pmem_valgr_simple.c | /*
* Copyright 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_valgr_simple.c -- simple unit test using pmemcheck
*
* usage: pmem_valgr_simple file
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
size_t mapped_len;
char *dest;
int is_pmem;
START(argc, argv, "pmem_valgr_simple");
if (argc != 4)
UT_FATAL("usage: %s file offset length", argv[0]);
int dest_off = atoi(argv[2]);
size_t bytes = strtoul(argv[3], NULL, 0);
dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, &is_pmem);
if (dest == NULL)
UT_FATAL("!Could not mmap %s\n", argv[1]);
/* these will not be made persistent */
*(int *)dest = 4;
/* this will be made persistent */
uint64_t *tmp64dst = (void *)((uintptr_t)dest + 4096);
*tmp64dst = 50;
if (is_pmem) {
pmem_persist(tmp64dst, sizeof(*tmp64dst));
} else {
UT_ASSERTeq(pmem_msync(tmp64dst, sizeof(*tmp64dst)), 0);
}
uint16_t *tmp16dst = (void *)((uintptr_t)dest + 1024);
*tmp16dst = 21;
/* will appear as flushed/fenced in valgrind log */
pmem_flush(tmp16dst, sizeof(*tmp16dst));
/* shows strange behavior of memset in some cases */
memset(dest + dest_off, 0, bytes);
UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);
DONE(NULL);
}
| 2,755 | 31.423529 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_mt/obj_tx_mt.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_mt.c -- multi-threaded test for pmemobj_tx_*
*
* It checks that objects are removed from transactions before on abort/commit
* phase.
*/
#include "unittest.h"
#define THREADS 8
#define LOOPS 8
static PMEMobjpool *pop;
static PMEMoid tab;
static os_mutex_t mtx;
static void *
tx_alloc_free(void *arg)
{
volatile int locked;
for (int i = 0; i < LOOPS; ++i) {
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
tab = pmemobj_tx_zalloc(128, 1);
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
pmemobj_tx_free(tab);
tab = OID_NULL;
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
}
return NULL;
}
static void *
tx_snap(void *arg)
{
volatile int locked;
for (int i = 0; i < LOOPS; ++i) {
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
if (!OID_IS_NULL(tab))
pmemobj_tx_add_range(tab, 0, 8);
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
locked = 0;
}
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_mt");
os_mutex_init(&mtx);
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
if ((pop = pmemobj_create(argv[1], "mt", PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
int i = 0;
os_thread_t *threads = MALLOC(THREADS * sizeof(threads[0]));
for (int j = 0; j < THREADS / 2; ++j) {
PTHREAD_CREATE(&threads[i++], NULL, tx_alloc_free, NULL);
PTHREAD_CREATE(&threads[i++], NULL, tx_snap, NULL);
}
while (i > 0)
PTHREAD_JOIN(&threads[--i], NULL);
pmemobj_close(pop);
os_mutex_destroy(&mtx);
FREE(threads);
DONE(NULL);
}
| 3,515 | 24.294964 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_custom_alloc/vmem_custom_alloc.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_custom_alloc.c -- unit test for vmem_custom_alloc
*
* usage: vmem_custom_alloc (0-2) [directory]
*/
#include "unittest.h"
#define TEST_STRING_VALUE "Some test text, to check memory"
#define TEST_REPEAT_CREATE_POOLS (20)
static int custom_allocs;
static int custom_alloc_calls;
static int expect_malloc;
/*
* malloc_null -- custom malloc function with error
*
* This function updates statistics about custom alloc functions,
* and returns NULL.
*/
static void *
malloc_null(size_t size)
{
++custom_alloc_calls;
#ifdef _WIN32
/*
* Because Windows version requires UTF-16 string conversion
* which requires four malloc calls and one free to succeed due to
* long path support
*/
if (custom_alloc_calls < 6) {
custom_allocs++;
return malloc(size);
}
#endif
errno = ENOMEM;
return NULL;
}
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
/*
* pool_test -- test pool
*
* This function creates a memory pool in a file (if dir is not NULL),
* or in RAM (if dir is NULL) and allocates memory for the test.
*/
static void
pool_test(const char *dir)
{
VMEM *vmp = NULL;
if (dir != NULL) {
vmp = vmem_create(dir, VMEM_MIN_POOL);
} else {
/* allocate memory for function vmem_create_in_region() */
void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
}
if (vmp == NULL) {
if (dir == NULL) {
UT_FATAL("!vmem_create_in_region");
} else {
UT_FATAL("!vmem_create");
}
}
char *test = vmem_malloc(vmp, strlen(TEST_STRING_VALUE) + 1);
if (expect_malloc == 0) {
UT_ASSERTeq(test, NULL);
} else {
strcpy(test, TEST_STRING_VALUE);
UT_ASSERTeq(strcmp(test, TEST_STRING_VALUE), 0);
UT_ASSERT(vmem_malloc_usable_size(vmp, test) > 0);
vmem_free(vmp, test);
}
vmem_delete(vmp);
}
int
main(int argc, char *argv[])
{
int expect_custom_alloc = 0;
START(argc, argv, "vmem_custom_alloc");
if (argc < 2 || argc > 3 || strlen(argv[1]) != 1)
UT_FATAL("usage: %s (0-2) [directory]", argv[0]);
switch (argv[1][0]) {
case '0': {
/* use default allocator */
expect_custom_alloc = 0;
expect_malloc = 1;
break;
}
case '1': {
/* error in custom malloc function */
expect_custom_alloc = 1;
expect_malloc = 0;
vmem_set_funcs(malloc_null, free_custom,
realloc_custom, strdup_custom, NULL);
break;
}
case '2': {
/* use custom alloc functions */
expect_custom_alloc = 1;
expect_malloc = 1;
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
break;
}
default: {
UT_FATAL("usage: %s (0-2) [directory]", argv[0]);
break;
}
}
if (argc == 3) {
pool_test(argv[2]);
} else {
int i;
/* repeat create pool */
for (i = 0; i < TEST_REPEAT_CREATE_POOLS; ++i)
pool_test(NULL);
}
/* check memory leak in custom allocator */
UT_ASSERTeq(custom_allocs, 0);
if (expect_custom_alloc == 0) {
UT_ASSERTeq(custom_alloc_calls, 0);
} else {
UT_ASSERTne(custom_alloc_calls, 0);
}
DONE(NULL);
}
| 5,623 | 23.34632 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_mmap_dtor/win_mmap_dtor.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* win_mmap_dtor.c -- unit test for windows mmap destructor
*/
#include "unittest.h"
#include "os.h"
#include "win_mmap.h"
#define KILOBYTE (1 << 10)
#define MEGABYTE (1 << 20)
unsigned long long Mmap_align;
int
main(int argc, char *argv[])
{
START(argc, argv, "win_mmap_dtor");
if (argc != 2)
UT_FATAL("usage: %s path", argv[0]);
SYSTEM_INFO si;
GetSystemInfo(&si);
/* set pagesize for mmap */
Mmap_align = si.dwAllocationGranularity;
const char *path = argv[1];
int fd = os_open(path, O_RDWR);
UT_ASSERTne(fd, -1);
/*
* Input file has size equal to 2MB, but the mapping is 3MB.
* In this case mmap should map whole file and reserve 1MB
* of virtual address space for remaining part of the mapping.
*/
void *addr = mmap(NULL, 3 * MEGABYTE, PROT_READ, MAP_SHARED, fd, 0);
UT_ASSERTne(addr, MAP_FAILED);
MEMORY_BASIC_INFORMATION basic_info;
SIZE_T bytes_returned;
bytes_returned = VirtualQuery(addr, &basic_info,
sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, 2 * MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_COMMIT);
bytes_returned = VirtualQuery((char *)addr + 2 * MEGABYTE,
&basic_info, sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_RESERVE);
win_mmap_fini();
bytes_returned = VirtualQuery((char *)addr + 2 * MEGABYTE,
&basic_info, sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
/*
* region size can be bigger than 1MB because there was probably
* free space after this mapping
*/
UT_ASSERTeq(basic_info.State, MEM_FREE);
DONE(NULL);
}
| 3,293 | 30.673077 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file_win/mocks_windows.h | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of libc functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of pmem_map_file test.
* It would replace default implementation with mocked functions defined
* in pmem_map_file.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define os_posix_fallocate __wrap_os_posix_fallocate
#define os_ftruncate __wrap_os_ftruncate
#endif
| 2,123 | 41.48 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file_win/mocks_windows.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in pmem_map_file.c
* (Windows-specific)
*/
#include "unittest.h"
#define MAX_LEN (4 * 1024 * 1024)
/*
* posix_fallocate -- interpose on libc posix_fallocate()
*/
FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("posix_fallocate: off %ju len %ju", offset, len);
if (len > MAX_LEN)
return ENOSPC;
return _FUNC_REAL(os_posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* ftruncate -- interpose on libc ftruncate()
*/
FUNC_MOCK(os_ftruncate, int, int fd, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("ftruncate: len %ju", len);
if (len > MAX_LEN) {
errno = ENOSPC;
return -1;
}
return _FUNC_REAL(os_ftruncate)(fd, len);
}
FUNC_MOCK_END
| 2,383 | 34.58209 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file_win/pmem_map_file_win.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_map_file_win.c -- unit test for mapping persistent memory for raw access
*
* usage: pmem_map_file_win file
*/
#define _GNU_SOURCE
#include "unittest.h"
#include <stdlib.h>
#define CHECK_BYTES 4096 /* bytes to compare before/after map call */
ut_jmp_buf_t Jmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
ut_siglongjmp(Jmp);
}
#define PMEM_FILE_ALL_FLAGS\
(PMEM_FILE_CREATE|PMEM_FILE_EXCL|PMEM_FILE_SPARSE|PMEM_FILE_TMPFILE)
static int device_dax = 0;
/*
* parse_flags -- parse 'flags' string
*/
static int
parse_flags(const wchar_t *flags_str)
{
int ret = 0;
while (*flags_str != L'\0') {
switch (*flags_str) {
case L'0':
case L'-':
/* no flags */
break;
case L'T':
ret |= PMEM_FILE_TMPFILE;
break;
case L'S':
ret |= PMEM_FILE_SPARSE;
break;
case L'C':
ret |= PMEM_FILE_CREATE;
break;
case L'E':
ret |= PMEM_FILE_EXCL;
break;
case L'X':
/* not supported flag */
ret |= (PMEM_FILE_ALL_FLAGS + 1);
break;
case L'D':
device_dax = 1;
break;
default:
UT_FATAL("unknown flags: %c", *flags_str);
}
flags_str++;
};
return ret;
}
/*
* do_check -- check the mapping
*/
static void
do_check(int fd, void *addr, size_t mlen)
{
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
char pat[CHECK_BYTES];
char buf[CHECK_BYTES];
/* write some pattern to the file */
memset(pat, 0x5A, CHECK_BYTES);
WRITE(fd, pat, CHECK_BYTES);
if (memcmp(pat, addr, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
/* fill up mapped region with new pattern */
memset(pat, 0xA5, CHECK_BYTES);
memcpy(addr, pat, CHECK_BYTES);
UT_ASSERTeq(pmem_msync(addr, CHECK_BYTES), 0);
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
if (!ut_sigsetjmp(Jmp)) {
/* same memcpy from above should now fail */
memcpy(addr, pat, CHECK_BYTES);
} else {
UT_OUT("unmap successful");
}
LSEEK(fd, (os_off_t)0, SEEK_SET);
if (READ(fd, buf, CHECK_BYTES) == CHECK_BYTES) {
if (memcmp(pat, buf, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
}
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "pmem_map_file_win");
int fd;
void *addr;
size_t mlen;
size_t *mlenp;
const wchar_t *path;
unsigned long long len;
int flags;
int mode;
int is_pmem;
int *is_pmemp;
int use_mlen;
int use_is_pmem;
if (argc < 7)
UT_FATAL("usage: %s path len flags mode use_mlen "
"use_is_pmem ...", ut_toUTF8(argv[0]));
for (int i = 1; i + 5 < argc; i += 6) {
path = argv[i];
len = wcstoull(argv[i + 1], NULL, 0);
flags = parse_flags(argv[i + 2]);
mode = wcstol(argv[i + 3], NULL, 8);
use_mlen = _wtoi(argv[i + 4]);
use_is_pmem = _wtoi(argv[i + 5]);
mlen = SIZE_MAX;
if (use_mlen)
mlenp = &mlen;
else
mlenp = NULL;
if (use_is_pmem)
is_pmemp = &is_pmem;
else
is_pmemp = NULL;
char *upath = ut_toUTF8(path);
char *uflags = ut_toUTF8(argv[i + 2]);
UT_OUT("%s %lld %s %o %d %d",
upath, len, uflags, mode, use_mlen, use_is_pmem);
free(uflags);
free(upath);
addr = pmem_map_fileW(path, len, flags, mode, mlenp, is_pmemp);
if (addr == NULL) {
UT_OUT("!pmem_map_file");
continue;
}
if (use_mlen) {
UT_ASSERTne(mlen, SIZE_MAX);
UT_OUT("mapped_len %zu", mlen);
} else {
mlen = len;
}
if (addr) {
if ((flags & PMEM_FILE_TMPFILE) == 0 && !device_dax) {
fd = WOPEN(argv[i], O_RDWR);
if (!use_mlen) {
os_stat_t stbuf;
FSTAT(fd, &stbuf);
mlen = stbuf.st_size;
}
if (fd != -1) {
do_check(fd, addr, mlen);
(void) CLOSE(fd);
} else {
UT_OUT("!cannot open file: %s",
argv[i]);
}
} else {
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
}
}
}
DONEW(NULL);
}
/*
* Since libpmem is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmem_init)
MSVC_DESTR(libpmem_fini)
| 5,587 | 22.380753 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_locks/obj_tx_locks.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_locks.c -- unit test for transaction locks
*/
#include "unittest.h"
#define LAYOUT_NAME "direct"
#define NUM_LOCKS 2
#define NUM_THREADS 10
#define TEST_VALUE_A 5
#define TEST_VALUE_B 10
#define TEST_VALUE_C 15
#define BEGIN_TX(pop, mutexes, rwlocks)\
TX_BEGIN_PARAM((pop), TX_PARAM_MUTEX,\
&(mutexes)[0], TX_PARAM_MUTEX, &(mutexes)[1], TX_PARAM_RWLOCK,\
&(rwlocks)[0], TX_PARAM_RWLOCK, &(rwlocks)[1], TX_PARAM_NONE)
#define BEGIN_TX_OLD(pop, mutexes, rwlocks)\
TX_BEGIN_LOCK((pop), TX_LOCK_MUTEX,\
&(mutexes)[0], TX_LOCK_MUTEX, &(mutexes)[1], TX_LOCK_RWLOCK,\
&(rwlocks)[0], TX_LOCK_RWLOCK, &(rwlocks)[1], TX_LOCK_NONE)
struct transaction_data {
PMEMmutex mutexes[NUM_LOCKS];
PMEMrwlock rwlocks[NUM_LOCKS];
int a;
int b;
int c;
};
static PMEMobjpool *Pop;
/*
* do_tx -- (internal) thread-friendly transaction
*/
static void *
do_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_ONABORT { /* not called */
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_tx_old -- (internal) thread-friendly transaction, tests deprecated macros
*/
static void *
do_tx_old(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX_OLD(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_ONABORT { /* not called */
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_aborted_tx -- (internal) thread-friendly aborted transaction
*/
static void *
do_aborted_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
pmemobj_tx_abort(EINVAL);
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
data->a = TEST_VALUE_B;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_nested_tx-- (internal) thread-friendly nested transaction
*/
static void *
do_nested_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_END
} TX_ONCOMMIT {
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_aborted_nested_tx -- (internal) thread-friendly aborted nested transaction
*/
static void *
do_aborted_nested_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_C;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
pmemobj_tx_abort(EINVAL);
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
data->a = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
UT_ASSERT(data->a == TEST_VALUE_A);
data->c = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
UT_ASSERT(data->b == TEST_VALUE_B);
UT_ASSERT(data->c == TEST_VALUE_C);
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->a == TEST_VALUE_B);
data->b = TEST_VALUE_A;
} TX_END
return NULL;
}
static void
run_mt_test(void *(*worker)(void *), void *arg)
{
os_thread_t thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i) {
PTHREAD_CREATE(&thread[i], NULL, worker, arg);
}
for (int i = 0; i < NUM_THREADS; ++i) {
PTHREAD_JOIN(&thread[i], NULL);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_locks");
if (argc > 3)
UT_FATAL("usage: %s <file> [m]", argv[0]);
if ((Pop = pmemobj_create(argv[1], LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
int multithread = 0;
if (argc == 3) {
multithread = (argv[2][0] == 'm');
if (!multithread)
UT_FATAL("wrong test type supplied %c", argv[1][0]);
}
PMEMoid root = pmemobj_root(Pop, sizeof(struct transaction_data));
struct transaction_data *test_obj =
(struct transaction_data *)pmemobj_direct(root);
if (multithread) {
run_mt_test(do_tx, test_obj);
} else {
do_tx(test_obj);
do_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_aborted_tx, test_obj);
} else {
do_aborted_tx(test_obj);
do_aborted_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_nested_tx, test_obj);
} else {
do_nested_tx(test_obj);
do_nested_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_aborted_nested_tx, test_obj);
} else {
do_aborted_nested_tx(test_obj);
do_aborted_nested_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_B);
UT_ASSERT(test_obj->b == TEST_VALUE_A);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
/* test that deprecated macros still work */
UT_COMPILE_ERROR_ON((int)TX_LOCK_NONE != (int)TX_PARAM_NONE);
UT_COMPILE_ERROR_ON((int)TX_LOCK_MUTEX != (int)TX_PARAM_MUTEX);
UT_COMPILE_ERROR_ON((int)TX_LOCK_RWLOCK != (int)TX_PARAM_RWLOCK);
if (multithread) {
run_mt_test(do_tx_old, test_obj);
} else {
do_tx_old(test_obj);
do_tx_old(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
pmemobj_close(Pop);
DONE(NULL);
}
| 7,682 | 24.695652 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_recovery/blk_recovery.c | /*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_recovery.c -- unit test for pmemblk recovery
*
* usage: blk_recovery bsize file first_lba lba
*
*/
#include "unittest.h"
#include <sys/param.h>
#include "blk.h"
#include "btt_layout.h"
#include <endian.h>
static size_t Bsize;
/*
* construct -- build a buffer for writing
*/
static void
construct(unsigned char *buf)
{
static int ord = 1;
for (int i = 0; i < Bsize; i++)
buf[i] = ord;
ord++;
if (ord > 255)
ord = 1;
}
/*
* ident -- identify what a buffer holds
*/
static char *
ident(unsigned char *buf)
{
static char descr[100];
unsigned val = *buf;
for (int i = 1; i < Bsize; i++)
if (buf[i] != val) {
sprintf(descr, "{%u} TORN at byte %d", val, i);
return descr;
}
sprintf(descr, "{%u}", val);
return descr;
}
static ut_jmp_buf_t Jmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
UT_OUT("signal: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_recovery");
if (argc != 5)
UT_FATAL("usage: %s bsize file first_lba lba", argv[0]);
Bsize = strtoul(argv[1], NULL, 0);
const char *path = argv[2];
PMEMblkpool *handle;
if ((handle = pmemblk_create(path, Bsize, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!%s: pmemblk_create", path);
UT_OUT("%s block size %zu usable blocks %zu",
argv[1], Bsize, pmemblk_nblock(handle));
/* write the first lba */
os_off_t lba = STRTOL(argv[3], NULL, 0);
unsigned char *buf = MALLOC(Bsize);
construct(buf);
if (pmemblk_write(handle, buf, lba) < 0)
UT_FATAL("!write lba %zu", lba);
UT_OUT("write lba %zu: %s", lba, ident(buf));
/* reach into the layout and write-protect the map */
struct btt_info *infop = (void *)((char *)handle +
roundup(sizeof(struct pmemblk), BLK_FORMAT_DATA_ALIGN));
char *mapaddr = (char *)infop + le32toh(infop->mapoff);
char *flogaddr = (char *)infop + le32toh(infop->flogoff);
UT_OUT("write-protecting map, length %zu",
(size_t)(flogaddr - mapaddr));
MPROTECT(mapaddr, (size_t)(flogaddr - mapaddr), PROT_READ);
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
/* map each file argument with the given map type */
lba = STRTOL(argv[4], NULL, 0);
construct(buf);
if (!ut_sigsetjmp(Jmp)) {
if (pmemblk_write(handle, buf, lba) < 0)
UT_FATAL("!write lba %zu", lba);
else
UT_FATAL("write lba %zu: %s", lba, ident(buf));
}
pmemblk_close(handle);
FREE(buf);
int result = pmemblk_check(path, Bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", path);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", path);
else
UT_OUT("%s: consistent", path);
DONE(NULL);
}
| 4,446 | 24.854651 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/out_err_mt/out_err_mt.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out_err_mt.c -- unit test for error messages
*/
#include <sys/types.h>
#include <stdarg.h>
#include <errno.h>
#include "unittest.h"
#include "valgrind_internal.h"
#include "util.h"
#define NUM_THREADS 16
static void
print_errors(const char *msg)
{
UT_OUT("%s", msg);
UT_OUT("PMEM: %s", pmem_errormsg());
UT_OUT("PMEMOBJ: %s", pmemobj_errormsg());
UT_OUT("PMEMLOG: %s", pmemlog_errormsg());
UT_OUT("PMEMBLK: %s", pmemblk_errormsg());
UT_OUT("PMEMCTO: %s", pmemcto_errormsg());
UT_OUT("VMEM: %s", vmem_errormsg());
UT_OUT("PMEMPOOL: %s", pmempool_errormsg());
}
static void
check_errors(unsigned ver)
{
int ret;
int err_need;
int err_found;
ret = sscanf(pmem_errormsg(),
"libpmem major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION);
ret = sscanf(pmemobj_errormsg(),
"libpmemobj major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION);
ret = sscanf(pmemlog_errormsg(),
"libpmemlog major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION);
ret = sscanf(pmemblk_errormsg(),
"libpmemblk major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION);
ret = sscanf(pmemcto_errormsg(),
"libpmemcto major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMCTO_MAJOR_VERSION);
ret = sscanf(vmem_errormsg(),
"libvmem major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION);
ret = sscanf(pmempool_errormsg(),
"libpmempool major version mismatch (need %d, found %d)",
&err_need, &err_found);
UT_ASSERTeq(ret, 2);
UT_ASSERTeq(err_need, ver);
UT_ASSERTeq(err_found, PMEMPOOL_MAJOR_VERSION);
}
static void *
do_test(void *arg)
{
unsigned ver = *(unsigned *)arg;
pmem_check_version(ver, 0);
pmemobj_check_version(ver, 0);
pmemlog_check_version(ver, 0);
pmemblk_check_version(ver, 0);
pmemcto_check_version(ver, 0);
vmem_check_version(ver, 0);
pmempool_check_version(ver, 0);
check_errors(ver);
return NULL;
}
static void
run_mt_test(void *(*worker)(void *))
{
os_thread_t thread[NUM_THREADS];
unsigned ver[NUM_THREADS];
for (unsigned i = 0; i < NUM_THREADS; ++i) {
ver[i] = 10000 + i;
PTHREAD_CREATE(&thread[i], NULL, worker, &ver[i]);
}
for (unsigned i = 0; i < NUM_THREADS; ++i) {
PTHREAD_JOIN(&thread[i], NULL);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "out_err_mt");
if (argc != 6)
UT_FATAL("usage: %s file1 file2 file3 file4 dir",
argv[0]);
print_errors("start");
PMEMobjpool *pop = pmemobj_create(argv[1], "test",
PMEMOBJ_MIN_POOL, 0666);
PMEMlogpool *plp = pmemlog_create(argv[2],
PMEMLOG_MIN_POOL, 0666);
PMEMblkpool *pbp = pmemblk_create(argv[3],
128, PMEMBLK_MIN_POOL, 0666);
PMEMctopool *pcp = pmemcto_create(argv[4], "test",
PMEMCTO_MIN_POOL, 0666);
VMEM *vmp = vmem_create(argv[5], VMEM_MIN_POOL);
util_init();
pmem_check_version(10000, 0);
pmemobj_check_version(10001, 0);
pmemlog_check_version(10002, 0);
pmemblk_check_version(10003, 0);
pmemcto_check_version(10004, 0);
vmem_check_version(10005, 0);
pmempool_check_version(10006, 0);
print_errors("version check");
void *ptr = NULL;
/*
* We are testing library error reporting and we don't want this test
* to fail under memcheck.
*/
VALGRIND_DO_DISABLE_ERROR_REPORTING;
pmem_msync(ptr, 1);
VALGRIND_DO_ENABLE_ERROR_REPORTING;
print_errors("pmem_msync");
int ret;
PMEMoid oid;
ret = pmemobj_alloc(pop, &oid, 0, 0, NULL, NULL);
UT_ASSERTeq(ret, -1);
print_errors("pmemobj_alloc");
pmemlog_append(plp, NULL, PMEMLOG_MIN_POOL);
print_errors("pmemlog_append");
size_t nblock = pmemblk_nblock(pbp);
pmemblk_set_error(pbp, (long long)nblock + 1);
print_errors("pmemblk_set_error");
ret = pmemcto_check(argv[4], "xxx");
UT_ASSERTeq(ret, -1);
print_errors("pmemcto_check");
VMEM *vmp2 = vmem_create_in_region(NULL, 1);
UT_ASSERTeq(vmp2, NULL);
print_errors("vmem_create_in_region");
run_mt_test(do_test);
pmemobj_close(pop);
pmemlog_close(plp);
pmemblk_close(pbp);
pmemcto_close(pcp);
vmem_delete(vmp);
PMEMpoolcheck *ppc;
struct pmempool_check_args args = {NULL, };
ppc = pmempool_check_init(&args, sizeof(args) / 2);
UT_ASSERTeq(ppc, NULL);
print_errors("pmempool_check_init");
DONE(NULL);
}
| 6,370 | 27.066079 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_api/libpmempool_test.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_test -- test of libpmempool.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include "unittest.h"
/*
* Exact copy of the struct pmempool_check_args from libpmempool 1.0 provided to
* test libpmempool against various pmempool_check_args structure versions.
*/
struct pmempool_check_args_1_0 {
const char *path;
const char *backup_path;
enum pmempool_pool_type pool_type;
int flags;
};
/*
* check_pool -- check given pool
*/
static void
check_pool(struct pmempool_check_args *args, size_t args_size)
{
const char *status2str[] = {
[PMEMPOOL_CHECK_RESULT_CONSISTENT] = "consistent",
[PMEMPOOL_CHECK_RESULT_NOT_CONSISTENT] = "not consistent",
[PMEMPOOL_CHECK_RESULT_REPAIRED] = "repaired",
[PMEMPOOL_CHECK_RESULT_CANNOT_REPAIR] = "cannot repair",
[PMEMPOOL_CHECK_RESULT_ERROR] = "fatal",
};
PMEMpoolcheck *ppc = pmempool_check_init(args, args_size);
if (!ppc) {
char buff[UT_MAX_ERR_MSG];
ut_strerror(errno, buff, UT_MAX_ERR_MSG);
UT_OUT("Error: %s", buff);
return;
}
struct pmempool_check_status *status = NULL;
while ((status = pmempool_check(ppc)) != NULL) {
switch (status->type) {
case PMEMPOOL_CHECK_MSG_TYPE_ERROR:
UT_OUT("%s", status->str.msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_INFO:
UT_OUT("%s", status->str.msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_QUESTION:
UT_OUT("%s", status->str.msg);
status->str.answer = "yes";
break;
default:
pmempool_check_end(ppc);
exit(EXIT_FAILURE);
}
}
enum pmempool_check_result ret = pmempool_check_end(ppc);
UT_OUT("status = %s", status2str[ret]);
}
/*
* print_usage -- print usage of program
*/
static void
print_usage(char *name)
{
UT_OUT("Usage: %s [-t <pool_type>] [-r <repair>] [-d <dry_run>] "
"[-y <always_yes>] [-f <flags>] [-a <advanced>] "
"[-b <backup_path>] <pool_path>", name);
}
/*
* set_flag -- parse the value and set the flag according to a obtained value
*/
static void
set_flag(const char *value, int *flags, int flag)
{
if (atoi(value) > 0)
*flags |= flag;
else
*flags &= ~flag;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "libpmempool_test");
int opt;
struct pmempool_check_args_1_0 args = {
.path = NULL,
.backup_path = NULL,
.pool_type = PMEMPOOL_POOL_TYPE_LOG,
.flags = PMEMPOOL_CHECK_FORMAT_STR |
PMEMPOOL_CHECK_REPAIR | PMEMPOOL_CHECK_VERBOSE
};
size_t args_size = sizeof(struct pmempool_check_args_1_0);
while ((opt = getopt(argc, argv, "t:r:d:a:y:s:b:")) != -1) {
switch (opt) {
case 't':
if (strcmp(optarg, "blk") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_BLK;
} else if (strcmp(optarg, "log") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_LOG;
} else if (strcmp(optarg, "obj") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_OBJ;
} else if (strcmp(optarg, "btt") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_BTT;
} else {
args.pool_type =
(uint32_t)strtoul(optarg, NULL, 0);
}
break;
case 'r':
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_REPAIR);
break;
case 'd':
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_DRY_RUN);
break;
case 'a':
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_ADVANCED);
break;
case 'y':
set_flag(optarg, &args.flags,
PMEMPOOL_CHECK_ALWAYS_YES);
break;
case 's':
args_size = strtoul(optarg, NULL, 0);
break;
case 'b':
args.backup_path = optarg;
break;
default:
print_usage(argv[0]);
UT_FATAL("unknown option: %c", opt);
}
}
if (optind < argc) {
args.path = argv[optind];
}
check_pool((struct pmempool_check_args *)&args, args_size);
DONE(NULL);
}
| 5,268 | 26.731579 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_nblock/blk_nblock.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_nblock.c -- unit test for pmemblk_nblock()
*
* usage: blk_nblock bsize:file...
*
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_nblock");
if (argc < 2)
UT_FATAL("usage: %s bsize:file...", argv[0]);
/* map each file argument with the given map type */
for (int arg = 1; arg < argc; arg++) {
char *fname;
size_t bsize = strtoul(argv[arg], &fname, 0);
if (*fname != ':')
UT_FATAL("usage: %s bsize:file...", argv[0]);
fname++;
PMEMblkpool *handle;
handle = pmemblk_create(fname, bsize, 0, S_IWUSR | S_IRUSR);
if (handle == NULL) {
UT_OUT("!%s: pmemblk_create", fname);
} else {
UT_OUT("%s: block size %zu usable blocks: %zu",
fname, bsize, pmemblk_nblock(handle));
UT_ASSERTeq(pmemblk_bsize(handle), bsize);
pmemblk_close(handle);
int result = pmemblk_check(fname, bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", fname);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent",
fname);
else {
UT_ASSERTeq(pmemblk_check(fname, bsize + 1),
-1);
UT_ASSERTeq(pmemblk_check(fname, 0), 1);
handle = pmemblk_open(fname, 0);
UT_ASSERTeq(pmemblk_bsize(handle), bsize);
pmemblk_close(handle);
}
}
}
DONE(NULL);
}
| 2,873 | 32.034483 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_non_zero/blk_non_zero.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_non_zero.c -- unit test for pmemblk_read/write/set_zero/set_error
*
* usage: blk_non_zero bsize file func operation:lba...
*
* func is 'c' or 'o' (create or open)
* operations are 'r' or 'w' or 'z' or 'e'
*
*/
#define _GNU_SOURCE
#include <sys/param.h>
#include "unittest.h"
#include "blk.h"
static size_t Bsize;
/*
* construct -- build a buffer for writing
*/
static void
construct(unsigned char *buf)
{
static int ord = 1;
for (int i = 0; i < Bsize; i++)
buf[i] = ord;
ord++;
if (ord > 255)
ord = 1;
}
/*
* ident -- identify what a buffer holds
*/
static char *
ident(unsigned char *buf)
{
static char descr[100];
unsigned val = *buf;
for (int i = 1; i < Bsize; i++)
if (buf[i] != val) {
sprintf(descr, "{%u} TORN at byte %d", val, i);
return descr;
}
sprintf(descr, "{%u}", val);
return descr;
}
/*
* is_zeroed -- read is_zeroed flag from header
*/
static int
is_zeroed(const char *path)
{
int fd = OPEN(path, O_RDWR);
os_stat_t stbuf;
FSTAT(fd, &stbuf);
void *addr = MMAP(NULL, (size_t)stbuf.st_size, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
struct pmemblk *header = addr;
int ret = header->is_zeroed;
MUNMAP(addr, (size_t)stbuf.st_size);
CLOSE(fd);
return ret;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_non_zero");
if (argc < 5)
UT_FATAL("usage: %s bsize file func [file_size] op:lba...",
argv[0]);
int read_arg = 1;
Bsize = strtoul(argv[read_arg++], NULL, 0);
const char *path = argv[read_arg++];
PMEMblkpool *handle = NULL;
switch (*argv[read_arg++]) {
case 'c': {
size_t fsize = strtoul(argv[read_arg++], NULL, 0);
handle = pmemblk_create(path, Bsize, fsize,
S_IRUSR | S_IWUSR);
if (handle == NULL)
UT_FATAL("!%s: pmemblk_create", path);
break;
}
case 'o':
handle = pmemblk_open(path, Bsize);
if (handle == NULL)
UT_FATAL("!%s: pmemblk_open", path);
break;
default:
UT_FATAL("unrecognized command %s", argv[read_arg - 1]);
}
UT_OUT("%s block size %zu usable blocks %zu",
argv[1], Bsize, pmemblk_nblock(handle));
UT_OUT("is zeroed:\t%d", is_zeroed(path));
unsigned char *buf = MALLOC(Bsize);
if (buf == NULL)
UT_FATAL("cannot allocate buf");
/* map each file argument with the given map type */
for (; read_arg < argc; read_arg++) {
if (strchr("rwze", argv[read_arg][0]) == NULL ||
argv[read_arg][1] != ':')
UT_FATAL("op must be r: or w: or z: or e:");
os_off_t lba = STRTOL(&argv[read_arg][2], NULL, 0);
switch (argv[read_arg][0]) {
case 'r':
if (pmemblk_read(handle, buf, lba) < 0)
UT_OUT("!read lba %zu", lba);
else
UT_OUT("read lba %zu: %s", lba,
ident(buf));
break;
case 'w':
construct(buf);
if (pmemblk_write(handle, buf, lba) < 0)
UT_OUT("!write lba %zu", lba);
else
UT_OUT("write lba %zu: %s", lba,
ident(buf));
break;
case 'z':
if (pmemblk_set_zero(handle, lba) < 0)
UT_OUT("!set_zero lba %zu", lba);
else
UT_OUT("set_zero lba %zu", lba);
break;
case 'e':
if (pmemblk_set_error(handle, lba) < 0)
UT_OUT("!set_error lba %zu", lba);
else
UT_OUT("set_error lba %zu", lba);
break;
}
}
FREE(buf);
pmemblk_close(handle);
int result = pmemblk_check(path, Bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", path);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", path);
DONE(NULL);
}
| 5,032 | 23.31401 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_invalid/obj_tx_invalid.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_invalid.c -- tests which transactional functions are available in
* which transaction stages
*/
#include <stddef.h>
#include "file.h"
#include "unittest.h"
/*
* Layout definition
*/
POBJ_LAYOUT_BEGIN(tx_invalid);
POBJ_LAYOUT_ROOT(tx_invalid, struct dummy_root);
POBJ_LAYOUT_TOID(tx_invalid, struct dummy_node);
POBJ_LAYOUT_END(tx_invalid);
struct dummy_node {
int value;
};
struct dummy_root {
TOID(struct dummy_node) node;
};
int
main(int argc, char *argv[])
{
if (argc != 3)
UT_FATAL("usage: %s file-name op", argv[0]);
START(argc, argv, "obj_tx_invalid %s", argv[2]);
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(tx_invalid) != 1);
PMEMobjpool *pop;
const char *path = argv[1];
int exists = util_file_exists(path);
if (exists < 0)
UT_FATAL("!util_file_exists");
if (!exists) {
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(tx_invalid),
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) {
UT_FATAL("!pmemobj_create %s", path);
}
} else {
if ((pop = pmemobj_open(path, POBJ_LAYOUT_NAME(tx_invalid)))
== NULL) {
UT_FATAL("!pmemobj_open %s", path);
}
}
PMEMoid oid = pmemobj_first(pop);
if (OID_IS_NULL(oid)) {
if (pmemobj_alloc(pop, &oid, 10, 1, NULL, NULL))
UT_FATAL("!pmemobj_alloc");
} else {
UT_ASSERTeq(pmemobj_type_num(oid), 1);
}
if (strcmp(argv[2], "alloc") == 0)
pmemobj_tx_alloc(10, 1);
else if (strcmp(argv[2], "alloc-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_alloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "alloc-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_alloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "alloc-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_alloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "alloc-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_alloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "alloc-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_alloc(10, 1);
}
else if (strcmp(argv[2], "zalloc") == 0)
pmemobj_tx_zalloc(10, 1);
else if (strcmp(argv[2], "zalloc-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_zalloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "zalloc-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_zalloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "zalloc-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_zalloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "zalloc-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_zalloc(10, 1);
} TX_END
} else if (strcmp(argv[2], "zalloc-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_zalloc(10, 1);
}
else if (strcmp(argv[2], "strdup") == 0)
pmemobj_tx_strdup("aaa", 1);
else if (strcmp(argv[2], "strdup-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_strdup("aaa", 1);
} TX_END
} else if (strcmp(argv[2], "strdup-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_strdup("aaa", 1);
} TX_END
} else if (strcmp(argv[2], "strdup-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_strdup("aaa", 1);
} TX_END
} else if (strcmp(argv[2], "strdup-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_strdup("aaa", 1);
} TX_END
} else if (strcmp(argv[2], "strdup-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_strdup("aaa", 1);
}
else if (strcmp(argv[2], "realloc") == 0)
pmemobj_tx_realloc(oid, 10, 1);
else if (strcmp(argv[2], "realloc-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_realloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "realloc-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_realloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "realloc-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_realloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "realloc-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_realloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "realloc-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_realloc(oid, 10, 1);
}
else if (strcmp(argv[2], "zrealloc") == 0)
pmemobj_tx_zrealloc(oid, 10, 1);
else if (strcmp(argv[2], "zrealloc-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_zrealloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "zrealloc-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_zrealloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "zrealloc-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_zrealloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "zrealloc-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_zrealloc(oid, 10, 1);
} TX_END
} else if (strcmp(argv[2], "zrealloc-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_zrealloc(oid, 10, 1);
}
else if (strcmp(argv[2], "free") == 0)
pmemobj_tx_free(oid);
else if (strcmp(argv[2], "free-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_free(oid);
} TX_END
} else if (strcmp(argv[2], "free-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_free(oid);
} TX_END
} else if (strcmp(argv[2], "free-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_free(oid);
} TX_END
} else if (strcmp(argv[2], "free-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_free(oid);
} TX_END
} else if (strcmp(argv[2], "free-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_free(oid);
}
else if (strcmp(argv[2], "add_range") == 0)
pmemobj_tx_add_range(oid, 0, 10);
else if (strcmp(argv[2], "add_range-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
} else if (strcmp(argv[2], "add_range-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
} else if (strcmp(argv[2], "add_range-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
} else if (strcmp(argv[2], "add_range-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
} else if (strcmp(argv[2], "add_range-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_add_range(oid, 0, 10);
}
else if (strcmp(argv[2], "add_range_direct") == 0)
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
else if (strcmp(argv[2], "add_range_direct-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
} TX_END
} else if (strcmp(argv[2], "add_range_direct-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
} TX_END
} else if (strcmp(argv[2], "add_range_direct-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
} TX_END
} else if (strcmp(argv[2], "add_range_direct-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
} TX_END
} else if (strcmp(argv[2], "add_range_direct-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10);
}
else if (strcmp(argv[2], "abort") == 0)
pmemobj_tx_abort(ENOMEM);
else if (strcmp(argv[2], "abort-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_END
} else if (strcmp(argv[2], "abort-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_abort(ENOMEM);
} TX_END
} else if (strcmp(argv[2], "abort-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_abort(ENOMEM);
} TX_END
} else if (strcmp(argv[2], "abort-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_abort(ENOMEM);
} TX_END
} else if (strcmp(argv[2], "abort-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_abort(ENOMEM);
}
else if (strcmp(argv[2], "commit") == 0)
pmemobj_tx_commit();
else if (strcmp(argv[2], "commit-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_commit();
} TX_END
} else if (strcmp(argv[2], "commit-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_commit();
} TX_END
} else if (strcmp(argv[2], "commit-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_commit();
} TX_END
} else if (strcmp(argv[2], "commit-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_commit();
} TX_END
} else if (strcmp(argv[2], "commit-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_commit();
}
else if (strcmp(argv[2], "end") == 0)
pmemobj_tx_end();
else if (strcmp(argv[2], "end-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_end();
} TX_END
} else if (strcmp(argv[2], "end-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_end();
pmemobj_close(pop);
exit(0);
} TX_END
} else if (strcmp(argv[2], "end-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_end();
pmemobj_close(pop);
exit(0);
} TX_END
} else if (strcmp(argv[2], "end-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_end();
pmemobj_close(pop);
exit(0);
} TX_END
} else if (strcmp(argv[2], "end-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_end();
}
else if (strcmp(argv[2], "process") == 0)
pmemobj_tx_process();
else if (strcmp(argv[2], "process-in-work") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_process();
} TX_END
} else if (strcmp(argv[2], "process-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
pmemobj_tx_process();
} TX_END
} else if (strcmp(argv[2], "process-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
pmemobj_tx_process();
} TX_END
} else if (strcmp(argv[2], "process-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
pmemobj_tx_process();
pmemobj_tx_end();
pmemobj_close(pop);
exit(0);
} TX_END
} else if (strcmp(argv[2], "process-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
pmemobj_tx_process();
}
else if (strcmp(argv[2], "begin") == 0) {
TX_BEGIN(pop) {
} TX_END
} else if (strcmp(argv[2], "begin-in-work") == 0) {
TX_BEGIN(pop) {
TX_BEGIN(pop) {
} TX_END
} TX_END
} else if (strcmp(argv[2], "begin-in-abort") == 0) {
TX_BEGIN(pop) {
pmemobj_tx_abort(ENOMEM);
} TX_ONABORT {
TX_BEGIN(pop) {
} TX_END
} TX_END
} else if (strcmp(argv[2], "begin-in-commit") == 0) {
TX_BEGIN(pop) {
} TX_ONCOMMIT {
TX_BEGIN(pop) {
} TX_END
} TX_END
} else if (strcmp(argv[2], "begin-in-finally") == 0) {
TX_BEGIN(pop) {
} TX_FINALLY {
TX_BEGIN(pop) {
} TX_END
} TX_END
} else if (strcmp(argv[2], "begin-after-tx") == 0) {
TX_BEGIN(pop) {
} TX_END
TX_BEGIN(pop) {
} TX_END
}
pmemobj_close(pop);
DONE(NULL);
}
| 12,728 | 25.463617 | 75 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_valgrind/vmmalloc_valgrind.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_valgrind.c -- unit test for libvmmalloc valgrind
*
* usage: vmmalloc_valgrind <test-number>
*
* test-number can be a number from 0 to 2
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
int *ptr;
int test_case = -1;
START(argc, argv, "vmmalloc_valgrind");
if ((argc != 2) || (test_case = atoi(argv[1])) > 2)
UT_FATAL("usage: %s <test-number from 0 to 2>",
argv[0]);
switch (test_case) {
case 0: {
UT_OUT("remove all allocations");
ptr = malloc(sizeof(int));
if (ptr == NULL)
UT_FATAL("!malloc");
free(ptr);
break;
}
case 1: {
UT_OUT("memory leaks");
ptr = malloc(sizeof(int));
if (ptr == NULL)
UT_FATAL("!malloc");
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
break;
}
case 2: {
UT_OUT("heap block overrun");
ptr = malloc(12 * sizeof(int));
if (ptr == NULL)
UT_FATAL("!malloc");
/* heap block overrun */
ptr[12] = 7;
free(ptr);
break;
}
default: {
UT_FATAL("!unknown test-number");
}
}
DONE(NULL);
}
| 2,663 | 27.340426 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_pool_lock/blk_pool_lock.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_pool_lock.c -- unit test which checks whether it's possible to
* simultaneously open the same blk pool
*/
#include "unittest.h"
static void
test_reopen(const char *path)
{
PMEMblkpool *blk1 = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!blk1)
UT_FATAL("!create");
PMEMblkpool *blk2 = pmemblk_open(path, 4096);
if (blk2)
UT_FATAL("pmemblk_open should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemblk_open failed but for unexpected reason");
pmemblk_close(blk1);
blk2 = pmemblk_open(path, 4096);
if (!blk2)
UT_FATAL("pmemobj_open should succeed after close");
pmemblk_close(blk2);
UNLINK(path);
}
#ifndef _WIN32
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
pid_t pid = fork();
PMEMblkpool *blk;
char *path = argv[1];
if (pid < 0)
UT_FATAL("fork failed");
if (pid == 0) {
/* child */
if (sleep)
usleep(sleep);
while (os_access(path, R_OK))
usleep(100 * 1000);
blk = pmemblk_open(path, 4096);
if (blk)
UT_FATAL("pmemblk_open after fork should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemblk_open after fork failed but for "
"unexpected reason");
exit(0);
}
blk = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!blk)
UT_FATAL("!create");
int status;
if (waitpid(pid, &status, 0) < 0)
UT_FATAL("!waitpid failed");
if (!WIFEXITED(status))
UT_FATAL("child process failed");
pmemblk_close(blk);
UNLINK(path);
}
#else
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
PMEMblkpool *blk;
if (sleep > 0)
return;
char *path = argv[1];
/* before starting the 2nd process, create a pool */
blk = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!blk)
UT_FATAL("!create");
/*
* "X" is pass as an additional param to the new process
* created by ut_spawnv to distinguish second process on Windows
*/
uintptr_t result = ut_spawnv(argc, argv, "X", NULL);
if (result != 0)
UT_FATAL("Create new process failed error: %d", GetLastError());
pmemblk_close(blk);
}
#endif
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_pool_lock");
if (argc < 2)
UT_FATAL("usage: %s path", argv[0]);
if (argc == 2) {
test_reopen(argv[1]);
test_open_in_different_process(argc, argv, 0);
for (unsigned i = 1; i < 100000; i *= 2)
test_open_in_different_process(argc, argv, i);
} else if (argc == 3) {
PMEMblkpool *blk;
/* 2nd arg used by windows for 2 process test */
blk = pmemblk_open(argv[1], 4096);
if (blk)
UT_FATAL("pmemblk_open after create process should "
"not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemblk_open after create process failed "
"but for unexpected reason");
}
DONE(NULL);
}
| 4,438 | 25.111765 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmem_addr_ext/rpmem_addr_ext.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_addr_ext.c -- advanced unittest for invalid target formats
*/
#include "unittest.h"
#include "librpmem.h"
#include "pool_hdr.h"
#include "set.h"
#include "util.h"
#include "out.h"
#include "rpmem_common.h"
#include "rpmem_fip_common.h"
#define POOL_SIZE (8 * 1024 * 1024) /* 8 MiB */
#define NLANES 32
#define MAX_TARGET_LENGTH 256
/*
* test_prepare -- prepare test environment
*/
static void
test_prepare()
{
/*
* Till fix introduced to libfabric in pull request
* https://github.com/ofiwg/libfabric/pull/2551 misuse of errno value
* lead to SIGSEGV.
*/
errno = 0;
}
/*
* test_create -- test case for creating remote pool
*/
static int
test_create(const char *target, void *pool)
{
const char *pool_set = "invalid.poolset";
unsigned nlanes = NLANES;
struct rpmem_pool_attr pool_attr;
memset(&pool_attr, 0, sizeof(pool_attr));
RPMEMpool *rpp = rpmem_create(target, pool_set, pool, POOL_SIZE,
&nlanes, &pool_attr);
UT_ASSERTeq(rpp, NULL);
return 0;
}
/*
* test_open -- test case for opening remote pool
*/
static int
test_open(const char *target, void *pool)
{
const char *pool_set = "invalid.poolset";
unsigned nlanes = NLANES;
struct rpmem_pool_attr pool_attr;
memset(&pool_attr, 0, sizeof(pool_attr));
RPMEMpool *rpp = rpmem_open(target, pool_set, pool, POOL_SIZE, &nlanes,
&pool_attr);
UT_ASSERTeq(rpp, NULL);
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmem_addr_ext");
if (argc < 2)
UT_FATAL("usage: rpmem_addr_ext <targets>");
const char *targets_file_name = argv[1];
char target[MAX_TARGET_LENGTH];
void *pool = PAGEALIGNMALLOC(POOL_SIZE);
FILE *targets_file = FOPEN(targets_file_name, "r");
while (fgets(target, sizeof(target), targets_file)) {
/* assume each target has new line at the end and remove it */
target[strlen(target) - 1] = '\0';
test_prepare();
test_create(target, pool);
test_prepare();
test_open(target, pool);
}
FCLOSE(targets_file);
FREE(pool);
DONE(NULL);
}
| 3,604 | 25.313869 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_check_allocations/vmem_check_allocations.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_check_allocations -- unit test for vmem_check_allocations
*
* usage: vmem_check_allocations [directory]
*/
#include "unittest.h"
#define TEST_MAX_ALLOCATION_SIZE (4L * 1024L * 1024L)
#define TEST_ALLOCS_SIZE (VMEM_MIN_POOL / 8)
/* buffer for all allocations */
static void *allocs[TEST_ALLOCS_SIZE];
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_check_allocations");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
size_t object_size;
for (object_size = 8; object_size <= TEST_MAX_ALLOCATION_SIZE;
object_size *= 2) {
size_t i;
size_t j;
if (dir == NULL) {
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool,
VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
/* vmem_create should align pool to 4MB */
UT_ASSERTeq(((uintptr_t)vmp) & ((4 << 20) - 1), 0);
}
memset(allocs, 0, sizeof(allocs));
for (i = 0; i < TEST_ALLOCS_SIZE; ++i) {
allocs[i] = vmem_malloc(vmp, object_size);
if (allocs[i] == NULL) {
/* out of memory in pool */
break;
}
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(allocs[i],
mem_pool, VMEM_MIN_POOL);
}
/* fill each allocation with a unique value */
memset(allocs[i], (char)i, object_size);
}
UT_ASSERT((i > 0) && (i + 1 < TEST_MAX_ALLOCATION_SIZE));
/* check for unexpected modifications of the data */
for (i = 0; i < TEST_ALLOCS_SIZE && allocs[i] != NULL; ++i) {
char *buffer = allocs[i];
for (j = 0; j < object_size; ++j) {
if (buffer[j] != (char)i)
UT_FATAL("Content of data object was "
"modified unexpectedly for "
"object size: %zu, id: %zu",
object_size, j);
}
}
for (i = 0; i < TEST_ALLOCS_SIZE && allocs[i] != NULL; ++i)
vmem_free(vmp, allocs[i]);
vmem_delete(vmp);
}
DONE(NULL);
}
| 3,711 | 28.696 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_create_win/vmem_create_win.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_create_win.c -- unit test for vmem_createW
*
* usage: vmem_create_win directory
*/
#include "unittest.h"
VMEM *Vmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
UT_OUT("signal: %s", os_strsignal(sig));
vmem_delete(Vmp);
DONEW(NULL);
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "vmem_create_win");
if (argc < 2 || argc > 3)
UT_FATAL("usage: %s directory", ut_toUTF8(argv[0]));
Vmp = vmem_createW(argv[1], VMEM_MIN_POOL);
if (Vmp == NULL)
UT_OUT("!vmem_create");
else {
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
if (SIGACTION(SIGSEGV, &v, NULL) != 0)
UT_FATAL("!sigaction");
/* try to dereference the opaque handle */
char x = *(char *)Vmp;
UT_OUT("x = %c", x);
}
UT_FATAL("no signal received");
}
| 2,461 | 28.662651 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush/mocks_posix.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_posix.c -- mocked functions used in pmem_has_auto_flush.c
*/
#include <fts.h>
#include "fs.h"
#include "unittest.h"
#define BUS_DEVICE_PATH "/sys/bus/nd/devices"
/*
* open -- open mock
*/
FUNC_MOCK(open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
va_list ap;
va_start(ap, flags);
int mode = va_arg(ap, int);
va_end(ap);
if (!strstr(path, BUS_DEVICE_PATH))
return _FUNC_REAL(open)(path, flags, mode);
const char *prefix = os_getenv("BUS_DEVICE_PATH");
char path2[PATH_MAX] = { 0 };
strcat(path2, prefix);
strcat(path2, path + strlen(BUS_DEVICE_PATH));
return _FUNC_REAL(open)(path2, flags, mode);
}
FUNC_MOCK_END
struct fs {
FTS *ft;
struct fs_entry entry;
};
/*
* fs_new -- creates fs traversal instance
*/
FUNC_MOCK(fs_new, struct fs *, const char *path)
FUNC_MOCK_RUN_DEFAULT {
if (!strstr(path, BUS_DEVICE_PATH))
return _FUNC_REAL(fs_new)(path);
const char *prefix = os_getenv("BUS_DEVICE_PATH");
char path2[PATH_MAX] = { 0 };
strcat(path2, prefix);
strcat(path2, path + strlen(BUS_DEVICE_PATH));
return _FUNC_REAL(fs_new)(path2);
}
FUNC_MOCK_END
/*
* os_stat -- os_stat mock to handle sysfs path
*/
FUNC_MOCK(os_stat, int, const char *path, os_stat_t *buf)
FUNC_MOCK_RUN_DEFAULT {
if (!strstr(path, BUS_DEVICE_PATH))
return _FUNC_REAL(os_stat)(path, buf);
const char *prefix = os_getenv("BUS_DEVICE_PATH");
char path2[PATH_MAX] = { 0 };
strcat(path2, prefix);
strcat(path2, path + strlen(BUS_DEVICE_PATH));
return _FUNC_REAL(os_stat)(path2, buf);
}
FUNC_MOCK_END
| 3,142 | 30.747475 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush/pmem_has_auto_flush.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_has_auto_flush.c -- unit test for pmem_has_auto_flush() function
*
* this test checks if function pmem_has_auto_flush handle sysfs path
* and persistence_domain file in proper way
*/
#include <string.h>
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_has_auto_flush");
if (argc != 1)
UT_FATAL("usage: %s path", argv[0]);
int ret = pmem_has_auto_flush();
UT_OUT("pmem_has_auto_flush %d", ret);
DONE(NULL);
}
| 2,065 | 35.245614 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_mix_allocations/vmem_mix_allocations.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_mix_allocations.c -- unit test for vmem_mix_allocations
*
* usage: vmem_mix_allocations [directory]
*/
#include "unittest.h"
#define COUNT 24
#define POOL_SIZE VMEM_MIN_POOL
#define MAX_SIZE (1 << (COUNT - 1)) /* 8MB */
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
size_t obj_size;
int *ptr[COUNT + 1];
int i = 0;
size_t sum_alloc = 0;
START(argc, argv, "vmem_mix_allocations");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20);
vmp = vmem_create_in_region(mem_pool, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
obj_size = MAX_SIZE;
/* test with multiple size of allocations from 8MB to 1B */
for (i = 0; i < COUNT; ++i, obj_size /= 2) {
ptr[i] = vmem_malloc(vmp, obj_size);
if (ptr[i] == NULL)
continue;
sum_alloc += obj_size;
/* check that pointer came from mem_pool */
if (dir == NULL)
UT_ASSERTrange(ptr[i], mem_pool, POOL_SIZE);
}
/* allocate more than half of pool size */
UT_ASSERT(sum_alloc * 2 > POOL_SIZE);
while (i > 0)
vmem_free(vmp, ptr[--i]);
vmem_delete(vmp);
DONE(NULL);
}
| 3,013 | 28.54902 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_init/libtest.h | /*
* Copyright 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef LIBTEST_H
#define LIBTEST_H
#include <stddef.h>
void *falloc(size_t size, int c);
#endif
| 1,701 | 41.55 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_init/vmmalloc_init.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_init.c -- unit test for libvmmalloc initialization
*
* usage: vmmalloc_init [d|l]
*/
#include <stdlib.h>
#include <dlfcn.h>
#include "unittest.h"
static void *(*Falloc)(size_t size, int val);
int
main(int argc, char *argv[])
{
void *handle = NULL;
void *ptr;
START(argc, argv, "vmmalloc_init");
if (argc > 2)
UT_FATAL("usage: %s [d|l]", argv[0]);
if (argc == 2) {
switch (argv[1][0]) {
case 'd':
UT_OUT("deep binding");
handle = dlopen("./libtest.so",
RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND);
break;
case 'l':
UT_OUT("lazy binding");
handle = dlopen("./libtest.so", RTLD_LAZY);
break;
default:
UT_FATAL("usage: %s [d|l]", argv[0]);
}
if (handle == NULL)
UT_OUT("dlopen: %s", dlerror());
UT_ASSERTne(handle, NULL);
Falloc = dlsym(handle, "falloc");
UT_ASSERTne(Falloc, NULL);
}
ptr = malloc(4321);
free(ptr);
if (argc == 2) {
/*
* NOTE: falloc calls malloc internally.
* If libtest is loaded with RTLD_DEEPBIND flag, then it will
* use its own lookup scope in preference to global symbols
* from already loaded (LD_PRELOAD) libvmmalloc. So, falloc
* will call the stock libc's malloc.
* However, since we override the malloc hooks, a call to libc's
* malloc will be redirected to libvmmalloc anyway, and the
* memory can be safely reclaimed using libvmmalloc's free.
*/
ptr = Falloc(4321, 0xaa);
free(ptr);
}
if (handle != NULL)
dlclose(handle);
DONE(NULL);
}
| 3,086 | 29.264706 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_init/libtest.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libtest.c -- a simple test library that uses malloc()
*
* This is used to test libvmmalloc behavior in case when an application
* loads a shared library depending on libc using RTLD_DEEPBIND option.
*/
#include <stdlib.h>
#include <string.h>
#include "libtest.h"
/*
* falloc -- allocate a block of size bytes and fill it with a constant byte
*
* The memory obtained from falloc() can be freed using free().
*/
void *
falloc(size_t size, int c)
{
void *ptr = malloc(size);
if (ptr)
memset(ptr, c, size);
return ptr;
}
| 2,140 | 36.561404 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_misc.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_misc.c -- miscellaneous test cases for rpmemd_obc module
*/
#include "rpmemd_obc_test_common.h"
/*
* client_send_disconnect -- connect, send specified number of bytes and
* disconnect
*/
static void
client_send_disconnect(char *target, void *msg, size_t size)
{
struct rpmem_ssh *ssh = clnt_connect(target);
if (size)
clnt_send(ssh, msg, size);
clnt_close(ssh);
}
/*
* client_econnreset -- test case for closing connection when operation on
* server is in progress - client side
*/
int
client_econnreset(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_create *msg = MALLOC(msg_size);
*msg = CREATE_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
rpmem_hton_msg_create(msg);
set_rpmem_cmd("server_econnreset");
{
/*
* Connect and disconnect immediately.
*/
client_send_disconnect(target, msg, 0);
}
{
/*
* Connect, send half of a message header and close the
* connection.
*/
client_send_disconnect(target, msg,
sizeof(struct rpmem_msg_hdr) / 2);
}
{
/*
* Connect, send only a message header and close the
* connection.
*/
client_send_disconnect(target, msg,
sizeof(struct rpmem_msg_hdr));
}
{
/*
* Connect, send half of a message and close the connection.
*/
client_send_disconnect(target, msg, msg_size / 2);
}
FREE(msg);
return 1;
}
/*
* server_econnreset -- test case for closing connection when operation on
* server is in progress - server side
*/
int
server_econnreset(const struct test_case *tc, int argc, char *argv[])
{
struct rpmemd_obc *rpdc;
int ret;
rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO);
UT_ASSERTne(rpdc, NULL);
ret = rpmemd_obc_status(rpdc, 0);
UT_ASSERTeq(ret, 0);
ret = rpmemd_obc_process(rpdc, &REQ_CB, NULL);
UT_ASSERTne(ret, 0);
rpmemd_obc_fini(rpdc);
return 0;
}
| 3,643 | 25.794118 | 75 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_open.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_open.c -- test cases for open request message
*/
#include "rpmemd_obc_test_common.h"
/*
* Number of cases for checking open request message. Must be kept in sync
* with client_bad_msg_open function.
*/
#define BAD_MSG_OPEN_COUNT 11
/*
* client_bad_msg_open -- check if server detects invalid open request
* messages
*/
static void
client_bad_msg_open(const char *ctarget)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_open *msg = MALLOC(msg_size);
for (int i = 0; i < BAD_MSG_OPEN_COUNT; i++) {
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = OPEN_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
switch (i) {
case 0:
msg->c.provider = 0;
break;
case 1:
msg->c.provider = MAX_RPMEM_PROV;
break;
case 2:
msg->pool_desc.size -= 1;
break;
case 3:
msg->pool_desc.size += 1;
break;
case 4:
msg->pool_desc.size = 0;
msg->hdr.size = sizeof(OPEN_MSG) +
msg->pool_desc.size;
break;
case 5:
msg->pool_desc.size = 1;
msg->hdr.size = sizeof(OPEN_MSG) +
msg->pool_desc.size;
break;
case 6:
msg->pool_desc.desc[0] = '\0';
break;
case 7:
msg->pool_desc.desc[POOL_DESC_SIZE / 2] = '\0';
break;
case 8:
msg->pool_desc.desc[POOL_DESC_SIZE - 1] = 'E';
break;
case 9:
msg->c.major = RPMEM_PROTO_MAJOR + 1;
break;
case 10:
msg->c.minor = RPMEM_PROTO_MINOR + 1;
break;
default:
UT_ASSERT(0);
}
rpmem_hton_msg_open(msg);
clnt_send(ssh, msg, msg_size);
clnt_wait_disconnect(ssh);
clnt_close(ssh);
}
FREE(msg);
FREE(target);
}
/*
* client_msg_open_noresp -- send open request message and don't expect a
* response
*/
static void
client_msg_open_noresp(const char *ctarget)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_open *msg = MALLOC(msg_size);
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = OPEN_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
rpmem_hton_msg_open(msg);
clnt_send(ssh, msg, msg_size);
clnt_wait_disconnect(ssh);
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_msg_open_resp -- send open request message and expect a response
* with specified status. If status is 0, validate open request response
* message
*/
static void
client_msg_open_resp(const char *ctarget, int status)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_open *msg = MALLOC(msg_size);
struct rpmem_msg_open_resp resp;
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = OPEN_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
rpmem_hton_msg_open(msg);
clnt_send(ssh, msg, msg_size);
clnt_recv(ssh, &resp, sizeof(resp));
rpmem_ntoh_msg_open_resp(&resp);
if (status) {
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
} else {
UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_OPEN_RESP);
UT_ASSERTeq(resp.hdr.size,
sizeof(struct rpmem_msg_open_resp));
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
UT_ASSERTeq(resp.ibc.port, PORT);
UT_ASSERTeq(resp.ibc.rkey, RKEY);
UT_ASSERTeq(resp.ibc.raddr, RADDR);
UT_ASSERTeq(resp.ibc.persist_method, PERSIST_METHOD);
}
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_open -- test case for open request message - client side
*/
int
client_open(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
set_rpmem_cmd("server_bad_msg");
client_bad_msg_open(target);
set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_OPEN);
client_msg_open_noresp(target);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_OPEN, 0);
client_msg_open_resp(target, 0);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_OPEN, 1);
client_msg_open_resp(target, 1);
return 1;
}
| 5,620 | 25.63981 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test.c | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test.c -- unit test for rpmemd_obc module
*/
#include "rpmemd_obc_test_common.h"
#include "out.h"
#include "os.h"
/*
* test_cases -- available test cases
*/
static struct test_case test_cases[] = {
TEST_CASE(server_bad_msg),
TEST_CASE(server_msg_noresp),
TEST_CASE(server_msg_resp),
TEST_CASE(client_bad_msg_hdr),
TEST_CASE(server_econnreset),
TEST_CASE(client_econnreset),
TEST_CASE(client_create),
TEST_CASE(client_open),
TEST_CASE(client_close),
TEST_CASE(client_set_attr),
};
#define NTESTS (sizeof(test_cases) / sizeof(test_cases[0]))
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmemd_obc");
out_init("rpmemd_obc",
"RPMEM_LOG_LEVEL",
"RPMEM_LOG_FILE", 0, 0);
rpmemd_log_init("rpmemd", os_getenv("RPMEMD_LOG_FILE"), 0);
rpmemd_log_level = rpmemd_log_level_from_str(
os_getenv("RPMEMD_LOG_LEVEL"));
rpmem_util_cmds_init();
TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS);
rpmem_util_cmds_fini();
rpmemd_log_close();
out_fini();
DONE(NULL);
}
| 2,619 | 30.190476 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_msg_hdr.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_msg_hdr.c -- test cases for message header
*/
#include "rpmemd_obc_test_common.h"
/*
* Number of cases for checking message header. Must be kept in sync with
* client_bad_msg_hdr function.
*/
#define BAD_MSG_HDR_COUNT 6
/*
* client_bad_msg_hdr -- test case for checking message header
*/
int
client_bad_msg_hdr(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
set_rpmem_cmd("server_bad_msg");
for (int i = 0; i < BAD_MSG_HDR_COUNT; i++) {
struct rpmem_ssh *ssh = clnt_connect(target);
struct rpmem_msg_hdr msg = MSG_HDR;
switch (i) {
case 0:
msg.size -= 1;
break;
case 1:
msg.size = 0;
break;
case 2:
msg.type = MAX_RPMEM_MSG_TYPE;
break;
case 3:
msg.type = RPMEM_MSG_TYPE_OPEN_RESP;
break;
case 4:
msg.type = RPMEM_MSG_TYPE_CREATE_RESP;
break;
case 5:
msg.type = RPMEM_MSG_TYPE_CLOSE_RESP;
break;
default:
UT_ASSERT(0);
}
rpmem_hton_msg_hdr(&msg);
clnt_send(ssh, &msg, sizeof(msg));
clnt_wait_disconnect(ssh);
clnt_close(ssh);
}
return 1;
}
| 2,747 | 27.926316 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_create.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_create.c -- test cases for create request message
*/
#include "rpmemd_obc_test_common.h"
/*
* Number of cases for checking create request message. Must be kept in sync
* with client_bad_msg_create function.
*/
#define BAD_MSG_CREATE_COUNT 11
/*
* client_bad_msg_create -- check if server detects invalid create request
* messages
*/
static void
client_bad_msg_create(const char *ctarget)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_create *msg = MALLOC(msg_size);
for (int i = 0; i < BAD_MSG_CREATE_COUNT; i++) {
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = CREATE_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
switch (i) {
case 0:
msg->c.provider = 0;
break;
case 1:
msg->c.provider = MAX_RPMEM_PROV;
break;
case 2:
msg->pool_desc.size -= 1;
break;
case 3:
msg->pool_desc.size += 1;
break;
case 4:
msg->pool_desc.size = 0;
msg->hdr.size = sizeof(CREATE_MSG) +
msg->pool_desc.size;
break;
case 5:
msg->pool_desc.size = 1;
msg->hdr.size = sizeof(CREATE_MSG) +
msg->pool_desc.size;
break;
case 6:
msg->pool_desc.desc[0] = '\0';
break;
case 7:
msg->pool_desc.desc[POOL_DESC_SIZE / 2] = '\0';
break;
case 8:
msg->pool_desc.desc[POOL_DESC_SIZE - 1] = 'E';
break;
case 9:
msg->c.major = RPMEM_PROTO_MAJOR + 1;
break;
case 10:
msg->c.minor = RPMEM_PROTO_MINOR + 1;
break;
default:
UT_ASSERT(0);
}
rpmem_hton_msg_create(msg);
clnt_send(ssh, msg, msg_size);
clnt_wait_disconnect(ssh);
clnt_close(ssh);
}
FREE(msg);
FREE(target);
}
/*
* client_msg_create_noresp -- send create request message and don't expect
* a response
*/
static void
client_msg_create_noresp(const char *ctarget)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_create *msg = MALLOC(msg_size);
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = CREATE_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
rpmem_hton_msg_create(msg);
clnt_send(ssh, msg, msg_size);
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_msg_create_resp -- send create request message and expect a response
* with specified status. If status is 0, validate create request response
* message
*/
static void
client_msg_create_resp(const char *ctarget, int status)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE;
struct rpmem_msg_create *msg = MALLOC(msg_size);
struct rpmem_msg_create_resp resp;
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = CREATE_MSG;
msg->hdr.size = msg_size;
memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE);
rpmem_hton_msg_create(msg);
clnt_send(ssh, msg, msg_size);
clnt_recv(ssh, &resp, sizeof(resp));
rpmem_ntoh_msg_create_resp(&resp);
if (status) {
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
} else {
UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_CREATE_RESP);
UT_ASSERTeq(resp.hdr.size,
sizeof(struct rpmem_msg_create_resp));
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
UT_ASSERTeq(resp.ibc.port, PORT);
UT_ASSERTeq(resp.ibc.rkey, RKEY);
UT_ASSERTeq(resp.ibc.raddr, RADDR);
UT_ASSERTeq(resp.ibc.persist_method, PERSIST_METHOD);
}
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_create -- test case for create request message - client side
*/
int
client_create(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
set_rpmem_cmd("server_bad_msg");
client_bad_msg_create(target);
set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_CREATE);
client_msg_create_noresp(target);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CREATE, 0);
client_msg_create_resp(target, 0);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CREATE, 1);
client_msg_create_resp(target, 1);
return 1;
}
| 5,680 | 26.052381 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_set_attr.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_set_attr.c -- test cases for set attributes request message
*/
#include "rpmemd_obc_test_common.h"
/*
* client_msg_set_attr_noresp -- send set attributes request message and don't
* expect a response
*/
static void
client_msg_set_attr_noresp(const char *ctarget)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(SET_ATTR_MSG);
struct rpmem_msg_set_attr *msg = MALLOC(msg_size);
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = SET_ATTR_MSG;
rpmem_hton_msg_set_attr(msg);
clnt_send(ssh, msg, msg_size);
clnt_wait_disconnect(ssh);
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_msg_set_attr_resp -- send set attributes request message and expect
* a response with specified status. If status is 0, validate set attributes
* request response message
*/
static void
client_msg_set_attr_resp(const char *ctarget, int status)
{
char *target = STRDUP(ctarget);
size_t msg_size = sizeof(SET_ATTR_MSG);
struct rpmem_msg_set_attr *msg = MALLOC(msg_size);
struct rpmem_msg_set_attr_resp resp;
struct rpmem_ssh *ssh = clnt_connect(target);
*msg = SET_ATTR_MSG;
rpmem_hton_msg_set_attr(msg);
clnt_send(ssh, msg, msg_size);
clnt_recv(ssh, &resp, sizeof(resp));
rpmem_ntoh_msg_set_attr_resp(&resp);
if (status) {
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
} else {
UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_SET_ATTR_RESP);
UT_ASSERTeq(resp.hdr.size,
sizeof(struct rpmem_msg_set_attr_resp));
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
}
clnt_close(ssh);
FREE(msg);
FREE(target);
}
/*
* client_set_attr -- test case for set attributes request message - client
* side
*/
int
client_set_attr(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_SET_ATTR);
client_msg_set_attr_noresp(target);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_SET_ATTR, 0);
client_msg_set_attr_resp(target, 0);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_SET_ATTR, 1);
client_msg_set_attr_resp(target, 1);
return 1;
}
| 3,770 | 29.168 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_common.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_common.c -- common definitions for rpmemd_obc tests
*/
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "os.h"
#include "rpmemd_obc_test_common.h"
#define CMD_BUFF_SIZE 4096
static const char *rpmem_cmd;
/*
* set_rpmem_cmd -- set RPMEM_CMD variable
*/
void
set_rpmem_cmd(const char *fmt, ...)
{
static char cmd_buff[CMD_BUFF_SIZE];
if (!rpmem_cmd) {
char *cmd = os_getenv(RPMEM_CMD_ENV);
UT_ASSERTne(cmd, NULL);
rpmem_cmd = STRDUP(cmd);
}
ssize_t ret;
size_t cnt = 0;
va_list ap;
va_start(ap, fmt);
ret = snprintf(&cmd_buff[cnt], CMD_BUFF_SIZE - cnt,
"%s ", rpmem_cmd);
UT_ASSERT(ret > 0);
cnt += (size_t)ret;
ret = vsnprintf(&cmd_buff[cnt], CMD_BUFF_SIZE - cnt, fmt, ap);
UT_ASSERT(ret > 0);
cnt += (size_t)ret;
va_end(ap);
ret = os_setenv(RPMEM_CMD_ENV, cmd_buff, 1);
UT_ASSERTeq(ret, 0);
/*
* Rpmem has internal RPMEM_CMD variable copy and it is assumed
* RPMEMD_CMD will not change its value during execution. To refresh the
* internal copy it must be destroyed and a instance must be initialized
* manually.
*/
rpmem_util_cmds_fini();
rpmem_util_cmds_init();
}
/*
* req_cb_check_req -- validate request attributes
*/
static void
req_cb_check_req(const struct rpmem_req_attr *req)
{
UT_ASSERTeq(req->nlanes, NLANES);
UT_ASSERTeq(req->pool_size, POOL_SIZE);
UT_ASSERTeq(req->provider, PROVIDER);
UT_ASSERTeq(strcmp(req->pool_desc, POOL_DESC), 0);
}
/*
* req_cb_check_pool_attr -- validate pool attributes
*/
static void
req_cb_check_pool_attr(const struct rpmem_pool_attr *pool_attr)
{
struct rpmem_pool_attr attr = POOL_ATTR_INIT;
UT_ASSERTeq(memcmp(&attr, pool_attr, sizeof(attr)), 0);
}
/*
* req_cb_create -- callback for create request operation
*
* This function behaves according to arguments specified via
* struct req_cb_arg.
*/
static int
req_cb_create(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req,
const struct rpmem_pool_attr *pool_attr)
{
UT_ASSERTne(arg, NULL);
UT_ASSERTne(req, NULL);
UT_ASSERTne(pool_attr, NULL);
req_cb_check_req(req);
req_cb_check_pool_attr(pool_attr);
struct req_cb_arg *args = arg;
args->types |= (1 << RPMEM_MSG_TYPE_CREATE);
int ret = args->ret;
if (args->resp) {
struct rpmem_resp_attr resp = {
.port = PORT,
.rkey = RKEY,
.raddr = RADDR,
.persist_method = PERSIST_METHOD,
.nlanes = NLANES_RESP,
};
ret = rpmemd_obc_create_resp(obc,
args->status, &resp);
}
if (args->force_ret)
ret = args->ret;
return ret;
}
/*
* req_cb_open -- callback for open request operation
*
* This function behaves according to arguments specified via
* struct req_cb_arg.
*/
static int
req_cb_open(struct rpmemd_obc *obc, void *arg,
const struct rpmem_req_attr *req)
{
UT_ASSERTne(arg, NULL);
UT_ASSERTne(req, NULL);
req_cb_check_req(req);
struct req_cb_arg *args = arg;
args->types |= (1 << RPMEM_MSG_TYPE_OPEN);
int ret = args->ret;
if (args->resp) {
struct rpmem_resp_attr resp = {
.port = PORT,
.rkey = RKEY,
.raddr = RADDR,
.persist_method = PERSIST_METHOD,
.nlanes = NLANES_RESP,
};
struct rpmem_pool_attr pool_attr = POOL_ATTR_INIT;
ret = rpmemd_obc_open_resp(obc, args->status,
&resp, &pool_attr);
}
if (args->force_ret)
ret = args->ret;
return ret;
}
/*
* req_cb_close -- callback for close request operation
*
* This function behaves according to arguments specified via
* struct req_cb_arg.
*/
static int
req_cb_close(struct rpmemd_obc *obc, void *arg, int flags)
{
UT_ASSERTne(arg, NULL);
struct req_cb_arg *args = arg;
args->types |= (1 << RPMEM_MSG_TYPE_CLOSE);
int ret = args->ret;
if (args->resp)
ret = rpmemd_obc_close_resp(obc, args->status);
if (args->force_ret)
ret = args->ret;
return ret;
}
/*
* req_cb_set_attr -- callback for set attributes request operation
*
* This function behaves according to arguments specified via
* struct req_cb_arg.
*/
static int
req_cb_set_attr(struct rpmemd_obc *obc, void *arg,
const struct rpmem_pool_attr *pool_attr)
{
UT_ASSERTne(arg, NULL);
struct req_cb_arg *args = arg;
args->types |= (1 << RPMEM_MSG_TYPE_SET_ATTR);
int ret = args->ret;
if (args->resp)
ret = rpmemd_obc_set_attr_resp(obc, args->status);
if (args->force_ret)
ret = args->ret;
return ret;
}
/*
* REQ_CB -- request callbacks
*/
struct rpmemd_obc_requests REQ_CB = {
.create = req_cb_create,
.open = req_cb_open,
.close = req_cb_close,
.set_attr = req_cb_set_attr,
};
/*
* clnt_wait_disconnect -- wait for disconnection
*/
void
clnt_wait_disconnect(struct rpmem_ssh *ssh)
{
int ret;
ret = rpmem_ssh_monitor(ssh, 0);
UT_ASSERTne(ret, 1);
}
/*
* clnt_connect -- create a ssh connection with specified target
*/
struct rpmem_ssh *
clnt_connect(char *target)
{
struct rpmem_target_info *info;
info = rpmem_target_parse(target);
UT_ASSERTne(info, NULL);
struct rpmem_ssh *ssh = rpmem_ssh_open(info);
UT_ASSERTne(ssh, NULL);
rpmem_target_free(info);
return ssh;
}
/*
* clnt_close -- close client
*/
void
clnt_close(struct rpmem_ssh *ssh)
{
rpmem_ssh_close(ssh);
}
/*
* clnt_send -- send data
*/
void
clnt_send(struct rpmem_ssh *ssh, const void *buff, size_t len)
{
int ret;
ret = rpmem_ssh_send(ssh, buff, len);
UT_ASSERTeq(ret, 0);
}
/*
* clnt_recv -- receive data
*/
void
clnt_recv(struct rpmem_ssh *ssh, void *buff, size_t len)
{
int ret;
ret = rpmem_ssh_recv(ssh, buff, len);
UT_ASSERTeq(ret, 0);
}
/*
* server_msg_args -- process a message according to specified arguments
*/
static void
server_msg_args(struct rpmemd_obc *rpdc, enum conn_wait_close conn,
struct req_cb_arg *args)
{
int ret;
unsigned long long types = args->types;
args->types = 0;
ret = rpmemd_obc_process(rpdc, &REQ_CB, args);
UT_ASSERTeq(ret, args->ret);
UT_ASSERTeq(args->types, types);
if (conn == CONN_WAIT_CLOSE) {
ret = rpmemd_obc_process(rpdc, &REQ_CB, args);
UT_ASSERTeq(ret, 1);
}
rpmemd_obc_fini(rpdc);
}
/*
* server_msg_resp -- process a message of specified type, response to client
* with specific status value and return status of sending response function
*/
int
server_msg_resp(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 2)
UT_FATAL("usage: %s msg_type status", tc->name);
unsigned type = ATOU(argv[0]);
int status = atoi(argv[1]);
int ret;
struct rpmemd_obc *rpdc;
rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO);
UT_ASSERTne(rpdc, NULL);
ret = rpmemd_obc_status(rpdc, 0);
UT_ASSERTeq(ret, 0);
struct req_cb_arg args = {
.ret = 0,
.force_ret = 0,
.resp = 1,
.types = (1U << type),
.status = status,
};
server_msg_args(rpdc, CONN_WAIT_CLOSE, &args);
return 2;
}
/*
* server_msg_noresp -- process a message of specified type, do not response to
* client and return specific value from process callback
*/
int
server_msg_noresp(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s msg_type", tc->name);
int type = atoi(argv[0]);
int ret;
struct rpmemd_obc *rpdc;
rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO);
UT_ASSERTne(rpdc, NULL);
ret = rpmemd_obc_status(rpdc, 0);
UT_ASSERTeq(ret, 0);
struct req_cb_arg args = {
.ret = -1,
.force_ret = 1,
.resp = 0,
.types = (1U << type),
.status = 0,
};
server_msg_args(rpdc, CONN_CLOSE, &args);
return 1;
}
/*
* server_bad_msg -- process a message and expect
* error returned from rpmemd_obc_process function
*/
int
server_bad_msg(const struct test_case *tc, int argc, char *argv[])
{
int ret;
struct rpmemd_obc *rpdc;
rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO);
UT_ASSERTne(rpdc, NULL);
ret = rpmemd_obc_status(rpdc, 0);
UT_ASSERTeq(ret, 0);
ret = rpmemd_obc_process(rpdc, &REQ_CB, NULL);
UT_ASSERTne(ret, 0);
rpmemd_obc_fini(rpdc);
return 0;
}
| 9,441 | 20.410431 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_close.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_close.c -- test cases for close request message
*/
#include "rpmemd_obc_test_common.h"
/*
* client_msg_close_noresp -- send close request message and don't expect a
* response
*/
static void
client_msg_close_noresp(const char *ctarget)
{
char *target = STRDUP(ctarget);
struct rpmem_msg_close msg = CLOSE_MSG;
rpmem_hton_msg_close(&msg);
struct rpmem_ssh *ssh = clnt_connect(target);
clnt_send(ssh, &msg, sizeof(msg));
clnt_wait_disconnect(ssh);
clnt_close(ssh);
FREE(target);
}
/*
* client_msg_close_resp -- send close request message and expect a response
* with specified status. If status is 0, validate close request response
* message
*/
static void
client_msg_close_resp(const char *ctarget, int status)
{
char *target = STRDUP(ctarget);
struct rpmem_msg_close msg = CLOSE_MSG;
rpmem_hton_msg_close(&msg);
struct rpmem_msg_close_resp resp;
struct rpmem_ssh *ssh = clnt_connect(target);
clnt_send(ssh, &msg, sizeof(msg));
clnt_recv(ssh, &resp, sizeof(resp));
rpmem_ntoh_msg_close_resp(&resp);
if (status)
UT_ASSERTeq(resp.hdr.status, (uint32_t)status);
clnt_close(ssh);
FREE(target);
}
/*
* client_close -- test case for close request message - client side
*/
int
client_close(const struct test_case *tc, int argc, char *argv[])
{
if (argc < 1)
UT_FATAL("usage: %s <addr>[:<port>]", tc->name);
char *target = argv[0];
set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_CLOSE);
client_msg_close_noresp(target);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CLOSE, 0);
client_msg_close_resp(target, 0);
set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CLOSE, 1);
client_msg_close_resp(target, 1);
return 1;
}
| 3,306 | 29.62037 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_common.h | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_obc_test_common.h -- common declarations for rpmemd_obc test
*/
#include "unittest.h"
#include "librpmem.h"
#include "rpmem_proto.h"
#include "rpmem_common.h"
#include "rpmem_ssh.h"
#include "rpmem_util.h"
#include "rpmemd_log.h"
#include "rpmemd_obc.h"
#define PORT 1234
#define RKEY 0x0123456789abcdef
#define RADDR 0xfedcba9876543210
#define PERSIST_METHOD RPMEM_PM_APM
#define POOL_ATTR_INIT {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 3,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS012345",\
}
#define POOL_ATTR_ALT {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 7,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "012345USER_FLAGS",\
}
#define POOL_SIZE 0x0001234567abcdef
#define NLANES 0x123
#define NLANES_RESP 16
#define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS
#define POOL_DESC "pool.set"
#define BUFF_SIZE 8192
static const char pool_desc[] = POOL_DESC;
#define POOL_DESC_SIZE (sizeof(pool_desc) / sizeof(pool_desc[0]))
struct rpmem_ssh *clnt_connect(char *target);
void clnt_wait_disconnect(struct rpmem_ssh *ssh);
void clnt_send(struct rpmem_ssh *ssh, const void *buff, size_t len);
void clnt_recv(struct rpmem_ssh *ssh, void *buff, size_t len);
void clnt_close(struct rpmem_ssh *ssh);
enum conn_wait_close {
CONN_CLOSE,
CONN_WAIT_CLOSE,
};
void set_rpmem_cmd(const char *fmt, ...);
extern struct rpmemd_obc_requests REQ_CB;
struct req_cb_arg {
int resp;
unsigned long long types;
int force_ret;
int ret;
int status;
};
static const struct rpmem_msg_hdr MSG_HDR = {
.type = RPMEM_MSG_TYPE_CLOSE,
.size = sizeof(struct rpmem_msg_hdr),
};
static const struct rpmem_msg_create CREATE_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_CREATE,
.size = sizeof(struct rpmem_msg_create),
},
.c = {
.major = RPMEM_PROTO_MAJOR,
.minor = RPMEM_PROTO_MINOR,
.pool_size = POOL_SIZE,
.nlanes = NLANES,
.provider = PROVIDER,
.buff_size = BUFF_SIZE,
},
.pool_attr = POOL_ATTR_INIT,
.pool_desc = {
.size = POOL_DESC_SIZE,
},
};
static const struct rpmem_msg_open OPEN_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_OPEN,
.size = sizeof(struct rpmem_msg_open),
},
.c = {
.major = RPMEM_PROTO_MAJOR,
.minor = RPMEM_PROTO_MINOR,
.pool_size = POOL_SIZE,
.nlanes = NLANES,
.provider = PROVIDER,
.buff_size = BUFF_SIZE,
},
.pool_desc = {
.size = POOL_DESC_SIZE,
},
};
static const struct rpmem_msg_close CLOSE_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_CLOSE,
.size = sizeof(struct rpmem_msg_close),
},
};
static const struct rpmem_msg_set_attr SET_ATTR_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_SET_ATTR,
.size = sizeof(struct rpmem_msg_set_attr),
},
.pool_attr = POOL_ATTR_ALT,
};
TEST_CASE_DECLARE(server_accept_sim);
TEST_CASE_DECLARE(server_accept_sim_fork);
TEST_CASE_DECLARE(client_accept_sim);
TEST_CASE_DECLARE(server_accept_seq);
TEST_CASE_DECLARE(server_accept_seq_fork);
TEST_CASE_DECLARE(client_accept_seq);
TEST_CASE_DECLARE(client_bad_msg_hdr);
TEST_CASE_DECLARE(server_bad_msg);
TEST_CASE_DECLARE(server_msg_noresp);
TEST_CASE_DECLARE(server_msg_resp);
TEST_CASE_DECLARE(client_econnreset);
TEST_CASE_DECLARE(server_econnreset);
TEST_CASE_DECLARE(client_create);
TEST_CASE_DECLARE(server_open);
TEST_CASE_DECLARE(client_close);
TEST_CASE_DECLARE(server_close);
TEST_CASE_DECLARE(client_open);
TEST_CASE_DECLARE(client_set_attr);
| 5,306 | 27.379679 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_valgrind/vmem_valgrind.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_valgrind.c -- unit test for vmem_valgrind
*
* usage: vmem_valgrind <test-number> [directory]
*
* test-number can be a number from 0 to 9
*/
#include "unittest.h"
static int custom_allocs;
static int custom_alloc_calls;
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
int
main(int argc, char *argv[])
{
char *dir = NULL;
VMEM *vmp;
int *ptr;
int test_case = -1;
int expect_custom_alloc = 0;
START(argc, argv, "vmem_valgrind");
if (argc >= 2 && argc <= 3) {
test_case = atoi(argv[1]);
if (test_case > 9)
test_case = -1;
if (argc > 2)
dir = argv[2];
}
if (test_case < 0)
UT_FATAL("usage: %s <test-number from 0 to 9> [directory]",
argv[0]);
if (test_case < 5) {
UT_OUT("use default allocator");
expect_custom_alloc = 0;
} else {
UT_OUT("use custom alloc functions");
test_case -= 5;
expect_custom_alloc = 1;
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
switch (test_case) {
case 0: {
UT_OUT("remove all allocations and delete pool");
ptr = vmem_malloc(vmp, sizeof(int));
if (ptr == NULL)
UT_FATAL("!vmem_malloc");
vmem_free(vmp, ptr);
vmem_delete(vmp);
break;
}
case 1: {
UT_OUT("only remove allocations");
ptr = vmem_malloc(vmp, sizeof(int));
if (ptr == NULL)
UT_FATAL("!vmem_malloc");
vmem_free(vmp, ptr);
break;
}
case 2: {
UT_OUT("only delete pool");
ptr = vmem_malloc(vmp, sizeof(int));
if (ptr == NULL)
UT_FATAL("!vmem_malloc");
vmem_delete(vmp);
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
break;
}
case 3: {
UT_OUT("memory leaks");
ptr = vmem_malloc(vmp, sizeof(int));
if (ptr == NULL)
UT_FATAL("!vmem_malloc");
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
/* Clean up pool, above malloc will still leak */
vmem_delete(vmp);
break;
}
case 4: {
UT_OUT("heap block overrun");
ptr = vmem_malloc(vmp, 12 * sizeof(int));
if (ptr == NULL)
UT_FATAL("!vmem_malloc");
/* heap block overrun */
ptr[12] = 7;
vmem_free(vmp, ptr);
vmem_delete(vmp);
break;
}
default: {
UT_FATAL("!unknown test-number");
}
}
/* check memory leak in custom allocator */
UT_ASSERTeq(custom_allocs, 0);
if (expect_custom_alloc == 0) {
UT_ASSERTeq(custom_alloc_calls, 0);
} else {
UT_ASSERTne(custom_alloc_calls, 0);
}
DONE(NULL);
}
| 5,395 | 23.306306 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/ctl_prefault/ctl_prefault.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ctl_prefault.c -- tests for the ctl entry points: prefault
*/
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include "unittest.h"
#define OBJ_STR "obj"
#define BLK_STR "blk"
#define LOG_STR "log"
#define BSIZE 20
#define LAYOUT "obj_ctl_prefault"
#ifdef __FreeBSD__
typedef char vec_t;
#else
typedef unsigned char vec_t;
#endif
typedef int (*fun)(void *, const char *, void *);
/*
* prefault_fun -- function ctl_get/set testing
*/
static void
prefault_fun(int prefault, fun get_func, fun set_func)
{
int ret;
int arg;
int arg_read;
if (prefault == 1) { /* prefault at open */
arg_read = -1;
ret = get_func(NULL, "prefault.at_open", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
arg = 1;
ret = set_func(NULL, "prefault.at_open", &arg);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg, 1);
arg_read = -1;
ret = get_func(NULL, "prefault.at_open", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 1);
} else if (prefault == 2) { /* prefault at create */
arg_read = -1;
ret = get_func(NULL, "prefault.at_create", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
arg = 1;
ret = set_func(NULL, "prefault.at_create", &arg);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg, 1);
arg_read = -1;
ret = get_func(NULL, "prefault.at_create", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 1);
}
}
/*
* count_resident_pages -- count resident_pages
*/
static size_t
count_resident_pages(void *pool, size_t length)
{
size_t arr_len = (length + Ut_pagesize - 1) / Ut_pagesize;
vec_t *vec = MALLOC(sizeof(*vec) * arr_len);
int ret = mincore(pool, length, vec);
UT_ASSERTeq(ret, 0);
size_t resident_pages = 0;
for (size_t i = 0; i < arr_len; ++i)
resident_pages += vec[i] & 0x1;
FREE(vec);
return resident_pages;
}
/*
* test_obj -- open/create PMEMobjpool
*/
static void
test_obj(const char *path, int open)
{
PMEMobjpool *pop;
if (open) {
if ((pop = pmemobj_open(path, LAYOUT)) == NULL)
UT_FATAL("!pmemobj_open: %s", path);
} else {
if ((pop = pmemobj_create(path, LAYOUT,
PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
}
size_t resident_pages = count_resident_pages(pop, PMEMOBJ_MIN_POOL);
pmemobj_close(pop);
UT_OUT("%ld", resident_pages);
}
/*
* test_blk -- open/create PMEMblkpool
*/
static void
test_blk(const char *path, int open)
{
PMEMblkpool *pbp;
if (open) {
if ((pbp = pmemblk_open(path, BSIZE)) == NULL)
UT_FATAL("!pmemblk_open: %s", path);
} else {
if ((pbp = pmemblk_create(path, BSIZE, PMEMBLK_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemblk_create: %s", path);
}
size_t resident_pages = count_resident_pages(pbp, PMEMBLK_MIN_POOL);
pmemblk_close(pbp);
UT_OUT("%ld", resident_pages);
}
/*
* test_log -- open/create PMEMlogpool
*/
static void
test_log(const char *path, int open)
{
PMEMlogpool *plp;
/*
* To test prefaulting, pool must have size at least equal to 2 pages.
* If 2MB huge pages are used this is at least 4MB.
*/
size_t pool_size = 2 * PMEMLOG_MIN_POOL;
if (open) {
if ((plp = pmemlog_open(path)) == NULL)
UT_FATAL("!pmemlog_open: %s", path);
} else {
if ((plp = pmemlog_create(path, pool_size,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemlog_create: %s", path);
}
size_t resident_pages = count_resident_pages(plp, pool_size);
pmemlog_close(plp);
UT_OUT("%ld", resident_pages);
}
#define USAGE() do {\
UT_FATAL("usage: %s file-name type(obj/blk/log) prefault(0/1/2) "\
"open(0/1)", argv[0]);\
} while (0)
int
main(int argc, char *argv[])
{
START(argc, argv, "ctl_prefault");
if (argc != 5)
USAGE();
char *type = argv[1];
const char *path = argv[2];
int prefault = atoi(argv[3]);
int open = atoi(argv[4]);
if (strcmp(type, OBJ_STR) == 0) {
prefault_fun(prefault, (fun)pmemobj_ctl_get,
(fun)pmemobj_ctl_set);
test_obj(path, open);
} else if (strcmp(type, BLK_STR) == 0) {
prefault_fun(prefault, (fun)pmemblk_ctl_get,
(fun)pmemblk_ctl_set);
test_blk(path, open);
} else if (strcmp(type, LOG_STR) == 0) {
prefault_fun(prefault, (fun)pmemlog_ctl_get,
(fun)pmemlog_ctl_set);
test_log(path, open);
} else
USAGE();
DONE(NULL);
}
| 5,841 | 24.4 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_multiple_pools/vmem_multiple_pools.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_multiple_pools.c -- unit test for vmem_multiple_pools
*
* usage: vmem_multiple_pools directory npools [nthreads]
*/
#include "unittest.h"
#define TEST_REPEAT_CREATE_POOLS (10)
static char **mem_pools;
static VMEM **pools;
static unsigned npools;
static const char *dir;
static void *
thread_func(void *arg)
{
unsigned start_idx = *(unsigned *)arg;
for (int repeat = 0; repeat < TEST_REPEAT_CREATE_POOLS; ++repeat) {
for (unsigned idx = 0; idx < npools; ++idx) {
unsigned pool_id = start_idx + idx;
/* delete old pool with the same id if exist */
if (pools[pool_id] != NULL) {
vmem_delete(pools[pool_id]);
pools[pool_id] = NULL;
}
if (pool_id % 2 == 0) {
/* for even pool_id, create in region */
pools[pool_id] = vmem_create_in_region(
mem_pools[pool_id / 2], VMEM_MIN_POOL);
if (pools[pool_id] == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
/* for odd pool_id, create in file */
pools[pool_id] = vmem_create(dir,
VMEM_MIN_POOL);
if (pools[pool_id] == NULL)
UT_FATAL("!vmem_create");
}
void *test = vmem_malloc(pools[pool_id],
sizeof(void *));
UT_ASSERTne(test, NULL);
vmem_free(pools[pool_id], test);
}
}
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "vmem_multiple_pools");
if (argc < 4)
UT_FATAL("usage: %s directory npools nthreads", argv[0]);
dir = argv[1];
npools = ATOU(argv[2]);
unsigned nthreads = ATOU(argv[3]);
UT_OUT("create %d pools in %d thread(s)", npools, nthreads);
const unsigned mem_pools_size = (npools / 2 + npools % 2) * nthreads;
mem_pools = MALLOC(mem_pools_size * sizeof(char *));
pools = CALLOC(npools * nthreads, sizeof(VMEM *));
os_thread_t *threads = CALLOC(nthreads, sizeof(os_thread_t));
UT_ASSERTne(threads, NULL);
unsigned *pool_idx = CALLOC(nthreads, sizeof(pool_idx[0]));
UT_ASSERTne(pool_idx, NULL);
for (unsigned pool_id = 0; pool_id < mem_pools_size; ++pool_id) {
/* allocate memory for function vmem_create_in_region() */
mem_pools[pool_id] = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
}
/* create and destroy pools multiple times */
for (unsigned t = 0; t < nthreads; t++) {
pool_idx[t] = npools * t;
PTHREAD_CREATE(&threads[t], NULL, thread_func, &pool_idx[t]);
}
for (unsigned t = 0; t < nthreads; t++)
PTHREAD_JOIN(&threads[t], NULL);
for (unsigned pool_id = 0; pool_id < npools * nthreads; ++pool_id) {
if (pools[pool_id] != NULL) {
vmem_delete(pools[pool_id]);
pools[pool_id] = NULL;
}
}
FREE(mem_pools);
FREE(pools);
FREE(threads);
FREE(pool_idx);
DONE(NULL);
}
| 4,215 | 29.550725 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_malloc_usable_size/vmmalloc_malloc_usable_size.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_malloc_usable_size.c -- unit test for
* libvmmalloc malloc_usable_size
*
* usage: vmmalloc_malloc_usable_size
*/
#ifdef __FreeBSD__
#include <malloc_np.h>
#else
#include <malloc.h>
#endif
#include "unittest.h"
static const struct {
size_t size;
size_t spacing;
} Check_sizes[] = {
{.size = 10, .spacing = 8},
{.size = 100, .spacing = 16},
{.size = 200, .spacing = 32},
{.size = 500, .spacing = 64},
{.size = 1000, .spacing = 128},
{.size = 2000, .spacing = 256},
{.size = 3000, .spacing = 512},
{.size = 1 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 2 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 3 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 4 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 5 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 6 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 7 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 8 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 9 * 1024 * 1024, .spacing = 4 * 1024 * 1024}
};
int
main(int argc, char *argv[])
{
void *ptr;
size_t usable_size;
size_t size;
int i;
START(argc, argv, "vmmalloc_malloc_usable_size");
UT_ASSERTeq(malloc_usable_size(NULL), 0);
for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) {
size = Check_sizes[i].size;
UT_OUT("size %zu", size);
ptr = malloc(size);
UT_ASSERTne(ptr, NULL);
usable_size = malloc_usable_size(ptr);
UT_ASSERT(usable_size >= size);
if (usable_size - size > Check_sizes[i].spacing) {
UT_FATAL("Size %zu: spacing %zu is bigger"
"than expected: %zu", size,
(usable_size - size), Check_sizes[i].spacing);
}
memset(ptr, 0xEE, usable_size);
UT_ASSERTeq(*(unsigned char *)ptr, 0xEE);
free(ptr);
}
DONE(NULL);
}
| 3,392 | 31.314286 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_is_zeroed/util_is_zeroed.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_is_zeroed.c -- unit test for util_is_zeroed
*/
#include "unittest.h"
#include "util.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "util_is_zeroed");
util_init();
char bigbuf[3000];
memset(bigbuf + 0, 0x11, 1000);
memset(bigbuf + 1000, 0x0, 1000);
memset(bigbuf + 2000, 0xff, 1000);
UT_ASSERTeq(util_is_zeroed(bigbuf, 1000), 0);
UT_ASSERTeq(util_is_zeroed(bigbuf + 1000, 1000), 1);
UT_ASSERTeq(util_is_zeroed(bigbuf + 2000, 1000), 0);
UT_ASSERTeq(util_is_zeroed(bigbuf, 0), 1);
UT_ASSERTeq(util_is_zeroed(bigbuf + 999, 1000), 0);
UT_ASSERTeq(util_is_zeroed(bigbuf + 1000, 1001), 0);
UT_ASSERTeq(util_is_zeroed(bigbuf + 1001, 1000), 0);
char *buf = bigbuf + 1000;
buf[0] = 1;
UT_ASSERTeq(util_is_zeroed(buf, 1000), 0);
memset(buf, 0, 1000);
buf[1] = 1;
UT_ASSERTeq(util_is_zeroed(buf, 1000), 0);
memset(buf, 0, 1000);
buf[239] = 1;
UT_ASSERTeq(util_is_zeroed(buf, 1000), 0);
memset(buf, 0, 1000);
buf[999] = 1;
UT_ASSERTeq(util_is_zeroed(buf, 1000), 0);
memset(buf, 0, 1000);
buf[1000] = 1;
UT_ASSERTeq(util_is_zeroed(buf, 1000), 1);
DONE(NULL);
}
| 2,711 | 31.285714 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file/mocks_windows.h | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of libc functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of pmem_map_file test.
* It would replace default implementation with mocked functions defined
* in pmem_map_file.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define os_posix_fallocate __wrap_os_posix_fallocate
#define os_ftruncate __wrap_os_ftruncate
#endif
| 2,123 | 41.48 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file/mocks_windows.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in pmem_map_file.c
* (Windows-specific)
*/
#include "unittest.h"
#define MAX_LEN (4 * 1024 * 1024)
/*
* posix_fallocate -- interpose on libc posix_fallocate()
*/
FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("posix_fallocate: off %ju len %ju", offset, len);
if (len > MAX_LEN)
return ENOSPC;
return _FUNC_REAL(os_posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* ftruncate -- interpose on libc ftruncate()
*/
FUNC_MOCK(os_ftruncate, int, int fd, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("ftruncate: len %ju", len);
if (len > MAX_LEN) {
errno = ENOSPC;
return -1;
}
return _FUNC_REAL(os_ftruncate)(fd, len);
}
FUNC_MOCK_END
| 2,383 | 34.58209 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file/mocks_posix.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_posix.c -- mocked functions used in pmem_map_file.c (Posix-specific)
*/
#define _GNU_SOURCE
#include "unittest.h"
#include <dlfcn.h>
#define MAX_LEN (4 * 1024 * 1024)
/*
* posix_fallocate -- interpose on libc posix_fallocate()
*/
int
posix_fallocate(int fd, os_off_t offset, off_t len)
{
UT_OUT("posix_fallocate: off %ju len %ju", offset, len);
static int (*posix_fallocate_ptr)(int fd, os_off_t offset, off_t len);
if (posix_fallocate_ptr == NULL)
posix_fallocate_ptr = dlsym(RTLD_NEXT, "posix_fallocate");
if (len > MAX_LEN)
return ENOSPC;
return (*posix_fallocate_ptr)(fd, offset, len);
}
/*
* ftruncate -- interpose on libc ftruncate()
*/
int
ftruncate(int fd, os_off_t len)
{
UT_OUT("ftruncate: len %ju", len);
static int (*ftruncate_ptr)(int fd, os_off_t len);
if (ftruncate_ptr == NULL)
ftruncate_ptr = dlsym(RTLD_NEXT, "ftruncate");
if (len > MAX_LEN) {
errno = ENOSPC;
return -1;
}
return (*ftruncate_ptr)(fd, len);
}
| 2,579 | 30.463415 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_map_file/pmem_map_file.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_map_file.c -- unit test for mapping persistent memory for raw access
*
* usage: pmem_map_file file
*/
#define _GNU_SOURCE
#include "unittest.h"
#include <stdlib.h>
#define CHECK_BYTES 4096 /* bytes to compare before/after map call */
static ut_jmp_buf_t Jmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
ut_siglongjmp(Jmp);
}
#define PMEM_FILE_ALL_FLAGS\
(PMEM_FILE_CREATE|PMEM_FILE_EXCL|PMEM_FILE_SPARSE|PMEM_FILE_TMPFILE)
static int is_dev_dax = 0;
/*
* parse_flags -- parse 'flags' string
*/
static int
parse_flags(const char *flags_str)
{
int ret = 0;
while (*flags_str != '\0') {
switch (*flags_str) {
case '0':
case '-':
/* no flags */
break;
case 'T':
ret |= PMEM_FILE_TMPFILE;
break;
case 'S':
ret |= PMEM_FILE_SPARSE;
break;
case 'C':
ret |= PMEM_FILE_CREATE;
break;
case 'E':
ret |= PMEM_FILE_EXCL;
break;
case 'X':
/* not supported flag */
ret |= (PMEM_FILE_ALL_FLAGS + 1);
break;
case 'D':
is_dev_dax = 1;
break;
default:
UT_FATAL("unknown flags: %c", *flags_str);
}
flags_str++;
};
return ret;
}
/*
* do_check -- check the mapping
*/
static void
do_check(int fd, void *addr, size_t mlen)
{
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
char pat[CHECK_BYTES];
char buf[CHECK_BYTES];
/* write some pattern to the file */
memset(pat, 0x5A, CHECK_BYTES);
WRITE(fd, pat, CHECK_BYTES);
if (memcmp(pat, addr, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
/* fill up mapped region with new pattern */
memset(pat, 0xA5, CHECK_BYTES);
memcpy(addr, pat, CHECK_BYTES);
UT_ASSERTeq(pmem_msync(addr, CHECK_BYTES), 0);
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
if (!ut_sigsetjmp(Jmp)) {
/* same memcpy from above should now fail */
memcpy(addr, pat, CHECK_BYTES);
} else {
UT_OUT("unmap successful");
}
LSEEK(fd, (os_off_t)0, SEEK_SET);
if (READ(fd, buf, CHECK_BYTES) == CHECK_BYTES) {
if (memcmp(pat, buf, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_map_file");
int fd;
void *addr;
size_t mlen;
size_t *mlenp;
const char *path;
unsigned long long len;
int flags;
unsigned mode;
int is_pmem;
int *is_pmemp;
int use_mlen;
int use_is_pmem;
if (argc < 7)
UT_FATAL("usage: %s path len flags mode use_mlen "
"use_is_pmem ...", argv[0]);
for (int i = 1; i + 5 < argc; i += 6) {
path = argv[i];
len = strtoull(argv[i + 1], NULL, 0);
flags = parse_flags(argv[i + 2]);
mode = STRTOU(argv[i + 3], NULL, 8);
use_mlen = atoi(argv[i + 4]);
use_is_pmem = atoi(argv[i + 5]);
mlen = SIZE_MAX;
if (use_mlen)
mlenp = &mlen;
else
mlenp = NULL;
if (use_is_pmem)
is_pmemp = &is_pmem;
else
is_pmemp = NULL;
UT_OUT("%s %lld %s %o %d %d",
path, len, argv[i + 2], mode, use_mlen, use_is_pmem);
addr = pmem_map_file(path, len, flags, mode, mlenp, is_pmemp);
if (addr == NULL) {
UT_OUT("!pmem_map_file");
continue;
}
if (use_mlen) {
UT_ASSERTne(mlen, SIZE_MAX);
UT_OUT("mapped_len %zu", mlen);
} else {
mlen = len;
}
if (addr) {
/* is_pmem must be true for device DAX */
int is_pmem_check = pmem_is_pmem(addr, mlen);
UT_ASSERT(!is_dev_dax || is_pmem_check);
/* check is_pmem returned from pmem_map_file */
if (use_is_pmem)
UT_ASSERTeq(is_pmem, is_pmem_check);
if ((flags & PMEM_FILE_TMPFILE) == 0 && !is_dev_dax) {
fd = OPEN(argv[i], O_RDWR);
if (!use_mlen) {
os_stat_t stbuf;
FSTAT(fd, &stbuf);
mlen = (size_t)stbuf.st_size;
}
if (fd != -1) {
do_check(fd, addr, mlen);
(void) CLOSE(fd);
} else {
UT_OUT("!cannot open file: %s",
argv[i]);
}
} else {
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
}
}
}
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmem is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmem_init)
MSVC_DESTR(libpmem_fini)
#endif
| 5,733 | 22.404082 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_callbacks/obj_tx_callbacks.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_callbacks.c -- unit test for transaction stage callbacks
*/
#include "unittest.h"
#define LAYOUT_NAME "tx_callback"
POBJ_LAYOUT_BEGIN(tx_callback);
POBJ_LAYOUT_ROOT(tx_callback, struct pmem_root);
POBJ_LAYOUT_TOID(tx_callback, struct pmem_obj);
POBJ_LAYOUT_END(tx_callback);
struct runtime_info {
int something;
};
struct pmem_obj {
struct runtime_info *rt;
int pmem_info;
};
struct pmem_root {
TOID(struct pmem_obj) obj;
};
struct free_info {
void *to_free;
};
static int freed = 0;
static const char *desc[] = {
"TX_STAGE_NONE",
"TX_STAGE_WORK",
"TX_STAGE_ONCOMMIT",
"TX_STAGE_ONABORT",
"TX_STAGE_FINALLY",
"WTF?"
};
static void
free_onabort(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg)
{
UT_OUT("cb stage: %s", desc[stage]);
if (stage == TX_STAGE_ONABORT) {
struct free_info *f = (struct free_info *)arg;
UT_OUT("rt_onabort: free");
free(f->to_free);
freed++;
}
}
static void
allocate_pmem(struct free_info *f, TOID(struct pmem_root) root, int val)
{
TOID(struct pmem_obj) obj = TX_NEW(struct pmem_obj);
D_RW(obj)->pmem_info = val;
D_RW(obj)->rt =
(struct runtime_info *)malloc(sizeof(struct runtime_info));
f->to_free = D_RW(obj)->rt;
D_RW(obj)->rt->something = val;
TX_ADD_FIELD(root, obj);
D_RW(root)->obj = obj;
}
static void
do_something_fishy(TOID(struct pmem_root) root)
{
TX_ADD_FIELD(root, obj);
D_RW(root)->obj = TX_ALLOC(struct pmem_obj, 1 << 30);
}
static void
free_oncommit(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg)
{
UT_OUT("cb stage: %s", desc[stage]);
if (stage == TX_STAGE_ONCOMMIT) {
struct free_info *f = (struct free_info *)arg;
UT_OUT("rt_oncommit: free");
free(f->to_free);
freed++;
}
}
static void
free_pmem(struct free_info *f, TOID(struct pmem_root) root)
{
TOID(struct pmem_obj) obj = D_RW(root)->obj;
f->to_free = D_RW(obj)->rt;
TX_FREE(obj);
TX_SET(root, obj, TOID_NULL(struct pmem_obj));
}
static void
log_stages(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg)
{
UT_OUT("cb stage: %s", desc[stage]);
}
static void
test(PMEMobjpool *pop, TOID(struct pmem_root) root)
{
struct free_info *volatile f = (struct free_info *)ZALLOC(sizeof(*f));
TX_BEGIN_CB(pop, free_onabort, f) {
allocate_pmem(f, root, 7);
do_something_fishy(root);
UT_ASSERT(0);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
UT_OUT("on abort 1");
} TX_FINALLY {
UT_OUT("finally 1");
} TX_END
UT_OUT("end of tx 1\n");
memset(f, 0, sizeof(*f));
UT_ASSERTeq(freed, 1);
freed = 0;
TX_BEGIN_CB(pop, free_onabort, f) {
allocate_pmem(f, root, 7);
} TX_ONCOMMIT {
UT_OUT("on commit 2");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("finally 2");
} TX_END
UT_OUT("end of tx 2\n");
memset(f, 0, sizeof(*f));
UT_ASSERTeq(freed, 0);
TX_BEGIN_CB(pop, free_oncommit, f) {
free_pmem(f, root);
do_something_fishy(root);
UT_ASSERT(0);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
UT_OUT("on abort 3");
} TX_FINALLY {
UT_OUT("finally 3");
} TX_END
UT_OUT("end of tx 3\n");
memset(f, 0, sizeof(*f));
UT_ASSERTeq(freed, 0);
TX_BEGIN_CB(pop, free_oncommit, f) {
free_pmem(f, root);
} TX_ONCOMMIT {
UT_OUT("on commit 4");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("finally 4");
} TX_END
UT_OUT("end of tx 4\n");
memset(f, 0, sizeof(*f));
UT_ASSERTeq(freed, 1);
freed = 0;
TX_BEGIN_CB(pop, log_stages, NULL) {
TX_BEGIN(pop) {
UT_OUT("inner tx work 5");
} TX_ONCOMMIT {
UT_OUT("inner tx on commit 5");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("inner tx finally 5");
} TX_END
} TX_ONCOMMIT {
UT_OUT("on commit 5");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("finally 5");
} TX_END
UT_OUT("end of tx 5\n");
TX_BEGIN(pop) {
TX_BEGIN_CB(pop, log_stages, NULL) {
UT_OUT("inner tx work 6");
} TX_ONCOMMIT {
UT_OUT("inner tx on commit 6");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("inner tx finally 6");
} TX_END
} TX_ONCOMMIT {
UT_OUT("on commit 6");
} TX_ONABORT {
UT_ASSERT(0);
} TX_FINALLY {
UT_OUT("finally 6");
} TX_END
UT_OUT("end of tx 6\n");
UT_OUT("start of tx 7");
if (pmemobj_tx_begin(pop, NULL, TX_PARAM_CB, log_stages, NULL,
TX_PARAM_NONE))
UT_FATAL("!pmemobj_tx_begin");
UT_OUT("work");
pmemobj_tx_commit();
UT_OUT("on commit");
if (pmemobj_tx_end())
UT_FATAL("!pmemobj_tx_end");
UT_OUT("end of tx 7\n");
FREE(f);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_callbacks");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop = pmemobj_create(argv[1], LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!pmemobj_create");
TOID(struct pmem_root) root = POBJ_ROOT(pop, struct pmem_root);
test(pop, root);
pmemobj_close(pop);
DONE(NULL);
}
| 6,411 | 22.487179 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_cpuid/util_cpuid.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_cpuid.c -- unit test for CPU features detection
*/
#define _GNU_SOURCE
#include <emmintrin.h>
#include "unittest.h"
#include "cpu.h"
#ifndef _MSC_VER
/*
* The x86 memory instructions are new enough that the compiler
* intrinsic functions are not always available. The intrinsic
* functions are defined here in terms of asm statements for now.
*/
#define _mm_clflushopt(addr)\
asm volatile(".byte 0x66; clflush %0" :\
"+m" (*(volatile char *)(addr)));
#define _mm_clwb(addr)\
asm volatile(".byte 0x66; xsaveopt %0" :\
"+m" (*(volatile char *)(addr)));
#endif
static char Buf[32];
/*
* check_cpu_features -- validates CPU features detection
*/
static void
check_cpu_features(void)
{
if (is_cpu_clflush_present()) {
UT_OUT("CLFLUSH supported");
_mm_clflush(Buf);
} else {
UT_OUT("CLFLUSH not supported");
}
if (is_cpu_clflushopt_present()) {
UT_OUT("CLFLUSHOPT supported");
_mm_clflushopt(Buf);
} else {
UT_OUT("CLFLUSHOPT not supported");
}
if (is_cpu_clwb_present()) {
UT_OUT("CLWB supported");
_mm_clwb(Buf);
} else {
UT_OUT("CLWB not supported");
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_cpuid");
check_cpu_features();
DONE(NULL);
}
| 2,821 | 28.395833 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_heap/obj_heap.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_heap.c -- unit test for heap
*/
#include "libpmemobj.h"
#include "palloc.h"
#include "heap.h"
#include "recycler.h"
#include "obj.h"
#include "unittest.h"
#include "util.h"
#include "container_ravl.h"
#include "container_seglists.h"
#include "container.h"
#include "alloc_class.h"
#include "valgrind_internal.h"
#include "set.h"
#define MOCK_POOL_SIZE PMEMOBJ_MIN_POOL
#define MAX_BLOCKS 3
struct mock_pop {
PMEMobjpool p;
void *heap;
};
static int
obj_heap_persist(void *ctx, const void *ptr, size_t sz, unsigned flags)
{
UT_ASSERTeq(pmem_msync(ptr, sz), 0);
return 0;
}
static int
obj_heap_flush(void *ctx, const void *ptr, size_t sz, unsigned flags)
{
UT_ASSERTeq(pmem_msync(ptr, sz), 0);
return 0;
}
static void
obj_heap_drain(void *ctx)
{
}
static void *
obj_heap_memset(void *ctx, void *ptr, int c, size_t sz, unsigned flags)
{
memset(ptr, c, sz);
UT_ASSERTeq(pmem_msync(ptr, sz), 0);
return ptr;
}
static void
init_run_with_score(struct heap_layout *l, uint32_t chunk_id, int score)
{
l->zone0.chunk_headers[chunk_id].size_idx = 1;
l->zone0.chunk_headers[chunk_id].type = CHUNK_TYPE_RUN;
l->zone0.chunk_headers[chunk_id].flags = 0;
struct chunk_run *run = (struct chunk_run *)
&l->zone0.chunks[chunk_id];
VALGRIND_DO_MAKE_MEM_UNDEFINED(run, sizeof(*run));
run->hdr.block_size = 1024;
memset(run->content, 0xFF, RUN_DEFAULT_BITMAP_SIZE);
UT_ASSERTeq(score % 64, 0);
score /= 64;
uint64_t *bitmap = (uint64_t *)run->content;
for (; score >= 0; --score) {
bitmap[score] = 0;
}
}
static void
init_run_with_max_block(struct heap_layout *l, uint32_t chunk_id)
{
l->zone0.chunk_headers[chunk_id].size_idx = 1;
l->zone0.chunk_headers[chunk_id].type = CHUNK_TYPE_RUN;
l->zone0.chunk_headers[chunk_id].flags = 0;
struct chunk_run *run = (struct chunk_run *)
&l->zone0.chunks[chunk_id];
VALGRIND_DO_MAKE_MEM_UNDEFINED(run, sizeof(*run));
uint64_t *bitmap = (uint64_t *)run->content;
run->hdr.block_size = 1024;
memset(bitmap, 0xFF, RUN_DEFAULT_BITMAP_SIZE);
/* the biggest block is 10 bits */
bitmap[3] =
0b1000001110111000111111110000111111000000000011111111110000000011;
}
static void
test_container(struct block_container *bc, struct palloc_heap *heap)
{
UT_ASSERTne(bc, NULL);
struct memory_block a = {1, 0, 1, 4};
struct memory_block b = {1, 0, 2, 8};
struct memory_block c = {1, 0, 3, 16};
struct memory_block d = {1, 0, 5, 32};
init_run_with_score(heap->layout, 1, 128);
memblock_rebuild_state(heap, &a);
memblock_rebuild_state(heap, &b);
memblock_rebuild_state(heap, &c);
memblock_rebuild_state(heap, &d);
int ret;
ret = bc->c_ops->insert(bc, &a);
UT_ASSERTeq(ret, 0);
ret = bc->c_ops->insert(bc, &b);
UT_ASSERTeq(ret, 0);
ret = bc->c_ops->insert(bc, &c);
UT_ASSERTeq(ret, 0);
ret = bc->c_ops->insert(bc, &d);
UT_ASSERTeq(ret, 0);
struct memory_block invalid_ret = {0, 0, 6, 0};
ret = bc->c_ops->get_rm_bestfit(bc, &invalid_ret);
UT_ASSERTeq(ret, ENOMEM);
struct memory_block b_ret = {0, 0, 2, 0};
ret = bc->c_ops->get_rm_bestfit(bc, &b_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(b_ret.chunk_id, b.chunk_id);
struct memory_block a_ret = {0, 0, 1, 0};
ret = bc->c_ops->get_rm_bestfit(bc, &a_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(a_ret.chunk_id, a.chunk_id);
struct memory_block c_ret = {0, 0, 3, 0};
ret = bc->c_ops->get_rm_bestfit(bc, &c_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(c_ret.chunk_id, c.chunk_id);
struct memory_block d_ret = {0, 0, 4, 0}; /* less one than target */
ret = bc->c_ops->get_rm_bestfit(bc, &d_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(d_ret.chunk_id, d.chunk_id);
ret = bc->c_ops->get_rm_bestfit(bc, &c_ret);
UT_ASSERTeq(ret, ENOMEM);
ret = bc->c_ops->insert(bc, &a);
UT_ASSERTeq(ret, 0);
ret = bc->c_ops->insert(bc, &b);
UT_ASSERTeq(ret, 0);
ret = bc->c_ops->insert(bc, &c);
UT_ASSERTeq(ret, 0);
bc->c_ops->rm_all(bc);
ret = bc->c_ops->is_empty(bc);
UT_ASSERTeq(ret, 1);
ret = bc->c_ops->get_rm_bestfit(bc, &c_ret);
UT_ASSERTeq(ret, ENOMEM);
bc->c_ops->destroy(bc);
}
static void
test_heap(void)
{
struct mock_pop *mpop = MMAP_ANON_ALIGNED(MOCK_POOL_SIZE,
Ut_mmap_align);
PMEMobjpool *pop = &mpop->p;
memset(pop, 0, MOCK_POOL_SIZE);
pop->heap_offset = (uint64_t)((uint64_t)&mpop->heap - (uint64_t)mpop);
pop->p_ops.persist = obj_heap_persist;
pop->p_ops.flush = obj_heap_flush;
pop->p_ops.drain = obj_heap_drain;
pop->p_ops.memset = obj_heap_memset;
pop->p_ops.base = pop;
pop->set = MALLOC(sizeof(*(pop->set)));
pop->set->options = 0;
pop->set->directory_based = 0;
struct stats *s = stats_new(pop);
UT_ASSERTne(s, NULL);
void *heap_start = (char *)pop + pop->heap_offset;
uint64_t heap_size = MOCK_POOL_SIZE - sizeof(PMEMobjpool);
struct palloc_heap *heap = &pop->heap;
struct pmem_ops *p_ops = &pop->p_ops;
UT_ASSERT(heap_check(heap_start, heap_size) != 0);
UT_ASSERT(heap_init(heap_start, heap_size,
&pop->heap_size, p_ops) == 0);
UT_ASSERT(heap_boot(heap, heap_start, heap_size,
&pop->heap_size,
pop, p_ops, s, pop->set) == 0);
UT_ASSERT(heap_buckets_init(heap) == 0);
UT_ASSERT(pop->heap.rt != NULL);
test_container((struct block_container *)container_new_ravl(heap),
heap);
test_container((struct block_container *)container_new_seglists(heap),
heap);
struct alloc_class *c_small = heap_get_best_class(heap, 1);
struct alloc_class *c_big = heap_get_best_class(heap, 2048);
UT_ASSERT(c_small->unit_size < c_big->unit_size);
/* new small buckets should be empty */
UT_ASSERT(c_big->type == CLASS_RUN);
struct memory_block blocks[MAX_BLOCKS] = {
{0, 0, 1, 0},
{0, 0, 1, 0},
{0, 0, 1, 0}
};
struct bucket *b_def = heap_bucket_acquire_by_id(heap,
DEFAULT_ALLOC_CLASS_ID);
for (int i = 0; i < MAX_BLOCKS; ++i) {
heap_get_bestfit_block(heap, b_def, &blocks[i]);
UT_ASSERT(blocks[i].block_off == 0);
}
heap_bucket_release(heap, b_def);
struct memory_block old_run = {0, 0, 1, 0};
struct memory_block new_run = {0, 0, 0, 0};
struct alloc_class *c_run = heap_get_best_class(heap, 1024);
struct bucket *b_run = heap_bucket_acquire(heap, c_run);
/*
* Allocate blocks from a run until one run is exhausted.
*/
UT_ASSERTne(heap_get_bestfit_block(heap, b_run, &old_run), ENOMEM);
int *nresv = bucket_current_resvp(b_run);
do {
new_run.chunk_id = 0;
new_run.block_off = 0;
new_run.size_idx = 1;
UT_ASSERTne(heap_get_bestfit_block(heap, b_run, &new_run),
ENOMEM);
UT_ASSERTne(new_run.size_idx, 0);
*nresv = 0;
} while (old_run.block_off != new_run.block_off);
*nresv = 0;
heap_bucket_release(heap, b_run);
stats_delete(pop, s);
UT_ASSERT(heap_check(heap_start, heap_size) == 0);
heap_cleanup(heap);
UT_ASSERT(heap->rt == NULL);
FREE(pop->set);
MUNMAP_ANON_ALIGNED(mpop, MOCK_POOL_SIZE);
}
static void
test_recycler(void)
{
struct mock_pop *mpop = MMAP_ANON_ALIGNED(MOCK_POOL_SIZE,
Ut_mmap_align);
PMEMobjpool *pop = &mpop->p;
memset(pop, 0, MOCK_POOL_SIZE);
pop->heap_offset = (uint64_t)((uint64_t)&mpop->heap - (uint64_t)mpop);
pop->p_ops.persist = obj_heap_persist;
pop->p_ops.flush = obj_heap_flush;
pop->p_ops.drain = obj_heap_drain;
pop->p_ops.memset = obj_heap_memset;
pop->p_ops.base = pop;
pop->set = MALLOC(sizeof(*(pop->set)));
pop->set->options = 0;
pop->set->directory_based = 0;
void *heap_start = (char *)pop + pop->heap_offset;
uint64_t heap_size = MOCK_POOL_SIZE - sizeof(PMEMobjpool);
struct palloc_heap *heap = &pop->heap;
struct pmem_ops *p_ops = &pop->p_ops;
struct stats *s = stats_new(pop);
UT_ASSERTne(s, NULL);
UT_ASSERT(heap_check(heap_start, heap_size) != 0);
UT_ASSERT(heap_init(heap_start, heap_size,
&pop->heap_size, p_ops) == 0);
UT_ASSERT(heap_boot(heap, heap_start, heap_size,
&pop->heap_size,
pop, p_ops, s, pop->set) == 0);
UT_ASSERT(heap_buckets_init(heap) == 0);
UT_ASSERT(pop->heap.rt != NULL);
/* trigger heap bucket populate */
struct memory_block m = MEMORY_BLOCK_NONE;
m.size_idx = 1;
struct bucket *b = heap_bucket_acquire_by_id(heap,
DEFAULT_ALLOC_CLASS_ID);
UT_ASSERT(heap_get_bestfit_block(heap, b, &m) == 0);
heap_bucket_release(heap, b);
int ret;
struct recycler *r = recycler_new(&pop->heap, 10000 /* never recalc */);
UT_ASSERTne(r, NULL);
init_run_with_score(pop->heap.layout, 0, 64);
init_run_with_score(pop->heap.layout, 1, 128);
init_run_with_score(pop->heap.layout, 15, 0);
struct memory_block mrun = {0, 0, 1, 0};
struct memory_block mrun2 = {1, 0, 1, 0};
memblock_rebuild_state(&pop->heap, &mrun);
memblock_rebuild_state(&pop->heap, &mrun2);
ret = recycler_put(r, &mrun,
recycler_element_new(&pop->heap, &mrun));
UT_ASSERTeq(ret, 0);
ret = recycler_put(r, &mrun2,
recycler_element_new(&pop->heap, &mrun2));
UT_ASSERTeq(ret, 0);
struct memory_block mrun_ret = MEMORY_BLOCK_NONE;
mrun_ret.size_idx = 1;
struct memory_block mrun2_ret = MEMORY_BLOCK_NONE;
mrun2_ret.size_idx = 1;
ret = recycler_get(r, &mrun_ret);
UT_ASSERTeq(ret, 0);
ret = recycler_get(r, &mrun2_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(mrun2.chunk_id, mrun2_ret.chunk_id);
UT_ASSERTeq(mrun.chunk_id, mrun_ret.chunk_id);
init_run_with_score(pop->heap.layout, 7, 64);
init_run_with_score(pop->heap.layout, 2, 128);
init_run_with_score(pop->heap.layout, 5, 192);
init_run_with_score(pop->heap.layout, 10, 256);
mrun.chunk_id = 7;
mrun2.chunk_id = 2;
struct memory_block mrun3 = {5, 0, 1, 0};
struct memory_block mrun4 = {10, 0, 1, 0};
memblock_rebuild_state(&pop->heap, &mrun3);
memblock_rebuild_state(&pop->heap, &mrun4);
mrun_ret.size_idx = 1;
mrun2_ret.size_idx = 1;
struct memory_block mrun3_ret = MEMORY_BLOCK_NONE;
mrun3_ret.size_idx = 1;
struct memory_block mrun4_ret = MEMORY_BLOCK_NONE;
mrun4_ret.size_idx = 1;
ret = recycler_put(r, &mrun,
recycler_element_new(&pop->heap, &mrun));
UT_ASSERTeq(ret, 0);
ret = recycler_put(r, &mrun2,
recycler_element_new(&pop->heap, &mrun2));
UT_ASSERTeq(ret, 0);
ret = recycler_put(r, &mrun3,
recycler_element_new(&pop->heap, &mrun3));
UT_ASSERTeq(ret, 0);
ret = recycler_put(r, &mrun4,
recycler_element_new(&pop->heap, &mrun4));
UT_ASSERTeq(ret, 0);
ret = recycler_get(r, &mrun_ret);
UT_ASSERTeq(ret, 0);
ret = recycler_get(r, &mrun2_ret);
UT_ASSERTeq(ret, 0);
ret = recycler_get(r, &mrun3_ret);
UT_ASSERTeq(ret, 0);
ret = recycler_get(r, &mrun4_ret);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(mrun.chunk_id, mrun_ret.chunk_id);
UT_ASSERTeq(mrun2.chunk_id, mrun2_ret.chunk_id);
UT_ASSERTeq(mrun3.chunk_id, mrun3_ret.chunk_id);
UT_ASSERTeq(mrun4.chunk_id, mrun4_ret.chunk_id);
init_run_with_max_block(pop->heap.layout, 1);
struct memory_block mrun5 = {1, 0, 1, 0};
memblock_rebuild_state(&pop->heap, &mrun5);
ret = recycler_put(r, &mrun5,
recycler_element_new(&pop->heap, &mrun5));
UT_ASSERTeq(ret, 0);
struct memory_block mrun5_ret = MEMORY_BLOCK_NONE;
mrun5_ret.size_idx = 11;
ret = recycler_get(r, &mrun5_ret);
UT_ASSERTeq(ret, ENOMEM);
mrun5_ret = MEMORY_BLOCK_NONE;
mrun5_ret.size_idx = 10;
ret = recycler_get(r, &mrun5_ret);
UT_ASSERTeq(ret, 0);
recycler_delete(r);
stats_delete(pop, s);
heap_cleanup(heap);
UT_ASSERT(heap->rt == NULL);
FREE(pop->set);
MUNMAP_ANON_ALIGNED(mpop, MOCK_POOL_SIZE);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_heap");
test_heap();
test_recycler();
DONE(NULL);
}
| 12,892 | 26.967462 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmreorder_stack/pmreorder_stack.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmreorder_stack.c -- unit test for engines pmreorder stack
*
* usage: pmreorder_stack w|c file
* w - write data in a possibly inconsistent manner
* c - check data consistency
*
*/
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
/*
* Consistent only if field 'e' is set and field 'f' is not.
*/
struct fields {
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
};
/*
* write_fields -- (internal) write data in a consistent manner.
*/
static void
write_fields(struct fields *fieldsp)
{
VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.BEGIN");
VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.BEGIN");
fieldsp->a = 1;
fieldsp->b = 1;
fieldsp->c = 1;
fieldsp->d = 1;
pmem_persist(&fieldsp->a, sizeof(int) * 4);
VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.END");
fieldsp->e = 1;
fieldsp->f = 1;
fieldsp->g = 1;
fieldsp->h = 1;
pmem_persist(&fieldsp->e, sizeof(int) * 4);
VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.END");
fieldsp->i = 1;
fieldsp->j = 1;
fieldsp->k = 1;
fieldsp->l = 1;
pmem_persist(&fieldsp->i, sizeof(int) * 4);
}
/*
* check_consistency -- (internal) check struct fields consistency.
*/
static int
check_consistency(struct fields *fieldsp)
{
int consistency = 1;
if (fieldsp->e == 1 && fieldsp->f == 0)
consistency = 0;
return consistency;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "pmreorder_stack");
VALGRIND_EMIT_LOG("NOT_DEFINED_BY_USER.END");
util_init();
if ((argc != 3) || (strchr("wc", argv[1][0]) == NULL) ||
argv[1][1] != '\0')
UT_FATAL("usage: %s w|c file", argv[0]);
int fd = OPEN(argv[2], O_RDWR);
size_t size;
/* mmap and register in valgrind pmemcheck */
void *map = pmem_map_file(argv[2], 0, 0, 0, &size, NULL);
UT_ASSERTne(map, NULL);
UT_ASSERT(size >= sizeof(struct fields));
struct fields *fieldsp = map;
char opt = argv[1][0];
/* clear the struct to get a consistent start state for writing */
if (strchr("w", opt))
pmem_memset_persist(fieldsp, 0, sizeof(*fieldsp));
switch (opt) {
case 'w':
write_fields(fieldsp);
break;
case 'c':
return check_consistency(fieldsp);
default:
UT_FATAL("Unrecognized option %c", opt);
}
CLOSE(fd);
DONE(NULL);
}
| 3,820 | 23.811688 | 74 | c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.