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/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_recovery/blk_recovery.c
/* * Copyright 2014-2018, Intel Corporation * Copyright (c) 2016, Microsoft Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_recovery.c -- unit test for pmemblk recovery * * usage: blk_recovery bsize file first_lba lba * */ #include "unittest.h" #include <sys/param.h> #include "blk.h" #include "btt_layout.h" #include <endian.h> static size_t Bsize; /* * construct -- build a buffer for writing */ static void construct(unsigned char *buf) { static int ord = 1; for (int i = 0; i < Bsize; i++) buf[i] = ord; ord++; if (ord > 255) ord = 1; } /* * ident -- identify what a buffer holds */ static char * ident(unsigned char *buf) { static char descr[100]; unsigned val = *buf; for (int i = 1; i < Bsize; i++) if (buf[i] != val) { sprintf(descr, "{%u} TORN at byte %d", val, i); return descr; } sprintf(descr, "{%u}", val); return descr; } static ut_jmp_buf_t Jmp; /* * signal_handler -- called on SIGSEGV */ static void signal_handler(int sig) { UT_OUT("signal: %s", os_strsignal(sig)); ut_siglongjmp(Jmp); } int main(int argc, char *argv[]) { START(argc, argv, "blk_recovery"); if (argc != 5) UT_FATAL("usage: %s bsize file first_lba lba", argv[0]); Bsize = strtoul(argv[1], NULL, 0); const char *path = argv[2]; PMEMblkpool *handle; if ((handle = pmemblk_create(path, Bsize, 0, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!%s: pmemblk_create", path); UT_OUT("%s block size %zu usable blocks %zu", argv[1], Bsize, pmemblk_nblock(handle)); /* write the first lba */ os_off_t lba = STRTOL(argv[3], NULL, 0); unsigned char *buf = MALLOC(Bsize); construct(buf); if (pmemblk_write(handle, buf, lba) < 0) UT_FATAL("!write lba %zu", lba); UT_OUT("write lba %zu: %s", lba, ident(buf)); /* reach into the layout and write-protect the map */ struct btt_info *infop = (void *)((char *)handle + roundup(sizeof(struct pmemblk), BLK_FORMAT_DATA_ALIGN)); char *mapaddr = (char *)infop + le32toh(infop->mapoff); char *flogaddr = (char *)infop + le32toh(infop->flogoff); UT_OUT("write-protecting map, length %zu", (size_t)(flogaddr - mapaddr)); MPROTECT(mapaddr, (size_t)(flogaddr - mapaddr), PROT_READ); /* arrange to catch SEGV */ struct sigaction v; sigemptyset(&v.sa_mask); v.sa_flags = 0; v.sa_handler = signal_handler; SIGACTION(SIGSEGV, &v, NULL); /* map each file argument with the given map type */ lba = STRTOL(argv[4], NULL, 0); construct(buf); if (!ut_sigsetjmp(Jmp)) { if (pmemblk_write(handle, buf, lba) < 0) UT_FATAL("!write lba %zu", lba); else UT_FATAL("write lba %zu: %s", lba, ident(buf)); } pmemblk_close(handle); FREE(buf); int result = pmemblk_check(path, Bsize); if (result < 0) UT_OUT("!%s: pmemblk_check", path); else if (result == 0) UT_OUT("%s: pmemblk_check: not consistent", path); else UT_OUT("%s: consistent", path); DONE(NULL); }
4,446
24.854651
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/out_err_mt/out_err_mt.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * out_err_mt.c -- unit test for error messages */ #include <sys/types.h> #include <stdarg.h> #include <errno.h> #include "unittest.h" #include "valgrind_internal.h" #include "util.h" #define NUM_THREADS 16 static void print_errors(const char *msg) { UT_OUT("%s", msg); UT_OUT("PMEM: %s", pmem_errormsg()); UT_OUT("PMEMOBJ: %s", pmemobj_errormsg()); UT_OUT("PMEMLOG: %s", pmemlog_errormsg()); UT_OUT("PMEMBLK: %s", pmemblk_errormsg()); UT_OUT("PMEMCTO: %s", pmemcto_errormsg()); UT_OUT("VMEM: %s", vmem_errormsg()); UT_OUT("PMEMPOOL: %s", pmempool_errormsg()); } static void check_errors(unsigned ver) { int ret; int err_need; int err_found; ret = sscanf(pmem_errormsg(), "libpmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEM_MAJOR_VERSION); ret = sscanf(pmemobj_errormsg(), "libpmemobj major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMOBJ_MAJOR_VERSION); ret = sscanf(pmemlog_errormsg(), "libpmemlog major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMLOG_MAJOR_VERSION); ret = sscanf(pmemblk_errormsg(), "libpmemblk major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMBLK_MAJOR_VERSION); ret = sscanf(pmemcto_errormsg(), "libpmemcto major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMCTO_MAJOR_VERSION); ret = sscanf(vmem_errormsg(), "libvmem major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, VMEM_MAJOR_VERSION); ret = sscanf(pmempool_errormsg(), "libpmempool major version mismatch (need %d, found %d)", &err_need, &err_found); UT_ASSERTeq(ret, 2); UT_ASSERTeq(err_need, ver); UT_ASSERTeq(err_found, PMEMPOOL_MAJOR_VERSION); } static void * do_test(void *arg) { unsigned ver = *(unsigned *)arg; pmem_check_version(ver, 0); pmemobj_check_version(ver, 0); pmemlog_check_version(ver, 0); pmemblk_check_version(ver, 0); pmemcto_check_version(ver, 0); vmem_check_version(ver, 0); pmempool_check_version(ver, 0); check_errors(ver); return NULL; } static void run_mt_test(void *(*worker)(void *)) { os_thread_t thread[NUM_THREADS]; unsigned ver[NUM_THREADS]; for (unsigned i = 0; i < NUM_THREADS; ++i) { ver[i] = 10000 + i; PTHREAD_CREATE(&thread[i], NULL, worker, &ver[i]); } for (unsigned i = 0; i < NUM_THREADS; ++i) { PTHREAD_JOIN(&thread[i], NULL); } } int main(int argc, char *argv[]) { START(argc, argv, "out_err_mt"); if (argc != 6) UT_FATAL("usage: %s file1 file2 file3 file4 dir", argv[0]); print_errors("start"); PMEMobjpool *pop = pmemobj_create(argv[1], "test", PMEMOBJ_MIN_POOL, 0666); PMEMlogpool *plp = pmemlog_create(argv[2], PMEMLOG_MIN_POOL, 0666); PMEMblkpool *pbp = pmemblk_create(argv[3], 128, PMEMBLK_MIN_POOL, 0666); PMEMctopool *pcp = pmemcto_create(argv[4], "test", PMEMCTO_MIN_POOL, 0666); VMEM *vmp = vmem_create(argv[5], VMEM_MIN_POOL); util_init(); pmem_check_version(10000, 0); pmemobj_check_version(10001, 0); pmemlog_check_version(10002, 0); pmemblk_check_version(10003, 0); pmemcto_check_version(10004, 0); vmem_check_version(10005, 0); pmempool_check_version(10006, 0); print_errors("version check"); void *ptr = NULL; /* * We are testing library error reporting and we don't want this test * to fail under memcheck. */ VALGRIND_DO_DISABLE_ERROR_REPORTING; pmem_msync(ptr, 1); VALGRIND_DO_ENABLE_ERROR_REPORTING; print_errors("pmem_msync"); int ret; PMEMoid oid; ret = pmemobj_alloc(pop, &oid, 0, 0, NULL, NULL); UT_ASSERTeq(ret, -1); print_errors("pmemobj_alloc"); pmemlog_append(plp, NULL, PMEMLOG_MIN_POOL); print_errors("pmemlog_append"); size_t nblock = pmemblk_nblock(pbp); pmemblk_set_error(pbp, (long long)nblock + 1); print_errors("pmemblk_set_error"); ret = pmemcto_check(argv[4], "xxx"); UT_ASSERTeq(ret, -1); print_errors("pmemcto_check"); VMEM *vmp2 = vmem_create_in_region(NULL, 1); UT_ASSERTeq(vmp2, NULL); print_errors("vmem_create_in_region"); run_mt_test(do_test); pmemobj_close(pop); pmemlog_close(plp); pmemblk_close(pbp); pmemcto_close(pcp); vmem_delete(vmp); PMEMpoolcheck *ppc; struct pmempool_check_args args = {NULL, }; ppc = pmempool_check_init(&args, sizeof(args) / 2); UT_ASSERTeq(ppc, NULL); print_errors("pmempool_check_init"); DONE(NULL); }
6,370
27.066079
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_api/libpmempool_test.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool_test -- test of libpmempool. * */ #include <stddef.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <getopt.h> #include "unittest.h" /* * Exact copy of the struct pmempool_check_args from libpmempool 1.0 provided to * test libpmempool against various pmempool_check_args structure versions. */ struct pmempool_check_args_1_0 { const char *path; const char *backup_path; enum pmempool_pool_type pool_type; int flags; }; /* * check_pool -- check given pool */ static void check_pool(struct pmempool_check_args *args, size_t args_size) { const char *status2str[] = { [PMEMPOOL_CHECK_RESULT_CONSISTENT] = "consistent", [PMEMPOOL_CHECK_RESULT_NOT_CONSISTENT] = "not consistent", [PMEMPOOL_CHECK_RESULT_REPAIRED] = "repaired", [PMEMPOOL_CHECK_RESULT_CANNOT_REPAIR] = "cannot repair", [PMEMPOOL_CHECK_RESULT_ERROR] = "fatal", }; PMEMpoolcheck *ppc = pmempool_check_init(args, args_size); if (!ppc) { char buff[UT_MAX_ERR_MSG]; ut_strerror(errno, buff, UT_MAX_ERR_MSG); UT_OUT("Error: %s", buff); return; } struct pmempool_check_status *status = NULL; while ((status = pmempool_check(ppc)) != NULL) { switch (status->type) { case PMEMPOOL_CHECK_MSG_TYPE_ERROR: UT_OUT("%s", status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_INFO: UT_OUT("%s", status->str.msg); break; case PMEMPOOL_CHECK_MSG_TYPE_QUESTION: UT_OUT("%s", status->str.msg); status->str.answer = "yes"; break; default: pmempool_check_end(ppc); exit(EXIT_FAILURE); } } enum pmempool_check_result ret = pmempool_check_end(ppc); UT_OUT("status = %s", status2str[ret]); } /* * print_usage -- print usage of program */ static void print_usage(char *name) { UT_OUT("Usage: %s [-t <pool_type>] [-r <repair>] [-d <dry_run>] " "[-y <always_yes>] [-f <flags>] [-a <advanced>] " "[-b <backup_path>] <pool_path>", name); } /* * set_flag -- parse the value and set the flag according to a obtained value */ static void set_flag(const char *value, int *flags, int flag) { if (atoi(value) > 0) *flags |= flag; else *flags &= ~flag; } int main(int argc, char *argv[]) { START(argc, argv, "libpmempool_test"); int opt; struct pmempool_check_args_1_0 args = { .path = NULL, .backup_path = NULL, .pool_type = PMEMPOOL_POOL_TYPE_LOG, .flags = PMEMPOOL_CHECK_FORMAT_STR | PMEMPOOL_CHECK_REPAIR | PMEMPOOL_CHECK_VERBOSE }; size_t args_size = sizeof(struct pmempool_check_args_1_0); while ((opt = getopt(argc, argv, "t:r:d:a:y:s:b:")) != -1) { switch (opt) { case 't': if (strcmp(optarg, "blk") == 0) { args.pool_type = PMEMPOOL_POOL_TYPE_BLK; } else if (strcmp(optarg, "log") == 0) { args.pool_type = PMEMPOOL_POOL_TYPE_LOG; } else if (strcmp(optarg, "obj") == 0) { args.pool_type = PMEMPOOL_POOL_TYPE_OBJ; } else if (strcmp(optarg, "btt") == 0) { args.pool_type = PMEMPOOL_POOL_TYPE_BTT; } else { args.pool_type = (uint32_t)strtoul(optarg, NULL, 0); } break; case 'r': set_flag(optarg, &args.flags, PMEMPOOL_CHECK_REPAIR); break; case 'd': set_flag(optarg, &args.flags, PMEMPOOL_CHECK_DRY_RUN); break; case 'a': set_flag(optarg, &args.flags, PMEMPOOL_CHECK_ADVANCED); break; case 'y': set_flag(optarg, &args.flags, PMEMPOOL_CHECK_ALWAYS_YES); break; case 's': args_size = strtoul(optarg, NULL, 0); break; case 'b': args.backup_path = optarg; break; default: print_usage(argv[0]); UT_FATAL("unknown option: %c", opt); } } if (optind < argc) { args.path = argv[optind]; } check_pool((struct pmempool_check_args *)&args, args_size); DONE(NULL); }
5,268
26.731579
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_nblock/blk_nblock.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_nblock.c -- unit test for pmemblk_nblock() * * usage: blk_nblock bsize:file... * */ #include "unittest.h" int main(int argc, char *argv[]) { START(argc, argv, "blk_nblock"); if (argc < 2) UT_FATAL("usage: %s bsize:file...", argv[0]); /* map each file argument with the given map type */ for (int arg = 1; arg < argc; arg++) { char *fname; size_t bsize = strtoul(argv[arg], &fname, 0); if (*fname != ':') UT_FATAL("usage: %s bsize:file...", argv[0]); fname++; PMEMblkpool *handle; handle = pmemblk_create(fname, bsize, 0, S_IWUSR | S_IRUSR); if (handle == NULL) { UT_OUT("!%s: pmemblk_create", fname); } else { UT_OUT("%s: block size %zu usable blocks: %zu", fname, bsize, pmemblk_nblock(handle)); UT_ASSERTeq(pmemblk_bsize(handle), bsize); pmemblk_close(handle); int result = pmemblk_check(fname, bsize); if (result < 0) UT_OUT("!%s: pmemblk_check", fname); else if (result == 0) UT_OUT("%s: pmemblk_check: not consistent", fname); else { UT_ASSERTeq(pmemblk_check(fname, bsize + 1), -1); UT_ASSERTeq(pmemblk_check(fname, 0), 1); handle = pmemblk_open(fname, 0); UT_ASSERTeq(pmemblk_bsize(handle), bsize); pmemblk_close(handle); } } } DONE(NULL); }
2,873
32.034483
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_non_zero/blk_non_zero.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_non_zero.c -- unit test for pmemblk_read/write/set_zero/set_error * * usage: blk_non_zero bsize file func operation:lba... * * func is 'c' or 'o' (create or open) * operations are 'r' or 'w' or 'z' or 'e' * */ #define _GNU_SOURCE #include <sys/param.h> #include "unittest.h" #include "blk.h" static size_t Bsize; /* * construct -- build a buffer for writing */ static void construct(unsigned char *buf) { static int ord = 1; for (int i = 0; i < Bsize; i++) buf[i] = ord; ord++; if (ord > 255) ord = 1; } /* * ident -- identify what a buffer holds */ static char * ident(unsigned char *buf) { static char descr[100]; unsigned val = *buf; for (int i = 1; i < Bsize; i++) if (buf[i] != val) { sprintf(descr, "{%u} TORN at byte %d", val, i); return descr; } sprintf(descr, "{%u}", val); return descr; } /* * is_zeroed -- read is_zeroed flag from header */ static int is_zeroed(const char *path) { int fd = OPEN(path, O_RDWR); os_stat_t stbuf; FSTAT(fd, &stbuf); void *addr = MMAP(NULL, (size_t)stbuf.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); struct pmemblk *header = addr; int ret = header->is_zeroed; MUNMAP(addr, (size_t)stbuf.st_size); CLOSE(fd); return ret; } int main(int argc, char *argv[]) { START(argc, argv, "blk_non_zero"); if (argc < 5) UT_FATAL("usage: %s bsize file func [file_size] op:lba...", argv[0]); int read_arg = 1; Bsize = strtoul(argv[read_arg++], NULL, 0); const char *path = argv[read_arg++]; PMEMblkpool *handle = NULL; switch (*argv[read_arg++]) { case 'c': { size_t fsize = strtoul(argv[read_arg++], NULL, 0); handle = pmemblk_create(path, Bsize, fsize, S_IRUSR | S_IWUSR); if (handle == NULL) UT_FATAL("!%s: pmemblk_create", path); break; } case 'o': handle = pmemblk_open(path, Bsize); if (handle == NULL) UT_FATAL("!%s: pmemblk_open", path); break; default: UT_FATAL("unrecognized command %s", argv[read_arg - 1]); } UT_OUT("%s block size %zu usable blocks %zu", argv[1], Bsize, pmemblk_nblock(handle)); UT_OUT("is zeroed:\t%d", is_zeroed(path)); unsigned char *buf = MALLOC(Bsize); if (buf == NULL) UT_FATAL("cannot allocate buf"); /* map each file argument with the given map type */ for (; read_arg < argc; read_arg++) { if (strchr("rwze", argv[read_arg][0]) == NULL || argv[read_arg][1] != ':') UT_FATAL("op must be r: or w: or z: or e:"); os_off_t lba = STRTOL(&argv[read_arg][2], NULL, 0); switch (argv[read_arg][0]) { case 'r': if (pmemblk_read(handle, buf, lba) < 0) UT_OUT("!read lba %zu", lba); else UT_OUT("read lba %zu: %s", lba, ident(buf)); break; case 'w': construct(buf); if (pmemblk_write(handle, buf, lba) < 0) UT_OUT("!write lba %zu", lba); else UT_OUT("write lba %zu: %s", lba, ident(buf)); break; case 'z': if (pmemblk_set_zero(handle, lba) < 0) UT_OUT("!set_zero lba %zu", lba); else UT_OUT("set_zero lba %zu", lba); break; case 'e': if (pmemblk_set_error(handle, lba) < 0) UT_OUT("!set_error lba %zu", lba); else UT_OUT("set_error lba %zu", lba); break; } } FREE(buf); pmemblk_close(handle); int result = pmemblk_check(path, Bsize); if (result < 0) UT_OUT("!%s: pmemblk_check", path); else if (result == 0) UT_OUT("%s: pmemblk_check: not consistent", path); DONE(NULL); }
5,032
23.31401
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_invalid/obj_tx_invalid.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_invalid.c -- tests which transactional functions are available in * which transaction stages */ #include <stddef.h> #include "file.h" #include "unittest.h" /* * Layout definition */ POBJ_LAYOUT_BEGIN(tx_invalid); POBJ_LAYOUT_ROOT(tx_invalid, struct dummy_root); POBJ_LAYOUT_TOID(tx_invalid, struct dummy_node); POBJ_LAYOUT_END(tx_invalid); struct dummy_node { int value; }; struct dummy_root { TOID(struct dummy_node) node; }; int main(int argc, char *argv[]) { if (argc != 3) UT_FATAL("usage: %s file-name op", argv[0]); START(argc, argv, "obj_tx_invalid %s", argv[2]); /* root doesn't count */ UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(tx_invalid) != 1); PMEMobjpool *pop; const char *path = argv[1]; int exists = util_file_exists(path); if (exists < 0) UT_FATAL("!util_file_exists"); if (!exists) { if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(tx_invalid), PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) { UT_FATAL("!pmemobj_create %s", path); } } else { if ((pop = pmemobj_open(path, POBJ_LAYOUT_NAME(tx_invalid))) == NULL) { UT_FATAL("!pmemobj_open %s", path); } } PMEMoid oid = pmemobj_first(pop); if (OID_IS_NULL(oid)) { if (pmemobj_alloc(pop, &oid, 10, 1, NULL, NULL)) UT_FATAL("!pmemobj_alloc"); } else { UT_ASSERTeq(pmemobj_type_num(oid), 1); } if (strcmp(argv[2], "alloc") == 0) pmemobj_tx_alloc(10, 1); else if (strcmp(argv[2], "alloc-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_alloc(10, 1); } TX_END } else if (strcmp(argv[2], "alloc-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_alloc(10, 1); } TX_END } else if (strcmp(argv[2], "alloc-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_alloc(10, 1); } TX_END } else if (strcmp(argv[2], "alloc-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_alloc(10, 1); } TX_END } else if (strcmp(argv[2], "alloc-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_alloc(10, 1); } else if (strcmp(argv[2], "zalloc") == 0) pmemobj_tx_zalloc(10, 1); else if (strcmp(argv[2], "zalloc-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_zalloc(10, 1); } TX_END } else if (strcmp(argv[2], "zalloc-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_zalloc(10, 1); } TX_END } else if (strcmp(argv[2], "zalloc-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_zalloc(10, 1); } TX_END } else if (strcmp(argv[2], "zalloc-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_zalloc(10, 1); } TX_END } else if (strcmp(argv[2], "zalloc-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_zalloc(10, 1); } else if (strcmp(argv[2], "strdup") == 0) pmemobj_tx_strdup("aaa", 1); else if (strcmp(argv[2], "strdup-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_strdup("aaa", 1); } TX_END } else if (strcmp(argv[2], "strdup-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_strdup("aaa", 1); } TX_END } else if (strcmp(argv[2], "strdup-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_strdup("aaa", 1); } TX_END } else if (strcmp(argv[2], "strdup-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_strdup("aaa", 1); } TX_END } else if (strcmp(argv[2], "strdup-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_strdup("aaa", 1); } else if (strcmp(argv[2], "realloc") == 0) pmemobj_tx_realloc(oid, 10, 1); else if (strcmp(argv[2], "realloc-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_realloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "realloc-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_realloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "realloc-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_realloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "realloc-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_realloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "realloc-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_realloc(oid, 10, 1); } else if (strcmp(argv[2], "zrealloc") == 0) pmemobj_tx_zrealloc(oid, 10, 1); else if (strcmp(argv[2], "zrealloc-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_zrealloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "zrealloc-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_zrealloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "zrealloc-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_zrealloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "zrealloc-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_zrealloc(oid, 10, 1); } TX_END } else if (strcmp(argv[2], "zrealloc-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_zrealloc(oid, 10, 1); } else if (strcmp(argv[2], "free") == 0) pmemobj_tx_free(oid); else if (strcmp(argv[2], "free-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_free(oid); } TX_END } else if (strcmp(argv[2], "free-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_free(oid); } TX_END } else if (strcmp(argv[2], "free-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_free(oid); } TX_END } else if (strcmp(argv[2], "free-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_free(oid); } TX_END } else if (strcmp(argv[2], "free-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_free(oid); } else if (strcmp(argv[2], "add_range") == 0) pmemobj_tx_add_range(oid, 0, 10); else if (strcmp(argv[2], "add_range-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_add_range(oid, 0, 10); } TX_END } else if (strcmp(argv[2], "add_range-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_add_range(oid, 0, 10); } TX_END } else if (strcmp(argv[2], "add_range-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_add_range(oid, 0, 10); } TX_END } else if (strcmp(argv[2], "add_range-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_add_range(oid, 0, 10); } TX_END } else if (strcmp(argv[2], "add_range-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_add_range(oid, 0, 10); } else if (strcmp(argv[2], "add_range_direct") == 0) pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); else if (strcmp(argv[2], "add_range_direct-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); } TX_END } else if (strcmp(argv[2], "add_range_direct-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); } TX_END } else if (strcmp(argv[2], "add_range_direct-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); } TX_END } else if (strcmp(argv[2], "add_range_direct-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); } TX_END } else if (strcmp(argv[2], "add_range_direct-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_add_range_direct(pmemobj_direct(oid), 10); } else if (strcmp(argv[2], "abort") == 0) pmemobj_tx_abort(ENOMEM); else if (strcmp(argv[2], "abort-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_END } else if (strcmp(argv[2], "abort-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_abort(ENOMEM); } TX_END } else if (strcmp(argv[2], "abort-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_abort(ENOMEM); } TX_END } else if (strcmp(argv[2], "abort-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_abort(ENOMEM); } TX_END } else if (strcmp(argv[2], "abort-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_abort(ENOMEM); } else if (strcmp(argv[2], "commit") == 0) pmemobj_tx_commit(); else if (strcmp(argv[2], "commit-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_commit(); } TX_END } else if (strcmp(argv[2], "commit-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_commit(); } TX_END } else if (strcmp(argv[2], "commit-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_commit(); } TX_END } else if (strcmp(argv[2], "commit-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_commit(); } TX_END } else if (strcmp(argv[2], "commit-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_commit(); } else if (strcmp(argv[2], "end") == 0) pmemobj_tx_end(); else if (strcmp(argv[2], "end-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_end(); } TX_END } else if (strcmp(argv[2], "end-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_end(); pmemobj_close(pop); exit(0); } TX_END } else if (strcmp(argv[2], "end-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_end(); pmemobj_close(pop); exit(0); } TX_END } else if (strcmp(argv[2], "end-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_end(); pmemobj_close(pop); exit(0); } TX_END } else if (strcmp(argv[2], "end-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_end(); } else if (strcmp(argv[2], "process") == 0) pmemobj_tx_process(); else if (strcmp(argv[2], "process-in-work") == 0) { TX_BEGIN(pop) { pmemobj_tx_process(); } TX_END } else if (strcmp(argv[2], "process-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { pmemobj_tx_process(); } TX_END } else if (strcmp(argv[2], "process-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { pmemobj_tx_process(); } TX_END } else if (strcmp(argv[2], "process-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { pmemobj_tx_process(); pmemobj_tx_end(); pmemobj_close(pop); exit(0); } TX_END } else if (strcmp(argv[2], "process-after-tx") == 0) { TX_BEGIN(pop) { } TX_END pmemobj_tx_process(); } else if (strcmp(argv[2], "begin") == 0) { TX_BEGIN(pop) { } TX_END } else if (strcmp(argv[2], "begin-in-work") == 0) { TX_BEGIN(pop) { TX_BEGIN(pop) { } TX_END } TX_END } else if (strcmp(argv[2], "begin-in-abort") == 0) { TX_BEGIN(pop) { pmemobj_tx_abort(ENOMEM); } TX_ONABORT { TX_BEGIN(pop) { } TX_END } TX_END } else if (strcmp(argv[2], "begin-in-commit") == 0) { TX_BEGIN(pop) { } TX_ONCOMMIT { TX_BEGIN(pop) { } TX_END } TX_END } else if (strcmp(argv[2], "begin-in-finally") == 0) { TX_BEGIN(pop) { } TX_FINALLY { TX_BEGIN(pop) { } TX_END } TX_END } else if (strcmp(argv[2], "begin-after-tx") == 0) { TX_BEGIN(pop) { } TX_END TX_BEGIN(pop) { } TX_END } pmemobj_close(pop); DONE(NULL); }
12,728
25.463617
75
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_valgrind/vmmalloc_valgrind.c
/* * Copyright 2014-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmmalloc_valgrind.c -- unit test for libvmmalloc valgrind * * usage: vmmalloc_valgrind <test-number> * * test-number can be a number from 0 to 2 */ #include "unittest.h" int main(int argc, char *argv[]) { int *ptr; int test_case = -1; START(argc, argv, "vmmalloc_valgrind"); if ((argc != 2) || (test_case = atoi(argv[1])) > 2) UT_FATAL("usage: %s <test-number from 0 to 2>", argv[0]); switch (test_case) { case 0: { UT_OUT("remove all allocations"); ptr = malloc(sizeof(int)); if (ptr == NULL) UT_FATAL("!malloc"); free(ptr); break; } case 1: { UT_OUT("memory leaks"); ptr = malloc(sizeof(int)); if (ptr == NULL) UT_FATAL("!malloc"); /* prevent reporting leaked memory as still reachable */ ptr = NULL; break; } case 2: { UT_OUT("heap block overrun"); ptr = malloc(12 * sizeof(int)); if (ptr == NULL) UT_FATAL("!malloc"); /* heap block overrun */ ptr[12] = 7; free(ptr); break; } default: { UT_FATAL("!unknown test-number"); } } DONE(NULL); }
2,663
27.340426
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_pool_lock/blk_pool_lock.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_pool_lock.c -- unit test which checks whether it's possible to * simultaneously open the same blk pool */ #include "unittest.h" static void test_reopen(const char *path) { PMEMblkpool *blk1 = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL, S_IWUSR | S_IRUSR); if (!blk1) UT_FATAL("!create"); PMEMblkpool *blk2 = pmemblk_open(path, 4096); if (blk2) UT_FATAL("pmemblk_open should not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemblk_open failed but for unexpected reason"); pmemblk_close(blk1); blk2 = pmemblk_open(path, 4096); if (!blk2) UT_FATAL("pmemobj_open should succeed after close"); pmemblk_close(blk2); UNLINK(path); } #ifndef _WIN32 static void test_open_in_different_process(int argc, char **argv, unsigned sleep) { pid_t pid = fork(); PMEMblkpool *blk; char *path = argv[1]; if (pid < 0) UT_FATAL("fork failed"); if (pid == 0) { /* child */ if (sleep) usleep(sleep); while (os_access(path, R_OK)) usleep(100 * 1000); blk = pmemblk_open(path, 4096); if (blk) UT_FATAL("pmemblk_open after fork should not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemblk_open after fork failed but for " "unexpected reason"); exit(0); } blk = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL, S_IWUSR | S_IRUSR); if (!blk) UT_FATAL("!create"); int status; if (waitpid(pid, &status, 0) < 0) UT_FATAL("!waitpid failed"); if (!WIFEXITED(status)) UT_FATAL("child process failed"); pmemblk_close(blk); UNLINK(path); } #else static void test_open_in_different_process(int argc, char **argv, unsigned sleep) { PMEMblkpool *blk; if (sleep > 0) return; char *path = argv[1]; /* before starting the 2nd process, create a pool */ blk = pmemblk_create(path, 4096, PMEMBLK_MIN_POOL, S_IWUSR | S_IRUSR); if (!blk) UT_FATAL("!create"); /* * "X" is pass as an additional param to the new process * created by ut_spawnv to distinguish second process on Windows */ uintptr_t result = ut_spawnv(argc, argv, "X", NULL); if (result != 0) UT_FATAL("Create new process failed error: %d", GetLastError()); pmemblk_close(blk); } #endif int main(int argc, char *argv[]) { START(argc, argv, "blk_pool_lock"); if (argc < 2) UT_FATAL("usage: %s path", argv[0]); if (argc == 2) { test_reopen(argv[1]); test_open_in_different_process(argc, argv, 0); for (unsigned i = 1; i < 100000; i *= 2) test_open_in_different_process(argc, argv, i); } else if (argc == 3) { PMEMblkpool *blk; /* 2nd arg used by windows for 2 process test */ blk = pmemblk_open(argv[1], 4096); if (blk) UT_FATAL("pmemblk_open after create process should " "not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemblk_open after create process failed " "but for unexpected reason"); } DONE(NULL); }
4,438
25.111765
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmem_addr_ext/rpmem_addr_ext.c
/* * Copyright 2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_addr_ext.c -- advanced unittest for invalid target formats */ #include "unittest.h" #include "librpmem.h" #include "pool_hdr.h" #include "set.h" #include "util.h" #include "out.h" #include "rpmem_common.h" #include "rpmem_fip_common.h" #define POOL_SIZE (8 * 1024 * 1024) /* 8 MiB */ #define NLANES 32 #define MAX_TARGET_LENGTH 256 /* * test_prepare -- prepare test environment */ static void test_prepare() { /* * Till fix introduced to libfabric in pull request * https://github.com/ofiwg/libfabric/pull/2551 misuse of errno value * lead to SIGSEGV. */ errno = 0; } /* * test_create -- test case for creating remote pool */ static int test_create(const char *target, void *pool) { const char *pool_set = "invalid.poolset"; unsigned nlanes = NLANES; struct rpmem_pool_attr pool_attr; memset(&pool_attr, 0, sizeof(pool_attr)); RPMEMpool *rpp = rpmem_create(target, pool_set, pool, POOL_SIZE, &nlanes, &pool_attr); UT_ASSERTeq(rpp, NULL); return 0; } /* * test_open -- test case for opening remote pool */ static int test_open(const char *target, void *pool) { const char *pool_set = "invalid.poolset"; unsigned nlanes = NLANES; struct rpmem_pool_attr pool_attr; memset(&pool_attr, 0, sizeof(pool_attr)); RPMEMpool *rpp = rpmem_open(target, pool_set, pool, POOL_SIZE, &nlanes, &pool_attr); UT_ASSERTeq(rpp, NULL); return 0; } int main(int argc, char *argv[]) { START(argc, argv, "rpmem_addr_ext"); if (argc < 2) UT_FATAL("usage: rpmem_addr_ext <targets>"); const char *targets_file_name = argv[1]; char target[MAX_TARGET_LENGTH]; void *pool = PAGEALIGNMALLOC(POOL_SIZE); FILE *targets_file = FOPEN(targets_file_name, "r"); while (fgets(target, sizeof(target), targets_file)) { /* assume each target has new line at the end and remove it */ target[strlen(target) - 1] = '\0'; test_prepare(); test_create(target, pool); test_prepare(); test_open(target, pool); } FCLOSE(targets_file); FREE(pool); DONE(NULL); }
3,604
25.313869
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_check_allocations/vmem_check_allocations.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_check_allocations -- unit test for vmem_check_allocations * * usage: vmem_check_allocations [directory] */ #include "unittest.h" #define TEST_MAX_ALLOCATION_SIZE (4L * 1024L * 1024L) #define TEST_ALLOCS_SIZE (VMEM_MIN_POOL / 8) /* buffer for all allocations */ static void *allocs[TEST_ALLOCS_SIZE]; int main(int argc, char *argv[]) { char *dir = NULL; void *mem_pool = NULL; VMEM *vmp; START(argc, argv, "vmem_check_allocations"); if (argc == 2) { dir = argv[1]; } else if (argc > 2) { UT_FATAL("usage: %s [directory]", argv[0]); } size_t object_size; for (object_size = 8; object_size <= TEST_MAX_ALLOCATION_SIZE; object_size *= 2) { size_t i; size_t j; if (dir == NULL) { mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20); vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); } else { vmp = vmem_create(dir, VMEM_MIN_POOL); if (vmp == NULL) UT_FATAL("!vmem_create"); /* vmem_create should align pool to 4MB */ UT_ASSERTeq(((uintptr_t)vmp) & ((4 << 20) - 1), 0); } memset(allocs, 0, sizeof(allocs)); for (i = 0; i < TEST_ALLOCS_SIZE; ++i) { allocs[i] = vmem_malloc(vmp, object_size); if (allocs[i] == NULL) { /* out of memory in pool */ break; } /* check that pointer came from mem_pool */ if (dir == NULL) { UT_ASSERTrange(allocs[i], mem_pool, VMEM_MIN_POOL); } /* fill each allocation with a unique value */ memset(allocs[i], (char)i, object_size); } UT_ASSERT((i > 0) && (i + 1 < TEST_MAX_ALLOCATION_SIZE)); /* check for unexpected modifications of the data */ for (i = 0; i < TEST_ALLOCS_SIZE && allocs[i] != NULL; ++i) { char *buffer = allocs[i]; for (j = 0; j < object_size; ++j) { if (buffer[j] != (char)i) UT_FATAL("Content of data object was " "modified unexpectedly for " "object size: %zu, id: %zu", object_size, j); } } for (i = 0; i < TEST_ALLOCS_SIZE && allocs[i] != NULL; ++i) vmem_free(vmp, allocs[i]); vmem_delete(vmp); } DONE(NULL); }
3,711
28.696
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_create_win/vmem_create_win.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_create_win.c -- unit test for vmem_createW * * usage: vmem_create_win directory */ #include "unittest.h" VMEM *Vmp; /* * signal_handler -- called on SIGSEGV */ static void signal_handler(int sig) { UT_OUT("signal: %s", os_strsignal(sig)); vmem_delete(Vmp); DONEW(NULL); } int wmain(int argc, wchar_t *argv[]) { STARTW(argc, argv, "vmem_create_win"); if (argc < 2 || argc > 3) UT_FATAL("usage: %s directory", ut_toUTF8(argv[0])); Vmp = vmem_createW(argv[1], VMEM_MIN_POOL); if (Vmp == NULL) UT_OUT("!vmem_create"); else { struct sigaction v; sigemptyset(&v.sa_mask); v.sa_flags = 0; v.sa_handler = signal_handler; if (SIGACTION(SIGSEGV, &v, NULL) != 0) UT_FATAL("!sigaction"); /* try to dereference the opaque handle */ char x = *(char *)Vmp; UT_OUT("x = %c", x); } UT_FATAL("no signal received"); }
2,461
28.662651
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_has_auto_flush/mocks_posix.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_posix.c -- mocked functions used in pmem_has_auto_flush.c */ #include <fts.h> #include "fs.h" #include "unittest.h" #define BUS_DEVICE_PATH "/sys/bus/nd/devices" /* * open -- open mock */ FUNC_MOCK(open, int, const char *path, int flags, ...) FUNC_MOCK_RUN_DEFAULT { va_list ap; va_start(ap, flags); int mode = va_arg(ap, int); va_end(ap); if (!strstr(path, BUS_DEVICE_PATH)) return _FUNC_REAL(open)(path, flags, mode); const char *prefix = os_getenv("BUS_DEVICE_PATH"); char path2[PATH_MAX] = { 0 }; strcat(path2, prefix); strcat(path2, path + strlen(BUS_DEVICE_PATH)); return _FUNC_REAL(open)(path2, flags, mode); } FUNC_MOCK_END struct fs { FTS *ft; struct fs_entry entry; }; /* * fs_new -- creates fs traversal instance */ FUNC_MOCK(fs_new, struct fs *, const char *path) FUNC_MOCK_RUN_DEFAULT { if (!strstr(path, BUS_DEVICE_PATH)) return _FUNC_REAL(fs_new)(path); const char *prefix = os_getenv("BUS_DEVICE_PATH"); char path2[PATH_MAX] = { 0 }; strcat(path2, prefix); strcat(path2, path + strlen(BUS_DEVICE_PATH)); return _FUNC_REAL(fs_new)(path2); } FUNC_MOCK_END /* * os_stat -- os_stat mock to handle sysfs path */ FUNC_MOCK(os_stat, int, const char *path, os_stat_t *buf) FUNC_MOCK_RUN_DEFAULT { if (!strstr(path, BUS_DEVICE_PATH)) return _FUNC_REAL(os_stat)(path, buf); const char *prefix = os_getenv("BUS_DEVICE_PATH"); char path2[PATH_MAX] = { 0 }; strcat(path2, prefix); strcat(path2, path + strlen(BUS_DEVICE_PATH)); return _FUNC_REAL(os_stat)(path2, buf); } FUNC_MOCK_END
3,142
30.747475
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_has_auto_flush/pmem_has_auto_flush.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem_has_auto_flush.c -- unit test for pmem_has_auto_flush() function * * this test checks if function pmem_has_auto_flush handle sysfs path * and persistence_domain file in proper way */ #include <string.h> #include "unittest.h" int main(int argc, char *argv[]) { START(argc, argv, "pmem_has_auto_flush"); if (argc != 1) UT_FATAL("usage: %s path", argv[0]); int ret = pmem_has_auto_flush(); UT_OUT("pmem_has_auto_flush %d", ret); DONE(NULL); }
2,065
35.245614
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_mix_allocations/vmem_mix_allocations.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_mix_allocations.c -- unit test for vmem_mix_allocations * * usage: vmem_mix_allocations [directory] */ #include "unittest.h" #define COUNT 24 #define POOL_SIZE VMEM_MIN_POOL #define MAX_SIZE (1 << (COUNT - 1)) /* 8MB */ int main(int argc, char *argv[]) { char *dir = NULL; void *mem_pool = NULL; VMEM *vmp; size_t obj_size; int *ptr[COUNT + 1]; int i = 0; size_t sum_alloc = 0; START(argc, argv, "vmem_mix_allocations"); if (argc == 2) { dir = argv[1]; } else if (argc > 2) { UT_FATAL("usage: %s [directory]", argv[0]); } if (dir == NULL) { /* allocate memory for function vmem_create_in_region() */ mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20); vmp = vmem_create_in_region(mem_pool, POOL_SIZE); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); } else { vmp = vmem_create(dir, POOL_SIZE); if (vmp == NULL) UT_FATAL("!vmem_create"); } obj_size = MAX_SIZE; /* test with multiple size of allocations from 8MB to 1B */ for (i = 0; i < COUNT; ++i, obj_size /= 2) { ptr[i] = vmem_malloc(vmp, obj_size); if (ptr[i] == NULL) continue; sum_alloc += obj_size; /* check that pointer came from mem_pool */ if (dir == NULL) UT_ASSERTrange(ptr[i], mem_pool, POOL_SIZE); } /* allocate more than half of pool size */ UT_ASSERT(sum_alloc * 2 > POOL_SIZE); while (i > 0) vmem_free(vmp, ptr[--i]); vmem_delete(vmp); DONE(NULL); }
3,013
28.54902
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_init/libtest.h
/* * Copyright 2015-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef LIBTEST_H #define LIBTEST_H #include <stddef.h> void *falloc(size_t size, int c); #endif
1,701
41.55
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_init/vmmalloc_init.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmmalloc_init.c -- unit test for libvmmalloc initialization * * usage: vmmalloc_init [d|l] */ #include <stdlib.h> #include <dlfcn.h> #include "unittest.h" static void *(*Falloc)(size_t size, int val); int main(int argc, char *argv[]) { void *handle = NULL; void *ptr; START(argc, argv, "vmmalloc_init"); if (argc > 2) UT_FATAL("usage: %s [d|l]", argv[0]); if (argc == 2) { switch (argv[1][0]) { case 'd': UT_OUT("deep binding"); handle = dlopen("./libtest.so", RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND); break; case 'l': UT_OUT("lazy binding"); handle = dlopen("./libtest.so", RTLD_LAZY); break; default: UT_FATAL("usage: %s [d|l]", argv[0]); } if (handle == NULL) UT_OUT("dlopen: %s", dlerror()); UT_ASSERTne(handle, NULL); Falloc = dlsym(handle, "falloc"); UT_ASSERTne(Falloc, NULL); } ptr = malloc(4321); free(ptr); if (argc == 2) { /* * NOTE: falloc calls malloc internally. * If libtest is loaded with RTLD_DEEPBIND flag, then it will * use its own lookup scope in preference to global symbols * from already loaded (LD_PRELOAD) libvmmalloc. So, falloc * will call the stock libc's malloc. * However, since we override the malloc hooks, a call to libc's * malloc will be redirected to libvmmalloc anyway, and the * memory can be safely reclaimed using libvmmalloc's free. */ ptr = Falloc(4321, 0xaa); free(ptr); } if (handle != NULL) dlclose(handle); DONE(NULL); }
3,086
29.264706
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_init/libtest.c
/* * Copyright 2014-2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libtest.c -- a simple test library that uses malloc() * * This is used to test libvmmalloc behavior in case when an application * loads a shared library depending on libc using RTLD_DEEPBIND option. */ #include <stdlib.h> #include <string.h> #include "libtest.h" /* * falloc -- allocate a block of size bytes and fill it with a constant byte * * The memory obtained from falloc() can be freed using free(). */ void * falloc(size_t size, int c) { void *ptr = malloc(size); if (ptr) memset(ptr, c, size); return ptr; }
2,140
36.561404
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_misc.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_misc.c -- miscellaneous test cases for rpmemd_obc module */ #include "rpmemd_obc_test_common.h" /* * client_send_disconnect -- connect, send specified number of bytes and * disconnect */ static void client_send_disconnect(char *target, void *msg, size_t size) { struct rpmem_ssh *ssh = clnt_connect(target); if (size) clnt_send(ssh, msg, size); clnt_close(ssh); } /* * client_econnreset -- test case for closing connection when operation on * server is in progress - client side */ int client_econnreset(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE; struct rpmem_msg_create *msg = MALLOC(msg_size); *msg = CREATE_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); rpmem_hton_msg_create(msg); set_rpmem_cmd("server_econnreset"); { /* * Connect and disconnect immediately. */ client_send_disconnect(target, msg, 0); } { /* * Connect, send half of a message header and close the * connection. */ client_send_disconnect(target, msg, sizeof(struct rpmem_msg_hdr) / 2); } { /* * Connect, send only a message header and close the * connection. */ client_send_disconnect(target, msg, sizeof(struct rpmem_msg_hdr)); } { /* * Connect, send half of a message and close the connection. */ client_send_disconnect(target, msg, msg_size / 2); } FREE(msg); return 1; } /* * server_econnreset -- test case for closing connection when operation on * server is in progress - server side */ int server_econnreset(const struct test_case *tc, int argc, char *argv[]) { struct rpmemd_obc *rpdc; int ret; rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO); UT_ASSERTne(rpdc, NULL); ret = rpmemd_obc_status(rpdc, 0); UT_ASSERTeq(ret, 0); ret = rpmemd_obc_process(rpdc, &REQ_CB, NULL); UT_ASSERTne(ret, 0); rpmemd_obc_fini(rpdc); return 0; }
3,643
25.794118
75
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_open.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_open.c -- test cases for open request message */ #include "rpmemd_obc_test_common.h" /* * Number of cases for checking open request message. Must be kept in sync * with client_bad_msg_open function. */ #define BAD_MSG_OPEN_COUNT 11 /* * client_bad_msg_open -- check if server detects invalid open request * messages */ static void client_bad_msg_open(const char *ctarget) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE; struct rpmem_msg_open *msg = MALLOC(msg_size); for (int i = 0; i < BAD_MSG_OPEN_COUNT; i++) { struct rpmem_ssh *ssh = clnt_connect(target); *msg = OPEN_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); switch (i) { case 0: msg->c.provider = 0; break; case 1: msg->c.provider = MAX_RPMEM_PROV; break; case 2: msg->pool_desc.size -= 1; break; case 3: msg->pool_desc.size += 1; break; case 4: msg->pool_desc.size = 0; msg->hdr.size = sizeof(OPEN_MSG) + msg->pool_desc.size; break; case 5: msg->pool_desc.size = 1; msg->hdr.size = sizeof(OPEN_MSG) + msg->pool_desc.size; break; case 6: msg->pool_desc.desc[0] = '\0'; break; case 7: msg->pool_desc.desc[POOL_DESC_SIZE / 2] = '\0'; break; case 8: msg->pool_desc.desc[POOL_DESC_SIZE - 1] = 'E'; break; case 9: msg->c.major = RPMEM_PROTO_MAJOR + 1; break; case 10: msg->c.minor = RPMEM_PROTO_MINOR + 1; break; default: UT_ASSERT(0); } rpmem_hton_msg_open(msg); clnt_send(ssh, msg, msg_size); clnt_wait_disconnect(ssh); clnt_close(ssh); } FREE(msg); FREE(target); } /* * client_msg_open_noresp -- send open request message and don't expect a * response */ static void client_msg_open_noresp(const char *ctarget) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE; struct rpmem_msg_open *msg = MALLOC(msg_size); struct rpmem_ssh *ssh = clnt_connect(target); *msg = OPEN_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); rpmem_hton_msg_open(msg); clnt_send(ssh, msg, msg_size); clnt_wait_disconnect(ssh); clnt_close(ssh); FREE(msg); FREE(target); } /* * client_msg_open_resp -- send open request message and expect a response * with specified status. If status is 0, validate open request response * message */ static void client_msg_open_resp(const char *ctarget, int status) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(OPEN_MSG) + POOL_DESC_SIZE; struct rpmem_msg_open *msg = MALLOC(msg_size); struct rpmem_msg_open_resp resp; struct rpmem_ssh *ssh = clnt_connect(target); *msg = OPEN_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); rpmem_hton_msg_open(msg); clnt_send(ssh, msg, msg_size); clnt_recv(ssh, &resp, sizeof(resp)); rpmem_ntoh_msg_open_resp(&resp); if (status) { UT_ASSERTeq(resp.hdr.status, (uint32_t)status); } else { UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_OPEN_RESP); UT_ASSERTeq(resp.hdr.size, sizeof(struct rpmem_msg_open_resp)); UT_ASSERTeq(resp.hdr.status, (uint32_t)status); UT_ASSERTeq(resp.ibc.port, PORT); UT_ASSERTeq(resp.ibc.rkey, RKEY); UT_ASSERTeq(resp.ibc.raddr, RADDR); UT_ASSERTeq(resp.ibc.persist_method, PERSIST_METHOD); } clnt_close(ssh); FREE(msg); FREE(target); } /* * client_open -- test case for open request message - client side */ int client_open(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; set_rpmem_cmd("server_bad_msg"); client_bad_msg_open(target); set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_OPEN); client_msg_open_noresp(target); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_OPEN, 0); client_msg_open_resp(target, 0); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_OPEN, 1); client_msg_open_resp(target, 1); return 1; }
5,620
25.63981
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test.c
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test.c -- unit test for rpmemd_obc module */ #include "rpmemd_obc_test_common.h" #include "out.h" #include "os.h" /* * test_cases -- available test cases */ static struct test_case test_cases[] = { TEST_CASE(server_bad_msg), TEST_CASE(server_msg_noresp), TEST_CASE(server_msg_resp), TEST_CASE(client_bad_msg_hdr), TEST_CASE(server_econnreset), TEST_CASE(client_econnreset), TEST_CASE(client_create), TEST_CASE(client_open), TEST_CASE(client_close), TEST_CASE(client_set_attr), }; #define NTESTS (sizeof(test_cases) / sizeof(test_cases[0])) int main(int argc, char *argv[]) { START(argc, argv, "rpmemd_obc"); out_init("rpmemd_obc", "RPMEM_LOG_LEVEL", "RPMEM_LOG_FILE", 0, 0); rpmemd_log_init("rpmemd", os_getenv("RPMEMD_LOG_FILE"), 0); rpmemd_log_level = rpmemd_log_level_from_str( os_getenv("RPMEMD_LOG_LEVEL")); rpmem_util_cmds_init(); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); rpmem_util_cmds_fini(); rpmemd_log_close(); out_fini(); DONE(NULL); }
2,619
30.190476
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_msg_hdr.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_msg_hdr.c -- test cases for message header */ #include "rpmemd_obc_test_common.h" /* * Number of cases for checking message header. Must be kept in sync with * client_bad_msg_hdr function. */ #define BAD_MSG_HDR_COUNT 6 /* * client_bad_msg_hdr -- test case for checking message header */ int client_bad_msg_hdr(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; set_rpmem_cmd("server_bad_msg"); for (int i = 0; i < BAD_MSG_HDR_COUNT; i++) { struct rpmem_ssh *ssh = clnt_connect(target); struct rpmem_msg_hdr msg = MSG_HDR; switch (i) { case 0: msg.size -= 1; break; case 1: msg.size = 0; break; case 2: msg.type = MAX_RPMEM_MSG_TYPE; break; case 3: msg.type = RPMEM_MSG_TYPE_OPEN_RESP; break; case 4: msg.type = RPMEM_MSG_TYPE_CREATE_RESP; break; case 5: msg.type = RPMEM_MSG_TYPE_CLOSE_RESP; break; default: UT_ASSERT(0); } rpmem_hton_msg_hdr(&msg); clnt_send(ssh, &msg, sizeof(msg)); clnt_wait_disconnect(ssh); clnt_close(ssh); } return 1; }
2,747
27.926316
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_create.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_create.c -- test cases for create request message */ #include "rpmemd_obc_test_common.h" /* * Number of cases for checking create request message. Must be kept in sync * with client_bad_msg_create function. */ #define BAD_MSG_CREATE_COUNT 11 /* * client_bad_msg_create -- check if server detects invalid create request * messages */ static void client_bad_msg_create(const char *ctarget) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE; struct rpmem_msg_create *msg = MALLOC(msg_size); for (int i = 0; i < BAD_MSG_CREATE_COUNT; i++) { struct rpmem_ssh *ssh = clnt_connect(target); *msg = CREATE_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); switch (i) { case 0: msg->c.provider = 0; break; case 1: msg->c.provider = MAX_RPMEM_PROV; break; case 2: msg->pool_desc.size -= 1; break; case 3: msg->pool_desc.size += 1; break; case 4: msg->pool_desc.size = 0; msg->hdr.size = sizeof(CREATE_MSG) + msg->pool_desc.size; break; case 5: msg->pool_desc.size = 1; msg->hdr.size = sizeof(CREATE_MSG) + msg->pool_desc.size; break; case 6: msg->pool_desc.desc[0] = '\0'; break; case 7: msg->pool_desc.desc[POOL_DESC_SIZE / 2] = '\0'; break; case 8: msg->pool_desc.desc[POOL_DESC_SIZE - 1] = 'E'; break; case 9: msg->c.major = RPMEM_PROTO_MAJOR + 1; break; case 10: msg->c.minor = RPMEM_PROTO_MINOR + 1; break; default: UT_ASSERT(0); } rpmem_hton_msg_create(msg); clnt_send(ssh, msg, msg_size); clnt_wait_disconnect(ssh); clnt_close(ssh); } FREE(msg); FREE(target); } /* * client_msg_create_noresp -- send create request message and don't expect * a response */ static void client_msg_create_noresp(const char *ctarget) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE; struct rpmem_msg_create *msg = MALLOC(msg_size); struct rpmem_ssh *ssh = clnt_connect(target); *msg = CREATE_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); rpmem_hton_msg_create(msg); clnt_send(ssh, msg, msg_size); clnt_close(ssh); FREE(msg); FREE(target); } /* * client_msg_create_resp -- send create request message and expect a response * with specified status. If status is 0, validate create request response * message */ static void client_msg_create_resp(const char *ctarget, int status) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(CREATE_MSG) + POOL_DESC_SIZE; struct rpmem_msg_create *msg = MALLOC(msg_size); struct rpmem_msg_create_resp resp; struct rpmem_ssh *ssh = clnt_connect(target); *msg = CREATE_MSG; msg->hdr.size = msg_size; memcpy(msg->pool_desc.desc, POOL_DESC, POOL_DESC_SIZE); rpmem_hton_msg_create(msg); clnt_send(ssh, msg, msg_size); clnt_recv(ssh, &resp, sizeof(resp)); rpmem_ntoh_msg_create_resp(&resp); if (status) { UT_ASSERTeq(resp.hdr.status, (uint32_t)status); } else { UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_CREATE_RESP); UT_ASSERTeq(resp.hdr.size, sizeof(struct rpmem_msg_create_resp)); UT_ASSERTeq(resp.hdr.status, (uint32_t)status); UT_ASSERTeq(resp.ibc.port, PORT); UT_ASSERTeq(resp.ibc.rkey, RKEY); UT_ASSERTeq(resp.ibc.raddr, RADDR); UT_ASSERTeq(resp.ibc.persist_method, PERSIST_METHOD); } clnt_close(ssh); FREE(msg); FREE(target); } /* * client_create -- test case for create request message - client side */ int client_create(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; set_rpmem_cmd("server_bad_msg"); client_bad_msg_create(target); set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_CREATE); client_msg_create_noresp(target); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CREATE, 0); client_msg_create_resp(target, 0); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CREATE, 1); client_msg_create_resp(target, 1); return 1; }
5,680
26.052381
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_set_attr.c
/* * Copyright 2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_set_attr.c -- test cases for set attributes request message */ #include "rpmemd_obc_test_common.h" /* * client_msg_set_attr_noresp -- send set attributes request message and don't * expect a response */ static void client_msg_set_attr_noresp(const char *ctarget) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(SET_ATTR_MSG); struct rpmem_msg_set_attr *msg = MALLOC(msg_size); struct rpmem_ssh *ssh = clnt_connect(target); *msg = SET_ATTR_MSG; rpmem_hton_msg_set_attr(msg); clnt_send(ssh, msg, msg_size); clnt_wait_disconnect(ssh); clnt_close(ssh); FREE(msg); FREE(target); } /* * client_msg_set_attr_resp -- send set attributes request message and expect * a response with specified status. If status is 0, validate set attributes * request response message */ static void client_msg_set_attr_resp(const char *ctarget, int status) { char *target = STRDUP(ctarget); size_t msg_size = sizeof(SET_ATTR_MSG); struct rpmem_msg_set_attr *msg = MALLOC(msg_size); struct rpmem_msg_set_attr_resp resp; struct rpmem_ssh *ssh = clnt_connect(target); *msg = SET_ATTR_MSG; rpmem_hton_msg_set_attr(msg); clnt_send(ssh, msg, msg_size); clnt_recv(ssh, &resp, sizeof(resp)); rpmem_ntoh_msg_set_attr_resp(&resp); if (status) { UT_ASSERTeq(resp.hdr.status, (uint32_t)status); } else { UT_ASSERTeq(resp.hdr.type, RPMEM_MSG_TYPE_SET_ATTR_RESP); UT_ASSERTeq(resp.hdr.size, sizeof(struct rpmem_msg_set_attr_resp)); UT_ASSERTeq(resp.hdr.status, (uint32_t)status); } clnt_close(ssh); FREE(msg); FREE(target); } /* * client_set_attr -- test case for set attributes request message - client * side */ int client_set_attr(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_SET_ATTR); client_msg_set_attr_noresp(target); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_SET_ATTR, 0); client_msg_set_attr_resp(target, 0); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_SET_ATTR, 1); client_msg_set_attr_resp(target, 1); return 1; }
3,770
29.168
78
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_common.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_common.c -- common definitions for rpmemd_obc tests */ #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include "os.h" #include "rpmemd_obc_test_common.h" #define CMD_BUFF_SIZE 4096 static const char *rpmem_cmd; /* * set_rpmem_cmd -- set RPMEM_CMD variable */ void set_rpmem_cmd(const char *fmt, ...) { static char cmd_buff[CMD_BUFF_SIZE]; if (!rpmem_cmd) { char *cmd = os_getenv(RPMEM_CMD_ENV); UT_ASSERTne(cmd, NULL); rpmem_cmd = STRDUP(cmd); } ssize_t ret; size_t cnt = 0; va_list ap; va_start(ap, fmt); ret = snprintf(&cmd_buff[cnt], CMD_BUFF_SIZE - cnt, "%s ", rpmem_cmd); UT_ASSERT(ret > 0); cnt += (size_t)ret; ret = vsnprintf(&cmd_buff[cnt], CMD_BUFF_SIZE - cnt, fmt, ap); UT_ASSERT(ret > 0); cnt += (size_t)ret; va_end(ap); ret = os_setenv(RPMEM_CMD_ENV, cmd_buff, 1); UT_ASSERTeq(ret, 0); /* * Rpmem has internal RPMEM_CMD variable copy and it is assumed * RPMEMD_CMD will not change its value during execution. To refresh the * internal copy it must be destroyed and a instance must be initialized * manually. */ rpmem_util_cmds_fini(); rpmem_util_cmds_init(); } /* * req_cb_check_req -- validate request attributes */ static void req_cb_check_req(const struct rpmem_req_attr *req) { UT_ASSERTeq(req->nlanes, NLANES); UT_ASSERTeq(req->pool_size, POOL_SIZE); UT_ASSERTeq(req->provider, PROVIDER); UT_ASSERTeq(strcmp(req->pool_desc, POOL_DESC), 0); } /* * req_cb_check_pool_attr -- validate pool attributes */ static void req_cb_check_pool_attr(const struct rpmem_pool_attr *pool_attr) { struct rpmem_pool_attr attr = POOL_ATTR_INIT; UT_ASSERTeq(memcmp(&attr, pool_attr, sizeof(attr)), 0); } /* * req_cb_create -- callback for create request operation * * This function behaves according to arguments specified via * struct req_cb_arg. */ static int req_cb_create(struct rpmemd_obc *obc, void *arg, const struct rpmem_req_attr *req, const struct rpmem_pool_attr *pool_attr) { UT_ASSERTne(arg, NULL); UT_ASSERTne(req, NULL); UT_ASSERTne(pool_attr, NULL); req_cb_check_req(req); req_cb_check_pool_attr(pool_attr); struct req_cb_arg *args = arg; args->types |= (1 << RPMEM_MSG_TYPE_CREATE); int ret = args->ret; if (args->resp) { struct rpmem_resp_attr resp = { .port = PORT, .rkey = RKEY, .raddr = RADDR, .persist_method = PERSIST_METHOD, .nlanes = NLANES_RESP, }; ret = rpmemd_obc_create_resp(obc, args->status, &resp); } if (args->force_ret) ret = args->ret; return ret; } /* * req_cb_open -- callback for open request operation * * This function behaves according to arguments specified via * struct req_cb_arg. */ static int req_cb_open(struct rpmemd_obc *obc, void *arg, const struct rpmem_req_attr *req) { UT_ASSERTne(arg, NULL); UT_ASSERTne(req, NULL); req_cb_check_req(req); struct req_cb_arg *args = arg; args->types |= (1 << RPMEM_MSG_TYPE_OPEN); int ret = args->ret; if (args->resp) { struct rpmem_resp_attr resp = { .port = PORT, .rkey = RKEY, .raddr = RADDR, .persist_method = PERSIST_METHOD, .nlanes = NLANES_RESP, }; struct rpmem_pool_attr pool_attr = POOL_ATTR_INIT; ret = rpmemd_obc_open_resp(obc, args->status, &resp, &pool_attr); } if (args->force_ret) ret = args->ret; return ret; } /* * req_cb_close -- callback for close request operation * * This function behaves according to arguments specified via * struct req_cb_arg. */ static int req_cb_close(struct rpmemd_obc *obc, void *arg, int flags) { UT_ASSERTne(arg, NULL); struct req_cb_arg *args = arg; args->types |= (1 << RPMEM_MSG_TYPE_CLOSE); int ret = args->ret; if (args->resp) ret = rpmemd_obc_close_resp(obc, args->status); if (args->force_ret) ret = args->ret; return ret; } /* * req_cb_set_attr -- callback for set attributes request operation * * This function behaves according to arguments specified via * struct req_cb_arg. */ static int req_cb_set_attr(struct rpmemd_obc *obc, void *arg, const struct rpmem_pool_attr *pool_attr) { UT_ASSERTne(arg, NULL); struct req_cb_arg *args = arg; args->types |= (1 << RPMEM_MSG_TYPE_SET_ATTR); int ret = args->ret; if (args->resp) ret = rpmemd_obc_set_attr_resp(obc, args->status); if (args->force_ret) ret = args->ret; return ret; } /* * REQ_CB -- request callbacks */ struct rpmemd_obc_requests REQ_CB = { .create = req_cb_create, .open = req_cb_open, .close = req_cb_close, .set_attr = req_cb_set_attr, }; /* * clnt_wait_disconnect -- wait for disconnection */ void clnt_wait_disconnect(struct rpmem_ssh *ssh) { int ret; ret = rpmem_ssh_monitor(ssh, 0); UT_ASSERTne(ret, 1); } /* * clnt_connect -- create a ssh connection with specified target */ struct rpmem_ssh * clnt_connect(char *target) { struct rpmem_target_info *info; info = rpmem_target_parse(target); UT_ASSERTne(info, NULL); struct rpmem_ssh *ssh = rpmem_ssh_open(info); UT_ASSERTne(ssh, NULL); rpmem_target_free(info); return ssh; } /* * clnt_close -- close client */ void clnt_close(struct rpmem_ssh *ssh) { rpmem_ssh_close(ssh); } /* * clnt_send -- send data */ void clnt_send(struct rpmem_ssh *ssh, const void *buff, size_t len) { int ret; ret = rpmem_ssh_send(ssh, buff, len); UT_ASSERTeq(ret, 0); } /* * clnt_recv -- receive data */ void clnt_recv(struct rpmem_ssh *ssh, void *buff, size_t len) { int ret; ret = rpmem_ssh_recv(ssh, buff, len); UT_ASSERTeq(ret, 0); } /* * server_msg_args -- process a message according to specified arguments */ static void server_msg_args(struct rpmemd_obc *rpdc, enum conn_wait_close conn, struct req_cb_arg *args) { int ret; unsigned long long types = args->types; args->types = 0; ret = rpmemd_obc_process(rpdc, &REQ_CB, args); UT_ASSERTeq(ret, args->ret); UT_ASSERTeq(args->types, types); if (conn == CONN_WAIT_CLOSE) { ret = rpmemd_obc_process(rpdc, &REQ_CB, args); UT_ASSERTeq(ret, 1); } rpmemd_obc_fini(rpdc); } /* * server_msg_resp -- process a message of specified type, response to client * with specific status value and return status of sending response function */ int server_msg_resp(const struct test_case *tc, int argc, char *argv[]) { if (argc < 2) UT_FATAL("usage: %s msg_type status", tc->name); unsigned type = ATOU(argv[0]); int status = atoi(argv[1]); int ret; struct rpmemd_obc *rpdc; rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO); UT_ASSERTne(rpdc, NULL); ret = rpmemd_obc_status(rpdc, 0); UT_ASSERTeq(ret, 0); struct req_cb_arg args = { .ret = 0, .force_ret = 0, .resp = 1, .types = (1U << type), .status = status, }; server_msg_args(rpdc, CONN_WAIT_CLOSE, &args); return 2; } /* * server_msg_noresp -- process a message of specified type, do not response to * client and return specific value from process callback */ int server_msg_noresp(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s msg_type", tc->name); int type = atoi(argv[0]); int ret; struct rpmemd_obc *rpdc; rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO); UT_ASSERTne(rpdc, NULL); ret = rpmemd_obc_status(rpdc, 0); UT_ASSERTeq(ret, 0); struct req_cb_arg args = { .ret = -1, .force_ret = 1, .resp = 0, .types = (1U << type), .status = 0, }; server_msg_args(rpdc, CONN_CLOSE, &args); return 1; } /* * server_bad_msg -- process a message and expect * error returned from rpmemd_obc_process function */ int server_bad_msg(const struct test_case *tc, int argc, char *argv[]) { int ret; struct rpmemd_obc *rpdc; rpdc = rpmemd_obc_init(STDIN_FILENO, STDOUT_FILENO); UT_ASSERTne(rpdc, NULL); ret = rpmemd_obc_status(rpdc, 0); UT_ASSERTeq(ret, 0); ret = rpmemd_obc_process(rpdc, &REQ_CB, NULL); UT_ASSERTne(ret, 0); rpmemd_obc_fini(rpdc); return 0; }
9,441
20.410431
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_close.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_close.c -- test cases for close request message */ #include "rpmemd_obc_test_common.h" /* * client_msg_close_noresp -- send close request message and don't expect a * response */ static void client_msg_close_noresp(const char *ctarget) { char *target = STRDUP(ctarget); struct rpmem_msg_close msg = CLOSE_MSG; rpmem_hton_msg_close(&msg); struct rpmem_ssh *ssh = clnt_connect(target); clnt_send(ssh, &msg, sizeof(msg)); clnt_wait_disconnect(ssh); clnt_close(ssh); FREE(target); } /* * client_msg_close_resp -- send close request message and expect a response * with specified status. If status is 0, validate close request response * message */ static void client_msg_close_resp(const char *ctarget, int status) { char *target = STRDUP(ctarget); struct rpmem_msg_close msg = CLOSE_MSG; rpmem_hton_msg_close(&msg); struct rpmem_msg_close_resp resp; struct rpmem_ssh *ssh = clnt_connect(target); clnt_send(ssh, &msg, sizeof(msg)); clnt_recv(ssh, &resp, sizeof(resp)); rpmem_ntoh_msg_close_resp(&resp); if (status) UT_ASSERTeq(resp.hdr.status, (uint32_t)status); clnt_close(ssh); FREE(target); } /* * client_close -- test case for close request message - client side */ int client_close(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; set_rpmem_cmd("server_msg_noresp %d", RPMEM_MSG_TYPE_CLOSE); client_msg_close_noresp(target); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CLOSE, 0); client_msg_close_resp(target, 0); set_rpmem_cmd("server_msg_resp %d %d", RPMEM_MSG_TYPE_CLOSE, 1); client_msg_close_resp(target, 1); return 1; }
3,306
29.62037
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_obc/rpmemd_obc_test_common.h
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmemd_obc_test_common.h -- common declarations for rpmemd_obc test */ #include "unittest.h" #include "librpmem.h" #include "rpmem_proto.h" #include "rpmem_common.h" #include "rpmem_ssh.h" #include "rpmem_util.h" #include "rpmemd_log.h" #include "rpmemd_obc.h" #define PORT 1234 #define RKEY 0x0123456789abcdef #define RADDR 0xfedcba9876543210 #define PERSIST_METHOD RPMEM_PM_APM #define POOL_ATTR_INIT {\ .signature = "<RPMEM>",\ .major = 1,\ .compat_features = 2,\ .incompat_features = 3,\ .ro_compat_features = 4,\ .poolset_uuid = "POOLSET_UUID0123",\ .uuid = "UUID0123456789AB",\ .next_uuid = "NEXT_UUID0123456",\ .prev_uuid = "PREV_UUID0123456",\ .user_flags = "USER_FLAGS012345",\ } #define POOL_ATTR_ALT {\ .signature = "<ALT>",\ .major = 5,\ .compat_features = 6,\ .incompat_features = 7,\ .ro_compat_features = 8,\ .poolset_uuid = "UUID_POOLSET_ALT",\ .uuid = "ALT_UUIDCDEFFEDC",\ .next_uuid = "456UUID_NEXT_ALT",\ .prev_uuid = "UUID012_ALT_PREV",\ .user_flags = "012345USER_FLAGS",\ } #define POOL_SIZE 0x0001234567abcdef #define NLANES 0x123 #define NLANES_RESP 16 #define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS #define POOL_DESC "pool.set" #define BUFF_SIZE 8192 static const char pool_desc[] = POOL_DESC; #define POOL_DESC_SIZE (sizeof(pool_desc) / sizeof(pool_desc[0])) struct rpmem_ssh *clnt_connect(char *target); void clnt_wait_disconnect(struct rpmem_ssh *ssh); void clnt_send(struct rpmem_ssh *ssh, const void *buff, size_t len); void clnt_recv(struct rpmem_ssh *ssh, void *buff, size_t len); void clnt_close(struct rpmem_ssh *ssh); enum conn_wait_close { CONN_CLOSE, CONN_WAIT_CLOSE, }; void set_rpmem_cmd(const char *fmt, ...); extern struct rpmemd_obc_requests REQ_CB; struct req_cb_arg { int resp; unsigned long long types; int force_ret; int ret; int status; }; static const struct rpmem_msg_hdr MSG_HDR = { .type = RPMEM_MSG_TYPE_CLOSE, .size = sizeof(struct rpmem_msg_hdr), }; static const struct rpmem_msg_create CREATE_MSG = { .hdr = { .type = RPMEM_MSG_TYPE_CREATE, .size = sizeof(struct rpmem_msg_create), }, .c = { .major = RPMEM_PROTO_MAJOR, .minor = RPMEM_PROTO_MINOR, .pool_size = POOL_SIZE, .nlanes = NLANES, .provider = PROVIDER, .buff_size = BUFF_SIZE, }, .pool_attr = POOL_ATTR_INIT, .pool_desc = { .size = POOL_DESC_SIZE, }, }; static const struct rpmem_msg_open OPEN_MSG = { .hdr = { .type = RPMEM_MSG_TYPE_OPEN, .size = sizeof(struct rpmem_msg_open), }, .c = { .major = RPMEM_PROTO_MAJOR, .minor = RPMEM_PROTO_MINOR, .pool_size = POOL_SIZE, .nlanes = NLANES, .provider = PROVIDER, .buff_size = BUFF_SIZE, }, .pool_desc = { .size = POOL_DESC_SIZE, }, }; static const struct rpmem_msg_close CLOSE_MSG = { .hdr = { .type = RPMEM_MSG_TYPE_CLOSE, .size = sizeof(struct rpmem_msg_close), }, }; static const struct rpmem_msg_set_attr SET_ATTR_MSG = { .hdr = { .type = RPMEM_MSG_TYPE_SET_ATTR, .size = sizeof(struct rpmem_msg_set_attr), }, .pool_attr = POOL_ATTR_ALT, }; TEST_CASE_DECLARE(server_accept_sim); TEST_CASE_DECLARE(server_accept_sim_fork); TEST_CASE_DECLARE(client_accept_sim); TEST_CASE_DECLARE(server_accept_seq); TEST_CASE_DECLARE(server_accept_seq_fork); TEST_CASE_DECLARE(client_accept_seq); TEST_CASE_DECLARE(client_bad_msg_hdr); TEST_CASE_DECLARE(server_bad_msg); TEST_CASE_DECLARE(server_msg_noresp); TEST_CASE_DECLARE(server_msg_resp); TEST_CASE_DECLARE(client_econnreset); TEST_CASE_DECLARE(server_econnreset); TEST_CASE_DECLARE(client_create); TEST_CASE_DECLARE(server_open); TEST_CASE_DECLARE(client_close); TEST_CASE_DECLARE(server_close); TEST_CASE_DECLARE(client_open); TEST_CASE_DECLARE(client_set_attr);
5,306
27.379679
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_valgrind/vmem_valgrind.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_valgrind.c -- unit test for vmem_valgrind * * usage: vmem_valgrind <test-number> [directory] * * test-number can be a number from 0 to 9 */ #include "unittest.h" static int custom_allocs; static int custom_alloc_calls; /* * malloc_custom -- custom malloc function * * This function updates statistics about custom alloc functions, * and returns allocated memory. */ static void * malloc_custom(size_t size) { ++custom_alloc_calls; ++custom_allocs; return malloc(size); } /* * free_custom -- custom free function * * This function updates statistics about custom alloc functions, * and frees allocated memory. */ static void free_custom(void *ptr) { ++custom_alloc_calls; --custom_allocs; free(ptr); } /* * realloc_custom -- custom realloc function * * This function updates statistics about custom alloc functions, * and returns reallocated memory. */ static void * realloc_custom(void *ptr, size_t size) { ++custom_alloc_calls; return realloc(ptr, size); } /* * strdup_custom -- custom strdup function * * This function updates statistics about custom alloc functions, * and returns allocated memory with a duplicated string. */ static char * strdup_custom(const char *s) { ++custom_alloc_calls; ++custom_allocs; return strdup(s); } int main(int argc, char *argv[]) { char *dir = NULL; VMEM *vmp; int *ptr; int test_case = -1; int expect_custom_alloc = 0; START(argc, argv, "vmem_valgrind"); if (argc >= 2 && argc <= 3) { test_case = atoi(argv[1]); if (test_case > 9) test_case = -1; if (argc > 2) dir = argv[2]; } if (test_case < 0) UT_FATAL("usage: %s <test-number from 0 to 9> [directory]", argv[0]); if (test_case < 5) { UT_OUT("use default allocator"); expect_custom_alloc = 0; } else { UT_OUT("use custom alloc functions"); test_case -= 5; expect_custom_alloc = 1; vmem_set_funcs(malloc_custom, free_custom, realloc_custom, strdup_custom, NULL); } if (dir == NULL) { /* allocate memory for function vmem_create_in_region() */ void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20); vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); } else { vmp = vmem_create(dir, VMEM_MIN_POOL); if (vmp == NULL) UT_FATAL("!vmem_create"); } switch (test_case) { case 0: { UT_OUT("remove all allocations and delete pool"); ptr = vmem_malloc(vmp, sizeof(int)); if (ptr == NULL) UT_FATAL("!vmem_malloc"); vmem_free(vmp, ptr); vmem_delete(vmp); break; } case 1: { UT_OUT("only remove allocations"); ptr = vmem_malloc(vmp, sizeof(int)); if (ptr == NULL) UT_FATAL("!vmem_malloc"); vmem_free(vmp, ptr); break; } case 2: { UT_OUT("only delete pool"); ptr = vmem_malloc(vmp, sizeof(int)); if (ptr == NULL) UT_FATAL("!vmem_malloc"); vmem_delete(vmp); /* prevent reporting leaked memory as still reachable */ ptr = NULL; break; } case 3: { UT_OUT("memory leaks"); ptr = vmem_malloc(vmp, sizeof(int)); if (ptr == NULL) UT_FATAL("!vmem_malloc"); /* prevent reporting leaked memory as still reachable */ ptr = NULL; /* Clean up pool, above malloc will still leak */ vmem_delete(vmp); break; } case 4: { UT_OUT("heap block overrun"); ptr = vmem_malloc(vmp, 12 * sizeof(int)); if (ptr == NULL) UT_FATAL("!vmem_malloc"); /* heap block overrun */ ptr[12] = 7; vmem_free(vmp, ptr); vmem_delete(vmp); break; } default: { UT_FATAL("!unknown test-number"); } } /* check memory leak in custom allocator */ UT_ASSERTeq(custom_allocs, 0); if (expect_custom_alloc == 0) { UT_ASSERTeq(custom_alloc_calls, 0); } else { UT_ASSERTne(custom_alloc_calls, 0); } DONE(NULL); }
5,395
23.306306
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/ctl_prefault/ctl_prefault.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ctl_prefault.c -- tests for the ctl entry points: prefault */ #include <stdlib.h> #include <string.h> #include <sys/resource.h> #include "unittest.h" #define OBJ_STR "obj" #define BLK_STR "blk" #define LOG_STR "log" #define BSIZE 20 #define LAYOUT "obj_ctl_prefault" #ifdef __FreeBSD__ typedef char vec_t; #else typedef unsigned char vec_t; #endif typedef int (*fun)(void *, const char *, void *); /* * prefault_fun -- function ctl_get/set testing */ static void prefault_fun(int prefault, fun get_func, fun set_func) { int ret; int arg; int arg_read; if (prefault == 1) { /* prefault at open */ arg_read = -1; ret = get_func(NULL, "prefault.at_open", &arg_read); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg_read, 0); arg = 1; ret = set_func(NULL, "prefault.at_open", &arg); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg, 1); arg_read = -1; ret = get_func(NULL, "prefault.at_open", &arg_read); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg_read, 1); } else if (prefault == 2) { /* prefault at create */ arg_read = -1; ret = get_func(NULL, "prefault.at_create", &arg_read); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg_read, 0); arg = 1; ret = set_func(NULL, "prefault.at_create", &arg); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg, 1); arg_read = -1; ret = get_func(NULL, "prefault.at_create", &arg_read); UT_ASSERTeq(ret, 0); UT_ASSERTeq(arg_read, 1); } } /* * count_resident_pages -- count resident_pages */ static size_t count_resident_pages(void *pool, size_t length) { size_t arr_len = (length + Ut_pagesize - 1) / Ut_pagesize; vec_t *vec = MALLOC(sizeof(*vec) * arr_len); int ret = mincore(pool, length, vec); UT_ASSERTeq(ret, 0); size_t resident_pages = 0; for (size_t i = 0; i < arr_len; ++i) resident_pages += vec[i] & 0x1; FREE(vec); return resident_pages; } /* * test_obj -- open/create PMEMobjpool */ static void test_obj(const char *path, int open) { PMEMobjpool *pop; if (open) { if ((pop = pmemobj_open(path, LAYOUT)) == NULL) UT_FATAL("!pmemobj_open: %s", path); } else { if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); } size_t resident_pages = count_resident_pages(pop, PMEMOBJ_MIN_POOL); pmemobj_close(pop); UT_OUT("%ld", resident_pages); } /* * test_blk -- open/create PMEMblkpool */ static void test_blk(const char *path, int open) { PMEMblkpool *pbp; if (open) { if ((pbp = pmemblk_open(path, BSIZE)) == NULL) UT_FATAL("!pmemblk_open: %s", path); } else { if ((pbp = pmemblk_create(path, BSIZE, PMEMBLK_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemblk_create: %s", path); } size_t resident_pages = count_resident_pages(pbp, PMEMBLK_MIN_POOL); pmemblk_close(pbp); UT_OUT("%ld", resident_pages); } /* * test_log -- open/create PMEMlogpool */ static void test_log(const char *path, int open) { PMEMlogpool *plp; /* * To test prefaulting, pool must have size at least equal to 2 pages. * If 2MB huge pages are used this is at least 4MB. */ size_t pool_size = 2 * PMEMLOG_MIN_POOL; if (open) { if ((plp = pmemlog_open(path)) == NULL) UT_FATAL("!pmemlog_open: %s", path); } else { if ((plp = pmemlog_create(path, pool_size, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemlog_create: %s", path); } size_t resident_pages = count_resident_pages(plp, pool_size); pmemlog_close(plp); UT_OUT("%ld", resident_pages); } #define USAGE() do {\ UT_FATAL("usage: %s file-name type(obj/blk/log) prefault(0/1/2) "\ "open(0/1)", argv[0]);\ } while (0) int main(int argc, char *argv[]) { START(argc, argv, "ctl_prefault"); if (argc != 5) USAGE(); char *type = argv[1]; const char *path = argv[2]; int prefault = atoi(argv[3]); int open = atoi(argv[4]); if (strcmp(type, OBJ_STR) == 0) { prefault_fun(prefault, (fun)pmemobj_ctl_get, (fun)pmemobj_ctl_set); test_obj(path, open); } else if (strcmp(type, BLK_STR) == 0) { prefault_fun(prefault, (fun)pmemblk_ctl_get, (fun)pmemblk_ctl_set); test_blk(path, open); } else if (strcmp(type, LOG_STR) == 0) { prefault_fun(prefault, (fun)pmemlog_ctl_get, (fun)pmemlog_ctl_set); test_log(path, open); } else USAGE(); DONE(NULL); }
5,841
24.4
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_multiple_pools/vmem_multiple_pools.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_multiple_pools.c -- unit test for vmem_multiple_pools * * usage: vmem_multiple_pools directory npools [nthreads] */ #include "unittest.h" #define TEST_REPEAT_CREATE_POOLS (10) static char **mem_pools; static VMEM **pools; static unsigned npools; static const char *dir; static void * thread_func(void *arg) { unsigned start_idx = *(unsigned *)arg; for (int repeat = 0; repeat < TEST_REPEAT_CREATE_POOLS; ++repeat) { for (unsigned idx = 0; idx < npools; ++idx) { unsigned pool_id = start_idx + idx; /* delete old pool with the same id if exist */ if (pools[pool_id] != NULL) { vmem_delete(pools[pool_id]); pools[pool_id] = NULL; } if (pool_id % 2 == 0) { /* for even pool_id, create in region */ pools[pool_id] = vmem_create_in_region( mem_pools[pool_id / 2], VMEM_MIN_POOL); if (pools[pool_id] == NULL) UT_FATAL("!vmem_create_in_region"); } else { /* for odd pool_id, create in file */ pools[pool_id] = vmem_create(dir, VMEM_MIN_POOL); if (pools[pool_id] == NULL) UT_FATAL("!vmem_create"); } void *test = vmem_malloc(pools[pool_id], sizeof(void *)); UT_ASSERTne(test, NULL); vmem_free(pools[pool_id], test); } } return NULL; } int main(int argc, char *argv[]) { START(argc, argv, "vmem_multiple_pools"); if (argc < 4) UT_FATAL("usage: %s directory npools nthreads", argv[0]); dir = argv[1]; npools = ATOU(argv[2]); unsigned nthreads = ATOU(argv[3]); UT_OUT("create %d pools in %d thread(s)", npools, nthreads); const unsigned mem_pools_size = (npools / 2 + npools % 2) * nthreads; mem_pools = MALLOC(mem_pools_size * sizeof(char *)); pools = CALLOC(npools * nthreads, sizeof(VMEM *)); os_thread_t *threads = CALLOC(nthreads, sizeof(os_thread_t)); UT_ASSERTne(threads, NULL); unsigned *pool_idx = CALLOC(nthreads, sizeof(pool_idx[0])); UT_ASSERTne(pool_idx, NULL); for (unsigned pool_id = 0; pool_id < mem_pools_size; ++pool_id) { /* allocate memory for function vmem_create_in_region() */ mem_pools[pool_id] = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20); } /* create and destroy pools multiple times */ for (unsigned t = 0; t < nthreads; t++) { pool_idx[t] = npools * t; PTHREAD_CREATE(&threads[t], NULL, thread_func, &pool_idx[t]); } for (unsigned t = 0; t < nthreads; t++) PTHREAD_JOIN(&threads[t], NULL); for (unsigned pool_id = 0; pool_id < npools * nthreads; ++pool_id) { if (pools[pool_id] != NULL) { vmem_delete(pools[pool_id]); pools[pool_id] = NULL; } } FREE(mem_pools); FREE(pools); FREE(threads); FREE(pool_idx); DONE(NULL); }
4,215
29.550725
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_malloc_usable_size/vmmalloc_malloc_usable_size.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmmalloc_malloc_usable_size.c -- unit test for * libvmmalloc malloc_usable_size * * usage: vmmalloc_malloc_usable_size */ #ifdef __FreeBSD__ #include <malloc_np.h> #else #include <malloc.h> #endif #include "unittest.h" static const struct { size_t size; size_t spacing; } Check_sizes[] = { {.size = 10, .spacing = 8}, {.size = 100, .spacing = 16}, {.size = 200, .spacing = 32}, {.size = 500, .spacing = 64}, {.size = 1000, .spacing = 128}, {.size = 2000, .spacing = 256}, {.size = 3000, .spacing = 512}, {.size = 1 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 2 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 3 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 4 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 5 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 6 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 7 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 8 * 1024 * 1024, .spacing = 4 * 1024 * 1024}, {.size = 9 * 1024 * 1024, .spacing = 4 * 1024 * 1024} }; int main(int argc, char *argv[]) { void *ptr; size_t usable_size; size_t size; int i; START(argc, argv, "vmmalloc_malloc_usable_size"); UT_ASSERTeq(malloc_usable_size(NULL), 0); for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) { size = Check_sizes[i].size; UT_OUT("size %zu", size); ptr = malloc(size); UT_ASSERTne(ptr, NULL); usable_size = malloc_usable_size(ptr); UT_ASSERT(usable_size >= size); if (usable_size - size > Check_sizes[i].spacing) { UT_FATAL("Size %zu: spacing %zu is bigger" "than expected: %zu", size, (usable_size - size), Check_sizes[i].spacing); } memset(ptr, 0xEE, usable_size); UT_ASSERTeq(*(unsigned char *)ptr, 0xEE); free(ptr); } DONE(NULL); }
3,392
31.314286
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_is_zeroed/util_is_zeroed.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util_is_zeroed.c -- unit test for util_is_zeroed */ #include "unittest.h" #include "util.h" int main(int argc, char *argv[]) { START(argc, argv, "util_is_zeroed"); util_init(); char bigbuf[3000]; memset(bigbuf + 0, 0x11, 1000); memset(bigbuf + 1000, 0x0, 1000); memset(bigbuf + 2000, 0xff, 1000); UT_ASSERTeq(util_is_zeroed(bigbuf, 1000), 0); UT_ASSERTeq(util_is_zeroed(bigbuf + 1000, 1000), 1); UT_ASSERTeq(util_is_zeroed(bigbuf + 2000, 1000), 0); UT_ASSERTeq(util_is_zeroed(bigbuf, 0), 1); UT_ASSERTeq(util_is_zeroed(bigbuf + 999, 1000), 0); UT_ASSERTeq(util_is_zeroed(bigbuf + 1000, 1001), 0); UT_ASSERTeq(util_is_zeroed(bigbuf + 1001, 1000), 0); char *buf = bigbuf + 1000; buf[0] = 1; UT_ASSERTeq(util_is_zeroed(buf, 1000), 0); memset(buf, 0, 1000); buf[1] = 1; UT_ASSERTeq(util_is_zeroed(buf, 1000), 0); memset(buf, 0, 1000); buf[239] = 1; UT_ASSERTeq(util_is_zeroed(buf, 1000), 0); memset(buf, 0, 1000); buf[999] = 1; UT_ASSERTeq(util_is_zeroed(buf, 1000), 0); memset(buf, 0, 1000); buf[1000] = 1; UT_ASSERTeq(util_is_zeroed(buf, 1000), 1); DONE(NULL); }
2,711
31.285714
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file/mocks_windows.h
/* * Copyright 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_windows.h -- redefinitions of libc functions * * This file is Windows-specific. * * This file should be included (i.e. using Forced Include) by libpmem * files, when compiled for the purpose of pmem_map_file test. * It would replace default implementation with mocked functions defined * in pmem_map_file.c. * * These defines could be also passed as preprocessor definitions. */ #ifndef WRAP_REAL #define os_posix_fallocate __wrap_os_posix_fallocate #define os_ftruncate __wrap_os_ftruncate #endif
2,123
41.48
74
h
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file/mocks_windows.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_windows.c -- mocked functions used in pmem_map_file.c * (Windows-specific) */ #include "unittest.h" #define MAX_LEN (4 * 1024 * 1024) /* * posix_fallocate -- interpose on libc posix_fallocate() */ FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len) FUNC_MOCK_RUN_DEFAULT { UT_OUT("posix_fallocate: off %ju len %ju", offset, len); if (len > MAX_LEN) return ENOSPC; return _FUNC_REAL(os_posix_fallocate)(fd, offset, len); } FUNC_MOCK_END /* * ftruncate -- interpose on libc ftruncate() */ FUNC_MOCK(os_ftruncate, int, int fd, os_off_t len) FUNC_MOCK_RUN_DEFAULT { UT_OUT("ftruncate: len %ju", len); if (len > MAX_LEN) { errno = ENOSPC; return -1; } return _FUNC_REAL(os_ftruncate)(fd, len); } FUNC_MOCK_END
2,383
34.58209
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file/mocks_posix.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * mocks_posix.c -- mocked functions used in pmem_map_file.c (Posix-specific) */ #define _GNU_SOURCE #include "unittest.h" #include <dlfcn.h> #define MAX_LEN (4 * 1024 * 1024) /* * posix_fallocate -- interpose on libc posix_fallocate() */ int posix_fallocate(int fd, os_off_t offset, off_t len) { UT_OUT("posix_fallocate: off %ju len %ju", offset, len); static int (*posix_fallocate_ptr)(int fd, os_off_t offset, off_t len); if (posix_fallocate_ptr == NULL) posix_fallocate_ptr = dlsym(RTLD_NEXT, "posix_fallocate"); if (len > MAX_LEN) return ENOSPC; return (*posix_fallocate_ptr)(fd, offset, len); } /* * ftruncate -- interpose on libc ftruncate() */ int ftruncate(int fd, os_off_t len) { UT_OUT("ftruncate: len %ju", len); static int (*ftruncate_ptr)(int fd, os_off_t len); if (ftruncate_ptr == NULL) ftruncate_ptr = dlsym(RTLD_NEXT, "ftruncate"); if (len > MAX_LEN) { errno = ENOSPC; return -1; } return (*ftruncate_ptr)(fd, len); }
2,579
30.463415
77
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file/pmem_map_file.c
/* * Copyright 2014-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmem_map_file.c -- unit test for mapping persistent memory for raw access * * usage: pmem_map_file file */ #define _GNU_SOURCE #include "unittest.h" #include <stdlib.h> #define CHECK_BYTES 4096 /* bytes to compare before/after map call */ static ut_jmp_buf_t Jmp; /* * signal_handler -- called on SIGSEGV */ static void signal_handler(int sig) { ut_siglongjmp(Jmp); } #define PMEM_FILE_ALL_FLAGS\ (PMEM_FILE_CREATE|PMEM_FILE_EXCL|PMEM_FILE_SPARSE|PMEM_FILE_TMPFILE) static int is_dev_dax = 0; /* * parse_flags -- parse 'flags' string */ static int parse_flags(const char *flags_str) { int ret = 0; while (*flags_str != '\0') { switch (*flags_str) { case '0': case '-': /* no flags */ break; case 'T': ret |= PMEM_FILE_TMPFILE; break; case 'S': ret |= PMEM_FILE_SPARSE; break; case 'C': ret |= PMEM_FILE_CREATE; break; case 'E': ret |= PMEM_FILE_EXCL; break; case 'X': /* not supported flag */ ret |= (PMEM_FILE_ALL_FLAGS + 1); break; case 'D': is_dev_dax = 1; break; default: UT_FATAL("unknown flags: %c", *flags_str); } flags_str++; }; return ret; } /* * do_check -- check the mapping */ static void do_check(int fd, void *addr, size_t mlen) { /* arrange to catch SEGV */ struct sigaction v; sigemptyset(&v.sa_mask); v.sa_flags = 0; v.sa_handler = signal_handler; SIGACTION(SIGSEGV, &v, NULL); char pat[CHECK_BYTES]; char buf[CHECK_BYTES]; /* write some pattern to the file */ memset(pat, 0x5A, CHECK_BYTES); WRITE(fd, pat, CHECK_BYTES); if (memcmp(pat, addr, CHECK_BYTES)) UT_OUT("first %d bytes do not match", CHECK_BYTES); /* fill up mapped region with new pattern */ memset(pat, 0xA5, CHECK_BYTES); memcpy(addr, pat, CHECK_BYTES); UT_ASSERTeq(pmem_msync(addr, CHECK_BYTES), 0); UT_ASSERTeq(pmem_unmap(addr, mlen), 0); if (!ut_sigsetjmp(Jmp)) { /* same memcpy from above should now fail */ memcpy(addr, pat, CHECK_BYTES); } else { UT_OUT("unmap successful"); } LSEEK(fd, (os_off_t)0, SEEK_SET); if (READ(fd, buf, CHECK_BYTES) == CHECK_BYTES) { if (memcmp(pat, buf, CHECK_BYTES)) UT_OUT("first %d bytes do not match", CHECK_BYTES); } } int main(int argc, char *argv[]) { START(argc, argv, "pmem_map_file"); int fd; void *addr; size_t mlen; size_t *mlenp; const char *path; unsigned long long len; int flags; unsigned mode; int is_pmem; int *is_pmemp; int use_mlen; int use_is_pmem; if (argc < 7) UT_FATAL("usage: %s path len flags mode use_mlen " "use_is_pmem ...", argv[0]); for (int i = 1; i + 5 < argc; i += 6) { path = argv[i]; len = strtoull(argv[i + 1], NULL, 0); flags = parse_flags(argv[i + 2]); mode = STRTOU(argv[i + 3], NULL, 8); use_mlen = atoi(argv[i + 4]); use_is_pmem = atoi(argv[i + 5]); mlen = SIZE_MAX; if (use_mlen) mlenp = &mlen; else mlenp = NULL; if (use_is_pmem) is_pmemp = &is_pmem; else is_pmemp = NULL; UT_OUT("%s %lld %s %o %d %d", path, len, argv[i + 2], mode, use_mlen, use_is_pmem); addr = pmem_map_file(path, len, flags, mode, mlenp, is_pmemp); if (addr == NULL) { UT_OUT("!pmem_map_file"); continue; } if (use_mlen) { UT_ASSERTne(mlen, SIZE_MAX); UT_OUT("mapped_len %zu", mlen); } else { mlen = len; } if (addr) { /* is_pmem must be true for device DAX */ int is_pmem_check = pmem_is_pmem(addr, mlen); UT_ASSERT(!is_dev_dax || is_pmem_check); /* check is_pmem returned from pmem_map_file */ if (use_is_pmem) UT_ASSERTeq(is_pmem, is_pmem_check); if ((flags & PMEM_FILE_TMPFILE) == 0 && !is_dev_dax) { fd = OPEN(argv[i], O_RDWR); if (!use_mlen) { os_stat_t stbuf; FSTAT(fd, &stbuf); mlen = (size_t)stbuf.st_size; } if (fd != -1) { do_check(fd, addr, mlen); (void) CLOSE(fd); } else { UT_OUT("!cannot open file: %s", argv[i]); } } else { UT_ASSERTeq(pmem_unmap(addr, mlen), 0); } } } DONE(NULL); } #ifdef _MSC_VER /* * Since libpmem is linked statically, we need to invoke its ctor/dtor. */ MSVC_CONSTR(libpmem_init) MSVC_DESTR(libpmem_fini) #endif
5,733
22.404082
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_callbacks/obj_tx_callbacks.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_callbacks.c -- unit test for transaction stage callbacks */ #include "unittest.h" #define LAYOUT_NAME "tx_callback" POBJ_LAYOUT_BEGIN(tx_callback); POBJ_LAYOUT_ROOT(tx_callback, struct pmem_root); POBJ_LAYOUT_TOID(tx_callback, struct pmem_obj); POBJ_LAYOUT_END(tx_callback); struct runtime_info { int something; }; struct pmem_obj { struct runtime_info *rt; int pmem_info; }; struct pmem_root { TOID(struct pmem_obj) obj; }; struct free_info { void *to_free; }; static int freed = 0; static const char *desc[] = { "TX_STAGE_NONE", "TX_STAGE_WORK", "TX_STAGE_ONCOMMIT", "TX_STAGE_ONABORT", "TX_STAGE_FINALLY", "WTF?" }; static void free_onabort(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg) { UT_OUT("cb stage: %s", desc[stage]); if (stage == TX_STAGE_ONABORT) { struct free_info *f = (struct free_info *)arg; UT_OUT("rt_onabort: free"); free(f->to_free); freed++; } } static void allocate_pmem(struct free_info *f, TOID(struct pmem_root) root, int val) { TOID(struct pmem_obj) obj = TX_NEW(struct pmem_obj); D_RW(obj)->pmem_info = val; D_RW(obj)->rt = (struct runtime_info *)malloc(sizeof(struct runtime_info)); f->to_free = D_RW(obj)->rt; D_RW(obj)->rt->something = val; TX_ADD_FIELD(root, obj); D_RW(root)->obj = obj; } static void do_something_fishy(TOID(struct pmem_root) root) { TX_ADD_FIELD(root, obj); D_RW(root)->obj = TX_ALLOC(struct pmem_obj, 1 << 30); } static void free_oncommit(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg) { UT_OUT("cb stage: %s", desc[stage]); if (stage == TX_STAGE_ONCOMMIT) { struct free_info *f = (struct free_info *)arg; UT_OUT("rt_oncommit: free"); free(f->to_free); freed++; } } static void free_pmem(struct free_info *f, TOID(struct pmem_root) root) { TOID(struct pmem_obj) obj = D_RW(root)->obj; f->to_free = D_RW(obj)->rt; TX_FREE(obj); TX_SET(root, obj, TOID_NULL(struct pmem_obj)); } static void log_stages(PMEMobjpool *pop, enum pobj_tx_stage stage, void *arg) { UT_OUT("cb stage: %s", desc[stage]); } static void test(PMEMobjpool *pop, TOID(struct pmem_root) root) { struct free_info *volatile f = (struct free_info *)ZALLOC(sizeof(*f)); TX_BEGIN_CB(pop, free_onabort, f) { allocate_pmem(f, root, 7); do_something_fishy(root); UT_ASSERT(0); } TX_ONCOMMIT { UT_ASSERT(0); } TX_ONABORT { UT_OUT("on abort 1"); } TX_FINALLY { UT_OUT("finally 1"); } TX_END UT_OUT("end of tx 1\n"); memset(f, 0, sizeof(*f)); UT_ASSERTeq(freed, 1); freed = 0; TX_BEGIN_CB(pop, free_onabort, f) { allocate_pmem(f, root, 7); } TX_ONCOMMIT { UT_OUT("on commit 2"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("finally 2"); } TX_END UT_OUT("end of tx 2\n"); memset(f, 0, sizeof(*f)); UT_ASSERTeq(freed, 0); TX_BEGIN_CB(pop, free_oncommit, f) { free_pmem(f, root); do_something_fishy(root); UT_ASSERT(0); } TX_ONCOMMIT { UT_ASSERT(0); } TX_ONABORT { UT_OUT("on abort 3"); } TX_FINALLY { UT_OUT("finally 3"); } TX_END UT_OUT("end of tx 3\n"); memset(f, 0, sizeof(*f)); UT_ASSERTeq(freed, 0); TX_BEGIN_CB(pop, free_oncommit, f) { free_pmem(f, root); } TX_ONCOMMIT { UT_OUT("on commit 4"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("finally 4"); } TX_END UT_OUT("end of tx 4\n"); memset(f, 0, sizeof(*f)); UT_ASSERTeq(freed, 1); freed = 0; TX_BEGIN_CB(pop, log_stages, NULL) { TX_BEGIN(pop) { UT_OUT("inner tx work 5"); } TX_ONCOMMIT { UT_OUT("inner tx on commit 5"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("inner tx finally 5"); } TX_END } TX_ONCOMMIT { UT_OUT("on commit 5"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("finally 5"); } TX_END UT_OUT("end of tx 5\n"); TX_BEGIN(pop) { TX_BEGIN_CB(pop, log_stages, NULL) { UT_OUT("inner tx work 6"); } TX_ONCOMMIT { UT_OUT("inner tx on commit 6"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("inner tx finally 6"); } TX_END } TX_ONCOMMIT { UT_OUT("on commit 6"); } TX_ONABORT { UT_ASSERT(0); } TX_FINALLY { UT_OUT("finally 6"); } TX_END UT_OUT("end of tx 6\n"); UT_OUT("start of tx 7"); if (pmemobj_tx_begin(pop, NULL, TX_PARAM_CB, log_stages, NULL, TX_PARAM_NONE)) UT_FATAL("!pmemobj_tx_begin"); UT_OUT("work"); pmemobj_tx_commit(); UT_OUT("on commit"); if (pmemobj_tx_end()) UT_FATAL("!pmemobj_tx_end"); UT_OUT("end of tx 7\n"); FREE(f); } int main(int argc, char *argv[]) { START(argc, argv, "obj_tx_callbacks"); if (argc != 2) UT_FATAL("usage: %s [file]", argv[0]); PMEMobjpool *pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); if (!pop) UT_FATAL("!pmemobj_create"); TOID(struct pmem_root) root = POBJ_ROOT(pop, struct pmem_root); test(pop, root); pmemobj_close(pop); DONE(NULL); }
6,411
22.487179
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_cpuid/util_cpuid.c
/* * Copyright 2015-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * util_cpuid.c -- unit test for CPU features detection */ #define _GNU_SOURCE #include <emmintrin.h> #include "unittest.h" #include "cpu.h" #ifndef _MSC_VER /* * The x86 memory instructions are new enough that the compiler * intrinsic functions are not always available. The intrinsic * functions are defined here in terms of asm statements for now. */ #define _mm_clflushopt(addr)\ asm volatile(".byte 0x66; clflush %0" :\ "+m" (*(volatile char *)(addr))); #define _mm_clwb(addr)\ asm volatile(".byte 0x66; xsaveopt %0" :\ "+m" (*(volatile char *)(addr))); #endif static char Buf[32]; /* * check_cpu_features -- validates CPU features detection */ static void check_cpu_features(void) { if (is_cpu_clflush_present()) { UT_OUT("CLFLUSH supported"); _mm_clflush(Buf); } else { UT_OUT("CLFLUSH not supported"); } if (is_cpu_clflushopt_present()) { UT_OUT("CLFLUSHOPT supported"); _mm_clflushopt(Buf); } else { UT_OUT("CLFLUSHOPT not supported"); } if (is_cpu_clwb_present()) { UT_OUT("CLWB supported"); _mm_clwb(Buf); } else { UT_OUT("CLWB not supported"); } } int main(int argc, char *argv[]) { START(argc, argv, "util_cpuid"); check_cpu_features(); DONE(NULL); }
2,821
28.395833
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_heap/obj_heap.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_heap.c -- unit test for heap */ #include "libpmemobj.h" #include "palloc.h" #include "heap.h" #include "recycler.h" #include "obj.h" #include "unittest.h" #include "util.h" #include "container_ravl.h" #include "container_seglists.h" #include "container.h" #include "alloc_class.h" #include "valgrind_internal.h" #include "set.h" #define MOCK_POOL_SIZE PMEMOBJ_MIN_POOL #define MAX_BLOCKS 3 struct mock_pop { PMEMobjpool p; void *heap; }; static int obj_heap_persist(void *ctx, const void *ptr, size_t sz, unsigned flags) { UT_ASSERTeq(pmem_msync(ptr, sz), 0); return 0; } static int obj_heap_flush(void *ctx, const void *ptr, size_t sz, unsigned flags) { UT_ASSERTeq(pmem_msync(ptr, sz), 0); return 0; } static void obj_heap_drain(void *ctx) { } static void * obj_heap_memset(void *ctx, void *ptr, int c, size_t sz, unsigned flags) { memset(ptr, c, sz); UT_ASSERTeq(pmem_msync(ptr, sz), 0); return ptr; } static void init_run_with_score(struct heap_layout *l, uint32_t chunk_id, int score) { l->zone0.chunk_headers[chunk_id].size_idx = 1; l->zone0.chunk_headers[chunk_id].type = CHUNK_TYPE_RUN; l->zone0.chunk_headers[chunk_id].flags = 0; struct chunk_run *run = (struct chunk_run *) &l->zone0.chunks[chunk_id]; VALGRIND_DO_MAKE_MEM_UNDEFINED(run, sizeof(*run)); run->hdr.block_size = 1024; memset(run->content, 0xFF, RUN_DEFAULT_BITMAP_SIZE); UT_ASSERTeq(score % 64, 0); score /= 64; uint64_t *bitmap = (uint64_t *)run->content; for (; score >= 0; --score) { bitmap[score] = 0; } } static void init_run_with_max_block(struct heap_layout *l, uint32_t chunk_id) { l->zone0.chunk_headers[chunk_id].size_idx = 1; l->zone0.chunk_headers[chunk_id].type = CHUNK_TYPE_RUN; l->zone0.chunk_headers[chunk_id].flags = 0; struct chunk_run *run = (struct chunk_run *) &l->zone0.chunks[chunk_id]; VALGRIND_DO_MAKE_MEM_UNDEFINED(run, sizeof(*run)); uint64_t *bitmap = (uint64_t *)run->content; run->hdr.block_size = 1024; memset(bitmap, 0xFF, RUN_DEFAULT_BITMAP_SIZE); /* the biggest block is 10 bits */ bitmap[3] = 0b1000001110111000111111110000111111000000000011111111110000000011; } static void test_container(struct block_container *bc, struct palloc_heap *heap) { UT_ASSERTne(bc, NULL); struct memory_block a = {1, 0, 1, 4}; struct memory_block b = {1, 0, 2, 8}; struct memory_block c = {1, 0, 3, 16}; struct memory_block d = {1, 0, 5, 32}; init_run_with_score(heap->layout, 1, 128); memblock_rebuild_state(heap, &a); memblock_rebuild_state(heap, &b); memblock_rebuild_state(heap, &c); memblock_rebuild_state(heap, &d); int ret; ret = bc->c_ops->insert(bc, &a); UT_ASSERTeq(ret, 0); ret = bc->c_ops->insert(bc, &b); UT_ASSERTeq(ret, 0); ret = bc->c_ops->insert(bc, &c); UT_ASSERTeq(ret, 0); ret = bc->c_ops->insert(bc, &d); UT_ASSERTeq(ret, 0); struct memory_block invalid_ret = {0, 0, 6, 0}; ret = bc->c_ops->get_rm_bestfit(bc, &invalid_ret); UT_ASSERTeq(ret, ENOMEM); struct memory_block b_ret = {0, 0, 2, 0}; ret = bc->c_ops->get_rm_bestfit(bc, &b_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(b_ret.chunk_id, b.chunk_id); struct memory_block a_ret = {0, 0, 1, 0}; ret = bc->c_ops->get_rm_bestfit(bc, &a_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(a_ret.chunk_id, a.chunk_id); struct memory_block c_ret = {0, 0, 3, 0}; ret = bc->c_ops->get_rm_bestfit(bc, &c_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(c_ret.chunk_id, c.chunk_id); struct memory_block d_ret = {0, 0, 4, 0}; /* less one than target */ ret = bc->c_ops->get_rm_bestfit(bc, &d_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(d_ret.chunk_id, d.chunk_id); ret = bc->c_ops->get_rm_bestfit(bc, &c_ret); UT_ASSERTeq(ret, ENOMEM); ret = bc->c_ops->insert(bc, &a); UT_ASSERTeq(ret, 0); ret = bc->c_ops->insert(bc, &b); UT_ASSERTeq(ret, 0); ret = bc->c_ops->insert(bc, &c); UT_ASSERTeq(ret, 0); bc->c_ops->rm_all(bc); ret = bc->c_ops->is_empty(bc); UT_ASSERTeq(ret, 1); ret = bc->c_ops->get_rm_bestfit(bc, &c_ret); UT_ASSERTeq(ret, ENOMEM); bc->c_ops->destroy(bc); } static void test_heap(void) { struct mock_pop *mpop = MMAP_ANON_ALIGNED(MOCK_POOL_SIZE, Ut_mmap_align); PMEMobjpool *pop = &mpop->p; memset(pop, 0, MOCK_POOL_SIZE); pop->heap_offset = (uint64_t)((uint64_t)&mpop->heap - (uint64_t)mpop); pop->p_ops.persist = obj_heap_persist; pop->p_ops.flush = obj_heap_flush; pop->p_ops.drain = obj_heap_drain; pop->p_ops.memset = obj_heap_memset; pop->p_ops.base = pop; pop->set = MALLOC(sizeof(*(pop->set))); pop->set->options = 0; pop->set->directory_based = 0; struct stats *s = stats_new(pop); UT_ASSERTne(s, NULL); void *heap_start = (char *)pop + pop->heap_offset; uint64_t heap_size = MOCK_POOL_SIZE - sizeof(PMEMobjpool); struct palloc_heap *heap = &pop->heap; struct pmem_ops *p_ops = &pop->p_ops; UT_ASSERT(heap_check(heap_start, heap_size) != 0); UT_ASSERT(heap_init(heap_start, heap_size, &pop->heap_size, p_ops) == 0); UT_ASSERT(heap_boot(heap, heap_start, heap_size, &pop->heap_size, pop, p_ops, s, pop->set) == 0); UT_ASSERT(heap_buckets_init(heap) == 0); UT_ASSERT(pop->heap.rt != NULL); test_container((struct block_container *)container_new_ravl(heap), heap); test_container((struct block_container *)container_new_seglists(heap), heap); struct alloc_class *c_small = heap_get_best_class(heap, 1); struct alloc_class *c_big = heap_get_best_class(heap, 2048); UT_ASSERT(c_small->unit_size < c_big->unit_size); /* new small buckets should be empty */ UT_ASSERT(c_big->type == CLASS_RUN); struct memory_block blocks[MAX_BLOCKS] = { {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0} }; struct bucket *b_def = heap_bucket_acquire_by_id(heap, DEFAULT_ALLOC_CLASS_ID); for (int i = 0; i < MAX_BLOCKS; ++i) { heap_get_bestfit_block(heap, b_def, &blocks[i]); UT_ASSERT(blocks[i].block_off == 0); } heap_bucket_release(heap, b_def); struct memory_block old_run = {0, 0, 1, 0}; struct memory_block new_run = {0, 0, 0, 0}; struct alloc_class *c_run = heap_get_best_class(heap, 1024); struct bucket *b_run = heap_bucket_acquire(heap, c_run); /* * Allocate blocks from a run until one run is exhausted. */ UT_ASSERTne(heap_get_bestfit_block(heap, b_run, &old_run), ENOMEM); int *nresv = bucket_current_resvp(b_run); do { new_run.chunk_id = 0; new_run.block_off = 0; new_run.size_idx = 1; UT_ASSERTne(heap_get_bestfit_block(heap, b_run, &new_run), ENOMEM); UT_ASSERTne(new_run.size_idx, 0); *nresv = 0; } while (old_run.block_off != new_run.block_off); *nresv = 0; heap_bucket_release(heap, b_run); stats_delete(pop, s); UT_ASSERT(heap_check(heap_start, heap_size) == 0); heap_cleanup(heap); UT_ASSERT(heap->rt == NULL); FREE(pop->set); MUNMAP_ANON_ALIGNED(mpop, MOCK_POOL_SIZE); } static void test_recycler(void) { struct mock_pop *mpop = MMAP_ANON_ALIGNED(MOCK_POOL_SIZE, Ut_mmap_align); PMEMobjpool *pop = &mpop->p; memset(pop, 0, MOCK_POOL_SIZE); pop->heap_offset = (uint64_t)((uint64_t)&mpop->heap - (uint64_t)mpop); pop->p_ops.persist = obj_heap_persist; pop->p_ops.flush = obj_heap_flush; pop->p_ops.drain = obj_heap_drain; pop->p_ops.memset = obj_heap_memset; pop->p_ops.base = pop; pop->set = MALLOC(sizeof(*(pop->set))); pop->set->options = 0; pop->set->directory_based = 0; void *heap_start = (char *)pop + pop->heap_offset; uint64_t heap_size = MOCK_POOL_SIZE - sizeof(PMEMobjpool); struct palloc_heap *heap = &pop->heap; struct pmem_ops *p_ops = &pop->p_ops; struct stats *s = stats_new(pop); UT_ASSERTne(s, NULL); UT_ASSERT(heap_check(heap_start, heap_size) != 0); UT_ASSERT(heap_init(heap_start, heap_size, &pop->heap_size, p_ops) == 0); UT_ASSERT(heap_boot(heap, heap_start, heap_size, &pop->heap_size, pop, p_ops, s, pop->set) == 0); UT_ASSERT(heap_buckets_init(heap) == 0); UT_ASSERT(pop->heap.rt != NULL); /* trigger heap bucket populate */ struct memory_block m = MEMORY_BLOCK_NONE; m.size_idx = 1; struct bucket *b = heap_bucket_acquire_by_id(heap, DEFAULT_ALLOC_CLASS_ID); UT_ASSERT(heap_get_bestfit_block(heap, b, &m) == 0); heap_bucket_release(heap, b); int ret; struct recycler *r = recycler_new(&pop->heap, 10000 /* never recalc */); UT_ASSERTne(r, NULL); init_run_with_score(pop->heap.layout, 0, 64); init_run_with_score(pop->heap.layout, 1, 128); init_run_with_score(pop->heap.layout, 15, 0); struct memory_block mrun = {0, 0, 1, 0}; struct memory_block mrun2 = {1, 0, 1, 0}; memblock_rebuild_state(&pop->heap, &mrun); memblock_rebuild_state(&pop->heap, &mrun2); ret = recycler_put(r, &mrun, recycler_element_new(&pop->heap, &mrun)); UT_ASSERTeq(ret, 0); ret = recycler_put(r, &mrun2, recycler_element_new(&pop->heap, &mrun2)); UT_ASSERTeq(ret, 0); struct memory_block mrun_ret = MEMORY_BLOCK_NONE; mrun_ret.size_idx = 1; struct memory_block mrun2_ret = MEMORY_BLOCK_NONE; mrun2_ret.size_idx = 1; ret = recycler_get(r, &mrun_ret); UT_ASSERTeq(ret, 0); ret = recycler_get(r, &mrun2_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(mrun2.chunk_id, mrun2_ret.chunk_id); UT_ASSERTeq(mrun.chunk_id, mrun_ret.chunk_id); init_run_with_score(pop->heap.layout, 7, 64); init_run_with_score(pop->heap.layout, 2, 128); init_run_with_score(pop->heap.layout, 5, 192); init_run_with_score(pop->heap.layout, 10, 256); mrun.chunk_id = 7; mrun2.chunk_id = 2; struct memory_block mrun3 = {5, 0, 1, 0}; struct memory_block mrun4 = {10, 0, 1, 0}; memblock_rebuild_state(&pop->heap, &mrun3); memblock_rebuild_state(&pop->heap, &mrun4); mrun_ret.size_idx = 1; mrun2_ret.size_idx = 1; struct memory_block mrun3_ret = MEMORY_BLOCK_NONE; mrun3_ret.size_idx = 1; struct memory_block mrun4_ret = MEMORY_BLOCK_NONE; mrun4_ret.size_idx = 1; ret = recycler_put(r, &mrun, recycler_element_new(&pop->heap, &mrun)); UT_ASSERTeq(ret, 0); ret = recycler_put(r, &mrun2, recycler_element_new(&pop->heap, &mrun2)); UT_ASSERTeq(ret, 0); ret = recycler_put(r, &mrun3, recycler_element_new(&pop->heap, &mrun3)); UT_ASSERTeq(ret, 0); ret = recycler_put(r, &mrun4, recycler_element_new(&pop->heap, &mrun4)); UT_ASSERTeq(ret, 0); ret = recycler_get(r, &mrun_ret); UT_ASSERTeq(ret, 0); ret = recycler_get(r, &mrun2_ret); UT_ASSERTeq(ret, 0); ret = recycler_get(r, &mrun3_ret); UT_ASSERTeq(ret, 0); ret = recycler_get(r, &mrun4_ret); UT_ASSERTeq(ret, 0); UT_ASSERTeq(mrun.chunk_id, mrun_ret.chunk_id); UT_ASSERTeq(mrun2.chunk_id, mrun2_ret.chunk_id); UT_ASSERTeq(mrun3.chunk_id, mrun3_ret.chunk_id); UT_ASSERTeq(mrun4.chunk_id, mrun4_ret.chunk_id); init_run_with_max_block(pop->heap.layout, 1); struct memory_block mrun5 = {1, 0, 1, 0}; memblock_rebuild_state(&pop->heap, &mrun5); ret = recycler_put(r, &mrun5, recycler_element_new(&pop->heap, &mrun5)); UT_ASSERTeq(ret, 0); struct memory_block mrun5_ret = MEMORY_BLOCK_NONE; mrun5_ret.size_idx = 11; ret = recycler_get(r, &mrun5_ret); UT_ASSERTeq(ret, ENOMEM); mrun5_ret = MEMORY_BLOCK_NONE; mrun5_ret.size_idx = 10; ret = recycler_get(r, &mrun5_ret); UT_ASSERTeq(ret, 0); recycler_delete(r); stats_delete(pop, s); heap_cleanup(heap); UT_ASSERT(heap->rt == NULL); FREE(pop->set); MUNMAP_ANON_ALIGNED(mpop, MOCK_POOL_SIZE); } int main(int argc, char *argv[]) { START(argc, argv, "obj_heap"); test_heap(); test_recycler(); DONE(NULL); }
12,892
26.967462
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmreorder_stack/pmreorder_stack.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmreorder_stack.c -- unit test for engines pmreorder stack * * usage: pmreorder_stack w|c file * w - write data in a possibly inconsistent manner * c - check data consistency * */ #include "unittest.h" #include "util.h" #include "valgrind_internal.h" /* * Consistent only if field 'e' is set and field 'f' is not. */ struct fields { int a; int b; int c; int d; int e; int f; int g; int h; int i; int j; int k; int l; }; /* * write_fields -- (internal) write data in a consistent manner. */ static void write_fields(struct fields *fieldsp) { VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.BEGIN"); VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.BEGIN"); fieldsp->a = 1; fieldsp->b = 1; fieldsp->c = 1; fieldsp->d = 1; pmem_persist(&fieldsp->a, sizeof(int) * 4); VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.END"); fieldsp->e = 1; fieldsp->f = 1; fieldsp->g = 1; fieldsp->h = 1; pmem_persist(&fieldsp->e, sizeof(int) * 4); VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.END"); fieldsp->i = 1; fieldsp->j = 1; fieldsp->k = 1; fieldsp->l = 1; pmem_persist(&fieldsp->i, sizeof(int) * 4); } /* * check_consistency -- (internal) check struct fields consistency. */ static int check_consistency(struct fields *fieldsp) { int consistency = 1; if (fieldsp->e == 1 && fieldsp->f == 0) consistency = 0; return consistency; } int main(int argc, char *argv[]) { START(argc, argv, "pmreorder_stack"); VALGRIND_EMIT_LOG("NOT_DEFINED_BY_USER.END"); util_init(); if ((argc != 3) || (strchr("wc", argv[1][0]) == NULL) || argv[1][1] != '\0') UT_FATAL("usage: %s w|c file", argv[0]); int fd = OPEN(argv[2], O_RDWR); size_t size; /* mmap and register in valgrind pmemcheck */ void *map = pmem_map_file(argv[2], 0, 0, 0, &size, NULL); UT_ASSERTne(map, NULL); UT_ASSERT(size >= sizeof(struct fields)); struct fields *fieldsp = map; char opt = argv[1][0]; /* clear the struct to get a consistent start state for writing */ if (strchr("w", opt)) pmem_memset_persist(fieldsp, 0, sizeof(*fieldsp)); switch (opt) { case 'w': write_fields(fieldsp); break; case 'c': return check_consistency(fieldsp); default: UT_FATAL("Unrecognized option %c", opt); } CLOSE(fd); DONE(NULL); }
3,820
23.811688
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_memmove/pmem_memmove.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_memmove.c -- unit test for doing a memmove * * usage: * pmem_memmove file b:length [d:{offset}] [s:offset] [o:{1|2} S:{overlap}] * */ #include "unittest.h" #include "util_pmem.h" #include "file.h" typedef void *pmem_memmove_fn(void *pmemdest, const void *src, size_t len, unsigned flags); 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); } /* * 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. * In the event of an error caller must unmap all passed in mappings. */ static void swap_mappings(char **dest, char **src, size_t size, int fd) { char *d = *dest; char *s = *src; char *ts; char *td; 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; } /* * verify_contents -- verify that buffers match, if they don't - print contents * of both and abort the test */ static void verify_contents(const char *file_name, int test, const char *buf1, const char *buf2, size_t len) { if (memcmp(buf1, buf2, len) == 0) return; for (size_t i = 0; i < len; ++i) UT_ERR("%04zu 0x%02x 0x%02x %s", i, (uint8_t)buf1[i], (uint8_t)buf2[i], buf1[i] != buf2[i] ? "!!!" : ""); UT_FATAL("%s %d: %zu bytes do not match with memcmp", file_name, test, len); } /* * do_memmove: Worker function for memmove. * * 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_memmove(int ddax, char *dst, char *src, const char *file_name, size_t dest_off, size_t src_off, size_t bytes, pmem_memmove_fn fn, unsigned flags) { void *ret; char *srcshadow = MALLOC(dest_off + src_off + bytes); char *dstshadow = srcshadow; if (src != dst) dstshadow = MALLOC(dest_off + src_off + bytes); char old; memset(src, 0x11, bytes); memset(dst, 0x22, bytes); memset(src, 0x33, bytes / 4); memset(src + bytes / 4, 0x44, bytes / 4); util_persist_auto(ddax, src, bytes); util_persist_auto(ddax, dst, bytes); memcpy(srcshadow, src, bytes); memcpy(dstshadow, dst, bytes); /* TEST 1, dest == src */ old = *(char *)(dst + dest_off); ret = fn(dst + dest_off, dst + dest_off, bytes / 2, flags); UT_ASSERTeq(ret, dst + dest_off); UT_ASSERTeq(*(char *)(dst + dest_off), old); /* do the same using regular memmove and verify that buffers match */ memmove(dstshadow + dest_off, dstshadow + dest_off, bytes / 2); verify_contents(file_name, 0, dstshadow, dst, bytes); verify_contents(file_name, 1, srcshadow, src, bytes); /* TEST 2, len == 0 */ old = *(char *)(dst + dest_off); ret = fn(dst + dest_off, src + src_off, 0, flags); UT_ASSERTeq(ret, dst + dest_off); UT_ASSERTeq(*(char *)(dst + dest_off), old); /* do the same using regular memmove and verify that buffers match */ memmove(dstshadow + dest_off, srcshadow + src_off, 0); verify_contents(file_name, 2, dstshadow, dst, bytes); verify_contents(file_name, 3, srcshadow, src, bytes); /* TEST 3, len == bytes / 2 */ ret = fn(dst + dest_off, src + src_off, bytes / 2, flags); UT_ASSERTeq(ret, dst + dest_off); if (flags & PMEM_F_MEM_NOFLUSH) /* for pmemcheck */ util_persist_auto(ddax, dst + dest_off, bytes / 2); /* do the same using regular memmove and verify that buffers match */ memmove(dstshadow + dest_off, srcshadow + src_off, bytes / 2); verify_contents(file_name, 4, dstshadow, dst, bytes); verify_contents(file_name, 5, srcshadow, src, bytes); FREE(srcshadow); if (dstshadow != srcshadow) FREE(dstshadow); } #define USAGE() do { UT_FATAL("usage: %s file b:length [d:{offset}] "\ "[s:{offset}] [o:{0|1}]", argv[0]); } while (0) static unsigned Flags[] = { 0, PMEM_F_MEM_NODRAIN, PMEM_F_MEM_NONTEMPORAL, PMEM_F_MEM_TEMPORAL, PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL, PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_NODRAIN, PMEM_F_MEM_WC, PMEM_F_MEM_WB, PMEM_F_MEM_NOFLUSH, /* all possible flags */ PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH | PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL | PMEM_F_MEM_WC | PMEM_F_MEM_WB, }; static void do_memmove_variants(int ddax, char *dst, char *src, const char *file_name, size_t dest_off, size_t src_off, size_t bytes) { do_memmove(ddax, dst, src, file_name, dest_off, src_off, bytes, pmem_memmove_persist_wrapper, 0); do_memmove(ddax, dst, src, file_name, dest_off, src_off, bytes, pmem_memmove_nodrain_wrapper, 0); for (int i = 0; i < ARRAY_SIZE(Flags); ++i) { do_memmove(ddax, dst, src, file_name, dest_off, src_off, bytes, pmem_memmove, Flags[i]); } } int main(int argc, char *argv[]) { int fd; char *dst; char *src; size_t dst_off = 0; size_t src_off = 0; size_t bytes = 0; int who = 0; size_t mapped_len; const char *thr = getenv("PMEM_MOVNT_THRESHOLD"); const char *avx = getenv("PMEM_AVX"); const char *avx512f = getenv("PMEM_AVX512F"); START(argc, argv, "pmem_memmove %s %s %s %s %savx %savx512f", argc > 2 ? argv[2] : "null", argc > 3 ? argv[3] : "null", argc > 4 ? argv[4] : "null", thr ? thr : "default", avx ? "" : "!", avx512f ? "" : "!"); fd = OPEN(argv[1], O_RDWR); enum file_type type = util_fd_get_type(fd); if (type < 0) UT_FATAL("cannot check type of file %s", argv[1]); if (argc < 3) USAGE(); for (int arg = 2; arg < argc; arg++) { if (strchr("dsbo", argv[arg][0]) == NULL || argv[arg][1] != ':') UT_FATAL("op must be d: or s: or b: or o:"); size_t val = STRTOUL(&argv[arg][2], NULL, 0); switch (argv[arg][0]) { case 'd': if (val <= 0) UT_FATAL("bad offset (%lu) with d: option", val); dst_off = val; break; case 's': if (val <= 0) UT_FATAL("bad offset (%lu) with s: option", val); src_off = val; break; case 'b': if (val <= 0) UT_FATAL("bad length (%lu) with b: option", val); bytes = val; break; case 'o': if (val != 1 && val != 0) UT_FATAL("bad val (%lu) with o: option", val); who = (int)val; break; } } if (who == 0) { /* src > dest */ dst = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL); if (dst == NULL) UT_FATAL("!could not mmap dest file %s", argv[1]); src = MMAP(dst + 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. Log * the error if the mapped addresses cannot be swapped * but allow the test to continue. */ if (src <= dst) { swap_mappings(&dst, &src, mapped_len, fd); if (src <= dst) UT_FATAL("cannot map files in memory order"); } do_memmove_variants(type == TYPE_DEVDAX, dst, src, argv[1], dst_off, src_off, bytes); /* dest > src */ swap_mappings(&dst, &src, mapped_len, fd); if (dst <= src) UT_FATAL("cannot map files in memory order"); do_memmove_variants(type == TYPE_DEVDAX, dst, src, argv[1], dst_off, src_off, bytes); int ret = pmem_unmap(dst, mapped_len); UT_ASSERTeq(ret, 0); MUNMAP(src, mapped_len); } else { /* use the same buffer for source and destination */ dst = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL); if (dst == NULL) UT_FATAL("!Could not mmap %s: \n", argv[1]); memset(dst, 0, bytes); util_persist_auto(type == TYPE_DEVDAX, dst, bytes); do_memmove_variants(type == TYPE_DEVDAX, dst, dst, argv[1], dst_off, src_off, bytes); int ret = pmem_unmap(dst, mapped_len); UT_ASSERTeq(ret, 0); } CLOSE(fd); DONE(NULL); }
10,012
27.690544
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_heap_size/obj_ctl_heap_size.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_heap_size.c -- tests for the ctl entry points: heap.size.* */ #include "unittest.h" #define LAYOUT "obj_ctl_heap_size" #define CUSTOM_GRANULARITY ((1 << 20) * 10) #define OBJ_SIZE 1024 int main(int argc, char *argv[]) { START(argc, argv, "obj_ctl_heap_size"); if (argc != 3) UT_FATAL("usage: %s poolset [w|x]", argv[0]); const char *path = argv[1]; char t = argv[2][0]; PMEMobjpool *pop; if ((pop = pmemobj_open(path, LAYOUT)) == NULL) UT_FATAL("!pmemobj_open: %s", path); int ret = 0; size_t disable_granularity = 0; ret = pmemobj_ctl_set(pop, "heap.size.granularity", &disable_granularity); UT_ASSERTeq(ret, 0); /* allocate until OOM */ while (pmemobj_alloc(pop, NULL, OBJ_SIZE, 0, NULL, NULL) == 0) ; if (t == 'x') { ssize_t extend_size = CUSTOM_GRANULARITY; ret = pmemobj_ctl_exec(pop, "heap.size.extend", &extend_size); UT_ASSERTeq(ret, 0); } else if (t == 'w') { ssize_t new_granularity = CUSTOM_GRANULARITY; ret = pmemobj_ctl_set(pop, "heap.size.granularity", &new_granularity); UT_ASSERTeq(ret, 0); ssize_t curr_granularity; ret = pmemobj_ctl_get(pop, "heap.size.granularity", &curr_granularity); UT_ASSERTeq(ret, 0); UT_ASSERTeq(new_granularity, curr_granularity); } else { UT_ASSERT(0); } /* should succeed */ ret = pmemobj_alloc(pop, NULL, OBJ_SIZE, 0, NULL, NULL); UT_ASSERTeq(ret, 0); pmemobj_close(pop); DONE(NULL); }
3,015
30.416667
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_basic_integration/obj_basic_integration.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_basic_integration.c -- Basic integration tests * */ #include <stddef.h> #include "unittest.h" #define TEST_STR "abcdefgh" #define TEST_STR_LEN 8 #define TEST_VALUE 5 /* * Layout definition */ POBJ_LAYOUT_BEGIN(basic); POBJ_LAYOUT_ROOT(basic, struct dummy_root); POBJ_LAYOUT_TOID(basic, struct dummy_node); POBJ_LAYOUT_TOID(basic, struct dummy_node_c); POBJ_LAYOUT_END(basic); struct dummy_node { int value; char teststr[TEST_STR_LEN]; POBJ_LIST_ENTRY(struct dummy_node) plist; POBJ_LIST_ENTRY(struct dummy_node) plist_m; }; struct dummy_node_c { int value; char teststr[TEST_STR_LEN]; POBJ_LIST_ENTRY(struct dummy_node) plist; POBJ_LIST_ENTRY(struct dummy_node) plist_m; }; struct dummy_root { int value; PMEMmutex lock; TOID(struct dummy_node) node; POBJ_LIST_HEAD(dummy_list, struct dummy_node) dummies; POBJ_LIST_HEAD(moved_list, struct dummy_node) moved; }; static int dummy_node_constructor(PMEMobjpool *pop, void *ptr, void *arg) { struct dummy_node *n = (struct dummy_node *)ptr; int *test_val = (int *)arg; n->value = *test_val; pmemobj_persist(pop, &n->value, sizeof(n->value)); return 0; } static void test_alloc_api(PMEMobjpool *pop) { TOID(struct dummy_node) node_zeroed; TOID(struct dummy_node_c) node_constructed; POBJ_ZNEW(pop, &node_zeroed, struct dummy_node); UT_ASSERT_rt(OID_INSTANCEOF(node_zeroed.oid, struct dummy_node)); int *test_val = (int *)MALLOC(sizeof(*test_val)); *test_val = TEST_VALUE; POBJ_NEW(pop, &node_constructed, struct dummy_node_c, dummy_node_constructor, test_val); FREE(test_val); TOID(struct dummy_node) iter; POBJ_FOREACH_TYPE(pop, iter) { UT_ASSERTeq(D_RO(iter)->value, 0); } TOID(struct dummy_node_c) iter_c; POBJ_FOREACH_TYPE(pop, iter_c) { UT_ASSERTeq(D_RO(iter_c)->value, TEST_VALUE); } PMEMoid oid_iter; int nodes_count = 0; POBJ_FOREACH(pop, oid_iter) { nodes_count++; } UT_ASSERTne(nodes_count, 0); POBJ_FREE(&node_zeroed); POBJ_FREE(&node_constructed); nodes_count = 0; POBJ_FOREACH(pop, oid_iter) { nodes_count++; } UT_ASSERTeq(nodes_count, 0); int val = 10; POBJ_ALLOC(pop, &node_constructed, struct dummy_node_c, sizeof(struct dummy_node_c), dummy_node_constructor, &val); POBJ_REALLOC(pop, &node_constructed, struct dummy_node_c, sizeof(struct dummy_node_c) + 1000); UT_ASSERTeq(pmemobj_type_num(node_constructed.oid), TOID_TYPE_NUM(struct dummy_node_c)); POBJ_ZREALLOC(pop, &node_constructed, struct dummy_node_c, sizeof(struct dummy_node_c) + 2000); UT_ASSERTeq(pmemobj_type_num(node_constructed.oid), TOID_TYPE_NUM(struct dummy_node_c)); POBJ_FREE(&node_constructed); POBJ_ZALLOC(pop, &node_zeroed, struct dummy_node, sizeof(struct dummy_node)); POBJ_FREE(&node_zeroed); int err = 0; err = pmemobj_alloc(pop, NULL, SIZE_MAX, 0, NULL, NULL); UT_ASSERTeq(err, -1); UT_ASSERTeq(errno, ENOMEM); err = pmemobj_zalloc(pop, NULL, SIZE_MAX, 0); UT_ASSERTeq(err, -1); UT_ASSERTeq(errno, ENOMEM); err = pmemobj_alloc(pop, NULL, PMEMOBJ_MAX_ALLOC_SIZE + 1, 0, NULL, NULL); UT_ASSERTeq(err, -1); UT_ASSERTeq(errno, ENOMEM); err = pmemobj_zalloc(pop, NULL, PMEMOBJ_MAX_ALLOC_SIZE + 1, 0); UT_ASSERTeq(err, -1); UT_ASSERTeq(errno, ENOMEM); } static void test_realloc_api(PMEMobjpool *pop) { PMEMoid oid = OID_NULL; int ret; ret = pmemobj_alloc(pop, &oid, 128, 0, NULL, NULL); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("alloc: %u, size: %zu", 128, pmemobj_alloc_usable_size(oid)); /* grow */ ret = pmemobj_realloc(pop, &oid, 655360, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 128, 655360, pmemobj_alloc_usable_size(oid)); /* shrink */ ret = pmemobj_realloc(pop, &oid, 1, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 655360, 1, pmemobj_alloc_usable_size(oid)); /* free */ ret = pmemobj_realloc(pop, &oid, 0, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(OID_IS_NULL(oid)); UT_OUT("free"); /* alloc */ ret = pmemobj_realloc(pop, &oid, 777, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 0, 777, pmemobj_alloc_usable_size(oid)); /* shrink */ ret = pmemobj_realloc(pop, &oid, 1, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 777, 1, pmemobj_alloc_usable_size(oid)); pmemobj_free(&oid); UT_ASSERT(OID_IS_NULL(oid)); UT_ASSERTeq(pmemobj_alloc_usable_size(oid), 0); UT_OUT("free"); /* alloc */ ret = pmemobj_realloc(pop, &oid, 1, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 0, 1, pmemobj_alloc_usable_size(oid)); /* do nothing */ ret = pmemobj_realloc(pop, &oid, 1, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); UT_OUT("realloc: %u => %u, size: %zu", 1, 1, pmemobj_alloc_usable_size(oid)); pmemobj_free(&oid); UT_ASSERT(OID_IS_NULL(oid)); UT_OUT("free"); /* do nothing */ ret = pmemobj_realloc(pop, &oid, 0, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(OID_IS_NULL(oid)); /* alloc */ ret = pmemobj_realloc(pop, &oid, 1, 0); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(oid)); /* grow beyond reasonable size */ ret = pmemobj_realloc(pop, &oid, SIZE_MAX, 0); UT_ASSERTeq(ret, -1); UT_ASSERTeq(errno, ENOMEM); ret = pmemobj_realloc(pop, &oid, PMEMOBJ_MAX_ALLOC_SIZE + 1, 0); UT_ASSERTeq(ret, -1); UT_ASSERTeq(errno, ENOMEM); pmemobj_free(&oid); UT_ASSERT(OID_IS_NULL(oid)); } static void test_list_api(PMEMobjpool *pop) { TOID(struct dummy_root) root; root = POBJ_ROOT(pop, struct dummy_root); int nodes_count = 0; UT_ASSERTeq(pmemobj_type_num(root.oid), POBJ_ROOT_TYPE_NUM); UT_COMPILE_ERROR_ON(TOID_TYPE_NUM_OF(root) != POBJ_ROOT_TYPE_NUM); TOID(struct dummy_node) first; TOID(struct dummy_node) iter; POBJ_LIST_FOREACH_REVERSE(iter, &D_RO(root)->dummies, plist) { UT_OUT("POBJ_LIST_FOREACH_REVERSE: dummy_node %d", D_RO(iter)->value); nodes_count++; } UT_ASSERTeq(nodes_count, 0); int test_val = TEST_VALUE; PMEMoid ret; /* should fail */ ret = POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->dummies, plist, SIZE_MAX, dummy_node_constructor, &test_val); UT_ASSERTeq(errno, ENOMEM); UT_ASSERT(OID_IS_NULL(ret)); errno = 0; ret = POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->dummies, plist, PMEMOBJ_MAX_ALLOC_SIZE + 1, dummy_node_constructor, &test_val); UT_ASSERTeq(errno, ENOMEM); UT_ASSERT(OID_IS_NULL(ret)); POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->dummies, plist, sizeof(struct dummy_node), dummy_node_constructor, &test_val); test_val++; POBJ_LIST_INSERT_NEW_TAIL(pop, &D_RW(root)->dummies, plist, sizeof(struct dummy_node), dummy_node_constructor, &test_val); TOID(struct dummy_node) inserted = POBJ_LIST_FIRST(&D_RW(root)->dummies); UT_ASSERTeq(pmemobj_type_num(inserted.oid), TOID_TYPE_NUM(struct dummy_node)); TOID(struct dummy_node) node; POBJ_ZNEW(pop, &node, struct dummy_node); POBJ_LIST_INSERT_HEAD(pop, &D_RW(root)->dummies, node, plist); nodes_count = 0; POBJ_LIST_FOREACH(iter, &D_RO(root)->dummies, plist) { UT_OUT("POBJ_LIST_FOREACH: dummy_node %d", D_RO(iter)->value); nodes_count++; } UT_ASSERTeq(nodes_count, 3); /* now do the same, but w/o using FOREACH macro */ nodes_count = 0; first = POBJ_LIST_FIRST(&D_RO(root)->dummies); iter = first; do { UT_OUT("POBJ_LIST_NEXT: dummy_node %d", D_RO(iter)->value); nodes_count++; iter = POBJ_LIST_NEXT(iter, plist); } while (!TOID_EQUALS(iter, first)); UT_ASSERTeq(nodes_count, 3); POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(root)->dummies, &D_RW(root)->moved, node, plist, plist_m); UT_ASSERTeq(POBJ_LIST_EMPTY(&D_RW(root)->moved), 0); POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(root)->moved, &D_RW(root)->dummies, node, plist_m, plist); POBJ_LIST_MOVE_ELEMENT_TAIL(pop, &D_RW(root)->dummies, &D_RW(root)->moved, node, plist, plist_m); UT_ASSERTeq(POBJ_LIST_EMPTY(&D_RW(root)->moved), 0); POBJ_LIST_MOVE_ELEMENT_TAIL(pop, &D_RW(root)->moved, &D_RW(root)->dummies, node, plist_m, plist); POBJ_LIST_REMOVE(pop, &D_RW(root)->dummies, node, plist); POBJ_LIST_INSERT_TAIL(pop, &D_RW(root)->dummies, node, plist); POBJ_LIST_REMOVE_FREE(pop, &D_RW(root)->dummies, node, plist); nodes_count = 0; POBJ_LIST_FOREACH_REVERSE(iter, &D_RO(root)->dummies, plist) { UT_OUT("POBJ_LIST_FOREACH_REVERSE: dummy_node %d", D_RO(iter)->value); nodes_count++; } UT_ASSERTeq(nodes_count, 2); /* now do the same, but w/o using FOREACH macro */ nodes_count = 0; first = POBJ_LIST_FIRST(&D_RO(root)->dummies); iter = first; do { UT_OUT("POBJ_LIST_PREV: dummy_node %d", D_RO(iter)->value); nodes_count++; iter = POBJ_LIST_PREV(iter, plist); } while (!TOID_EQUALS(iter, first)); UT_ASSERTeq(nodes_count, 2); test_val++; POBJ_LIST_INSERT_NEW_AFTER(pop, &D_RW(root)->dummies, POBJ_LIST_FIRST(&D_RO(root)->dummies), plist, sizeof(struct dummy_node), dummy_node_constructor, &test_val); test_val++; POBJ_LIST_INSERT_NEW_BEFORE(pop, &D_RW(root)->dummies, POBJ_LIST_LAST(&D_RO(root)->dummies, plist), plist, sizeof(struct dummy_node), dummy_node_constructor, &test_val); nodes_count = 0; POBJ_LIST_FOREACH_REVERSE(iter, &D_RO(root)->dummies, plist) { UT_OUT("POBJ_LIST_FOREACH_REVERSE: dummy_node %d", D_RO(iter)->value); nodes_count++; } UT_ASSERTeq(nodes_count, 4); /* now do the same, but w/o using FOREACH macro */ nodes_count = 0; first = POBJ_LIST_LAST(&D_RO(root)->dummies, plist); iter = first; do { UT_OUT("POBJ_LIST_PREV: dummy_node %d", D_RO(iter)->value); nodes_count++; iter = POBJ_LIST_PREV(iter, plist); } while (!TOID_EQUALS(iter, first)); UT_ASSERTeq(nodes_count, 4); } static void test_tx_api(PMEMobjpool *pop) { TOID(struct dummy_root) root; TOID_ASSIGN(root, pmemobj_root(pop, sizeof(struct dummy_root))); int *vstate = NULL; /* volatile state */ TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { vstate = (int *)MALLOC(sizeof(*vstate)); *vstate = TEST_VALUE; TX_ADD(root); D_RW(root)->value = *vstate; TOID_ASSIGN(D_RW(root)->node, OID_NULL); } TX_FINALLY { FREE(vstate); vstate = NULL; } TX_END UT_ASSERTeq(vstate, NULL); UT_ASSERTeq(D_RW(root)->value, TEST_VALUE); TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); D_RW(root)->node = TX_ALLOC(struct dummy_node, SIZE_MAX); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); UT_ASSERTeq(errno, ENOMEM); } TX_END errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { D_RW(root)->node = TX_ZALLOC(struct dummy_node, SIZE_MAX); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); UT_ASSERTeq(errno, ENOMEM); } TX_END errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { D_RW(root)->node = TX_XALLOC(struct dummy_node, SIZE_MAX, POBJ_XALLOC_ZERO); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); UT_ASSERTeq(errno, ENOMEM); } TX_END errno = 0; TX_BEGIN_LOCK(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { D_RW(root)->node = TX_ALLOC(struct dummy_node, PMEMOBJ_MAX_ALLOC_SIZE + 1); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); UT_ASSERTeq(errno, ENOMEM); } TX_END errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { D_RW(root)->node = TX_ZALLOC(struct dummy_node, PMEMOBJ_MAX_ALLOC_SIZE + 1); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); UT_ASSERTeq(errno, ENOMEM); } TX_END errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); D_RW(root)->node = TX_ZNEW(struct dummy_node); D_RW(root)->node = TX_REALLOC(D_RO(root)->node, SIZE_MAX); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERTeq(errno, ENOMEM); } TX_END UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); D_RW(root)->node = TX_ZNEW(struct dummy_node); D_RW(root)->node = TX_REALLOC(D_RO(root)->node, PMEMOBJ_MAX_ALLOC_SIZE + 1); UT_ASSERT(0); /* should not get to this point */ } TX_ONABORT { UT_ASSERTeq(errno, ENOMEM); } TX_END UT_ASSERT(TOID_IS_NULL(D_RO(root)->node)); errno = 0; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); D_RW(root)->node = TX_ZNEW(struct dummy_node); TX_MEMSET(D_RW(D_RW(root)->node)->teststr, 'a', TEST_STR_LEN); TX_MEMCPY(D_RW(D_RW(root)->node)->teststr, TEST_STR, TEST_STR_LEN); TX_SET(D_RW(root)->node, value, TEST_VALUE); } TX_END UT_ASSERTeq(D_RW(D_RW(root)->node)->value, TEST_VALUE); UT_ASSERT(strncmp(D_RW(D_RW(root)->node)->teststr, TEST_STR, TEST_STR_LEN) == 0); TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); UT_ASSERT(!TOID_IS_NULL(D_RW(root)->node)); TX_FREE(D_RW(root)->node); D_RW(root)->node = TOID_NULL(struct dummy_node); TOID_ASSIGN(D_RW(root)->node, OID_NULL); } TX_END errno = 0; TX_BEGIN(pop) { TX_BEGIN(NULL) { } TX_ONCOMMIT { UT_ASSERT(0); } TX_END UT_ASSERT(errno == EFAULT); } TX_END errno = 0; TX_BEGIN(pop) { TX_BEGIN((PMEMobjpool *)(uintptr_t)7) { } TX_ONCOMMIT { UT_ASSERT(0); } TX_END UT_ASSERT(errno == EINVAL); } TX_END UT_OUT("%s", pmemobj_errormsg()); TX_BEGIN(pop) { pmemobj_tx_abort(ECANCELED); } TX_END UT_OUT("%s", pmemobj_errormsg()); } static void test_action_api(PMEMobjpool *pop) { struct pobj_action act[2]; uint64_t dest_value = 0; PMEMoid oid = pmemobj_reserve(pop, &act[0], 1, 1); pmemobj_set_value(pop, &act[1], &dest_value, 1); pmemobj_publish(pop, act, 2); UT_ASSERTeq(dest_value, 1); pmemobj_free(&oid); UT_ASSERT(OID_IS_NULL(oid)); oid = pmemobj_reserve(pop, &act[0], 1, 1); TX_BEGIN(pop) { pmemobj_tx_publish(act, 1); } TX_ONABORT { UT_ASSERT(0); } TX_END pmemobj_free(&oid); UT_ASSERT(OID_IS_NULL(oid)); dest_value = 0; oid = pmemobj_reserve(pop, &act[0], 1, 1); pmemobj_set_value(pop, &act[1], &dest_value, 1); pmemobj_cancel(pop, act, 2); UT_ASSERTeq(dest_value, 0); TOID(struct dummy_node) n = POBJ_RESERVE_NEW(pop, struct dummy_node, &act[0]); TOID(struct dummy_node_c) c = POBJ_RESERVE_ALLOC(pop, struct dummy_node_c, sizeof(struct dummy_node_c), &act[1]); pmemobj_publish(pop, act, 2); /* valgrind would warn in case they were not allocated */ D_RW(n)->value = 1; D_RW(c)->value = 1; pmemobj_persist(pop, D_RW(n), sizeof(struct dummy_node)); pmemobj_persist(pop, D_RW(c), sizeof(struct dummy_node_c)); } static void test_offsetof(void) { TOID(struct dummy_root) r; TOID(struct dummy_node) n; UT_COMPILE_ERROR_ON(TOID_OFFSETOF(r, value) != offsetof(struct dummy_root, value)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(r, lock) != offsetof(struct dummy_root, lock)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(r, node) != offsetof(struct dummy_root, node)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(r, dummies) != offsetof(struct dummy_root, dummies)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(r, moved) != offsetof(struct dummy_root, moved)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(n, value) != offsetof(struct dummy_node, value)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(n, teststr) != offsetof(struct dummy_node, teststr)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(n, plist) != offsetof(struct dummy_node, plist)); UT_COMPILE_ERROR_ON(TOID_OFFSETOF(n, plist_m) != offsetof(struct dummy_node, plist_m)); } static void test_layout(void) { /* get number of declared types when there are no types declared */ POBJ_LAYOUT_BEGIN(mylayout); POBJ_LAYOUT_END(mylayout); size_t number_of_declared_types = POBJ_LAYOUT_TYPES_NUM(mylayout); UT_ASSERTeq(number_of_declared_types, 0); } static void test_root_size(PMEMobjpool *pop) { UT_ASSERTeq(pmemobj_root_size(pop), 0); size_t alloc_size = sizeof(struct dummy_root); pmemobj_root(pop, alloc_size); UT_ASSERTeq(pmemobj_root_size(pop), sizeof(struct dummy_root)); } int main(int argc, char *argv[]) { START(argc, argv, "obj_basic_integration"); /* root doesn't count */ UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(basic) != 2); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(basic), 0, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); test_root_size(pop); test_alloc_api(pop); test_realloc_api(pop); test_list_api(pop); test_tx_api(pop); test_action_api(pop); test_offsetof(); test_layout(); pmemobj_close(pop); if ((pop = pmemobj_open(path, POBJ_LAYOUT_NAME(basic))) == NULL) UT_FATAL("!pmemobj_open: %s", path); /* second open should fail, checks file locking */ if ((pmemobj_open(path, POBJ_LAYOUT_NAME(basic))) != NULL) UT_FATAL("!pmemobj_open: %s", path); pmemobj_close(pop); int result = pmemobj_check(path, POBJ_LAYOUT_NAME(basic)); if (result < 0) UT_OUT("!%s: pmemobj_check", path); else if (result == 0) UT_OUT("%s: pmemobj_check: not consistent", path); DONE(NULL); }
18,875
26.198847
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/arch_flags/arch_flags.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. */ /* * arch_flags.c -- unit test for architecture flags */ #include <inttypes.h> #include <string.h> #include "unittest.h" #include "pool_hdr.h" #include "pmemcommon.h" #define FATAL_USAGE()\ UT_FATAL(\ "usage: arch_flags <machine>:<machine_class>:<data>:<alignment_desc>:<reserved>") #define ARCH_FLAGS_LOG_PREFIX "arch_flags" #define ARCH_FLAGS_LOG_LEVEL_VAR "ARCH_FLAGS_LOG_LEVEL" #define ARCH_FLAGS_LOG_FILE_VAR "ARCH_FLAGS_LOG_FILE" #define ARCH_FLAGS_LOG_MAJOR 0 #define ARCH_FLAGS_LOG_MINOR 0 /* * read_arch_flags -- read arch flags from file */ static int read_arch_flags(char *opts, struct arch_flags *arch_flags) { uint64_t alignment_desc; uint64_t reserved; uint16_t machine; uint8_t machine_class; uint8_t data; if (sscanf(opts, "%" SCNu16 ":%" SCNu8 ":%" SCNu8 ":0x%" SCNx64 ":0x%" SCNx64, &machine, &machine_class, &data, &alignment_desc, &reserved) != 5) return -1; util_get_arch_flags(arch_flags); if (machine) arch_flags->machine = machine; if (machine_class) arch_flags->machine_class = machine_class; if (data) arch_flags->data = data; if (alignment_desc) arch_flags->alignment_desc = alignment_desc; if (reserved) memcpy(arch_flags->reserved, &reserved, sizeof(arch_flags->reserved)); return 0; } int main(int argc, char *argv[]) { START(argc, argv, "arch_flags"); common_init(ARCH_FLAGS_LOG_PREFIX, ARCH_FLAGS_LOG_LEVEL_VAR, ARCH_FLAGS_LOG_FILE_VAR, ARCH_FLAGS_LOG_MAJOR, ARCH_FLAGS_LOG_MINOR); if (argc < 2) FATAL_USAGE(); int i; for (i = 1; i < argc; i++) { int ret; struct arch_flags arch_flags; if ((ret = read_arch_flags(argv[i], &arch_flags)) < 0) FATAL_USAGE(); else if (ret == 0) { ret = util_check_arch_flags(&arch_flags); UT_OUT("check: %d", ret); } } common_fini(); DONE(NULL); }
3,410
26.959016
82
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_transform/libpmempool_transform.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool_transform -- a unittest for libpmempool transform. * */ #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_transform"); if (argc != 4) UT_FATAL("usage: %s poolset_in poolset_out flags", argv[0]); int ret = pmempool_transform(argv[1], argv[2], (unsigned)strtoul(argv[3], NULL, 0)); if (ret) UT_OUT("result: %d, errno: %d", ret, errno); else UT_OUT("result: %d", ret); DONE(NULL); }
2,138
34.65
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pmemcheck/obj_pmemcheck.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. */ #include "unittest.h" #include "valgrind_internal.h" struct foo { PMEMmutex bar; }; static void test_mutex_pmem_mapping_register(PMEMobjpool *pop) { PMEMoid foo; int ret = pmemobj_alloc(pop, &foo, sizeof(struct foo), 0, NULL, NULL); UT_ASSERTeq(ret, 0); UT_ASSERT(!OID_IS_NULL(foo)); struct foo *foop = pmemobj_direct(foo); ret = pmemobj_mutex_lock(pop, &foop->bar); /* foo->bar has been removed from pmem mappings collection */ VALGRIND_PRINT_PMEM_MAPPINGS; UT_ASSERTeq(ret, 0); ret = pmemobj_mutex_unlock(pop, &foop->bar); UT_ASSERTeq(ret, 0); pmemobj_free(&foo); /* the entire foo object has been re-registered as pmem mapping */ VALGRIND_PRINT_PMEM_MAPPINGS; } int main(int argc, char *argv[]) { START(argc, argv, "obj_pmemcheck"); if (argc != 2) UT_FATAL("usage: %s [file]", argv[0]); PMEMobjpool *pop; if ((pop = pmemobj_create(argv[1], "pmemcheck", PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create"); test_mutex_pmem_mapping_register(pop); pmemobj_close(pop); DONE(NULL); }
2,642
32.455696
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/log_include/log_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * log_include.c -- include test for libpmemlog * * this is only a compilation test - do not run this program */ #include <libpmemlog.h> int main(int argc, char *argv[]) { return 0; }
1,790
37.934783
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmreorder_simple/pmreorder_simple.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * pmreorder_simple.c -- a simple unit test for store reordering * * usage: pmreorder_simple g|b|c file * g - write data in a consistent manner * b - write data in a possibly inconsistent manner * c - check data consistency * */ #include "unittest.h" #include "util.h" #include "valgrind_internal.h" /* * The struct three_field is inconsistent if flag is set and the fields have * different values. */ struct three_field { int first_field; int second_field; int third_field; int flag; }; /* * write_consistent -- (internal) write data in a consistent manner */ static void write_consistent(struct three_field *structp) { structp->first_field = 1; structp->second_field = 1; structp->third_field = 1; pmem_persist(&structp->first_field, sizeof(int) * 3); structp->flag = 1; pmem_persist(&structp->flag, sizeof(structp->flag)); } /* * write_inconsistent -- (internal) write data in an inconsistent manner. */ static void write_inconsistent(struct three_field *structp) { structp->flag = 1; structp->first_field = 1; structp->second_field = 1; structp->third_field = 1; pmem_persist(structp, sizeof(*structp)); } /* * check_consistency -- (internal) check struct three_field consistency */ static int check_consistency(struct three_field *structp) { int consistent = 0; if (structp->flag) consistent = (structp->first_field != structp->second_field) || (structp->first_field != structp->third_field); return consistent; } int main(int argc, char *argv[]) { START(argc, argv, "pmreorder_simple"); util_init(); if ((argc != 3) || (strchr("gbc", argv[1][0]) == NULL) || argv[1][1] != '\0') UT_FATAL("usage: %s g|b|c file", argv[0]); int fd = OPEN(argv[2], O_RDWR); size_t size; /* mmap and register in valgrind pmemcheck */ void *map = pmem_map_file(argv[2], 0, 0, 0, &size, NULL); UT_ASSERTne(map, NULL); struct three_field *structp = map; char opt = argv[1][0]; /* clear the struct to get a consistent start state for writing */ if (strchr("gb", opt)) pmem_memset_persist(structp, 0, sizeof(*structp)); /* verify that DEFAULT_REORDER restores default engine */ VALGRIND_EMIT_LOG("PMREORDER_MARKER_CHANGE.BEGIN"); switch (opt) { case 'g': write_consistent(structp); break; case 'b': write_inconsistent(structp); break; case 'c': return check_consistency(structp); default: UT_FATAL("Unrecognized option %c", opt); } VALGRIND_EMIT_LOG("PMREORDER_MARKER_CHANGE.END"); /* check if undefined marker will not cause an issue */ VALGRIND_EMIT_LOG("PMREORDER_MARKER_UNDEFINED.BEGIN"); VALGRIND_EMIT_LOG("PMREORDER_MARKER_UNDEFINED.END"); CLOSE(fd); DONE(NULL); }
4,261
27.797297
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_vec/util_vec.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_vec.c -- unit test for vec implementation */ #include "unittest.h" #define Realloc REALLOC #include "vec.h" #define Free FREE struct test { int foo; int bar; }; static void vec_test() { VEC(testvec, struct test) v = VEC_INITIALIZER; UT_ASSERTeq(VEC_SIZE(&v), 0); struct test t = {1, 2}; struct test t2 = {3, 4}; VEC_PUSH_BACK(&v, t); VEC_PUSH_BACK(&v, t2); UT_ASSERTeq(VEC_ARR(&v)[0].foo, 1); UT_ASSERTeq(VEC_GET(&v, 1)->foo, 3); UT_ASSERTeq(VEC_SIZE(&v), 2); int n = 0; VEC_FOREACH(t, &v) { switch (n) { case 0: UT_ASSERTeq(t.foo, 1); UT_ASSERTeq(t.bar, 2); break; case 1: UT_ASSERTeq(t.foo, 3); UT_ASSERTeq(t.bar, 4); break; } n++; } UT_ASSERTeq(n, 2); UT_ASSERTeq(VEC_SIZE(&v), n); VEC_POP_BACK(&v); n = 0; VEC_FOREACH(t, &v) { UT_ASSERTeq(t.foo, 1); UT_ASSERTeq(t.bar, 2); n++; } UT_ASSERTeq(n, 1); UT_ASSERTeq(VEC_SIZE(&v), n); VEC_CLEAR(&v); UT_ASSERTeq(VEC_SIZE(&v), 0); VEC_DELETE(&v); } int main(int argc, char *argv[]) { START(argc, argv, "util_vec"); vec_test(); DONE(NULL); }
2,683
23.18018
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmem_addr/rpmem_addr.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. */ /* * rpmem_addr.c -- unit test for parsing target address */ #include "unittest.h" #include "rpmem_common.h" int main(int argc, char *argv[]) { START(argc, argv, "rpmem_addr"); struct rpmem_target_info *info; for (int i = 1; i < argc; i++) { info = rpmem_target_parse(argv[i]); if (info) { UT_OUT("'%s': '%s' '%s' '%s'", argv[i], info->flags & RPMEM_HAS_USER ? info->user : "(null)", *info->node ? info->node : "(null)", info->flags & RPMEM_HAS_SERVICE ? info->service : "(null)"); free(info); } else { UT_OUT("!%s", argv[i]); } } DONE(NULL); }
2,198
33.359375
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/log_pool_lock/log_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. */ /* * log_pool_lock.c -- unit test which checks whether it's possible to * simultaneously open the same log pool */ #include "unittest.h" static void test_reopen(const char *path) { PMEMlogpool *log1 = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR); if (!log1) UT_FATAL("!create"); PMEMlogpool *log2 = pmemlog_open(path); if (log2) UT_FATAL("pmemlog_open should not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemlog_open failed but for unexpected reason"); pmemlog_close(log1); log2 = pmemlog_open(path); if (!log2) UT_FATAL("pmemlog_open should succeed after close"); pmemlog_close(log2); UNLINK(path); } #ifndef _WIN32 static void test_open_in_different_process(int argc, char **argv, unsigned sleep) { pid_t pid = fork(); PMEMlogpool *log; 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); log = pmemlog_open(path); if (log) UT_FATAL("pmemlog_open after fork should not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemlog_open after fork failed but for " "unexpected reason"); exit(0); } log = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR); if (!log) UT_FATAL("!create"); int status; if (waitpid(pid, &status, 0) < 0) UT_FATAL("!waitpid failed"); if (!WIFEXITED(status)) UT_FATAL("child process failed"); pmemlog_close(log); UNLINK(path); } #else static void test_open_in_different_process(int argc, char **argv, unsigned sleep) { PMEMlogpool *log; if (sleep > 0) return; char *path = argv[1]; /* before starting the 2nd process, create a pool */ log = pmemlog_create(path, PMEMLOG_MIN_POOL, S_IWUSR | S_IRUSR); if (!log) 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()); pmemlog_close(log); } #endif int main(int argc, char *argv[]) { START(argc, argv, "log_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) { PMEMlogpool *log; /* 2nd arg used by windows for 2 process test */ log = pmemlog_open(argv[1]); if (log) UT_FATAL("pmemlog_open after create process should " "not succeed"); if (errno != EWOULDBLOCK) UT_FATAL("!pmemlog_open after create process failed " "but for unexpected reason"); } DONE(NULL); }
4,392
25.14881
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_dirty/cto_dirty.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. */ /* * cto_dirty -- unit test for detecting inconsistent pool * * usage: cto_dirty filename [phase] */ #include "unittest.h" #define POOL_SIZE (2 * PMEMCTO_MIN_POOL) #define EXIT_ON(x, y) do {\ if ((x) == (y)) {\ exit(1);\ }\ } while (0) int main(int argc, char *argv[]) { START(argc, argv, "cto_dirty"); if (argc < 2) UT_FATAL("usage: %s filename [phase]", argv[0]); PMEMctopool *pcp; int phase = 0; if (argc > 2) { phase = atoi(argv[2]); pcp = pmemcto_create(argv[1], "test", POOL_SIZE, 0666); UT_ASSERTne(pcp, NULL); } else { pcp = pmemcto_open(argv[1], "test"); if (pcp == NULL) { UT_ERR("pmemcto_open: %s", pmemcto_errormsg()); goto end; } } EXIT_ON(phase, 1); void *ptr = pmemcto_malloc(pcp, 16); UT_ASSERTne(ptr, NULL); pmemcto_set_root_pointer(pcp, ptr); EXIT_ON(phase, 2); pmemcto_free(pcp, ptr); pmemcto_set_root_pointer(pcp, NULL); pmemcto_close(pcp); end: DONE(NULL); }
2,535
27.494382
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_out_of_memory/vmem_out_of_memory.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_out_of_memory -- unit test for vmem_out_of_memory * * usage: vmem_out_of_memory [directory] */ #include "unittest.h" int main(int argc, char *argv[]) { char *dir = NULL; void *mem_pool = NULL; VMEM *vmp; START(argc, argv, "vmem_out_of_memory"); 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"); } /* allocate all memory */ void *prev = NULL; for (;;) { void **next = vmem_malloc(vmp, sizeof(void *)); if (next == NULL) { /* out of memory */ break; } /* check that pointer came from mem_pool */ if (dir == NULL) { UT_ASSERTrange(next, mem_pool, VMEM_MIN_POOL); } *next = prev; prev = next; } UT_ASSERTne(prev, NULL); /* free all allocations */ while (prev != NULL) { void **act = prev; prev = *act; vmem_free(vmp, act); } vmem_delete(vmp); DONE(NULL); }
2,835
27.646465
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/remote_obj_basic/remote_obj_basic.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. */ /* * remote_obj_basic.c -- unit test for remote tests support * * usage: remote_obj_basic <create|open> <poolset-file> */ #include "unittest.h" #define LAYOUT_NAME "remote_obj_basic" int main(int argc, char *argv[]) { PMEMobjpool *pop; START(argc, argv, "remote_obj_basic"); if (argc != 3) UT_FATAL("usage: %s <create|open> <poolset-file>", argv[0]); const char *mode = argv[1]; const char *file = argv[2]; if (strcmp(mode, "create") == 0) { if ((pop = pmemobj_create(file, LAYOUT_NAME, 0, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", file); else UT_OUT("The pool set %s has been created", file); } else if (strcmp(mode, "open") == 0) { if ((pop = pmemobj_open(file, LAYOUT_NAME)) == NULL) UT_FATAL("!pmemobj_open: %s", file); else UT_OUT("The pool set %s has been opened", file); } else { UT_FATAL("wrong mode: %s\n", argv[1]); } pmemobj_close(pop); DONE(NULL); }
2,534
31.922078
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_debug/obj_ctl_debug.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_debug.c -- tests for the ctl debug namesapce entry points */ #include "unittest.h" #include "../../libpmemobj/obj.h" #define LAYOUT "obj_ctl_debug" #define BUFFER_SIZE 128 #define ALLOC_PATTERN 0xAC static void test_alloc_pattern(PMEMobjpool *pop) { int ret; int pattern; PMEMoid oid; /* check default pattern */ ret = pmemobj_ctl_get(pop, "debug.heap.alloc_pattern", &pattern); UT_ASSERTeq(ret, 0); UT_ASSERTeq(pattern, PALLOC_CTL_DEBUG_NO_PATTERN); /* check set pattern */ pattern = ALLOC_PATTERN; ret = pmemobj_ctl_set(pop, "debug.heap.alloc_pattern", &pattern); UT_ASSERTeq(ret, 0); UT_ASSERTeq(pop->heap.alloc_pattern, pattern); /* check alloc with pattern */ ret = pmemobj_alloc(pop, &oid, BUFFER_SIZE, 0, NULL, NULL); UT_ASSERTeq(ret, 0); char *buff = pmemobj_direct(oid); int i; for (i = 0; i < BUFFER_SIZE; i++) /* should trigger memcheck error: read uninitialized values */ UT_ASSERTeq(*(buff + i), (char)pattern); pmemobj_free(&oid); } int main(int argc, char *argv[]) { START(argc, argv, "obj_ctl_debug"); if (argc < 2) UT_FATAL("usage: %s filename", argv[0]); const char *path = argv[1]; PMEMobjpool *pop; if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_open: %s", path); test_alloc_pattern(pop); pmemobj_close(pop); DONE(NULL); }
2,967
29.597938
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list_macro/obj_list_macro.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_list_macro.c -- unit tests for list module */ #include <stddef.h> #include "libpmemobj.h" #include "unittest.h" TOID_DECLARE(struct item, 0); TOID_DECLARE(struct list, 1); struct item { int id; POBJ_LIST_ENTRY(struct item) next; }; struct list { POBJ_LIST_HEAD(listhead, struct item) head; }; /* global lists */ static TOID(struct list) List; static TOID(struct list) List_sec; #define LAYOUT_NAME "list_macros" /* usage macros */ #define FATAL_USAGE()\ UT_FATAL("usage: obj_list_macro <file> [PRnifr]") #define FATAL_USAGE_PRINT()\ UT_FATAL("usage: obj_list_macro <file> P:<list>") #define FATAL_USAGE_PRINT_REVERSE()\ UT_FATAL("usage: obj_list_macro <file> R:<list>") #define FATAL_USAGE_INSERT()\ UT_FATAL("usage: obj_list_macro <file> i:<where>:<num>[:<id>]") #define FATAL_USAGE_INSERT_NEW()\ UT_FATAL("usage: obj_list_macro <file> n:<where>:<num>[:<id>]") #define FATAL_USAGE_REMOVE_FREE()\ UT_FATAL("usage: obj_list_macro <file> f:<list>:<num>") #define FATAL_USAGE_REMOVE()\ UT_FATAL("usage: obj_list_macro <file> r:<list>:<num>") #define FATAL_USAGE_MOVE()\ UT_FATAL("usage: obj_list_macro <file> m:<num>:<where>:<num>") /* * get_item_list -- get nth item from list */ static TOID(struct item) get_item_list(TOID(struct list) list, int n) { TOID(struct item) item; if (n >= 0) { POBJ_LIST_FOREACH(item, &D_RO(list)->head, next) { if (n == 0) return item; n--; } } else { POBJ_LIST_FOREACH_REVERSE(item, &D_RO(list)->head, next) { n++; if (n == 0) return item; } } return TOID_NULL(struct item); } /* * 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(); TOID(struct item) item; if (L == 1) { UT_OUT("list:"); POBJ_LIST_FOREACH(item, &D_RW(List)->head, next) { UT_OUT("id = %d", D_RO(item)->id); } } else if (L == 2) { UT_OUT("list sec:"); POBJ_LIST_FOREACH(item, &D_RW(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(); TOID(struct item) item; if (L == 1) { UT_OUT("list reverse:"); POBJ_LIST_FOREACH_REVERSE(item, &D_RW(List)->head, next) { UT_OUT("id = %d", D_RO(item)->id); } } else if (L == 2) { UT_OUT("list sec reverse:"); POBJ_LIST_FOREACH_REVERSE(item, &D_RW(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(PMEMobjpool *pop, void *ptr, void *arg) { int id = *(int *)arg; struct item *item = (struct item *)ptr; item->id = id; UT_OUT("constructor(id = %d)", id); return 0; } /* * 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 != 2) FATAL_USAGE_INSERT_NEW(); int ptr = (ret == 3) ? id : 0; TOID(struct item) item; if (POBJ_LIST_EMPTY(&D_RW(List)->head)) { POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(List)->head, next, sizeof(struct item), item_constructor, &ptr); if (POBJ_LIST_EMPTY(&D_RW(List)->head)) UT_FATAL("POBJ_LIST_INSERT_NEW_HEAD"); } else { item = get_item_list(List, n); UT_ASSERT(!TOID_IS_NULL(item)); if (!before) { POBJ_LIST_INSERT_NEW_AFTER(pop, &D_RW(List)->head, item, next, sizeof(struct item), item_constructor, &ptr); if (TOID_IS_NULL(POBJ_LIST_NEXT(item, next))) UT_FATAL("POBJ_LIST_INSERT_NEW_AFTER"); } else { POBJ_LIST_INSERT_NEW_BEFORE(pop, &D_RW(List)->head, item, next, sizeof(struct item), item_constructor, &ptr); if (TOID_IS_NULL(POBJ_LIST_PREV(item, next))) UT_FATAL("POBJ_LIST_INSERT_NEW_BEFORE"); } } } /* * do_insert -- insert element to list */ static void do_insert(PMEMobjpool *pop, const char *arg) { int n; /* which element on List */ int before; int id; int ret = sscanf(arg, "i:%d:%d:%d", &before, &n, &id); if (ret != 3 && ret != 2) FATAL_USAGE_INSERT(); int ptr = (ret == 3) ? id : 0; TOID(struct item) item; POBJ_NEW(pop, &item, struct item, item_constructor, &ptr); UT_ASSERT(!TOID_IS_NULL(item)); errno = 0; if (POBJ_LIST_EMPTY(&D_RW(List)->head)) { ret = POBJ_LIST_INSERT_HEAD(pop, &D_RW(List)->head, item, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_INSERT_HEAD"); } if (POBJ_LIST_EMPTY(&D_RW(List)->head)) UT_FATAL("POBJ_LIST_INSERT_HEAD"); } else { TOID(struct item) elm = get_item_list(List, n); UT_ASSERT(!TOID_IS_NULL(elm)); if (!before) { ret = POBJ_LIST_INSERT_AFTER(pop, &D_RW(List)->head, elm, item, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_INSERT_AFTER"); } if (!TOID_EQUALS(item, POBJ_LIST_NEXT(elm, next))) UT_FATAL("POBJ_LIST_INSERT_AFTER"); } else { ret = POBJ_LIST_INSERT_BEFORE(pop, &D_RW(List)->head, elm, item, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_INSERT_BEFORE"); } if (!TOID_EQUALS(item, POBJ_LIST_PREV(elm, next))) UT_FATAL("POBJ_LIST_INSERT_BEFORE"); } } } /* * 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 */ if (sscanf(arg, "f:%d:%d", &L, &n) != 2) FATAL_USAGE_REMOVE_FREE(); TOID(struct item) item; TOID(struct list) tmp_list; if (L == 1) tmp_list = List; else if (L == 2) tmp_list = List_sec; else FATAL_USAGE_REMOVE_FREE(); if (POBJ_LIST_EMPTY(&D_RW(tmp_list)->head)) return; item = get_item_list(tmp_list, n); UT_ASSERT(!TOID_IS_NULL(item)); errno = 0; int ret = POBJ_LIST_REMOVE_FREE(pop, &D_RW(tmp_list)->head, item, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_REMOVE_FREE"); } } /* * do_remove -- remove element from list */ static void do_remove(PMEMobjpool *pop, const char *arg) { int L; /* which list */ int n; /* which element */ if (sscanf(arg, "r:%d:%d", &L, &n) != 2) FATAL_USAGE_REMOVE(); TOID(struct item) item; TOID(struct list) tmp_list; if (L == 1) tmp_list = List; else if (L == 2) tmp_list = List_sec; else FATAL_USAGE_REMOVE_FREE(); if (POBJ_LIST_EMPTY(&D_RW(tmp_list)->head)) return; item = get_item_list(tmp_list, n); UT_ASSERT(!TOID_IS_NULL(item)); errno = 0; int ret = POBJ_LIST_REMOVE(pop, &D_RW(tmp_list)->head, item, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_REMOVE"); } POBJ_FREE(&item); } /* * 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(); int ret; errno = 0; if (POBJ_LIST_EMPTY(&D_RW(List)->head)) return; if (POBJ_LIST_EMPTY(&D_RW(List_sec)->head)) { ret = POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(List)->head, &D_RW(List_sec)->head, get_item_list(List, n), next, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_MOVE_ELEMENT_HEAD"); } } else { if (before) { ret = POBJ_LIST_MOVE_ELEMENT_BEFORE(pop, &D_RW(List)->head, &D_RW(List_sec)->head, get_item_list(List_sec, d), get_item_list(List, n), next, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_MOVE_ELEMENT_BEFORE"); } } else { ret = POBJ_LIST_MOVE_ELEMENT_AFTER(pop, &D_RW(List)->head, &D_RW(List_sec)->head, get_item_list(List_sec, d), get_item_list(List, n), next, next); if (ret) { UT_ASSERTeq(ret, -1); UT_ASSERTne(errno, 0); UT_FATAL("POBJ_LIST_MOVE_ELEMENT_AFTER"); } } } } /* * do_cleanup -- de-initialization function */ static void do_cleanup(PMEMobjpool *pop, TOID(struct list) list) { int ret; errno = 0; while (!POBJ_LIST_EMPTY(&D_RW(list)->head)) { TOID(struct item) tmp = POBJ_LIST_FIRST(&D_RW(list)->head); ret = POBJ_LIST_REMOVE_FREE(pop, &D_RW(list)->head, tmp, next); UT_ASSERTeq(errno, 0); UT_ASSERTeq(ret, 0); } POBJ_FREE(&list); } int main(int argc, char *argv[]) { START(argc, argv, "obj_list_macro"); if (argc < 2) FATAL_USAGE(); const char *path = argv[1]; PMEMobjpool *pop; if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create"); POBJ_ZNEW(pop, &List, struct list); POBJ_ZNEW(pop, &List_sec, struct list); 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; default: FATAL_USAGE(); } } do_cleanup(pop, List); do_cleanup(pop, List_sec); pmemobj_close(pop); DONE(NULL); }
11,141
23.596026
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_pool/cto_pool.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 char *path, const char *layout, size_t poolsize, unsigned mode) { PMEMctopool *pcp = pmemcto_create(path, layout, poolsize, mode); if (pcp == NULL) UT_OUT("!%s: pmemcto_create", path); 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); pmemcto_close(pcp); int result = pmemcto_check(path, layout); if (result < 0) UT_OUT("!%s: pmemcto_check", path); else if (result == 0) UT_OUT("%s: pmemcto_check: not consistent", path); } } static void pool_open(const char *path, const char *layout) { PMEMctopool *pcp = pmemcto_open(path, layout); if (pcp == NULL) UT_OUT("!%s: pmemcto_open", path); else { UT_OUT("%s: pmemcto_open: Success", path); pmemcto_close(pcp); } } int main(int argc, char *argv[]) { START(argc, argv, "cto_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 = strtoul(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; default: UT_FATAL("unknown operation"); } DONE(NULL); }
3,327
26.278689
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_valgrind_region/vmem_valgrind_region.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. */ /* * vmem_valgrind_region.c -- unit test for vmem_valgrind_region */ #include "unittest.h" #define POOLSIZE (16 << 20) #define CHUNKSIZE (4 << 20) #define NOBJS 8 struct foo { size_t size; char data[1]; /* dynamically sized */ }; static struct foo *objs[NOBJS]; static void do_alloc(VMEM *vmp) { size_t size = 256; /* allocate objects */ for (int i = 0; i < NOBJS; i++) { objs[i] = vmem_malloc(vmp, size + sizeof(size_t)); UT_ASSERTne(objs[i], NULL); objs[i]->size = size; memset(objs[i]->data, '0' + i, size - 1); objs[i]->data[size] = '\0'; size *= 4; } } static void do_iterate(void) { /* dump selected objects */ for (int i = 0; i < NOBJS; i++) UT_OUT("%p size %zu", objs[i], objs[i]->size); } static void do_free(VMEM *vmp) { /* free objects */ for (int i = 0; i < NOBJS; i++) vmem_free(vmp, objs[i]); } int main(int argc, char *argv[]) { VMEM *vmp; START(argc, argv, "vmem_valgrind_region"); if (argc < 2) UT_FATAL("usage: %s <0..4>", argv[0]); int test = atoi(argv[1]); /* * Allocate memory for vmem_create_in_region(). * Reserve more space for test case #4. */ char *addr = MMAP_ANON_ALIGNED(VMEM_MIN_POOL + CHUNKSIZE, CHUNKSIZE); vmp = vmem_create_in_region(addr, POOLSIZE); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); do_alloc(vmp); switch (test) { case 0: /* free objects and delete pool */ do_free(vmp); vmem_delete(vmp); break; case 1: /* delete pool without freeing objects */ vmem_delete(vmp); break; case 2: /* * delete pool without freeing objects * try to access objects * expected: use of uninitialized value */ vmem_delete(vmp); do_iterate(); break; case 3: /* * delete pool without freeing objects * re-create pool in the same region * try to access objects * expected: invalid read */ vmem_delete(vmp); vmp = vmem_create_in_region(addr, POOLSIZE); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); do_iterate(); vmem_delete(vmp); break; case 4: /* * delete pool without freeing objects * re-create pool in the overlapping region * try to access objects * expected: use of uninitialized value & invalid read */ vmem_delete(vmp); vmp = vmem_create_in_region(addr + CHUNKSIZE, POOLSIZE); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); do_iterate(); vmem_delete(vmp); break; default: UT_FATAL("wrong test case %d", test); } MUNMAP(addr, VMEM_MIN_POOL + CHUNKSIZE); DONE(NULL); }
4,094
23.668675
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/win_signal/win_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. */ /* * win_signal.c -- test signal related routines */ #include "unittest.h" extern int sys_siglist_size; int main(int argc, char *argv[]) { int sig; START(argc, argv, "win_signal"); for (sig = 0; sig < sys_siglist_size; sig++) { UT_OUT("%d; %s", sig, os_strsignal(sig)); } for (sig = 33; sig < 66; sig++) { UT_OUT("%d; %s", sig, os_strsignal(sig)); } DONE(NULL); }
1,983
35.072727
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_extent/util_extent.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_extent.c -- unit test for the linux fs extent query API * */ #include "unittest.h" #include "extent.h" /* * test_size -- test if sum of all file's extents sums up to the file's size */ static void test_size(const char *path, size_t size) { size_t total_length = 0; struct extents *exts = MALLOC(sizeof(struct extents)); UT_ASSERT(os_extents_count(path, exts) >= 0); UT_OUT("exts->extents_count: %u", exts->extents_count); if (exts->extents_count > 0) { exts->extents = MALLOC(exts->extents_count * sizeof(struct extent)); UT_ASSERTeq(os_extents_get(path, exts), 0); unsigned e; for (e = 0; e < exts->extents_count; e++) total_length += exts->extents[e].length; FREE(exts->extents); } FREE(exts); UT_ASSERTeq(total_length, size); } int main(int argc, char *argv[]) { START(argc, argv, "util_extent"); if (argc != 3) UT_FATAL("usage: %s file file-size", argv[0]); long long isize = atoi(argv[2]); UT_ASSERT(isize > 0); size_t size = (size_t)isize; test_size(argv[1], size); DONE(NULL); }
2,651
28.797753
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/win_poolset_unmap/win_poolset_unmap.c
/* * Copyright 2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * win_poolset_unmap.c -- test for windows mmap destructor. * * It checks whether all mappings are properly unmpapped and memory is properly * unreserved when auto growing pool is used. */ #include "unittest.h" #include "os.h" #include "libpmemobj.h" #define KILOBYTE (1 << 10) #define MEGABYTE (1 << 20) #define LAYOUT_NAME "poolset_unmap" int main(int argc, char *argv[]) { START(argc, argv, "win_poolset_unmap"); if (argc != 2) UT_FATAL("usage: %s path", argv[0]); PMEMobjpool *pop; if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, 0, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create"); MEMORY_BASIC_INFORMATION basic_info; SIZE_T bytes_returned; SIZE_T offset = 0; bytes_returned = VirtualQuery(pop, &basic_info, sizeof(basic_info)); /* * When opening pool, we try to remove all permissions on header. * If this action fails VirtualQuery will return one region with * size 8MB. If it succeeds, RegionSize will be equal to 4KB due * to different header and rest of the mapping permissions. */ if (basic_info.RegionSize == 4 * KILOBYTE) { /* header */ UT_ASSERTeq(bytes_returned, sizeof(basic_info)); UT_ASSERTeq(basic_info.State, MEM_COMMIT); offset += basic_info.RegionSize; /* first part */ bytes_returned = VirtualQuery((char *)pop + offset, &basic_info, sizeof(basic_info)); UT_ASSERTeq(bytes_returned, sizeof(basic_info)); UT_ASSERTeq(basic_info.RegionSize, 8 * MEGABYTE - 4 * KILOBYTE); UT_ASSERTeq(basic_info.State, MEM_COMMIT); } else { /* first part with header */ UT_ASSERTeq(bytes_returned, sizeof(basic_info)); UT_ASSERTeq(basic_info.RegionSize, 8 * MEGABYTE); UT_ASSERTeq(basic_info.State, MEM_COMMIT); } offset += basic_info.RegionSize; /* reservation after first part */ bytes_returned = VirtualQuery((char *)pop + offset, &basic_info, sizeof(basic_info)); UT_ASSERTeq(bytes_returned, sizeof(basic_info)); UT_ASSERTeq(basic_info.RegionSize, (50 - 8) * MEGABYTE); UT_ASSERTeq(basic_info.State, MEM_RESERVE); DONE(NULL); }
3,632
32.638889
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/remote_basic/remote_basic.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. */ /* * remote_basic.c -- unit test for remote tests support * * usage: remote_basic <file-to-be-checked> */ #include "file.h" #include "unittest.h" int main(int argc, char *argv[]) { START(argc, argv, "remote_basic"); if (argc != 2) UT_FATAL("usage: %s <file-to-be-checked>", argv[0]); const char *file = argv[1]; int exists = util_file_exists(file); if (exists < 0) UT_FATAL("!util_file_exists"); if (!exists) UT_FATAL("File '%s' does not exist", file); else UT_OUT("File '%s' exists", file); UT_OUT("An example of OUT message"); UT_ERR("An example of ERR message"); DONE(NULL); }
2,213
32.044776
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/win_getopt/win_getopt.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. */ /* * win_getopt.c -- test for windows getopt() implementation */ #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include "unittest.h" /* * long_options -- command line arguments */ static const struct option long_options[] = { { "arg_a", no_argument, NULL, 'a' }, { "arg_b", no_argument, NULL, 'b' }, { "arg_c", no_argument, NULL, 'c' }, { "arg_d", no_argument, NULL, 'd' }, { "arg_e", no_argument, NULL, 'e' }, { "arg_f", no_argument, NULL, 'f' }, { "arg_g", no_argument, NULL, 'g' }, { "arg_h", no_argument, NULL, 'h' }, { "arg_A", required_argument, NULL, 'A' }, { "arg_B", required_argument, NULL, 'B' }, { "arg_C", required_argument, NULL, 'C' }, { "arg_D", required_argument, NULL, 'D' }, { "arg_E", required_argument, NULL, 'E' }, { "arg_F", required_argument, NULL, 'F' }, { "arg_G", required_argument, NULL, 'G' }, { "arg_H", required_argument, NULL, 'H' }, { "arg_1", optional_argument, NULL, '1' }, { "arg_2", optional_argument, NULL, '2' }, { "arg_3", optional_argument, NULL, '3' }, { "arg_4", optional_argument, NULL, '4' }, { "arg_5", optional_argument, NULL, '5' }, { "arg_6", optional_argument, NULL, '6' }, { "arg_7", optional_argument, NULL, '7' }, { "arg_8", optional_argument, NULL, '8' }, { NULL, 0, NULL, 0 }, }; int main(int argc, char *argv[]) { int opt; int option_index; START(argc, argv, "win_getopt"); while ((opt = getopt_long(argc, argv, "abcdefghA:B:C:D:E:F:G::H1::2::3::4::5::6::7::8::", long_options, &option_index)) != -1) { switch (opt) { case '?': UT_OUT("unknown argument"); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': UT_OUT("arg_%c", opt); break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': UT_OUT("arg_%c=%s", opt, optarg == NULL ? "null": optarg); break; } } while (optind < argc) { UT_OUT("%s", argv[optind++]); } DONE(NULL); }
3,677
28.66129
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_strdup/obj_tx_strdup.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_strdup.c -- unit test for pmemobj_tx_strdup */ #include <sys/param.h> #include <string.h> #include <wchar.h> #include "unittest.h" #define LAYOUT_NAME "tx_strdup" TOID_DECLARE(char, 0); TOID_DECLARE(wchar_t, 1); enum type_number { TYPE_NO_TX, TYPE_WCS_NO_TX, TYPE_COMMIT, TYPE_WCS_COMMIT, TYPE_ABORT, TYPE_WCS_ABORT, TYPE_FREE_COMMIT, TYPE_WCS_FREE_COMMIT, TYPE_FREE_ABORT, TYPE_WCS_FREE_ABORT, TYPE_COMMIT_NESTED1, TYPE_WCS_COMMIT_NESTED1, TYPE_COMMIT_NESTED2, TYPE_WCS_COMMIT_NESTED2, TYPE_ABORT_NESTED1, TYPE_WCS_ABORT_NESTED1, TYPE_ABORT_NESTED2, TYPE_WCS_ABORT_NESTED2, TYPE_ABORT_AFTER_NESTED1, TYPE_WCS_ABORT_AFTER_NESTED1, TYPE_ABORT_AFTER_NESTED2, TYPE_WCS_ABORT_AFTER_NESTED2, }; #define TEST_STR_1 "Test string 1" #define TEST_STR_2 "Test string 2" #define TEST_WCS_1 L"Test string 3" #define TEST_WCS_2 L"Test string 4" #define MAX_FUNC 2 typedef void (*fn_tx_strdup)(TOID(char) *str, const char *s, unsigned type_num); typedef void (*fn_tx_wcsdup)(TOID(wchar_t) *wcs, const wchar_t *s, unsigned type_num); static unsigned counter; /* * tx_strdup -- duplicate a string using pmemobj_tx_strdup */ static void tx_strdup(TOID(char) *str, const char *s, unsigned type_num) { TOID_ASSIGN(*str, pmemobj_tx_strdup(s, type_num)); } /* * tx_wcsdup -- duplicate a string using pmemobj_tx_wcsdup */ static void tx_wcsdup(TOID(wchar_t) *wcs, const wchar_t *s, unsigned type_num) { TOID_ASSIGN(*wcs, pmemobj_tx_wcsdup(s, type_num)); } /* * tx_strdup_macro -- duplicate a string using macro */ static void tx_strdup_macro(TOID(char) *str, const char *s, unsigned type_num) { TOID_ASSIGN(*str, TX_STRDUP(s, type_num)); } /* * tx_wcsdup_macro -- duplicate a wide character string using macro */ static void tx_wcsdup_macro(TOID(wchar_t) *wcs, const wchar_t *s, unsigned type_num) { TOID_ASSIGN(*wcs, TX_WCSDUP(s, type_num)); } static fn_tx_strdup do_tx_strdup[MAX_FUNC] = {tx_strdup, tx_strdup_macro}; static fn_tx_wcsdup do_tx_wcsdup[MAX_FUNC] = {tx_wcsdup, tx_wcsdup_macro}; /* * do_tx_strdup_commit -- duplicate a string and commit the transaction */ static void do_tx_strdup_commit(PMEMobjpool *pop) { TOID(char) str; TOID(wchar_t) wcs; TX_BEGIN(pop) { do_tx_strdup[counter](&str, TEST_STR_1, TYPE_COMMIT); do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_COMMIT); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERT(!TOID_IS_NULL(wcs)); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT)); TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT)); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERTeq(strcmp(TEST_STR_1, D_RO(str)), 0); UT_ASSERTeq(wcscmp(TEST_WCS_1, D_RO(wcs)), 0); } /* * do_tx_strdup_abort -- duplicate a string and abort the transaction */ static void do_tx_strdup_abort(PMEMobjpool *pop) { TOID(char) str; TOID(wchar_t) wcs; TX_BEGIN(pop) { do_tx_strdup[counter](&str, TEST_STR_1, TYPE_ABORT); do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_ABORT); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERT(!TOID_IS_NULL(wcs)); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT)); TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT)); UT_ASSERT(TOID_IS_NULL(str)); UT_ASSERT(TOID_IS_NULL(wcs)); } /* * do_tx_strdup_null -- duplicate a NULL string to trigger tx abort */ static void do_tx_strdup_null(PMEMobjpool *pop) { TOID(char) str; TOID(wchar_t) wcs; TX_BEGIN(pop) { do_tx_strdup[counter](&str, NULL, TYPE_ABORT); do_tx_wcsdup[counter](&wcs, NULL, TYPE_WCS_ABORT); UT_ASSERT(0); /* should not get to this point */ } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT)); TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT)); UT_ASSERT(TOID_IS_NULL(str)); UT_ASSERT(TOID_IS_NULL(wcs)); } /* * do_tx_strdup_free_commit -- duplicate a string, free and commit the * transaction */ static void do_tx_strdup_free_commit(PMEMobjpool *pop) { TOID(char) str; TOID(wchar_t) wcs; TX_BEGIN(pop) { do_tx_strdup[counter](&str, TEST_STR_1, TYPE_FREE_COMMIT); do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_FREE_COMMIT); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERT(!TOID_IS_NULL(wcs)); int ret = pmemobj_tx_free(str.oid); UT_ASSERTeq(ret, 0); ret = pmemobj_tx_free(wcs.oid); UT_ASSERTeq(ret, 0); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_COMMIT)); TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_FREE_COMMIT)); UT_ASSERT(TOID_IS_NULL(str)); UT_ASSERT(TOID_IS_NULL(wcs)); } /* * do_tx_strdup_free_abort -- duplicate a string, free and abort the * transaction */ static void do_tx_strdup_free_abort(PMEMobjpool *pop) { TOID(char) str; TOID(wchar_t) wcs; TX_BEGIN(pop) { do_tx_strdup[counter](&str, TEST_STR_1, TYPE_FREE_ABORT); do_tx_wcsdup[counter](&wcs, TEST_WCS_1, TYPE_WCS_FREE_ABORT); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERT(!TOID_IS_NULL(wcs)); int ret = pmemobj_tx_free(str.oid); UT_ASSERTeq(ret, 0); ret = pmemobj_tx_free(wcs.oid); UT_ASSERTeq(ret, 0); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE_ABORT)); TOID_ASSIGN(wcs, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_FREE_ABORT)); UT_ASSERT(TOID_IS_NULL(str)); UT_ASSERT(TOID_IS_NULL(wcs)); } /* * do_tx_strdup_commit_nested -- duplicate two string suing nested * transaction and commit the transaction */ static void do_tx_strdup_commit_nested(PMEMobjpool *pop) { TOID(char) str1; TOID(char) str2; TOID(wchar_t) wcs1; TOID(wchar_t) wcs2; TX_BEGIN(pop) { do_tx_strdup[counter](&str1, TEST_STR_1, TYPE_COMMIT_NESTED1); do_tx_wcsdup[counter](&wcs1, TEST_WCS_1, TYPE_WCS_COMMIT_NESTED1); UT_ASSERT(!TOID_IS_NULL(str1)); UT_ASSERT(!TOID_IS_NULL(wcs1)); TX_BEGIN(pop) { do_tx_strdup[counter](&str2, TEST_STR_2, TYPE_COMMIT_NESTED2); do_tx_wcsdup[counter](&wcs2, TEST_WCS_2, TYPE_WCS_COMMIT_NESTED2); UT_ASSERT(!TOID_IS_NULL(str2)); UT_ASSERT(!TOID_IS_NULL(wcs2)); } TX_ONABORT { UT_ASSERT(0); } TX_END } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED1)); TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT_NESTED1)); UT_ASSERT(!TOID_IS_NULL(str1)); UT_ASSERT(!TOID_IS_NULL(wcs1)); UT_ASSERTeq(strcmp(TEST_STR_1, D_RO(str1)), 0); UT_ASSERTeq(wcscmp(TEST_WCS_1, D_RO(wcs1)), 0); TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED2)); TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_COMMIT_NESTED2)); UT_ASSERT(!TOID_IS_NULL(str2)); UT_ASSERT(!TOID_IS_NULL(wcs2)); UT_ASSERTeq(strcmp(TEST_STR_2, D_RO(str2)), 0); UT_ASSERTeq(wcscmp(TEST_WCS_2, D_RO(wcs2)), 0); } /* * do_tx_strdup_commit_abort -- duplicate two string suing nested * transaction and abort the transaction */ static void do_tx_strdup_abort_nested(PMEMobjpool *pop) { TOID(char) str1; TOID(char) str2; TOID(wchar_t) wcs1; TOID(wchar_t) wcs2; TX_BEGIN(pop) { do_tx_strdup[counter](&str1, TEST_STR_1, TYPE_ABORT_NESTED1); do_tx_wcsdup[counter](&wcs1, TEST_WCS_1, TYPE_WCS_ABORT_NESTED1); UT_ASSERT(!TOID_IS_NULL(str1)); UT_ASSERT(!TOID_IS_NULL(wcs1)); TX_BEGIN(pop) { do_tx_strdup[counter](&str2, TEST_STR_2, TYPE_ABORT_NESTED2); do_tx_wcsdup[counter](&wcs2, TEST_WCS_2, TYPE_WCS_ABORT_NESTED2); UT_ASSERT(!TOID_IS_NULL(str2)); UT_ASSERT(!TOID_IS_NULL(wcs2)); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED1)); TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_NESTED1)); UT_ASSERT(TOID_IS_NULL(str1)); UT_ASSERT(TOID_IS_NULL(wcs1)); TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED2)); TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_NESTED2)); UT_ASSERT(TOID_IS_NULL(str2)); UT_ASSERT(TOID_IS_NULL(wcs2)); } /* * do_tx_strdup_commit_abort -- duplicate two string suing nested * transaction and abort after the nested transaction */ static void do_tx_strdup_abort_after_nested(PMEMobjpool *pop) { TOID(char) str1; TOID(char) str2; TOID(wchar_t) wcs1; TOID(wchar_t) wcs2; TX_BEGIN(pop) { do_tx_strdup[counter](&str1, TEST_STR_1, TYPE_ABORT_AFTER_NESTED1); do_tx_wcsdup[counter](&wcs1, TEST_WCS_1, TYPE_WCS_ABORT_AFTER_NESTED1); UT_ASSERT(!TOID_IS_NULL(str1)); UT_ASSERT(!TOID_IS_NULL(wcs1)); TX_BEGIN(pop) { do_tx_strdup[counter](&str2, TEST_STR_2, TYPE_ABORT_AFTER_NESTED2); do_tx_wcsdup[counter](&wcs2, TEST_WCS_2, TYPE_WCS_ABORT_AFTER_NESTED2); UT_ASSERT(!TOID_IS_NULL(str2)); UT_ASSERT(!TOID_IS_NULL(wcs2)); } TX_ONABORT { UT_ASSERT(0); } TX_END pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(str1, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED1)); TOID_ASSIGN(wcs1, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_AFTER_NESTED1)); UT_ASSERT(TOID_IS_NULL(str1)); UT_ASSERT(TOID_IS_NULL(wcs1)); TOID_ASSIGN(str2, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED2)); TOID_ASSIGN(wcs2, POBJ_FIRST_TYPE_NUM(pop, TYPE_WCS_ABORT_AFTER_NESTED2)); UT_ASSERT(TOID_IS_NULL(str2)); UT_ASSERT(TOID_IS_NULL(wcs2)); } int main(int argc, char *argv[]) { START(argc, argv, "obj_tx_strdup"); 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"); for (counter = 0; counter < MAX_FUNC; counter++) { do_tx_strdup_commit(pop); do_tx_strdup_abort(pop); do_tx_strdup_null(pop); do_tx_strdup_free_commit(pop); do_tx_strdup_free_abort(pop); do_tx_strdup_commit_nested(pop); do_tx_strdup_abort_nested(pop); do_tx_strdup_abort_after_nested(pop); } pmemobj_close(pop); DONE(NULL); }
11,575
26.760192
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_realloc/obj_tx_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_tx_realloc.c -- unit test for pmemobj_tx_realloc and pmemobj_tx_zrealloc */ #include <sys/param.h> #include <string.h> #include "unittest.h" #include "util.h" #define LAYOUT_NAME "tx_realloc" #define TEST_VALUE_1 1 #define OBJ_SIZE 1024 enum type_number { TYPE_NO_TX, TYPE_COMMIT, TYPE_ABORT, TYPE_TYPE, TYPE_COMMIT_ZERO, TYPE_COMMIT_ZERO_MACRO, TYPE_ABORT_ZERO, TYPE_ABORT_ZERO_MACRO, TYPE_COMMIT_ALLOC, TYPE_ABORT_ALLOC, TYPE_ABORT_HUGE, TYPE_ABORT_ZERO_HUGE, TYPE_ABORT_ZERO_HUGE_MACRO, TYPE_FREE, }; struct object { size_t value; char data[OBJ_SIZE - sizeof(size_t)]; }; TOID_DECLARE(struct object, 0); struct object_macro { size_t value; char data[OBJ_SIZE - sizeof(size_t)]; }; TOID_DECLARE(struct object_macro, TYPE_COMMIT_ZERO_MACRO); /* * do_tx_alloc -- do tx allocation with specified type number */ static PMEMoid do_tx_alloc(PMEMobjpool *pop, unsigned type_num, size_t value) { TOID(struct object) obj; TOID_ASSIGN(obj, OID_NULL); TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_alloc( sizeof(struct object), type_num)); if (!TOID_IS_NULL(obj)) { D_RW(obj)->value = value; } } TX_ONABORT { UT_ASSERT(0); } TX_END return obj.oid; } /* * do_tx_realloc_commit -- reallocate an object and commit the transaction */ static void do_tx_realloc_commit(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT, TEST_VALUE_1)); size_t new_size = 2 * pmemobj_alloc_usable_size(obj.oid); TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, new_size, TYPE_COMMIT)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_abort -- reallocate an object and commit the transaction */ static void do_tx_realloc_abort(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT, TEST_VALUE_1)); size_t new_size = 2 * pmemobj_alloc_usable_size(obj.oid); TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, new_size, TYPE_ABORT)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_huge -- reallocate an object to a huge size to trigger tx abort */ static void do_tx_realloc_huge(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_HUGE, TEST_VALUE_1)); size_t new_size = PMEMOBJ_MAX_ALLOC_SIZE + 1; TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, new_size, TYPE_ABORT_HUGE)); UT_ASSERT(0); /* should not get to this point */ } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_HUGE)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_zrealloc_commit_macro -- reallocate an object, zero it and commit * the transaction using macro */ static void do_tx_zrealloc_commit_macro(PMEMobjpool *pop) { TOID(struct object_macro) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ZERO_MACRO, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { obj = TX_ZREALLOC(obj, new_size); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ZERO_MACRO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_zrealloc_commit -- reallocate an object, zero it and commit * the transaction */ static void do_tx_zrealloc_commit(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ZERO, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid, new_size, TYPE_COMMIT_ZERO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ZERO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_abort_macro -- reallocate an object, zero it and commit the * transaction using macro */ static void do_tx_zrealloc_abort_macro(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_MACRO, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { obj = TX_ZREALLOC(obj, new_size); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_MACRO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_abort -- reallocate an object and commit the transaction */ static void do_tx_zrealloc_abort(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid, new_size, TYPE_ABORT_ZERO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); void *new_ptr = (void *)((uintptr_t)D_RW(obj) + old_size); UT_ASSERT(util_is_zeroed(new_ptr, new_size - old_size)); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_huge_macro -- reallocate an object to a huge size to trigger * tx abort and zero it using macro */ static void do_tx_zrealloc_huge_macro(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_HUGE_MACRO, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { obj = TX_ZREALLOC(obj, PMEMOBJ_MAX_ALLOC_SIZE + 1); UT_ASSERT(0); /* should not get to this point */ } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_HUGE_MACRO)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_huge -- reallocate an object to a huge size to trigger tx abort */ static void do_tx_zrealloc_huge(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ZERO_HUGE, TEST_VALUE_1)); size_t old_size = pmemobj_alloc_usable_size(obj.oid); size_t new_size = 2 * old_size; TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_zrealloc(obj.oid, PMEMOBJ_MAX_ALLOC_SIZE + 1, TYPE_ABORT_ZERO_HUGE)); UT_ASSERT(0); /* should not get to this point */ } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ZERO_HUGE)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) < new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_alloc_commit -- reallocate an allocated object * and commit the transaction */ static void do_tx_realloc_alloc_commit(PMEMobjpool *pop) { TOID(struct object) obj; size_t new_size = 0; TX_BEGIN(pop) { TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_COMMIT_ALLOC, TEST_VALUE_1)); UT_ASSERT(!TOID_IS_NULL(obj)); new_size = 2 * pmemobj_alloc_usable_size(obj.oid); TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, new_size, TYPE_COMMIT_ALLOC)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_ALLOC)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); TOID_ASSIGN(obj, POBJ_NEXT_TYPE_NUM(obj.oid)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_realloc_alloc_abort -- reallocate an allocated object * and commit the transaction */ static void do_tx_realloc_alloc_abort(PMEMobjpool *pop) { TOID(struct object) obj; size_t new_size = 0; TX_BEGIN(pop) { TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_ABORT_ALLOC, TEST_VALUE_1)); UT_ASSERT(!TOID_IS_NULL(obj)); new_size = 2 * pmemobj_alloc_usable_size(obj.oid); TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, new_size, TYPE_ABORT_ALLOC)); UT_ASSERT(!TOID_IS_NULL(obj)); UT_ASSERT(pmemobj_alloc_usable_size(obj.oid) >= new_size); pmemobj_tx_abort(-1); } TX_ONCOMMIT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_ALLOC)); UT_ASSERT(TOID_IS_NULL(obj)); } /* * do_tx_root_realloc -- retrieve root inside of transaction */ static void do_tx_root_realloc(PMEMobjpool *pop) { TX_BEGIN(pop) { PMEMoid root = pmemobj_root(pop, sizeof(struct object)); UT_ASSERT(!OID_IS_NULL(root)); UT_ASSERT(util_is_zeroed(pmemobj_direct(root), sizeof(struct object))); UT_ASSERTeq(sizeof(struct object), pmemobj_root_size(pop)); root = pmemobj_root(pop, 2 * sizeof(struct object)); UT_ASSERT(!OID_IS_NULL(root)); UT_ASSERT(util_is_zeroed(pmemobj_direct(root), 2 * sizeof(struct object))); UT_ASSERTeq(2 * sizeof(struct object), pmemobj_root_size(pop)); } TX_ONABORT { UT_ASSERT(0); } TX_END } /* * do_tx_realloc_free -- reallocate an allocated object * and commit the transaction */ static void do_tx_realloc_free(PMEMobjpool *pop) { TOID(struct object) obj; TOID_ASSIGN(obj, do_tx_alloc(pop, TYPE_FREE, TEST_VALUE_1)); TX_BEGIN(pop) { TOID_ASSIGN(obj, pmemobj_tx_realloc(obj.oid, 0, TYPE_COMMIT)); } TX_ONABORT { UT_ASSERT(0); } TX_END TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_FREE)); UT_ASSERT(TOID_IS_NULL(obj)); } int main(int argc, char *argv[]) { START(argc, argv, "obj_tx_realloc"); 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_realloc(pop); do_tx_realloc_commit(pop); do_tx_realloc_abort(pop); do_tx_realloc_huge(pop); do_tx_zrealloc_commit(pop); do_tx_zrealloc_commit_macro(pop); do_tx_zrealloc_abort(pop); do_tx_zrealloc_abort_macro(pop); do_tx_zrealloc_huge(pop); do_tx_zrealloc_huge_macro(pop); do_tx_realloc_alloc_commit(pop); do_tx_realloc_alloc_abort(pop); do_tx_realloc_free(pop); pmemobj_close(pop); DONE(NULL); }
14,391
27.109375
80
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/log_pool/log_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. */ /* * log_pool.c -- unit test for pmemlog_create() and pmemlog_open() * * usage: log_pool op path [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 poolsize, unsigned mode) { PMEMlogpool *plp = pmemlog_create(path, poolsize, mode); if (plp == NULL) UT_OUT("!%s: pmemlog_create", path); else { os_stat_t stbuf; STAT(path, &stbuf); UT_OUT("%s: file size %zu usable space %zu mode 0%o", path, stbuf.st_size, pmemlog_nbyte(plp), stbuf.st_mode & 0777); pmemlog_close(plp); int 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); } } static void pool_open(const char *path) { PMEMlogpool *plp = pmemlog_open(path); if (plp == NULL) UT_OUT("!%s: pmemlog_open", path); else { UT_OUT("%s: pmemlog_open: Success", path); pmemlog_close(plp); } } int main(int argc, char *argv[]) { START(argc, argv, "log_pool"); if (argc < 3) UT_FATAL("usage: %s op path [poolsize mode]", argv[0]); size_t poolsize; unsigned mode; switch (argv[1][0]) { case 'c': poolsize = strtoul(argv[3], NULL, 0) * MB; /* in megabytes */ mode = strtoul(argv[4], NULL, 8); pool_create(argv[2], poolsize, mode); break; case 'o': pool_open(argv[2]); break; default: UT_FATAL("unknown operation"); } DONE(NULL); }
3,144
26.112069
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_lists_atomic_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_lists_atomic_include.c -- include test for libpmemobj */ #include <libpmemobj/lists_atomic.h>
1,703
43.842105
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_lists_atomic_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_lists_atomic_base_include.c -- include test for libpmemobj */ #include <libpmemobj/lists_atomic_base.h>
1,713
44.105263
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_tx_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_include.c -- include test for libpmemobj */ #include <libpmemobj/tx.h>
1,683
43.315789
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_base_include.c -- include test for libpmemobj */ #include <libpmemobj/base.h> int main(int argc, char *argv[]) { return 0; }
1,736
38.477273
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_atomic_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_atomic_include.c -- include test for libpmemobj */ #include <libpmemobj/atomic.h>
1,691
43.526316
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_iterator_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_iterator_base_include.c -- include test for libpmemobj */ #include <libpmemobj/iterator_base.h>
1,705
43.894737
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_thread_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_thread_include.c -- include test for libpmemobj */ #include <libpmemobj/thread.h>
1,691
43.526316
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_iterator_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_iterator_include.c -- include test for libpmemobj */ #include <libpmemobj/iterator.h>
1,695
43.631579
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_types_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_types_include.c -- include test for libpmemobj */ #include <libpmemobj/types.h>
1,689
43.473684
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_tx_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_base_include.c -- include test for libpmemobj */ #include <libpmemobj/tx_base.h>
1,693
43.578947
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_pool_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_pool_include.c -- include test for libpmemobj */ #include <libpmemobj/pool.h>
1,687
43.421053
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_pool_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_pool_base_include.c -- include test for libpmemobj */ #include <libpmemobj/pool_base.h>
1,697
43.684211
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_include/obj_atomic_base_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_atomic_base_include.c -- include test for libpmemobj */ #include <libpmemobj/atomic_base.h>
1,701
43.789474
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_rm_win/libpmempool_rm_win.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. */ /* * libpmempool_rm_win -- a unittest for pmempool_rm. * */ #include <stddef.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <getopt.h> #include "unittest.h" #define FATAL_USAGE(n) UT_FATAL("usage: %s [-f -l -r] path..", (n)) static PMEMobjpool *Pop; int wmain(int argc, wchar_t *argv[]) { STARTW(argc, argv, "libpmempool_rm_win"); if (argc < 2) FATAL_USAGE(ut_toUTF8(argv[0])); unsigned flags = 0; int do_open = 0; int i = 1; for (; i < argc - 1; i++) { wchar_t *optarg = argv[i + 1]; if (wcscmp(L"-f", argv[i]) == 0) flags |= PMEMPOOL_RM_FORCE; else if (wcscmp(L"-r", argv[i]) == 0) flags |= PMEMPOOL_RM_POOLSET_REMOTE; else if (wcscmp(L"-l", argv[i]) == 0) flags |= PMEMPOOL_RM_POOLSET_LOCAL; else if (wcscmp(L"-o", argv[i]) == 0) do_open = 1; else if (wcschr(argv[i], L'-') == argv[i]) FATAL_USAGE(argv[0]); else break; } for (; i < argc; i++) { const wchar_t *path = argv[i]; if (do_open) { Pop = pmemobj_openW(path, NULL); UT_ASSERTne(Pop, NULL); } int ret = pmempool_rmW(path, flags); if (ret) { UT_OUT("!%s: %s", ut_toUTF8(path), pmempool_errormsgU()); } if (do_open) { UT_ASSERTne(Pop, NULL); pmemobj_close(Pop); } } DONEW(NULL); }
2,857
28.770833
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_rw/blk_rw.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * blk_rw.c -- unit test for pmemblk_read/write/set_zero/set_error * * usage: blk_rw bsize file func operation:lba... * * func is 'c' or 'o' (create or open) * operations are 'r' or 'w' or 'z' or 'e' * */ #include "unittest.h" static size_t Bsize; /* * construct -- build a buffer for writing */ static void construct(unsigned char *buf) { static int ord = 1; for (int i = 0; i < Bsize; i++) buf[i] = ord; ord++; if (ord > 255) ord = 1; } /* * ident -- identify what a buffer holds */ static char * ident(unsigned char *buf) { static char descr[100]; unsigned val = *buf; for (int i = 1; i < Bsize; i++) if (buf[i] != val) { sprintf(descr, "{%u} TORN at byte %d", val, i); return descr; } sprintf(descr, "{%u}", val); return descr; } int main(int argc, char *argv[]) { START(argc, argv, "blk_rw"); if (argc < 5) UT_FATAL("usage: %s bsize file func op:lba...", argv[0]); Bsize = strtoul(argv[1], NULL, 0); const char *path = argv[2]; PMEMblkpool *handle; switch (*argv[3]) { case 'c': handle = pmemblk_create(path, Bsize, 0, S_IWUSR | S_IRUSR); if (handle == NULL) UT_FATAL("!%s: pmemblk_create", path); break; case 'o': handle = pmemblk_open(path, Bsize); if (handle == NULL) UT_FATAL("!%s: pmemblk_open", path); break; } UT_OUT("%s block size %zu usable blocks %zu", argv[1], Bsize, pmemblk_nblock(handle)); unsigned char *buf = MALLOC(Bsize); if (buf == NULL) UT_FATAL("cannot allocate buf"); /* map each file argument with the given map type */ for (int arg = 4; arg < argc; arg++) { if (strchr("rwze", argv[arg][0]) == NULL || argv[arg][1] != ':') UT_FATAL("op must be r: or w: or z: or e:"); os_off_t lba = strtol(&argv[arg][2], NULL, 0); switch (argv[arg][0]) { case 'r': if (pmemblk_read(handle, buf, lba) < 0) UT_OUT("!read lba %jd", lba); else UT_OUT("read lba %jd: %s", lba, ident(buf)); break; case 'w': construct(buf); if (pmemblk_write(handle, buf, lba) < 0) UT_OUT("!write lba %jd", lba); else UT_OUT("write lba %jd: %s", lba, ident(buf)); break; case 'z': if (pmemblk_set_zero(handle, lba) < 0) UT_OUT("!set_zero lba %jd", lba); else UT_OUT("set_zero lba %jd", lba); break; case 'e': if (pmemblk_set_error(handle, lba) < 0) UT_OUT("!set_error lba %jd", lba); else UT_OUT("set_error lba %jd", lba); break; } } FREE(buf); pmemblk_close(handle); int result = pmemblk_check(path, Bsize); if (result < 0) UT_OUT("!%s: pmemblk_check", path); else if (result == 0) UT_OUT("%s: pmemblk_check: not consistent", path); DONE(NULL); }
4,288
24.529762
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_lock/obj_tx_lock.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_lock.c -- unit test for pmemobj_tx_lock() */ #include "unittest.h" #include "libpmemobj.h" #define LAYOUT_NAME "obj_tx_lock" #define NUM_LOCKS 2 struct transaction_data { PMEMmutex mutexes[NUM_LOCKS]; PMEMrwlock rwlocks[NUM_LOCKS]; }; static PMEMobjpool *Pop; #define DO_LOCK(mtx, rwlock)\ pmemobj_tx_lock(TX_PARAM_MUTEX, &(mtx)[0]);\ pmemobj_tx_lock(TX_PARAM_MUTEX, &(mtx)[1]);\ pmemobj_tx_lock(TX_PARAM_RWLOCK, &(rwlock)[0]);\ pmemobj_tx_lock(TX_PARAM_RWLOCK, &(rwlock)[1]) #define IS_UNLOCKED(pop, mtx, rwlock)\ ret = 0;\ ret += pmemobj_mutex_trylock((pop), &(mtx)[0]);\ ret += pmemobj_mutex_trylock((pop), &(mtx)[1]);\ ret += pmemobj_rwlock_trywrlock((pop), &(rwlock)[0]);\ ret += pmemobj_rwlock_trywrlock((pop), &(rwlock)[1]);\ UT_ASSERTeq(ret, 0);\ pmemobj_mutex_unlock((pop), &(mtx)[0]);\ pmemobj_mutex_unlock((pop), &(mtx)[1]);\ pmemobj_rwlock_unlock((pop), &(rwlock)[0]);\ pmemobj_rwlock_unlock((pop), &(rwlock)[1]) #define IS_LOCKED(pop, mtx, rwlock)\ ret = pmemobj_mutex_trylock((pop), &(mtx)[0]);\ UT_ASSERT(ret != 0);\ ret = pmemobj_mutex_trylock((pop), &(mtx)[1]);\ UT_ASSERT(ret != 0);\ ret = pmemobj_rwlock_trywrlock((pop), &(rwlock)[0]);\ UT_ASSERT(ret != 0);\ ret = pmemobj_rwlock_trywrlock((pop), &(rwlock)[1]);\ UT_ASSERT(ret != 0) /* * do_tx_add_locks -- (internal) transaction where locks are added after * transaction begins */ static void * do_tx_add_locks(struct transaction_data *data) { int ret; IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); TX_BEGIN(Pop) { DO_LOCK(data->mutexes, data->rwlocks); IS_LOCKED(Pop, data->mutexes, data->rwlocks); } TX_ONABORT { /* not called */ UT_ASSERT(0); } TX_END IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); return NULL; } /* * do_tx_add_locks_nested -- (internal) transaction where locks * are added after nested transaction begins */ static void * do_tx_add_locks_nested(struct transaction_data *data) { int ret; TX_BEGIN(Pop) { IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); TX_BEGIN(Pop) { DO_LOCK(data->mutexes, data->rwlocks); IS_LOCKED(Pop, data->mutexes, data->rwlocks); } TX_END IS_LOCKED(Pop, data->mutexes, data->rwlocks); } TX_ONABORT { UT_ASSERT(0); } TX_END IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); return NULL; } /* * do_tx_add_locks_nested_all -- (internal) transaction where all locks * are added in both transactions after transaction begins */ static void * do_tx_add_locks_nested_all(struct transaction_data *data) { int ret; TX_BEGIN(Pop) { IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); DO_LOCK(data->mutexes, data->rwlocks); IS_LOCKED(Pop, data->mutexes, data->rwlocks); TX_BEGIN(Pop) { IS_LOCKED(Pop, data->mutexes, data->rwlocks); DO_LOCK(data->mutexes, data->rwlocks); IS_LOCKED(Pop, data->mutexes, data->rwlocks); } TX_END IS_LOCKED(Pop, data->mutexes, data->rwlocks); } TX_ONABORT { UT_ASSERT(0); } TX_END IS_UNLOCKED(Pop, data->mutexes, data->rwlocks); return NULL; } int main(int argc, char *argv[]) { START(argc, argv, "obj_tx_lock"); if (argc != 2) UT_FATAL("usage: %s <file>", argv[0]); if ((Pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create"); PMEMoid root = pmemobj_root(Pop, sizeof(struct transaction_data)); struct transaction_data *test_obj = (struct transaction_data *)pmemobj_direct(root); do_tx_add_locks(test_obj); do_tx_add_locks_nested(test_obj); do_tx_add_locks_nested_all(test_obj); pmemobj_close(Pop); DONE(NULL); }
5,159
29.352941
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_memops/obj_memops.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_memops.c -- basic memory operations tests * */ #include <stddef.h> #include "obj.h" #include "memops.h" #include "ulog.h" #include "unittest.h" #define TEST_ENTRIES 256 #define TEST_VALUES 128 enum fail_types { FAIL_NONE, FAIL_CHECKSUM, FAIL_MODIFY_NEXT, FAIL_MODIFY_VALUE, }; struct test_object { uint8_t padding[CACHELINE_SIZE - 16]; /* align to a cacheline */ struct ULOG(TEST_ENTRIES) redo; struct ULOG(TEST_ENTRIES) undo; uint64_t values[TEST_VALUES]; }; static void clear_test_values(struct test_object *object) { memset(object->values, 0, sizeof(uint64_t) * TEST_VALUES); } static int redo_log_constructor(void *ctx, void *ptr, size_t usable_size, void *arg) { PMEMobjpool *pop = ctx; const struct pmem_ops *p_ops = &pop->p_ops; ulog_construct(OBJ_PTR_TO_OFF(ctx, ptr), TEST_ENTRIES, 1, p_ops); return 0; } static int pmalloc_redo_extend(void *base, uint64_t *redo) { size_t s = SIZEOF_ULOG(TEST_ENTRIES); return pmalloc_construct(base, redo, s, redo_log_constructor, NULL, 0, OBJ_INTERNAL_OBJECT_MASK, 0); } static void test_set_entries(PMEMobjpool *pop, struct operation_context *ctx, struct test_object *object, size_t nentries, enum fail_types fail) { operation_start(ctx); for (size_t i = 0; i < nentries; ++i) { operation_add_typed_entry(ctx, &object->values[i], i + 1, ULOG_OPERATION_SET, LOG_PERSISTENT); } operation_reserve(ctx, nentries * 16); if (fail != FAIL_NONE) { operation_cancel(ctx); switch (fail) { case FAIL_CHECKSUM: object->redo.checksum += 1; break; case FAIL_MODIFY_NEXT: pmalloc_redo_extend(pop, &object->redo.next); break; case FAIL_MODIFY_VALUE: object->redo.data[16] += 8; break; default: UT_ASSERT(0); } ulog_recover((struct ulog *)&object->redo, OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops); for (size_t i = 0; i < nentries; ++i) UT_ASSERTeq(object->values[i], 0); } else { operation_finish(ctx); for (size_t i = 0; i < nentries; ++i) UT_ASSERTeq(object->values[i], i + 1); } } static void test_merge_op(struct operation_context *ctx, struct test_object *object) { operation_start(ctx); operation_add_typed_entry(ctx, &object->values[0], 0b10, ULOG_OPERATION_OR, LOG_PERSISTENT); operation_add_typed_entry(ctx, &object->values[0], 0b01, ULOG_OPERATION_OR, LOG_PERSISTENT); operation_add_typed_entry(ctx, &object->values[0], 0b00, ULOG_OPERATION_AND, LOG_PERSISTENT); operation_add_typed_entry(ctx, &object->values[0], 0b01, ULOG_OPERATION_OR, LOG_PERSISTENT); operation_finish(ctx); UT_ASSERTeq(object->values[0], 0b01); } static void test_same_twice(struct operation_context *ctx, struct test_object *object) { operation_start(ctx); operation_add_typed_entry(ctx, &object->values[0], 5, ULOG_OPERATION_SET, LOG_PERSISTENT); operation_add_typed_entry(ctx, &object->values[0], 10, ULOG_OPERATION_SET, LOG_PERSISTENT); operation_process(ctx); UT_ASSERTeq(object->values[0], 10); } static void test_redo(PMEMobjpool *pop, struct test_object *object) { struct operation_context *ctx = operation_new( (struct ulog *)&object->redo, TEST_ENTRIES, pmalloc_redo_extend, NULL, &pop->p_ops, LOG_TYPE_REDO); test_set_entries(pop, ctx, object, 10, FAIL_NONE); clear_test_values(object); test_merge_op(ctx, object); clear_test_values(object); test_set_entries(pop, ctx, object, 100, FAIL_NONE); clear_test_values(object); test_set_entries(pop, ctx, object, 100, FAIL_CHECKSUM); clear_test_values(object); test_set_entries(pop, ctx, object, 10, FAIL_CHECKSUM); clear_test_values(object); test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_VALUE); clear_test_values(object); test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_VALUE); clear_test_values(object); test_same_twice(ctx, object); clear_test_values(object); operation_delete(ctx); /* verify that rebuilding redo_next works */ ctx = operation_new( (struct ulog *)&object->redo, TEST_ENTRIES, NULL, NULL, &pop->p_ops, LOG_TYPE_REDO); test_set_entries(pop, ctx, object, 100, 0); clear_test_values(object); /* FAIL_MODIFY_NEXT tests can only happen after redo_next test */ test_set_entries(pop, ctx, object, 100, FAIL_MODIFY_NEXT); clear_test_values(object); test_set_entries(pop, ctx, object, 10, FAIL_MODIFY_NEXT); clear_test_values(object); operation_delete(ctx); } static void test_undo_small_single_copy(struct operation_context *ctx, struct test_object *object) { operation_start(ctx); object->values[0] = 1; object->values[1] = 2; operation_add_buffer(ctx, &object->values, &object->values, sizeof(*object->values) * 2, ULOG_OPERATION_BUF_CPY); object->values[0] = 2; object->values[1] = 1; operation_process(ctx); operation_finish(ctx); operation_start(ctx); UT_ASSERTeq(object->values[0], 1); UT_ASSERTeq(object->values[1], 2); object->values[0] = 2; object->values[1] = 1; operation_process(ctx); UT_ASSERTeq(object->values[0], 2); UT_ASSERTeq(object->values[1], 1); operation_finish(ctx); } static void test_undo_small_single_set(struct operation_context *ctx, struct test_object *object) { operation_start(ctx); object->values[0] = 1; object->values[1] = 2; int c = 0; operation_add_buffer(ctx, &object->values, &c, sizeof(*object->values) * 2, ULOG_OPERATION_BUF_SET); operation_process(ctx); UT_ASSERTeq(object->values[0], 0); UT_ASSERTeq(object->values[1], 0); operation_finish(ctx); } static void test_undo_large_single_copy(struct operation_context *ctx, struct test_object *object) { operation_start(ctx); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 1; operation_add_buffer(ctx, &object->values, &object->values, sizeof(object->values), ULOG_OPERATION_BUF_CPY); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 2; operation_process(ctx); for (uint64_t i = 0; i < TEST_VALUES; ++i) UT_ASSERTeq(object->values[i], i + 1); operation_finish(ctx); } static void test_undo_checksum_mismatch(PMEMobjpool *pop, struct operation_context *ctx, struct test_object *object, struct ulog *log) { operation_start(ctx); for (uint64_t i = 0; i < 20; ++i) object->values[i] = i + 1; operation_add_buffer(ctx, &object->values, &object->values, sizeof(*object->values) * 20, ULOG_OPERATION_BUF_CPY); for (uint64_t i = 0; i < 20; ++i) object->values[i] = i + 2; pmemobj_persist(pop, &object->values, sizeof(*object->values) * 20); log->data[100] += 1; /* corrupt the log somewhere */ operation_process(ctx); /* the log shouldn't get applied */ for (uint64_t i = 0; i < 20; ++i) UT_ASSERTeq(object->values[i], i + 2); operation_finish(ctx); } static void test_undo_large_copy(PMEMobjpool *pop, struct operation_context *ctx, struct test_object *object) { operation_start(ctx); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 1; operation_add_buffer(ctx, &object->values, &object->values, sizeof(object->values), ULOG_OPERATION_BUF_CPY); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 2; operation_process(ctx); for (uint64_t i = 0; i < TEST_VALUES; ++i) UT_ASSERTeq(object->values[i], i + 1); operation_finish(ctx); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 3; operation_start(ctx); operation_add_buffer(ctx, &object->values, &object->values, sizeof(*object->values) * 26, ULOG_OPERATION_BUF_CPY); for (uint64_t i = 0; i < TEST_VALUES; ++i) object->values[i] = i + 4; pmemobj_persist(pop, &object->values, sizeof(object->values)); operation_process(ctx); for (uint64_t i = 0; i < 26; ++i) UT_ASSERTeq(object->values[i], i + 3); for (uint64_t i = 26; i < TEST_VALUES; ++i) UT_ASSERTeq(object->values[i], i + 4); operation_finish(ctx); } static void test_undo(PMEMobjpool *pop, struct test_object *object) { struct operation_context *ctx = operation_new( (struct ulog *)&object->undo, TEST_ENTRIES, pmalloc_redo_extend, (ulog_free_fn)pfree, &pop->p_ops, LOG_TYPE_UNDO); test_undo_small_single_copy(ctx, object); test_undo_small_single_set(ctx, object); test_undo_large_single_copy(ctx, object); test_undo_large_copy(pop, ctx, object); test_undo_checksum_mismatch(pop, ctx, object, (struct ulog *)&object->undo); /* undo logs are clobbered at the end, which shrinks their size */ size_t capacity = ulog_capacity((struct ulog *)&object->undo, TEST_ENTRIES, &pop->p_ops); /* builtin log + one next */ UT_ASSERTeq(capacity, TEST_ENTRIES * 2); operation_delete(ctx); } int main(int argc, char *argv[]) { START(argc, argv, "obj_memops"); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, "obj_memops", PMEMOBJ_MIN_POOL * 10, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); struct test_object *object = pmemobj_direct(pmemobj_root(pop, sizeof(struct test_object))); UT_ASSERTne(object, NULL); ulog_construct(OBJ_PTR_TO_OFF(pop, &object->undo), TEST_ENTRIES, 1, &pop->p_ops); test_redo(pop, object); test_undo(pop, object); 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
10,934
23.908884
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_include/libpmempool_include.c
/* * Copyright 2016, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool_include.c -- include test for libpmempool * * this is only a compilation test - do not run this program */ #include <libpmempool.h> int main(int argc, char *argv[]) { return 0; }
1,800
38.152174
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_strdup/obj_strdup.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_strdup.c -- unit test for pmemobj_strdup */ #include <sys/param.h> #include <string.h> #include <wchar.h> #include "unittest.h" #include "libpmemobj.h" #define LAYOUT_NAME "strdup" TOID_DECLARE(char, 0); TOID_DECLARE(wchar_t, 1); enum type_number { TYPE_SIMPLE, TYPE_NULL, TYPE_SIMPLE_ALLOC, TYPE_SIMPLE_ALLOC_1, TYPE_SIMPLE_ALLOC_2, TYPE_NULL_ALLOC, TYPE_NULL_ALLOC_1, }; #define TEST_STR_1 "Test string 1" #define TEST_STR_2 "Test string 2" #define TEST_WCS_1 L"Test string 3" #define TEST_WCS_2 L"Test string 4" /* * do_strdup -- duplicate a string to not allocated toid using pmemobj_strdup */ static void do_strdup(PMEMobjpool *pop) { TOID(char) str = TOID_NULL(char); TOID(wchar_t) wcs = TOID_NULL(wchar_t); pmemobj_strdup(pop, &str.oid, TEST_STR_1, TYPE_SIMPLE); pmemobj_wcsdup(pop, &wcs.oid, TEST_WCS_1, TYPE_SIMPLE); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERT(!TOID_IS_NULL(wcs)); UT_ASSERTeq(strcmp(D_RO(str), TEST_STR_1), 0); UT_ASSERTeq(wcscmp(D_RO(wcs), TEST_WCS_1), 0); } /* * do_strdup_null -- duplicate a NULL string to not allocated toid */ static void do_strdup_null(PMEMobjpool *pop) { TOID(char) str = TOID_NULL(char); TOID(wchar_t) wcs = TOID_NULL(wchar_t); pmemobj_strdup(pop, &str.oid, NULL, TYPE_NULL); pmemobj_wcsdup(pop, &wcs.oid, NULL, TYPE_NULL); UT_ASSERT(TOID_IS_NULL(str)); UT_ASSERT(TOID_IS_NULL(wcs)); } /* * do_alloc -- allocate toid and duplicate a string */ static TOID(char) do_alloc(PMEMobjpool *pop, const char *s, unsigned type_num) { TOID(char) str; POBJ_ZNEW(pop, &str, char); pmemobj_strdup(pop, &str.oid, s, type_num); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERTeq(strcmp(D_RO(str), s), 0); return str; } /* * do_wcs_alloc -- allocate toid and duplicate a wide character string */ static TOID(wchar_t) do_wcs_alloc(PMEMobjpool *pop, const wchar_t *s, unsigned type_num) { TOID(wchar_t) str; POBJ_ZNEW(pop, &str, wchar_t); pmemobj_wcsdup(pop, &str.oid, s, type_num); UT_ASSERT(!TOID_IS_NULL(str)); UT_ASSERTeq(wcscmp(D_RO(str), s), 0); return str; } /* * do_strdup_alloc -- duplicate a string to allocated toid */ static void do_strdup_alloc(PMEMobjpool *pop) { TOID(char) str1 = do_alloc(pop, TEST_STR_1, TYPE_SIMPLE_ALLOC_1); TOID(wchar_t) wcs1 = do_wcs_alloc(pop, TEST_WCS_1, TYPE_SIMPLE_ALLOC_1); TOID(char) str2 = do_alloc(pop, TEST_STR_2, TYPE_SIMPLE_ALLOC_2); TOID(wchar_t) wcs2 = do_wcs_alloc(pop, TEST_WCS_2, TYPE_SIMPLE_ALLOC_2); pmemobj_strdup(pop, &str1.oid, D_RO(str2), TYPE_SIMPLE_ALLOC); pmemobj_wcsdup(pop, &wcs1.oid, D_RO(wcs2), TYPE_SIMPLE_ALLOC); UT_ASSERTeq(strcmp(D_RO(str1), D_RO(str2)), 0); UT_ASSERTeq(wcscmp(D_RO(wcs1), D_RO(wcs2)), 0); } /* * do_strdup_null_alloc -- duplicate a NULL string to allocated toid */ static void do_strdup_null_alloc(PMEMobjpool *pop) { TOID(char) str1 = do_alloc(pop, TEST_STR_1, TYPE_NULL_ALLOC_1); TOID(wchar_t) wcs1 = do_wcs_alloc(pop, TEST_WCS_1, TYPE_NULL_ALLOC_1); TOID(char) str2 = TOID_NULL(char); TOID(wchar_t) wcs2 = TOID_NULL(wchar_t); pmemobj_strdup(pop, &str1.oid, D_RO(str2), TYPE_NULL_ALLOC); pmemobj_wcsdup(pop, &wcs1.oid, D_RO(wcs2), TYPE_NULL_ALLOC); UT_ASSERT(!TOID_IS_NULL(str1)); UT_ASSERT(!TOID_IS_NULL(wcs1)); } int main(int argc, char *argv[]) { START(argc, argv, "obj_strdup"); 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_strdup(pop); do_strdup_null(pop); do_strdup_alloc(pop); do_strdup_null_alloc(pop); pmemobj_close(pop); DONE(NULL); }
5,221
29.011494
77
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_fork/vmmalloc_fork.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. */ /* * vmmalloc_fork.c -- unit test for libvmmalloc fork() support * * usage: vmmalloc_fork [c|e] <nfork> <nthread> */ #ifdef __FreeBSD__ #include <stdlib.h> #include <malloc_np.h> #else #include <malloc.h> #endif #include <sys/wait.h> #include "unittest.h" #define NBUFS 16 /* * get_rand_size -- returns random size of allocation */ static size_t get_rand_size(void) { return sizeof(int) + 64 * ((unsigned)rand() % 100); } /* * do_test -- thread callback * * This function is called in separate thread and the main thread * forks a child processes. Please be aware that any locks held in this * function may potentially cause a deadlock. * * For example using rand() in this function may cause a deadlock because * it grabs an internal lock. */ static void * do_test(void *arg) { int **bufs = malloc(NBUFS * sizeof(void *)); UT_ASSERTne(bufs, NULL); size_t *sizes = (size_t *)arg; UT_ASSERTne(sizes, NULL); for (int j = 0; j < NBUFS; j++) { bufs[j] = malloc(sizes[j]); UT_ASSERTne(bufs[j], NULL); } for (int j = 0; j < NBUFS; j++) { UT_ASSERT(malloc_usable_size(bufs[j]) >= sizes[j]); free(bufs[j]); } free(bufs); return NULL; } int main(int argc, char *argv[]) { if (argc == 4 && argv[3][0] == 't') { exit(0); } START(argc, argv, "vmmalloc_fork"); if (argc < 4) UT_FATAL("usage: %s [c|e] <nfork> <nthread>", argv[0]); unsigned nfork = ATOU(argv[2]); unsigned nthread = ATOU(argv[3]); os_thread_t thread[nthread]; unsigned first_child = 0; unsigned **bufs = malloc(nfork * NBUFS * sizeof(void *)); UT_ASSERTne(bufs, NULL); size_t *sizes = malloc(nfork * NBUFS * sizeof(size_t)); UT_ASSERTne(sizes, NULL); int *pids1 = malloc(nfork * sizeof(pid_t)); UT_ASSERTne(pids1, NULL); int *pids2 = malloc(nfork * sizeof(pid_t)); UT_ASSERTne(pids2, NULL); for (unsigned i = 0; i < nfork; i++) { for (unsigned j = 0; j < NBUFS; j++) { unsigned idx = i * NBUFS + j; sizes[idx] = get_rand_size(); bufs[idx] = malloc(sizes[idx]); UT_ASSERTne(bufs[idx], NULL); UT_ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]); } size_t **thread_sizes = malloc(sizeof(size_t *) * nthread); UT_ASSERTne(thread_sizes, NULL); for (int t = 0; t < nthread; ++t) { thread_sizes[t] = malloc(NBUFS * sizeof(size_t)); UT_ASSERTne(thread_sizes[t], NULL); for (int j = 0; j < NBUFS; j++) thread_sizes[t][j] = get_rand_size(); } for (int t = 0; t < nthread; ++t) { PTHREAD_CREATE(&thread[t], NULL, do_test, thread_sizes[t]); } pids1[i] = fork(); if (pids1[i] == -1) UT_OUT("fork failed"); UT_ASSERTne(pids1[i], -1); if (pids1[i] == 0 && argv[1][0] == 'e' && i == nfork - 1) { int fd = os_open("/dev/null", O_RDWR, S_IWUSR); int res = dup2(fd, 1); UT_ASSERTne(res, -1); os_close(fd); execl("/bin/echo", "/bin/echo", "Hello world!", NULL); } pids2[i] = getpid(); for (unsigned j = 0; j < NBUFS; j++) { *bufs[i * NBUFS + j] = ((unsigned)pids2[i] << 16) + j; } if (pids1[i]) { /* parent */ for (int t = 0; t < nthread; ++t) { PTHREAD_JOIN(&thread[t], NULL); free(thread_sizes[t]); } free(thread_sizes); } else { /* child */ first_child = i + 1; } for (unsigned ii = 0; ii < i; ii++) { for (unsigned j = 0; j < NBUFS; j++) { UT_ASSERTeq(*bufs[ii * NBUFS + j], ((unsigned)pids2[ii] << 16) + j); } } } for (unsigned i = first_child; i < nfork; i++) { int status; waitpid(pids1[i], &status, 0); UT_ASSERT(WIFEXITED(status)); UT_ASSERTeq(WEXITSTATUS(status), 0); } free(pids1); free(pids2); for (int i = 0; i < nfork; i++) { for (int j = 0; j < NBUFS; j++) { int idx = i * NBUFS + j; UT_ASSERT(malloc_usable_size(bufs[idx]) >= sizes[idx]); free(bufs[idx]); } } free(sizes); free(bufs); if (first_child == 0) { DONE(NULL); } }
5,443
24.439252
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_is_pmem/pmem_is_pmem.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. */ /* * pmem_is_pmem.c -- unit test for pmem_is_pmem() * * usage: pmem_is_pmem file [env] */ #include "unittest.h" #define NTHREAD 16 static void *Addr; static size_t Size; /* * worker -- the work each thread performs */ static void * worker(void *arg) { int *ret = (int *)arg; *ret = pmem_is_pmem(Addr, Size); return NULL; } int main(int argc, char *argv[]) { START(argc, argv, "pmem_is_pmem"); if (argc < 2 || argc > 3) UT_FATAL("usage: %s file [env]", argv[0]); if (argc == 3) UT_ASSERTeq(os_setenv("PMEM_IS_PMEM_FORCE", argv[2], 1), 0); Addr = pmem_map_file(argv[1], 0, 0, 0, &Size, NULL); UT_ASSERTne(Addr, NULL); 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("threads.is_pmem(Addr, Size): %d", ret[0]); UT_ASSERTeq(os_unsetenv("PMEM_IS_PMEM_FORCE"), 0); UT_OUT("is_pmem(Addr, Size): %d", pmem_is_pmem(Addr, Size)); /* zero-sized region is not pmem */ UT_OUT("is_pmem(Addr, 0): %d", pmem_is_pmem(Addr, 0)); UT_OUT("is_pmem(Addr + Size / 2, 0): %d", pmem_is_pmem((char *)Addr + Size / 2, 0)); UT_OUT("is_pmem(Addr + Size, 0): %d", pmem_is_pmem((char *)Addr + Size, 0)); DONE(NULL); }
3,174
30.127451
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmem_obc_int/rpmem_obc_int.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_obc_int.c -- integration test for rpmem_obc and rpmemd_obc modules */ #include "unittest.h" #include "pmemcommon.h" #include "librpmem.h" #include "rpmem.h" #include "rpmem_proto.h" #include "rpmem_common.h" #include "rpmem_util.h" #include "rpmem_obc.h" #include "rpmemd_obc.h" #include "rpmemd_log.h" #include "os.h" #define POOL_SIZE 1024 #define NLANES 32 #define NLANES_RESP 16 #define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS #define POOL_DESC "pool_desc" #define RKEY 0xabababababababab #define RADDR 0x0101010101010101 #define PORT 1234 #define PERSIST_METHOD RPMEM_PM_GPSPM #define RESP_ATTR_INIT {\ .port = PORT,\ .rkey = RKEY,\ .raddr = RADDR,\ .persist_method = PERSIST_METHOD,\ .nlanes = NLANES_RESP,\ } #define REQ_ATTR_INIT {\ .pool_size = POOL_SIZE,\ .nlanes = NLANES,\ .provider = PROVIDER,\ .pool_desc = POOL_DESC,\ } #define POOL_ATTR_INIT {\ .signature = "<RPMEM>",\ .major = 1,\ .compat_features = 2,\ .incompat_features = 3,\ .ro_compat_features = 4,\ .poolset_uuid = "POOLSET_UUID0123",\ .uuid = "UUID0123456789AB",\ .next_uuid = "NEXT_UUID0123456",\ .prev_uuid = "PREV_UUID0123456",\ .user_flags = "USER_FLAGS012345",\ } #define POOL_ATTR_ALT {\ .signature = "<ALT>",\ .major = 5,\ .compat_features = 6,\ .incompat_features = 7,\ .ro_compat_features = 8,\ .poolset_uuid = "UUID_POOLSET_ALT",\ .uuid = "ALT_UUIDCDEFFEDC",\ .next_uuid = "456UUID_NEXT_ALT",\ .prev_uuid = "UUID012_ALT_PREV",\ .user_flags = "012345USER_FLAGS",\ } TEST_CASE_DECLARE(client_create); TEST_CASE_DECLARE(client_open); TEST_CASE_DECLARE(client_set_attr); TEST_CASE_DECLARE(server); /* * client_create -- perform create request */ int client_create(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; int ret; struct rpmem_obc *rpc; struct rpmem_target_info *info; struct rpmem_req_attr req = REQ_ATTR_INIT; struct rpmem_pool_attr pool_attr = POOL_ATTR_INIT; struct rpmem_resp_attr ex_res = RESP_ATTR_INIT; struct rpmem_resp_attr res; info = rpmem_target_parse(target); UT_ASSERTne(info, NULL); rpc = rpmem_obc_init(); UT_ASSERTne(rpc, NULL); ret = rpmem_obc_connect(rpc, info); UT_ASSERTeq(ret, 0); rpmem_target_free(info); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_create(rpc, &req, &res, &pool_attr); UT_ASSERTeq(ret, 0); UT_ASSERTeq(ex_res.port, res.port); UT_ASSERTeq(ex_res.rkey, res.rkey); UT_ASSERTeq(ex_res.raddr, res.raddr); UT_ASSERTeq(ex_res.persist_method, res.persist_method); UT_ASSERTeq(ex_res.nlanes, res.nlanes); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_close(rpc, 0); UT_ASSERTeq(ret, 0); ret = rpmem_obc_disconnect(rpc); UT_ASSERTeq(ret, 0); rpmem_obc_fini(rpc); return 1; } /* * client_open -- perform open request */ int client_open(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; int ret; struct rpmem_obc *rpc; struct rpmem_target_info *info; struct rpmem_req_attr req = REQ_ATTR_INIT; struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_INIT; struct rpmem_pool_attr pool_attr; struct rpmem_resp_attr ex_res = RESP_ATTR_INIT; struct rpmem_resp_attr res; info = rpmem_target_parse(target); UT_ASSERTne(info, NULL); rpc = rpmem_obc_init(); UT_ASSERTne(rpc, NULL); ret = rpmem_obc_connect(rpc, info); UT_ASSERTeq(ret, 0); rpmem_target_free(info); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_open(rpc, &req, &res, &pool_attr); UT_ASSERTeq(ret, 0); UT_ASSERTeq(ex_res.port, res.port); UT_ASSERTeq(ex_res.rkey, res.rkey); UT_ASSERTeq(ex_res.raddr, res.raddr); UT_ASSERTeq(ex_res.persist_method, res.persist_method); UT_ASSERTeq(ex_res.nlanes, res.nlanes); UT_ASSERTeq(memcmp(&ex_pool_attr, &pool_attr, sizeof(ex_pool_attr)), 0); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_close(rpc, 0); UT_ASSERTeq(ret, 0); ret = rpmem_obc_disconnect(rpc); UT_ASSERTeq(ret, 0); rpmem_obc_fini(rpc); return 1; } /* * client_set_attr -- perform set attributes request */ int client_set_attr(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: %s <addr>[:<port>]", tc->name); char *target = argv[0]; int ret; struct rpmem_obc *rpc; struct rpmem_target_info *info; const struct rpmem_pool_attr pool_attr = POOL_ATTR_ALT; info = rpmem_target_parse(target); UT_ASSERTne(info, NULL); rpc = rpmem_obc_init(); UT_ASSERTne(rpc, NULL); ret = rpmem_obc_connect(rpc, info); UT_ASSERTeq(ret, 0); rpmem_target_free(info); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_set_attr(rpc, &pool_attr); UT_ASSERTeq(ret, 0); ret = rpmem_obc_monitor(rpc, 1); UT_ASSERTeq(ret, 1); ret = rpmem_obc_close(rpc, 0); UT_ASSERTeq(ret, 0); ret = rpmem_obc_disconnect(rpc); UT_ASSERTeq(ret, 0); rpmem_obc_fini(rpc); return 1; } /* * req_arg -- request callbacks argument */ struct req_arg { struct rpmem_resp_attr resp; struct rpmem_pool_attr pool_attr; int closing; }; /* * req_create -- process create request */ static int req_create(struct rpmemd_obc *obc, void *arg, const struct rpmem_req_attr *req, const struct rpmem_pool_attr *pool_attr) { struct rpmem_req_attr ex_req = REQ_ATTR_INIT; struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_INIT; UT_ASSERTne(arg, NULL); UT_ASSERTeq(ex_req.provider, req->provider); UT_ASSERTeq(ex_req.pool_size, req->pool_size); UT_ASSERTeq(ex_req.nlanes, req->nlanes); UT_ASSERTeq(strcmp(ex_req.pool_desc, req->pool_desc), 0); UT_ASSERTeq(memcmp(&ex_pool_attr, pool_attr, sizeof(ex_pool_attr)), 0); struct req_arg *args = arg; return rpmemd_obc_create_resp(obc, 0, &args->resp); } /* * req_open -- process open request */ static int req_open(struct rpmemd_obc *obc, void *arg, const struct rpmem_req_attr *req) { struct rpmem_req_attr ex_req = REQ_ATTR_INIT; UT_ASSERTne(arg, NULL); UT_ASSERTeq(ex_req.provider, req->provider); UT_ASSERTeq(ex_req.pool_size, req->pool_size); UT_ASSERTeq(ex_req.nlanes, req->nlanes); UT_ASSERTeq(strcmp(ex_req.pool_desc, req->pool_desc), 0); struct req_arg *args = arg; return rpmemd_obc_open_resp(obc, 0, &args->resp, &args->pool_attr); } /* * req_set_attr -- process set attributes request */ static int req_set_attr(struct rpmemd_obc *obc, void *arg, const struct rpmem_pool_attr *pool_attr) { struct rpmem_pool_attr ex_pool_attr = POOL_ATTR_ALT; UT_ASSERTne(arg, NULL); UT_ASSERTeq(memcmp(&ex_pool_attr, pool_attr, sizeof(ex_pool_attr)), 0); return rpmemd_obc_set_attr_resp(obc, 0); } /* * req_close -- process close request */ static int req_close(struct rpmemd_obc *obc, void *arg, int flags) { UT_ASSERTne(arg, NULL); struct req_arg *args = arg; args->closing = 1; return rpmemd_obc_close_resp(obc, 0); } /* * REQ -- server request callbacks */ static struct rpmemd_obc_requests REQ = { .create = req_create, .open = req_open, .close = req_close, .set_attr = req_set_attr, }; /* * server -- run server and process clients requests */ int server(const struct test_case *tc, int argc, char *argv[]) { int ret; struct req_arg arg = { .resp = RESP_ATTR_INIT, .pool_attr = POOL_ATTR_INIT, .closing = 0, }; struct rpmemd_obc *obc; obc = rpmemd_obc_init(0, 1); UT_ASSERTne(obc, NULL); ret = rpmemd_obc_status(obc, 0); UT_ASSERTeq(ret, 0); while (1) { ret = rpmemd_obc_process(obc, &REQ, &arg); if (arg.closing) { break; } else { UT_ASSERTeq(ret, 0); } } ret = rpmemd_obc_process(obc, &REQ, &arg); UT_ASSERTeq(ret, 1); rpmemd_obc_fini(obc); return 0; } /* * test_cases -- available test cases */ static struct test_case test_cases[] = { TEST_CASE(server), TEST_CASE(client_create), TEST_CASE(client_open), TEST_CASE(client_set_attr), }; #define NTESTS (sizeof(test_cases) / sizeof(test_cases[0])) int main(int argc, char *argv[]) { START(argc, argv, "rpmem_obc"); common_init("rpmem_fip", "RPMEM_LOG_LEVEL", "RPMEM_LOG_FILE", 0, 0); rpmemd_log_init("rpmemd", os_getenv("RPMEMD_LOG_FILE"), 0); rpmemd_log_level = rpmemd_log_level_from_str( os_getenv("RPMEMD_LOG_LEVEL")); rpmem_util_cmds_init(); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); rpmem_util_cmds_fini(); common_fini(); rpmemd_log_close(); DONE(NULL); }
10,054
22.770686
75
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmem_basic/rpmem_basic.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * rpmem_basic.c -- unit test for rpmem operations */ #include "unittest.h" #include "librpmem.h" #include "pool_hdr.h" #include "set.h" #include "util.h" #include "out.h" #include "rpmem_common.h" #include "rpmem_fip_common.h" /* * Use default terminal command for terminating session in user flags field * in order to make sure this is not interpreted by terminal. */ #define POOL_ATTR_INIT {\ .signature = "<RPMEM>",\ .major = 1,\ .compat_features = 2,\ .incompat_features = 2,\ .ro_compat_features = 4,\ .poolset_uuid = "POOLSET_UUID0123",\ .uuid = "UUID0123456789AB",\ .next_uuid = "NEXT_UUID0123456",\ .prev_uuid = "PREV_UUID0123456",\ .user_flags = "USER_FLAGS\0\0\0\n~.",\ } /* as above but with SINGLEHDR incompat feature */ #define POOL_ATTR_INIT_SINGLEHDR {\ .signature = "<RPMEM>",\ .major = 1,\ .compat_features = 2,\ .incompat_features = 3,\ .ro_compat_features = 4,\ .poolset_uuid = "POOLSET_UUID0123",\ .uuid = "UUID0123456789AB",\ .next_uuid = "NEXT_UUID0123456",\ .prev_uuid = "PREV_UUID0123456",\ .user_flags = "USER_FLAGS\0\0\0\n~.",\ } #define POOL_ATTR_ALT {\ .signature = "<ALT>",\ .major = 5,\ .compat_features = 6,\ .incompat_features = 2,\ .ro_compat_features = 8,\ .poolset_uuid = "UUID_POOLSET_ALT",\ .uuid = "ALT_UUIDCDEFFEDC",\ .next_uuid = "456UUID_NEXT_ALT",\ .prev_uuid = "UUID012_ALT_PREV",\ .user_flags = "\0\0\0\n~._ALT_FLAGS",\ } /* as above but with SINGLEHDR incompat feature */ #define POOL_ATTR_ALT_SINGLEHDR {\ .signature = "<ALT>",\ .major = 5,\ .compat_features = 6,\ .incompat_features = 3,\ .ro_compat_features = 8,\ .poolset_uuid = "UUID_POOLSET_ALT",\ .uuid = "ALT_UUIDCDEFFEDC",\ .next_uuid = "456UUID_NEXT_ALT",\ .prev_uuid = "UUID012_ALT_PREV",\ .user_flags = "\0\0\0\n~._ALT_FLAGS",\ } static const struct rpmem_pool_attr pool_attrs[] = { POOL_ATTR_INIT, POOL_ATTR_INIT_SINGLEHDR, POOL_ATTR_ALT, POOL_ATTR_ALT_SINGLEHDR }; static const char *pool_attr_names[] = { "init", "init_singlehdr", "alt", "alt_singlehdr" }; #define POOL_ATTR_INIT_INDEX 0 #define NLANES 32 struct pool_entry { RPMEMpool *rpp; const char *target; void *pool; size_t size; unsigned nlanes; int is_mem; int error_must_occur; int exp_errno; }; #define MAX_IDS 1024 static struct pool_entry pools[MAX_IDS]; /* * init_pool -- map local pool file or allocate memory region */ static void init_pool(struct pool_entry *pool, const char *target, const char *pool_path, const char *pool_size) { pool->target = target; pool->exp_errno = 0; pool->nlanes = NLANES; int ret = util_parse_size(pool_size, &pool->size); UT_ASSERTeq(ret, 0); int flags = PMEM_FILE_CREATE; if (pool->size) flags |= PMEM_FILE_EXCL; if (strncmp(pool_path, "mem", strlen("mem")) == 0) { pool->pool = PAGEALIGNMALLOC(pool->size); pool->is_mem = 1; } else { pool->pool = pmem_map_file(pool_path, pool->size, flags, 0666, &pool->size, NULL); UT_ASSERTne(pool->pool, NULL); /* * This is a workaround for an issue with using device dax with * libibverbs. The problem is that libfabric to handle fork() * function calls correctly use ibv_fork_init(3) which makes * all registered memory being madvised with MADV_DONTFORK flag. * In libpmemobj the remote replication is performed without * pool header (first 4k). In such case the address passed to * madvise(2) is aligned to 4k, but device dax can require * different alignment (default is 2MB). This workaround * madvises the entire memory region before registering * it by fi_mr_reg(3). * * The librpmem client requires fork() support to work * correctly. */ ret = os_madvise(pool->pool, pool->size, MADV_DONTFORK); UT_ASSERTeq(ret, 0); pool->is_mem = 0; os_unlink(pool_path); } } /* * free_pool -- unmap local pool file or free memory region */ static void free_pool(struct pool_entry *pool) { if (pool->is_mem) FREE(pool->pool); else UT_ASSERTeq(pmem_unmap(pool->pool, pool->size), 0); pool->pool = NULL; pool->rpp = NULL; pool->target = NULL; } /* * str_2_pool_attr_index -- convert string to the index of pool attributes */ static int str_2_pool_attr_index(const char *str) { COMPILE_ERROR_ON((sizeof(pool_attr_names) / sizeof(pool_attr_names[0])) != (sizeof(pool_attrs) / sizeof(pool_attrs[0]))); const unsigned num_of_names = sizeof(pool_attr_names) / sizeof(pool_attr_names[0]); for (int i = 0; i < num_of_names; ++i) { if (strcmp(str, pool_attr_names[i]) == 0) { return i; } } UT_FATAL("unrecognized name of pool attributes set: %s", str); } /* * cmp_pool_attr -- check pool attributes */ static void cmp_pool_attr(const struct rpmem_pool_attr *attr1, const struct rpmem_pool_attr *attr2) { if (attr2 == NULL) { UT_ASSERTeq(util_is_zeroed(attr1, sizeof(*attr1)), 1); } else { UT_ASSERTeq(memcmp(attr1->signature, attr2->signature, sizeof(attr1->signature)), 0); UT_ASSERTeq(attr1->major, attr2->major); UT_ASSERTeq(attr1->compat_features, attr2->compat_features); UT_ASSERTeq(attr1->ro_compat_features, attr2->ro_compat_features); UT_ASSERTeq(attr1->incompat_features, attr2->incompat_features); UT_ASSERTeq(memcmp(attr1->uuid, attr2->uuid, sizeof(attr1->uuid)), 0); UT_ASSERTeq(memcmp(attr1->poolset_uuid, attr2->poolset_uuid, sizeof(attr1->poolset_uuid)), 0); UT_ASSERTeq(memcmp(attr1->prev_uuid, attr2->prev_uuid, sizeof(attr1->prev_uuid)), 0); UT_ASSERTeq(memcmp(attr1->next_uuid, attr2->next_uuid, sizeof(attr1->next_uuid)), 0); } } /* * check_return_and_errno - validate return value and errno */ #define check_return_and_errno(ret, error_must_occur, exp_errno) \ if ((exp_errno) != 0) { \ if (error_must_occur) { \ UT_ASSERTne(ret, 0); \ UT_ASSERTeq(errno, exp_errno); \ } else { \ if ((ret) != 0) { \ UT_ASSERTeq(errno, exp_errno); \ } \ } \ } else { \ UT_ASSERTeq(ret, 0); \ } /* * test_create -- test case for creating remote pool * * The <option> argument values: * - "singlehdr" - the incompat feature flag is set to POOL_FEAT_SINGLEHDR, * - "noattr" - NULL pool attributes are passed to rpmem_create(), * - "none" or any other string - no options. */ static int test_create(const struct test_case *tc, int argc, char *argv[]) { if (argc < 6) UT_FATAL("usage: test_create <id> <pool set> " "<target> <pool> <size> <option>"); const char *id_str = argv[0]; const char *pool_set = argv[1]; const char *target = argv[2]; const char *pool_path = argv[3]; const char *size_str = argv[4]; const char *option = argv[5]; int id = atoi(id_str); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; UT_ASSERTeq(pool->rpp, NULL); struct rpmem_pool_attr *rattr = NULL; struct rpmem_pool_attr pool_attr = pool_attrs[POOL_ATTR_INIT_INDEX]; if (strcmp(option, "noattr") == 0) { /* pass NULL pool attributes */ } else { if (strcmp(option, "singlehdr") == 0) pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR; rattr = &pool_attr; } init_pool(pool, target, pool_path, size_str); pool->rpp = rpmem_create(target, pool_set, pool->pool, pool->size, &pool->nlanes, rattr); if (pool->rpp) { UT_ASSERTne(pool->nlanes, 0); UT_OUT("%s: created", pool_set); } else { UT_OUT("!%s", pool_set); free_pool(pool); } return 6; } /* * test_open -- test case for opening remote pool * * The <option> argument values: * - "singlehdr" - the incompat feature flag is set to POOL_FEAT_SINGLEHDR, * - "noattr" - NULL pool attributes are passed to rpmem_create(), * - "none" or any other string - no options. */ static int test_open(const struct test_case *tc, int argc, char *argv[]) { if (argc < 7) UT_FATAL("usage: test_open <id> <pool set> " "<target> <pool> <size> <pool attr name> " "<option>"); const char *id_str = argv[0]; const char *pool_set = argv[1]; const char *target = argv[2]; const char *pool_path = argv[3]; const char *size_str = argv[4]; const char *pool_attr_name = argv[5]; const char *option = argv[6]; int id = atoi(id_str); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; UT_ASSERTeq(pool->rpp, NULL); const struct rpmem_pool_attr *rattr = NULL; const int pool_attr_id = str_2_pool_attr_index(pool_attr_name); struct rpmem_pool_attr pool_attr = pool_attrs[pool_attr_id]; if (strcmp(option, "noattr") == 0) { /* pass NULL pool attributes */ } else { /* pass non-NULL pool attributes */ if (strcmp(option, "singlehdr") == 0) pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR; rattr = &pool_attr; } init_pool(pool, target, pool_path, size_str); struct rpmem_pool_attr pool_attr_open; pool->rpp = rpmem_open(target, pool_set, pool->pool, pool->size, &pool->nlanes, &pool_attr_open); if (pool->rpp) { cmp_pool_attr(&pool_attr_open, rattr); UT_ASSERTne(pool->nlanes, 0); UT_OUT("%s: opened", pool_set); } else { UT_OUT("!%s", pool_set); free_pool(pool); } return 7; } /* * test_close -- test case for closing remote pool */ static int test_close(const struct test_case *tc, int argc, char *argv[]) { if (argc < 1) UT_FATAL("usage: test_close <id>"); const char *id_str = argv[0]; int id = atoi(id_str); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; UT_ASSERTne(pool->rpp, NULL); int ret = rpmem_close(pool->rpp); check_return_and_errno(ret, pool->error_must_occur, pool->exp_errno); free_pool(pool); return 1; } typedef int (*flush_func)(RPMEMpool *rpp, size_t off, size_t size, unsigned lane); static int persist_relaxed(RPMEMpool *rpp, size_t off, size_t size, unsigned lane) { return rpmem_persist(rpp, off, size, lane, RPMEM_PERSIST_RELAXED); } static int persist_normal(RPMEMpool *rpp, size_t off, size_t size, unsigned lane) { return rpmem_persist(rpp, off, size, lane, 0); } /* * thread_arg -- persist worker thread arguments */ struct thread_arg { RPMEMpool *rpp; size_t off; size_t size; unsigned nops; unsigned lane; int error_must_occur; int exp_errno; flush_func flush; }; /* * thread_func -- worker thread function */ static void * thread_func(void *arg) { struct thread_arg *args = arg; size_t flush_size = args->size / args->nops; UT_ASSERTeq(args->size % args->nops, 0); for (unsigned i = 0; i < args->nops; i++) { size_t off = args->off + i * flush_size; size_t left = args->size - i * flush_size; size_t size = left < flush_size ? left : flush_size; int ret = args->flush(args->rpp, off, size, args->lane); check_return_and_errno(ret, args->error_must_occur, args->exp_errno); } return NULL; } static void test_flush(unsigned id, unsigned seed, unsigned nthreads, unsigned nops, flush_func func) { struct pool_entry *pool = &pools[id]; UT_ASSERTne(pool->nlanes, 0); nthreads = min(nthreads, pool->nlanes); size_t buff_size = pool->size - POOL_HDR_SIZE; if (seed) { srand(seed); uint8_t *buff = (uint8_t *)((uintptr_t)pool->pool + POOL_HDR_SIZE); for (size_t i = 0; i < buff_size; i++) buff[i] = rand(); } os_thread_t *threads = MALLOC(nthreads * sizeof(*threads)); struct thread_arg *args = MALLOC(nthreads * sizeof(*args)); size_t size_per_thread = buff_size / nthreads; UT_ASSERTeq(buff_size % nthreads, 0); for (unsigned i = 0; i < nthreads; i++) { args[i].rpp = pool->rpp; args[i].nops = nops; args[i].lane = (unsigned)i; args[i].off = POOL_HDR_SIZE + i * size_per_thread; args[i].flush = func; size_t size_left = buff_size - size_per_thread * i; args[i].size = size_left < size_per_thread ? size_left : size_per_thread; args[i].exp_errno = pool->exp_errno; args[i].error_must_occur = pool->error_must_occur; PTHREAD_CREATE(&threads[i], NULL, thread_func, &args[i]); } for (int i = 0; i < nthreads; i++) PTHREAD_JOIN(&threads[i], NULL); FREE(args); FREE(threads); } /* * test_persist -- test case for persist operation */ static int test_persist(const struct test_case *tc, int argc, char *argv[]) { if (argc < 4) UT_FATAL("usage: test_persist <id> <seed> <nthreads> " "<nops> <relaxed>"); unsigned id = ATOU(argv[0]); UT_ASSERT(id >= 0 && id < MAX_IDS); unsigned seed = ATOU(argv[1]); unsigned nthreads = ATOU(argv[2]); unsigned nops = ATOU(argv[3]); unsigned relaxed = ATOU(argv[4]); if (relaxed) test_flush(id, seed, nthreads, nops, persist_relaxed); else test_flush(id, seed, nthreads, nops, persist_normal); return 5; } /* * test_deep_persist -- test case for deep_persist operation */ static int test_deep_persist(const struct test_case *tc, int argc, char *argv[]) { if (argc < 4) UT_FATAL("usage: test_deep_persist <id> <seed> <nthreads> " "<nops>"); unsigned id = ATOU(argv[0]); UT_ASSERT(id >= 0 && id < MAX_IDS); unsigned seed = ATOU(argv[1]); unsigned nthreads = ATOU(argv[2]); unsigned nops = ATOU(argv[3]); test_flush(id, seed, nthreads, nops, rpmem_deep_persist); return 4; } /* * test_read -- test case for read operation */ static int test_read(const struct test_case *tc, int argc, char *argv[]) { if (argc < 2) UT_FATAL("usage: test_read <id> <seed>"); int id = atoi(argv[0]); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; srand(ATOU(argv[1])); int ret; uint8_t *buff = (uint8_t *)((uintptr_t)pool->pool + POOL_HDR_SIZE); size_t buff_size = pool->size - POOL_HDR_SIZE; ret = rpmem_read(pool->rpp, buff, POOL_HDR_SIZE, buff_size, 0); check_return_and_errno(ret, pool->error_must_occur, pool->exp_errno); if (ret == 0) { for (size_t i = 0; i < buff_size; i++) { uint8_t r = rand(); UT_ASSERTeq(buff[i], r); } } return 2; } /* * test_remove -- test case for remove operation */ static int test_remove(const struct test_case *tc, int argc, char *argv[]) { if (argc < 4) UT_FATAL("usage: test_remove <target> <pool set> " "<force> <rm pool set>"); const char *target = argv[0]; const char *pool_set = argv[1]; int force = atoi(argv[2]); int rm_pool_set = atoi(argv[3]); int flags = 0; if (force) flags |= RPMEM_REMOVE_FORCE; if (rm_pool_set) flags |= RPMEM_REMOVE_POOL_SET; int ret; ret = rpmem_remove(target, pool_set, flags); UT_ASSERTeq(ret, 0); return 4; } /* * test_set_attr -- test case for set attributes operation */ static int test_set_attr(const struct test_case *tc, int argc, char *argv[]) { if (argc < 3) UT_FATAL("usage: test_set_attr <id> <pool attr name> <option>"); const char *id_str = argv[0]; const char *pool_attr_name = argv[1]; const char *option = argv[2]; int id = atoi(id_str); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; UT_ASSERTne(pool->rpp, NULL); struct rpmem_pool_attr *rattr = NULL; const int pool_attr_id = str_2_pool_attr_index(pool_attr_name); struct rpmem_pool_attr pool_attr = pool_attrs[pool_attr_id]; if (strcmp(option, "noattr") == 0) { /* pass NULL pool attributes */ } else { /* pass non-NULL pool attributes */ if (strcmp(option, "singlehdr") == 0) pool_attr.incompat_features |= POOL_FEAT_SINGLEHDR; rattr = &pool_attr; } int ret = rpmem_set_attr(pool->rpp, rattr); if (ret) UT_OUT("set attributes failed (%s)", pool_attr_name); else UT_OUT("set attributes succeeded (%s)", pool_attr_name); return 3; } /* * check_pool -- check if remote pool contains specified random sequence */ static int check_pool(const struct test_case *tc, int argc, char *argv[]) { if (argc < 3) UT_FATAL("usage: fill_pool <pool set> <seed> <size>"); char *pool_set = argv[0]; srand(ATOU(argv[1])); int ret; size_t size; ret = util_parse_size(argv[2], &size); size -= POOL_HDR_SIZE; struct pool_set *set; ret = util_poolset_create_set(&set, pool_set, 0, 0, 0); UT_ASSERTeq(ret, 0); ret = util_pool_open_nocheck(set, 0); UT_ASSERTeq(ret, 0); uint8_t *data = set->replica[0]->part[0].addr; for (size_t i = 0; i < size; i++) { uint8_t r = rand(); UT_ASSERTeq(data[POOL_HDR_SIZE + i], r); } util_poolset_close(set, DO_NOT_DELETE_PARTS); return 3; } /* * fill_pool -- fill remote pool with specified random sequence */ static int fill_pool(const struct test_case *tc, int argc, char *argv[]) { if (argc < 2) UT_FATAL("usage: fill_pool <pool set> <seed>"); char *pool_set = argv[0]; srand(ATOU(argv[1])); int ret; struct pool_set *set; ret = util_poolset_create_set(&set, pool_set, 0, 0, 0); UT_ASSERTeq(ret, 0); ret = util_pool_open_nocheck(set, 0); UT_ASSERTeq(ret, 0); uint8_t *data = set->replica[0]->part[0].addr; for (size_t i = POOL_HDR_SIZE; i < set->poolsize; i++) data[i] = rand(); util_poolset_close(set, DO_NOT_DELETE_PARTS); return 2; } enum wait_type { WAIT, NOWAIT }; static const char *wait_type_str[2] = { "wait", "nowait" }; static enum wait_type str2wait(const char *str) { for (int i = 0; i < ARRAY_SIZE(wait_type_str); ++i) { if (strcmp(wait_type_str[i], str) == 0) return (enum wait_type)i; } UT_FATAL("'%s' does not match <wait|nowait>", str); } #define SSH_EXE "ssh" #define RPMEMD_TERMINATE_CMD SSH_EXE " -tt %s kill -9 %d" #define GET_RPMEMD_PID_CMD SSH_EXE " %s cat %s" #define COUNT_RPMEMD_CMD SSH_EXE " %s ps -A | grep -c %d" /* * rpmemd_kill -- kill target rpmemd */ static int rpmemd_kill(const char *target, int pid) { char cmd[100]; snprintf(cmd, sizeof(cmd), RPMEMD_TERMINATE_CMD, target, pid); return system(cmd); } /* * popen_readi -- popen cmd and read integer */ static int popen_readi(const char *cmd) { FILE *stream = popen(cmd, "r"); UT_ASSERT(stream != NULL); int i; int ret = fscanf(stream, "%d", &i); UT_ASSERT(ret == 1); pclose(stream); return i; } /* * rpmemd_get_pid -- get target rpmemd pid */ static int rpmemd_get_pid(const char *target, const char *pid_file) { char cmd[PATH_MAX]; snprintf(cmd, sizeof(cmd), GET_RPMEMD_PID_CMD, target, pid_file); return popen_readi(cmd); } /* * rpmemd_is_running -- tell if target rpmemd is running */ static int rpmemd_is_running(const char *target, int pid) { char cmd[100]; snprintf(cmd, sizeof(cmd), COUNT_RPMEMD_CMD, target, pid); return popen_readi(cmd) > 0; } /* * rpmemd_kill_wait -- kill target rpmemd and wait for it to stop */ static void rpmemd_kill_wait(const char *target, const char *pid_file, enum wait_type wait) { int pid = rpmemd_get_pid(target, pid_file); int ret; do { ret = rpmemd_kill(target, pid); if (ret != 0 || wait == NOWAIT) { break; } } while (rpmemd_is_running(target, pid)); } /* * rpmemd_terminate -- terminate target rpmemd */ static int rpmemd_terminate(const struct test_case *tc, int argc, char *argv[]) { if (argc < 3) { UT_FATAL("usage: rpmemd_terminate <id> <pid file> " "<wait|nowait>"); } const char *id_str = argv[0]; const char *pid_file = argv[1]; const char *wait_str = argv[2]; int id = atoi(id_str); UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; UT_ASSERTne(pool->target, NULL); pool->exp_errno = ECONNRESET; enum wait_type wait = str2wait(wait_str); /* * if process will wait for rpmemd to terminate it is sure error will * occur */ pool->error_must_occur = wait == WAIT; rpmemd_kill_wait(pool->target, pid_file, wait); return 3; } /* * test_persist_header -- test case for persisting data with offset < 4096 * * if 'hdr' argument is used, test passes if rpmem_persist fails * if 'nohdr' argument is used, test passes if rpmem_persist passes */ static int test_persist_header(const struct test_case *tc, int argc, char *argv[]) { if (argc < 2) UT_FATAL("usage: test_persist_header <id> " "<hdr|nohdr> <relaxed>"); int id = atoi(argv[0]); const char *hdr_str = argv[1]; int relaxed = atoi(argv[2]); unsigned flags = 0; if (relaxed) flags |= RPMEM_PERSIST_RELAXED; UT_ASSERT(id >= 0 && id < MAX_IDS); struct pool_entry *pool = &pools[id]; int with_hdr; if (strcmp(hdr_str, "hdr") == 0) with_hdr = 1; else if (strcmp(hdr_str, "nohdr") == 0) with_hdr = 0; else UT_ASSERT(0); for (size_t off = 0; off < POOL_HDR_SIZE; off += 8) { int ret = rpmem_persist(pool->rpp, off, 8, 0, flags); UT_ASSERTeq(ret, with_hdr ? -1 : 0); } return 3; } /* * test_cases -- available test cases */ static struct test_case test_cases[] = { TEST_CASE(test_create), TEST_CASE(test_open), TEST_CASE(test_set_attr), TEST_CASE(test_close), TEST_CASE(test_persist), TEST_CASE(test_deep_persist), TEST_CASE(test_read), TEST_CASE(test_remove), TEST_CASE(check_pool), TEST_CASE(fill_pool), TEST_CASE(rpmemd_terminate), TEST_CASE(test_persist_header), }; #define NTESTS (sizeof(test_cases) / sizeof(test_cases[0])) int main(int argc, char *argv[]) { util_init(); rpmem_fip_probe_get("localhost", NULL); START(argc, argv, "rpmem_basic"); out_init("rpmem_basic", "TEST_LOG_LEVEL", "TEST_LOG_FILE", 0, 0); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); out_fini(); DONE(NULL); }
22,499
23.377031
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_realloc_inplace/vmem_realloc_inplace.c
/* * Copyright 2014-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * vmem_realloc_inplace -- unit test for vmem_realloc * * usage: vmem_realloc_inplace [directory] */ #include "unittest.h" #define POOL_SIZE (16 * 1024 * 1024) int main(int argc, char *argv[]) { char *dir = NULL; void *mem_pool = NULL; VMEM *vmp; START(argc, argv, "vmem_realloc_inplace"); if (argc == 2) { dir = argv[1]; } else if (argc > 2) { UT_FATAL("usage: %s [directory]", argv[0]); } if (dir == NULL) { /* allocate memory for function vmem_create_in_region() */ mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20); vmp = vmem_create_in_region(mem_pool, POOL_SIZE); if (vmp == NULL) UT_FATAL("!vmem_create_in_region"); } else { vmp = vmem_create(dir, POOL_SIZE); if (vmp == NULL) UT_FATAL("!vmem_create"); } int *test1 = vmem_malloc(vmp, 12 * 1024 * 1024); UT_ASSERTne(test1, NULL); int *test1r = vmem_realloc(vmp, test1, 6 * 1024 * 1024); UT_ASSERTeq(test1r, test1); test1r = vmem_realloc(vmp, test1, 12 * 1024 * 1024); UT_ASSERTeq(test1r, test1); test1r = vmem_realloc(vmp, test1, 8 * 1024 * 1024); UT_ASSERTeq(test1r, test1); int *test2 = vmem_malloc(vmp, 4 * 1024 * 1024); UT_ASSERTne(test2, NULL); /* 4MB => 16B */ int *test2r = vmem_realloc(vmp, test2, 16); UT_ASSERTeq(test2r, NULL); /* ... but the usable size is still 4MB. */ UT_ASSERTeq(vmem_malloc_usable_size(vmp, test2), 4 * 1024 * 1024); /* 8MB => 16B */ test1r = vmem_realloc(vmp, test1, 16); /* * If the old size of the allocation is larger than * the chunk size (4MB), we can reallocate it to 4MB first (in place), * releasing some space, which makes it possible to do the actual * shrinking... */ UT_ASSERTne(test1r, NULL); UT_ASSERTne(test1r, test1); UT_ASSERTeq(vmem_malloc_usable_size(vmp, test1r), 16); /* ... and leaves some memory for new allocations. */ int *test3 = vmem_malloc(vmp, 3 * 1024 * 1024); UT_ASSERTne(test3, NULL); vmem_free(vmp, test1r); vmem_free(vmp, test2r); vmem_free(vmp, test3); vmem_delete(vmp); DONE(NULL); }
3,606
30.094828
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_rm/libpmempool_rm.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. */ /* * libpmempool_rm -- a unittest for pmempool_rm. * */ #include <stddef.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <getopt.h> #include "unittest.h" #define FATAL_USAGE(n) UT_FATAL("usage: %s [-f -l -r] path..", (n)) static PMEMobjpool *Pop; int main(int argc, char *argv[]) { START(argc, argv, "libpmempool_rm"); if (argc < 2) FATAL_USAGE(argv[0]); unsigned flags = 0; char *optstr = "flro"; int do_open = 0; int opt; while ((opt = getopt(argc, argv, optstr)) != -1) { switch (opt) { case 'f': flags |= PMEMPOOL_RM_FORCE; break; case 'r': flags |= PMEMPOOL_RM_POOLSET_REMOTE; break; case 'l': flags |= PMEMPOOL_RM_POOLSET_LOCAL; break; case 'o': do_open = 1; break; default: FATAL_USAGE(argv[0]); } } for (int i = optind; i < argc; i++) { const char *path = argv[i]; if (do_open) { Pop = pmemobj_open(path, NULL); UT_ASSERTne(Pop, NULL); } int ret = pmempool_rm(path, flags); if (ret) { UT_OUT("!%s: %s", path, pmempool_errormsg()); } if (do_open) { UT_ASSERTne(Pop, NULL); pmemobj_close(Pop); } } DONE(NULL); }
2,741
26.42
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_zones/obj_zones.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_zones.c -- allocates from a very large pool (exceeding 1 zone) * */ #include <stddef.h> #include "unittest.h" #define LAYOUT_NAME "obj_zones" #define ALLOC_SIZE ((8191 * (256 * 1024)) - 16) /* must evenly divide a zone */ /* * test_create -- allocate all possible objects and log the number. It should * exceed what would be possible on a single zone. * Additionally, free one object so that we can later check that it can be * allocated after the next open. */ static void test_create(const char *path) { PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, LAYOUT_NAME, 0, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); PMEMoid oid; int n = 0; while (1) { if (pmemobj_alloc(pop, &oid, ALLOC_SIZE, 0, NULL, NULL) != 0) break; n++; } UT_OUT("allocated: %d", n); pmemobj_free(&oid); pmemobj_close(pop); } /* * test_open -- in the open test we should be able to allocate exactly * one object. */ static void test_open(const char *path) { PMEMobjpool *pop; if ((pop = pmemobj_open(path, LAYOUT_NAME)) == NULL) UT_FATAL("!pmemobj_open: %s", path); int ret = pmemobj_alloc(pop, NULL, ALLOC_SIZE, 0, NULL, NULL); UT_ASSERTeq(ret, 0); ret = pmemobj_alloc(pop, NULL, ALLOC_SIZE, 0, NULL, NULL); UT_ASSERTne(ret, 0); pmemobj_close(pop); } int main(int argc, char *argv[]) { START(argc, argv, "obj_zones"); if (argc != 3) UT_FATAL("usage: %s file-name [open|create]", argv[0]); const char *path = argv[1]; char op = argv[2][0]; if (op == 'c') test_create(path); else if (op == 'o') test_open(path); else UT_FATAL("invalid operation"); DONE(NULL); }
3,249
27.508772
79
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_is_poolset/util_is_poolset.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_poolset.c -- unit test for util_is_poolset * * usage: util_is_poolset file */ #include "unittest.h" #include "set.h" #include "pmemcommon.h" #include <errno.h> #define LOG_PREFIX "ut" #define LOG_LEVEL_VAR "TEST_LOG_LEVEL" #define LOG_FILE_VAR "TEST_LOG_FILE" #define MAJOR_VERSION 1 #define MINOR_VERSION 0 int main(int argc, char *argv[]) { START(argc, argv, "util_is_poolset"); common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR, MAJOR_VERSION, MINOR_VERSION); if (argc < 2) UT_FATAL("usage: %s file...", argv[0]); for (int i = 1; i < argc; i++) { char *fname = argv[i]; int is_poolset = util_is_poolset_file(fname); UT_OUT("util_is_poolset(%s): %d", fname, is_poolset); } common_fini(); DONE(NULL); }
2,349
31.638889
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_config/obj_ctl_config.c
/* * Copyright 2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_ctl_config.c -- tests for ctl configuration */ #include "unittest.h" #include "out.h" #define LAYOUT "obj_ctl_config" int main(int argc, char *argv[]) { START(argc, argv, "obj_ctl_config"); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; PMEMobjpool *pop = pmemobj_open(path, LAYOUT); if (pop == NULL) UT_FATAL("!pmemobj_open: %s", path); /* dump all available ctl read entry points */ int result; pmemobj_ctl_get(pop, "prefault.at_open", &result); UT_OUT("%d", result); pmemobj_ctl_get(pop, "prefault.at_create", &result); UT_OUT("%d", result); pmemobj_close(pop); DONE(NULL); }
2,250
33.106061
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_locks_abort/obj_tx_locks_abort.c
/* * Copyright 2015-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * obj_tx_locks_nested.c -- unit test for transaction locks */ #include "unittest.h" #define LAYOUT_NAME "locks" TOID_DECLARE_ROOT(struct root_obj); TOID_DECLARE(struct obj, 1); struct root_obj { PMEMmutex lock; TOID(struct obj) head; }; struct obj { int data; PMEMmutex lock; TOID(struct obj) next; }; /* * do_nested_tx-- (internal) nested transaction */ static void do_nested_tx(PMEMobjpool *pop, TOID(struct obj) o, int value) { TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(o)->lock, TX_PARAM_NONE) { TX_ADD(o); D_RW(o)->data = value; if (!TOID_IS_NULL(D_RO(o)->next)) { /* * Add the object to undo log, while the mutex * it contains is not locked. */ TX_ADD(D_RO(o)->next); do_nested_tx(pop, D_RO(o)->next, value); } } TX_END; } /* * do_aborted_nested_tx -- (internal) aborted nested transaction */ static void do_aborted_nested_tx(PMEMobjpool *pop, TOID(struct obj) oid, int value) { TOID(struct obj) o = oid; TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(o)->lock, TX_PARAM_NONE) { TX_ADD(o); D_RW(o)->data = value; if (!TOID_IS_NULL(D_RO(o)->next)) { /* * Add the object to undo log, while the mutex * it contains is not locked. */ TX_ADD(D_RO(o)->next); do_nested_tx(pop, D_RO(o)->next, value); } pmemobj_tx_abort(EINVAL); } TX_FINALLY { o = oid; while (!TOID_IS_NULL(o)) { if (pmemobj_mutex_trylock(pop, &D_RW(o)->lock)) { UT_OUT("trylock failed"); } else { UT_OUT("trylock succeeded"); pmemobj_mutex_unlock(pop, &D_RW(o)->lock); } o = D_RO(o)->next; } } TX_END; } /* * do_check -- (internal) print 'data' value of each object on the list */ static void do_check(TOID(struct obj) o) { while (!TOID_IS_NULL(o)) { UT_OUT("data = %d", D_RO(o)->data); o = D_RO(o)->next; } } int main(int argc, char *argv[]) { PMEMobjpool *pop; START(argc, argv, "obj_tx_locks_abort"); if (argc > 3) UT_FATAL("usage: %s <file>", argv[0]); pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL * 4, S_IWUSR | S_IRUSR); if (pop == NULL) UT_FATAL("!pmemobj_create"); TOID(struct root_obj) root = POBJ_ROOT(pop, struct root_obj); TX_BEGIN_PARAM(pop, TX_PARAM_MUTEX, &D_RW(root)->lock) { TX_ADD(root); D_RW(root)->head = TX_ZNEW(struct obj); TOID(struct obj) o; o = D_RW(root)->head; D_RW(o)->data = 100; pmemobj_mutex_zero(pop, &D_RW(o)->lock); for (int i = 0; i < 3; i++) { D_RW(o)->next = TX_ZNEW(struct obj); o = D_RO(o)->next; D_RW(o)->data = 101 + i; pmemobj_mutex_zero(pop, &D_RW(o)->lock); } TOID_ASSIGN(D_RW(o)->next, OID_NULL); } TX_END; UT_OUT("initial state"); do_check(D_RO(root)->head); UT_OUT("nested tx"); do_nested_tx(pop, D_RW(root)->head, 200); do_check(D_RO(root)->head); UT_OUT("aborted nested tx"); do_aborted_nested_tx(pop, D_RW(root)->head, 300); do_check(D_RO(root)->head); pmemobj_close(pop); DONE(NULL); }
4,509
25.686391
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_sync_win/libpmempool_sync_win.c
/* * Copyright 2016-2018, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * libpmempool_sync_win -- a unittest for libpmempool sync. * */ #include <stddef.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include "unittest.h" int wmain(int argc, wchar_t *argv[]) { STARTW(argc, argv, "libpmempool_sync_win"); if (argc != 3) UT_FATAL("usage: %s poolset_file flags", ut_toUTF8(argv[0])); int ret = pmempool_syncW(argv[1], (unsigned)wcstoul(argv[2], NULL, 0)); if (ret) UT_OUT("result: %d, errno: %d", ret, errno); else UT_OUT("result: 0"); DONEW(NULL); }
2,117
34.3
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_cuckoo/obj_cuckoo.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_cuckoo.c -- unit test for cuckoo hash table */ #include <errno.h> #include "unittest.h" #include "cuckoo.h" #include "util.h" #include "libpmemobj.h" #define TEST_INSERTS 100 #define TEST_VAL(x) ((void *)((uintptr_t)(x))) static int Rcounter_malloc; static void * __wrap_malloc(size_t size) { switch (util_fetch_and_add32(&Rcounter_malloc, 1)) { case 1: /* internal out_err malloc */ default: return malloc(size); case 2: /* tab malloc */ case 0: /* cuckoo malloc */ return NULL; } } static void test_cuckoo_new_delete(void) { struct cuckoo *c = NULL; /* cuckoo malloc fail */ c = cuckoo_new(); UT_ASSERT(c == NULL); /* tab malloc fail */ c = cuckoo_new(); UT_ASSERT(c == NULL); /* all ok */ c = cuckoo_new(); UT_ASSERT(c != NULL); cuckoo_delete(c); } static void test_insert_get_remove(void) { struct cuckoo *c = cuckoo_new(); UT_ASSERT(c != NULL); for (unsigned i = 0; i < TEST_INSERTS; ++i) UT_ASSERT(cuckoo_insert(c, i, TEST_VAL(i)) == 0); for (unsigned i = 0; i < TEST_INSERTS; ++i) UT_ASSERT(cuckoo_get(c, i) == TEST_VAL(i)); for (unsigned i = 0; i < TEST_INSERTS; ++i) UT_ASSERT(cuckoo_remove(c, i) == TEST_VAL(i)); for (unsigned i = 0; i < TEST_INSERTS; ++i) UT_ASSERT(cuckoo_remove(c, i) == NULL); for (unsigned i = 0; i < TEST_INSERTS; ++i) UT_ASSERT(cuckoo_get(c, i) == NULL); cuckoo_delete(c); } /* * rand64 -- (internal) 64-bit random function of doubtful quality, but good * enough for the test. */ static uint64_t rand64(void) { return (((uint64_t)rand()) << 32) | (unsigned)rand(); } #define NVALUES (100000) #define TEST_VALUE ((void *)0x1) #define INITIAL_SEED 54321 /* * test_load_factor -- calculates the average load factor of the hash table * when inserting <0, 1M> elements in random order. * * The factor itself isn't really that important because the implementation * is optimized for lookup speed, but it should be reasonable. */ static void test_load_factor(void) { struct cuckoo *c = cuckoo_new(); UT_ASSERT(c != NULL); /* * The seed is intentionally constant so that the test result is * consistent (at least on the same platform). */ srand(INITIAL_SEED); float avg_load = 0.f; int inserted = 0; for (int i = 0; ; ++i) { if (cuckoo_insert(c, rand64() % NVALUES, TEST_VALUE) == 0) { inserted++; avg_load += (float)inserted / cuckoo_get_size(c); if (inserted == NVALUES) break; } } avg_load /= inserted; UT_ASSERT(avg_load >= 0.4f); cuckoo_delete(c); } int main(int argc, char *argv[]) { START(argc, argv, "obj_cuckoo"); Malloc = __wrap_malloc; test_cuckoo_new_delete(); test_insert_get_remove(); test_load_factor(); DONE(NULL); }
4,294
24.414201
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_alloc_class/obj_ctl_alloc_class.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_ctl_alloc_class.c -- tests for the ctl entry points: heap.alloc_class */ #include <sys/resource.h> #include "unittest.h" #define LAYOUT "obj_ctl_alloc_class" static void basic(const char *path) { PMEMobjpool *pop; if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL * 20, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); int ret; PMEMoid oid; size_t usable_size; struct pobj_alloc_class_desc alloc_class_128; alloc_class_128.header_type = POBJ_HEADER_NONE; alloc_class_128.unit_size = 128; alloc_class_128.units_per_block = 1000; alloc_class_128.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.128.desc", &alloc_class_128); UT_ASSERTeq(ret, 0); struct pobj_alloc_class_desc alloc_class_129; alloc_class_129.header_type = POBJ_HEADER_COMPACT; alloc_class_129.unit_size = 1024; alloc_class_129.units_per_block = 1000; alloc_class_129.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.129.desc", &alloc_class_129); UT_ASSERTeq(ret, 0); struct pobj_alloc_class_desc alloc_class_128_r; ret = pmemobj_ctl_get(pop, "heap.alloc_class.128.desc", &alloc_class_128_r); UT_ASSERTeq(ret, 0); UT_ASSERTeq(alloc_class_128.header_type, alloc_class_128_r.header_type); UT_ASSERTeq(alloc_class_128.unit_size, alloc_class_128_r.unit_size); UT_ASSERT(alloc_class_128.units_per_block <= alloc_class_128_r.units_per_block); /* * One unit from alloc class 128 - 128 bytes unit size, minimal headers. */ ret = pmemobj_xalloc(pop, &oid, 128, 0, POBJ_CLASS_ID(128), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, 128); pmemobj_free(&oid); /* * Reserve as above. */ struct pobj_action act; oid = pmemobj_xreserve(pop, &act, 128, 0, POBJ_CLASS_ID(128)); UT_ASSERT(!OID_IS_NULL(oid)); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, 128); pmemobj_cancel(pop, &act, 1); /* * One unit from alloc class 128 - 128 bytes unit size, minimal headers, * but request size 1 byte. */ ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(128), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, 128); pmemobj_free(&oid); /* * Two units from alloc class 129 - * 1024 bytes unit size, compact headers. */ ret = pmemobj_xalloc(pop, &oid, 1024 + 1, 0, POBJ_CLASS_ID(129), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, (1024 * 2) - 16); /* 2 units minus hdr */ pmemobj_free(&oid); /* * 64 units from alloc class 129 * - 1024 bytes unit size, compact headers. */ ret = pmemobj_xalloc(pop, &oid, (1024 * 64) - 16, 0, POBJ_CLASS_ID(129), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, (1024 * 64) - 16); pmemobj_free(&oid); /* * 65 units from alloc class 129 - * 1024 bytes unit size, compact headers. * Should fail, as it would require two bitmap modifications. */ ret = pmemobj_xalloc(pop, &oid, 1024 * 64 + 1, 0, POBJ_CLASS_ID(129), NULL, NULL); UT_ASSERTeq(ret, -1); /* * Nonexistent alloc class. */ ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(130), NULL, NULL); UT_ASSERTeq(ret, -1); struct pobj_alloc_class_desc alloc_class_new; alloc_class_new.header_type = POBJ_HEADER_NONE; alloc_class_new.unit_size = 777; alloc_class_new.units_per_block = 200; alloc_class_new.class_id = 0; alloc_class_new.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_new); UT_ASSERTeq(ret, 0); struct pobj_alloc_class_desc alloc_class_fail; alloc_class_fail.header_type = POBJ_HEADER_NONE; alloc_class_fail.unit_size = 777; alloc_class_fail.units_per_block = 200; alloc_class_fail.class_id = 0; alloc_class_fail.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_fail); UT_ASSERTeq(ret, -1); ret = pmemobj_ctl_set(pop, "heap.alloc_class.200.desc", &alloc_class_fail); UT_ASSERTeq(ret, -1); ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(alloc_class_new.class_id), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, 777); struct pobj_alloc_class_desc alloc_class_new_huge; alloc_class_new_huge.header_type = POBJ_HEADER_NONE; alloc_class_new_huge.unit_size = (2 << 23); alloc_class_new_huge.units_per_block = 1; alloc_class_new_huge.class_id = 0; alloc_class_new_huge.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_new_huge); UT_ASSERTeq(ret, 0); ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(alloc_class_new_huge.class_id), NULL, NULL); UT_ASSERTeq(ret, 0); usable_size = pmemobj_alloc_usable_size(oid); UT_ASSERTeq(usable_size, (2 << 23)); struct pobj_alloc_class_desc alloc_class_new_max; alloc_class_new_max.header_type = POBJ_HEADER_COMPACT; alloc_class_new_max.unit_size = PMEMOBJ_MAX_ALLOC_SIZE; alloc_class_new_max.units_per_block = 1024; alloc_class_new_max.class_id = 0; alloc_class_new_max.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_new_max); UT_ASSERTeq(ret, 0); ret = pmemobj_xalloc(pop, &oid, 1, 0, POBJ_CLASS_ID(alloc_class_new_max.class_id), NULL, NULL); UT_ASSERTne(ret, 0); struct pobj_alloc_class_desc alloc_class_new_loop; alloc_class_new_loop.header_type = POBJ_HEADER_COMPACT; alloc_class_new_loop.unit_size = 16384; alloc_class_new_loop.units_per_block = 63; alloc_class_new_loop.class_id = 0; alloc_class_new_loop.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_new_loop); UT_ASSERTeq(ret, 0); size_t s = (63 * 16384) - 16; ret = pmemobj_xalloc(pop, &oid, s + 1, 0, POBJ_CLASS_ID(alloc_class_new_loop.class_id), NULL, NULL); UT_ASSERTne(ret, 0); struct pobj_alloc_class_desc alloc_class_tiny; alloc_class_tiny.header_type = POBJ_HEADER_NONE; alloc_class_tiny.unit_size = 7; alloc_class_tiny.units_per_block = 1000; alloc_class_tiny.class_id = 0; alloc_class_tiny.alignment = 0; ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_tiny); UT_ASSERTeq(ret, 0); for (int i = 0; i < 1000; ++i) { ret = pmemobj_xalloc(pop, &oid, 7, 0, POBJ_CLASS_ID(alloc_class_tiny.class_id), NULL, NULL); UT_ASSERTeq(ret, 0); } pmemobj_close(pop); } static void many(const char *path) { PMEMobjpool *pop; if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); unsigned nunits = UINT16_MAX + 1; struct pobj_alloc_class_desc alloc_class_tiny; alloc_class_tiny.header_type = POBJ_HEADER_NONE; alloc_class_tiny.unit_size = 8; alloc_class_tiny.units_per_block = nunits; alloc_class_tiny.class_id = 0; alloc_class_tiny.alignment = 0; int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &alloc_class_tiny); UT_ASSERTeq(ret, 0); PMEMoid oid; uint64_t *counterp = NULL; for (size_t i = 0; i < nunits; ++i) { pmemobj_xalloc(pop, &oid, 8, 0, POBJ_CLASS_ID(alloc_class_tiny.class_id), NULL, NULL); counterp = pmemobj_direct(oid); (*counterp)++; /* * This works only because this is a fresh pool in a new file * and so the counter must be initially zero. * This might have to be fixed if that ever changes. */ UT_ASSERTeq(*counterp, 1); } pmemobj_close(pop); } int main(int argc, char *argv[]) { START(argc, argv, "obj_ctl_alloc_class"); if (argc != 3) UT_FATAL("usage: %s file-name b|m", argv[0]); const char *path = argv[1]; if (argv[2][0] == 'b') basic(path); else if (argv[2][0] == 'm') many(path); DONE(NULL); }
9,325
29.083871
76
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/traces_pmem/traces_pmem.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_pmem.c -- unit test traces for libraries pmem */ #include "unittest.h" int main(int argc, char *argv[]) { START(argc, argv, "traces_pmem"); UT_ASSERT(!pmem_check_version(PMEM_MAJOR_VERSION, PMEM_MINOR_VERSION)); UT_ASSERT(!pmemblk_check_version(PMEMBLK_MAJOR_VERSION, PMEMBLK_MINOR_VERSION)); UT_ASSERT(!pmemlog_check_version(PMEMLOG_MAJOR_VERSION, PMEMLOG_MINOR_VERSION)); UT_ASSERT(!pmemobj_check_version(PMEMOBJ_MAJOR_VERSION, PMEMOBJ_MINOR_VERSION)); UT_ASSERT(!pmemcto_check_version(PMEMCTO_MAJOR_VERSION, PMEMCTO_MINOR_VERSION)); DONE(NULL); }
2,197
37.561404
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_debug/obj_debug.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_debug.c -- unit test for debug features * * usage: obj_debug file operation [op_index]:... * * operations are 'f' or 'l' or 'r' or 'a' or 'n' or 's' * */ #include <stddef.h> #include <stdlib.h> #include <sys/param.h> #include "unittest.h" #include "libpmemobj.h" #define LAYOUT_NAME "layout_obj_debug" TOID_DECLARE_ROOT(struct root); TOID_DECLARE(struct tobj, 0); TOID_DECLARE(struct int3_s, 1); struct root { POBJ_LIST_HEAD(listhead, struct tobj) lhead, lhead2; uint32_t val; }; struct tobj { POBJ_LIST_ENTRY(struct tobj) next; }; struct int3_s { uint32_t i1; uint32_t i2; uint32_t i3; }; typedef void (*func)(PMEMobjpool *pop, void *sync, void *cond); static void test_FOREACH(const char *path) { PMEMobjpool *pop = NULL; PMEMoid varoid, nvaroid; TOID(struct root) root; TOID(struct tobj) var, nvar; #define COMMANDS_FOREACH()\ do {\ POBJ_FOREACH(pop, varoid) {}\ POBJ_FOREACH_SAFE(pop, varoid, nvaroid) {}\ POBJ_FOREACH_TYPE(pop, var) {}\ POBJ_FOREACH_SAFE_TYPE(pop, var, nvar) {}\ POBJ_LIST_FOREACH(var, &D_RW(root)->lhead, next) {}\ POBJ_LIST_FOREACH_REVERSE(var, &D_RW(root)->lhead, next) {}\ } while (0) if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); TOID_ASSIGN(root, pmemobj_root(pop, sizeof(struct root))); POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->lhead, next, sizeof(struct tobj), NULL, NULL); COMMANDS_FOREACH(); TX_BEGIN(pop) { COMMANDS_FOREACH(); } TX_ONABORT { UT_ASSERT(0); } TX_END COMMANDS_FOREACH(); pmemobj_close(pop); } static void test_lists(const char *path) { PMEMobjpool *pop = NULL; TOID(struct root) root; TOID(struct tobj) elm; #define COMMANDS_LISTS()\ do {\ POBJ_LIST_INSERT_NEW_HEAD(pop, &D_RW(root)->lhead, next,\ sizeof(struct tobj), NULL, NULL);\ POBJ_NEW(pop, &elm, struct tobj, NULL, NULL);\ POBJ_LIST_INSERT_AFTER(pop, &D_RW(root)->lhead,\ POBJ_LIST_FIRST(&D_RW(root)->lhead), elm, next);\ POBJ_LIST_MOVE_ELEMENT_HEAD(pop, &D_RW(root)->lhead,\ &D_RW(root)->lhead2, elm, next, next);\ POBJ_LIST_REMOVE(pop, &D_RW(root)->lhead2, elm, next);\ POBJ_FREE(&elm);\ } while (0) if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); TOID_ASSIGN(root, pmemobj_root(pop, sizeof(struct root))); COMMANDS_LISTS(); TX_BEGIN(pop) { COMMANDS_LISTS(); } TX_ONABORT { UT_ASSERT(0); } TX_END COMMANDS_LISTS(); pmemobj_close(pop); } static int int3_constructor(PMEMobjpool *pop, void *ptr, void *arg) { struct int3_s *args = (struct int3_s *)arg; struct int3_s *val = (struct int3_s *)ptr; val->i1 = args->i1; val->i2 = args->i2; val->i3 = args->i3; pmemobj_persist(pop, val, sizeof(*val)); return 0; } static void test_alloc_construct(const char *path) { PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); TX_BEGIN(pop) { struct int3_s args = { 1, 2, 3 }; PMEMoid allocation; pmemobj_alloc(pop, &allocation, sizeof(allocation), 1, int3_constructor, &args); } TX_ONABORT { UT_ASSERT(0); } TX_END pmemobj_close(pop); } static void test_double_free(const char *path) { PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); PMEMoid oid, oid2; int err = pmemobj_zalloc(pop, &oid, 100, 0); UT_ASSERTeq(err, 0); UT_ASSERT(!OID_IS_NULL(oid)); oid2 = oid; pmemobj_free(&oid); pmemobj_free(&oid2); } static int test_constr(PMEMobjpool *pop, void *ptr, void *arg) { PMEMoid oid; pmemobj_alloc(pop, &oid, 1, 1, test_constr, NULL); return 0; } static void test_alloc_in_constructor(const char *path) { PMEMobjpool *pop = NULL; if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); PMEMoid oid; pmemobj_alloc(pop, &oid, 1, 1, test_constr, NULL); } static void test_mutex_lock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_mutex_lock(pop, (PMEMmutex *)sync); } static void test_mutex_unlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_mutex_unlock(pop, (PMEMmutex *)sync); } static void test_mutex_trylock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_mutex_trylock(pop, (PMEMmutex *)sync); } static void test_mutex_timedlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_mutex_timedlock(pop, (PMEMmutex *)sync, NULL); } static void test_mutex_zero(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_mutex_zero(pop, (PMEMmutex *)sync); } static void test_rwlock_rdlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_rdlock(pop, (PMEMrwlock *)sync); } static void test_rwlock_wrlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_wrlock(pop, (PMEMrwlock *)sync); } static void test_rwlock_timedrdlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_timedrdlock(pop, (PMEMrwlock *)sync, NULL); } static void test_rwlock_timedwrlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_timedwrlock(pop, (PMEMrwlock *)sync, NULL); } static void test_rwlock_tryrdlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_tryrdlock(pop, (PMEMrwlock *)sync); } static void test_rwlock_trywrlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_trywrlock(pop, (PMEMrwlock *)sync); } static void test_rwlock_unlock(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_unlock(pop, (PMEMrwlock *)sync); } static void test_rwlock_zero(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_rwlock_zero(pop, (PMEMrwlock *)sync); } static void test_cond_wait(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_cond_wait(pop, (PMEMcond *)cond, (PMEMmutex *)sync); } static void test_cond_signal(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_cond_signal(pop, (PMEMcond *)cond); } static void test_cond_broadcast(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_cond_broadcast(pop, (PMEMcond *)cond); } static void test_cond_timedwait(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_cond_timedwait(pop, (PMEMcond *)cond, (PMEMmutex *)sync, NULL); } static void test_cond_zero(PMEMobjpool *pop, void *sync, void *cond) { pmemobj_cond_zero(pop, (PMEMcond *)cond); } static void test_sync_pop_check(unsigned long op_index) { PMEMobjpool *pop = (PMEMobjpool *)(uintptr_t)0x1; func to_test[] = { test_mutex_lock, test_mutex_unlock, test_mutex_trylock, test_mutex_timedlock, test_mutex_zero, test_rwlock_rdlock, test_rwlock_wrlock, test_rwlock_timedrdlock, test_rwlock_timedwrlock, test_rwlock_tryrdlock, test_rwlock_trywrlock, test_rwlock_unlock, test_rwlock_zero, test_cond_wait, test_cond_signal, test_cond_broadcast, test_cond_timedwait, test_cond_zero }; if (op_index >= (sizeof(to_test) / sizeof(to_test[0]))) UT_FATAL("Invalid op_index provided"); PMEMmutex stack_sync; PMEMcond stack_cond; to_test[op_index](pop, &stack_sync, &stack_cond); } int main(int argc, char *argv[]) { START(argc, argv, "obj_debug"); if (argc < 3) UT_FATAL("usage: %s file-name op:f|l|r|a|s [op_index]", argv[0]); const char *path = argv[1]; if (strchr("flrapns", argv[2][0]) == NULL || argv[2][1] != '\0') UT_FATAL("op must be f or l or r or a or p or n or s"); unsigned long op_index; char *tailptr; switch (argv[2][0]) { case 'f': test_FOREACH(path); break; case 'l': test_lists(path); break; case 'a': test_alloc_construct(path); break; case 'p': test_double_free(path); break; case 'n': test_alloc_in_constructor(path); break; case 's': if (argc != 4) UT_FATAL("Provide an op_index with option s"); op_index = strtoul(argv[3], &tailptr, 10); if (tailptr[0] != '\0') UT_FATAL("Wrong op_index format"); test_sync_pop_check(op_index); break; } DONE(NULL); }
9,613
22.975062
74
c
null
NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pmalloc_rand_mt/obj_pmalloc_rand_mt.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_pmalloc_mt.c -- multithreaded test of allocator */ #include <stdint.h> #include "file.h" #include "unittest.h" #define RRAND(seed, max, min) (os_rand_r(&(seed)) % ((max) - (min)) + (min)) static size_t object_size; static unsigned nobjects; static unsigned iterations = 1000000; static unsigned seed; static void * test_worker(void *arg) { PMEMobjpool *pop = arg; PMEMoid *objects = ZALLOC(sizeof(PMEMoid) * nobjects); unsigned fill = 0; int ret; unsigned myseed = seed; for (unsigned i = 0; i < iterations; ++i) { unsigned fill_ratio = (fill * 100) / nobjects; unsigned pos = RRAND(myseed, nobjects, 0); size_t size = RRAND(myseed, object_size, 64); if (RRAND(myseed, 100, 0) < fill_ratio) { if (!OID_IS_NULL(objects[pos])) { pmemobj_free(&objects[pos]); objects[pos] = OID_NULL; fill--; } } else { if (OID_IS_NULL(objects[pos])) { ret = pmemobj_alloc(pop, &objects[pos], size, 0, NULL, NULL); UT_ASSERTeq(ret, 0); fill++; } } } FREE(objects); return NULL; } int main(int argc, char *argv[]) { START(argc, argv, "obj_pmalloc_rand_mt"); if (argc < 5 || argc > 7) UT_FATAL("usage: %s [file] " "[threads #] [objects #] [object size] " "[iterations (def: 1000000)] [seed (def: time)]", argv[0]); unsigned nthreads = ATOU(argv[2]); nobjects = ATOU(argv[3]); object_size = ATOUL(argv[4]); if (argc > 5) iterations = ATOU(argv[5]); if (argc > 6) seed = ATOU(argv[6]); else seed = (unsigned)time(NULL); PMEMobjpool *pop; int exists = util_file_exists(argv[1]); if (exists < 0) UT_FATAL("!util_file_exists"); if (!exists) { pop = pmemobj_create(argv[1], "TEST", (PMEMOBJ_MIN_POOL * 10) + (nthreads * nobjects * object_size), 0666); if (pop == NULL) UT_FATAL("!pmemobj_create"); } else { pop = pmemobj_open(argv[1], "TEST"); if (pop == NULL) UT_FATAL("!pmemobj_open"); } os_thread_t *threads = MALLOC(sizeof(os_thread_t) * nthreads); for (unsigned i = 0; i < nthreads; ++i) { PTHREAD_CREATE(&threads[i], NULL, test_worker, pop); } for (unsigned i = 0; i < nthreads; ++i) { PTHREAD_JOIN(&threads[i], NULL); } FREE(threads); pmemobj_close(pop); DONE(NULL); }
3,809
26.021277
76
c