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/tools/fallocate_detect/fallocate_detect.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.
*/
/*
* fallocate_detect -- checks fallocate support on filesystem
*/
#define _GNU_SOURCE
#include "file.h"
#include "os.h"
#ifdef __linux__
#include <errno.h>
#include <fcntl.h>
#include <linux/magic.h>
#include <sys/vfs.h>
#ifndef XFS_SUPER_MAGIC
#define XFS_SUPER_MAGIC 0x58465342
#endif
/*
* posix_fallocate on Linux is implemented using fallocate
* syscall. This syscall requires file system-specific code on
* the kernel side and not all file systems have this code.
* So when posix_fallocate gets 'not supported' error from
* fallocate it falls back to just writing zeroes.
* Detect it and return information to the caller.
*/
static int
check_fallocate(const char *file)
{
int exit_code = 0;
int fd = os_open(file, O_RDWR | O_CREAT | O_EXCL, 0644);
if (fd < 0) {
perror("os_open");
return 2;
}
if (fallocate(fd, 0, 0, 4096)) {
if (errno == EOPNOTSUPP) {
exit_code = 1;
goto exit;
}
perror("fallocate");
exit_code = 2;
goto exit;
}
struct statfs fs;
if (!fstatfs(fd, &fs)) {
if (fs.f_type != EXT4_SUPER_MAGIC && /* also ext2, ext3 */
fs.f_type != XFS_SUPER_MAGIC) {
/*
* On CoW filesystems, fallocate reserves _amount
* of_ space but doesn't allocate a specific block.
* As we're interested in DAX filesystems only, just
* skip these tests anywhere else.
*/
exit_code = 1;
goto exit;
}
}
exit:
os_close(fd);
os_unlink(file);
return exit_code;
}
#else
/* no support for fallocate in FreeBSD */
static int
check_fallocate(const char *file)
{
return 1;
}
#endif
int
main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "usage: %s filename\n", argv[0]);
return 1;
}
return check_fallocate(argv[1]);
}
| 3,308 | 26.575 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/cmpmap/cmpmap.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.
*/
/*
* cmpmap -- a tool for comparing files using mmap
*/
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/mman.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "file.h"
#include "fcntl.h"
#include "mmap.h"
#include "os.h"
#define CMPMAP_ZERO (1<<0)
#define ADDR_SUM(vp, lp) ((void *)((char *)(vp) + (lp)))
/* arguments */
static char *File1 = NULL; /* file1 name */
static char *File2 = NULL; /* file2 name */
static size_t Length = 0; /* number of bytes to read */
static os_off_t Offset = 0; /* offset from beginning of file */
static int Opts = 0; /* options flag */
/*
* print_usage -- print short description of usage
*/
static void
print_usage(void)
{
printf("Usage: cmpmap [options] file1 [file2]\n");
printf("Valid options:\n");
printf("-l, --length=N - compare up to N bytes\n");
printf("-o, --offset=N - skip N bytes at start of the files\n");
printf("-z, --zero - compare bytes of the file1 to NUL\n");
printf("-h, --help - print this usage info\n");
}
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"length", required_argument, NULL, 'l'},
{"offset", required_argument, NULL, 'o'},
{"zero", no_argument, NULL, 'z'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0 },
};
/*
* parse_args -- (internal) parse command line arguments
*/
static int
parse_args(int argc, char *argv[])
{
int opt;
char *endptr;
os_off_t off;
ssize_t len;
while ((opt = getopt_long(argc, argv, "l:o:zh",
long_options, NULL)) != -1) {
switch (opt) {
case 'l':
errno = 0;
len = strtoll(optarg, &endptr, 0);
if ((endptr && *endptr != '\0') || errno || len < 0) {
fprintf(stderr, "'%s' -- invalid length",
optarg);
return -1;
}
Length = (size_t)len;
break;
case 'o':
errno = 0;
off = strtol(optarg, &endptr, 0);
if ((endptr && *endptr != '\0') || errno || off < 0) {
fprintf(stderr, "'%s' -- invalid offset",
optarg);
return -1;
}
Offset = off;
break;
case 'z':
Opts |= CMPMAP_ZERO;
break;
case 'h':
print_usage();
exit(EXIT_SUCCESS);
default:
print_usage();
exit(EXIT_FAILURE);
}
}
if (optind < argc) {
File1 = argv[optind];
if (optind + 1 < argc)
File2 = argv[optind + 1];
} else {
print_usage();
exit(EXIT_FAILURE);
}
return 0;
}
/*
* validate_args -- (internal) validate arguments
*/
static int
validate_args(void)
{
if (File1 == NULL) {
fprintf(stderr, "no file provided");
return -1;
} else if (File2 == NULL && Length == 0) {
fprintf(stderr, "length of the file has to be provided");
return -1;
}
return 0;
}
/*
* do_cmpmap -- (internal) perform cmpmap
*/
static int
do_cmpmap(void)
{
int ret = EXIT_SUCCESS;
int fd1;
int fd2;
size_t size1;
size_t size2;
/* open the first file */
if ((fd1 = os_open(File1, O_RDONLY)) < 0) {
fprintf(stderr, "opening %s failed, errno %d\n", File1, errno);
exit(EXIT_FAILURE);
}
ssize_t size_tmp = util_file_get_size(File1);
if (size_tmp < 0) {
fprintf(stderr, "getting size of %s failed, errno %d\n", File1,
errno);
ret = EXIT_FAILURE;
goto out_close1;
}
size1 = (size_t)size_tmp;
int flag = MAP_SHARED;
if (Opts & CMPMAP_ZERO) {
/* when checking if bytes are zeroed */
fd2 = -1;
size2 = (size_t)Offset + Length;
flag |= MAP_ANONYMOUS;
} else if (File2 != NULL) {
/* when comparing two files */
/* open the second file */
if ((fd2 = os_open(File2, O_RDONLY)) < 0) {
fprintf(stderr, "opening %s failed, errno %d\n",
File2, errno);
ret = EXIT_FAILURE;
goto out_close1;
}
size_tmp = util_file_get_size(File2);
if (size_tmp < 0) {
fprintf(stderr, "getting size of %s failed, errno %d\n",
File2, errno);
ret = EXIT_FAILURE;
goto out_close2;
}
size2 = (size_t)size_tmp;
/* basic check */
size_t min_size = (size1 < size2) ? size1 : size2;
if ((size_t)Offset + Length > min_size) {
if (size1 != size2) {
fprintf(stdout, "%s %s differ in size: %zu"
" %zu\n", File1, File2, size1, size2);
ret = EXIT_FAILURE;
goto out_close2;
} else {
Length = min_size - (size_t)Offset;
}
}
} else {
assert(0);
}
/* initialize utils */
util_init();
/* map the first file */
void *addr1;
if ((addr1 = util_map(fd1, size1, MAP_SHARED,
1, 0, NULL)) == MAP_FAILED) {
fprintf(stderr, "mmap failed, file %s, length %zu, offset 0,"
" errno %d\n", File1, size1, errno);
ret = EXIT_FAILURE;
goto out_close2;
}
/* map the second file, or do anonymous mapping to get zeroed bytes */
void *addr2;
if ((addr2 = util_map(fd2, size2, flag, 1, 0, NULL)) == MAP_FAILED) {
fprintf(stderr, "mmap failed, file %s, length %zu, errno %d\n",
File2 ? File2 : "(anonymous)", size2, errno);
ret = EXIT_FAILURE;
goto out_unmap1;
}
/* compare bytes of memory */
if ((ret = memcmp(ADDR_SUM(addr1, Offset), ADDR_SUM(addr2, Offset),
Length))) {
if (Opts & CMPMAP_ZERO)
fprintf(stderr, "%s is not zeroed\n", File1);
else
fprintf(stderr, "%s %s differ\n", File1, File2);
ret = EXIT_FAILURE;
}
munmap(addr2, size2);
out_unmap1:
munmap(addr1, size1);
out_close2:
if (File2 != NULL)
(void) os_close(fd2);
out_close1:
(void) os_close(fd1);
exit(ret);
}
int
main(int argc, char *argv[])
{
if (parse_args(argc, argv))
exit(EXIT_FAILURE);
if (validate_args())
exit(EXIT_FAILURE);
do_cmpmap();
}
| 7,071 | 23.989399 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/fip/fip.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.
*/
/*
* fip.c -- simple application which helps detecting libfabric providers
*
* usage: fip <addr> [<provider>]
*
* If no <provider> argument is specified returns 0 if any supported provider
* from libfabric is available. Otherwise returns 1;
*
* If <provider> argument is specified returns 0 if <provider> is supported
* by libfabric. Otherwise returns 1;
*
* On error returns -1.
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "rpmem_common.h"
#include "rpmem_fip_common.h"
int
main(int argc, char *argv[])
{
struct rpmem_fip_probe probe;
int ret;
if (argc > 3 || argc < 2) {
fprintf(stderr, "usage: %s <addr> [<provider>]\n", argv[0]);
return -1;
}
char *addr = argv[1];
char *prov_str = NULL;
if (argc == 3)
prov_str = argv[2];
struct rpmem_target_info *info;
info = rpmem_target_parse(addr);
if (!info) {
fprintf(stderr, "error: cannot parse address -- '%s'", addr);
return -1;
}
ret = rpmem_fip_probe_get(info->node, &probe);
if (ret) {
fprintf(stderr, "error: probing on '%s' failed\n", info->node);
return -1;
}
if (!prov_str) {
if (!rpmem_fip_probe_any(probe)) {
printf("no providers found\n");
ret = 1;
goto out;
}
ret = 0;
goto out;
}
enum rpmem_provider prov = rpmem_provider_from_str(prov_str);
if (prov == RPMEM_PROV_UNKNOWN) {
fprintf(stderr, "error: unsupported provider '%s'\n",
prov_str);
ret = -1;
goto out;
}
if (!rpmem_fip_probe(probe, prov)) {
printf("'%s' provider not available at '%s'\n",
prov_str, info->node);
ret = 1;
goto out;
}
out:
rpmem_target_free(info);
return ret;
}
| 3,240 | 27.182609 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/sparsefile/sparsefile.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.
*/
/*
* sparsefile.c -- a simple utility to create sparse files on Windows
*
* usage: sparsefile [options] filename len
* where options can be:
* -v - verbose output
* -s - do not create file if sparse files are not supported
* -f - overwrite file if already exists
*/
#include <windows.h>
#include <stdio.h>
#define MAXPRINT 8192
static int Opt_verbose;
static int Opt_sparse;
static int Opt_force;
/*
* out_err_vargs -- print error message
*/
static void
out_err_vargs(const wchar_t *fmt, va_list ap)
{
wchar_t errmsg[MAXPRINT];
DWORD lasterr = GetLastError();
vfwprintf(stderr, fmt, ap);
if (lasterr) {
size_t size = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM,
NULL, lasterr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
errmsg, MAXPRINT, NULL);
fwprintf(stderr, L": %s", errmsg);
} else {
fwprintf(stderr, L"\n");
}
SetLastError(0);
}
/*
* out_err -- print error message
*/
static void
out_err(const wchar_t *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
out_err_vargs(fmt, ap);
va_end(ap);
}
/*
* print_file_size -- prints file size and its size on disk
*/
static void
print_file_size(const wchar_t *filename)
{
LARGE_INTEGER filesize;
FILE_COMPRESSION_INFO fci;
HANDLE fh = CreateFileW(filename, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE) {
out_err(L"CreateFile");
return;
}
BOOL ret = GetFileSizeEx(fh, &filesize);
if (ret == FALSE) {
out_err(L"GetFileSizeEx");
goto err;
}
ret = GetFileInformationByHandleEx(fh, FileCompressionInfo,
&fci, sizeof(fci));
if (ret == FALSE) {
out_err(L"GetFileInformationByHandleEx");
goto err;
}
if (filesize.QuadPart < 65536)
fwprintf(stderr, L"\ntotal size: %lluB",
filesize.QuadPart);
else
fwprintf(stderr, L"\ntotal size: %lluKB",
filesize.QuadPart / 1024);
if (fci.CompressedFileSize.QuadPart < 65536)
fwprintf(stderr, L", actual size on disk: %lluKB\n",
fci.CompressedFileSize.QuadPart);
else
fwprintf(stderr, L", actual size on disk: %lluKB\n",
fci.CompressedFileSize.QuadPart / 1024);
err:
CloseHandle(fh);
}
/*
* create_sparse_file -- creates sparse file of given size
*/
static int
create_sparse_file(const wchar_t *filename, size_t len)
{
/* create zero-length file */
DWORD create = Opt_force ? CREATE_ALWAYS : CREATE_NEW;
HANDLE fh = CreateFileW(filename, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
create, FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE) {
out_err(L"CreateFile");
return -1;
}
SetLastError(0);
/* check if sparse files are supported */
DWORD flags = 0;
BOOL ret = GetVolumeInformationByHandleW(fh, NULL, 0, NULL, NULL,
&flags, NULL, 0);
if (ret == FALSE) {
if (Opt_verbose || Opt_sparse)
out_err(L"GetVolumeInformationByHandle");
} else if ((flags & FILE_SUPPORTS_SPARSE_FILES) == 0) {
if (Opt_verbose || Opt_sparse)
out_err(L"Volume does not support sparse files.");
if (Opt_sparse)
goto err;
}
/* mark file as sparse */
if (flags & FILE_SUPPORTS_SPARSE_FILES) {
DWORD nbytes;
ret = DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL,
0, &nbytes, NULL);
if (ret == FALSE) {
if (Opt_verbose || Opt_sparse)
out_err(L"DeviceIoControl");
if (Opt_sparse)
goto err;
}
}
/* set file length */
LARGE_INTEGER llen;
llen.QuadPart = len;
DWORD ptr = SetFilePointerEx(fh, llen, NULL, FILE_BEGIN);
if (ptr == INVALID_SET_FILE_POINTER) {
out_err(L"SetFilePointerEx");
goto err;
}
ret = SetEndOfFile(fh);
if (ret == FALSE) {
out_err(L"SetEndOfFile");
goto err;
}
CloseHandle(fh);
return 0;
err:
CloseHandle(fh);
DeleteFileW(filename);
return -1;
}
int
wmain(int argc, const wchar_t *argv[])
{
if (argc < 2) {
fwprintf(stderr, L"Usage: %s filename len\n", argv[0]);
exit(1);
}
int i = 1;
while (i < argc && argv[i][0] == '-') {
switch (argv[i][1]) {
case 'v':
Opt_verbose = 1;
break;
case 's':
Opt_sparse = 1;
break;
case 'f':
Opt_force = 1;
break;
default:
out_err(L"Unknown option: \'%c\'.", argv[i][1]);
exit(2);
}
++i;
}
const wchar_t *filename = argv[i];
long long len = _wtoll(argv[i + 1]);
if (len < 0) {
out_err(L"Invalid file length: %lld.\n", len);
exit(3);
}
if (create_sparse_file(filename, len) < 0) {
out_err(L"File creation failed.");
exit(4);
}
if (Opt_verbose)
print_file_size(filename);
return 0;
}
| 6,110 | 23.542169 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/obj_verify/obj_verify.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_verify.c -- tool for creating and verifying a pmemobj pool
*/
#include <stddef.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "libpmemobj.h"
#include "set.h"
#define SIGNATURE_LEN 10
#define NUMBER_LEN 10
#define FILL_SIZE 245 /* so that size of one record is 1024 bytes */
#define SKIP_OFFSET offsetof(struct data_s, checksum)
static const char *Signature = "OBJ_VERIFY";
POBJ_LAYOUT_BEGIN(obj_verify);
POBJ_LAYOUT_ROOT(obj_verify, struct root_s);
POBJ_LAYOUT_ROOT(obj_verify, struct data_s);
POBJ_LAYOUT_END(obj_verify);
struct data_s {
char signature[SIGNATURE_LEN];
char number_str[NUMBER_LEN];
uint64_t number;
uint32_t fill[FILL_SIZE];
uint64_t checksum;
};
struct root_s {
uint64_t count;
};
/*
* record_constructor -- constructor of a list element
*/
static int
record_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
struct data_s *rec = (struct data_s *)ptr;
uint64_t *count = arg;
memcpy(rec->signature, Signature, sizeof(rec->signature));
snprintf(rec->number_str, NUMBER_LEN, "%09lu", *count);
rec->number = *count;
for (int i = 0; i < FILL_SIZE; i++)
rec->fill[i] = (uint32_t)rand();
util_checksum(rec, sizeof(*rec), &rec->checksum,
1 /* insert */, SKIP_OFFSET);
pmemobj_persist(pop, rec, sizeof(*rec));
(*count)++;
pmemobj_persist(pop, count, sizeof(*count));
return 0;
}
/*
* do_create -- (internal) create a pool to be verified
*/
static void
do_create(const char *path, const char *layout)
{
struct pobj_alloc_class_desc class;
PMEMobjpool *pop;
PMEMoid oid;
uint64_t count;
srand((unsigned int)time(NULL));
if ((pop = pmemobj_create(path, layout, 0,
S_IWUSR | S_IRUSR)) == NULL) {
if (errno != EEXIST) {
out("!%s: pmemobj_create: %s",
path, pmemobj_errormsg());
exit(-1);
}
if ((pop = pmemobj_open(path, layout)) == NULL) {
out("!%s: pmemobj_open: %s",
path, pmemobj_errormsg());
exit(-1);
}
}
TOID(struct root_s) root = POBJ_ROOT(pop, struct root_s);
class.header_type = POBJ_HEADER_NONE;
class.unit_size = sizeof(struct data_s);
class.alignment = 0;
class.units_per_block = 1000;
if (pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &class) != 0) {
pmemobj_close(pop);
out("!pmemobj_ctl_set: %s", path);
exit(-1);
}
out("create(%s): allocating records in the pool ...", path);
count = D_RO(root)->count;
while (pmemobj_xalloc(pop, &oid, class.unit_size, 0,
POBJ_CLASS_ID(class.class_id),
record_constructor, &D_RW(root)->count) == 0)
;
count = D_RO(root)->count - count;
if (count) {
out("create(%s): allocated %lu records (of size %zu)",
path, count, sizeof(struct data_s));
} else {
out("create(%s): pool is full", path);
}
pmemobj_close(pop);
}
/*
* do_verify -- (internal) verify a poolset
*/
static void
do_verify(const char *path, const char *layout)
{
PMEMobjpool *pop;
PMEMoid oid;
uint64_t count = 0;
int error = 0;
if ((pop = pmemobj_open(path, layout)) == NULL) {
out("!%s: pmemobj_open: %s",
path, pmemobj_errormsg());
exit(-1);
}
TOID(struct root_s) root = POBJ_ROOT(pop, struct root_s);
TOID(struct data_s) rec;
POBJ_FOREACH(pop, oid) {
TOID_ASSIGN(rec, oid);
if (!util_checksum(D_RW(rec), sizeof(*D_RW(rec)),
&D_RW(rec)->checksum,
0 /* verify */, SKIP_OFFSET)) {
out("verify(%s): incorrect record: %s (#%lu)",
path, D_RW(rec)->signature, count);
error = 1;
break;
}
count++;
}
if (D_RO(root)->count != count) {
out(
"verify(%s): incorrect number of records (is: %lu, should be: %lu)",
path, count, D_RO(root)->count);
error = 1;
}
pmemobj_close(pop);
if (error) {
out("verify(%s): pool file contains error", path);
exit(-1);
}
out(
"verify(%s): pool file successfully verified (%lu records of size %zu)",
path, count, sizeof(struct data_s));
}
int
main(int argc, char *argv[])
{
util_init();
out_init("OBJ_VERIFY", "OBJ_VERIFY", "", 1, 0);
if (argc < 4) {
out("Usage: %s <obj_pool> <layout> <op:c|v>\n"
"Options:\n"
" c - create\n"
" v - verify\n",
argv[0]);
exit(-1);
}
const char *path = argv[1];
const char *layout = argv[2];
const char *op;
/* go through all arguments one by one */
for (int arg = 3; arg < argc; arg++) {
op = argv[arg];
if (op[1] != '\0') {
out("op must be c or v (c=create, v=verify)");
exit(-1);
}
switch (op[0]) {
case 'c': /* create and verify (no debug) */
do_create(path, layout);
break;
case 'v': /* verify (no debug) */
do_verify(path, layout);
break;
default:
out("op must be c or v (c=create, v=verify)");
exit(-1);
break;
}
}
out_fini();
return 0;
}
| 6,251 | 23.232558 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/ctrld/signals_linux.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.
*/
/*
* signals_linux.h - Signal definitions for Linux
*/
#ifndef _SIGNALS_LINUX_H
#define _SIGNALS_LINUX_H 1
#define SIGNAL_2_STR(sig) [sig] = #sig
static const char *signal2str[] = {
SIGNAL_2_STR(SIGHUP), /* 1 */
SIGNAL_2_STR(SIGINT), /* 2 */
SIGNAL_2_STR(SIGQUIT), /* 3 */
SIGNAL_2_STR(SIGILL), /* 4 */
SIGNAL_2_STR(SIGTRAP), /* 5 */
SIGNAL_2_STR(SIGABRT), /* 6 */
SIGNAL_2_STR(SIGBUS), /* 7 */
SIGNAL_2_STR(SIGFPE), /* 8 */
SIGNAL_2_STR(SIGKILL), /* 9 */
SIGNAL_2_STR(SIGUSR1), /* 10 */
SIGNAL_2_STR(SIGSEGV), /* 11 */
SIGNAL_2_STR(SIGUSR2), /* 12 */
SIGNAL_2_STR(SIGPIPE), /* 13 */
SIGNAL_2_STR(SIGALRM), /* 14 */
SIGNAL_2_STR(SIGTERM), /* 15 */
SIGNAL_2_STR(SIGSTKFLT), /* 16 */
SIGNAL_2_STR(SIGCHLD), /* 17 */
SIGNAL_2_STR(SIGCONT), /* 18 */
SIGNAL_2_STR(SIGSTOP), /* 19 */
SIGNAL_2_STR(SIGTSTP), /* 20 */
SIGNAL_2_STR(SIGTTIN), /* 21 */
SIGNAL_2_STR(SIGTTOU), /* 22 */
SIGNAL_2_STR(SIGURG), /* 23 */
SIGNAL_2_STR(SIGXCPU), /* 24 */
SIGNAL_2_STR(SIGXFSZ), /* 25 */
SIGNAL_2_STR(SIGVTALRM), /* 26 */
SIGNAL_2_STR(SIGPROF), /* 27 */
SIGNAL_2_STR(SIGWINCH), /* 28 */
SIGNAL_2_STR(SIGPOLL), /* 29 */
SIGNAL_2_STR(SIGPWR), /* 30 */
SIGNAL_2_STR(SIGSYS) /* 31 */
};
#define SIGNALMAX SIGSYS
#endif
| 2,837 | 36.342105 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/tools/ctrld/signals_freebsd.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.
*/
/*
* signals_fbsd.h - Signal definitions for FreeBSD
*/
#ifndef _SIGNALS_FBSD_H
#define _SIGNALS_FBSD_H 1
#define SIGNAL_2_STR(sig) [sig] = #sig
static const char *signal2str[] = {
SIGNAL_2_STR(SIGHUP), /* 1 */
SIGNAL_2_STR(SIGINT), /* 2 */
SIGNAL_2_STR(SIGQUIT), /* 3 */
SIGNAL_2_STR(SIGILL), /* 4 */
SIGNAL_2_STR(SIGTRAP), /* 5 */
SIGNAL_2_STR(SIGABRT), /* 6 */
SIGNAL_2_STR(SIGEMT), /* 7 */
SIGNAL_2_STR(SIGFPE), /* 8 */
SIGNAL_2_STR(SIGKILL), /* 9 */
SIGNAL_2_STR(SIGBUS), /* 10 */
SIGNAL_2_STR(SIGSEGV), /* 11 */
SIGNAL_2_STR(SIGSYS), /* 12 */
SIGNAL_2_STR(SIGPIPE), /* 13 */
SIGNAL_2_STR(SIGALRM), /* 14 */
SIGNAL_2_STR(SIGTERM), /* 15 */
SIGNAL_2_STR(SIGURG), /* 16 */
SIGNAL_2_STR(SIGSTOP), /* 17 */
SIGNAL_2_STR(SIGTSTP), /* 18 */
SIGNAL_2_STR(SIGCONT), /* 19 */
SIGNAL_2_STR(SIGCHLD), /* 20 */
SIGNAL_2_STR(SIGTTIN), /* 21 */
SIGNAL_2_STR(SIGTTOU), /* 22 */
SIGNAL_2_STR(SIGIO), /* 23 */
SIGNAL_2_STR(SIGXCPU), /* 24 */
SIGNAL_2_STR(SIGXFSZ), /* 25 */
SIGNAL_2_STR(SIGVTALRM), /* 26 */
SIGNAL_2_STR(SIGPROF), /* 27 */
SIGNAL_2_STR(SIGWINCH), /* 28 */
SIGNAL_2_STR(SIGINFO), /* 29 */
SIGNAL_2_STR(SIGUSR1), /* 30 */
SIGNAL_2_STR(SIGUSR2), /* 31 */
SIGNAL_2_STR(SIGTHR), /* 32 */
SIGNAL_2_STR(SIGLIBRT) /* 33 */
};
#define SIGNALMAX SIGLIBRT
#endif
| 2,901 | 35.734177 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_calloc/vmem_calloc.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_calloc.c -- unit test for vmem_calloc
*
* usage: vmem_calloc [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_calloc");
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(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");
}
int *test = vmem_calloc(vmp, 1, sizeof(int));
UT_ASSERTne(test, NULL);
/* pool_calloc should return zeroed memory */
UT_ASSERTeq(*test, 0);
*test = test_value;
UT_ASSERTeq(*test, test_value);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}
| 2,717 | 29.2 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_locks/obj_locks.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_locks.c -- unit test for PMEMmutex, PMEMrwlock and PMEMcond
*/
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "libpmemobj.h"
#define LAYOUT_NAME "obj_locks"
#define NUM_THREADS 16
#define MAX_FUNC 5
TOID_DECLARE(struct locks, 0);
struct locks {
PMEMobjpool *pop;
PMEMmutex mtx;
PMEMrwlock rwlk;
PMEMcond cond;
int data;
};
struct thread_args {
os_thread_t t;
TOID(struct locks) lock;
int t_id;
};
typedef void *(*fn_lock)(void *arg);
static struct thread_args threads[NUM_THREADS];
/*
* do_mutex_lock -- lock and unlock the mutex
*/
static void *
do_mutex_lock(void *arg)
{
struct thread_args *t = (struct thread_args *)arg;
struct locks *lock = D_RW(t->lock);
pmemobj_mutex_lock(lock->pop, &lock->mtx);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_mutex_unlock(lock->pop, &lock->mtx);
return NULL;
}
/*
* do_rwlock_wrlock -- lock and unlock the write rwlock
*/
static void *
do_rwlock_wrlock(void *arg)
{
struct thread_args *t = (struct thread_args *)arg;
struct locks *lock = D_RW(t->lock);
pmemobj_rwlock_wrlock(lock->pop, &lock->rwlk);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_rwlock_unlock(lock->pop, &lock->rwlk);
return NULL;
}
/*
* do_rwlock_rdlock -- lock and unlock the read rwlock
*/
static void *
do_rwlock_rdlock(void *arg)
{
struct thread_args *t = (struct thread_args *)arg;
struct locks *lock = D_RW(t->lock);
pmemobj_rwlock_rdlock(lock->pop, &lock->rwlk);
pmemobj_rwlock_unlock(lock->pop, &lock->rwlk);
return NULL;
}
/*
* do_cond_signal -- lock block on a condition variables,
* and unlock them by signal
*/
static void *
do_cond_signal(void *arg)
{
struct thread_args *t = (struct thread_args *)arg;
struct locks *lock = D_RW(t->lock);
if (t->t_id == 0) {
pmemobj_mutex_lock(lock->pop, &lock->mtx);
while (lock->data < (NUM_THREADS - 1))
pmemobj_cond_wait(lock->pop, &lock->cond,
&lock->mtx);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_mutex_unlock(lock->pop, &lock->mtx);
} else {
pmemobj_mutex_lock(lock->pop, &lock->mtx);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_cond_signal(lock->pop, &lock->cond);
pmemobj_mutex_unlock(lock->pop, &lock->mtx);
}
return NULL;
}
/*
* do_cond_broadcast -- lock block on a condition variables and unlock
* by broadcasting
*/
static void *
do_cond_broadcast(void *arg)
{
struct thread_args *t = (struct thread_args *)arg;
struct locks *lock = D_RW(t->lock);
if (t->t_id < (NUM_THREADS / 2)) {
pmemobj_mutex_lock(lock->pop, &lock->mtx);
while (lock->data < (NUM_THREADS / 2))
pmemobj_cond_wait(lock->pop, &lock->cond,
&lock->mtx);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_mutex_unlock(lock->pop, &lock->mtx);
} else {
pmemobj_mutex_lock(lock->pop, &lock->mtx);
lock->data++;
pmemobj_persist(lock->pop, &lock->data, sizeof(lock->data));
pmemobj_cond_broadcast(lock->pop, &lock->cond);
pmemobj_mutex_unlock(lock->pop, &lock->mtx);
}
return NULL;
}
static fn_lock do_lock[MAX_FUNC] = {do_mutex_lock, do_rwlock_wrlock,
do_rwlock_rdlock, do_cond_signal,
do_cond_broadcast};
/*
* do_lock_init -- initialize all types of locks
*/
static void
do_lock_init(struct locks *lock)
{
pmemobj_mutex_zero(lock->pop, &lock->mtx);
pmemobj_rwlock_zero(lock->pop, &lock->rwlk);
pmemobj_cond_zero(lock->pop, &lock->cond);
}
/*
* do_lock_mt -- perform multithread lock operations
*/
static void
do_lock_mt(TOID(struct locks) lock, unsigned f_num)
{
D_RW(lock)->data = 0;
for (int i = 0; i < NUM_THREADS; ++i) {
threads[i].lock = lock;
threads[i].t_id = i;
PTHREAD_CREATE(&threads[i].t, NULL, do_lock[f_num],
&threads[i]);
}
for (int i = 0; i < NUM_THREADS; ++i)
PTHREAD_JOIN(&threads[i].t, NULL);
/*
* If all threads passed function properly and used every lock, there
* should be every element in data array incremented exactly one time
* by every thread.
*/
UT_ASSERT((D_RO(lock)->data == NUM_THREADS) ||
(D_RO(lock)->data == 0));
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_locks");
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");
TOID(struct locks) lock;
POBJ_ALLOC(pop, &lock, struct locks, sizeof(struct locks), NULL, NULL);
D_RW(lock)->pop = pop;
do_lock_init(D_RW(lock));
for (unsigned i = 0; i < MAX_FUNC; i++)
do_lock_mt(lock, i);
POBJ_FREE(&lock);
pmemobj_close(pop);
DONE(NULL);
}
| 6,338 | 26.56087 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_feature/libpmempool_feature.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_feature -- pmempool_feature_(enable|disable|query) test
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include "libpmempool.h"
#include "pool_hdr.h"
#include "unittest.h"
#define EMPTY_FLAGS 0
/*
* print_usage -- print usage of program
*/
static void
print_usage(const char *name)
{
UT_OUT("usage: %s <pool_path> (e|d|q) <feature-name>", name);
UT_OUT("feature-name: SINGLEHDR, CKSUM_2K, SHUTDOWN_STATE");
}
/*
* str2pmempool_feature -- convert feature name to pmempool_feature enum
*/
static enum pmempool_feature
str2pmempool_feature(const char *app, const char *str)
{
uint32_t fval = util_str2pmempool_feature(str);
if (fval == UINT32_MAX) {
print_usage(app);
UT_FATAL("unknown feature: %s", str);
}
return (enum pmempool_feature)fval;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "libpmempool_feature");
if (argc < 4) {
print_usage(argv[0]);
UT_FATAL("insufficient number of arguments: %d", argc - 1);
}
const char *path = argv[1];
char cmd = argv[2][0];
enum pmempool_feature feature = str2pmempool_feature(argv[0], argv[3]);
int ret;
switch (cmd) {
case 'e':
return pmempool_feature_enable(path, feature, EMPTY_FLAGS);
case 'd':
return pmempool_feature_disable(path, feature, EMPTY_FLAGS);
case 'q':
ret = pmempool_feature_query(path, feature, EMPTY_FLAGS);
if (ret < 0)
return 1;
UT_OUT("query %s result is %d", argv[3], ret);
return 0;
default:
print_usage(argv[0]);
UT_FATAL("unknown command: %c", cmd);
}
DONE(NULL);
}
| 3,137 | 28.603774 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_flow/obj_tx_flow.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_flow.c -- unit test for transaction flow
*/
#include "unittest.h"
#define LAYOUT_NAME "direct"
#define TEST_VALUE_A 5
#define TEST_VALUE_B 10
#define TEST_VALUE_C 15
#define OPS_NUM 8
TOID_DECLARE(struct test_obj, 1);
struct test_obj {
int a;
int b;
int c;
};
static void
do_tx_macro_commit(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
TX_BEGIN(pop) {
D_RW(*obj)->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(D_RW(*obj)->a == TEST_VALUE_A);
D_RW(*obj)->b = TEST_VALUE_B;
} TX_ONABORT { /* not called */
D_RW(*obj)->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(D_RW(*obj)->b == TEST_VALUE_B);
D_RW(*obj)->c = TEST_VALUE_C;
} TX_END
}
static void
do_tx_macro_abort(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
D_RW(*obj)->a = TEST_VALUE_A;
D_RW(*obj)->b = TEST_VALUE_B;
TX_BEGIN(pop) {
TX_ADD(*obj);
D_RW(*obj)->a = TEST_VALUE_B;
pmemobj_tx_abort(EINVAL);
D_RW(*obj)->b = TEST_VALUE_A;
} TX_ONCOMMIT { /* not called */
D_RW(*obj)->a = TEST_VALUE_B;
} TX_ONABORT {
UT_ASSERT(D_RW(*obj)->a == TEST_VALUE_A);
UT_ASSERT(D_RW(*obj)->b == TEST_VALUE_B);
D_RW(*obj)->b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(D_RW(*obj)->b == TEST_VALUE_B);
D_RW(*obj)->c = TEST_VALUE_C;
} TX_END
}
static void
do_tx_macro_commit_nested(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
TX_BEGIN(pop) {
TX_BEGIN(pop) {
D_RW(*obj)->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(D_RW(*obj)->a == TEST_VALUE_A);
D_RW(*obj)->b = TEST_VALUE_B;
} TX_END
} TX_ONCOMMIT {
D_RW(*obj)->c = TEST_VALUE_C;
} TX_END
}
static void
do_tx_macro_abort_nested(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
volatile int a = 0;
volatile int b = 0;
volatile int c = 0;
D_RW(*obj)->a = TEST_VALUE_A;
D_RW(*obj)->b = TEST_VALUE_B;
TX_BEGIN(pop) {
TX_ADD(*obj);
D_RW(*obj)->a = TEST_VALUE_B;
a = TEST_VALUE_C;
TX_BEGIN(pop) {
D_RW(*obj)->b = TEST_VALUE_C;
a = TEST_VALUE_A;
pmemobj_tx_abort(EINVAL);
a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
a = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(a == TEST_VALUE_A);
b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(b == TEST_VALUE_B);
c = TEST_VALUE_C;
} TX_END
a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
UT_ASSERT(a == TEST_VALUE_A);
c = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(a == TEST_VALUE_A);
UT_ASSERT(b == TEST_VALUE_B);
UT_ASSERT(c == TEST_VALUE_C);
b = TEST_VALUE_A;
} TX_FINALLY {
UT_ASSERT(b == TEST_VALUE_A);
D_RW(*obj)->c = TEST_VALUE_C;
a = TEST_VALUE_B;
} TX_END
UT_ASSERT(a == TEST_VALUE_B);
}
static void
do_tx_commit(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
D_RW(*obj)->a = TEST_VALUE_A;
TX_ADD(*obj);
D_RW(*obj)->b = TEST_VALUE_B;
pmemobj_tx_commit();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONCOMMIT);
D_RW(*obj)->c = TEST_VALUE_C;
pmemobj_tx_end();
}
static void
do_tx_commit_nested(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
TX_ADD(*obj);
D_RW(*obj)->a = TEST_VALUE_A;
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
TX_ADD(*obj);
D_RW(*obj)->b = TEST_VALUE_B;
pmemobj_tx_commit();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONCOMMIT);
pmemobj_tx_end();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_WORK);
pmemobj_tx_commit();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONCOMMIT);
D_RW(*obj)->c = TEST_VALUE_C;
pmemobj_tx_end();
}
static void
do_tx_abort(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
D_RW(*obj)->a = TEST_VALUE_A;
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
D_RW(*obj)->b = TEST_VALUE_B;
TX_ADD(*obj);
D_RW(*obj)->a = 0;
pmemobj_tx_abort(EINVAL);
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONABORT);
D_RW(*obj)->c = TEST_VALUE_C;
pmemobj_tx_end();
}
static void
do_tx_abort_nested(PMEMobjpool *pop, TOID(struct test_obj) *obj)
{
D_RW(*obj)->a = TEST_VALUE_A;
D_RW(*obj)->b = TEST_VALUE_B;
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
TX_ADD(*obj);
D_RW(*obj)->a = 0;
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
TX_ADD(*obj);
D_RW(*obj)->b = 0;
pmemobj_tx_abort(EINVAL);
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONABORT);
pmemobj_tx_end();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONABORT);
D_RW(*obj)->c = TEST_VALUE_C;
pmemobj_tx_end();
}
typedef void (*fn_op)(PMEMobjpool *pop, TOID(struct test_obj) *obj);
static fn_op tx_op[OPS_NUM] = {do_tx_macro_commit, do_tx_macro_abort,
do_tx_macro_commit_nested, do_tx_macro_abort_nested,
do_tx_commit, do_tx_commit_nested, do_tx_abort,
do_tx_abort_nested};
static void
do_tx_process(PMEMobjpool *pop)
{
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_WORK);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONCOMMIT);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_FINALLY);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_NONE);
pmemobj_tx_end();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_NONE);
}
static void
do_tx_process_nested(PMEMobjpool *pop)
{
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_WORK);
pmemobj_tx_begin(pop, NULL, TX_PARAM_NONE);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONCOMMIT);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_FINALLY);
pmemobj_tx_end();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_WORK);
pmemobj_tx_abort(EINVAL);
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_ONABORT);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_FINALLY);
pmemobj_tx_process();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_NONE);
pmemobj_tx_end();
UT_ASSERT(pmemobj_tx_stage() == TX_STAGE_NONE);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_flow");
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");
TOID(struct test_obj) obj;
POBJ_ZNEW(pop, &obj, struct test_obj);
for (int i = 0; i < OPS_NUM; i++) {
D_RW(obj)->a = 0;
D_RW(obj)->b = 0;
D_RW(obj)->c = 0;
tx_op[i](pop, &obj);
UT_ASSERT(D_RO(obj)->a == TEST_VALUE_A);
UT_ASSERT(D_RO(obj)->b == TEST_VALUE_B);
UT_ASSERT(D_RO(obj)->c == TEST_VALUE_C);
}
do_tx_process(pop);
do_tx_process_nested(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 8,006 | 26.515464 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_pool_hdr/util_pool_hdr.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_pool_hdr.c -- unit test for pool_hdr layout and default values
*
* 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 "pool_hdr.h"
#define POOL_HDR_SIG_LEN_V1 (8)
#define POOL_HDR_UNUSED_LEN_V1 (1904)
#define POOL_HDR_UNUSED2_LEN_V1 (1976)
#define POOL_HDR_2K_CHECKPOINT (2048UL)
#define FEATURES_T_SIZE_V1 (12)
#define ARCH_FLAGS_SIZE_V1 (16)
#define ARCH_FLAGS_RESERVED_LEN_V1 (4)
#define SHUTDOWN_STATE_SIZE_V1 (64)
#define SHUTDOWN_STATE_RESERVED_LEN_V1 (39)
/*
* test_layout -- test pool_hdr layout
*/
static void
test_layout()
{
ASSERT_ALIGNED_BEGIN(struct pool_hdr);
ASSERT_ALIGNED_FIELD(struct pool_hdr, signature);
ASSERT_FIELD_SIZE(signature, POOL_HDR_SIG_LEN_V1);
ASSERT_ALIGNED_FIELD(struct pool_hdr, major);
ASSERT_ALIGNED_FIELD(struct pool_hdr, features);
ASSERT_ALIGNED_FIELD(struct pool_hdr, poolset_uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, prev_part_uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, next_part_uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, prev_repl_uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, next_repl_uuid);
ASSERT_ALIGNED_FIELD(struct pool_hdr, crtime);
ASSERT_ALIGNED_FIELD(struct pool_hdr, arch_flags);
ASSERT_ALIGNED_FIELD(struct pool_hdr, unused);
ASSERT_FIELD_SIZE(unused, POOL_HDR_UNUSED_LEN_V1);
ASSERT_OFFSET_CHECKPOINT(struct pool_hdr, POOL_HDR_2K_CHECKPOINT);
ASSERT_ALIGNED_FIELD(struct pool_hdr, unused2);
ASSERT_FIELD_SIZE(unused2, POOL_HDR_UNUSED2_LEN_V1);
ASSERT_ALIGNED_FIELD(struct pool_hdr, sds);
ASSERT_ALIGNED_FIELD(struct pool_hdr, checksum);
ASSERT_ALIGNED_CHECK(struct pool_hdr);
ASSERT_ALIGNED_BEGIN(features_t);
ASSERT_ALIGNED_FIELD(features_t, compat);
ASSERT_ALIGNED_FIELD(features_t, incompat);
ASSERT_ALIGNED_FIELD(features_t, ro_compat);
ASSERT_ALIGNED_CHECK(features_t);
UT_COMPILE_ERROR_ON(sizeof(features_t) != FEATURES_T_SIZE_V1);
ASSERT_ALIGNED_BEGIN(struct arch_flags);
ASSERT_ALIGNED_FIELD(struct arch_flags, alignment_desc);
ASSERT_ALIGNED_FIELD(struct arch_flags, machine_class);
ASSERT_ALIGNED_FIELD(struct arch_flags, data);
ASSERT_ALIGNED_FIELD(struct arch_flags, reserved);
ASSERT_FIELD_SIZE(reserved, ARCH_FLAGS_RESERVED_LEN_V1);
ASSERT_ALIGNED_FIELD(struct arch_flags, machine);
ASSERT_ALIGNED_CHECK(struct arch_flags);
UT_COMPILE_ERROR_ON(sizeof(struct arch_flags) != ARCH_FLAGS_SIZE_V1);
ASSERT_ALIGNED_BEGIN(struct shutdown_state);
ASSERT_ALIGNED_FIELD(struct shutdown_state, usc);
ASSERT_ALIGNED_FIELD(struct shutdown_state, uuid);
ASSERT_ALIGNED_FIELD(struct shutdown_state, dirty);
ASSERT_ALIGNED_FIELD(struct shutdown_state, reserved);
ASSERT_FIELD_SIZE(reserved, SHUTDOWN_STATE_RESERVED_LEN_V1);
ASSERT_ALIGNED_FIELD(struct shutdown_state, checksum);
ASSERT_ALIGNED_CHECK(struct shutdown_state);
UT_COMPILE_ERROR_ON(sizeof(struct shutdown_state) !=
SHUTDOWN_STATE_SIZE_V1);
}
/* incompat features - final values */
#define POOL_FEAT_SINGLEHDR_FINAL 0x0001U
#define POOL_FEAT_CKSUM_2K_FINAL 0x0002U
#define POOL_FEAT_SDS_FINAL 0x0004U
/* incompat features effective values */
#ifdef _WIN32
#ifdef SDS_ENABLED
#define POOL_E_FEAT_SDS_FINAL POOL_FEAT_SDS_FINAL
#else
#define POOL_E_FEAT_SDS_FINAL 0x0000U /* empty */
#endif
#endif
#ifdef _WIN32
#define POOL_FEAT_INCOMPAT_DEFAULT_V1 \
(POOL_FEAT_CKSUM_2K_FINAL | POOL_E_FEAT_SDS_FINAL)
#else
/*
* shutdown state support on Linux requires root access
* so it is disabled by default
*/
#define POOL_FEAT_INCOMPAT_DEFAULT_V1 \
(POOL_FEAT_CKSUM_2K_FINAL)
#endif
/*
* test_default_values -- test default values
*/
static void
test_default_values()
{
UT_COMPILE_ERROR_ON(POOL_FEAT_SINGLEHDR != POOL_FEAT_SINGLEHDR_FINAL);
UT_COMPILE_ERROR_ON(POOL_FEAT_CKSUM_2K != POOL_FEAT_CKSUM_2K_FINAL);
UT_COMPILE_ERROR_ON(POOL_FEAT_SDS != POOL_FEAT_SDS_FINAL);
UT_COMPILE_ERROR_ON(POOL_FEAT_INCOMPAT_DEFAULT !=
POOL_FEAT_INCOMPAT_DEFAULT_V1);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_pool_hdr");
test_layout();
test_default_values();
DONE(NULL);
}
| 5,743 | 34.02439 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_map_proc/util_map_proc.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.
*/
/*
* util_map_proc.c -- unit test for util_map() /proc parsing
*
* usage: util_map_proc maps_file len [len]...
*/
#define _GNU_SOURCE
#include <dlfcn.h>
#include "unittest.h"
#include "util.h"
#include "mmap.h"
#define GIGABYTE ((uintptr_t)1 << 30)
#define TERABYTE ((uintptr_t)1 << 40)
int
main(int argc, char *argv[])
{
START(argc, argv, "util_map_proc");
util_init();
util_mmap_init();
if (argc < 3)
UT_FATAL("usage: %s maps_file len [len]...", argv[0]);
Mmap_mapfile = argv[1];
UT_OUT("redirecting " OS_MAPFILE " to %s", Mmap_mapfile);
for (int arg = 2; arg < argc; arg++) {
size_t len = (size_t)strtoull(argv[arg], NULL, 0);
size_t align = 2 * MEGABYTE;
if (len >= 2 * GIGABYTE)
align = GIGABYTE;
void *h1 =
util_map_hint_unused((void *)TERABYTE, len, GIGABYTE);
void *h2 = util_map_hint(len, 0);
if (h1 != MAP_FAILED && h1 != NULL)
UT_ASSERTeq((uintptr_t)h1 & (GIGABYTE - 1), 0);
if (h2 != MAP_FAILED && h2 != NULL)
UT_ASSERTeq((uintptr_t)h2 & (align - 1), 0);
if (h1 == NULL) /* XXX portability */
UT_OUT("len %zu: (nil) %p", len, h2);
else if (h2 == NULL)
UT_OUT("len %zu: %p (nil)", len, h1);
else
UT_OUT("len %zu: %p %p", len, h1, h2);
}
util_mmap_fini();
DONE(NULL);
}
| 2,850 | 31.397727 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_lists/win_lists.c | /*
* Copyright 2015-2017, 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.
*/
/*
* win_lists.c -- test list routines used in windows implementation
*/
#include "unittest.h"
#include "queue.h"
typedef struct TEST_LIST_NODE {
LIST_ENTRY(TEST_LIST_NODE) ListEntry;
int dummy;
} *PTEST_LIST_NODE;
LIST_HEAD(TestList, TEST_LIST_NODE);
static void
dump_list(struct TestList *head)
{
PTEST_LIST_NODE pNode = NULL;
pNode = (PTEST_LIST_NODE)LIST_FIRST(head);
while (pNode != NULL) {
UT_OUT("Node value: %d", pNode->dummy);
pNode = (PTEST_LIST_NODE)LIST_NEXT(pNode, ListEntry);
}
}
static int
get_list_count(struct TestList *head)
{
PTEST_LIST_NODE pNode = NULL;
int listCount = 0;
pNode = (PTEST_LIST_NODE)LIST_FIRST(head);
while (pNode != NULL) {
listCount++;
pNode = (PTEST_LIST_NODE)LIST_NEXT(pNode, ListEntry);
}
return listCount;
}
/*
* test_list - Do some basic list manipulations and output to log for
* script comparison. Only testing the macros we use.
*/
static void
test_list(void)
{
PTEST_LIST_NODE pNode = NULL;
struct TestList head = LIST_HEAD_INITIALIZER(head);
LIST_INIT(&head);
UT_ASSERT_rt(LIST_EMPTY(&head));
pNode = MALLOC(sizeof(struct TEST_LIST_NODE));
pNode->dummy = 0;
LIST_INSERT_HEAD(&head, pNode, ListEntry);
UT_ASSERTeq_rt(1, get_list_count(&head));
dump_list(&head);
/* Remove one node */
LIST_REMOVE(pNode, ListEntry);
UT_ASSERTeq_rt(0, get_list_count(&head));
dump_list(&head);
free(pNode);
/* Add a bunch of nodes */
for (int i = 1; i < 10; i++) {
pNode = MALLOC(sizeof(struct TEST_LIST_NODE));
pNode->dummy = i;
LIST_INSERT_HEAD(&head, pNode, ListEntry);
}
UT_ASSERTeq_rt(9, get_list_count(&head));
dump_list(&head);
/* Remove all of them */
while (!LIST_EMPTY(&head)) {
pNode = (PTEST_LIST_NODE)LIST_FIRST(&head);
LIST_REMOVE(pNode, ListEntry);
free(pNode);
}
UT_ASSERTeq_rt(0, get_list_count(&head));
dump_list(&head);
}
typedef struct TEST_SORTEDQ_NODE {
SORTEDQ_ENTRY(TEST_SORTEDQ_NODE) queue_link;
int dummy;
} TEST_SORTEDQ_NODE, *PTEST_SORTEDQ_NODE;
SORTEDQ_HEAD(TEST_SORTEDQ, TEST_SORTEDQ_NODE);
static int
sortedq_node_comparer(TEST_SORTEDQ_NODE *a, TEST_SORTEDQ_NODE *b)
{
return a->dummy - b->dummy;
}
struct TEST_DATA_SORTEDQ {
int count;
int data[10];
};
/*
* test_sortedq - Do some basic operations on SORTEDQ and make sure that the
* queue is sorted for different input sequences.
*/
void
test_sortedq(void)
{
PTEST_SORTEDQ_NODE node = NULL;
struct TEST_SORTEDQ head = SORTEDQ_HEAD_INITIALIZER(head);
struct TEST_DATA_SORTEDQ test_data[] = {
{5, {5, 7, 9, 100, 101}},
{7, {1, 2, 3, 4, 5, 6, 7}},
{5, {100, 90, 80, 70, 40}},
{6, {10, 9, 8, 7, 6, 5}},
{5, {23, 13, 27, 4, 15}},
{5, {2, 2, 2, 2, 2}}
};
SORTEDQ_INIT(&head);
UT_ASSERT_rt(SORTEDQ_EMPTY(&head));
for (int i = 0; i < _countof(test_data); i++) {
for (int j = 0; j < test_data[i].count; j++) {
node = MALLOC(sizeof(TEST_SORTEDQ_NODE));
node->dummy = test_data[i].data[j];
SORTEDQ_INSERT(&head, node, queue_link,
TEST_SORTEDQ_NODE, sortedq_node_comparer);
}
int prev = MININT;
int num_entries = 0;
SORTEDQ_FOREACH(node, &head, queue_link) {
UT_ASSERT(prev <= node->dummy);
num_entries++;
}
UT_ASSERT(num_entries == test_data[i].count);
while (!SORTEDQ_EMPTY(&head)) {
node = SORTEDQ_FIRST(&head);
SORTEDQ_REMOVE(&head, node, queue_link);
FREE(node);
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "win_lists - testing %s",
(argc > 1) ? argv[1] : "list");
if (argc == 1 || (stricmp(argv[1], "list") == 0))
test_list();
if (argc > 1 && (stricmp(argv[1], "sortedq") == 0))
test_sortedq();
DONE(NULL);
}
| 5,267 | 26.295337 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_pool_win/cto_pool_win.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.
*/
/*
* cto_pool.c -- unit test for pmemcto_create() and pmemcto_open()
*
* usage: cto_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);
PMEMctopool *pop = pmemcto_createW(path, layout, poolsize, mode);
if (pop == NULL)
UT_OUT("!%s: pmemcto_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);
pmemcto_close(pop);
int result = pmemcto_checkW(path, layout);
if (result < 0)
UT_OUT("!%s: pmemcto_check", upath);
else if (result == 0)
UT_OUT("%s: pmemcto_check: not consistent", upath);
}
free(upath);
}
static void
pool_open(const wchar_t *path, const wchar_t *layout)
{
char *upath = ut_toUTF8(path);
PMEMctopool *pop = pmemcto_openW(path, layout);
if (pop == NULL) {
UT_OUT("!%s: pmemcto_open", upath);
} else {
UT_OUT("%s: pmemcto_open: Success", upath);
pmemcto_close(pop);
}
free(upath);
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "cto_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,475 | 26.15625 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pool/obj_pool.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_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 char *path, const char *layout, size_t poolsize,
unsigned mode)
{
PMEMobjpool *pop = pmemobj_create(path, layout, poolsize, mode);
if (pop == NULL)
UT_OUT("!%s: pmemobj_create: %s", path, pmemobj_errormsg());
else {
os_stat_t stbuf;
STAT(path, &stbuf);
UT_OUT("%s: file size %zu mode 0%o",
path, stbuf.st_size,
stbuf.st_mode & 0777);
pmemobj_close(pop);
int result = pmemobj_check(path, layout);
if (result < 0)
UT_OUT("!%s: pmemobj_check", path);
else if (result == 0)
UT_OUT("%s: pmemobj_check: not consistent", path);
}
}
static void
pool_open(const char *path, const char *layout)
{
PMEMobjpool *pop = pmemobj_open(path, layout);
if (pop == NULL)
UT_OUT("!%s: pmemobj_open: %s", path, pmemobj_errormsg());
else {
UT_OUT("%s: pmemobj_open: Success", path);
pmemobj_close(pop);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pool");
if (argc < 4)
UT_FATAL("usage: %s op path layout [poolsize mode]", argv[0]);
char *layout = NULL;
size_t poolsize;
unsigned mode;
if (strcmp(argv[3], "EMPTY") == 0)
layout = "";
else if (strcmp(argv[3], "NULL") != 0)
layout = argv[3];
switch (argv[1][0]) {
case 'c':
poolsize = strtoull(argv[4], NULL, 0) * MB; /* in megabytes */
mode = strtoul(argv[5], NULL, 8);
pool_create(argv[2], layout, poolsize, mode);
break;
case 'o':
pool_open(argv[2], layout);
break;
case 'f':
os_setenv("PMEMOBJ_CONF", "invalid-query", 1);
pool_open(argv[2], layout);
os_unsetenv("PMEMOBJ_CONF");
pool_open(argv[2], layout);
break;
default:
UT_FATAL("unknown operation");
}
DONE(NULL);
}
| 3,540 | 26.88189 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_create/vmem_create.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.c -- unit test for vmem_create
*
* usage: vmem_create directory
*/
#include "unittest.h"
static 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
main(int argc, char *argv[])
{
START(argc, argv, "vmem_create");
if (argc < 2 || argc > 3)
UT_FATAL("usage: %s directory", argv[0]);
Vmp = vmem_create(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,442 | 28.433735 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_root/obj_root.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_root.c -- unit tests for pmemobj_root
*/
#include "unittest.h"
#define FILE_SIZE ((size_t)0x440000000) /* 17 GB */
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_root");
if (argc < 2)
UT_FATAL("usage: obj_root <file> [l]");
const char *path = argv[1];
PMEMobjpool *pop = NULL;
os_stat_t st;
int long_test = 0;
if (argc >= 3 && argv[2][0] == 'l')
long_test = 1;
os_stat(path, &st);
UT_ASSERTeq(st.st_size, FILE_SIZE);
if ((pop = pmemobj_create(path, NULL, 0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
errno = 0;
PMEMoid oid = pmemobj_root(pop, 0);
UT_ASSERT(OID_EQUALS(oid, OID_NULL));
UT_ASSERTeq(errno, EINVAL);
if (long_test) {
oid = pmemobj_root(pop, PMEMOBJ_MAX_ALLOC_SIZE);
UT_ASSERT(!OID_EQUALS(oid, OID_NULL));
}
oid = pmemobj_root(pop, 1);
UT_ASSERT(!OID_EQUALS(oid, OID_NULL));
oid = pmemobj_root(pop, 0);
UT_ASSERT(!OID_EQUALS(oid, OID_NULL));
errno = 0;
oid = pmemobj_root(pop, FILE_SIZE);
UT_ASSERT(OID_EQUALS(oid, OID_NULL));
UT_ASSERTeq(errno, ENOMEM);
errno = 0;
oid = pmemobj_root(pop, SIZE_MAX);
UT_ASSERT(OID_EQUALS(oid, OID_NULL));
UT_ASSERTeq(errno, ENOMEM);
pmemobj_close(pop);
DONE(NULL);
}
| 2,813 | 29.586957 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pmalloc_basic/obj_pmalloc_basic.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_pmalloc_basic.c -- unit test for pmalloc interface
*/
#include <stdint.h>
#include "heap.h"
#include "obj.h"
#include "pmalloc.h"
#include "unittest.h"
#include "valgrind_internal.h"
#include "set.h"
#define MOCK_POOL_SIZE (PMEMOBJ_MIN_POOL * 3)
#define TEST_MEGA_ALLOC_SIZE (10 * 1024 * 1024)
#define TEST_HUGE_ALLOC_SIZE (4 * 255 * 1024)
#define TEST_SMALL_ALLOC_SIZE (1000)
#define TEST_MEDIUM_ALLOC_SIZE (1024 * 200)
#define TEST_TINY_ALLOC_SIZE (64)
#define TEST_RUNS 2
#define MAX_MALLOC_FREE_LOOP 1000
#define MALLOC_FREE_SIZE 8000
struct mock_pop {
PMEMobjpool p;
char lanes[LANE_TOTAL_SIZE];
char padding[1024]; /* to page boundary */
uint64_t ptr;
};
static struct mock_pop *addr;
static PMEMobjpool *mock_pop;
/*
* drain_empty -- (internal) empty function for drain on non-pmem memory
*/
static void
drain_empty(void)
{
/* do nothing */
}
/*
* obj_persist -- pmemobj version of pmem_persist w/o replication
*/
static int
obj_persist(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = ctx;
pop->persist_local(addr, len);
return 0;
}
/*
* obj_flush -- pmemobj version of pmem_flush w/o replication
*/
static int
obj_flush(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = ctx;
pop->flush_local(addr, len);
return 0;
}
/*
* obj_drain -- pmemobj version of pmem_drain w/o replication
*/
static void
obj_drain(void *ctx)
{
PMEMobjpool *pop = ctx;
pop->drain_local();
}
static void
obj_msync_nofail(const void *addr, size_t size)
{
if (pmem_msync(addr, size))
UT_FATAL("!pmem_msync");
}
/*
* obj_memcpy -- pmemobj version of memcpy w/o replication
*/
static void *
obj_memcpy(void *ctx, void *dest, const void *src, size_t len, unsigned flags)
{
pmem_memcpy(dest, src, len, flags);
return dest;
}
static void *
obj_memset(void *ctx, void *ptr, int c, size_t sz, unsigned flags)
{
pmem_memset(ptr, c, sz, flags);
return ptr;
}
static size_t
test_oom_allocs(size_t size)
{
uint64_t max_allocs = MOCK_POOL_SIZE / size;
uint64_t *allocs = CALLOC(max_allocs, sizeof(*allocs));
size_t count = 0;
for (;;) {
if (pmalloc(mock_pop, &addr->ptr, size, 0, 0)) {
break;
}
UT_ASSERT(addr->ptr != 0);
allocs[count++] = addr->ptr;
}
for (int i = 0; i < count; ++i) {
addr->ptr = allocs[i];
pfree(mock_pop, &addr->ptr);
UT_ASSERT(addr->ptr == 0);
}
UT_ASSERT(count != 0);
FREE(allocs);
return count;
}
static size_t
test_oom_resrv(size_t size)
{
uint64_t max_allocs = MOCK_POOL_SIZE / size;
uint64_t *allocs = CALLOC(max_allocs, sizeof(*allocs));
struct pobj_action *resvs = CALLOC(max_allocs, sizeof(*resvs));
size_t count = 0;
for (;;) {
if (palloc_reserve(&mock_pop->heap, size, NULL, NULL, 0, 0, 0,
&resvs[count]) != 0)
break;
allocs[count] = resvs[count].heap.offset;
UT_ASSERT(allocs[count] != 0);
count++;
}
for (size_t i = 0; i < count; ) {
size_t nresv = MIN(count - i, 10);
struct operation_context *ctx =
pmalloc_operation_hold(mock_pop);
palloc_publish(&mock_pop->heap, &resvs[i], nresv, ctx);
pmalloc_operation_release(mock_pop);
i += nresv;
}
for (int i = 0; i < count; ++i) {
addr->ptr = allocs[i];
pfree(mock_pop, &addr->ptr);
UT_ASSERT(addr->ptr == 0);
}
UT_ASSERT(count != 0);
FREE(allocs);
FREE(resvs);
return count;
}
static void
test_malloc_free_loop(size_t size)
{
int err;
for (int i = 0; i < MAX_MALLOC_FREE_LOOP; ++i) {
err = pmalloc(mock_pop, &addr->ptr, size, 0, 0);
UT_ASSERTeq(err, 0);
pfree(mock_pop, &addr->ptr);
}
}
static void
test_realloc(size_t org, size_t dest)
{
int err;
struct palloc_heap *heap = &mock_pop->heap;
err = pmalloc(mock_pop, &addr->ptr, org, 0, 0);
UT_ASSERTeq(err, 0);
UT_ASSERT(palloc_usable_size(heap, addr->ptr) >= org);
err = prealloc(mock_pop, &addr->ptr, dest, 0, 0);
UT_ASSERTeq(err, 0);
UT_ASSERT(palloc_usable_size(heap, addr->ptr) >= dest);
pfree(mock_pop, &addr->ptr);
}
#define PMALLOC_EXTRA 20
#define PALLOC_FLAG (1 << 15)
#define FIRST_SIZE 1 /* use the first allocation class */
#define FIRST_USIZE 112 /* the usable size is 128 - 16 */
static void
test_pmalloc_extras(PMEMobjpool *pop)
{
uint64_t val;
int ret = pmalloc(pop, &val, FIRST_SIZE, PMALLOC_EXTRA, PALLOC_FLAG);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(palloc_extra(&pop->heap, val), PMALLOC_EXTRA);
UT_ASSERT((palloc_flags(&pop->heap, val) & PALLOC_FLAG) == PALLOC_FLAG);
UT_ASSERT(palloc_usable_size(&pop->heap, val) == FIRST_USIZE);
pfree(pop, &val);
}
#define PMALLOC_ELEMENTS 20
static void
test_pmalloc_first_next(PMEMobjpool *pop)
{
uint64_t vals[PMALLOC_ELEMENTS];
for (unsigned i = 0; i < PMALLOC_ELEMENTS; ++i) {
int ret = pmalloc(pop, &vals[i], FIRST_SIZE, i, i);
UT_ASSERTeq(ret, 0);
}
uint64_t off = palloc_first(&pop->heap);
UT_ASSERTne(off, 0);
int nvalues = 0;
do {
UT_ASSERTeq(vals[nvalues], off);
UT_ASSERTeq(palloc_extra(&pop->heap, off), nvalues);
UT_ASSERTeq(palloc_flags(&pop->heap, off), nvalues);
UT_ASSERT(palloc_usable_size(&pop->heap, off) == FIRST_USIZE);
nvalues ++;
} while ((off = palloc_next(&pop->heap, off)) != 0);
UT_ASSERTeq(nvalues, PMALLOC_ELEMENTS);
for (int i = 0; i < PMALLOC_ELEMENTS; ++i)
pfree(pop, &vals[i]);
}
static void
test_mock_pool_allocs(void)
{
addr = MMAP_ANON_ALIGNED(MOCK_POOL_SIZE, Ut_mmap_align);
mock_pop = &addr->p;
mock_pop->addr = addr;
mock_pop->rdonly = 0;
mock_pop->is_pmem = 0;
mock_pop->heap_offset = offsetof(struct mock_pop, ptr);
UT_ASSERTeq(mock_pop->heap_offset % Ut_pagesize, 0);
mock_pop->nlanes = 1;
mock_pop->lanes_offset = sizeof(PMEMobjpool);
mock_pop->is_master_replica = 1;
mock_pop->persist_local = obj_msync_nofail;
mock_pop->flush_local = obj_msync_nofail;
mock_pop->drain_local = drain_empty;
mock_pop->p_ops.persist = obj_persist;
mock_pop->p_ops.flush = obj_flush;
mock_pop->p_ops.drain = obj_drain;
mock_pop->p_ops.memcpy = obj_memcpy;
mock_pop->p_ops.memset = obj_memset;
mock_pop->p_ops.base = mock_pop;
mock_pop->set = MALLOC(sizeof(*(mock_pop->set)));
mock_pop->set->options = 0;
mock_pop->set->directory_based = 0;
void *heap_start = (char *)mock_pop + mock_pop->heap_offset;
uint64_t heap_size = MOCK_POOL_SIZE - mock_pop->heap_offset;
struct stats *s = stats_new(mock_pop);
UT_ASSERTne(s, NULL);
heap_init(heap_start, heap_size, &mock_pop->heap_size,
&mock_pop->p_ops);
heap_boot(&mock_pop->heap, heap_start, heap_size, &mock_pop->heap_size,
mock_pop, &mock_pop->p_ops, s, mock_pop->set);
heap_buckets_init(&mock_pop->heap);
/* initialize runtime lanes structure */
mock_pop->lanes_desc.runtime_nlanes = (unsigned)mock_pop->nlanes;
lane_boot(mock_pop);
UT_ASSERTne(mock_pop->heap.rt, NULL);
test_pmalloc_extras(mock_pop);
test_pmalloc_first_next(mock_pop);
test_malloc_free_loop(MALLOC_FREE_SIZE);
size_t medium_resv = test_oom_resrv(TEST_MEDIUM_ALLOC_SIZE);
/*
* Allocating till OOM and freeing the objects in a loop for different
* buckets covers basically all code paths except error cases.
*/
size_t medium0 = test_oom_allocs(TEST_MEDIUM_ALLOC_SIZE);
size_t mega0 = test_oom_allocs(TEST_MEGA_ALLOC_SIZE);
size_t huge0 = test_oom_allocs(TEST_HUGE_ALLOC_SIZE);
size_t small0 = test_oom_allocs(TEST_SMALL_ALLOC_SIZE);
size_t tiny0 = test_oom_allocs(TEST_TINY_ALLOC_SIZE);
size_t huge1 = test_oom_allocs(TEST_HUGE_ALLOC_SIZE);
size_t small1 = test_oom_allocs(TEST_SMALL_ALLOC_SIZE);
size_t mega1 = test_oom_allocs(TEST_MEGA_ALLOC_SIZE);
size_t tiny1 = test_oom_allocs(TEST_TINY_ALLOC_SIZE);
size_t medium1 = test_oom_allocs(TEST_MEDIUM_ALLOC_SIZE);
UT_ASSERTeq(mega0, mega1);
UT_ASSERTeq(huge0, huge1);
UT_ASSERTeq(small0, small1);
UT_ASSERTeq(tiny0, tiny1);
UT_ASSERTeq(medium0, medium1);
UT_ASSERTeq(medium0, medium_resv);
/* realloc to the same size shouldn't affect anything */
for (size_t i = 0; i < tiny1; ++i)
test_realloc(TEST_TINY_ALLOC_SIZE, TEST_TINY_ALLOC_SIZE);
size_t tiny2 = test_oom_allocs(TEST_TINY_ALLOC_SIZE);
UT_ASSERTeq(tiny1, tiny2);
test_realloc(TEST_SMALL_ALLOC_SIZE, TEST_MEDIUM_ALLOC_SIZE);
test_realloc(TEST_HUGE_ALLOC_SIZE, TEST_MEGA_ALLOC_SIZE);
stats_delete(mock_pop, s);
lane_cleanup(mock_pop);
heap_cleanup(&mock_pop->heap);
FREE(mock_pop->set);
MUNMAP_ANON_ALIGNED(addr, MOCK_POOL_SIZE);
}
static void
test_spec_compliance(void)
{
uint64_t max_alloc = MAX_MEMORY_BLOCK_SIZE -
sizeof(struct allocation_header_legacy);
UT_ASSERTeq(max_alloc, PMEMOBJ_MAX_ALLOC_SIZE);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_basic");
for (int i = 0; i < TEST_RUNS; ++i)
test_mock_pool_allocs();
test_spec_compliance();
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
| 10,417 | 25.110276 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_check/vmem_check.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.c -- unit test for vmem_check
*
* usage: vmem_check [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_check");
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(VMEM_MIN_POOL * 2, 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");
}
UT_ASSERTeq(1, vmem_check(vmp));
/* create pool in this same memory region */
if (dir == NULL) {
void *mem_pool2 = (void *)(((uintptr_t)mem_pool +
VMEM_MIN_POOL / 2) & ~(Ut_mmap_align - 1));
VMEM *vmp2 = vmem_create_in_region(mem_pool2,
VMEM_MIN_POOL);
if (vmp2 == NULL)
UT_FATAL("!vmem_create_in_region");
/* detect memory range collision */
UT_ASSERTne(1, vmem_check(vmp));
UT_ASSERTne(1, vmem_check(vmp2));
vmem_delete(vmp2);
UT_ASSERTne(1, vmem_check(vmp2));
}
vmem_delete(vmp);
/* for vmem_create() memory unmapped after delete pool */
if (!dir)
UT_ASSERTne(1, vmem_check(vmp));
DONE(NULL);
}
| 2,949 | 28.79798 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_pool_win/blk_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.
*/
/*
* blk_pool_win.c -- unit test for pmemblk_create() and pmemblk_open()
*
* usage: blk_pool_win op path bsize [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, size_t bsize, size_t poolsize, unsigned mode)
{
char *upath = ut_toUTF8(path);
UT_ASSERTne(upath, NULL);
PMEMblkpool *pbp = pmemblk_createW(path, bsize, poolsize, mode);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_create", upath);
else {
os_stat_t stbuf;
STATW(path, &stbuf);
UT_OUT("%s: file size %zu usable blocks %zu mode 0%o",
upath, stbuf.st_size,
pmemblk_nblock(pbp),
stbuf.st_mode & 0777);
pmemblk_close(pbp);
int result = pmemblk_checkW(path, bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", upath);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", upath);
else
UT_ASSERTeq(pmemblk_checkW(path, bsize * 2), -1);
free(upath);
}
}
static void
pool_open(const wchar_t *path, size_t bsize)
{
char *upath = ut_toUTF8(path);
UT_ASSERTne(upath, NULL);
PMEMblkpool *pbp = pmemblk_openW(path, bsize);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_open", upath);
else {
UT_OUT("%s: pmemblk_open: Success", upath);
pmemblk_close(pbp);
}
free(upath);
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "blk_pool_win");
if (argc < 4)
UT_FATAL("usage: %s op path bsize [poolsize mode]",
ut_toUTF8(argv[0]));
size_t bsize = wcstoul(argv[3], NULL, 0);
size_t poolsize;
unsigned mode;
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], bsize, poolsize, mode);
break;
case 'o':
pool_open(argv[2], bsize);
break;
default:
UT_FATAL("unknown operation");
}
DONEW(NULL);
}
| 3,522 | 26.310078 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_common/win_common.c | /*
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
* 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.
*/
/*
* win_common.c -- test common POSIX or Linux API that were implemented
* for Windows by our library.
*/
#include "unittest.h"
/*
* test_setunsetenv - test the setenv and unsetenv APIs
*/
static void
test_setunsetenv(void)
{
os_unsetenv("TEST_SETUNSETENV_ONE");
/* set a new variable without overwriting - expect the new value */
UT_ASSERT(os_setenv("TEST_SETUNSETENV_ONE",
"test_setunsetenv_one", 0) == 0);
UT_ASSERT(strcmp(os_getenv("TEST_SETUNSETENV_ONE"),
"test_setunsetenv_one") == 0);
/* set an existing variable without overwriting - expect old value */
UT_ASSERT(os_setenv("TEST_SETUNSETENV_ONE",
"test_setunsetenv_two", 0) == 0);
UT_ASSERT(strcmp(os_getenv("TEST_SETUNSETENV_ONE"),
"test_setunsetenv_one") == 0);
/* set an existing variable with overwriting - expect the new value */
UT_ASSERT(os_setenv("TEST_SETUNSETENV_ONE",
"test_setunsetenv_two", 1) == 0);
UT_ASSERT(strcmp(os_getenv("TEST_SETUNSETENV_ONE"),
"test_setunsetenv_two") == 0);
/* unset our test value - expect it to be empty */
UT_ASSERT(os_unsetenv("TEST_SETUNSETENV_ONE") == 0);
UT_ASSERT(os_getenv("TEST_SETUNSETENV_ONE") == NULL);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "win_common - testing %s",
(argc > 1) ? argv[1] : "setunsetenv");
if (argc == 1 || (stricmp(argv[1], "setunsetenv") == 0))
test_setunsetenv();
DONE(NULL);
}
| 3,036 | 35.590361 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_realloc/obj_realloc.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_realloc.c -- unit test for pmemobj_realloc and pmemobj_zrealloc
*/
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "heap.h"
#include "alloc_class.h"
#include "obj.h"
#include "util.h"
#define MAX_ALLOC_MUL 8
#define MAX_ALLOC_CLASS 5
POBJ_LAYOUT_BEGIN(realloc);
POBJ_LAYOUT_ROOT(realloc, struct root);
POBJ_LAYOUT_TOID(realloc, struct object);
POBJ_LAYOUT_END(realloc);
struct object {
size_t value;
char data[];
};
struct root {
TOID(struct object) obj;
char data[CHUNKSIZE - sizeof(TOID(struct object))];
};
static struct alloc_class_collection *alloc_classes;
/*
* test_alloc -- test allocation using realloc
*/
static void
test_alloc(PMEMobjpool *pop, size_t size)
{
TOID(struct root) root = POBJ_ROOT(pop, struct root);
UT_ASSERT(TOID_IS_NULL(D_RO(root)->obj));
int ret = pmemobj_realloc(pop, &D_RW(root)->obj.oid, size,
TOID_TYPE_NUM(struct object));
UT_ASSERTeq(ret, 0);
UT_ASSERT(!TOID_IS_NULL(D_RO(root)->obj));
UT_ASSERT(pmemobj_alloc_usable_size(D_RO(root)->obj.oid) >= size);
}
/*
* test_free -- test free using realloc
*/
static void
test_free(PMEMobjpool *pop)
{
TOID(struct root) root = POBJ_ROOT(pop, struct root);
UT_ASSERT(!TOID_IS_NULL(D_RO(root)->obj));
int ret = pmemobj_realloc(pop, &D_RW(root)->obj.oid, 0,
TOID_TYPE_NUM(struct object));
UT_ASSERTeq(ret, 0);
UT_ASSERT(TOID_IS_NULL(D_RO(root)->obj));
}
static int check_integrity = 1;
/*
* fill_buffer -- fill buffer with random data and return its checksum
*/
static uint16_t
fill_buffer(unsigned char *buf, size_t size)
{
for (size_t i = 0; i < size; ++i)
buf[i] = rand() % 255;
pmem_persist(buf, size);
return ut_checksum(buf, size);
}
/*
* test_realloc -- test single reallocation
*/
static void
test_realloc(PMEMobjpool *pop, size_t size_from, size_t size_to,
unsigned type_from, unsigned type_to, int zrealloc)
{
TOID(struct root) root = POBJ_ROOT(pop, struct root);
UT_ASSERT(TOID_IS_NULL(D_RO(root)->obj));
int ret;
if (zrealloc)
ret = pmemobj_zalloc(pop, &D_RW(root)->obj.oid,
size_from, type_from);
else
ret = pmemobj_alloc(pop, &D_RW(root)->obj.oid,
size_from, type_from, NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERT(!TOID_IS_NULL(D_RO(root)->obj));
size_t usable_size_from =
pmemobj_alloc_usable_size(D_RO(root)->obj.oid);
UT_ASSERT(usable_size_from >= size_from);
size_t check_size;
uint16_t checksum;
if (zrealloc) {
UT_ASSERT(util_is_zeroed(D_RO(D_RO(root)->obj),
size_from));
} else if (check_integrity) {
check_size = size_to >= usable_size_from ?
usable_size_from : size_to;
checksum = fill_buffer((unsigned char *)D_RW(D_RW(root)->obj),
check_size);
}
if (zrealloc) {
ret = pmemobj_zrealloc(pop, &D_RW(root)->obj.oid,
size_to, type_to);
} else {
ret = pmemobj_realloc(pop, &D_RW(root)->obj.oid,
size_to, type_to);
}
UT_ASSERTeq(ret, 0);
UT_ASSERT(!TOID_IS_NULL(D_RO(root)->obj));
size_t usable_size_to =
pmemobj_alloc_usable_size(D_RO(root)->obj.oid);
UT_ASSERT(usable_size_to >= size_to);
if (size_to < size_from) {
UT_ASSERT(usable_size_to <= usable_size_from);
}
if (zrealloc) {
UT_ASSERT(util_is_zeroed(D_RO(D_RO(root)->obj), size_to));
} else if (check_integrity) {
uint16_t checksum2 = ut_checksum(
(uint8_t *)D_RW(D_RW(root)->obj), check_size);
if (checksum2 != checksum)
UT_ASSERTinfo(0, "memory corruption");
}
pmemobj_free(&D_RW(root)->obj.oid);
UT_ASSERT(TOID_IS_NULL(D_RO(root)->obj));
}
/*
* test_realloc_sizes -- test reallocations from/to specified sizes
*/
static void
test_realloc_sizes(PMEMobjpool *pop, unsigned type_from,
unsigned type_to, int zrealloc, unsigned size_diff)
{
for (uint8_t i = 0; i < MAX_ALLOCATION_CLASSES; ++i) {
struct alloc_class *c = alloc_class_by_id(alloc_classes, i);
if (c == NULL)
continue;
size_t header_size = header_type_to_size[c->header_type];
size_t size_from = c->unit_size - header_size - size_diff;
for (unsigned j = 2; j <= MAX_ALLOC_MUL; j++) {
size_t inc_size_to = c->unit_size * j - header_size;
test_realloc(pop, size_from, inc_size_to,
type_from, type_to, zrealloc);
size_t dec_size_to = c->unit_size / j;
if (dec_size_to <= header_size)
dec_size_to = header_size;
else
dec_size_to -= header_size;
test_realloc(pop, size_from, dec_size_to,
type_from, type_to, zrealloc);
for (int k = 0; k < MAX_ALLOC_CLASS; k++) {
struct alloc_class *ck = alloc_class_by_id(
alloc_classes, k);
if (c == NULL)
continue;
size_t header_sizek =
header_type_to_size[c->header_type];
size_t prev_size = ck->unit_size - header_sizek;
test_realloc(pop, size_from, prev_size,
type_from, type_to, zrealloc);
}
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_realloc");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(realloc) != 1);
if (argc < 2)
UT_FATAL("usage: %s file [check_integrity]", argv[0]);
PMEMobjpool *pop = pmemobj_open(argv[1], POBJ_LAYOUT_NAME(realloc));
if (!pop)
UT_FATAL("!pmemobj_open");
if (argc >= 3)
check_integrity = atoi(argv[2]);
alloc_classes = alloc_class_collection_new();
/* test alloc and free */
test_alloc(pop, 16);
test_free(pop);
/* test realloc without changing type number */
test_realloc_sizes(pop, 0, 0, 0, 0);
/* test realloc with changing type number */
test_realloc_sizes(pop, 0, 1, 0, 0);
/* test zrealloc without changing type number... */
test_realloc_sizes(pop, 0, 0, 1, 8);
test_realloc_sizes(pop, 0, 0, 1, 0);
/* test zrealloc with changing type number... */
test_realloc_sizes(pop, 0, 1, 1, 8);
test_realloc_sizes(pop, 0, 1, 1, 0);
alloc_class_collection_delete(alloc_classes);
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
extern "C" {
/*
* Since libpmemobj is linked statically,
* we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
}
#endif
| 7,547 | 26.249097 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_deep_persist/pmem_deep_persist.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_deep_persist.c -- unit test for pmem_deep_persist()
*
* usage: pmem_deep_persist file type deep_persist_size offset
*
* type is one of:
* p - call pmem_map_file()
* m - call mmap()
* o - call pmemobj_create()
*/
#include <string.h>
#include "unittest.h"
#include "file.h"
#include "os.h"
#include "file.h"
#include "set.h"
#include "obj.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "deep_persist"
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_deep_persist");
if (argc != 5)
UT_FATAL("usage: %s file type deep_persist_size offset",
argv[0]);
char *addr;
size_t mapped_len;
size_t persist_size;
size_t offset;
const char *path;
int is_pmem;
int ret = -1;
path = argv[1];
persist_size = (size_t)atoi(argv[3]);
offset = (size_t)atoi(argv[4]);
switch (*argv[2]) {
case 'p':
if ((addr = pmem_map_file(path, 0, 0,
0, &mapped_len, &is_pmem)) == NULL) {
UT_FATAL("!pmem_map_file");
}
if (persist_size == -1)
persist_size = mapped_len;
ret = pmem_deep_persist(addr + offset, persist_size);
break;
case 'm':
{
int fd = OPEN(path, O_RDWR);
ssize_t size = util_file_get_size(path);
if (size < 0)
UT_FATAL("!util_file_get_size: %s", path);
size_t file_size = (size_t)size;
/* XXX: add MAP_SYNC flag */
addr = MMAP(NULL, file_size, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, 0);
UT_ASSERTne(addr, MAP_FAILED);
CLOSE(fd);
if (persist_size == -1)
persist_size = file_size;
ret = pmem_deep_persist(addr + offset, persist_size);
break;
}
case 'o':
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
void *start = (void *)((uintptr_t)pop + offset);
int flush = 1;
VALGRIND_DO_MAKE_MEM_DEFINED(start, persist_size);
ret = util_replica_deep_common(start, persist_size,
pop->set, 0, flush);
pmemobj_close(pop);
}
}
UT_OUT("deep_persist %d", ret);
DONE(NULL);
}
/*
* open -- open mock because of Dev DAX without deep_flush
* sysfs file, eg. DAX on emulated pmem
*/
FUNC_MOCK(os_open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
if (strstr(path, "/sys/bus/nd/devices/region") &&
strstr(path, "/deep_flush")) {
UT_OUT("mocked open, path %s", path);
if (access(path, R_OK))
return 999;
}
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
/*
* write -- write mock
*/
FUNC_MOCK(write, int, int fd, const void *buffer, size_t count)
FUNC_MOCK_RUN_DEFAULT {
if (fd == 999) {
UT_OUT("mocked write, path %d", fd);
return 1;
}
return _FUNC_REAL(write)(fd, buffer, count);
}
FUNC_MOCK_END
| 4,376 | 26.018519 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_free/obj_tx_free.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_free.c -- unit test for pmemobj_tx_free
*/
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "tx_free"
#define OBJ_SIZE (200 * 1024)
enum type_number {
TYPE_FREE_NO_TX,
TYPE_FREE_WRONG_UUID,
TYPE_FREE_COMMIT,
TYPE_FREE_ABORT,
TYPE_FREE_COMMIT_NESTED1,
TYPE_FREE_COMMIT_NESTED2,
TYPE_FREE_ABORT_NESTED1,
TYPE_FREE_ABORT_NESTED2,
TYPE_FREE_ABORT_AFTER_NESTED1,
TYPE_FREE_ABORT_AFTER_NESTED2,
TYPE_FREE_OOM,
TYPE_FREE_ALLOC,
TYPE_FREE_AFTER_ABORT,
TYPE_FREE_MANY_TIMES,
};
TOID_DECLARE(struct object, 0);
struct object {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
/*
* do_tx_alloc -- do tx allocation with specified type number
*/
static PMEMoid
do_tx_alloc(PMEMobjpool *pop, unsigned type_num)
{
PMEMoid ret = OID_NULL;
TX_BEGIN(pop) {
ret = pmemobj_tx_alloc(sizeof(struct object), type_num);
} TX_END
return ret;
}
/*
* do_tx_free_wrong_uuid -- try to free object with invalid uuid
*/
static void
do_tx_free_wrong_uuid(PMEMobjpool *pop)
{
volatile int ret = 0;
PMEMoid oid = do_tx_alloc(pop, TYPE_FREE_WRONG_UUID);
oid.pool_uuid_lo = ~oid.pool_uuid_lo;
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid);
UT_ASSERTeq(ret, 0);
} TX_ONABORT {
ret = -1;
} TX_END
UT_ASSERTeq(ret, -1);
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_WRONG_UUID));
UT_ASSERT(!TOID_IS_NULL(obj));
}
/*
* do_tx_free_null_oid -- call pmemobj_tx_free with OID_NULL
*/
static void
do_tx_free_null_oid(PMEMobjpool *pop)
{
volatile int ret = 0;
TX_BEGIN(pop) {
ret = pmemobj_tx_free(OID_NULL);
} TX_ONABORT {
ret = -1;
} TX_END
UT_ASSERTeq(ret, 0);
}
/*
* do_tx_free_commit -- do the basic transactional deallocation of object
*/
static void
do_tx_free_commit(PMEMobjpool *pop)
{
int ret;
PMEMoid oid = do_tx_alloc(pop, TYPE_FREE_COMMIT);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid);
UT_ASSERTeq(ret, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_COMMIT));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_free_abort -- abort deallocation of object
*/
static void
do_tx_free_abort(PMEMobjpool *pop)
{
int ret;
PMEMoid oid = do_tx_alloc(pop, TYPE_FREE_ABORT);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid);
UT_ASSERTeq(ret, 0);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
}
/*
* do_tx_free_commit_nested -- do allocation in nested transaction
*/
static void
do_tx_free_commit_nested(PMEMobjpool *pop)
{
int ret;
PMEMoid oid1 = do_tx_alloc(pop, TYPE_FREE_COMMIT_NESTED1);
PMEMoid oid2 = do_tx_alloc(pop, TYPE_FREE_COMMIT_NESTED2);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid1);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid2);
UT_ASSERTeq(ret, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_COMMIT_NESTED1));
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_COMMIT_NESTED2));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_free_abort_nested -- abort allocation in nested transaction
*/
static void
do_tx_free_abort_nested(PMEMobjpool *pop)
{
int ret;
PMEMoid oid1 = do_tx_alloc(pop, TYPE_FREE_ABORT_NESTED1);
PMEMoid oid2 = do_tx_alloc(pop, TYPE_FREE_ABORT_NESTED2);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid1);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid2);
UT_ASSERTeq(ret, 0);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ABORT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj));
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ABORT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj));
}
/*
* do_tx_free_abort_after_nested -- abort transaction after nested
* pmemobj_tx_free
*/
static void
do_tx_free_abort_after_nested(PMEMobjpool *pop)
{
int ret;
PMEMoid oid1 = do_tx_alloc(pop, TYPE_FREE_ABORT_AFTER_NESTED1);
PMEMoid oid2 = do_tx_alloc(pop, TYPE_FREE_ABORT_AFTER_NESTED2);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid1);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
ret = pmemobj_tx_free(oid2);
UT_ASSERTeq(ret, 0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID(struct object) obj;
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop,
TYPE_FREE_ABORT_AFTER_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj));
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop,
TYPE_FREE_ABORT_AFTER_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj));
}
/*
* do_tx_free_alloc_abort -- free object allocated in the same transaction
* and abort transaction
*/
static void
do_tx_free_alloc_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(
sizeof(struct object), TYPE_FREE_ALLOC));
UT_ASSERT(!TOID_IS_NULL(obj));
ret = pmemobj_tx_free(obj.oid);
UT_ASSERTeq(ret, 0);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ALLOC));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_free_alloc_abort -- free object allocated in the same transaction
* and commit transaction
*/
static void
do_tx_free_alloc_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(
sizeof(struct object), TYPE_FREE_ALLOC));
UT_ASSERT(!TOID_IS_NULL(obj));
ret = pmemobj_tx_free(obj.oid);
UT_ASSERTeq(ret, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ALLOC));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_free_abort_free - allocate a new object, perform a transactional free
* in an aborted transaction and then to actually free the object.
*
* This can expose any issues with not properly handled free undo log.
*/
static void
do_tx_free_abort_free(PMEMobjpool *pop)
{
PMEMoid oid = do_tx_alloc(pop, TYPE_FREE_AFTER_ABORT);
TX_BEGIN(pop) {
pmemobj_tx_free(oid);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
pmemobj_tx_free(oid);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
/*
* do_tx_free_many_times -- free enough objects to trigger vector array alloc
*/
static void
do_tx_free_many_times(PMEMobjpool *pop)
{
#define TX_FREE_COUNT ((1 << 3) + 1)
PMEMoid oids[TX_FREE_COUNT];
for (int i = 0; i < TX_FREE_COUNT; ++i)
oids[i] = do_tx_alloc(pop, TYPE_FREE_MANY_TIMES);
TX_BEGIN(pop) {
for (int i = 0; i < TX_FREE_COUNT; ++i)
pmemobj_tx_free(oids[i]);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
#undef TX_FREE_COUNT
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_free");
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,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_free_wrong_uuid(pop);
VALGRIND_WRITE_STATS;
do_tx_free_null_oid(pop);
VALGRIND_WRITE_STATS;
do_tx_free_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_free_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_free_commit_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_free_abort_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_free_abort_after_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_free_alloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_free_alloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_free_abort_free(pop);
VALGRIND_WRITE_STATS;
do_tx_free_many_times(pop);
VALGRIND_WRITE_STATS;
pmemobj_close(pop);
DONE(NULL);
}
| 9,431 | 21.782609 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_malloc/vmmalloc_malloc.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_malloc.c -- unit test for libvmmalloc malloc
*
* usage: vmmalloc_malloc
*/
#include "unittest.h"
#define MIN_SIZE (sizeof(int))
#define SIZE 20
#define MAX_SIZE (MIN_SIZE << SIZE)
int
main(int argc, char *argv[])
{
const int test_value = 12345;
size_t size;
int *ptr[SIZE];
int i = 0;
size_t sum_alloc = 0;
START(argc, argv, "vmmalloc_malloc");
/* test with multiple size of allocations from 4MB to sizeof(int) */
for (size = MAX_SIZE; size > MIN_SIZE; size /= 2) {
ptr[i] = malloc(size);
if (ptr[i] == NULL)
continue;
*ptr[i] = test_value;
UT_ASSERTeq(*ptr[i], test_value);
sum_alloc += size;
i++;
}
/* at least one allocation for each size must succeed */
UT_ASSERTeq(size, MIN_SIZE);
/* allocate more than half of pool size */
UT_ASSERT(sum_alloc * 2 > VMEM_MIN_POOL);
while (i > 0)
free(ptr[--i]);
DONE(NULL);
}
| 2,480 | 29.62963 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_uuid_generate/util_uuid_generate.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_uuid_generate.c -- unit test for generating a uuid
*
* usage: util_uuid_generate [string] [valid|invalid]
*/
#include "unittest.h"
#include "uuid.h"
#include <unistd.h>
#include <string.h>
int
main(int argc, char *argv[])
{
START(argc, argv, "util_uuid_generate");
uuid_t uuid;
uuid_t uuid1;
int ret;
char conv_uu[POOL_HDR_UUID_STR_LEN];
char uu[POOL_HDR_UUID_STR_LEN];
/*
* No string passed in. Generate uuid.
*/
if (argc == 1) {
/* generate a UUID string */
ret = ut_get_uuid_str(uu);
UT_ASSERTeq(ret, 0);
/*
* Convert the the string to a uuid, convert generated
* uuid back to a string and compare strings.
*/
ret = util_uuid_from_string(uu, (struct uuid *)&uuid);
UT_ASSERTeq(ret, 0);
ret = util_uuid_to_string(uuid, conv_uu);
UT_ASSERTeq(ret, 0);
UT_ASSERT(strncmp(uu, conv_uu, POOL_HDR_UUID_STR_LEN) == 0);
/*
* Generate uuid from util_uuid_generate and translate to
* string then back to uuid to verify they match.
*/
memset(uuid, 0, sizeof(uuid_t));
memset(uu, 0, POOL_HDR_UUID_STR_LEN);
memset(conv_uu, 0, POOL_HDR_UUID_STR_LEN);
ret = util_uuid_generate(uuid);
UT_ASSERTeq(ret, 0);
ret = util_uuid_to_string(uuid, uu);
UT_ASSERTeq(ret, 0);
ret = util_uuid_from_string(uu, (struct uuid *)&uuid1);
UT_ASSERTeq(ret, 0);
UT_ASSERT(memcmp(&uuid, &uuid1, sizeof(uuid_t)) == 0);
} else {
/*
* Caller passed in string.
*/
if (strcmp(argv[2], "valid") == 0) {
ret = util_uuid_from_string(argv[1],
(struct uuid *)&uuid);
UT_ASSERTeq(ret, 0);
ret = util_uuid_to_string(uuid, conv_uu);
UT_ASSERTeq(ret, 0);
} else {
ret = util_uuid_from_string(argv[1],
(struct uuid *)&uuid);
UT_ASSERT(ret < 0);
UT_OUT("util_uuid_generate: invalid uuid string");
}
}
DONE(NULL);
}
| 3,404 | 29.401786 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pool_lookup/obj_pool_lookup.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_pool_lookup.c -- unit test for pmemobj_pool and pmemobj_pool_of
*/
#include "unittest.h"
#define MAX_PATH_LEN 255
#define LAYOUT_NAME "pool_lookup"
#define ALLOC_SIZE 100
static void
define_path(char *str, size_t size, const char *dir, unsigned i)
{
int ret = snprintf(str, size, "%s"OS_DIR_SEP_STR"testfile%d",
dir, i);
if (ret < 0 || ret >= size)
UT_FATAL("snprintf: %d", ret);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pool_lookup");
if (argc != 3)
UT_FATAL("usage: %s [directory] [# of pools]", argv[0]);
unsigned npools = ATOU(argv[2]);
const char *dir = argv[1];
int r;
/* check before pool creation */
PMEMoid some_oid = {2, 3};
UT_ASSERTeq(pmemobj_pool_by_ptr(&some_oid), NULL);
UT_ASSERTeq(pmemobj_pool_by_oid(some_oid), NULL);
PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMobjpool *));
void **guard_after = MALLOC(npools * sizeof(void *));
size_t length = strlen(dir) + MAX_PATH_LEN;
char *path = MALLOC(length);
for (unsigned i = 0; i < npools; ++i) {
define_path(path, length, dir, i);
pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
/*
* Reserve a page after the pool for address checks, if it
* doesn't map precisely at that address - it's OK.
*/
guard_after[i] =
MMAP((char *)pops[i] + PMEMOBJ_MIN_POOL, Ut_pagesize,
PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
UT_ASSERTne(guard_after[i], NULL);
if (pops[i] == NULL)
UT_FATAL("!pmemobj_create");
}
PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid));
for (unsigned i = 0; i < npools; ++i) {
r = pmemobj_alloc(pops[i], &oids[i], ALLOC_SIZE, 1, NULL, NULL);
UT_ASSERTeq(r, 0);
}
PMEMoid invalid = {123, 321};
UT_ASSERTeq(pmemobj_pool_by_oid(OID_NULL), NULL);
UT_ASSERTeq(pmemobj_pool_by_oid(invalid), NULL);
for (unsigned i = 0; i < npools; ++i) {
UT_ASSERTeq(pmemobj_pool_by_oid(oids[i]), pops[i]);
}
UT_ASSERTeq(pmemobj_pool_by_ptr(NULL), NULL);
UT_ASSERTeq(pmemobj_pool_by_ptr((void *)0xCBA), NULL);
void *valid_ptr = MALLOC(ALLOC_SIZE);
UT_ASSERTeq(pmemobj_pool_by_ptr(valid_ptr), NULL);
FREE(valid_ptr);
for (unsigned i = 0; i < npools; ++i) {
void *before_pool = (char *)pops[i] - 1;
void *after_pool = (char *)pops[i] + PMEMOBJ_MIN_POOL + 1;
void *start_pool = (char *)pops[i];
void *end_pool = (char *)pops[i] + PMEMOBJ_MIN_POOL - 1;
void *edge = (char *)pops[i] + PMEMOBJ_MIN_POOL;
void *middle = (char *)pops[i] + (PMEMOBJ_MIN_POOL / 2);
void *in_oid = (char *)pmemobj_direct(oids[i]) +
(ALLOC_SIZE / 2);
UT_ASSERTeq(pmemobj_pool_by_ptr(before_pool), NULL);
UT_ASSERTeq(pmemobj_pool_by_ptr(after_pool), NULL);
UT_ASSERTeq(pmemobj_pool_by_ptr(start_pool), pops[i]);
UT_ASSERTeq(pmemobj_pool_by_ptr(end_pool), pops[i]);
UT_ASSERTeq(pmemobj_pool_by_ptr(edge), NULL);
UT_ASSERTeq(pmemobj_pool_by_ptr(middle), pops[i]);
UT_ASSERTeq(pmemobj_pool_by_ptr(in_oid), pops[i]);
pmemobj_close(pops[i]);
UT_ASSERTeq(pmemobj_pool_by_ptr(middle), NULL);
UT_ASSERTeq(pmemobj_pool_by_ptr(in_oid), NULL);
MUNMAP(guard_after[i], Ut_pagesize);
}
for (unsigned i = 0; i < npools; ++i) {
UT_ASSERTeq(pmemobj_pool_by_oid(oids[i]), NULL);
define_path(path, length, dir, i);
pops[i] = pmemobj_open(path, LAYOUT_NAME);
UT_ASSERTne(pops[i], NULL);
UT_ASSERTeq(pmemobj_pool_by_oid(oids[i]), pops[i]);
pmemobj_close(pops[i]);
}
FREE(path);
FREE(pops);
FREE(guard_after);
FREE(oids);
DONE(NULL);
}
| 5,091 | 30.825 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_delete/vmem_delete.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_delete.c -- unit test for vmem_delete
*
* usage: vmem_delete <operation>
*
* operations are: 'h', 'f', 'm', 'c', 'r', 'a', 's', 'd'
*
*/
#include "unittest.h"
static ut_jmp_buf_t Jmp;
#ifndef _WIN32
#include <unistd.h>
#include <stdbool.h>
static bool is_done;
#endif
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
#ifndef _WIN32
/* Ignore signals from jemalloc destructor */
if (is_done)
_exit(0);
#endif
UT_OUT("\tsignal: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "vmem_delete");
VMEM *vmp;
void *ptr;
if (argc < 2)
UT_FATAL("usage: %s op:h|f|m|c|r|a|s|d", argv[0]);
/* 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");
ptr = vmem_malloc(vmp, sizeof(long long));
if (ptr == NULL)
UT_ERR("!vmem_malloc");
vmem_delete(vmp);
ASAN_POISON_MEMORY_REGION(vmp, sizeof(vmp));
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
SIGACTION(SIGABRT, &v, NULL);
SIGACTION(SIGILL, &v, NULL);
/* go through all arguments one by one */
for (int arg = 1; arg < argc; arg++) {
/* Scan the character of each argument. */
if (strchr("hfmcrasd", argv[arg][0]) == NULL ||
argv[arg][1] != '\0')
UT_FATAL("op must be one of: h, f, m, c, r, a, s, d");
switch (argv[arg][0]) {
case 'h':
UT_OUT("Testing vmem_check...");
if (!ut_sigsetjmp(Jmp)) {
UT_OUT("\tvmem_check returned %i",
vmem_check(vmp));
}
break;
case 'f':
UT_OUT("Testing vmem_free...");
if (!ut_sigsetjmp(Jmp)) {
vmem_free(vmp, ptr);
UT_OUT("\tvmem_free succeeded");
}
break;
case 'm':
UT_OUT("Testing vmem_malloc...");
if (!ut_sigsetjmp(Jmp)) {
ptr = vmem_malloc(vmp, sizeof(long long));
if (ptr != NULL)
UT_OUT("\tvmem_malloc succeeded");
else
UT_OUT("\tvmem_malloc returned NULL");
}
break;
case 'c':
UT_OUT("Testing vmem_calloc...");
if (!ut_sigsetjmp(Jmp)) {
ptr = vmem_calloc(vmp, 10, sizeof(int));
if (ptr != NULL)
UT_OUT("\tvmem_calloc succeeded");
else
UT_OUT("\tvmem_calloc returned NULL");
}
break;
case 'r':
UT_OUT("Testing vmem_realloc...");
if (!ut_sigsetjmp(Jmp)) {
ptr = vmem_realloc(vmp, ptr, 128);
if (ptr != NULL)
UT_OUT("\tvmem_realloc succeeded");
else
UT_OUT("\tvmem_realloc returned NULL");
}
break;
case 'a':
UT_OUT("Testing vmem_aligned_alloc...");
if (!ut_sigsetjmp(Jmp)) {
ptr = vmem_aligned_alloc(vmp, 128, 128);
if (ptr != NULL)
UT_OUT("\tvmem_aligned_alloc "
"succeeded");
else
UT_OUT("\tvmem_aligned_alloc"
" returned NULL");
}
break;
case 's':
UT_OUT("Testing vmem_strdup...");
if (!ut_sigsetjmp(Jmp)) {
ptr = vmem_strdup(vmp, "Test string");
if (ptr != NULL)
UT_OUT("\tvmem_strdup succeeded");
else
UT_OUT("\tvmem_strdup returned NULL");
}
break;
case 'd':
UT_OUT("Testing vmem_delete...");
if (!ut_sigsetjmp(Jmp)) {
vmem_delete(vmp);
if (errno != 0)
UT_OUT("\tvmem_delete failed: %s",
vmem_errormsg());
else
UT_OUT("\tvmem_delete succeeded");
}
break;
}
}
MUNMAP(mem_pool, VMEM_MIN_POOL);
#ifndef _WIN32
is_done = true;
#endif
DONE(NULL);
}
| 5,157 | 24.408867 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ravl/obj_ravl.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_ravl.c -- unit test for ravl tree
*/
#include <stdint.h>
#include <stdlib.h>
#include "ravl.h"
#include "util.h"
#include "unittest.h"
static int
cmpkey(const void *lhs, const void *rhs)
{
intptr_t l = (intptr_t)lhs;
intptr_t r = (intptr_t)rhs;
return (int)(l - r);
}
static void
test_misc(void)
{
struct ravl *r = ravl_new(cmpkey);
struct ravl_node *n = NULL;
ravl_insert(r, (void *)3);
ravl_insert(r, (void *)6);
ravl_insert(r, (void *)1);
ravl_insert(r, (void *)7);
ravl_insert(r, (void *)9);
ravl_insert(r, (void *)5);
ravl_insert(r, (void *)8);
ravl_insert(r, (void *)2);
ravl_insert(r, (void *)4);
ravl_insert(r, (void *)10);
n = ravl_find(r, (void *)11, RAVL_PREDICATE_EQUAL);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)10, RAVL_PREDICATE_GREATER);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)11, RAVL_PREDICATE_GREATER);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)11,
RAVL_PREDICATE_GREATER | RAVL_PREDICATE_EQUAL);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)1, RAVL_PREDICATE_LESS);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)0, RAVL_PREDICATE_LESS_EQUAL);
UT_ASSERTeq(n, NULL);
n = ravl_find(r, (void *)9, RAVL_PREDICATE_GREATER);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)10);
n = ravl_find(r, (void *)9, RAVL_PREDICATE_LESS);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)8);
n = ravl_find(r, (void *)9,
RAVL_PREDICATE_GREATER | RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)9);
n = ravl_find(r, (void *)9,
RAVL_PREDICATE_LESS | RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)9);
n = ravl_find(r, (void *)100, RAVL_PREDICATE_LESS);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)10);
n = ravl_find(r, (void *)0, RAVL_PREDICATE_GREATER);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)1);
n = ravl_find(r, (void *)3, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)10, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)6, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)9, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)7, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)1, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)5, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)8, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)2, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
n = ravl_find(r, (void *)4, RAVL_PREDICATE_EQUAL);
UT_ASSERTne(n, NULL);
ravl_remove(r, n);
ravl_delete(r);
}
static void
test_predicate(void)
{
struct ravl *r = ravl_new(cmpkey);
struct ravl_node *n = NULL;
ravl_insert(r, (void *)10);
ravl_insert(r, (void *)5);
ravl_insert(r, (void *)7);
n = ravl_find(r, (void *)6, RAVL_PREDICATE_GREATER);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)7);
n = ravl_find(r, (void *)6, RAVL_PREDICATE_LESS);
UT_ASSERTne(n, NULL);
UT_ASSERTeq(ravl_data(n), (void *)5);
ravl_delete(r);
}
static void
test_stress(void)
{
struct ravl *r = ravl_new(cmpkey);
for (int i = 0; i < 1000000; ++i) {
ravl_insert(r, (void *)(uintptr_t)rand());
}
ravl_delete(r);
}
struct foo {
int a;
int b;
int c;
};
static int
cmpfoo(const void *lhs, const void *rhs)
{
const struct foo *l = lhs;
const struct foo *r = rhs;
return ((l->a + l->b + l->c) - (r->a + r->b + r->c));
}
static void
test_emplace(void)
{
struct ravl *r = ravl_new_sized(cmpfoo, sizeof(struct foo));
struct foo a = {1, 2, 3};
struct foo b = {2, 3, 4};
struct foo z = {0, 0, 0};
ravl_emplace_copy(r, &a);
ravl_emplace_copy(r, &b);
struct ravl_node *n = ravl_find(r, &z, RAVL_PREDICATE_GREATER);
struct foo *fn = ravl_data(n);
UT_ASSERTeq(fn->a, a.a);
UT_ASSERTeq(fn->b, a.b);
UT_ASSERTeq(fn->c, a.c);
ravl_remove(r, n);
n = ravl_find(r, &z, RAVL_PREDICATE_GREATER);
fn = ravl_data(n);
UT_ASSERTeq(fn->a, b.a);
UT_ASSERTeq(fn->b, b.b);
UT_ASSERTeq(fn->c, b.c);
ravl_remove(r, n);
ravl_delete(r);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ravl");
test_predicate();
test_misc();
test_stress();
test_emplace();
DONE(NULL);
}
| 6,070 | 23.881148 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_constructor/obj_constructor.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_constructor.c -- tests for constructor
*/
#include <stddef.h>
#include "unittest.h"
/*
* Command line toggle indicating use of a bigger node structure for querying
* pool size expressed in a number of possible allocations. A small node
* structure results in a great number of allocations impossible to replicate
* in assumed timeout. It is required by unit tests using remote replication to
* pass on Travis.
*/
#define USE_BIG_ALLOC "--big-alloc"
/*
* Layout definition
*/
POBJ_LAYOUT_BEGIN(constr);
POBJ_LAYOUT_ROOT(constr, struct root);
POBJ_LAYOUT_TOID(constr, struct node);
POBJ_LAYOUT_TOID(constr, struct node_big);
POBJ_LAYOUT_END(constr);
struct root {
TOID(struct node) n;
POBJ_LIST_HEAD(head, struct node) list;
POBJ_LIST_HEAD(head_big, struct node_big) list_big;
};
struct node {
POBJ_LIST_ENTRY(struct node) next;
};
struct node_big {
POBJ_LIST_ENTRY(struct node_big) next;
int weight[2048];
};
static int
root_constr_cancel(PMEMobjpool *pop, void *ptr, void *arg)
{
return 1;
}
static int
node_constr_cancel(PMEMobjpool *pop, void *ptr, void *arg)
{
return 1;
}
struct foo {
int bar;
};
static struct foo *Canceled_ptr;
static int
vg_test_save_ptr(PMEMobjpool *pop, void *ptr, void *arg)
{
Canceled_ptr = (struct foo *)ptr;
return 1;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_constructor");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(constr) != 2);
int big = (argc == 3 && strcmp(argv[2], USE_BIG_ALLOC) == 0);
size_t node_size;
size_t next_off;
if (big) {
node_size = sizeof(struct node_big);
next_off = offsetof(struct node_big, next);
} else if (argc == 2) {
node_size = sizeof(struct node);
next_off = offsetof(struct node, next);
} else {
UT_FATAL("usage: %s file-name [ %s ]", argv[0], USE_BIG_ALLOC);
}
const char *path = argv[1];
PMEMobjpool *pop = NULL;
int ret;
TOID(struct root) root;
TOID(struct node) node;
TOID(struct node_big) node_big;
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(constr),
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
errno = 0;
root.oid = pmemobj_root_construct(pop, sizeof(struct root),
root_constr_cancel, NULL);
UT_ASSERT(TOID_IS_NULL(root));
UT_ASSERTeq(errno, ECANCELED);
/*
* Allocate memory until OOM, so we can check later if the alloc
* cancellation didn't damage the heap in any way.
*/
int allocs = 0;
while (pmemobj_alloc(pop, NULL, node_size, 1, NULL, NULL) == 0)
allocs++;
UT_ASSERTne(allocs, 0);
PMEMoid oid;
PMEMoid next;
POBJ_FOREACH_SAFE(pop, oid, next)
pmemobj_free(&oid);
errno = 0;
ret = pmemobj_alloc(pop, NULL, node_size, 1, node_constr_cancel, NULL);
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(errno, ECANCELED);
/* the same number of allocations should be possible. */
while (pmemobj_alloc(pop, NULL, node_size, 1, NULL, NULL) == 0)
allocs--;
UT_ASSERT(allocs <= 0);
POBJ_FOREACH_SAFE(pop, oid, next)
pmemobj_free(&oid);
root.oid = pmemobj_root_construct(pop, sizeof(struct root),
NULL, NULL);
UT_ASSERT(!TOID_IS_NULL(root));
errno = 0;
if (big) {
node_big.oid = pmemobj_list_insert_new(pop, next_off,
&D_RW(root)->list_big, OID_NULL, 0, node_size,
1, node_constr_cancel, NULL);
UT_ASSERT(TOID_IS_NULL(node_big));
} else {
node.oid = pmemobj_list_insert_new(pop, next_off,
&D_RW(root)->list, OID_NULL, 0, node_size,
1, node_constr_cancel, NULL);
UT_ASSERT(TOID_IS_NULL(node));
}
UT_ASSERTeq(errno, ECANCELED);
pmemobj_alloc(pop, &oid, sizeof(struct foo), 1,
vg_test_save_ptr, NULL);
UT_ASSERTne(Canceled_ptr, NULL);
/* this should generate a valgrind memcheck warning */
Canceled_ptr->bar = 5;
pmemobj_persist(pop, &Canceled_ptr->bar, sizeof(Canceled_ptr->bar));
/*
* Allocate and cancel a huge object. It should return back to the
* heap and it should be possible to allocate it again.
*/
Canceled_ptr = NULL;
ret = pmemobj_alloc(pop, &oid, sizeof(struct foo) + (1 << 22), 1,
vg_test_save_ptr, NULL);
UT_ASSERTne(Canceled_ptr, NULL);
void *first_ptr = Canceled_ptr;
Canceled_ptr = NULL;
ret = pmemobj_alloc(pop, &oid, sizeof(struct foo) + (1 << 22), 1,
vg_test_save_ptr, NULL);
UT_ASSERTeq(first_ptr, Canceled_ptr);
pmemobj_close(pop);
DONE(NULL);
}
| 5,884 | 26.5 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_poolset_parse/util_poolset_parse.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_sets_parser.c -- unit test for parsing a set file
*
* usage: obj_pool_sets_parser set-file ...
*/
#include "set.h"
#include "unittest.h"
#include "pmemcommon.h"
#define LOG_PREFIX "parser"
#define LOG_LEVEL_VAR "PARSER_LOG_LEVEL"
#define LOG_FILE_VAR "PARSER_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
int
main(int argc, char *argv[])
{
START(argc, argv, "util_poolset_parse");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 2)
UT_FATAL("usage: %s set-file-name ...", argv[0]);
struct pool_set *set;
int fd;
for (int i = 1; i < argc; i++) {
const char *path = argv[i];
fd = OPEN(path, O_RDWR);
int ret = util_poolset_parse(&set, path, fd);
if (ret == 0)
util_poolset_free(set);
CLOSE(fd);
}
common_fini();
DONE(NULL);
}
| 2,442 | 29.924051 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/log_recovery/log_recovery.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.
*/
/*
* log_recovery.c -- unit test for pmemlog recovery
*
* usage: log_recovery file operation:...
*
* operation has to be 'a' or 'v'
*
*/
#include <sys/param.h>
#include "unittest.h"
#include "log.h"
/*
* do_append -- call pmemlog_append() & print result
*/
static void
do_append(PMEMlogpool *plp)
{
const char *str[6] = {
"1st append string\n",
"2nd append string\n",
"3rd append string\n",
"4th append string\n",
"5th append string\n",
"6th append string\n"
};
for (int i = 0; i < 6; ++i) {
int rv = pmemlog_append(plp, str[i], strlen(str[i]));
switch (rv) {
case 0:
UT_OUT("append str[%i] %s", i, str[i]);
break;
case -1:
UT_OUT("!append str[%i] %s", i, str[i]);
break;
default:
UT_OUT("!append: wrong return value");
break;
}
}
}
/*
* do_appendv -- call pmemlog_appendv() & print result
*/
static void
do_appendv(PMEMlogpool *plp)
{
struct iovec iov[9] = {
{
.iov_base = "1st appendv string\n",
.iov_len = 19
},
{
.iov_base = "2nd appendv string\n",
.iov_len = 19
},
{
.iov_base = "3rd appendv string\n",
.iov_len = 19
},
{
.iov_base = "4th appendv string\n",
.iov_len = 19
},
{
.iov_base = "5th appendv string\n",
.iov_len = 19
},
{
.iov_base = "6th appendv string\n",
.iov_len = 19
},
{
.iov_base = "7th appendv string\n",
.iov_len = 19
},
{
.iov_base = "8th appendv string\n",
.iov_len = 19
},
{
.iov_base = "9th appendv string\n",
.iov_len = 19
}
};
int rv = pmemlog_appendv(plp, iov, 9);
switch (rv) {
case 0:
UT_OUT("appendv");
break;
case -1:
UT_OUT("!appendv");
break;
default:
UT_OUT("!appendv: wrong return value");
break;
}
}
/*
* do_tell -- call pmemlog_tell() & print result
*/
static void
do_tell(PMEMlogpool *plp)
{
os_off_t tell = pmemlog_tell(plp);
UT_OUT("tell %zu", tell);
}
/*
* printit -- print out the 'buf' of length 'len'.
*
* It is a walker function for pmemlog_walk
*/
static int
printit(const void *buf, size_t len, void *arg)
{
char *str = MALLOC(len + 1);
strncpy(str, buf, len);
str[len] = '\0';
UT_OUT("%s", str);
FREE(str);
return 0;
}
/*
* do_walk -- call pmemlog_walk() & print result
*/
static void
do_walk(PMEMlogpool *plp)
{
pmemlog_walk(plp, 0, printit, NULL);
UT_OUT("walk all at once");
}
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[])
{
PMEMlogpool *plp;
int result;
START(argc, argv, "log_recovery");
if (argc != 3)
UT_FATAL("usage: %s file-name op:a|v", argv[0]);
if (strchr("av", argv[2][0]) == NULL || argv[2][1] != '\0')
UT_FATAL("op must be a or v");
const char *path = argv[1];
int fd = OPEN(path, O_RDWR);
/* pre-allocate 2MB of persistent memory */
POSIX_FALLOCATE(fd, (os_off_t)0, (size_t)(2 * 1024 * 1024));
CLOSE(fd);
if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemlog_create: %s", path);
/* append some data */
if (argv[2][0] == 'a')
do_append(plp);
else
do_appendv(plp);
/* print out current write point */
do_tell(plp);
size_t len = roundup(sizeof(*plp), LOG_FORMAT_DATA_ALIGN);
UT_OUT("write-protecting the metadata, length %zu", len);
MPROTECT(plp, len, 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);
if (!ut_sigsetjmp(Jmp)) {
/* try to append more data */
if (argv[2][0] == 'a')
do_append(plp);
else
do_appendv(plp);
}
MPROTECT(plp, len, PROT_READ | PROT_WRITE);
pmemlog_close(plp);
/* check consistency */
result = pmemlog_check(path);
if (result < 0)
UT_OUT("!%s: pmemlog_check", path);
else if (result == 0)
UT_OUT("%s: pmemlog_check: not consistent", path);
else
UT_OUT("%s: consistent", path);
/* map again to print out whole log */
if ((plp = pmemlog_open(path)) == NULL)
UT_FATAL("!pmemlog_open: %s", path);
/* print out current write point */
do_tell(plp);
/* print out whole log */
do_walk(plp);
pmemlog_close(plp);
DONE(NULL);
}
| 5,805 | 20.745318 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_heap_state/obj_heap_state.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_heap_state.c -- volatile heap state verification test
*/
#include <stddef.h>
#include "unittest.h"
#define LAYOUT_NAME "heap_state"
#define ROOT_SIZE 256
#define ALLOCS 100
#define ALLOC_SIZE 50
static char buf[ALLOC_SIZE];
static int
test_constructor(PMEMobjpool *pop, void *addr, void *args)
{
/* do not use pmem_memcpy_persist() here */
pmemobj_memcpy_persist(pop, addr, buf, ALLOC_SIZE);
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_heap_state");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
for (int i = 0; i < ALLOC_SIZE; i++)
buf[i] = rand() % 256;
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
pmemobj_root(pop, ROOT_SIZE); /* just to trigger allocation */
pmemobj_close(pop);
pop = pmemobj_open(path, LAYOUT_NAME);
UT_ASSERTne(pop, NULL);
for (int i = 0; i < ALLOCS; ++i) {
PMEMoid oid;
pmemobj_alloc(pop, &oid, ALLOC_SIZE, 0,
test_constructor, NULL);
UT_OUT("%d %lu", i, oid.off);
}
pmemobj_close(pop);
DONE(NULL);
}
| 2,754 | 28.308511 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/win_mmap_fixed/win_mmap_fixed.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.
*/
/*
* win_mmap_fixed.c -- test memory mapping with MAP_FIXED for various lengths
*
* This test is intended to be used for testing Windows implementation
* of memory mapping routines - mmap(), munmap(), msync() and mprotect().
* Those functions should provide the same functionality as their Linux
* counterparts, at least with respect to the features that are used
* in PMDK libraries.
*
* Known issues and differences between Linux and Windows implementation
* are described in src/common/mmap_windows.c.
*/
#include "unittest.h"
#include <sys/mman.h>
#define ALIGN(size) ((size) & ~(Ut_mmap_align - 1))
/*
* test_mmap_fixed -- test fixed mappings
*/
static void
test_mmap_fixed(const char *name1, const char *name2, size_t len1, size_t len2)
{
size_t len1_aligned = ALIGN(len1);
size_t len2_aligned = ALIGN(len2);
UT_OUT("len: %zu (%zu) + %zu (%zu) = %zu", len1, len1_aligned,
len2, len2_aligned, len1_aligned + len2_aligned);
int fd1 = OPEN(name1, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR);
int fd2 = OPEN(name2, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR);
POSIX_FALLOCATE(fd1, 0, len1);
POSIX_FALLOCATE(fd2, 0, len2);
char *ptr1 = mmap(NULL, len1_aligned + len2_aligned,
PROT_READ|PROT_WRITE, MAP_SHARED, fd1, 0);
UT_ASSERTne(ptr1, MAP_FAILED);
UT_OUT("ptr1: %p, ptr2: %p", ptr1, ptr1 + len1_aligned);
char *ptr2 = mmap(ptr1 + len1_aligned, len2_aligned,
PROT_READ|PROT_WRITE, MAP_FIXED|MAP_SHARED, fd2, 0);
UT_ASSERTne(ptr2, MAP_FAILED);
UT_ASSERTeq(ptr2, ptr1 + len1_aligned);
UT_ASSERTne(munmap(ptr1, len1_aligned), -1);
UT_ASSERTne(munmap(ptr2, len2_aligned), -1);
CLOSE(fd1);
CLOSE(fd2);
UNLINK(name1);
UNLINK(name2);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "win_mmap_fixed");
if (argc < 4)
UT_FATAL("usage: %s dirname len1 len2 ...", argv[0]);
size_t *lengths = MALLOC(sizeof(size_t) * argc - 2);
UT_ASSERTne(lengths, NULL);
size_t appendix_length = 20; /* a file name length */
char *name1 = MALLOC(strlen(argv[1]) + appendix_length);
char *name2 = MALLOC(strlen(argv[1]) + appendix_length);
sprintf(name1, "%s\\testfile1", argv[1]);
sprintf(name2, "%s\\testfile2", argv[1]);
for (int i = 0; i < argc - 2; i++)
lengths[i] = atoll(argv[i + 2]);
for (int i = 0; i < argc - 2; i++)
for (int j = 0; j < argc - 2; j++)
test_mmap_fixed(name1, name2, lengths[i], lengths[j]);
FREE(name1);
FREE(name2);
FREE(lengths);
DONE(NULL);
}
| 4,016 | 31.92623 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/out_err/out_err.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 "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
main(int argc, char *argv[])
{
char buff[UT_MAX_ERR_MSG];
START(argc, argv, "out_err");
/* 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_errormsg());
errno = 0;
ERR("!ERR #%d", 2);
UT_OUT("%s", out_get_errormsg());
errno = EINVAL;
ERR("!ERR #%d", 3);
UT_OUT("%s", out_get_errormsg());
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_errormsg());
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_errormsg());
/* Cleanup */
common_fini();
DONE(NULL);
}
| 2,661 | 29.25 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/unittest/ut_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.
*/
/*
* ut_alloc.c -- unit test memory allocation routines
*/
#include "unittest.h"
/*
* ut_malloc -- a malloc that cannot return NULL
*/
void *
ut_malloc(const char *file, int line, const char *func, size_t size)
{
void *retval = malloc(size);
if (retval == NULL)
ut_fatal(file, line, func, "cannot malloc %zu bytes", size);
return retval;
}
/*
* ut_calloc -- a calloc that cannot return NULL
*/
void *
ut_calloc(const char *file, int line, const char *func,
size_t nmemb, size_t size)
{
void *retval = calloc(nmemb, size);
if (retval == NULL)
ut_fatal(file, line, func, "cannot calloc %zu bytes", size);
return retval;
}
/*
* ut_free -- wrapper for free
*
* technically we don't need to wrap free since there's no return to
* check. using this wrapper to add memory allocation tracking later.
*/
void
ut_free(const char *file, int line, const char *func, void *ptr)
{
free(ptr);
}
/*
* ut_aligned_free -- wrapper for aligned memory free
*/
void
ut_aligned_free(const char *file, int line, const char *func, void *ptr)
{
#ifndef _WIN32
free(ptr);
#else
_aligned_free(ptr);
#endif
}
/*
* ut_realloc -- a realloc that cannot return NULL
*/
void *
ut_realloc(const char *file, int line, const char *func,
void *ptr, size_t size)
{
void *retval = realloc(ptr, size);
if (retval == NULL)
ut_fatal(file, line, func, "cannot realloc %zu bytes", size);
return retval;
}
/*
* ut_strdup -- a strdup that cannot return NULL
*/
char *
ut_strdup(const char *file, int line, const char *func,
const char *str)
{
char *retval = strdup(str);
if (retval == NULL)
ut_fatal(file, line, func, "cannot strdup %zu bytes",
strlen(str));
return retval;
}
/*
* ut_memalign -- like malloc but page-aligned memory
*/
void *
ut_memalign(const char *file, int line, const char *func, size_t alignment,
size_t size)
{
void *retval;
#ifndef _WIN32
if ((errno = posix_memalign(&retval, alignment, size)) != 0)
ut_fatal(file, line, func,
"!memalign %zu bytes (%zu alignment)", size, alignment);
#else
retval = _aligned_malloc(size, alignment);
if (!retval) {
ut_fatal(file, line, func,
"!memalign %zu bytes (%zu alignment)", size, alignment);
}
#endif
return retval;
}
/*
* ut_pagealignmalloc -- like malloc but page-aligned memory
*/
void *
ut_pagealignmalloc(const char *file, int line, const char *func,
size_t size)
{
return ut_memalign(file, line, func, (size_t)Ut_pagesize, size);
}
/*
* ut_mmap_anon_aligned -- mmaps anonymous memory with specified (power of two,
* multiple of page size) alignment and adds guard
* pages around it
*/
void *
ut_mmap_anon_aligned(const char *file, int line, const char *func,
size_t alignment, size_t size)
{
char *d, *d_aligned;
uintptr_t di, di_aligned;
size_t sz;
if (alignment == 0)
alignment = Ut_mmap_align;
/* alignment must be a multiple of page size */
if (alignment & (Ut_mmap_align - 1))
return NULL;
/* power of two */
if (alignment & (alignment - 1))
return NULL;
d = ut_mmap(file, line, func, NULL, size + 2 * alignment,
PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
di = (uintptr_t)d;
di_aligned = (di + alignment - 1) & ~(alignment - 1);
if (di == di_aligned)
di_aligned += alignment;
d_aligned = (void *)di_aligned;
sz = di_aligned - di;
if (sz - Ut_mmap_align)
ut_munmap(file, line, func, d, sz - Ut_mmap_align);
/* guard page before */
ut_mprotect(file, line, func,
d_aligned - Ut_mmap_align, Ut_mmap_align, PROT_NONE);
/* guard page after */
ut_mprotect(file, line, func,
d_aligned + size, Ut_mmap_align, PROT_NONE);
sz = di + size + 2 * alignment - (di_aligned + size) - Ut_mmap_align;
if (sz)
ut_munmap(file, line, func,
d_aligned + size + Ut_mmap_align, sz);
return d_aligned;
}
/*
* ut_munmap_anon_aligned -- unmaps anonymous memory allocated by
* ut_mmap_anon_aligned
*/
int
ut_munmap_anon_aligned(const char *file, int line, const char *func,
void *start, size_t size)
{
return ut_munmap(file, line, func, (char *)start - Ut_mmap_align,
size + 2 * Ut_mmap_align);
}
| 5,753 | 24.918919 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/unittest/ut_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.
*/
/*
* ut_file.c -- unit test file operations
*/
#include "unittest.h"
/*
* ut_open -- an open that cannot return < 0
*/
int
ut_open(const char *file, int line, const char *func, const char *path,
int flags, ...)
{
va_list ap;
int mode;
va_start(ap, flags);
mode = va_arg(ap, int);
int retval = os_open(path, flags, mode);
va_end(ap);
if (retval < 0)
ut_fatal(file, line, func, "!open: %s", path);
return retval;
}
#ifdef _WIN32
/*
* ut_wopen -- a _wopen that cannot return < 0
*/
int
ut_wopen(const char *file, int line, const char *func, const wchar_t *path,
int flags, ...)
{
va_list ap;
int mode;
va_start(ap, flags);
mode = va_arg(ap, int);
int retval = _wopen(path, flags, mode);
va_end(ap);
if (retval < 0)
ut_fatal(file, line, func, "!wopen: %s", ut_toUTF8(path));
return retval;
}
#endif
/*
* ut_close -- a close that cannot return -1
*/
int
ut_close(const char *file, int line, const char *func, int fd)
{
int retval = os_close(fd);
if (retval != 0)
ut_fatal(file, line, func, "!close: %d", fd);
return retval;
}
/*
* ut_fopen --an fopen that cannot return != 0
*/
FILE *
ut_fopen(const char *file, int line, const char *func, const char *path,
const char *mode)
{
FILE *retval = os_fopen(path, mode);
if (retval == NULL)
ut_fatal(file, line, func, "!fopen: %s", path);
return retval;
}
/*
* ut_fclose -- a fclose that cannot return != 0
*/
int
ut_fclose(const char *file, int line, const char *func, FILE *stream)
{
int retval = os_fclose(stream);
if (retval != 0) {
ut_fatal(file, line, func, "!fclose: 0x%llx",
(unsigned long long)stream);
}
return retval;
}
/*
* ut_unlink -- an unlink that cannot return -1
*/
int
ut_unlink(const char *file, int line, const char *func, const char *path)
{
int retval = os_unlink(path);
if (retval != 0)
ut_fatal(file, line, func, "!unlink: %s", path);
return retval;
}
/*
* ut_posix_fallocate -- a posix_fallocate that cannot return -1
*/
int
ut_posix_fallocate(const char *file, int line, const char *func, int fd,
os_off_t offset, os_off_t len)
{
int retval = os_posix_fallocate(fd, offset, len);
if (retval != 0) {
errno = retval;
ut_fatal(file, line, func,
"!fallocate: fd %d offset 0x%llx len %llu",
fd, (unsigned long long)offset, (unsigned long long)len);
}
return retval;
}
/*
* ut_write -- a write that can't return -1
*/
size_t
ut_write(const char *file, int line, const char *func, int fd,
const void *buf, size_t count)
{
#ifndef _WIN32
ssize_t retval = write(fd, buf, count);
#else
/*
* XXX - do multiple write() calls in a loop?
* Or just use native Windows API?
*/
if (count > UINT_MAX)
ut_fatal(file, line, func, "read: count > UINT_MAX (%zu > %u)",
count, UINT_MAX);
ssize_t retval = _write(fd, buf, (unsigned)count);
#endif
if (retval < 0)
ut_fatal(file, line, func, "!write: %d", fd);
return (size_t)retval;
}
/*
* ut_read -- a read that can't return -1
*/
size_t
ut_read(const char *file, int line, const char *func, int fd,
void *buf, size_t count)
{
#ifndef _WIN32
ssize_t retval = read(fd, buf, count);
#else
/*
* XXX - do multiple read() calls in a loop?
* Or just use native Windows API?
*/
if (count > UINT_MAX)
ut_fatal(file, line, func, "read: count > UINT_MAX (%zu > %u)",
count, UINT_MAX);
ssize_t retval = read(fd, buf, (unsigned)count);
#endif
if (retval < 0)
ut_fatal(file, line, func, "!read: %d", fd);
return (size_t)retval;
}
/*
* ut_lseek -- an lseek that can't return -1
*/
os_off_t
ut_lseek(const char *file, int line, const char *func, int fd,
os_off_t offset, int whence)
{
os_off_t retval = os_lseek(fd, offset, whence);
if (retval == -1)
ut_fatal(file, line, func, "!lseek: %d", fd);
return retval;
}
/*
* ut_fstat -- a fstat that cannot return -1
*/
int
ut_fstat(const char *file, int line, const char *func, int fd,
os_stat_t *st_bufp)
{
int retval = os_fstat(fd, st_bufp);
if (retval < 0)
ut_fatal(file, line, func, "!fstat: %d", fd);
#ifdef _WIN32
/* clear unused bits to avoid confusion */
st_bufp->st_mode &= 0600;
#endif
return retval;
}
/*
* ut_stat -- a stat that cannot return -1
*/
int
ut_stat(const char *file, int line, const char *func, const char *path,
os_stat_t *st_bufp)
{
int retval = os_stat(path, st_bufp);
if (retval < 0)
ut_fatal(file, line, func, "!stat: %s", path);
#ifdef _WIN32
/* clear unused bits to avoid confusion */
st_bufp->st_mode &= 0600;
#endif
return retval;
}
#ifdef _WIN32
/*
* ut_statW -- a stat that cannot return -1
*/
int
ut_statW(const char *file, int line, const char *func, const wchar_t *path,
os_stat_t *st_bufp)
{
int retval = ut_util_statW(path, st_bufp);
if (retval < 0)
ut_fatal(file, line, func, "!stat: %S", path);
#ifdef _WIN32
/* clear unused bits to avoid confusion */
st_bufp->st_mode &= 0600;
#endif
return retval;
}
#endif
/*
* ut_mmap -- a mmap call that cannot return MAP_FAILED
*/
void *
ut_mmap(const char *file, int line, const char *func, void *addr,
size_t length, int prot, int flags, int fd, os_off_t offset)
{
void *ret_addr = mmap(addr, length, prot, flags, fd, offset);
if (ret_addr == MAP_FAILED) {
const char *error = "";
#ifdef _WIN32
/*
* XXX: on Windows mmap is implemented and exported by libpmem
*/
error = pmem_errormsg();
#endif
ut_fatal(file, line, func,
"!mmap: addr=0x%llx length=0x%zx prot=%d flags=%d fd=%d offset=0x%llx %s",
(unsigned long long)addr, length, prot,
flags, fd, (unsigned long long)offset, error);
}
return ret_addr;
}
/*
* ut_munmap -- a munmap call that cannot return -1
*/
int
ut_munmap(const char *file, int line, const char *func, void *addr,
size_t length)
{
int retval = munmap(addr, length);
if (retval < 0)
ut_fatal(file, line, func, "!munmap: addr=0x%llx length=0x%zx",
(unsigned long long)addr, length);
return retval;
}
/*
* ut_mprotect -- a mprotect call that cannot return -1
*/
int
ut_mprotect(const char *file, int line, const char *func, void *addr,
size_t len, int prot)
{
int retval = mprotect(addr, len, prot);
if (retval < 0)
ut_fatal(file, line, func,
"!mprotect: addr=0x%llx length=0x%zx prot=0x%x",
(unsigned long long)addr, len, prot);
return retval;
}
/*
* ut_ftruncate -- a ftruncate that cannot return -1
*/
int
ut_ftruncate(const char *file, int line, const char *func, int fd,
os_off_t length)
{
int retval = os_ftruncate(fd, length);
if (retval < 0)
ut_fatal(file, line, func, "!ftruncate: %d %llu",
fd, (unsigned long long)length);
return retval;
}
| 8,210 | 21.871866 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/unittest/ut_signal.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.
*/
/*
* ut_signal.c -- unit test signal operations
*/
#include "unittest.h"
#ifdef _WIN32
/*
* On Windows, Access Violation exception does not raise SIGSEGV signal.
* The trick is to catch the exception and... call the signal handler.
*/
/*
* Sigactions[] - allows registering more than one signal/exception handler
*/
static struct sigaction Sigactions[NSIG];
/*
* exception_handler -- called for unhandled exceptions
*/
static LONG CALLBACK
exception_handler(_In_ PEXCEPTION_POINTERS ExceptionInfo)
{
DWORD excode = ExceptionInfo->ExceptionRecord->ExceptionCode;
if (excode == EXCEPTION_ACCESS_VIOLATION)
Sigactions[SIGSEGV].sa_handler(SIGSEGV);
return EXCEPTION_CONTINUE_EXECUTION;
}
/*
* signal_handler_wrapper -- (internal) wrapper for user-defined signal handler
*
* Before the specified handler function is executed, signal disposition
* is reset to SIG_DFL. This wrapper allows to handle subsequent signals
* without the need to set the signal disposition again.
*/
static void
signal_handler_wrapper(int signum)
{
_crt_signal_t retval = signal(signum, signal_handler_wrapper);
if (retval == SIG_ERR)
UT_FATAL("!signal: %d", signum);
if (Sigactions[signum].sa_handler)
Sigactions[signum].sa_handler(signum);
else
UT_FATAL("handler for signal: %d is not defined", signum);
}
#endif
/*
* ut_sigaction -- a sigaction that cannot return < 0
*/
int
ut_sigaction(const char *file, int line, const char *func,
int signum, struct sigaction *act, struct sigaction *oldact)
{
#ifndef _WIN32
int retval = sigaction(signum, act, oldact);
if (retval != 0)
ut_fatal(file, line, func, "!sigaction: %s",
os_strsignal(signum));
return retval;
#else
UT_ASSERT(signum < NSIG);
os_mutex_lock(&Sigactions_lock);
if (oldact)
*oldact = Sigactions[signum];
if (act)
Sigactions[signum] = *act;
os_mutex_unlock(&Sigactions_lock);
if (signum == SIGABRT) {
ut_suppress_errmsg();
}
if (signum == SIGSEGV) {
AddVectoredExceptionHandler(0, exception_handler);
}
_crt_signal_t retval = signal(signum, signal_handler_wrapper);
if (retval == SIG_ERR)
ut_fatal(file, line, func, "!signal: %d", signum);
if (oldact != NULL)
oldact->sa_handler = retval;
return 0;
#endif
}
| 3,821 | 30.327869 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/unittest/ut_backtrace.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.
*/
/*
* ut_backtrace.c -- backtrace reporting routines
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "unittest.h"
#ifdef USE_LIBUNWIND
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <dlfcn.h>
#define PROCNAMELEN 256
/*
* ut_dump_backtrace -- dump stacktrace to error log using libunwind
*/
void
ut_dump_backtrace(void)
{
unw_context_t context;
unw_proc_info_t pip;
pip.unwind_info = NULL;
int ret = unw_getcontext(&context);
if (ret) {
UT_ERR("unw_getcontext: %s [%d]", unw_strerror(ret), ret);
return;
}
unw_cursor_t cursor;
ret = unw_init_local(&cursor, &context);
if (ret) {
UT_ERR("unw_init_local: %s [%d]", unw_strerror(ret), ret);
return;
}
ret = unw_step(&cursor);
char procname[PROCNAMELEN];
unsigned i = 0;
while (ret > 0) {
ret = unw_get_proc_info(&cursor, &pip);
if (ret) {
UT_ERR("unw_get_proc_info: %s [%d]", unw_strerror(ret),
ret);
break;
}
unw_word_t off;
ret = unw_get_proc_name(&cursor, procname, PROCNAMELEN, &off);
if (ret && ret != -UNW_ENOMEM) {
if (ret != -UNW_EUNSPEC) {
UT_ERR("unw_get_proc_name: %s [%d]",
unw_strerror(ret), ret);
}
strcpy(procname, "?");
}
void *ptr = (void *)(pip.start_ip + off);
Dl_info dlinfo;
const char *fname = "?";
uintptr_t in_object_offset = 0;
if (dladdr(ptr, &dlinfo) && dlinfo.dli_fname &&
*dlinfo.dli_fname) {
fname = dlinfo.dli_fname;
uintptr_t base = (uintptr_t)dlinfo.dli_fbase;
if ((uintptr_t)ptr >= base)
in_object_offset = (uintptr_t)ptr - base;
}
UT_ERR("%u: %s (%s%s+0x%lx) [%p] [0x%" PRIxPTR "]",
i++, fname, procname,
ret == -UNW_ENOMEM ? "..." : "", off, ptr,
in_object_offset);
ret = unw_step(&cursor);
if (ret < 0)
UT_ERR("unw_step: %s [%d]", unw_strerror(ret), ret);
}
}
#else /* USE_LIBUNWIND */
#define SIZE 100
#ifndef _WIN32
#include <execinfo.h>
/*
* ut_dump_backtrace -- dump stacktrace to error log using libc's backtrace
*/
void
ut_dump_backtrace(void)
{
int j, nptrs;
void *buffer[SIZE];
char **strings;
nptrs = backtrace(buffer, SIZE);
strings = backtrace_symbols(buffer, nptrs);
if (strings == NULL) {
UT_ERR("!backtrace_symbols");
return;
}
for (j = 0; j < nptrs; j++)
UT_ERR("%u: %s", j, strings[j]);
free(strings);
}
#else /* _WIN32 */
#include <DbgHelp.h>
/*
* ut_dump_backtrace -- dump stacktrace to error log
*/
void
ut_dump_backtrace(void)
{
void *buffer[SIZE];
unsigned nptrs;
SYMBOL_INFO *symbol;
HANDLE proc_hndl = GetCurrentProcess();
SymInitialize(proc_hndl, NULL, TRUE);
nptrs = CaptureStackBackTrace(0, SIZE, buffer, NULL);
symbol = CALLOC(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(CHAR), 1);
symbol->MaxNameLen = MAX_SYM_NAME - 1;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
for (unsigned i = 0; i < nptrs; i++) {
if (SymFromAddr(proc_hndl, (DWORD64)buffer[i], 0, symbol)) {
UT_ERR("%u: %s [%p]", nptrs - i - 1, symbol->Name,
buffer[i]);
} else {
UT_ERR("%u: [%p]", nptrs - i - 1, buffer[i]);
}
}
FREE(symbol);
}
#endif /* _WIN32 */
#endif /* USE_LIBUNWIND */
/*
* ut_sighandler -- fatal signal handler
*/
void
ut_sighandler(int sig)
{
/*
* Usually SIGABRT is a result of ASSERT() or FATAL().
* We don't need backtrace, as the reason of the failure
* is logged in debug traces.
*/
if (sig != SIGABRT) {
UT_ERR("\n");
UT_ERR("Signal %d, backtrace:", sig);
ut_dump_backtrace();
UT_ERR("\n");
}
exit(128 + sig);
}
/*
* ut_register_sighandlers -- register signal handlers for various fatal signals
*/
void
ut_register_sighandlers(void)
{
signal(SIGSEGV, ut_sighandler);
signal(SIGABRT, ut_sighandler);
signal(SIGILL, ut_sighandler);
signal(SIGFPE, ut_sighandler);
signal(SIGINT, ut_sighandler);
#ifndef _WIN32
signal(SIGQUIT, ut_sighandler);
signal(SIGBUS, ut_sighandler);
#endif
}
| 5,430 | 22.820175 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/unittest/ut_pthread.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.
*/
/*
* ut_pthread.c -- unit test wrappers for pthread routines
*/
#include "unittest.h"
/*
* ut_thread_create -- a os_thread_create that cannot return an error
*/
int
ut_thread_create(const char *file, int line, const char *func,
os_thread_t *__restrict thread,
const os_thread_attr_t *__restrict attr,
void *(*start_routine)(void *), void *__restrict arg)
{
if ((errno = os_thread_create(thread, attr, start_routine, arg)) != 0)
ut_fatal(file, line, func, "!os_thread_create");
return 0;
}
/*
* ut_thread_join -- a os_thread_join that cannot return an error
*/
int
ut_thread_join(const char *file, int line, const char *func,
os_thread_t *thread, void **value_ptr)
{
if ((errno = os_thread_join(thread, value_ptr)) != 0)
ut_fatal(file, line, func, "!os_thread_join");
return 0;
}
| 2,416 | 35.621212 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_movnt_align/pmem_movnt_align.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_movnt_align.c -- unit test for functions with non-temporal stores
*
* usage: pmem_movnt_align [C|F|B|S]
*
* C - pmem_memcpy_persist()
* B - pmem_memmove_persist() in backward direction
* F - pmem_memmove_persist() in forward direction
* S - pmem_memset_persist()
*/
#include <stdio.h>
#include <string.h>
#include "libpmem.h"
#include "unittest.h"
#define CACHELINE 64
#define N_BYTES 8192
typedef void *(*mem_fn)(void *, const void *, size_t);
static char *Src;
static char *Dst;
static char *Scratch;
static int Heavy;
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,
};
typedef void *pmem_memcpy_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void *pmem_memmove_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void *pmem_memset_fn(void *pmemdest, int c, size_t len, unsigned flags);
static void *
pmem_memcpy_persist_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_persist(pmemdest, src, len);
}
static void *
pmem_memcpy_nodrain_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_nodrain(pmemdest, src, len);
}
static void *
pmem_memmove_persist_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memmove_persist(pmemdest, src, len);
}
static void *
pmem_memmove_nodrain_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memmove_nodrain(pmemdest, src, len);
}
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);
}
/*
* check_memmove -- invoke check function with pmem_memmove_persist
*/
static void
check_memmove(size_t doff, size_t soff, size_t len, pmem_memmove_fn fn,
unsigned flags)
{
memset(Dst + doff, 1, len);
memset(Src + soff, 0, len);
fn(Dst + doff, Src + soff, len, flags);
if (memcmp(Dst + doff, Src + soff, len))
UT_FATAL("memcpy/memmove failed");
}
static void
check_memmove_variants(size_t doff, size_t soff, size_t len)
{
check_memmove(doff, soff, len, pmem_memmove_persist_wrapper, 0);
if (!Heavy)
return;
check_memmove(doff, soff, len, pmem_memmove_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i)
check_memmove(doff, soff, len, pmem_memmove, Flags[i]);
}
/*
* check_memmove -- invoke check function with pmem_memcpy_persist
*/
static void
check_memcpy(size_t doff, size_t soff, size_t len, pmem_memcpy_fn fn,
unsigned flags)
{
memset(Dst, 2, N_BYTES);
memset(Src, 3, N_BYTES);
memset(Scratch, 2, N_BYTES);
memset(Dst + doff, 1, len);
memset(Src + soff, 0, len);
memcpy(Scratch + doff, Src + soff, len);
fn(Dst + doff, Src + soff, len, flags);
if (memcmp(Dst, Scratch, N_BYTES))
UT_FATAL("memcpy/memmove failed");
}
static void
check_memcpy_variants(size_t doff, size_t soff, size_t len)
{
check_memcpy(doff, soff, len, pmem_memcpy_persist_wrapper, 0);
if (!Heavy)
return;
check_memcpy(doff, soff, len, pmem_memcpy_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i)
check_memcpy(doff, soff, len, pmem_memcpy, Flags[i]);
}
/*
* check_memset -- check pmem_memset_no_drain function
*/
static void
check_memset(size_t off, size_t len, pmem_memset_fn fn, unsigned flags)
{
memset(Scratch, 2, N_BYTES);
memset(Scratch + off, 1, len);
memset(Dst, 2, N_BYTES);
fn(Dst + off, 1, len, flags);
if (memcmp(Dst, Scratch, N_BYTES))
UT_FATAL("memset failed");
}
static void
check_memset_variants(size_t off, size_t len)
{
check_memset(off, len, pmem_memset_persist_wrapper, 0);
if (!Heavy)
return;
check_memset(off, len, pmem_memset_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i)
check_memset(off, len, pmem_memset, Flags[i]);
}
int
main(int argc, char *argv[])
{
if (argc != 3)
UT_FATAL("usage: %s type heavy=[0|1]", argv[0]);
char type = argv[1][0];
Heavy = argv[2][0] == '1';
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_movnt_align %c %s %savx %savx512f", type,
thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
size_t s;
switch (type) {
case 'C': /* memcpy */
/* mmap with guard pages */
Src = MMAP_ANON_ALIGNED(N_BYTES, 0);
Dst = MMAP_ANON_ALIGNED(N_BYTES, 0);
if (Src == NULL || Dst == NULL)
UT_FATAL("!mmap");
Scratch = MALLOC(N_BYTES);
/* check memcpy with 0 size */
check_memcpy_variants(0, 0, 0);
/* check memcpy with unaligned size */
for (s = 0; s < CACHELINE; s++)
check_memcpy_variants(0, 0, N_BYTES - s);
/* check memcpy with unaligned begin */
for (s = 0; s < CACHELINE; s++)
check_memcpy_variants(s, 0, N_BYTES - s);
/* check memcpy with unaligned begin and end */
for (s = 0; s < CACHELINE; s++)
check_memcpy_variants(s, s, N_BYTES - 2 * s);
MUNMAP_ANON_ALIGNED(Src, N_BYTES);
MUNMAP_ANON_ALIGNED(Dst, N_BYTES);
FREE(Scratch);
break;
case 'B': /* memmove backward */
/* mmap with guard pages */
Src = MMAP_ANON_ALIGNED(2 * N_BYTES - 4096, 0);
Dst = Src + N_BYTES - 4096;
if (Src == NULL)
UT_FATAL("!mmap");
/* check memmove in backward direction with 0 size */
check_memmove_variants(0, 0, 0);
/* check memmove in backward direction with unaligned size */
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(0, 0, N_BYTES - s);
/* check memmove in backward direction with unaligned begin */
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(s, 0, N_BYTES - s);
/*
* check memmove in backward direction with unaligned begin
* and end
*/
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(s, s, N_BYTES - 2 * s);
MUNMAP_ANON_ALIGNED(Src, 2 * N_BYTES - 4096);
break;
case 'F': /* memmove forward */
/* mmap with guard pages */
Dst = MMAP_ANON_ALIGNED(2 * N_BYTES - 4096, 0);
Src = Dst + N_BYTES - 4096;
if (Src == NULL)
UT_FATAL("!mmap");
/* check memmove in forward direction with 0 size */
check_memmove_variants(0, 0, 0);
/* check memmove in forward direction with unaligned size */
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(0, 0, N_BYTES - s);
/* check memmove in forward direction with unaligned begin */
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(s, 0, N_BYTES - s);
/*
* check memmove in forward direction with unaligned begin
* and end
*/
for (s = 0; s < CACHELINE; s++)
check_memmove_variants(s, s, N_BYTES - 2 * s);
MUNMAP_ANON_ALIGNED(Dst, 2 * N_BYTES - 4096);
break;
case 'S': /* memset */
/* mmap with guard pages */
Dst = MMAP_ANON_ALIGNED(N_BYTES, 0);
if (Dst == NULL)
UT_FATAL("!mmap");
Scratch = MALLOC(N_BYTES);
/* check memset with 0 size */
check_memset_variants(0, 0);
/* check memset with unaligned size */
for (s = 0; s < CACHELINE; s++)
check_memset_variants(0, N_BYTES - s);
/* check memset with unaligned begin */
for (s = 0; s < CACHELINE; s++)
check_memset_variants(s, N_BYTES - s);
/* check memset with unaligned begin and end */
for (s = 0; s < CACHELINE; s++)
check_memset_variants(s, N_BYTES - 2 * s);
MUNMAP_ANON_ALIGNED(Dst, N_BYTES);
FREE(Scratch);
break;
default:
UT_FATAL("!wrong type of test");
break;
}
DONE(NULL);
}
| 9,542 | 25.731092 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_sync/libpmempool_sync.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_sync -- a unittest for libpmempool sync.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "libpmempool_sync");
if (argc != 3)
UT_FATAL("usage: %s poolset_file flags", argv[0]);
int ret = pmempool_sync(argv[1], (unsigned)strtoul(argv[2], NULL, 0));
if (ret)
UT_OUT("result: %d, errno: %d", ret, errno);
else
UT_OUT("result: %d", ret);
DONE(NULL);
}
| 2,097 | 33.966667 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_create_error/vmem_create_error.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_error.c -- unit test for vmem_create_error
*
* usage: vmem_create_error
*/
#include "unittest.h"
static char mem_pool[VMEM_MIN_POOL];
int
main(int argc, char *argv[])
{
VMEM *vmp;
START(argc, argv, "vmem_create_error");
if (argc > 1)
UT_FATAL("usage: %s", argv[0]);
errno = 0;
vmp = vmem_create_in_region(mem_pool, 0);
UT_ASSERTeq(vmp, NULL);
UT_ASSERTeq(errno, EINVAL);
errno = 0;
vmp = vmem_create("./", 0);
UT_ASSERTeq(vmp, NULL);
UT_ASSERTeq(errno, EINVAL);
errno = 0;
vmp = vmem_create("invalid dir !@#$%^&*()=", VMEM_MIN_POOL);
UT_ASSERTeq(vmp, NULL);
UT_ASSERTne(errno, 0);
DONE(NULL);
}
| 2,245 | 31.085714 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_memblock/obj_memblock.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_memblock.c -- unit test for memblock interface
*/
#include "memblock.h"
#include "memops.h"
#include "obj.h"
#include "unittest.h"
#include "heap.h"
#define NCHUNKS 10
static PMEMobjpool *pop;
FUNC_MOCK(operation_add_typed_entry, int, struct operation_context *ctx,
void *ptr, uint64_t value,
ulog_operation_type type, enum operation_log_type en_type)
FUNC_MOCK_RUN_DEFAULT {
uint64_t *pval = ptr;
switch (type) {
case ULOG_OPERATION_SET:
*pval = value;
break;
case ULOG_OPERATION_AND:
*pval &= value;
break;
case ULOG_OPERATION_OR:
*pval |= value;
break;
default:
UT_ASSERT(0);
}
return 0;
}
FUNC_MOCK_END
FUNC_MOCK(operation_add_entry, int, struct operation_context *ctx, void *ptr,
uint64_t value, ulog_operation_type type)
FUNC_MOCK_RUN_DEFAULT {
/* just call the mock above - the entry type doesn't matter */
return operation_add_typed_entry(ctx, ptr, value, type,
LOG_TRANSIENT);
}
FUNC_MOCK_END
static void
test_detect(void)
{
struct memory_block mhuge_used = { .chunk_id = 0, 0, 0, 0 };
struct memory_block mhuge_free = { .chunk_id = 1, 0, 0, 0 };
struct memory_block mrun = { .chunk_id = 2, 0, 0, 0 };
struct heap_layout *layout = pop->heap.layout;
layout->zone0.chunk_headers[0].size_idx = 1;
layout->zone0.chunk_headers[0].type = CHUNK_TYPE_USED;
layout->zone0.chunk_headers[1].size_idx = 1;
layout->zone0.chunk_headers[1].type = CHUNK_TYPE_FREE;
layout->zone0.chunk_headers[2].size_idx = 1;
layout->zone0.chunk_headers[2].type = CHUNK_TYPE_RUN;
memblock_rebuild_state(&pop->heap, &mhuge_used);
memblock_rebuild_state(&pop->heap, &mhuge_free);
memblock_rebuild_state(&pop->heap, &mrun);
UT_ASSERTeq(mhuge_used.type, MEMORY_BLOCK_HUGE);
UT_ASSERTeq(mhuge_free.type, MEMORY_BLOCK_HUGE);
UT_ASSERTeq(mrun.type, MEMORY_BLOCK_RUN);
}
static void
test_block_size(void)
{
struct memory_block mhuge = { .chunk_id = 0, 0, 0, 0 };
struct memory_block mrun = { .chunk_id = 1, 0, 0, 0 };
struct palloc_heap *heap = &pop->heap;
struct heap_layout *layout = heap->layout;
layout->zone0.chunk_headers[0].size_idx = 1;
layout->zone0.chunk_headers[0].type = CHUNK_TYPE_USED;
layout->zone0.chunk_headers[1].size_idx = 1;
layout->zone0.chunk_headers[1].type = CHUNK_TYPE_RUN;
struct chunk_run *run = (struct chunk_run *)
&layout->zone0.chunks[1];
run->hdr.block_size = 1234;
memblock_rebuild_state(&pop->heap, &mhuge);
memblock_rebuild_state(&pop->heap, &mrun);
UT_ASSERTne(mhuge.m_ops, NULL);
UT_ASSERTne(mrun.m_ops, NULL);
UT_ASSERTeq(mhuge.m_ops->block_size(&mhuge), CHUNKSIZE);
UT_ASSERTeq(mrun.m_ops->block_size(&mrun), 1234);
}
static void
test_prep_hdr(void)
{
struct memory_block mhuge_used = { .chunk_id = 0, 0, .size_idx = 1, 0 };
struct memory_block mhuge_free = { .chunk_id = 1, 0, .size_idx = 1, 0 };
struct memory_block mrun_used = { .chunk_id = 2, 0,
.size_idx = 4, .block_off = 0 };
struct memory_block mrun_free = { .chunk_id = 2, 0,
.size_idx = 4, .block_off = 4 };
struct memory_block mrun_large_used = { .chunk_id = 2, 0,
.size_idx = 64, .block_off = 64 };
struct memory_block mrun_large_free = { .chunk_id = 2, 0,
.size_idx = 64, .block_off = 128 };
struct palloc_heap *heap = &pop->heap;
struct heap_layout *layout = heap->layout;
layout->zone0.chunk_headers[0].size_idx = 1;
layout->zone0.chunk_headers[0].type = CHUNK_TYPE_USED;
layout->zone0.chunk_headers[1].size_idx = 1;
layout->zone0.chunk_headers[1].type = CHUNK_TYPE_FREE;
layout->zone0.chunk_headers[2].size_idx = 1;
layout->zone0.chunk_headers[2].type = CHUNK_TYPE_RUN;
struct chunk_run *run = (struct chunk_run *)&layout->zone0.chunks[2];
run->hdr.block_size = 128;
uint64_t *bitmap = (uint64_t *)run->content;
bitmap[0] = 0b1111;
bitmap[1] = ~0ULL;
bitmap[2] = 0ULL;
memblock_rebuild_state(heap, &mhuge_used);
memblock_rebuild_state(heap, &mhuge_free);
memblock_rebuild_state(heap, &mrun_used);
memblock_rebuild_state(heap, &mrun_free);
memblock_rebuild_state(heap, &mrun_large_used);
memblock_rebuild_state(heap, &mrun_large_free);
UT_ASSERTne(mhuge_used.m_ops, NULL);
mhuge_used.m_ops->prep_hdr(&mhuge_used, MEMBLOCK_FREE, NULL);
UT_ASSERTeq(layout->zone0.chunk_headers[0].type, CHUNK_TYPE_FREE);
mhuge_free.m_ops->prep_hdr(&mhuge_free, MEMBLOCK_ALLOCATED, NULL);
UT_ASSERTeq(layout->zone0.chunk_headers[1].type, CHUNK_TYPE_USED);
mrun_used.m_ops->prep_hdr(&mrun_used, MEMBLOCK_FREE, NULL);
UT_ASSERTeq(bitmap[0], 0ULL);
mrun_free.m_ops->prep_hdr(&mrun_free, MEMBLOCK_ALLOCATED, NULL);
UT_ASSERTeq(bitmap[0], 0b11110000);
mrun_large_used.m_ops->prep_hdr(&mrun_large_used, MEMBLOCK_FREE, NULL);
UT_ASSERTeq(bitmap[1], 0ULL);
mrun_large_free.m_ops->prep_hdr(&mrun_large_free,
MEMBLOCK_ALLOCATED, NULL);
UT_ASSERTeq(bitmap[2], ~0ULL);
}
static int
fake_persist(void *base, const void *addr, size_t size, unsigned flags)
{
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memblock");
PMEMobjpool pool;
pop = &pool;
pop->heap.layout = ZALLOC(sizeof(struct heap_layout) +
NCHUNKS * sizeof(struct chunk));
pop->heap.p_ops.persist = fake_persist;
test_detect();
test_block_size();
test_prep_hdr();
FREE(pop->heap.layout);
DONE(NULL);
}
| 6,835 | 30.357798 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_memblock/mocks_windows.h | /*
* 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.
*/
/*
* mocks_windows.h -- redefinitions of memops 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_memblock test.
* It would replace default implementation with mocked functions defined
* in obj_memblock.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define operation_add_typed_entry __wrap_operation_add_typed_entry
#define operation_add_entry __wrap_operation_add_entry
#endif
| 2,149 | 42 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sds/obj_sds.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.
*/
/*
* util_sds.c -- unit test for shutdown status functions
*/
#include "unittest.h"
#include "shutdown_state.h"
#include <stdlib.h>
#include <libpmemobj.h>
static char **uids;
static size_t uids_size;
static size_t uid_it;
static uint64_t *uscs;
static size_t uscs_size;
static size_t usc_it;
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_sds");
if (argc < 2)
UT_FATAL("usage: %s init fail file (uuid usc)...", argv[0]);
unsigned files = (unsigned)(argc - 3) / 2;
uids = MALLOC(files * sizeof(uids[0]));
uscs = MALLOC(files * sizeof(uscs[0]));
uids_size = files;
uscs_size = files;
int init = atoi(argv[1]);
int fail = atoi(argv[2]);
char *path = argv[3];
char **args = argv + 4;
for (unsigned i = 0; i < files; i++) {
uids[i] = args[i * 2];
uscs[i] = strtoull(args[i * 2 + 1], NULL, 0);
}
PMEMobjpool *pop;
if (init) {
if ((pop = pmemobj_create(path, "LAYOUT", 0, 0600)) == NULL) {
UT_FATAL("!%s: pmemobj_create", path);
}
#ifndef _WIN32
pmemobj_close(pop);
pmempool_feature_enable(path, PMEMPOOL_FEAT_SHUTDOWN_STATE, 0);
if ((pop = pmemobj_open(path, "LAYOUT")) == NULL) {
UT_FATAL("!%s: pmemobj_open", path);
}
#endif
} else {
if ((pop = pmemobj_open(path, "LAYOUT")) == NULL) {
UT_FATAL("!%s: pmemobj_open", path);
}
}
if (!fail)
pmemobj_close(pop);
FREE(uids);
FREE(uscs);
if (fail)
exit(1);
DONE(NULL);
}
FUNC_MOCK(os_dimm_uid, int, const char *path, char *uid, size_t *len, ...)
FUNC_MOCK_RUN_DEFAULT {
if (uid_it < uids_size) {
if (uid != NULL) {
strcpy(uid, uids[uid_it]);
uid_it++;
} else {
*len = strlen(uids[uid_it]) + 1;
}
} else {
return -1;
}
return 0;
}
FUNC_MOCK_END
FUNC_MOCK(os_dimm_usc, int, const char *path, uint64_t *usc, ...)
FUNC_MOCK_RUN_DEFAULT {
if (usc_it < uscs_size) {
*usc = uscs[usc_it];
usc_it++;
} else {
return -1;
}
return 0;
}
FUNC_MOCK_END
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 3,665 | 25 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_sds/mocks_windows.h | /*
* 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_windows.h -- redefinitions of dimm functions
*/
#ifndef WRAP_REAL
#define os_dimm_usc __wrap_os_dimm_usc
#define os_dimm_uid __wrap_os_dimm_uid
#endif
| 1,762 | 42 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/libpmempool_api_win/libpmempool_test_win.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.
*/
/*
* libpmempool_test_win -- test of libpmempool.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.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 wchar_t *path;
const wchar_t *backup_path;
enum pmempool_pool_type pool_type;
int flags;
};
/*
* check_pool -- check given pool
*/
static void
check_pool(struct pmempool_check_argsW *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_initW(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_statusW *status = NULL;
while ((status = pmempool_checkW(ppc)) != NULL) {
char *msg = ut_toUTF8(status->str.msg);
switch (status->type) {
case PMEMPOOL_CHECK_MSG_TYPE_ERROR:
UT_OUT("%s", msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_INFO:
UT_OUT("%s", msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_QUESTION:
UT_OUT("%s", msg);
status->str.answer = L"yes";
break;
default:
pmempool_check_end(ppc);
free(msg);
exit(EXIT_FAILURE);
}
free(msg);
}
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(wchar_t *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 wchar_t *value, int *flags, int flag)
{
if (_wtoi(value) > 0)
*flags |= flag;
else
*flags &= ~flag;
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "libpmempool_test_win");
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);
for (int i = 1; i < argc - 1; i += 2) {
wchar_t *optarg = argv[i + 1];
if (wcscmp(L"-t", argv[i]) == 0) {
if (wcscmp(optarg, L"blk") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_BLK;
} else if (wcscmp(optarg, L"log") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_LOG;
} else if (wcscmp(optarg, L"obj") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_OBJ;
} else if (wcscmp(optarg, L"btt") == 0) {
args.pool_type = PMEMPOOL_POOL_TYPE_BTT;
} else {
args.pool_type =
(uint32_t)wcstoul(optarg, NULL, 0);
}
} else if (wcscmp(L"-r", argv[i]) == 0) {
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_REPAIR);
} else if (wcscmp(L"-d", argv[i]) == 0) {
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_DRY_RUN);
} else if (wcscmp(L"-a", argv[i]) == 0) {
set_flag(optarg, &args.flags, PMEMPOOL_CHECK_ADVANCED);
} else if (wcscmp(L"-y", argv[i]) == 0) {
set_flag(optarg, &args.flags,
PMEMPOOL_CHECK_ALWAYS_YES);
} else if (wcscmp(L"-s", argv[i]) == 0) {
args_size = wcstoul(optarg, NULL, 0);
} else if (wcscmp(L"-b", argv[i]) == 0) {
args.backup_path = optarg;
} else {
print_usage(argv[0]);
UT_FATAL("unknown option: %c", argv[i][1]);
}
}
args.path = argv[argc - 1];
check_pool((struct pmempool_check_argsW *)&args, args_size);
DONEW(NULL);
}
| 5,427 | 28.98895 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_is_pmem_windows/pmem_is_pmem_windows.c | /*
* Copyright 2014-2017, Intel Corporation
* Copyright (c) 2015-2017, 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.
*/
/*
* pmem_is_pmem_windows.c -- Windows specific unit test for is_pmem_detect()
*
* usage: pmem_is_pmem_windows file [env]
*/
#include "unittest.h"
#include "pmem.h"
#include "queue.h"
#include "win_mmap.h"
#include "util.h"
#define NTHREAD 16
static void *Addr;
static size_t Size;
static int pmem_is_pmem_force = 0;
enum test_mmap_scenarios {
TEST_MMAP_SCENARIO_UNKNOWN,
TEST_MMAP_SCENARIO_BEGIN_HOLE,
TEST_MMAP_SCENARIO_END_HOLE,
TEST_MMAP_SCENARIO_MIDDLE_HOLE,
TEST_MMAP_SCENARIO_NO_HOLE
};
enum test_mmap_scenarios
get_mmap_scenarios(char *name)
{
if (stricmp(name, "nothing") == 0)
return TEST_MMAP_SCENARIO_NO_HOLE;
if (stricmp(name, "begin") == 0)
return TEST_MMAP_SCENARIO_BEGIN_HOLE;
if (stricmp(name, "end") == 0)
return TEST_MMAP_SCENARIO_END_HOLE;
if (stricmp(name, "middle") == 0)
return TEST_MMAP_SCENARIO_MIDDLE_HOLE;
return TEST_MMAP_SCENARIO_UNKNOWN;
}
/*
* mmap_file_mapping_comparer -- (internal) compares the two file mapping
* trackers
*/
static LONG_PTR
mmap_file_mapping_comparer(PFILE_MAPPING_TRACKER a, PFILE_MAPPING_TRACKER b)
{
return ((LONG_PTR)a->BaseAddress - (LONG_PTR)b->BaseAddress);
}
/*
* worker -- the work each thread performs
*/
static void *
worker(void *arg)
{
int *ret = (int *)arg;
/*
* We honor the force just to let the scenarios that require pmem fs
* work in the environment that forces pmem.
*
* NOTE: We can't use pmem_is_pmem instead of checking for the ENV
* variable explicitly, because we want to call is_pmem_detect that is
* defined in this test so that it will use the FileMappingQHead
* that's defined here. Because we are crafting the Q in the test.
*/
if (pmem_is_pmem_force)
*ret = 1;
else
*ret = is_pmem_detect(Addr, Size);
return NULL;
}
extern SRWLOCK FileMappingQLock;
extern struct FMLHead FileMappingQHead;
int
main(int argc, char *argv[])
{
HANDLE file_map;
SIZE_T chunk_length;
enum test_mmap_scenarios scenario;
int still_holey = 1;
int already_holey = 0;
START(argc, argv, "pmem_is_pmem_windows");
if (argc != 3)
UT_FATAL("usage: %s file {begin|end|middle|nothing}", argv[0]);
util_init(); /* to initialize Mmap_align */
char *str_pmem_is_pmem_force = os_getenv("PMEM_IS_PMEM_FORCE");
if (str_pmem_is_pmem_force && atoi(str_pmem_is_pmem_force) == 1)
pmem_is_pmem_force = 1;
scenario = get_mmap_scenarios(argv[2]);
UT_ASSERT(scenario != TEST_MMAP_SCENARIO_UNKNOWN);
int fd = OPEN(argv[1], O_RDWR);
os_stat_t stbuf;
FSTAT(fd, &stbuf);
Size = stbuf.st_size;
chunk_length = Mmap_align;
/*
* We dont' support too small a file size.
*/
UT_ASSERT(Size / 8 > chunk_length);
file_map = CreateFileMapping((HANDLE)_get_osfhandle(fd), NULL,
PAGE_READONLY, 0, 0, NULL);
UT_ASSERT(file_map != NULL);
Addr = MapViewOfFile(file_map, FILE_MAP_READ, 0, 0, 0);
/*
* let's setup FileMappingQHead such that, it appears to have lot of
* DAX mapping created through our mmap. Here are our cases based
* on the input:
* - entire region in mapped through our mmap
* - there is a region at the beginning that's not mapped through our
* mmap
* - there is a region at the end that's not mapped through our mmap
* - there is a region in the middle that mapped through our mmap
*/
for (size_t offset = 0;
offset < Size;
offset += chunk_length) {
void *base_address = (void *)((char *)Addr + offset);
switch (scenario) {
case TEST_MMAP_SCENARIO_BEGIN_HOLE:
if (still_holey &&
((offset == 0) || ((rand() % 2) == 0)) &&
(offset < (Size / 2)))
continue;
else
still_holey = 0;
break;
case TEST_MMAP_SCENARIO_END_HOLE:
if ((offset > (Size / 2)) &&
(already_holey || ((rand() % 2) == 0) ||
(offset >= (Size - chunk_length)))) {
already_holey = 1;
continue;
} else
UT_ASSERT(!already_holey);
break;
case TEST_MMAP_SCENARIO_MIDDLE_HOLE:
if ((((offset > (Size / 8)) && ((rand() % 2) == 0)) ||
(offset > (Size / 8) * 6)) &&
(offset < (Size / 8) * 7))
continue;
break;
}
PFILE_MAPPING_TRACKER mt =
MALLOC(sizeof(struct FILE_MAPPING_TRACKER));
mt->Flags = FILE_MAPPING_TRACKER_FLAG_DIRECT_MAPPED;
mt->FileHandle = (HANDLE)_get_osfhandle(fd);
mt->FileMappingHandle = file_map;
mt->BaseAddress = base_address;
mt->EndAddress = (void *)((char *)base_address + chunk_length);
mt->Access = FILE_MAP_READ;
mt->Offset = offset;
AcquireSRWLockExclusive(&FileMappingQLock);
SORTEDQ_INSERT(&FileMappingQHead, mt, ListEntry,
FILE_MAPPING_TRACKER,
mmap_file_mapping_comparer);
ReleaseSRWLockExclusive(&FileMappingQLock);
}
CloseHandle(file_map);
CLOSE(fd);
os_thread_t threads[NTHREAD];
int ret[NTHREAD];
/* kick off NTHREAD threads */
for (int i = 0; i < NTHREAD; i++)
PTHREAD_CREATE(&threads[i], NULL, worker, &ret[i]);
/* wait for all the threads to complete */
for (int i = 0; i < NTHREAD; i++)
PTHREAD_JOIN(&threads[i], NULL);
/* verify that all the threads return the same value */
for (int i = 1; i < NTHREAD; i++)
UT_ASSERTeq(ret[0], ret[i]);
UT_OUT("%d", ret[0]);
DONE(NULL);
}
/*
* Since libpmem is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmem_init)
MSVC_DESTR(libpmem_fini)
| 6,900 | 27.052846 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_fragmentation2/obj_fragmentation2.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_fragmentation.c -- measures average heap external fragmentation
*
* This test is based on the workloads proposed in:
* Log-structured Memory for DRAM-based Storage
* by Stephen M. Rumble, Ankita Kejriwal, and John Ousterhout
*
* https://www.usenix.org/system/files/conference/fast14/fast14-paper_rumble.pdf
*/
#include <stdlib.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_fragmentation"
#define MEGABYTE (1UL << 20)
#define GIGABYTE (1UL << 30)
#define RRAND(seed, max, min)\
((min) == (max) ? (min) : (os_rand_r(&(seed)) % ((max) - (min)) + (min)))
static uint64_t *objects;
static size_t nobjects;
static size_t allocated_current;
#define MAX_OBJECTS (200ULL * 1000000)
#define ALLOC_TOTAL (5000ULL * MEGABYTE)
#define ALLOC_CURR (1000 * MEGABYTE)
#define FREES_P 200
#define DEFAULT_FILE_SIZE (3 * GIGABYTE)
static unsigned seed;
static void
shuffle_objects(size_t start, size_t end)
{
uint64_t tmp;
size_t dest;
for (size_t n = start; n < end; ++n) {
dest = RRAND(seed, nobjects - 1, 0);
tmp = objects[n];
objects[n] = objects[dest];
objects[dest] = tmp;
}
}
static uint64_t
remove_last()
{
UT_ASSERT(nobjects > 0);
uint64_t obj = objects[--nobjects];
return obj;
}
static void
allocate_objects(PMEMobjpool *pop, size_t size_min, size_t size_max)
{
size_t allocated_total = 0;
size_t sstart = 0;
PMEMoid oid = pmemobj_root(pop, 1);
uint64_t uuid_lo = oid.pool_uuid_lo;
while (allocated_total < ALLOC_TOTAL) {
size_t s = RRAND(seed, size_max, size_min);
pmemobj_alloc(pop, &oid, s, 0, NULL, NULL);
s = pmemobj_alloc_usable_size(oid);
UT_ASSERTeq(OID_IS_NULL(oid), 0);
objects[nobjects++] = oid.off;
UT_ASSERT(nobjects < MAX_OBJECTS);
allocated_total += s;
allocated_current += s;
if (allocated_current > ALLOC_CURR) {
shuffle_objects(sstart, nobjects);
for (int i = 0; i < FREES_P; ++i) {
oid.pool_uuid_lo = uuid_lo;
oid.off = remove_last();
allocated_current -=
pmemobj_alloc_usable_size(oid);
pmemobj_free(&oid);
}
sstart = nobjects;
}
}
}
static void
delete_objects(PMEMobjpool *pop, float pct)
{
size_t nfree = (size_t)(nobjects * pct);
PMEMoid oid = pmemobj_root(pop, 1);
uint64_t uuid_lo = oid.pool_uuid_lo;
shuffle_objects(0, nobjects);
while (nfree--) {
oid.off = remove_last();
oid.pool_uuid_lo = uuid_lo;
allocated_current -= pmemobj_alloc_usable_size(oid);
pmemobj_free(&oid);
}
}
typedef void workload(PMEMobjpool *pop);
static void w0(PMEMobjpool *pop) {
allocate_objects(pop, 100, 100);
}
static void w1(PMEMobjpool *pop) {
allocate_objects(pop, 100, 100);
allocate_objects(pop, 130, 130);
}
static void w2(PMEMobjpool *pop) {
allocate_objects(pop, 100, 100);
delete_objects(pop, 0.9F);
allocate_objects(pop, 130, 130);
}
static void w3(PMEMobjpool *pop) {
allocate_objects(pop, 100, 150);
allocate_objects(pop, 200, 250);
}
static void w4(PMEMobjpool *pop) {
allocate_objects(pop, 100, 150);
delete_objects(pop, 0.9F);
allocate_objects(pop, 200, 250);
}
static void w5(PMEMobjpool *pop) {
allocate_objects(pop, 100, 200);
delete_objects(pop, 0.5);
allocate_objects(pop, 1000, 2000);
}
static void w6(PMEMobjpool *pop) {
allocate_objects(pop, 1000, 2000);
delete_objects(pop, 0.9F);
allocate_objects(pop, 1500, 2500);
}
static void w7(PMEMobjpool *pop) {
allocate_objects(pop, 50, 150);
delete_objects(pop, 0.9F);
allocate_objects(pop, 5000, 15000);
}
static void w8(PMEMobjpool *pop) {
allocate_objects(pop, 2 * MEGABYTE, 2 * MEGABYTE);
}
static workload *workloads[] = {
w0, w1, w2, w3, w4, w5, w6, w7, w8
};
static float workloads_target[] = {
0.01f, 0.01f, 0.01f, 0.9f, 0.8f, 0.7f, 0.3f, 0.8f, 0.73f
};
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_fragmentation2");
if (argc < 3)
UT_FATAL("usage: %s filename workload [seed]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, DEFAULT_FILE_SIZE,
S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
int w = atoi(argv[2]);
if (argc > 3)
seed = (unsigned)atoi(argv[3]);
else
seed = ((unsigned)time(NULL));
objects = ZALLOC(sizeof(uint64_t) * MAX_OBJECTS);
UT_ASSERTne(objects, NULL);
workloads[w](pop);
PMEMoid oid;
size_t remaining = 0;
size_t chunk = 100; /* calc at chunk level */
while (pmemobj_alloc(pop, &oid, chunk, 0, NULL, NULL) == 0)
remaining += pmemobj_alloc_usable_size(oid) + 16;
size_t allocated_sum = 0;
oid = pmemobj_root(pop, 1);
for (size_t n = 0; n < nobjects; ++n) {
if (objects[n] == 0)
continue;
oid.off = objects[n];
allocated_sum += pmemobj_alloc_usable_size(oid) + 16;
}
size_t used = DEFAULT_FILE_SIZE - remaining;
float frag = ((float)used / allocated_sum) - 1.f;
UT_ASSERT(frag <= workloads_target[w]);
pmemobj_close(pop);
FREE(objects);
DONE(NULL);
}
| 6,459 | 24.433071 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/rpmemd_config/rpmemd_config_test.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_log_test.c -- unit tests for rpmemd_log
*/
#include <stddef.h>
#include <inttypes.h>
#include <sys/param.h>
#include <syslog.h>
#include <pwd.h>
#include "unittest.h"
#include "rpmemd_log.h"
#include "rpmemd_config.h"
static const char *config_print_fmt =
"log_file\t\t%s\n"
"poolset_dir:\t\t%s\n"
"persist_apm:\t\t%s\n"
"persist_general:\t%s\n"
"use_syslog:\t\t%s\n"
"max_lanes:\t\t%" PRIu64 "\n"
"log_level:\t\t%s";
/*
* bool_to_str -- convert bool value to a string ("yes" / "no")
*/
static inline const char *
bool_to_str(bool v)
{
return v ? "yes" : "no";
}
/*
* config_print -- print rpmemd_config to the stdout
*/
static void
config_print(struct rpmemd_config *config)
{
UT_ASSERT(config->log_level < MAX_RPD_LOG);
UT_OUT(
config_print_fmt,
config->log_file,
config->poolset_dir,
bool_to_str(config->persist_apm),
bool_to_str(config->persist_general),
bool_to_str(config->use_syslog),
config->max_lanes,
rpmemd_log_level_to_str(config->log_level));
}
/*
* parse_test_params -- parse command line options specific to the test
*
* usage: rpmemd_config [rpmemd options] [test options]
*
* Available test options:
* - print_HOME_env prints current HOME_ENV value
*/
static void
parse_test_params(int *argc, char *argv[])
{
if (*argc <= 1)
return;
if (strcmp(argv[*argc - 1], "print_HOME_env") == 0) {
char *home = os_getenv(HOME_ENV);
if (home) {
UT_OUT("$%s == %s", HOME_ENV, home);
} else {
UT_OUT("$%s is not set", HOME_ENV);
}
} else {
return;
}
*argc -= 1;
}
int
main(int argc, char *argv[])
{
/* workaround for getpwuid open fd */
getpwuid(getuid());
START(argc, argv, "rpmemd_config");
int ret = rpmemd_log_init("rpmemd_log", NULL, 0);
UT_ASSERTeq(ret, 0);
parse_test_params(&argc, argv);
struct rpmemd_config config;
ret = rpmemd_config_read(&config, argc, argv);
if (ret) {
UT_OUT("invalid config");
} else {
config_print(&config);
}
rpmemd_log_close();
rpmemd_config_free(&config);
DONE(NULL);
}
| 3,614 | 24.821429 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_sds/util_sds.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.
*/
/*
* util_sds.c -- unit test for shutdown state functions
*/
#include <stdlib.h>
#include "unittest.h"
#include "shutdown_state.h"
#include "pmemcommon.h"
#include "set.h"
#define PMEM_LEN 4096
static char **uids;
static size_t uids_size;
static size_t uid_it;
static uint64_t *uscs;
static size_t uscs_size;
static size_t usc_it;
#define FAIL(X, Y) \
if ((X) == (Y)) {\
common_fini();\
DONE(NULL);\
exit(0);\
}
#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
int
main(int argc, char *argv[])
{
START(argc, argv, "util_sds");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
size_t mapped_len = PMEM_LEN;
int is_pmem;
if (argc < 2)
UT_FATAL("usage: %s init fail (file uuid usc)...", argv[0]);
unsigned files = (unsigned)(argc - 2) / 3;
char **pmemaddr = MALLOC(files * sizeof(char *));
uids = MALLOC(files * sizeof(uids[0]));
uscs = MALLOC(files * sizeof(uscs[0]));
uids_size = files;
uscs_size = files;
int init = atoi(argv[1]);
int fail_on = atoi(argv[2]);
char **args = argv + 3;
for (unsigned i = 0; i < files; i++) {
if ((pmemaddr[i] = pmem_map_file(args[i * 3], PMEM_LEN,
PMEM_FILE_CREATE, 0666, &mapped_len,
&is_pmem)) == NULL) {
UT_FATAL("pmem_map_file");
}
uids[i] = args[i * 3 + 1];
uscs[i] = strtoull(args[i * 3 + 2], NULL, 0);
}
FAIL(fail_on, 1);
struct pool_replica *rep = MALLOC(
sizeof(*rep) + sizeof(struct pool_set_part));
memset(rep, 0, sizeof(*rep) + sizeof(struct pool_set_part));
struct shutdown_state *pool_sds = (struct shutdown_state *)pmemaddr[0];
if (init) {
/* initialize pool shutdown state */
shutdown_state_init(pool_sds, rep);
FAIL(fail_on, 2);
for (unsigned i = 0; i < files; i++) {
if (shutdown_state_add_part(pool_sds, args[2 + i], rep))
UT_FATAL("shutdown_state_add_part");
FAIL(fail_on, 3);
}
} else {
/* verify a shutdown state saved in the pool */
struct shutdown_state current_sds;
shutdown_state_init(¤t_sds, NULL);
FAIL(fail_on, 2);
for (unsigned i = 0; i < files; i++) {
if (shutdown_state_add_part(¤t_sds,
args[2 + i], NULL))
UT_FATAL("shutdown_state_add_part");
FAIL(fail_on, 3);
}
if (shutdown_state_check(¤t_sds, pool_sds, rep)) {
UT_FATAL(
"An ADR failure is detected, the pool might be corrupted");
}
}
FAIL(fail_on, 4);
shutdown_state_set_dirty(pool_sds, rep);
/* pool is open */
FAIL(fail_on, 5);
/* close pool */
shutdown_state_clear_dirty(pool_sds, rep);
FAIL(fail_on, 6);
for (unsigned i = 0; i < files; i++)
pmem_unmap(pmemaddr[i], mapped_len);
FREE(pmemaddr);
FREE(uids);
FREE(uscs);
common_fini();
DONE(NULL);
}
FUNC_MOCK(os_dimm_uid, int, const char *path, char *uid, size_t *len, ...)
FUNC_MOCK_RUN_DEFAULT {
if (uid_it < uids_size) {
if (uid != NULL) {
strcpy(uid, uids[uid_it]);
uid_it++;
} else {
*len = strlen(uids[uid_it]) + 1;
}
} else {
return -1;
}
return 0;
}
FUNC_MOCK_END
FUNC_MOCK(os_dimm_usc, int, const char *path, uint64_t *usc, ...)
FUNC_MOCK_RUN_DEFAULT {
if (usc_it < uscs_size) {
*usc = uscs[usc_it];
usc_it++;
} else {
return -1;
}
return 0;
}
FUNC_MOCK_END
| 4,879 | 25.813187 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_sds/mocks_windows.h | /*
* 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_windows.h -- redefinitions of dimm functions
*/
#ifndef WRAP_REAL
#define os_dimm_usc __wrap_os_dimm_usc
#define os_dimm_uid __wrap_os_dimm_uid
#endif
| 1,762 | 42 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_file_create/util_file_create.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.
*/
/*
* util_file_create.c -- unit test for util_file_create()
*
* usage: util_file_create minlen len:path [len:path]...
*/
#include "unittest.h"
#include "file.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "util_file_create");
if (argc < 3)
UT_FATAL("usage: %s minlen len:path...", argv[0]);
char *fname;
size_t minsize = strtoul(argv[1], &fname, 0);
for (int arg = 2; arg < argc; arg++) {
size_t size = strtoul(argv[arg], &fname, 0);
if (*fname != ':')
UT_FATAL("usage: %s minlen len:path...", argv[0]);
fname++;
int fd;
if ((fd = util_file_create(fname, size, minsize)) == -1)
UT_OUT("!%s: util_file_create", fname);
else {
UT_OUT("%s: created", fname);
os_close(fd);
}
}
DONE(NULL);
}
| 2,344 | 32.5 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_create_in_region/vmem_create_in_region.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_in_region.c -- unit test for vmem_create_in_region
*
* usage: vmem_create_in_region
*/
#include "unittest.h"
#define TEST_ALLOCATIONS (300)
static void *allocs[TEST_ALLOCATIONS];
int
main(int argc, char *argv[])
{
VMEM *vmp;
size_t i;
START(argc, argv, "vmem_create_in_region");
if (argc > 1)
UT_FATAL("usage: %s", argv[0]);
/* 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");
for (i = 0; i < TEST_ALLOCATIONS; ++i) {
allocs[i] = vmem_malloc(vmp, sizeof(int));
UT_ASSERTne(allocs[i], NULL);
/* check that pointer came from mem_pool */
UT_ASSERTrange(allocs[i], mem_pool, VMEM_MIN_POOL);
}
for (i = 0; i < TEST_ALLOCATIONS; ++i) {
vmem_free(vmp, allocs[i]);
}
vmem_delete(vmp);
DONE(NULL);
}
| 2,531 | 30.259259 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_add_range/obj_tx_add_range.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.c -- unit test for pmemobj_tx_add_range
*/
#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"
#define OBJ_SIZE 1024
#define OVERLAP_SIZE 100
#define ROOT_TAB_SIZE\
(TX_DEFAULT_RANGE_CACHE_SIZE / sizeof(int))
#define REOPEN_COUNT 10
enum type_number {
TYPE_OBJ,
TYPE_OBJ_ABORT,
};
TOID_DECLARE(struct object, 0);
TOID_DECLARE(struct overlap_object, 1);
TOID_DECLARE_ROOT(struct root);
struct root {
int val;
int tab[ROOT_TAB_SIZE];
};
struct object {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
struct overlap_object {
uint8_t data[OVERLAP_SIZE];
};
#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, uint64_t 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 pmemobj_add_range 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));
ret = pmemobj_tx_add_range(obj.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range(obj.oid, 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 pmemobj_add_range 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));
ret = pmemobj_tx_add_range(obj.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range(obj.oid, 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 pmemobj_add_range 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) {
ret = pmemobj_tx_add_range(obj.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range(obj.oid, 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 pmemobj_add_range 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) {
ret = pmemobj_tx_add_range(obj.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range(obj.oid, 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 pmemobj_tx_add_range 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) {
ret = pmemobj_tx_add_range(obj1.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
ret = pmemobj_tx_add_range(obj2.oid,
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 pmemobj_tx_add_range 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) {
ret = pmemobj_tx_add_range(obj1.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
ret = pmemobj_tx_add_range(obj2.oid,
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 pmemobj_tx_add_range 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) {
ret = pmemobj_tx_add_range(obj1.oid, VALUE_OFF, VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
ret = pmemobj_tx_add_range(obj2.oid,
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 pmemobj_tx_add_range 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) {
ret = pmemobj_tx_add_range(obj.oid, 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_huge_range_abort -- call pmemobj_tx_add_range on a huge range and
* commit the tx
*/
static void
do_tx_add_huge_range_abort(PMEMobjpool *pop)
{
int ret;
size_t snapshot_s = TX_DEFAULT_RANGE_CACHE_THRESHOLD + 1;
PMEMoid obj;
pmemobj_zalloc(pop, &obj, snapshot_s, 0);
TX_BEGIN(pop) {
ret = pmemobj_tx_add_range(obj, 0, snapshot_s);
UT_ASSERTeq(ret, 0);
memset(pmemobj_direct(obj), 0xc, snapshot_s);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(pmemobj_direct(obj), snapshot_s));
}
/*
* do_tx_add_range_commit -- call pmemobj_tx_add_range and commit the 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) {
ret = pmemobj_tx_add_range(obj.oid, 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 pmemobj_tx_xadd_range and commit the 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) {
ret = pmemobj_tx_xadd_range(obj.oid, 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_add_range_overlapping -- call pmemobj_tx_add_range with overlapping
*/
static void
do_tx_add_range_overlapping(PMEMobjpool *pop)
{
TOID(struct overlap_object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, 1));
/*
* -+-+-+-+-
* +++++++++
*/
TX_BEGIN(pop) {
TX_ADD_FIELD(obj, data[1]);
D_RW(obj)->data[1] = 1;
TX_ADD_FIELD(obj, data[3]);
D_RW(obj)->data[3] = 3;
TX_ADD_FIELD(obj, data[5]);
D_RW(obj)->data[5] = 5;
TX_ADD_FIELD(obj, data[7]);
D_RW(obj)->data[7] = 7;
TX_ADD(obj);
memset(D_RW(obj)->data, 0xFF, OVERLAP_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(D_RO(obj)->data, OVERLAP_SIZE));
/*
* ++++----++++
* --++++++++--
*/
TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 4);
memset(D_RW(obj)->data + 0, 1, 4);
pmemobj_tx_add_range(obj.oid, 8, 4);
memset(D_RW(obj)->data + 8, 2, 4);
pmemobj_tx_add_range(obj.oid, 2, 8);
memset(D_RW(obj)->data + 2, 3, 8);
TX_ADD(obj);
memset(D_RW(obj)->data, 0xFF, OVERLAP_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(D_RO(obj)->data, OVERLAP_SIZE));
/*
* ++++----++++
* ----++++----
*/
TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 4);
memset(D_RW(obj)->data + 0, 1, 4);
pmemobj_tx_add_range(obj.oid, 8, 4);
memset(D_RW(obj)->data + 8, 2, 4);
pmemobj_tx_add_range(obj.oid, 4, 4);
memset(D_RW(obj)->data + 4, 3, 4);
TX_ADD(obj);
memset(D_RW(obj)->data, 0xFF, OVERLAP_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(D_RO(obj)->data, OVERLAP_SIZE));
/*
* ++++-++-++++
* --++++++++--
*/
TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 4);
memset(D_RW(obj)->data + 0, 1, 4);
pmemobj_tx_add_range(obj.oid, 5, 2);
memset(D_RW(obj)->data + 5, 2, 2);
pmemobj_tx_add_range(obj.oid, 8, 4);
memset(D_RW(obj)->data + 8, 3, 4);
pmemobj_tx_add_range(obj.oid, 2, 8);
memset(D_RW(obj)->data + 2, 4, 8);
TX_ADD(obj);
memset(D_RW(obj)->data, 0xFF, OVERLAP_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(D_RO(obj)->data, OVERLAP_SIZE));
/*
* ++++
* ++++
*/
TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 4);
memset(D_RW(obj)->data, 1, 4);
pmemobj_tx_add_range(obj.oid, 0, 4);
memset(D_RW(obj)->data, 2, 4);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(D_RO(obj)->data, OVERLAP_SIZE));
}
/*
* do_tx_add_range_reopen -- check for persistent memory leak in undo log set
*/
static void
do_tx_add_range_reopen(char *path)
{
for (int i = 0; i < REOPEN_COUNT; i++) {
PMEMobjpool *pop = pmemobj_open(path, LAYOUT_NAME);
UT_ASSERTne(pop, NULL);
TOID(struct root) root = POBJ_ROOT(pop, struct root);
UT_ASSERT(!TOID_IS_NULL(root));
UT_ASSERTeq(D_RO(root)->val, i);
for (int j = 0; j < ROOT_TAB_SIZE; j++)
UT_ASSERTeq(D_RO(root)->tab[j], i);
TX_BEGIN(pop) {
TX_SET(root, val, i + 1);
TX_ADD_FIELD(root, tab);
for (int j = 0; j < ROOT_TAB_SIZE; j++)
D_RW(root)->tab[j] = i + 1;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_close(pop);
}
}
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(obj.oid, 0,
PMEMOBJ_MAX_ALLOC_SIZE + 1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTne(errno, 0);
}
static void
do_tx_add_range_zero(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
pmemobj_tx_add_range(obj.oid, 0, 0);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTne(errno, 0);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_add_range");
util_init();
if (argc != 3)
UT_FATAL("usage: %s [file] [0|1]", argv[0]);
int do_reopen = atoi(argv[2]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL * 2,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
if (do_reopen) {
pmemobj_close(pop);
do_tx_add_range_reopen(argv[1]);
} else {
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_add_range_overlapping(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_too_large(pop);
VALGRIND_WRITE_STATS;
do_tx_add_huge_range_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_zero(pop);
VALGRIND_WRITE_STATS;
do_tx_xadd_range_commit(pop);
pmemobj_close(pop);
}
DONE(NULL);
}
| 15,405 | 21.327536 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_recreate/obj_recreate.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_recreate.c -- recreate pool on dirty file and check consistency
*/
#include "unittest.h"
POBJ_LAYOUT_BEGIN(recreate);
POBJ_LAYOUT_ROOT(recreate, struct root);
POBJ_LAYOUT_TOID(recreate, struct foo);
POBJ_LAYOUT_END(recreate);
struct foo {
int bar;
};
struct root {
TOID(struct foo) foo;
};
#define LAYOUT_NAME "obj_recreate"
#define ZEROLEN 4096
#define N PMEMOBJ_MIN_POOL
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_recreate");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(recreate) != 1);
if (argc < 2)
UT_FATAL("usage: %s file-name [trunc]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
/* create pool 2*N */
pop = pmemobj_create(path, LAYOUT_NAME, 2 * N, S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
/* allocate 1.5*N */
TOID(struct root) root = (TOID(struct root))pmemobj_root(pop,
(size_t)(1.5 * N));
/* use root object for something */
POBJ_NEW(pop, &D_RW(root)->foo, struct foo, NULL, NULL);
pmemobj_close(pop);
int fd = OPEN(path, O_RDWR);
if (argc >= 3 && strcmp(argv[2], "trunc") == 0) {
UT_OUT("truncating");
/* shrink file to N */
FTRUNCATE(fd, N);
}
/* zero first 4kB */
void *p = MMAP(NULL, ZEROLEN, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
memset(p, 0, ZEROLEN);
MUNMAP(p, ZEROLEN);
CLOSE(fd);
/* create pool on existing file */
pop = pmemobj_create(path, LAYOUT_NAME, 0, S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
/* try to allocate 0.7*N */
root = (TOID(struct root))pmemobj_root(pop, (size_t)(0.5 * N));
if (TOID_IS_NULL(root))
UT_FATAL("couldn't allocate root object");
/* validate root object is empty */
if (!TOID_IS_NULL(D_RW(root)->foo))
UT_FATAL("root object is already filled after pmemobj_create!");
pmemobj_close(pop);
DONE(NULL);
}
| 3,468 | 28.398305 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_stats/cto_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.
*/
/*
* cto_stats.c -- unit test for cto_stats
*
* usage: cto_stats filename1 filename2 [opts]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
PMEMctopool *pcp1;
PMEMctopool *pcp2;
char *opts = "";
START(argc, argv, "cto_stats");
if (argc > 4) {
UT_FATAL("usage: %s filename1 filename2 [opts]", argv[0]);
} else {
if (argc > 3)
opts = argv[3];
}
pcp1 = pmemcto_create(argv[1], "test1", PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(pcp1, NULL);
pcp2 = pmemcto_create(argv[2], "test2", PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(pcp2, NULL);
int *ptr = pmemcto_malloc(pcp1, sizeof(int) * 100);
UT_ASSERTne(ptr, NULL);
pmemcto_stats_print(pcp1, opts);
pmemcto_stats_print(pcp2, opts);
pmemcto_close(pcp1);
pmemcto_close(pcp2);
pcp1 = pmemcto_open(argv[1], "test1");
UT_ASSERTne(pcp1, NULL);
pcp2 = pmemcto_open(argv[2], "test2");
UT_ASSERTne(pcp2, NULL);
pmemcto_stats_print(pcp1, opts);
pmemcto_stats_print(pcp2, opts);
pmemcto_free(pcp1, ptr);
pmemcto_stats_print(pcp1, opts);
pmemcto_stats_print(pcp2, opts);
pmemcto_close(pcp1);
pmemcto_close(pcp2);
DONE(NULL);
}
| 2,716 | 29.52809 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_ctl/util_ctl.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_ctl.c -- tests for the control module
*/
#include "unittest.h"
#include "ctl.h"
#include "out.h"
#include "pmemcommon.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
struct pool {
struct ctl *ctl;
};
static char *testconfig_path;
static int test_config_written;
static int
CTL_READ_HANDLER(test_rw)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_PROGRAMMATIC);
int *arg_rw = arg;
*arg_rw = 0;
return 0;
}
static int
CTL_WRITE_HANDLER(test_rw)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int *arg_rw = arg;
*arg_rw = 1;
test_config_written++;
return 0;
}
static struct ctl_argument CTL_ARG(test_rw) = CTL_ARG_INT;
static int
CTL_WRITE_HANDLER(test_wo)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int *arg_wo = arg;
*arg_wo = 1;
test_config_written++;
return 0;
}
static struct ctl_argument CTL_ARG(test_wo) = CTL_ARG_INT;
#define TEST_CONFIG_VALUE "abcd"
static int
CTL_WRITE_HANDLER(test_config)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_CONFIG_INPUT);
char *config_value = arg;
UT_ASSERTeq(strcmp(config_value, TEST_CONFIG_VALUE), 0);
test_config_written++;
return 0;
}
static struct ctl_argument CTL_ARG(test_config) = CTL_ARG_STRING(8);
struct complex_arg {
int a;
char b[5];
long long c;
int d;
};
#define COMPLEX_ARG_TEST_A 12345
#define COMPLEX_ARG_TEST_B "abcd"
#define COMPLEX_ARG_TEST_C 3147483647
#define COMPLEX_ARG_TEST_D 1
static int
CTL_WRITE_HANDLER(test_config_complex_arg)(void *ctx,
enum ctl_query_source source, void *arg,
struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_CONFIG_INPUT);
struct complex_arg *c = arg;
UT_ASSERTeq(c->a, COMPLEX_ARG_TEST_A);
UT_ASSERT(strcmp(COMPLEX_ARG_TEST_B, c->b) == 0);
UT_ASSERTeq(c->c, COMPLEX_ARG_TEST_C);
UT_ASSERTeq(c->d, COMPLEX_ARG_TEST_D);
test_config_written++;
return 0;
}
static struct ctl_argument CTL_ARG(test_config_complex_arg) = {
.dest_size = sizeof(struct complex_arg),
.parsers = {
CTL_ARG_PARSER_STRUCT(struct complex_arg, a, ctl_arg_integer),
CTL_ARG_PARSER_STRUCT(struct complex_arg, b, ctl_arg_string),
CTL_ARG_PARSER_STRUCT(struct complex_arg, c, ctl_arg_integer),
CTL_ARG_PARSER_STRUCT(struct complex_arg, d, ctl_arg_boolean),
CTL_ARG_PARSER_END
}
};
static int
CTL_READ_HANDLER(test_ro)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_PROGRAMMATIC);
int *arg_ro = arg;
*arg_ro = 0;
return 0;
}
static int
CTL_READ_HANDLER(index_value)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_PROGRAMMATIC);
long *index_value = arg;
struct ctl_index *idx = SLIST_FIRST(indexes);
UT_ASSERT(strcmp(idx->name, "test_index") == 0);
*index_value = idx->value;
return 0;
}
static int
CTL_RUNNABLE_HANDLER(test_runnable)(void *ctx,
enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_PROGRAMMATIC);
int *arg_runnable = arg;
*arg_runnable = 0;
return 0;
}
static const struct ctl_node CTL_NODE(test_index)[] = {
CTL_LEAF_RO(index_value),
CTL_NODE_END
};
static const struct ctl_node CTL_NODE(debug)[] = {
CTL_LEAF_RO(test_ro),
CTL_LEAF_WO(test_wo),
CTL_LEAF_RUNNABLE(test_runnable),
CTL_LEAF_RW(test_rw),
CTL_INDEXED(test_index),
CTL_LEAF_WO(test_config),
CTL_LEAF_WO(test_config_complex_arg),
CTL_NODE_END
};
static int
CTL_WRITE_HANDLER(gtest_config)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_CONFIG_INPUT);
char *config_value = arg;
UT_ASSERTeq(strcmp(config_value, TEST_CONFIG_VALUE), 0);
test_config_written = 1;
return 0;
}
static struct ctl_argument CTL_ARG(gtest_config) = CTL_ARG_STRING(8);
static int
CTL_READ_HANDLER(gtest_ro)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
UT_ASSERTeq(source, CTL_QUERY_PROGRAMMATIC);
int *arg_ro = arg;
*arg_ro = 0;
return 0;
}
static const struct ctl_node CTL_NODE(global_debug)[] = {
CTL_LEAF_RO(gtest_ro),
CTL_LEAF_WO(gtest_config),
CTL_NODE_END
};
static int
util_ctl_get(struct pool *pop, const char *name, void *arg)
{
LOG(3, "pop %p name %s arg %p", pop, name, arg);
return ctl_query(pop ? pop->ctl : NULL, pop,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ, arg);
}
static int
util_ctl_set(struct pool *pop, const char *name, void *arg)
{
LOG(3, "pop %p name %s arg %p", pop, name, arg);
return ctl_query(pop ? pop->ctl : NULL, pop,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE, arg);
}
static int
util_ctl_exec(struct pool *pop, const char *name, void *arg)
{
LOG(3, "pop %p name %s arg %p", pop, name, arg);
return ctl_query(pop ? pop->ctl : NULL, pop,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_RUNNABLE, arg);
}
static void
test_ctl_parser(struct pool *pop)
{
errno = 0;
int ret;
ret = util_ctl_get(pop, NULL, NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "a.b.c.d", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, ".", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "..", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "1.2.3.4", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.1.", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.1.invalid", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
/* test methods set read to 0 and write to 1 if successful */
int arg_read = 1;
int arg_write = 0;
errno = 0;
/* correct name, wrong args */
ret = util_ctl_get(pop, "debug.test_rw", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_set(pop, "debug.test_rw", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.test_wo", &arg_read);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.test_wo", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_set(pop, "debug.test_ro", &arg_write);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_set(pop, "debug.test_ro", NULL);
UT_ASSERTne(ret, 0);
UT_ASSERTne(errno, 0);
errno = 0;
ret = util_ctl_get(pop, "debug.test_rw", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
UT_ASSERTeq(arg_write, 0);
UT_ASSERTeq(errno, 0);
ret = util_ctl_set(pop, "debug.test_rw", &arg_write);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
UT_ASSERTeq(arg_write, 1);
arg_read = 1;
arg_write = 0;
ret = util_ctl_get(pop, "debug.test_ro", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
UT_ASSERTeq(arg_write, 0);
arg_read = 1;
arg_write = 0;
ret = util_ctl_set(pop, "debug.test_wo", &arg_write);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 1);
UT_ASSERTeq(arg_write, 1);
long index_value = 0;
ret = util_ctl_get(pop, "debug.5.index_value", &index_value);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(index_value, 5);
ret = util_ctl_get(pop, "debug.10.index_value", &index_value);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(index_value, 10);
arg_read = 1;
arg_write = 1;
int arg_runnable = 1;
ret = util_ctl_exec(pop, "debug.test_runnable", &arg_runnable);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 1);
UT_ASSERTeq(arg_write, 1);
UT_ASSERTeq(arg_runnable, 0);
}
static void
test_string_config(struct pool *pop)
{
UT_ASSERTne(pop, NULL);
int ret;
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop, "");
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop, ";;");
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop, ";=;");
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop, "=");
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop,
"debug.test_wo=");
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop, "=b");
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop,
"debug.test_wo=111=222");
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(test_config_written, 0);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop,
"debug.test_wo=333;debug.test_rw=444;");
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(test_config_written, 2);
test_config_written = 0;
ret = ctl_load_config_from_string(pop->ctl, pop,
"debug.test_config="TEST_CONFIG_VALUE";");
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(test_config_written, 1);
}
static void
config_file_create(const char *buf)
{
/* the test script will take care of removing this file for us */
FILE *f = os_fopen(testconfig_path, "w+");
fwrite(buf, sizeof(char), strlen(buf), f);
fclose(f);
}
static void
create_and_test_file_config(struct pool *pop, const char *buf, int ret,
int result)
{
config_file_create(buf);
test_config_written = 0;
int r = ctl_load_config_from_file(pop ? pop->ctl : NULL,
pop, testconfig_path);
UT_ASSERTeq(r, ret);
UT_ASSERTeq(test_config_written, result);
}
static void
test_too_large_file(struct pool *pop)
{
char *too_large_buf = calloc(1, 1 << 21);
UT_ASSERTne(too_large_buf, NULL);
memset(too_large_buf, 0xc, (1 << 21) - 1);
config_file_create(too_large_buf);
int ret = ctl_load_config_from_file(pop->ctl, pop,
testconfig_path);
UT_ASSERTne(ret, 0);
free(too_large_buf);
}
static void
test_file_config(struct pool *pop)
{
create_and_test_file_config(pop,
"debug.test_config="TEST_CONFIG_VALUE";", 0, 1);
create_and_test_file_config(pop,
"debug.test_config="TEST_CONFIG_VALUE";"
"debug.test_config="TEST_CONFIG_VALUE";", 0, 2);
create_and_test_file_config(pop,
"#this is a comment\n"
"debug.test_config="TEST_CONFIG_VALUE";", 0, 1);
create_and_test_file_config(pop,
"debug.#this is a comment\n"
"test_config#this is a comment\n"
"="TEST_CONFIG_VALUE";", 0, 1);
create_and_test_file_config(pop,
"debug.test_config="TEST_CONFIG_VALUE";#this is a comment",
0, 1);
create_and_test_file_config(pop,
"\n\n\ndebug\n.\ntest\t_\tconfig="TEST_CONFIG_VALUE";\n", 0, 1);
create_and_test_file_config(pop,
" d e b u g . t e s t _ c o n f i g = "TEST_CONFIG_VALUE";",
0, 1);
create_and_test_file_config(pop,
"#debug.test_config="TEST_CONFIG_VALUE";", 0, 0);
create_and_test_file_config(pop,
"debug.#this is a comment\n"
"test_config#this is a not properly terminated comment"
"="TEST_CONFIG_VALUE";", -1, 0);
create_and_test_file_config(pop,
"invalid", -1, 0);
create_and_test_file_config(pop,
"", 0, 0);
create_and_test_file_config(pop,
"debug.test_config_complex_arg=;", -1, 0);
create_and_test_file_config(pop,
"debug.test_config_complex_arg=1,2,3;", -1, 0);
create_and_test_file_config(pop,
"debug.test_config_complex_arg=12345,abcd,,1;", -1, 0);
create_and_test_file_config(pop,
"debug.test_config_complex_arg=12345,abcd,3147483647,1;", 0, 1);
create_and_test_file_config(NULL,
"global_debug.gtest_config="TEST_CONFIG_VALUE";", 0, 1);
create_and_test_file_config(NULL, "private.missing.query=1;"
"global_debug.gtest_config="TEST_CONFIG_VALUE";", 0, 1);
test_too_large_file(pop);
int ret = ctl_load_config_from_file(pop->ctl,
pop, "does_not_exist");
UT_ASSERTne(ret, 0);
}
static void
test_ctl_global_namespace(struct pool *pop)
{
int arg_read = 1;
int ret = util_ctl_get(pop, "global_debug.gtest_ro", &arg_read);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(arg_read, 0);
}
static void
test_ctl_arg_parsers()
{
char *input;
input = "";
int boolean = -1;
int ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(boolean, -1);
input = "abcdefgh";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(boolean, -1);
input = "-999";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(boolean, -1);
input = "N";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 0);
input = "0";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 0);
input = "yes";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 1);
input = "Yes";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 1);
input = "1";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 1);
input = "1234";
boolean = -1;
ret = ctl_arg_boolean(input, &boolean, sizeof(int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(boolean, 1);
input = "";
int small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "abcd";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "12345678901234567890";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "-12345678901234567890";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "2147483648"; /* INT_MAX + 1 */
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "-2147483649"; /* INT_MIN - 2 */
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(small_int, -1);
input = "0";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(small_int, 0);
input = "500";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(small_int, 500);
input = "-500";
small_int = -1;
ret = ctl_arg_integer(input, &small_int, sizeof(small_int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(small_int, -500);
input = "";
long long ll_int = -1;
ret = ctl_arg_integer(input, &ll_int, sizeof(ll_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(ll_int, -1);
input = "12345678901234567890";
ll_int = -1;
ret = ctl_arg_integer(input, &ll_int, sizeof(ll_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(ll_int, -1);
input = "-12345678901234567890";
ll_int = -1;
ret = ctl_arg_integer(input, &ll_int, sizeof(ll_int));
UT_ASSERTeq(ret, -1);
UT_ASSERTeq(ll_int, -1);
input = "2147483648";
ll_int = -1;
ret = ctl_arg_integer(input, &ll_int, sizeof(ll_int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ll_int, 2147483648);
input = "-2147483649";
ll_int = -1;
ret = ctl_arg_integer(input, &ll_int, sizeof(ll_int));
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ll_int, -2147483649LL);
input = "";
char string[1000] = {0};
ret = ctl_arg_string(input, string, 0);
UT_ASSERTeq(ret, -1);
input = "abcd";
ret = ctl_arg_string(input, string, 3);
UT_ASSERTeq(ret, -1);
input = "abcdefg";
ret = ctl_arg_string(input, string, 3);
UT_ASSERTeq(ret, -1);
input = "abcd";
ret = ctl_arg_string(input, string, 4);
UT_ASSERTeq(ret, -1);
input = "abc";
ret = ctl_arg_string(input, string, 4);
UT_ASSERTeq(ret, 0);
UT_ASSERT(strcmp(input, string) == 0);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_ctl");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc != 2)
UT_FATAL("usage: %s testconfig", argv[0]);
testconfig_path = argv[1];
CTL_REGISTER_MODULE(NULL, global_debug);
test_ctl_global_namespace(NULL);
struct pool *pop = malloc(sizeof(pop));
pop->ctl = ctl_new();
test_ctl_global_namespace(NULL);
CTL_REGISTER_MODULE(pop->ctl, debug);
test_ctl_global_namespace(pop);
test_ctl_parser(pop);
test_string_config(pop);
test_file_config(pop);
test_ctl_arg_parsers();
ctl_delete(pop->ctl);
free(pop);
common_fini();
DONE(NULL);
}
| 18,586 | 23.651194 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/util_is_absolute/util_is_absolute.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_is_absolute.c -- unit test for testing if path is absolute
*
* usage: util_is_absolute path [path ...]
*/
#include "unittest.h"
#include "file.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "util_is_absolute");
for (int i = 1; i < argc; i++) {
UT_OUT("\"%s\" - %d", argv[i],
util_is_absolute_path(argv[i]));
}
DONE(NULL);
}
| 1,958 | 35.277778 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush_win/mocks_windows.h | /*
* 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_windows.h -- redefinitions of EnumSystemFirmwareTables and
* GetSystemFirmwareTable
*
* 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_has_auto_flush_win test.
* It would replace default implementation with mocked functions defined
* in mocks_windows.c
*
* This WRAP_REAL define could be also passed as preprocessor definition.
*/
#include <windows.h>
#ifndef WRAP_REAL
#define EnumSystemFirmwareTables __wrap_EnumSystemFirmwareTables
#define GetSystemFirmwareTable __wrap_GetSystemFirmwareTable
UINT
__wrap_EnumSystemFirmwareTables(DWORD FirmwareTableProviderSignature,
PVOID pFirmwareTableEnumBuffer, DWORD BufferSize);
UINT
__wrap_GetSystemFirmwareTable(DWORD FirmwareTableProviderSignature,
DWORD FirmwareTableID, PVOID pFirmwareTableBuffer, DWORD BufferSize);
#endif
| 2,503 | 42.172414 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush_win/pmem_has_auto_flush_win.h | /*
* 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_win.h -- header file for windows mocks
* for pmem_has_auto_flush_win
*/
#ifndef PMDK_HAS_AUTO_FLUSH_WIN_H
#define PMDK_HAS_AUTO_FLUSH_WIN_H 1
extern size_t Is_nfit;
extern size_t Pc_type;
extern size_t Pc_capabilities;
#endif
| 1,853 | 40.2 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush_win/mocks_windows.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_windows.c -- mocked functions used in os_auto_flush_windows.c
*/
#include "pmem.h"
#include "util.h"
#include "unittest.h"
#include "set.h"
#include "pmemcommon.h"
#include "os_auto_flush_windows.h"
#include "pmem_has_auto_flush_win.h"
#include <errno.h>
extern size_t Is_nfit;
extern size_t Pc_type;
extern size_t Pc_capabilities;
FUNC_MOCK_DLLIMPORT(EnumSystemFirmwareTables, UINT,
DWORD FirmwareTableProviderSignature,
PVOID pFirmwareTableBuffer,
DWORD BufferSize)
FUNC_MOCK_RUN_DEFAULT {
if (FirmwareTableProviderSignature != ACPI_SIGNATURE)
return _FUNC_REAL(EnumSystemFirmwareTables)
(FirmwareTableProviderSignature,
pFirmwareTableBuffer, BufferSize);
if (Is_nfit == 1 && pFirmwareTableBuffer != NULL &&
BufferSize != 0) {
UT_OUT("Mock NFIT available");
strncpy(pFirmwareTableBuffer, NFIT_STR_SIGNATURE, BufferSize);
}
return NFIT_SIGNATURE_LEN + sizeof(struct nfit_header);
}
FUNC_MOCK_END
FUNC_MOCK_DLLIMPORT(GetSystemFirmwareTable, UINT,
DWORD FirmwareTableProviderSignature,
DWORD FirmwareTableID,
PVOID pFirmwareTableBuffer,
DWORD BufferSize)
FUNC_MOCK_RUN_DEFAULT {
if (FirmwareTableProviderSignature != ACPI_SIGNATURE ||
FirmwareTableID != NFIT_REV_SIGNATURE)
return _FUNC_REAL(GetSystemFirmwareTable)
(FirmwareTableProviderSignature, FirmwareTableID,
pFirmwareTableBuffer, BufferSize);
if (pFirmwareTableBuffer == NULL && BufferSize == 0) {
UT_OUT("GetSystemFirmwareTable mock");
return sizeof(struct platform_capabilities) +
sizeof(struct nfit_header);
}
struct nfit_header nfit;
struct platform_capabilities pc;
/* fill nfit */
char sig[NFIT_SIGNATURE_LEN] = NFIT_STR_SIGNATURE;
strncpy(nfit.signature, sig, NFIT_SIGNATURE_LEN);
nfit.length = sizeof(nfit);
memcpy(pFirmwareTableBuffer, &nfit, nfit.length);
/* fill platform_capabilities */
pc.length = sizeof(pc);
/* [...] 0000 0011 - proper capabilities bits combination */
pc.capabilities = (uint32_t)Pc_capabilities;
pc.type = (uint16_t)Pc_type;
memcpy((char *)pFirmwareTableBuffer + nfit.length, &pc, pc.length);
return BufferSize;
}
FUNC_MOCK_END
/*
* libpmem_init -- load-time initialization for libpmem
* Called automatically by the run-time loader.
*/
CONSTRUCTOR(libpmem_init)
void
libpmem_init(void)
{
pmem_init();
}
| 3,887 | 32.808696 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_has_auto_flush_win/pmem_has_auto_flush_win.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_win.c -- unit test for pmem_has_auto_flush_win()
*
* usage: pmem_has_auto_flush_win <option>
* options:
* n - is nfit available or not (y or n)
* type: number of platform capabilities structure
* capabilities: platform capabilities bits
*/
#include <stdbool.h>
#include <errno.h>
#include "unittest.h"
#include "pmemcommon.h"
#include "set.h"
#include "mocks_windows.h"
#include "pmem_has_auto_flush_win.h"
#include "util.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
size_t Is_nfit = 0;
size_t Pc_type = 0;
size_t Pc_capabilities = 3;
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_has_auto_flush_win");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 4)
UT_FATAL("usage: pmem_has_auto_flush_win "
"<option> <type> <capabilities>",
argv[0]);
Pc_type = (size_t)atoi(argv[2]);
Pc_capabilities = (size_t)atoi(argv[3]);
Is_nfit = argv[1][0] == 'y';
int eADR = pmem_has_auto_flush();
UT_OUT("pmem_has_auto_flush ret: %d", eADR);
common_fini();
DONE(NULL);
}
| 2,782 | 32.130952 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_bucket/obj_bucket.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_bucket.c -- unit test for bucket
*/
#include "bucket.h"
#include "container_ravl.h"
#include "util.h"
#include "unittest.h"
#define TEST_CHUNK_ID 10
#define TEST_ZONE_ID 20
#define TEST_SIZE_IDX 30
#define TEST_BLOCK_OFF 40
struct container_test {
struct block_container super;
};
static const struct memory_block *inserted_memblock;
static int
container_test_insert(struct block_container *c,
const struct memory_block *m)
{
inserted_memblock = m;
return 0;
}
static int
container_test_get_rm_bestfit(struct block_container *c,
struct memory_block *m)
{
if (inserted_memblock == NULL)
return ENOMEM;
*m = *inserted_memblock;
inserted_memblock = NULL;
return 0;
}
static int
container_test_get_rm_exact(struct block_container *c,
const struct memory_block *m)
{
if (inserted_memblock == NULL)
return ENOMEM;
if (inserted_memblock->chunk_id == m->chunk_id) {
inserted_memblock = NULL;
return 0;
}
return ENOMEM;
}
static void
container_test_destroy(struct block_container *c)
{
FREE(c);
}
static struct block_container_ops container_test_ops = {
.insert = container_test_insert,
.get_rm_exact = container_test_get_rm_exact,
.get_rm_bestfit = container_test_get_rm_bestfit,
.get_exact = NULL,
.is_empty = NULL,
.rm_all = NULL,
.destroy = container_test_destroy,
};
static struct block_container *
container_new_test(void)
{
struct container_test *c = MALLOC(sizeof(struct container_test));
c->super.c_ops = &container_test_ops;
return &c->super;
}
static void *
mock_get_real_data(const struct memory_block *m)
{
return NULL;
}
static size_t
mock_get_real_size(const struct memory_block *m)
{
return 0;
}
static const struct memory_block_ops mock_ops = {
.block_size = NULL,
.prep_hdr = NULL,
.get_lock = NULL,
.get_state = NULL,
.get_user_data = NULL,
.get_real_data = mock_get_real_data,
.get_user_size = NULL,
.get_real_size = mock_get_real_size,
.write_header = NULL,
.reinit_header = NULL,
.get_extra = NULL,
.get_flags = NULL,
};
static void
test_bucket_insert_get(void)
{
struct bucket *b = bucket_new(container_new_test(), NULL);
UT_ASSERT(b != NULL);
struct memory_block m = {TEST_CHUNK_ID, TEST_ZONE_ID,
TEST_SIZE_IDX, TEST_BLOCK_OFF};
m.m_ops = &mock_ops;
/* get from empty */
UT_ASSERT(b->c_ops->get_rm_bestfit(b->container, &m) != 0);
UT_ASSERT(bucket_insert_block(b, &m) == 0);
UT_ASSERT(b->c_ops->get_rm_bestfit(b->container, &m) == 0);
UT_ASSERT(m.chunk_id == TEST_CHUNK_ID);
UT_ASSERT(m.zone_id == TEST_ZONE_ID);
UT_ASSERT(m.size_idx == TEST_SIZE_IDX);
UT_ASSERT(m.block_off == TEST_BLOCK_OFF);
bucket_delete(b);
}
static void
test_bucket_remove(void)
{
struct bucket *b = bucket_new(container_new_test(), NULL);
UT_ASSERT(b != NULL);
struct memory_block m = {TEST_CHUNK_ID, TEST_ZONE_ID,
TEST_SIZE_IDX, TEST_BLOCK_OFF};
m.m_ops = &mock_ops;
UT_ASSERT(bucket_insert_block(b, &m) == 0);
UT_ASSERT(b->c_ops->get_rm_exact(b->container, &m) == 0);
bucket_delete(b);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_bucket");
test_bucket_insert_get();
test_bucket_remove();
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
| 4,892 | 23.465 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pmalloc_oom_mt/obj_pmalloc_oom_mt.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_pmalloc_oom_mt.c -- build multithreaded out of memory test
*
*/
#include <stddef.h>
#include "unittest.h"
#define TEST_ALLOC_SIZE (32 * 1024)
#define LAYOUT_NAME "oom_mt"
static int allocated;
static PMEMobjpool *pop;
static void *
oom_worker(void *arg)
{
allocated = 0;
while (pmemobj_alloc(pop, NULL, TEST_ALLOC_SIZE, 0, NULL, NULL) == 0)
allocated++;
PMEMoid iter, iter2;
POBJ_FOREACH_SAFE(pop, iter, iter2)
pmemobj_free(&iter);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_oom_mt");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
os_thread_t t;
os_thread_create(&t, NULL, oom_worker, NULL);
os_thread_join(&t, NULL);
int first_thread_allocated = allocated;
os_thread_create(&t, NULL, oom_worker, NULL);
os_thread_join(&t, NULL);
UT_ASSERTeq(first_thread_allocated, allocated);
pmemobj_close(pop);
DONE(NULL);
}
| 2,680 | 28.461538 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_realloc/vmem_realloc.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_realloc -- unit test for vmem_realloc
*
* usage: vmem_realloc [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_realloc");
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(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");
}
int *test = vmem_realloc(vmp, NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = test_value;
UT_ASSERTeq(test[0], test_value);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
test = vmem_realloc(vmp, test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], test_value);
test[1] = test_value;
test[9] = test_value;
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}
| 2,932 | 28.928571 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_malloc_hooks/vmmalloc_malloc_hooks.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.
*/
/*
* vmmalloc_malloc_hooks.c -- unit test for libvmmalloc malloc hooks
*
* usage: vmmalloc_malloc_hooks
*/
#include <stdlib.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
static void *(*old_malloc_hook) (size_t, const void *);
static void *(*old_realloc_hook) (void *, size_t, const void *);
static void *(*old_memalign_hook) (size_t, size_t, const void *);
static void (*old_free_hook) (void *, const void *);
static int malloc_cnt = 0;
static int realloc_cnt = 0;
static int memalign_cnt = 0;
static int free_cnt = 0;
static void *
hook_malloc(size_t size, const void *caller)
{
void *p;
malloc_cnt++;
__malloc_hook = old_malloc_hook;
p = malloc(size);
old_malloc_hook = __malloc_hook; /* might changed */
__malloc_hook = hook_malloc;
return p;
}
static void *
hook_realloc(void *ptr, size_t size, const void *caller)
{
void *p;
realloc_cnt++;
__realloc_hook = old_realloc_hook;
p = realloc(ptr, size);
old_realloc_hook = __realloc_hook; /* might changed */
__realloc_hook = hook_realloc;
return p;
}
static void *
hook_memalign(size_t alignment, size_t size, const void *caller)
{
void *p;
memalign_cnt++;
__memalign_hook = old_memalign_hook;
p = memalign(alignment, size);
old_memalign_hook = __memalign_hook; /* might changed */
__memalign_hook = hook_memalign;
return p;
}
static void
hook_free(void *ptr, const void *caller)
{
free_cnt++;
__free_hook = old_free_hook;
free(ptr);
old_free_hook = __free_hook; /* might changed */
__free_hook = hook_free;
}
static void
hook_init(void)
{
UT_OUT("installing hooks");
old_malloc_hook = __malloc_hook;
old_realloc_hook = __realloc_hook;
old_memalign_hook = __memalign_hook;
old_free_hook = __free_hook;
__malloc_hook = hook_malloc;
__realloc_hook = hook_realloc;
__memalign_hook = hook_memalign;
__free_hook = hook_free;
}
int
main(int argc, char *argv[])
{
void *ptr;
START(argc, argv, "vmmalloc_malloc_hooks");
hook_init();
ptr = malloc(4321);
free(ptr);
ptr = calloc(1, 4321);
free(ptr);
ptr = malloc(8);
ptr = realloc(ptr, 4321);
free(ptr);
ptr = memalign(16, 4321);
free(ptr);
UT_OUT("malloc %d realloc %d memalign %d free %d",
malloc_cnt, realloc_cnt, memalign_cnt, free_cnt);
DONE(NULL);
}
| 3,837 | 26.028169 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_valloc/vmmalloc_valloc.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.
*/
/*
* vmmalloc_valloc.c -- unit test for libvmmalloc valloc/pvalloc
*
* usage: vmmalloc_valloc [v|p]
*/
#include <sys/param.h>
#include <libvmmalloc.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
static void *(*Valloc)(size_t size);
int
main(int argc, char *argv[])
{
const int test_value = 123456;
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
size_t min_size = sizeof(int);
size_t max_size = 4 * pagesize;
size_t size;
int *ptr;
START(argc, argv, "vmmalloc_valloc");
if (argc != 2)
UT_FATAL("usage: %s [v|p]", argv[0]);
switch (argv[1][0]) {
case 'v':
UT_OUT("testing valloc");
Valloc = valloc;
break;
case 'p':
UT_OUT("testing pvalloc");
Valloc = pvalloc;
break;
default:
UT_FATAL("usage: %s [v|p]", argv[0]);
}
for (size = min_size; size < max_size; size *= 2) {
ptr = Valloc(size);
/* at least one allocation must succeed */
UT_ASSERT(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) & (pagesize - 1), 0);
if (Valloc == pvalloc) {
/* check for correct allocation size */
size_t usable = malloc_usable_size(ptr);
UT_ASSERTeq(usable, roundup(size, pagesize));
}
free(ptr);
}
DONE(NULL);
}
| 2,930 | 28.31 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/log_walker/log_walker.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.
*/
/*
* log_walker.c -- unit test to verify pool's write-protection in debug mode
*
* usage: log_walker file
*
*/
#include <sys/param.h>
#include "unittest.h"
/*
* do_append -- call pmemlog_append() & print result
*/
static void
do_append(PMEMlogpool *plp)
{
const char *str[6] = {
"1st append string\n",
"2nd append string\n",
"3rd append string\n",
"4th append string\n",
"5th append string\n",
"6th append string\n"
};
for (int i = 0; i < 6; ++i) {
int rv = pmemlog_append(plp, str[i], strlen(str[i]));
switch (rv) {
case 0:
UT_OUT("append str[%i] %s", i, str[i]);
break;
case -1:
UT_OUT("!append str[%i] %s", i, str[i]);
break;
default:
UT_OUT("!append: wrong return value");
break;
}
}
}
/*
* try_to_store -- try to store to the buffer 'buf'
*
* It is a walker function for pmemlog_walk
*/
static int
try_to_store(const void *buf, size_t len, void *arg)
{
memset((void *)buf, 0, len);
return 0;
}
/*
* do_walk -- call pmemlog_walk() & print result
*/
static void
do_walk(PMEMlogpool *plp)
{
pmemlog_walk(plp, 0, try_to_store, NULL);
UT_OUT("walk all at once");
}
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[])
{
PMEMlogpool *plp;
START(argc, argv, "log_walker");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
int fd = OPEN(path, O_RDWR);
/* pre-allocate 2MB of persistent memory */
POSIX_FALLOCATE(fd, (os_off_t)0, (size_t)(2 * 1024 * 1024));
CLOSE(fd);
if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemlog_create: %s", path);
/* append some data */
do_append(plp);
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
if (!ut_sigsetjmp(Jmp)) {
do_walk(plp);
}
pmemlog_close(plp);
DONE(NULL);
}
| 3,640 | 23.436242 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_tx_alloc/obj_tx_alloc.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_tx_alloc.c -- unit test for pmemobj_tx_alloc and pmemobj_tx_zalloc
*/
#include <assert.h>
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "libpmemobj.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "tx_alloc"
#define TEST_VALUE_1 1
#define TEST_VALUE_2 2
#define OBJ_SIZE (200 * 1024)
enum type_number {
TYPE_NO_TX,
TYPE_COMMIT,
TYPE_ABORT,
TYPE_ZEROED_COMMIT,
TYPE_ZEROED_ABORT,
TYPE_XCOMMIT,
TYPE_XABORT,
TYPE_XZEROED_COMMIT,
TYPE_XZEROED_ABORT,
TYPE_XNOFLUSHED_COMMIT,
TYPE_COMMIT_NESTED1,
TYPE_COMMIT_NESTED2,
TYPE_ABORT_NESTED1,
TYPE_ABORT_NESTED2,
TYPE_ABORT_AFTER_NESTED1,
TYPE_ABORT_AFTER_NESTED2,
TYPE_OOM,
};
TOID_DECLARE(struct object, TYPE_OOM);
struct object {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
/*
* do_tx_alloc_oom -- allocates objects until OOM
*/
static void
do_tx_alloc_oom(PMEMobjpool *pop)
{
int do_alloc = 1;
size_t alloc_cnt = 0;
do {
TX_BEGIN(pop) {
TOID(struct object) obj = TX_NEW(struct object);
D_RW(obj)->value = alloc_cnt;
} TX_ONCOMMIT {
alloc_cnt++;
} TX_ONABORT {
do_alloc = 0;
} TX_END
} while (do_alloc);
size_t bitmap_size = howmany(alloc_cnt, 8);
char *bitmap = (char *)MALLOC(bitmap_size);
pmemobj_memset_persist(pop, bitmap, 0, bitmap_size);
size_t obj_cnt = 0;
TOID(struct object) i;
POBJ_FOREACH_TYPE(pop, i) {
UT_ASSERT(D_RO(i)->value < alloc_cnt);
UT_ASSERT(!isset(bitmap, D_RO(i)->value));
setbit(bitmap, D_RO(i)->value);
obj_cnt++;
}
FREE(bitmap);
UT_ASSERTeq(obj_cnt, alloc_cnt);
TOID(struct object) o = POBJ_FIRST(pop, struct object);
while (!TOID_IS_NULL(o)) {
TOID(struct object) next = POBJ_NEXT(o);
POBJ_FREE(&o);
o = next;
}
}
/*
* do_tx_alloc_abort_after_nested -- aborts transaction after allocation
* in nested transaction
*/
static void
do_tx_alloc_abort_after_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT_AFTER_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_ABORT_AFTER_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj1, OID_NULL);
TOID_ASSIGN(obj2, OID_NULL);
} TX_END
TOID(struct object) first;
/* check the obj1 object */
UT_ASSERT(TOID_IS_NULL(obj1));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED1);
UT_ASSERT(TOID_IS_NULL(first));
/* check the obj2 object */
UT_ASSERT(TOID_IS_NULL(obj2));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED2);
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_abort_nested -- aborts transaction in nested transaction
*/
static void
do_tx_alloc_abort_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_ABORT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj2, OID_NULL);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj1, OID_NULL);
} TX_END
TOID(struct object) first;
/* check the obj1 object */
UT_ASSERT(TOID_IS_NULL(obj1));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED1);
UT_ASSERT(TOID_IS_NULL(first));
/* check the obj2 object */
UT_ASSERT(TOID_IS_NULL(obj2));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED2);
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_commit_nested -- allocates two objects, one in nested transaction
*/
static void
do_tx_alloc_commit_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_COMMIT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_COMMIT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID(struct object) next;
/* check the obj1 object */
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED1));
UT_ASSERT(TOID_EQUALS(first, obj1));
UT_ASSERTeq(D_RO(first)->value, TEST_VALUE_1);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
/* check the obj2 object */
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED2));
UT_ASSERT(TOID_EQUALS(first, obj2));
UT_ASSERTeq(D_RO(first)->value, TEST_VALUE_2);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_alloc_abort -- allocates an object and aborts the transaction
*/
static void
do_tx_alloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_zerolen -- allocates an object of zero size to trigger tx abort
*/
static void
do_tx_alloc_zerolen(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(0, TYPE_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_alloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_commit -- allocates and object
*/
static void
do_tx_alloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(sizeof(struct object),
TYPE_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
next = POBJ_NEXT(first);
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_zalloc_abort -- allocates a zeroed object and aborts the transaction
*/
static void
do_tx_zalloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(sizeof(struct object),
TYPE_ZEROED_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_zerolen -- allocate an object of zero size to trigger tx abort
*/
static void
do_tx_zalloc_zerolen(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(0, TYPE_ZEROED_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_zalloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_ZEROED_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_commit -- allocates zeroed object
*/
static void
do_tx_zalloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(sizeof(struct object),
TYPE_ZEROED_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
next = POBJ_NEXT(first);
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_xalloc_abort -- allocates a zeroed object and aborts the transaction
*/
static void
do_tx_xalloc_abort(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XABORT, 0));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XZEROED_ABORT, POBJ_XALLOC_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_zerolen -- allocate an object of zero size to trigger tx abort
*/
static void
do_tx_xalloc_zerolen(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(0, TYPE_XABORT, 0));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(0, TYPE_XZEROED_ABORT,
POBJ_XALLOC_ZERO));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_xalloc_huge(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_XABORT, 0));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_XZEROED_ABORT, POBJ_XALLOC_ZERO));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_commit -- allocates zeroed object
*/
static void
do_tx_xalloc_commit(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XCOMMIT, 0));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XCOMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XZEROED_COMMIT, POBJ_XALLOC_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_xalloc_noflush -- allocates zeroed object
*/
static void
do_tx_xalloc_noflush(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XNOFLUSHED_COMMIT, POBJ_XALLOC_NO_FLUSH));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->data[OBJ_SIZE - sizeof(size_t) - 1] = TEST_VALUE_1;
/* let pmemcheck find we didn't flush it */
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->data[OBJ_SIZE - sizeof(size_t) - 1],
TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XNOFLUSHED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->data[OBJ_SIZE - sizeof(size_t) - 1],
D_RO(obj)->data[OBJ_SIZE - sizeof(size_t) - 1]);
TOID(struct object) next;
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_root -- retrieve root inside of transaction
*/
static void
do_tx_root(PMEMobjpool *pop)
{
size_t root_size = 24;
TX_BEGIN(pop) {
PMEMoid root = pmemobj_root(pop, root_size);
UT_ASSERT(!OID_IS_NULL(root));
UT_ASSERT(util_is_zeroed(pmemobj_direct(root),
root_size));
UT_ASSERTeq(root_size, pmemobj_root_size(pop));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
/*
* do_tx_alloc_many -- allocates many objects inside of a single transaction
*/
static void
do_tx_alloc_many(PMEMobjpool *pop)
{
#define TX_ALLOC_COUNT 70 /* bigger than max reservations */
PMEMoid oid, oid2;
POBJ_FOREACH_SAFE(pop, oid, oid2) {
pmemobj_free(&oid);
}
TOID(struct object) first;
TOID_ASSIGN(first, pmemobj_first(pop));
UT_ASSERT(TOID_IS_NULL(first));
PMEMoid oids[TX_ALLOC_COUNT];
TX_BEGIN(pop) {
for (int i = 0; i < TX_ALLOC_COUNT; ++i) {
oids[i] = pmemobj_tx_alloc(1, 0);
UT_ASSERT(!OID_IS_NULL(oids[i]));
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
/* empty tx to make sure there's no leftover state */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
for (int i = 0; i < TX_ALLOC_COUNT; ++i) {
pmemobj_tx_free(oids[i]);
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(first, pmemobj_first(pop));
UT_ASSERT(TOID_IS_NULL(first));
#undef TX_ALLOC_COUNT
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_alloc");
util_init();
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_root(pop);
VALGRIND_WRITE_STATS;
/* alloc */
do_tx_alloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_huge(pop);
VALGRIND_WRITE_STATS;
/* zalloc */
do_tx_zalloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_huge(pop);
VALGRIND_WRITE_STATS;
/* xalloc */
do_tx_xalloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_huge(pop);
VALGRIND_WRITE_STATS;
/* alloc */
do_tx_alloc_commit_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort_after_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_oom(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_many(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_noflush(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 20,174 | 22.651817 | 80 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pool_lock/obj_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.
*/
/*
* obj_pool_lock.c -- unit test which checks whether it's possible to
* simultaneously open the same obj pool
*/
#include "unittest.h"
#define LAYOUT "layout"
static void
test_reopen(const char *path)
{
PMEMobjpool *pop1 = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop1)
UT_FATAL("!create");
PMEMobjpool *pop2 = pmemobj_open(path, LAYOUT);
if (pop2)
UT_FATAL("pmemobj_open should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open failed but for unexpected reason");
pmemobj_close(pop1);
pop2 = pmemobj_open(path, LAYOUT);
if (!pop2)
UT_FATAL("pmemobj_open should succeed after close");
pmemobj_close(pop2);
UNLINK(path);
}
#ifndef _WIN32
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
pid_t pid = fork();
PMEMobjpool *pop;
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);
pop = pmemobj_open(path, LAYOUT);
if (pop)
UT_FATAL("pmemobj_open after fork should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open after fork failed but for "
"unexpected reason");
exit(0);
}
pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!create");
int status;
if (waitpid(pid, &status, 0) < 0)
UT_FATAL("!waitpid failed");
if (!WIFEXITED(status))
UT_FATAL("child process failed");
pmemobj_close(pop);
UNLINK(path);
}
#else
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
PMEMobjpool *pop;
if (sleep > 0)
return;
char *path = argv[1];
/* before starting the 2nd process, create a pool */
pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop)
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 == -1)
UT_FATAL("Create new process failed error: %d", GetLastError());
pmemobj_close(pop);
}
#endif
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_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) {
PMEMobjpool *pop;
/* 2nd arg used by windows for 2 process test */
pop = pmemobj_open(argv[1], LAYOUT);
if (pop)
UT_FATAL("pmemobj_open after create process should "
"not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open after create process failed "
"but for unexpected reason");
}
DONE(NULL);
}
| 4,478 | 25.040698 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_pool/blk_pool.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.
*/
/*
* blk_pool.c -- unit test for pmemblk_create() and pmemblk_open()
*
* usage: blk_pool op path bsize [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 char *path, size_t bsize, size_t poolsize, unsigned mode)
{
PMEMblkpool *pbp = pmemblk_create(path, bsize, poolsize, mode);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_create", path);
else {
os_stat_t stbuf;
STAT(path, &stbuf);
UT_OUT("%s: file size %zu usable blocks %zu mode 0%o",
path, stbuf.st_size,
pmemblk_nblock(pbp),
stbuf.st_mode & 0777);
pmemblk_close(pbp);
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_ASSERTeq(pmemblk_check(path, bsize * 2), -1);
}
}
static void
pool_open(const char *path, size_t bsize)
{
PMEMblkpool *pbp = pmemblk_open(path, bsize);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_open", path);
else {
UT_OUT("%s: pmemblk_open: Success", path);
pmemblk_close(pbp);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_pool");
if (argc < 4)
UT_FATAL("usage: %s op path bsize [poolsize mode]", argv[0]);
size_t bsize = strtoul(argv[3], NULL, 0);
size_t poolsize;
unsigned mode;
switch (argv[1][0]) {
case 'c':
poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
mode = strtoul(argv[5], NULL, 8);
pool_create(argv[2], bsize, poolsize, mode);
break;
case 'o':
pool_open(argv[2], bsize);
break;
default:
UT_FATAL("unknown operation");
}
DONE(NULL);
}
| 3,323 | 26.932773 | 75 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_dummy_funcs/vmmalloc_dummy_funcs.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.
*/
/*
* vmmalloc_dummy_funcs.c -- dummy functions for vmmalloc tests
*/
#include "vmmalloc_dummy_funcs.h"
__attribute__((weak))
void *
aligned_alloc(size_t alignment, size_t size)
{
return NULL;
}
#ifdef __FreeBSD__
__attribute__((weak))
void *
memalign(size_t alignment, size_t size)
{
return NULL;
}
__attribute__((weak))
void *
pvalloc(size_t size)
{
return NULL;
}
/* XXX These exist only to allow the tests to link - they are never used */
void (*__free_hook)(void *, const void *);
void *(*__malloc_hook)(size_t size, const void *);
void *(*__memalign_hook)(size_t alignment, size_t size, const void *);
void *(*__realloc_hook)(void *ptr, size_t size, const void *);
#endif
| 2,289 | 33.179104 | 75 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_dummy_funcs/vmmalloc_dummy_funcs.h | /*
* 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.
*/
/*
* vmmalloc_weakfuncs.h -- definitions for vmmalloc tests
*/
#ifndef VMMALLOC_WEAKFUNCS_H
#define VMMALLOC_WEAKFUNCS_H
#include <stddef.h>
#ifndef __FreeBSD__
#include <malloc.h>
#endif
void *aligned_alloc(size_t alignment, size_t size);
#ifdef __FreeBSD__
void *memalign(size_t boundary, size_t size);
void *pvalloc(size_t size);
/* XXX These exist only to allow the tests to compile - they are never used */
extern void (*__free_hook)(void *, const void *);
extern void *(*__malloc_hook)(size_t size, const void *);
extern void *(*__memalign_hook)(size_t alignment, size_t size, const void *);
extern void *(*__realloc_hook)(void *ptr, size_t size, const void *);
#endif
#endif
| 2,292 | 37.864407 | 78 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_memcpy/pmem_memcpy.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_memcpy.c -- unit test for doing a memcpy
*
* usage: pmem_memcpy file destoff srcoff length
*
*/
#include "unittest.h"
#include "util_pmem.h"
#include "file.h"
typedef void *pmem_memcpy_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
static void *
pmem_memcpy_persist_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_persist(pmemdest, src, len);
}
static void *
pmem_memcpy_nodrain_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_nodrain(pmemdest, src, len);
}
/*
* swap_mappings - given to mmapped regions swap them.
*
* Try swapping src and dest by unmapping src, mapping a new dest with
* the original src address as a hint. If successful, unmap original dest.
* Map a new src with the original dest as a hint.
*/
static void
swap_mappings(char **dest, char **src, size_t size, int fd)
{
char *d = *dest;
char *s = *src;
char *td, *ts;
MUNMAP(*src, size);
/* mmap destination using src addr as hint */
td = MMAP(s, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
MUNMAP(*dest, size);
*dest = td;
/* mmap src using original destination addr as a hint */
ts = MMAP(d, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS,
-1, 0);
*src = ts;
}
/*
* do_memcpy: Worker function for memcpy
*
* Always work within the boundary of bytes. Fill in 1/2 of the src
* memory with the pattern we want to write. This allows us to check
* that we did not overwrite anything we were not supposed to in the
* dest. Use the non pmem version of the memset/memcpy commands
* so as not to introduce any possible side affects.
*/
static void
do_memcpy(int fd, char *dest, int dest_off, char *src, int src_off,
size_t bytes, const char *file_name, pmem_memcpy_fn fn, unsigned flags)
{
void *ret;
char *buf = MALLOC(bytes);
enum file_type type = util_fd_get_type(fd);
if (type < 0)
UT_FATAL("cannot check type of file with fd %d", fd);
memset(buf, 0, bytes);
memset(dest, 0, bytes);
memset(src, 0, bytes);
util_persist_auto(type == TYPE_DEVDAX, src, bytes);
memset(src, 0x5A, bytes / 4);
util_persist_auto(type == TYPE_DEVDAX, src, bytes / 4);
memset(src + bytes / 4, 0x46, bytes / 4);
util_persist_auto(type == TYPE_DEVDAX, src + bytes / 4,
bytes / 4);
/* dest == src */
ret = fn(dest + dest_off, dest + dest_off, bytes / 2, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
/* len == 0 */
ret = fn(dest + dest_off, src, 0, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
ret = fn(dest + dest_off, src + src_off, bytes / 2, flags);
UT_ASSERTeq(ret, dest + dest_off);
/* memcmp will validate that what I expect in memory. */
if (memcmp(src + src_off, dest + dest_off, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
/* Now validate the contents of the file */
LSEEK(fd, (os_off_t)dest_off, SEEK_SET);
if (READ(fd, buf, bytes / 2) == bytes / 2) {
if (memcmp(src + src_off, buf, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
}
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,
};
/*
* do_memcpy_variants -- do_memcpy wrapper that tests multiple variants
* of memcpy functions
*/
static void
do_memcpy_variants(int fd, char *dest, int dest_off, char *src, int src_off,
size_t bytes, const char *file_name)
{
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy_persist_wrapper, 0);
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy, Flags[i]);
}
}
int
main(int argc, char *argv[])
{
int fd;
char *dest;
char *src;
char *dest_orig;
char *src_orig;
size_t mapped_len;
if (argc != 5)
UT_FATAL("usage: %s file srcoff destoff 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_memcpy %s %s %s %s %savx %savx512f",
argv[2], argv[3], argv[4], thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
fd = OPEN(argv[1], O_RDWR);
int dest_off = atoi(argv[2]);
int src_off = atoi(argv[3]);
size_t bytes = strtoul(argv[4], NULL, 0);
/* src > dst */
dest_orig = dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL);
if (dest == NULL)
UT_FATAL("!could not map file: %s", argv[1]);
src_orig = src = MMAP(dest + mapped_len, mapped_len,
PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
/*
* Its very unlikely that src would not be > dest. pmem_map_file
* chooses the first unused address >= 1TB, large
* enough to hold the give range, and 1GB aligned. If the
* addresses did not get swapped to allow src > dst, log error
* and allow test to continue.
*/
if (src <= dest) {
swap_mappings(&dest, &src, mapped_len, fd);
if (src <= dest)
UT_FATAL("cannot map files in memory order");
}
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, (2 * bytes));
util_persist_auto(type == TYPE_DEVDAX, dest, 2 * bytes);
memset(src, 0, (2 * bytes));
do_memcpy_variants(fd, dest, dest_off, src, src_off, bytes, argv[1]);
/* dest > src */
swap_mappings(&dest, &src, mapped_len, fd);
if (dest <= src)
UT_FATAL("cannot map files in memory order");
do_memcpy_variants(fd, dest, dest_off, src, src_off, bytes, argv[1]);
int ret = pmem_unmap(dest_orig, mapped_len);
UT_ASSERTeq(ret, 0);
MUNMAP(src_orig, mapped_len);
CLOSE(fd);
DONE(NULL);
}
| 7,772 | 28.667939 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_out_of_memory/vmmalloc_out_of_memory.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_out_of_memory -- unit test for libvmmalloc out_of_memory
*
* usage: vmmalloc_out_of_memory
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "vmmalloc_out_of_memory");
/* allocate all memory */
void *prev = NULL;
for (;;) {
void **next = malloc(sizeof(void *));
if (next == NULL) {
/* out of memory */
break;
}
*next = prev;
prev = next;
}
UT_ASSERTne(prev, NULL);
/* free all allocations */
while (prev != NULL) {
void **act = prev;
prev = *act;
free(act);
}
DONE(NULL);
}
| 2,161 | 29.885714 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_check_allocations/vmmalloc_check_allocations.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_check_allocations -- unit test for
* libvmmalloc check_allocations
*
* usage: vmmalloc_check_allocations
*/
#include "unittest.h"
#define MIN_SIZE (sizeof(int))
#define MAX_SIZE (4L * 1024L * 1024L)
#define MAX_ALLOCS (VMEM_MIN_POOL / MIN_SIZE)
/* buffer for all allocations */
static void *allocs[MAX_ALLOCS];
int
main(int argc, char *argv[])
{
int i, j;
size_t size;
START(argc, argv, "vmmalloc_check_allocations");
for (size = MAX_SIZE; size >= MIN_SIZE; size /= 2) {
UT_OUT("size %zu", size);
memset(allocs, 0, sizeof(allocs));
for (i = 0; i < MAX_ALLOCS; ++i) {
allocs[i] = malloc(size);
if (allocs[i] == NULL) {
/* out of memory in pool */
break;
}
/* fill each allocation with a unique value */
memset(allocs[i], (char)i, size);
}
/* at least one allocation for each size must succeed */
UT_ASSERT(i > 0);
/* check for unexpected modifications of the data */
for (i = 0; i < MAX_ALLOCS && allocs[i] != NULL; ++i) {
char *buffer = allocs[i];
for (j = 0; j < size; ++j) {
if (buffer[j] != (char)i)
UT_FATAL("Content of data object was "
"modified unexpectedly for "
"object size: %zu, id: %d",
size, j);
}
free(allocs[i]);
}
}
DONE(NULL);
}
| 2,866 | 30.163043 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/cto_basic/cto_basic.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.
*/
/*
* cto_basic.c -- unit test for close-to-open persistence
*
* usage: cto_basic filename
*/
#include "unittest.h"
#define NALLOCS 100
static unsigned *ptrs[NALLOCS * 2];
#define POOL_SIZE (PMEMCTO_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}
};
static void
test_alloc(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
ptrs[i] = pmemcto_malloc(pcp, 16 * sizeof(ptrs[0]));
UT_ASSERTne(ptrs[i], NULL);
*(ptrs[i]) = i;
}
}
static void
test_check(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
size_t usize = pmemcto_malloc_usable_size(pcp, ptrs[i]);
UT_ASSERT(usize >= 16 * sizeof(ptrs[0]));
UT_ASSERTeq(*(ptrs[i]), i);
}
}
static void
test_free(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
pmemcto_free(pcp, ptrs[i]);
}
}
static void
do_malloc(PMEMctopool *pcp)
{
size_t sum_alloc = 0;
int i = 0;
/* test with multiple size of allocations from 8MB to 2B */
for (size_t size = 8 * 1024 * 1024; size > 2; ++i, size /= 2) {
ptrs[i] = pmemcto_malloc(pcp, size);
if (ptrs[i] == NULL)
continue;
*ptrs[i] = 0x1111;
UT_ASSERTeq(*ptrs[i], 0x1111);
sum_alloc += size;
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
}
/* allocate more than half of pool size */
UT_ASSERT(sum_alloc * 2 > 8 * 1024 * 1024);
while (i > 0)
pmemcto_free(pcp, ptrs[--i]);
}
static void
do_calloc(PMEMctopool *pcp)
{
for (size_t count = 1; count < 1024; count *= 2) {
for (int i = 0; i < NALLOCS; i++) {
ptrs[i] = pmemcto_calloc(pcp, count, sizeof(ptrs[0]));
UT_ASSERTne(ptrs[i], NULL);
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
/* pmemcto_calloc should return zeroed memory */
for (int j = 0; j < count; j++) {
UT_ASSERTeq(ptrs[i][j], 0);
ptrs[i][j] = 0x2222;
UT_ASSERTeq(ptrs[i][j], 0x2222);
}
}
for (int i = 0; i < NALLOCS; i++)
pmemcto_free(pcp, ptrs[i]);
}
}
static void
do_realloc(PMEMctopool *pcp)
{
int *test = pmemcto_realloc(pcp, NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = 0x3333;
UT_ASSERTeq(test[0], 0x3333);
/* check that pointer came from mem_pool */
UT_ASSERTrange(test, pcp, POOL_SIZE);
test = pmemcto_realloc(pcp, test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], 0x3333);
test[1] = 0x3333;
test[9] = 0x3333;
/* check that pointer came from mem_pool */
UT_ASSERTrange(test, pcp, POOL_SIZE);
pmemcto_free(pcp, test);
}
static void
do_malloc_usable_size(PMEMctopool *pcp)
{
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, NULL), 0);
int i;
for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) {
size_t size = Check_sizes[i].size;
void *ptr = pmemcto_malloc(pcp, size);
UT_ASSERTne(ptr, NULL);
size_t usable_size = pmemcto_malloc_usable_size(pcp, 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);
pmemcto_free(pcp, ptr);
}
}
static void
do_strdup(PMEMctopool *pcp)
{
const char *text = "Some test text";
const char *text_empty = "";
const wchar_t *wtext = L"Some test text";
const wchar_t *wtext_empty = L"";
char *str1 = pmemcto_strdup(pcp, text);
wchar_t *wcs1 = pmemcto_wcsdup(pcp, wtext);
UT_ASSERTne(str1, NULL);
UT_ASSERTne(wcs1, NULL);
UT_ASSERTeq(strcmp(text, str1), 0);
UT_ASSERTeq(wcscmp(wtext, wcs1), 0);
/* check that pointer came from mem_pool */
UT_ASSERTrange(str1, pcp, POOL_SIZE);
UT_ASSERTrange(wcs1, pcp, POOL_SIZE);
char *str2 = pmemcto_strdup(pcp, text_empty);
wchar_t *wcs2 = pmemcto_wcsdup(pcp, wtext_empty);
UT_ASSERTne(str2, NULL);
UT_ASSERTne(wcs2, NULL);
UT_ASSERTeq(strcmp(text_empty, str2), 0);
UT_ASSERTeq(wcscmp(wtext_empty, wcs2), 0);
/* check that pointer came from mem_pool */
UT_ASSERTrange(str2, pcp, POOL_SIZE);
UT_ASSERTrange(wcs2, pcp, POOL_SIZE);
pmemcto_free(pcp, str1);
pmemcto_free(pcp, wcs1);
pmemcto_free(pcp, str2);
pmemcto_free(pcp, wcs2);
}
int
main(int argc, char *argv[])
{
unsigned *root;
START(argc, argv, "cto_basic");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
UT_OUT("create: %s", argv[1]);
PMEMctopool *pcp = pmemcto_create(argv[1], "cto_basic",
0, S_IWUSR|S_IRUSR);
if (pcp == NULL)
UT_FATAL("!pmemcto_create");
test_alloc(pcp, 0, NALLOCS);
test_check(pcp, 0, NALLOCS);
pmemcto_set_root_pointer(pcp, ptrs[0]);
pmemcto_close(pcp);
PMEMctopool *pcp_old = pcp;
UT_OUT("re-open #1: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
test_check(pcp, 0, NALLOCS);
root = pmemcto_get_root_pointer(pcp);
UT_ASSERTeq(root, ptrs[0]);
test_alloc(pcp, NALLOCS, NALLOCS);
test_check(pcp, NALLOCS, NALLOCS);
pmemcto_set_root_pointer(pcp, ptrs[NALLOCS]);
pmemcto_close(pcp);
UT_OUT("re-open #2: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
test_check(pcp, 0, 2 * NALLOCS);
root = pmemcto_get_root_pointer(pcp);
UT_ASSERTeq(root, ptrs[NALLOCS]);
test_free(pcp, 0, 2 * NALLOCS);
pmemcto_close(pcp);
UT_OUT("re-open #3: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
do_malloc(pcp);
do_calloc(pcp);
do_realloc(pcp);
do_malloc_usable_size(pcp);
do_strdup(pcp);
pmemcto_close(pcp);
/* try to open the pool when the base address is busy */
void *ptr = mmap(pcp_old, 4096, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, -1, 0);
UT_ASSERTne(ptr, NULL);
UT_ASSERTeq(ptr, pcp_old);
pcp = pmemcto_open(argv[1], "cto_basic");
UT_ASSERTeq(pcp, NULL);
munmap(ptr, 4096);
int ret = pmemcto_check(argv[1], "cto_basic");
UT_ASSERTeq(ret, 1);
ret = pmemcto_check(argv[1], NULL);
UT_ASSERTeq(ret, 1);
ret = pmemcto_check(argv[1], "xxx");
UT_ASSERTeq(ret, -1);
DONE(NULL);
}
| 8,646 | 25.606154 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/pmem_movnt/pmem_movnt.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.
*/
/*
* pmem_movnt.c -- unit test for MOVNT threshold
*
* usage: pmem_movnt
*
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
char *dst;
char *src;
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_movnt %s %savx %savx512f",
thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
src = MEMALIGN(64, 8192);
dst = MEMALIGN(64, 8192);
memset(src, 0x88, 8192);
memset(dst, 0, 8192);
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memcpy_nodrain(dst, src, size);
UT_ASSERTeq(memcmp(src, dst, size), 0);
UT_ASSERTeq(dst[size], 0);
}
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memmove_nodrain(dst, src, size);
UT_ASSERTeq(memcmp(src, dst, size), 0);
UT_ASSERTeq(dst[size], 0);
}
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memset_nodrain(dst, 0x77, size);
UT_ASSERTeq(dst[0], 0x77);
UT_ASSERTeq(dst[size - 1], 0x77);
UT_ASSERTeq(dst[size], 0);
}
ALIGNED_FREE(dst);
ALIGNED_FREE(src);
DONE(NULL);
}
| 2,779 | 29.888889 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_strdup/vmem_strdup.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_strdup.c -- unit test for vmem_strdup
*
* usage: vmem_strdup [directory]
*/
#include "unittest.h"
#include <wchar.h>
int
main(int argc, char *argv[])
{
const char *text = "Some test text";
const char *text_empty = "";
const wchar_t *wtext = L"Some test text";
const wchar_t *wtext_empty = L"";
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_strdup");
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(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");
}
char *str1 = vmem_strdup(vmp, text);
wchar_t *wcs1 = vmem_wcsdup(vmp, wtext);
UT_ASSERTne(str1, NULL);
UT_ASSERTne(wcs1, NULL);
UT_ASSERTeq(strcmp(text, str1), 0);
UT_ASSERTeq(wcscmp(wtext, wcs1), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(str1, mem_pool, VMEM_MIN_POOL);
UT_ASSERTrange(wcs1, mem_pool, VMEM_MIN_POOL);
}
char *str2 = vmem_strdup(vmp, text_empty);
wchar_t *wcs2 = vmem_wcsdup(vmp, wtext_empty);
UT_ASSERTne(str2, NULL);
UT_ASSERTne(wcs2, NULL);
UT_ASSERTeq(strcmp(text_empty, str2), 0);
UT_ASSERTeq(wcscmp(wtext_empty, wcs2), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(str2, mem_pool, VMEM_MIN_POOL);
UT_ASSERTrange(wcs2, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, str1);
vmem_free(vmp, wcs1);
vmem_free(vmp, str2);
vmem_free(vmp, wcs2);
vmem_delete(vmp);
DONE(NULL);
}
| 3,374 | 29.963303 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_memcheck_register/obj_memcheck_register.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_memcheck_register.c - tests that verifies that objects are registered
* correctly in memcheck
*/
#include "unittest.h"
static void
test_create(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "register",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid oid = pmemobj_root(pop, 1024);
TX_BEGIN(pop) {
pmemobj_tx_alloc(1024, 0);
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
pmemobj_close(pop);
}
static void
test_open(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_open(path, "register")) == NULL)
UT_FATAL("!pmemobj_open: %s", path);
PMEMoid oid = pmemobj_root(pop, 1024);
TX_BEGIN(pop) {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
pmemobj_close(pop);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memcheck_register");
if (argc != 3)
UT_FATAL("usage: %s [c|o] file-name", argv[0]);
switch (argv[1][0]) {
case 'c':
test_create(argv[2]);
break;
case 'o':
test_open(argv[2]);
break;
default:
UT_FATAL("usage: %s [c|o] file-name", argv[0]);
break;
}
DONE(NULL);
}
| 2,731 | 26.877551 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_calloc/vmmalloc_calloc.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_calloc.c -- unit test for libvmmalloc calloc
*
* usage: vmmalloc_calloc
*/
#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
/* cfree() has been removed from glibc since version 2.26 */
#ifndef cfree
#define cfree free
#endif
int
main(int argc, char *argv[])
{
const int test_value = 123456;
int count = DEFAULT_COUNT;
int n = DEFAULT_N;
int *ptr;
int i, j;
START(argc, argv, "vmmalloc_calloc");
for (i = 0; i < n; i++) {
ptr = calloc(1, count * sizeof(int));
UT_ASSERTne(ptr, NULL);
/* calloc should return zeroed memory */
for (j = 0; j < count; j++)
UT_ASSERTeq(ptr[j], 0);
for (j = 0; j < count; j++)
ptr[j] = test_value;
for (j = 0; j < count; j++)
UT_ASSERTeq(ptr[j], test_value);
cfree(ptr);
}
DONE(NULL);
}
| 2,506 | 30.734177 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_reorder_basic/obj_reorder_basic.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_reorder_basic.c -- a simple unit test for store reordering
*
* usage: obj_reorder_basic file w|c
* w - write data
* c - check data consistency
*
*/
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "intro_1"
#define MAX_BUF_LEN 10
#define BUF_VALUE 'a'
struct my_root {
size_t len;
char buf[MAX_BUF_LEN];
};
/*
* write_consistent -- (internal) write data in a consistent manner
*/
static void
write_consistent(struct pmemobjpool *pop)
{
PMEMoid root = pmemobj_root(pop, sizeof(struct my_root));
struct my_root *rootp = pmemobj_direct(root);
char buf[MAX_BUF_LEN];
memset(buf, BUF_VALUE, sizeof(buf));
buf[MAX_BUF_LEN - 1] = '\0';
rootp->len = strlen(buf);
pmemobj_persist(pop, &rootp->len, sizeof(rootp->len));
pmemobj_memcpy_persist(pop, rootp->buf, buf, rootp->len);
}
/*
* check_consistency -- (internal) check buf consistency
*/
static int
check_consistency(struct pmemobjpool *pop)
{
PMEMoid root = pmemobj_root(pop, sizeof(struct my_root));
struct my_root *rootp = pmemobj_direct(root);
if (rootp->len == strlen(rootp->buf) && rootp->len != 0)
for (int i = 0; i < MAX_BUF_LEN - 1; ++i)
if (rootp->buf[i] != BUF_VALUE)
return 1;
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_reorder_basic");
util_init();
if (argc != 3 || strchr("wc", argv[1][0]) == 0 || argv[1][1] != '\0')
UT_FATAL("usage: %s w|c file", argv[0]);
PMEMobjpool *pop = pmemobj_open(argv[2], LAYOUT_NAME);
UT_ASSERT(pop != NULL);
char opt = argv[1][0];
VALGRIND_EMIT_LOG("PMREORDER_MARKER_WRITE.BEGIN");
switch (opt) {
case 'w':
{
write_consistent(pop);
break;
}
case 'c':
{
int ret = check_consistency(pop);
pmemobj_close(pop);
END(ret);
}
default:
UT_FATAL("Unrecognized option %c", opt);
}
VALGRIND_EMIT_LOG("PMREORDER_MARKER_WRITE.END");
pmemobj_close(pop);
DONE(NULL);
}
| 3,514 | 26.677165 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_heap_interrupt/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 memops 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_heap_interrupt test.
* It would replace default implementation with mocked functions defined
* in obj_heap_interrupt.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define operation_finish __wrap_operation_finish
#endif
| 2,093 | 41.734694 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_heap_interrupt/obj_heap_interrupt.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_heap_interrupt.c -- unit test for pool heap interruption
*/
#include "heap_layout.h"
#include "memops.h"
#include "unittest.h"
POBJ_LAYOUT_BEGIN(heap_interrupt);
POBJ_LAYOUT_END(heap_interrupt);
static int exit_on_finish = 0;
FUNC_MOCK(operation_finish, void, struct operation_context *ctx)
FUNC_MOCK_RUN_DEFAULT {
if (exit_on_finish)
exit(0);
else
_FUNC_REAL(operation_finish)(ctx);
}
FUNC_MOCK_END
static void
sc0_create(PMEMobjpool *pop)
{
PMEMoid oids[3];
TX_BEGIN(pop) {
oids[0] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
oids[1] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
oids[2] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
} TX_END
pmemobj_free(&oids[0]);
exit_on_finish = 1;
pmemobj_free(&oids[1]);
}
/*
* noop_verify -- used in cases in which a successful open means that the test
* have passed successfully.
*/
static void
noop_verify(PMEMobjpool *pop)
{
}
typedef void (*scenario_func)(PMEMobjpool *pop);
static struct {
scenario_func create;
scenario_func verify;
} scenarios[] = {
{sc0_create, noop_verify},
};
int
main(int argc, char *argv[])
{
START(argc, argv, "heap_interrupt");
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(heap_interrupt) != 0);
if (argc != 4)
UT_FATAL("usage: %s file [cmd: c/o] [scenario]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
int exists = argv[2][0] == 'o';
int scenario = atoi(argv[3]);
if (!exists) {
if ((pop = pmemobj_create(path,
POBJ_LAYOUT_NAME(heap_interrupt),
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_FATAL("failed to create pool\n");
}
scenarios[scenario].create(pop);
/* if we get here, something is wrong with function mocking */
UT_ASSERT(0);
} else {
if ((pop = pmemobj_open(path,
POBJ_LAYOUT_NAME(heap_interrupt)))
== NULL) {
UT_FATAL("failed to open pool\n");
}
scenarios[scenario].verify(pop);
}
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
| 3,671 | 26 | 78 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_pmalloc_mt/obj_pmalloc_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.
*/
/*
* obj_pmalloc_mt.c -- multithreaded test of allocator
*/
#include <stdint.h>
#include "file.h"
#include "obj.h"
#include "pmalloc.h"
#include "unittest.h"
#define MAX_THREADS 32
#define MAX_OPS_PER_THREAD 1000
#define ALLOC_SIZE 104
#define REALLOC_SIZE (ALLOC_SIZE * 3)
#define MIX_RERUNS 2
#define CHUNKSIZE (1 << 18)
#define CHUNKS_PER_THREAD 3
static unsigned Threads;
static unsigned Ops_per_thread;
static unsigned Tx_per_thread;
struct root {
uint64_t offs[MAX_THREADS][MAX_OPS_PER_THREAD];
};
struct worker_args {
PMEMobjpool *pop;
struct root *r;
unsigned idx;
};
static void *
alloc_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmalloc(a->pop, &a->r->offs[a->idx][i], ALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
realloc_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
prealloc(a->pop, &a->r->offs[a->idx][i], REALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
free_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pfree(a->pop, &a->r->offs[a->idx][i]);
UT_ASSERTeq(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
mix_worker(void *arg)
{
struct worker_args *a = arg;
/*
* The mix scenario is ran twice to increase the chances of run
* contention.
*/
for (unsigned j = 0; j < MIX_RERUNS; ++j) {
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmalloc(a->pop, &a->r->offs[a->idx][i],
ALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pfree(a->pop, &a->r->offs[a->idx][i]);
UT_ASSERTeq(a->r->offs[a->idx][i], 0);
}
}
return NULL;
}
static void *
tx_worker(void *arg)
{
struct worker_args *a = arg;
/*
* Allocate objects until exhaustion, once that happens the transaction
* will automatically abort and all of the objects will be freed.
*/
TX_BEGIN(a->pop) {
for (unsigned n = 0; ; ++n) { /* this is NOT an infinite loop */
pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
if (Ops_per_thread != MAX_OPS_PER_THREAD &&
n == Ops_per_thread) {
pmemobj_tx_abort(0);
}
}
} TX_END
return NULL;
}
static void *
tx3_worker(void *arg)
{
struct worker_args *a = arg;
/*
* Allocate N objects, abort, repeat M times. Should reveal issues in
* transaction abort handling.
*/
for (unsigned n = 0; n < Tx_per_thread; ++n) {
TX_BEGIN(a->pop) {
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
}
pmemobj_tx_abort(EINVAL);
} TX_END
}
return NULL;
}
static void *
alloc_free_worker(void *arg)
{
struct worker_args *a = arg;
PMEMoid oid;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
int err = pmemobj_alloc(a->pop, &oid, ALLOC_SIZE,
0, NULL, NULL);
UT_ASSERTeq(err, 0);
pmemobj_free(&oid);
}
return NULL;
}
#define OPS_PER_TX 10
#define STEP 8
#define TEST_LANES 4
static void *
tx2_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned n = 0; n < Tx_per_thread; ++n) {
PMEMoid oids[OPS_PER_TX];
TX_BEGIN(a->pop) {
for (int i = 0; i < OPS_PER_TX; ++i) {
oids[i] = pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
for (unsigned j = 0; j < ALLOC_SIZE;
j += STEP) {
pmemobj_tx_add_range(oids[i], j, STEP);
}
}
} TX_END
TX_BEGIN(a->pop) {
for (int i = 0; i < OPS_PER_TX; ++i)
pmemobj_tx_free(oids[i]);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
return NULL;
}
static void
run_worker(void *(worker_func)(void *arg), struct worker_args args[])
{
os_thread_t t[MAX_THREADS];
for (unsigned i = 0; i < Threads; ++i)
os_thread_create(&t[i], NULL, worker_func, &args[i]);
for (unsigned i = 0; i < Threads; ++i)
os_thread_join(&t[i], NULL);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_mt");
if (argc != 5)
UT_FATAL("usage: %s <threads> <ops/t> <tx/t> [file]", argv[0]);
PMEMobjpool *pop;
Threads = ATOU(argv[1]);
if (Threads > MAX_THREADS)
UT_FATAL("Threads %d > %d", Threads, MAX_THREADS);
Ops_per_thread = ATOU(argv[2]);
if (Ops_per_thread > MAX_OPS_PER_THREAD)
UT_FATAL("Ops per thread %d > %d", Threads, MAX_THREADS);
Tx_per_thread = ATOU(argv[3]);
int exists = util_file_exists(argv[4]);
if (exists < 0)
UT_FATAL("!util_file_exists");
if (!exists) {
pop = pmemobj_create(argv[4], "TEST", (PMEMOBJ_MIN_POOL) +
(MAX_THREADS * CHUNKSIZE * CHUNKS_PER_THREAD),
0666);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
} else {
pop = pmemobj_open(argv[4], "TEST");
if (pop == NULL)
UT_FATAL("!pmemobj_open");
}
PMEMoid oid = pmemobj_root(pop, sizeof(struct root));
struct root *r = pmemobj_direct(oid);
UT_ASSERTne(r, NULL);
struct worker_args args[MAX_THREADS];
for (unsigned i = 0; i < Threads; ++i) {
args[i].pop = pop;
args[i].r = r;
args[i].idx = i;
}
run_worker(alloc_worker, args);
run_worker(realloc_worker, args);
run_worker(free_worker, args);
run_worker(mix_worker, args);
run_worker(alloc_free_worker, args);
/*
* Reduce the number of lanes to a value smaller than the number of
* threads. This will ensure that at least some of the state of the lane
* will be shared between threads. Doing this might reveal bugs related
* to runtime race detection instrumentation.
*/
unsigned old_nlanes = pop->lanes_desc.runtime_nlanes;
pop->lanes_desc.runtime_nlanes = TEST_LANES;
run_worker(tx2_worker, args);
pop->lanes_desc.runtime_nlanes = old_nlanes;
/*
* This workload might create many allocation classes due to pvector,
* keep it last.
*/
if (Threads == MAX_THREADS) /* don't run for short tests */
run_worker(tx_worker, args);
run_worker(tx3_worker, args);
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
| 7,630 | 22.846875 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_alignment/obj_ctl_alignment.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_ctl_alignment.c -- tests for the alloc class alignment
*/
#include "unittest.h"
#define LAYOUT "obj_ctl_alignment"
static PMEMobjpool *pop;
static void
test_fail(void)
{
struct pobj_alloc_class_desc ac;
ac.header_type = POBJ_HEADER_NONE;
ac.unit_size = 1024 - 1;
ac.units_per_block = 100;
ac.alignment = 512;
int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &ac);
UT_ASSERTeq(ret, -1); /* unit_size must be multiple of alignment */
}
static void
test_aligned_allocs(size_t size, size_t alignment, enum pobj_header_type htype)
{
struct pobj_alloc_class_desc ac;
ac.header_type = htype;
ac.unit_size = size;
ac.units_per_block = 100;
ac.alignment = alignment;
int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &ac);
UT_ASSERTeq(ret, 0);
PMEMoid oid;
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(ac.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(oid.off % alignment, 0);
UT_ASSERTeq((uintptr_t)pmemobj_direct(oid) % alignment, 0);
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(ac.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(oid.off % alignment, 0);
UT_ASSERTeq((uintptr_t)pmemobj_direct(oid) % alignment, 0);
char query[1024];
snprintf(query, 1024, "heap.alloc_class.%u.desc", ac.class_id);
struct pobj_alloc_class_desc read_ac;
ret = pmemobj_ctl_get(pop, query, &read_ac);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ac.alignment, read_ac.alignment);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_alignment");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL * 10,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
test_fail();
test_aligned_allocs(1024, 512, POBJ_HEADER_NONE);
test_aligned_allocs(1024, 512, POBJ_HEADER_COMPACT);
test_aligned_allocs(64, 64, POBJ_HEADER_COMPACT);
pmemobj_close(pop);
DONE(NULL);
}
| 3,565 | 30.557522 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmmalloc_memalign/vmmalloc_memalign.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_memalign.c -- unit test for libvmmalloc memalign, posix_memalign
* and aligned_alloc (if available)
*
* usage: vmmalloc_memalign [m|p|a]
*/
#include <stdlib.h>
#include <errno.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
#define USAGE "usage: %s [m|p|a]"
#define MIN_ALIGN (2)
#define MAX_ALIGN (4L * 1024L * 1024L)
#define MAX_ALLOCS (100)
/* buffer for all allocations */
static int *allocs[MAX_ALLOCS];
static void *(*Aalloc)(size_t alignment, size_t size);
static void *
posix_memalign_wrap(size_t alignment, size_t size)
{
void *ptr;
int err = posix_memalign(&ptr, alignment, size);
/* ignore OOM */
if (err) {
char buff[UT_MAX_ERR_MSG];
ptr = NULL;
ut_strerror(err, buff, UT_MAX_ERR_MSG);
if (err != ENOMEM)
UT_OUT("posix_memalign: %s", buff);
}
return ptr;
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
size_t alignment;
int i;
START(argc, argv, "vmmalloc_memalign");
if (argc != 2)
UT_FATAL(USAGE, argv[0]);
switch (argv[1][0]) {
case 'm':
UT_OUT("testing memalign");
Aalloc = memalign;
break;
case 'p':
UT_OUT("testing posix_memalign");
Aalloc = posix_memalign_wrap;
break;
case 'a':
UT_OUT("testing aligned_alloc");
Aalloc = aligned_alloc;
break;
default:
UT_FATAL(USAGE, argv[0]);
}
/* test with address alignment from 2B to 4MB */
for (alignment = MAX_ALIGN; alignment >= MIN_ALIGN; alignment /= 2) {
UT_OUT("alignment %zu", alignment);
memset(allocs, 0, sizeof(allocs));
for (i = 0; i < MAX_ALLOCS; ++i) {
allocs[i] = Aalloc(alignment, sizeof(int));
if (allocs[i] == NULL)
break;
/* ptr should be usable */
*allocs[i] = test_value;
UT_ASSERTeq(*allocs[i], test_value);
/* check for correct address alignment */
UT_ASSERTeq(
(uintptr_t)(allocs[i]) & (alignment - 1), 0);
}
/* at least one allocation must succeed */
UT_ASSERT(i > 0);
for (i = 0; i < MAX_ALLOCS && allocs[i] != NULL; ++i)
free(allocs[i]);
}
DONE(NULL);
}
| 3,609 | 26.557252 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list/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 obj list 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_list test.
* It would replace default implementation with mocked functions defined
* in obj_list.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#ifdef WRAP_REAL
#define WRAP_REAL_PMALLOC
#define WRAP_REAL_ULOG
#define WRAP_REAL_LANE
#define WRAP_REAL_HEAP
#define WRAP_REAL_PMEMOBJ
#endif
#ifndef WRAP_REAL_PMALLOC
#define pmalloc __wrap_pmalloc
#define pfree __wrap_pfree
#define pmalloc_construct __wrap_pmalloc_construct
#define prealloc __wrap_prealloc
#define prealloc_construct __wrap_prealloc_construct
#define palloc_usable_size __wrap_palloc_usable_size
#define palloc_reserve __wrap_palloc_reserve
#define palloc_publish __wrap_palloc_publish
#define palloc_defer_free __wrap_palloc_defer_free
#endif
#ifndef WRAP_REAL_ULOG
#define ulog_store __wrap_ulog_store
#define ulog_process __wrap_ulog_process
#endif
#ifndef WRAP_REAL_LANE
#define lane_hold __wrap_lane_hold
#define lane_release __wrap_lane_release
#define lane_recover_and_section_boot __wrap_lane_recover_and_section_boot
#define lane_section_cleanup __wrap_lane_section_cleanup
#endif
#ifndef WRAP_REAL_HEAP
#define heap_boot __wrap_heap_boot
#endif
#ifndef WRAP_REAL_PMEMOBJ
#define pmemobj_alloc __wrap_pmemobj_alloc
#define pmemobj_alloc_usable_size __wrap_pmemobj_alloc_usable_size
#define pmemobj_openU __wrap_pmemobj_open
#define pmemobj_close __wrap_pmemobj_close
#define pmemobj_direct __wrap_pmemobj_direct
#define pmemobj_pool_by_oid __wrap_pmemobj_pool_by_oid
#define pmemobj_pool_by_ptr __wrap_pmemobj_pool_by_ptr
#endif
#if defined(__cplusplus)
}
#endif
| 3,448 | 33.838384 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list/obj_list.h | /*
* 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_list.h -- unit tests for list module
*/
#include <stddef.h>
#include <sys/param.h>
#include "list.h"
#include "obj.h"
#include "lane.h"
#include "unittest.h"
#include "util.h"
/* offset to "in band" item */
#define OOB_OFF (sizeof(struct oob_header))
/* pmemobj initial heap offset */
#define HEAP_OFFSET 8192
TOID_DECLARE(struct item, 0);
TOID_DECLARE(struct list, 1);
TOID_DECLARE(struct oob_list, 2);
TOID_DECLARE(struct oob_item, 3);
struct item {
int id;
POBJ_LIST_ENTRY(struct item) next;
};
struct oob_header {
char data[48];
};
struct oob_item {
struct oob_header oob;
struct item item;
};
struct oob_list {
struct list_head head;
};
struct list {
POBJ_LIST_HEAD(listhead, struct item) head;
};
enum ulog_fail
{
/* don't fail at all */
NO_FAIL,
/* fail after ulog_store */
FAIL_AFTER_FINISH,
/* fail before ulog_store */
FAIL_BEFORE_FINISH,
/* fail after process */
FAIL_AFTER_PROCESS
};
/* global handle to pmemobj pool */
extern PMEMobjpool *Pop;
/* pointer to heap offset */
extern uint64_t *Heap_offset;
/* list lane section */
extern struct lane Lane;
/* actual item id */
extern int *Id;
/* fail event */
extern enum ulog_fail Ulog_fail;
/* global "in band" lists */
extern TOID(struct list) List;
extern TOID(struct list) List_sec;
/* global "out of band" lists */
extern TOID(struct oob_list) List_oob;
extern TOID(struct oob_list) List_oob_sec;
extern TOID(struct oob_item) *Item;
/* usage macros */
#define FATAL_USAGE()\
UT_FATAL("usage: obj_list <file> [PRnifr]")
#define FATAL_USAGE_PRINT()\
UT_FATAL("usage: obj_list <file> P:<list>")
#define FATAL_USAGE_PRINT_REVERSE()\
UT_FATAL("usage: obj_list <file> R:<list>")
#define FATAL_USAGE_INSERT()\
UT_FATAL("usage: obj_list <file> i:<where>:<num>")
#define FATAL_USAGE_INSERT_NEW()\
UT_FATAL("usage: obj_list <file> n:<where>:<num>:<value>")
#define FATAL_USAGE_REMOVE_FREE()\
UT_FATAL("usage: obj_list <file> f:<list>:<num>:<from>")
#define FATAL_USAGE_REMOVE()\
UT_FATAL("usage: obj_list <file> r:<num>")
#define FATAL_USAGE_MOVE()\
UT_FATAL("usage: obj_list <file> m:<num>:<where>:<num>")
#define FATAL_USAGE_FAIL()\
UT_FATAL("usage: obj_list <file> "\
"F:<after_finish|before_finish|after_process>")
| 3,829 | 28.015152 | 74 | h |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list/obj_list_mocks.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_list_mocks.c -- mocks for redo/lane/heap/obj modules
*/
#include <inttypes.h>
#include "valgrind_internal.h"
#include "obj_list.h"
#include "set.h"
/*
* pmem_drain_nop -- no operation for drain on non-pmem memory
*/
static void
pmem_drain_nop(void)
{
/* NOP */
}
/*
* obj_persist -- pmemobj version of pmem_persist w/o replication
*/
static int
obj_persist(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->persist_local(addr, len);
return 0;
}
/*
* obj_flush -- pmemobj version of pmem_flush w/o replication
*/
static int
obj_flush(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->flush_local(addr, len);
return 0;
}
static uintptr_t Pool_addr;
static size_t Pool_size;
static void
obj_msync_nofail(const void *addr, size_t size)
{
uintptr_t addr_ptrt = (uintptr_t)addr;
/*
* Verify msynced range is in the last mapped file range. Useful for
* catching errors which normally would be caught only on Windows by
* win_mmap.c.
*/
if (addr_ptrt < Pool_addr || addr_ptrt >= Pool_addr + Pool_size ||
addr_ptrt + size >= Pool_addr + Pool_size)
UT_FATAL("<0x%" PRIxPTR ",0x%" PRIxPTR "> "
"not in <0x%" PRIxPTR ",0x%" PRIxPTR "> range",
addr_ptrt, addr_ptrt + size, Pool_addr,
Pool_addr + Pool_size);
if (pmem_msync(addr, size))
UT_FATAL("!pmem_msync");
}
/*
* obj_drain -- pmemobj version of pmem_drain w/o replication
*/
static void
obj_drain(void *ctx)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->drain_local();
}
static void *
obj_memcpy(void *ctx, void *dest, const void *src, size_t len,
unsigned flags)
{
return pmem_memcpy(dest, src, len, flags);
}
static void *
obj_memset(void *ctx, void *ptr, int c, size_t sz, unsigned flags)
{
return pmem_memset(ptr, c, sz, flags);
}
/*
* linear_alloc -- allocates `size` bytes (rounded up to 8 bytes) and returns
* offset to the allocated object
*/
static uint64_t
linear_alloc(uint64_t *cur_offset, size_t size)
{
uint64_t ret = *cur_offset;
*cur_offset += roundup(size, sizeof(uint64_t));
return ret;
}
/*
* pmemobj_open -- pmemobj_open mock
*
* This function initializes the pmemobj pool for purposes of this
* unittest.
*/
FUNC_MOCK(pmemobj_open, PMEMobjpool *, const char *fname, const char *layout)
FUNC_MOCK_RUN_DEFAULT
{
size_t size;
int is_pmem;
void *addr = pmem_map_file(fname, 0, 0, 0, &size, &is_pmem);
if (!addr) {
UT_OUT("!%s: pmem_map_file", fname);
return NULL;
}
Pool_addr = (uintptr_t)addr;
Pool_size = size;
Pop = (PMEMobjpool *)addr;
Pop->addr = Pop;
Pop->is_pmem = is_pmem;
Pop->rdonly = 0;
Pop->uuid_lo = 0x12345678;
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->mutex_head,
sizeof(Pop->mutex_head));
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->rwlock_head,
sizeof(Pop->rwlock_head));
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->cond_head,
sizeof(Pop->cond_head));
Pop->mutex_head = NULL;
Pop->rwlock_head = NULL;
Pop->cond_head = NULL;
if (Pop->is_pmem) {
Pop->persist_local = pmem_persist;
Pop->flush_local = pmem_flush;
Pop->drain_local = pmem_drain;
Pop->memcpy_local = pmem_memcpy;
Pop->memset_local = pmem_memset;
} else {
Pop->persist_local = obj_msync_nofail;
Pop->flush_local = obj_msync_nofail;
Pop->drain_local = pmem_drain_nop;
Pop->memcpy_local = pmem_memcpy;
Pop->memset_local = pmem_memset;
}
Pop->p_ops.persist = obj_persist;
Pop->p_ops.flush = obj_flush;
Pop->p_ops.drain = obj_drain;
Pop->p_ops.memcpy = obj_memcpy;
Pop->p_ops.memset = obj_memset;
Pop->p_ops.base = Pop;
struct pmem_ops *p_ops = &Pop->p_ops;
Pop->heap_offset = HEAP_OFFSET;
Pop->heap_size = size - Pop->heap_offset;
uint64_t heap_offset = HEAP_OFFSET;
Heap_offset = (uint64_t *)((uintptr_t)Pop +
linear_alloc(&heap_offset, sizeof(*Heap_offset)));
Id = (int *)((uintptr_t)Pop + linear_alloc(&heap_offset, sizeof(*Id)));
/* Alloc lane layout */
Lane.layout = (struct lane_layout *)((uintptr_t)Pop +
linear_alloc(&heap_offset, LANE_TOTAL_SIZE));
/* Alloc in band lists */
List.oid.pool_uuid_lo = Pop->uuid_lo;
List.oid.off = linear_alloc(&heap_offset, sizeof(struct list));
List_sec.oid.pool_uuid_lo = Pop->uuid_lo;
List_sec.oid.off = linear_alloc(&heap_offset, sizeof(struct list));
/* Alloc out of band lists */
List_oob.oid.pool_uuid_lo = Pop->uuid_lo;
List_oob.oid.off = linear_alloc(&heap_offset, sizeof(struct oob_list));
List_oob_sec.oid.pool_uuid_lo = Pop->uuid_lo;
List_oob_sec.oid.off =
linear_alloc(&heap_offset, sizeof(struct oob_list));
Item = (union oob_item_toid *)((uintptr_t)Pop +
linear_alloc(&heap_offset, sizeof(*Item)));
Item->oid.pool_uuid_lo = Pop->uuid_lo;
Item->oid.off = linear_alloc(&heap_offset, sizeof(struct oob_item));
pmemops_persist(p_ops, Item, sizeof(*Item));
if (*Heap_offset == 0) {
*Heap_offset = heap_offset;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
}
pmemops_persist(p_ops, Pop, HEAP_OFFSET);
Pop->run_id += 2;
pmemops_persist(p_ops, &Pop->run_id, sizeof(Pop->run_id));
Lane.external = operation_new((struct ulog *)&Lane.layout->external,
LANE_REDO_EXTERNAL_SIZE, NULL, NULL, p_ops, LOG_TYPE_REDO);
return Pop;
}
FUNC_MOCK_END
/*
* pmemobj_close -- pmemobj_close mock
*
* Just unmap the mapped area.
*/
FUNC_MOCK(pmemobj_close, void, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
operation_delete(Lane.external);
UT_ASSERTeq(pmem_unmap(Pop,
Pop->heap_size + Pop->heap_offset), 0);
Pop = NULL;
Pool_addr = 0;
Pool_size = 0;
}
FUNC_MOCK_END
/*
* pmemobj_pool_by_ptr -- pmemobj_pool_by_ptr mock
*
* Just return Pop.
*/
FUNC_MOCK_RET_ALWAYS(pmemobj_pool_by_ptr, PMEMobjpool *, Pop, const void *ptr);
/*
* pmemobj_direct -- pmemobj_direct mock
*/
FUNC_MOCK(pmemobj_direct, void *, PMEMoid oid)
FUNC_MOCK_RUN_DEFAULT {
return (void *)((uintptr_t)Pop + oid.off);
}
FUNC_MOCK_END
FUNC_MOCK_RET_ALWAYS(pmemobj_pool_by_oid, PMEMobjpool *, Pop, PMEMoid oid);
/*
* pmemobj_alloc_usable_size -- pmemobj_alloc_usable_size mock
*/
FUNC_MOCK(pmemobj_alloc_usable_size, size_t, PMEMoid oid)
FUNC_MOCK_RUN_DEFAULT {
size_t size = palloc_usable_size(
&Pop->heap, oid.off - OOB_OFF);
return size - OOB_OFF;
}
FUNC_MOCK_END
/*
* pmemobj_alloc -- pmemobj_alloc mock
*
* Allocates an object using pmalloc and return PMEMoid.
*/
FUNC_MOCK(pmemobj_alloc, int, PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num,
pmemobj_constr constructor, void *arg)
FUNC_MOCK_RUN_DEFAULT {
PMEMoid oid = {0, 0};
oid.pool_uuid_lo = 0;
pmalloc(pop, &oid.off, size, 0, 0);
if (oidp) {
*oidp = oid;
if (OBJ_PTR_FROM_POOL(pop, oidp))
pmemops_persist(&Pop->p_ops, oidp,
sizeof(*oidp));
}
return 0;
}
FUNC_MOCK_END
/*
* lane_hold -- lane_hold mock
*
* Returns pointer to list lane section.
*/
FUNC_MOCK(lane_hold, unsigned, PMEMobjpool *pop, struct lane **lane)
FUNC_MOCK_RUN_DEFAULT {
*lane = &Lane;
return 0;
}
FUNC_MOCK_END
/*
* lane_release -- lane_release mock
*
* Always returns success.
*/
FUNC_MOCK_RET_ALWAYS_VOID(lane_release, PMEMobjpool *pop);
/*
* lane_recover_and_section_boot -- lane_recover_and_section_boot mock
*/
FUNC_MOCK(lane_recover_and_section_boot, int, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
ulog_recover((struct ulog *)&Lane.layout->external,
OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops);
return 0;
}
FUNC_MOCK_END
/*
* lane_section_cleanup -- lane_section_cleanup mock
*/
FUNC_MOCK(lane_section_cleanup, int, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
return 0;
}
FUNC_MOCK_END
/*
* ulog_store_last -- ulog_store_last mock
*/
FUNC_MOCK(ulog_store, void,
struct ulog *dest,
struct ulog *src, size_t nbytes, size_t redo_base_nbytes,
struct ulog_next *next, const struct pmem_ops *p_ops)
FUNC_MOCK_RUN_DEFAULT {
switch (Ulog_fail) {
case FAIL_AFTER_FINISH:
_FUNC_REAL(ulog_store)(dest, src,
nbytes, redo_base_nbytes,
next, p_ops);
DONEW(NULL);
break;
case FAIL_BEFORE_FINISH:
DONEW(NULL);
break;
default:
_FUNC_REAL(ulog_store)(dest, src,
nbytes, redo_base_nbytes,
next, p_ops);
break;
}
}
FUNC_MOCK_END
/*
* ulog_process -- ulog_process mock
*/
FUNC_MOCK(ulog_process, void, struct ulog *ulog,
ulog_check_offset_fn check, const struct pmem_ops *p_ops)
FUNC_MOCK_RUN_DEFAULT {
_FUNC_REAL(ulog_process)(ulog, check, p_ops);
if (Ulog_fail == FAIL_AFTER_PROCESS) {
DONEW(NULL);
}
}
FUNC_MOCK_END
/*
* heap_boot -- heap_boot mock
*
* Always returns success.
*/
FUNC_MOCK_RET_ALWAYS(heap_boot, int, 0, PMEMobjpool *pop);
| 10,203 | 24.702771 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list/obj_list_mocks_palloc.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_list_mocks_palloc.c -- mocks for palloc/pmalloc modules
*/
#include "obj_list.h"
/*
* pmalloc -- pmalloc mock
*
* Allocates the memory using linear allocator.
* Prints the id of allocated struct oob_item for tracking purposes.
*/
FUNC_MOCK(pmalloc, int, PMEMobjpool *pop, uint64_t *ptr,
size_t size, uint64_t extra_field, uint16_t flags)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop
+ *Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
*ptr = *Heap_offset + sizeof(uint64_t);
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(p_ops, ptr, sizeof(*ptr));
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + *ptr);
*ptr += OOB_OFF;
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(p_ops, ptr, sizeof(*ptr));
item->item.id = *Id;
pmemops_persist(p_ops, &item->item.id, sizeof(item->item.id));
(*Id)++;
pmemops_persist(p_ops, Id, sizeof(*Id));
*Heap_offset = *Heap_offset + sizeof(uint64_t) +
size + OOB_OFF;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
UT_OUT("pmalloc(id = %d)", item->item.id);
return 0;
}
FUNC_MOCK_END
/*
* pfree -- pfree mock
*
* Just prints freeing struct oob_item id. Doesn't free the memory.
*/
FUNC_MOCK(pfree, void, PMEMobjpool *pop, uint64_t *ptr)
FUNC_MOCK_RUN_DEFAULT {
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + *ptr - OOB_OFF);
UT_OUT("pfree(id = %d)", item->item.id);
*ptr = 0;
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(&Pop->p_ops, ptr, sizeof(*ptr));
return;
}
FUNC_MOCK_END
/*
* pmalloc_construct -- pmalloc_construct mock
*
* Allocates the memory using linear allocator and invokes the constructor.
* Prints the id of allocated struct oob_item for tracking purposes.
*/
FUNC_MOCK(pmalloc_construct, int, PMEMobjpool *pop, uint64_t *off,
size_t size, palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t flags, uint16_t class_id)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
*Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
*off = *Heap_offset + sizeof(uint64_t) + OOB_OFF;
if (OBJ_PTR_FROM_POOL(pop, off))
pmemops_persist(p_ops, off, sizeof(*off));
*Heap_offset = *Heap_offset + sizeof(uint64_t) + size;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
void *ptr = (void *)((uintptr_t)Pop + *off);
constructor(pop, ptr, size, arg);
return 0;
}
FUNC_MOCK_END
/*
* prealloc -- prealloc mock
*/
FUNC_MOCK(prealloc, int, PMEMobjpool *pop, uint64_t *off, size_t size,
uint64_t extra_field, uint16_t flags)
FUNC_MOCK_RUN_DEFAULT {
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
*off - sizeof(uint64_t));
struct item *item = (struct item *)((uintptr_t)Pop +
*off + OOB_OFF);
if (*alloc_size >= size) {
*alloc_size = size;
pmemops_persist(&Pop->p_ops, alloc_size,
sizeof(*alloc_size));
UT_OUT("prealloc(id = %d, size = %zu) = true",
item->id,
(size - OOB_OFF) / sizeof(struct item));
return 0;
} else {
UT_OUT("prealloc(id = %d, size = %zu) = false",
item->id,
(size - OOB_OFF) / sizeof(struct item));
return -1;
}
}
FUNC_MOCK_END
/*
* prealloc_construct -- prealloc_construct mock
*/
FUNC_MOCK(prealloc_construct, int, PMEMobjpool *pop, uint64_t *off,
size_t size, palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t flags, uint16_t class_id)
FUNC_MOCK_RUN_DEFAULT {
int ret = __wrap_prealloc(pop, off, size, 0, 0);
if (!ret) {
void *ptr = (void *)((uintptr_t)Pop + *off + OOB_OFF);
constructor(pop, ptr, size, arg);
}
return ret;
}
FUNC_MOCK_END
/*
* palloc_reserve -- palloc_reserve mock
*/
FUNC_MOCK(palloc_reserve, int, struct palloc_heap *heap, size_t size,
palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t object_flags, uint16_t class_id,
struct pobj_action *act)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop
+ *Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
act->heap.offset = *Heap_offset + sizeof(uint64_t);
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + act->heap.offset);
act->heap.offset += OOB_OFF;
item->item.id = *Id;
pmemops_persist(p_ops, &item->item.id, sizeof(item->item.id));
(*Id)++;
pmemops_persist(p_ops, Id, sizeof(*Id));
*Heap_offset += sizeof(uint64_t) + size + OOB_OFF;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
UT_OUT("pmalloc(id = %d)", item->item.id);
return 0;
}
FUNC_MOCK_END
/*
* palloc_publish -- mock publish, must process operation
*/
FUNC_MOCK(palloc_publish, void, struct palloc_heap *heap,
struct pobj_action *actv, size_t actvcnt,
struct operation_context *ctx)
FUNC_MOCK_RUN_DEFAULT {
operation_finish(ctx);
}
FUNC_MOCK_END
/*
* palloc_defer_free -- pfree mock
*
* Just prints freeing struct oob_item id. Doesn't free the memory.
*/
FUNC_MOCK(palloc_defer_free, void, struct palloc_heap *heap, uint64_t off,
struct pobj_action *act)
FUNC_MOCK_RUN_DEFAULT {
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + off - OOB_OFF);
UT_OUT("pfree(id = %d)", item->item.id);
act->heap.offset = off;
return;
}
FUNC_MOCK_END
/*
* pmalloc_usable_size -- pmalloc_usable_size mock
*/
FUNC_MOCK(palloc_usable_size, size_t, struct palloc_heap *heap, uint64_t off)
FUNC_MOCK_RUN_DEFAULT {
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
off - sizeof(uint64_t));
return (size_t)*alloc_size;
}
FUNC_MOCK_END
| 7,517 | 29.560976 | 77 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_list/obj_list.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_list.c -- unit tests for list module
*/
/*
* XXX - On VC++, this file must be compiled as C++ to have __typeof__ defined.
* However, the rest of the files (libpmemobj source) are still compiled as C.
* To avoid issues with 'C' linkage the entire file is in 'extern "C"' block.
*/
#if defined(__cplusplus) && defined(_MSC_VER)
extern "C" {
/*
* XXX - Templates cannot be used with 'C' linkage, so for the purpose
* of this test, we override template-based definition of __typeof__ with
* a simple alias to decltype.
*/
#define __typeof__(p) decltype(p)
#endif
#include "obj_list.h"
/* global handle to pmemobj pool */
PMEMobjpool *Pop;
/* pointer to heap offset */
uint64_t *Heap_offset;
/* list lane section */
struct lane Lane;
/* actual item id */
int *Id;
/* fail event */
enum ulog_fail Ulog_fail = NO_FAIL;
/* global "in band" lists */
TOID(struct list) List;
TOID(struct list) List_sec;
/* global "out of band" lists */
TOID(struct oob_list) List_oob;
TOID(struct oob_list) List_oob_sec;
TOID(struct oob_item) *Item;
/*
* for each element on list in normal order
*/
#define PLIST_FOREACH(item, list, head, field)\
for ((item) = \
D_RW((list))->head.pe_first;\
!TOID_IS_NULL((item));\
TOID_ASSIGN((item),\
TOID_EQUALS((item),\
D_RW(D_RW((list))->head.pe_first)->field.pe_prev) ?\
OID_NULL : \
D_RW(item)->field.pe_next.oid))
/*
* for each element on list in reverse order
*/
#define PLIST_FOREACH_REVERSE(item, list, head, field)\
for ((item) = \
TOID_IS_NULL(D_RW((list))->head.pe_first) ? D_RW(list)->head.pe_first :\
D_RW(D_RW(list)->head.pe_first)->field.pe_prev;\
!TOID_IS_NULL((item));\
TOID_ASSIGN((item),\
TOID_EQUALS((item),\
D_RW((list))->head.pe_first) ?\
OID_NULL :\
D_RW(item)->field.pe_prev.oid))
/*
* get_item_list -- get nth item from list
*/
static PMEMoid
get_item_list(PMEMoid head, int n)
{
TOID(struct list) list;
TOID_ASSIGN(list, head);
TOID(struct item) item;
if (n >= 0) {
PLIST_FOREACH(item, list, head, next) {
if (n == 0)
return item.oid;
n--;
}
} else {
PLIST_FOREACH_REVERSE(item, list, head, next) {
n++;
if (n == 0)
return item.oid;
}
}
return OID_NULL;
}
/*
* do_print -- print list elements in normal order
*/
static void
do_print(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "P:%d", &L) != 1)
FATAL_USAGE_PRINT();
if (L == 2) {
TOID(struct item) item;
UT_OUT("list:");
PLIST_FOREACH(item, List, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 4) {
TOID(struct item) item;
UT_OUT("list sec:");
PLIST_FOREACH(item, List_sec, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT();
}
}
/*
* do_print_reverse -- print list elements in reverse order
*/
static void
do_print_reverse(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "R:%d", &L) != 1)
FATAL_USAGE_PRINT_REVERSE();
if (L == 2) {
TOID(struct item) item;
UT_OUT("list reverse:");
PLIST_FOREACH_REVERSE(item, List, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 4) {
TOID(struct item) item;
UT_OUT("list sec reverse:");
PLIST_FOREACH_REVERSE(item, List_sec, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT_REVERSE();
}
}
/*
* item_constructor -- constructor which sets the item's id to
* new value
*/
static int
item_constructor(void *ctx, void *ptr, size_t usable_size, void *arg)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
int id = *(int *)arg;
struct item *item = (struct item *)ptr;
item->id = id;
pmemops_persist(&pop->p_ops, &item->id, sizeof(item->id));
UT_OUT("constructor(id = %d)", id);
return 0;
}
struct realloc_arg {
void *ptr;
size_t new_size;
size_t old_size;
};
/*
* do_insert_new -- insert new element to list
*/
static void
do_insert_new(PMEMobjpool *pop, const char *arg)
{
int n; /* which element on List */
int before;
int id;
int ret = sscanf(arg, "n:%d:%d:%d", &before, &n, &id);
if (ret == 3) {
ret = list_insert_new_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
sizeof(struct item),
TOID_TYPE_NUM(struct item),
item_constructor,
&id, (PMEMoid *)Item);
if (ret)
UT_FATAL("list_insert_new(List, List_oob) failed");
} else if (ret == 2) {
ret = list_insert_new_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
sizeof(struct item),
TOID_TYPE_NUM(struct item),
NULL, NULL, (PMEMoid *)Item);
if (ret)
UT_FATAL("list_insert_new(List, List_oob) failed");
} else {
FATAL_USAGE_INSERT_NEW();
}
}
/*
* do_insert -- insert element to list
*/
static void
do_insert(PMEMobjpool *pop, const char *arg)
{
int before;
int n; /* which element */
if (sscanf(arg, "i:%d:%d",
&before, &n) != 2)
FATAL_USAGE_INSERT();
PMEMoid it;
pmemobj_alloc(pop, &it,
sizeof(struct oob_item), 0, NULL, NULL);
if (list_insert(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
it)) {
UT_FATAL("list_insert(List) failed");
}
}
/*
* do_remove_free -- remove and free element from list
*/
static void
do_remove_free(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
int n; /* which element */
int N; /* remove from single/both lists */
if (sscanf(arg, "f:%d:%d:%d", &L, &n, &N) != 3)
FATAL_USAGE_REMOVE_FREE();
PMEMoid oid;
if (L == 2) {
oid = get_item_list(List.oid, n);
} else {
FATAL_USAGE_REMOVE_FREE();
}
if (N == 1) {
if (list_remove_free_user(pop,
0,
NULL,
&oid)) {
UT_FATAL("list_remove_free(List_oob) failed");
}
} else if (N == 2) {
if (list_remove_free_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
&oid)) {
UT_FATAL("list_remove_free(List_oob, List) failed");
}
} else {
FATAL_USAGE_REMOVE_FREE();
}
}
/*
* do_remove -- remove element from list
*/
static void
do_remove(PMEMobjpool *pop, const char *arg)
{
int n; /* which element */
if (sscanf(arg, "r:%d", &n) != 1)
FATAL_USAGE_REMOVE();
if (list_remove(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n))) {
UT_FATAL("list_remove(List) failed");
}
}
/*
* do_move -- move element from one list to another
*/
static void
do_move(PMEMobjpool *pop, const char *arg)
{
int n;
int d;
int before;
if (sscanf(arg, "m:%d:%d:%d", &n, &before, &d) != 3)
FATAL_USAGE_MOVE();
if (list_move(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
offsetof(struct item, next),
(struct list_head *)&D_RW(List_sec)->head,
get_item_list(List_sec.oid, d),
before,
get_item_list(List.oid, n))) {
UT_FATAL("list_move(List, List_sec) failed");
}
}
/*
* do_move_one_list -- move element within one list
*/
static void
do_move_one_list(PMEMobjpool *pop, const char *arg)
{
int n;
int d;
int before;
if (sscanf(arg, "M:%d:%d:%d", &n, &before, &d) != 3)
FATAL_USAGE_MOVE();
if (list_move(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, d),
before,
get_item_list(List.oid, n))) {
UT_FATAL("list_move(List, List) failed");
}
}
/*
* do_fail -- fail after specified event
*/
static void
do_fail(PMEMobjpool *pop, const char *arg)
{
if (strcmp(arg, "F:before_finish") == 0) {
Ulog_fail = FAIL_BEFORE_FINISH;
} else if (strcmp(arg, "F:after_finish") == 0) {
Ulog_fail = FAIL_AFTER_FINISH;
} else if (strcmp(arg, "F:after_process") == 0) {
Ulog_fail = FAIL_AFTER_PROCESS;
} else {
FATAL_USAGE_FAIL();
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_list");
if (argc < 2)
FATAL_USAGE();
const char *path = argv[1];
util_init(); /* to initialize On_valgrind flag */
UT_COMPILE_ERROR_ON(OOB_OFF != 48);
PMEMobjpool *pop = pmemobj_open(path, NULL);
UT_ASSERTne(pop, NULL);
UT_ASSERT(!TOID_IS_NULL(List));
UT_ASSERT(!TOID_IS_NULL(List_oob));
int i;
for (i = 2; i < argc; i++) {
switch (argv[i][0]) {
case 'P':
do_print(pop, argv[i]);
break;
case 'R':
do_print_reverse(pop, argv[i]);
break;
case 'n':
do_insert_new(pop, argv[i]);
break;
case 'i':
do_insert(pop, argv[i]);
break;
case 'f':
do_remove_free(pop, argv[i]);
break;
case 'r':
do_remove(pop, argv[i]);
break;
case 'm':
do_move(pop, argv[i]);
break;
case 'M':
do_move_one_list(pop, argv[i]);
break;
case 'V':
lane_recover_and_section_boot(pop);
break;
case 'F':
do_fail(pop, argv[i]);
break;
default:
FATAL_USAGE();
}
}
pmemobj_close(pop);
DONE(NULL);
}
#if defined(__cplusplus) && defined(_MSC_VER)
}
#endif
| 10,502 | 21.882353 | 79 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/blk_rw_mt/blk_rw_mt.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_rw_mt.c -- unit test for multi-threaded random I/O
*
* usage: blk_rw_mt bsize file seed nthread nops
*
*/
#include "unittest.h"
static size_t Bsize;
/* all I/O below this LBA (increases collisions) */
static const unsigned Nblock = 100;
static unsigned Seed;
static unsigned Nthread;
static unsigned Nops;
static PMEMblkpool *Handle;
/*
* construct -- build a buffer for writing
*/
static void
construct(int *ordp, unsigned char *buf)
{
for (int i = 0; i < Bsize; i++)
buf[i] = *ordp;
(*ordp)++;
if (*ordp > 255)
*ordp = 1;
}
/*
* check -- check for torn buffers
*/
static void
check(unsigned char *buf)
{
unsigned val = *buf;
for (int i = 1; i < Bsize; i++)
if (buf[i] != val) {
UT_OUT("{%u} TORN at byte %d", val, i);
break;
}
}
/*
* worker -- the work each thread performs
*/
static void *
worker(void *arg)
{
long mytid = (long)(intptr_t)arg;
unsigned myseed = Seed + mytid;
unsigned char *buf = MALLOC(Bsize);
int ord = 1;
for (unsigned i = 0; i < Nops; i++) {
os_off_t lba = os_rand_r(&myseed) % Nblock;
if (os_rand_r(&myseed) % 2) {
/* read */
if (pmemblk_read(Handle, buf, lba) < 0)
UT_OUT("!read lba %zu", lba);
else
check(buf);
} else {
/* write */
construct(&ord, buf);
if (pmemblk_write(Handle, buf, lba) < 0)
UT_OUT("!write lba %zu", lba);
}
}
FREE(buf);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_rw_mt");
if (argc != 6)
UT_FATAL("usage: %s bsize file seed nthread nops", argv[0]);
Bsize = strtoul(argv[1], NULL, 0);
const char *path = argv[2];
if ((Handle = pmemblk_create(path, Bsize, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!%s: pmemblk_create", path);
Seed = strtoul(argv[3], NULL, 0);
Nthread = strtoul(argv[4], NULL, 0);
Nops = strtoul(argv[5], NULL, 0);
UT_OUT("%s block size %zu usable blocks %u", argv[1], Bsize, Nblock);
os_thread_t *threads = MALLOC(Nthread * sizeof(os_thread_t));
/* kick off nthread threads */
for (unsigned i = 0; i < Nthread; i++)
PTHREAD_CREATE(&threads[i], NULL, worker, (void *)(intptr_t)i);
/* wait for all the threads to complete */
for (unsigned i = 0; i < Nthread; i++)
PTHREAD_JOIN(&threads[i], NULL);
FREE(threads);
pmemblk_close(Handle);
/* XXX not ready to pass this part of the test yet */
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);
}
| 4,184 | 25.487342 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/set_funcs/set_funcs.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.
*/
/*
* set_funcs.c -- unit test for pmem*_set_funcs()
*/
#include "unittest.h"
#define EXISTING_FILE "/root"
#define NON_ZERO_POOL_SIZE 1
#define GUARD 0x2BEE5AFEULL
#define EXTRA sizeof(GUARD)
#define OBJ 0
#define BLK 1
#define LOG 2
#define CTO 3
#define VMEM_ 4
#define VMEM_POOLS 4
static struct counters {
int mallocs;
int frees;
int reallocs;
int reallocs_null;
int strdups;
} cnt[5];
static void *
test_malloc(size_t size)
{
unsigned long long *p = malloc(size + EXTRA);
UT_ASSERTne(p, NULL);
*p = GUARD;
return ++p;
}
static void
test_free(void *ptr)
{
if (ptr == NULL)
return;
unsigned long long *p = ptr;
--p;
UT_ASSERTeq(*p, GUARD);
free(p);
}
static void *
test_realloc(void *ptr, size_t size)
{
unsigned long long *p;
if (ptr != NULL) {
p = ptr;
--p;
UT_ASSERTeq(*p, GUARD);
p = realloc(p, size + EXTRA);
} else {
p = malloc(size + EXTRA);
}
UT_ASSERTne(p, NULL);
*p = GUARD;
return ++p;
}
static char *
test_strdup(const char *s)
{
if (s == NULL)
return NULL;
size_t size = strlen(s) + 1;
unsigned long long *p = malloc(size + EXTRA);
UT_ASSERTne(p, NULL);
*p = GUARD;
++p;
strcpy((char *)p, s);
return (char *)p;
}
static void *
obj_malloc(size_t size)
{
cnt[OBJ].mallocs++;
return test_malloc(size);
}
static void
obj_free(void *ptr)
{
if (ptr)
cnt[OBJ].frees++;
test_free(ptr);
}
static void *
obj_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[OBJ].reallocs_null++;
else
cnt[OBJ].reallocs++;
return test_realloc(ptr, size);
}
static char *
obj_strdup(const char *s)
{
cnt[OBJ].strdups++;
return test_strdup(s);
}
static void *
blk_malloc(size_t size)
{
cnt[BLK].mallocs++;
return test_malloc(size);
}
static void
blk_free(void *ptr)
{
if (ptr)
cnt[BLK].frees++;
test_free(ptr);
}
static void *
blk_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[BLK].reallocs_null++;
else
cnt[BLK].reallocs++;
return test_realloc(ptr, size);
}
static char *
blk_strdup(const char *s)
{
cnt[BLK].strdups++;
return test_strdup(s);
}
static void *
log_malloc(size_t size)
{
cnt[LOG].mallocs++;
return test_malloc(size);
}
static void
log_free(void *ptr)
{
if (ptr)
cnt[LOG].frees++;
test_free(ptr);
}
static void *
log_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[LOG].reallocs_null++;
else
cnt[LOG].reallocs++;
return test_realloc(ptr, size);
}
static char *
log_strdup(const char *s)
{
cnt[LOG].strdups++;
return test_strdup(s);
}
static void *
_vmem_malloc(size_t size)
{
cnt[VMEM_].mallocs++;
return test_malloc(size);
}
static void
_vmem_free(void *ptr)
{
if (ptr)
cnt[VMEM_].frees++;
test_free(ptr);
}
static void *
_vmem_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[VMEM_].reallocs_null++;
else
cnt[VMEM_].reallocs++;
return test_realloc(ptr, size);
}
static char *
_vmem_strdup(const char *s)
{
cnt[VMEM_].strdups++;
return test_strdup(s);
}
static void *
cto_malloc(size_t size)
{
cnt[CTO].mallocs++;
return test_malloc(size);
}
static void
cto_free(void *ptr)
{
if (ptr)
cnt[CTO].frees++;
test_free(ptr);
}
static void *
cto_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[CTO].reallocs_null++;
else
cnt[CTO].reallocs++;
return test_realloc(ptr, size);
}
static char *
cto_strdup(const char *s)
{
cnt[CTO].strdups++;
return test_strdup(s);
}
/*
* There are a few allocations made at first call to pmemobj_open() or
* pmemobj_create(). They are related to some global structures
* holding a list of all open pools. These allocation are not released on
* pmemobj_close(), but in the library destructor. So, we need to take them
* into account when detecting memory leaks.
*
* obj_init/obj_pool_init:
* cuckoo_new - Malloc + Zalloc
* ctree_new - Malloc
* lane_info_ht_boot/lane_info_create:
* cuckoo_new - Malloc + Zalloc
*/
#define OBJ_EXTRA_NALLOC 5
static void
test_obj(const char *path)
{
pmemobj_set_funcs(obj_malloc, obj_free, obj_realloc, obj_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemobj_create(EXISTING_FILE, "", NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMobjpool *pop;
pop = pmemobj_create(path, NULL, PMEMOBJ_MIN_POOL, 0600);
PMEMoid oid;
if (pmemobj_alloc(pop, &oid, 10, 0, NULL, NULL))
UT_FATAL("!alloc");
if (pmemobj_realloc(pop, &oid, 100, 0))
UT_FATAL("!realloc");
pmemobj_free(&oid);
pmemobj_close(pop);
UT_OUT("obj_mallocs: %d", cnt[OBJ].mallocs);
UT_OUT("obj_frees: %d", cnt[OBJ].frees);
UT_OUT("obj_reallocs: %d", cnt[OBJ].reallocs);
UT_OUT("obj_reallocs_null: %d", cnt[OBJ].reallocs_null);
UT_OUT("obj_strdups: %d", cnt[OBJ].strdups);
if (cnt[OBJ].mallocs == 0 || cnt[OBJ].frees == 0)
UT_FATAL("OBJ mallocs: %d, frees: %d", cnt[OBJ].mallocs,
cnt[OBJ].frees);
for (int i = 0; i < 5; ++i) {
if (i == OBJ)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("OBJ allocation used %d functions", i);
}
if (cnt[OBJ].mallocs + cnt[OBJ].strdups + cnt[OBJ].reallocs_null !=
cnt[OBJ].frees + OBJ_EXTRA_NALLOC)
UT_FATAL("OBJ memory leak");
UNLINK(path);
}
static void
test_blk(const char *path)
{
pmemblk_set_funcs(blk_malloc, blk_free, blk_realloc, blk_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemblk_create(EXISTING_FILE, 0, NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMblkpool *blk = pmemblk_create(path, 512, PMEMBLK_MIN_POOL, 0600);
pmemblk_close(blk);
UT_OUT("blk_mallocs: %d", cnt[BLK].mallocs);
UT_OUT("blk_frees: %d", cnt[BLK].frees);
UT_OUT("blk_reallocs: %d", cnt[BLK].reallocs);
UT_OUT("blk_reallocs_null: %d", cnt[BLK].reallocs_null);
UT_OUT("blk_strdups: %d", cnt[BLK].strdups);
if (cnt[BLK].mallocs == 0 || cnt[BLK].frees == 0)
UT_FATAL("BLK mallocs: %d, frees: %d", cnt[BLK].mallocs,
cnt[BLK].frees);
for (int i = 0; i < 5; ++i) {
if (i == BLK)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("BLK allocation used %d functions", i);
}
if (cnt[BLK].mallocs + cnt[BLK].strdups + cnt[BLK].reallocs_null
!= cnt[BLK].frees)
UT_FATAL("BLK memory leak");
UNLINK(path);
}
static void
test_log(const char *path)
{
pmemlog_set_funcs(log_malloc, log_free, log_realloc, log_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemlog_create(EXISTING_FILE, NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMlogpool *log = pmemlog_create(path, PMEMLOG_MIN_POOL, 0600);
pmemlog_close(log);
UT_OUT("log_mallocs: %d", cnt[LOG].mallocs);
UT_OUT("log_frees: %d", cnt[LOG].frees);
UT_OUT("log_reallocs: %d", cnt[LOG].reallocs);
UT_OUT("log_reallocs_null: %d", cnt[LOG].reallocs_null);
UT_OUT("log_strdups: %d", cnt[LOG].strdups);
if (cnt[LOG].mallocs == 0 || cnt[LOG].frees == 0)
UT_FATAL("LOG mallocs: %d, frees: %d", cnt[LOG].mallocs,
cnt[LOG].frees);
for (int i = 0; i < 5; ++i) {
if (i == LOG)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("LOG allocation used %d functions", i);
}
if (cnt[LOG].mallocs + cnt[LOG].strdups + cnt[LOG].reallocs_null
!= cnt[LOG].frees)
UT_FATAL("LOG memory leak");
UNLINK(path);
}
/*
* There are a few allocations made at first call to pmemcto_malloc(),
* pmemcto_realloc(), etc.
* They are related to some global jemalloc structures in TSD, holding
* a list of all open pools. These allocation are not released on
* pmemcto_close(), but in the library destructor. So, we need to take them
* into account when detecting memory leaks.
* Same applies to errormsg buffer, which is allocated on the first error
* and released in library dtor.
*
* tcache_tsd - 2 * Zalloc
* areanas_tsd - 2 * Zalloc
*/
#define CTO_EXTRA_NALLOC 4
static void
test_cto(const char *path)
{
pmemcto_set_funcs(cto_malloc, cto_free, cto_realloc, cto_strdup, NULL);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemcto_create(EXISTING_FILE, "", NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMctopool *pcp;
pcp = pmemcto_create(path, "test", PMEMCTO_MIN_POOL, 0600);
void *ptr = pmemcto_malloc(pcp, 10);
UT_ASSERTne(ptr, NULL);
ptr = pmemcto_realloc(pcp, ptr, 100);
UT_ASSERTne(ptr, NULL);
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
UT_OUT("cto_mallocs: %d", cnt[CTO].mallocs);
UT_OUT("cto_frees: %d", cnt[CTO].frees);
UT_OUT("cto_reallocs: %d", cnt[CTO].reallocs);
UT_OUT("cto_reallocs_null: %d", cnt[CTO].reallocs_null);
UT_OUT("cto_strdups: %d", cnt[CTO].strdups);
if (cnt[CTO].mallocs == 0 || cnt[CTO].frees == 0)
UT_FATAL("CTO mallocs: %d, frees: %d", cnt[CTO].mallocs,
cnt[CTO].frees);
for (int i = 0; i < 5; ++i) {
if (i == CTO)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("CTO allocation used %d functions", i);
}
if (cnt[CTO].mallocs + cnt[CTO].strdups + cnt[CTO].reallocs_null !=
cnt[CTO].frees + CTO_EXTRA_NALLOC)
UT_FATAL("CTO memory leak");
UNLINK(path);
}
static void
test_vmem(const char *dir)
{
vmem_set_funcs(_vmem_malloc, _vmem_free, _vmem_realloc, _vmem_strdup,
NULL);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
vmem_create(EXISTING_FILE, 0);
memset(cnt, 0, sizeof(cnt));
VMEM *v[VMEM_POOLS];
void *ptr[VMEM_POOLS];
for (int i = 0; i < VMEM_POOLS; i++) {
v[i] = vmem_create(dir, VMEM_MIN_POOL);
ptr[i] = vmem_malloc(v[i], 64);
vmem_free(v[i], ptr[i]);
}
for (int i = 0; i < VMEM_POOLS; i++)
vmem_delete(v[i]);
UT_OUT("vmem_mallocs: %d", cnt[VMEM_].mallocs);
UT_OUT("vmem_frees: %d", cnt[VMEM_].frees);
UT_OUT("vmem_reallocs: %d", cnt[VMEM_].reallocs);
UT_OUT("vmem_reallocs_null: %d", cnt[VMEM_].reallocs_null);
UT_OUT("vmem_strdups: %d", cnt[VMEM_].strdups);
if (cnt[VMEM_].mallocs == 0 && cnt[VMEM_].frees == 0)
UT_FATAL("VMEM mallocs: %d, frees: %d", cnt[VMEM_].mallocs,
cnt[VMEM_].frees);
for (int i = 0; i < 5; ++i) {
if (i == VMEM_)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("VMEM allocation used %d functions", i);
}
if (cnt[VMEM_].mallocs + cnt[VMEM_].strdups + cnt[VMEM_].reallocs_null
> cnt[VMEM_].frees + 4)
UT_FATAL("VMEM memory leak");
}
int
main(int argc, char *argv[])
{
START(argc, argv, "set_funcs");
if (argc < 3)
UT_FATAL("usage: %s file dir", argv[0]);
test_obj(argv[1]);
test_blk(argv[1]);
test_log(argv[1]);
test_cto(argv[1]);
test_vmem(argv[2]);
DONE(NULL);
}
| 12,489 | 21.383513 | 76 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/vmem_malloc/vmem_malloc.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.c -- unit test for vmem_malloc
*
* usage: vmem_malloc [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_malloc");
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(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");
}
int *test = vmem_malloc(vmp, sizeof(int));
UT_ASSERTne(test, NULL);
*test = test_value;
UT_ASSERTeq(*test, test_value);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}
| 2,641 | 29.72093 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/obj_ctl_stats/obj_ctl_stats.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_stats.c -- tests for the libpmemobj statistics module
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_stats");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, "ctl", PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
int enabled;
int ret = pmemobj_ctl_get(pop, "stats.enabled", &enabled);
UT_ASSERTeq(enabled, 0);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, NULL, 1, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
size_t allocated;
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(allocated, 0);
enabled = 1;
ret = pmemobj_ctl_set(pop, "stats.enabled", &enabled);
UT_ASSERTeq(ret, 0);
PMEMoid oid;
ret = pmemobj_alloc(pop, &oid, 1, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
size_t oid_size = pmemobj_alloc_usable_size(oid) + 16;
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(allocated, oid_size);
pmemobj_free(&oid);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(allocated, 0);
pmemobj_close(pop);
DONE(NULL);
}
| 2,867 | 31.224719 | 74 | c |
null | NearPMSW-main/nearpm/shadow/redis-NDP-sd/deps/pmdk/src/test/traces_custom_function/traces_custom_function.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_custom_function.c -- unit test for traces with custom print or
* vsnprintf functions
*
* usage: traces_custom_function [v|p]
*
*/
#define LOG_PREFIX "trace_func"
#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 "pmemcommon.h"
#include "unittest.h"
/*
* print_custom_function -- Custom function to handle output
*
* This is called from the library to print text instead of output to stderr.
*/
static void
print_custom_function(const char *s)
{
if (s) {
UT_OUT("CUSTOM_PRINT: %s", s);
} else {
UT_OUT("CUSTOM_PRINT(NULL)");
}
}
/*
* vsnprintf_custom_function -- Custom vsnprintf implementation
*
* It modifies format by adding @@ in front of each conversion specification.
*/
static int
vsnprintf_custom_function(char *str, size_t size, const char *format,
va_list ap)
{
char *format2 = MALLOC(strlen(format) * 3);
int i = 0;
int ret_val;
while (*format != '\0') {
if (*format == '%') {
format2[i++] = '@';
format2[i++] = '@';
}
format2[i++] = *format++;
}
format2[i++] = '\0';
ret_val = vsnprintf(str, size, format2, ap);
FREE(format2);
return ret_val;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "traces_custom_function");
if (argc != 2)
UT_FATAL("usage: %s [v|p]", argv[0]);
out_set_print_func(print_custom_function);
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
switch (argv[1][0]) {
case 'p': {
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");
}
break;
case 'v':
out_set_vsnprintf_func(vsnprintf_custom_function);
LOG(0, "no format");
LOG(0, "pointer: %p", (void *)0x12345678);
LOG(0, "string: %s", "Hello world!");
LOG(0, "number: %u", 12345678);
errno = EINVAL;
LOG(0, "!error");
break;
default:
UT_FATAL("usage: %s [v|p]", argv[0]);
}
/* Cleanup */
common_fini();
DONE(NULL);
}
| 3,671 | 26 | 77 | c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.