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/pmem_has_auto_flush_win/mocks_windows.h | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of EnumSystemFirmwareTables and
* GetSystemFirmwareTable
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of pmem_has_auto_flush_win test.
* It would replace default implementation with mocked functions defined
* in mocks_windows.c
*
* This WRAP_REAL define could be also passed as preprocessor definition.
*/
#include <windows.h>
#ifndef WRAP_REAL
#define EnumSystemFirmwareTables __wrap_EnumSystemFirmwareTables
#define GetSystemFirmwareTable __wrap_GetSystemFirmwareTable
UINT
__wrap_EnumSystemFirmwareTables(DWORD FirmwareTableProviderSignature,
PVOID pFirmwareTableEnumBuffer, DWORD BufferSize);
UINT
__wrap_GetSystemFirmwareTable(DWORD FirmwareTableProviderSignature,
DWORD FirmwareTableID, PVOID pFirmwareTableBuffer, DWORD BufferSize);
#endif
| 2,503 | 42.172414 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_has_auto_flush_win/pmem_has_auto_flush_win.h | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_has_auto_flush_win.h -- header file for windows mocks
* for pmem_has_auto_flush_win
*/
#ifndef PMDK_HAS_AUTO_FLUSH_WIN_H
#define PMDK_HAS_AUTO_FLUSH_WIN_H 1
extern size_t Is_nfit;
extern size_t Pc_type;
extern size_t Pc_capabilities;
#endif
| 1,853 | 40.2 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_has_auto_flush_win/mocks_windows.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in os_auto_flush_windows.c
*/
#include "pmem.h"
#include "util.h"
#include "unittest.h"
#include "set.h"
#include "pmemcommon.h"
#include "os_auto_flush_windows.h"
#include "pmem_has_auto_flush_win.h"
#include <errno.h>
extern size_t Is_nfit;
extern size_t Pc_type;
extern size_t Pc_capabilities;
FUNC_MOCK_DLLIMPORT(EnumSystemFirmwareTables, UINT,
DWORD FirmwareTableProviderSignature,
PVOID pFirmwareTableBuffer,
DWORD BufferSize)
FUNC_MOCK_RUN_DEFAULT {
if (FirmwareTableProviderSignature != ACPI_SIGNATURE)
return _FUNC_REAL(EnumSystemFirmwareTables)
(FirmwareTableProviderSignature,
pFirmwareTableBuffer, BufferSize);
if (Is_nfit == 1 && pFirmwareTableBuffer != NULL &&
BufferSize != 0) {
UT_OUT("Mock NFIT available");
strncpy(pFirmwareTableBuffer, NFIT_STR_SIGNATURE, BufferSize);
}
return NFIT_SIGNATURE_LEN + sizeof(struct nfit_header);
}
FUNC_MOCK_END
FUNC_MOCK_DLLIMPORT(GetSystemFirmwareTable, UINT,
DWORD FirmwareTableProviderSignature,
DWORD FirmwareTableID,
PVOID pFirmwareTableBuffer,
DWORD BufferSize)
FUNC_MOCK_RUN_DEFAULT {
if (FirmwareTableProviderSignature != ACPI_SIGNATURE ||
FirmwareTableID != NFIT_REV_SIGNATURE)
return _FUNC_REAL(GetSystemFirmwareTable)
(FirmwareTableProviderSignature, FirmwareTableID,
pFirmwareTableBuffer, BufferSize);
if (pFirmwareTableBuffer == NULL && BufferSize == 0) {
UT_OUT("GetSystemFirmwareTable mock");
return sizeof(struct platform_capabilities) +
sizeof(struct nfit_header);
}
struct nfit_header nfit;
struct platform_capabilities pc;
/* fill nfit */
char sig[NFIT_SIGNATURE_LEN] = NFIT_STR_SIGNATURE;
strncpy(nfit.signature, sig, NFIT_SIGNATURE_LEN);
nfit.length = sizeof(nfit);
memcpy(pFirmwareTableBuffer, &nfit, nfit.length);
/* fill platform_capabilities */
pc.length = sizeof(pc);
/* [...] 0000 0011 - proper capabilities bits combination */
pc.capabilities = (uint32_t)Pc_capabilities;
pc.type = (uint16_t)Pc_type;
memcpy((char *)pFirmwareTableBuffer + nfit.length, &pc, pc.length);
return BufferSize;
}
FUNC_MOCK_END
/*
* libpmem_init -- load-time initialization for libpmem
* Called automatically by the run-time loader.
*/
CONSTRUCTOR(libpmem_init)
void
libpmem_init(void)
{
pmem_init();
}
| 3,887 | 32.808696 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_has_auto_flush_win/pmem_has_auto_flush_win.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_has_auto_flush_win.c -- unit test for pmem_has_auto_flush_win()
*
* usage: pmem_has_auto_flush_win <option>
* options:
* n - is nfit available or not (y or n)
* type: number of platform capabilities structure
* capabilities: platform capabilities bits
*/
#include <stdbool.h>
#include <errno.h>
#include "unittest.h"
#include "pmemcommon.h"
#include "set.h"
#include "mocks_windows.h"
#include "pmem_has_auto_flush_win.h"
#include "util.h"
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
size_t Is_nfit = 0;
size_t Pc_type = 0;
size_t Pc_capabilities = 3;
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_has_auto_flush_win");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 4)
UT_FATAL("usage: pmem_has_auto_flush_win "
"<option> <type> <capabilities>",
argv[0]);
Pc_type = (size_t)atoi(argv[2]);
Pc_capabilities = (size_t)atoi(argv[3]);
Is_nfit = argv[1][0] == 'y';
int eADR = pmem_has_auto_flush();
UT_OUT("pmem_has_auto_flush ret: %d", eADR);
common_fini();
DONE(NULL);
}
| 2,782 | 32.130952 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_bucket/obj_bucket.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_bucket.c -- unit test for bucket
*/
#include "bucket.h"
#include "container_ravl.h"
#include "util.h"
#include "unittest.h"
#define TEST_CHUNK_ID 10
#define TEST_ZONE_ID 20
#define TEST_SIZE_IDX 30
#define TEST_BLOCK_OFF 40
struct container_test {
struct block_container super;
};
static const struct memory_block *inserted_memblock;
static int
container_test_insert(struct block_container *c,
const struct memory_block *m)
{
inserted_memblock = m;
return 0;
}
static int
container_test_get_rm_bestfit(struct block_container *c,
struct memory_block *m)
{
if (inserted_memblock == NULL)
return ENOMEM;
*m = *inserted_memblock;
inserted_memblock = NULL;
return 0;
}
static int
container_test_get_rm_exact(struct block_container *c,
const struct memory_block *m)
{
if (inserted_memblock == NULL)
return ENOMEM;
if (inserted_memblock->chunk_id == m->chunk_id) {
inserted_memblock = NULL;
return 0;
}
return ENOMEM;
}
static void
container_test_destroy(struct block_container *c)
{
FREE(c);
}
static struct block_container_ops container_test_ops = {
.insert = container_test_insert,
.get_rm_exact = container_test_get_rm_exact,
.get_rm_bestfit = container_test_get_rm_bestfit,
.get_exact = NULL,
.is_empty = NULL,
.rm_all = NULL,
.destroy = container_test_destroy,
};
static struct block_container *
container_new_test(void)
{
struct container_test *c = MALLOC(sizeof(struct container_test));
c->super.c_ops = &container_test_ops;
return &c->super;
}
static void *
mock_get_real_data(const struct memory_block *m)
{
return NULL;
}
static size_t
mock_get_real_size(const struct memory_block *m)
{
return 0;
}
static const struct memory_block_ops mock_ops = {
.block_size = NULL,
.prep_hdr = NULL,
.get_lock = NULL,
.get_state = NULL,
.get_user_data = NULL,
.get_real_data = mock_get_real_data,
.get_user_size = NULL,
.get_real_size = mock_get_real_size,
.write_header = NULL,
.reinit_header = NULL,
.get_extra = NULL,
.get_flags = NULL,
};
static void
test_bucket_insert_get(void)
{
struct bucket *b = bucket_new(container_new_test(), NULL);
UT_ASSERT(b != NULL);
struct memory_block m = {TEST_CHUNK_ID, TEST_ZONE_ID,
TEST_SIZE_IDX, TEST_BLOCK_OFF};
m.m_ops = &mock_ops;
/* get from empty */
UT_ASSERT(b->c_ops->get_rm_bestfit(b->container, &m) != 0);
UT_ASSERT(bucket_insert_block(b, &m) == 0);
UT_ASSERT(b->c_ops->get_rm_bestfit(b->container, &m) == 0);
UT_ASSERT(m.chunk_id == TEST_CHUNK_ID);
UT_ASSERT(m.zone_id == TEST_ZONE_ID);
UT_ASSERT(m.size_idx == TEST_SIZE_IDX);
UT_ASSERT(m.block_off == TEST_BLOCK_OFF);
bucket_delete(b);
}
static void
test_bucket_remove(void)
{
struct bucket *b = bucket_new(container_new_test(), NULL);
UT_ASSERT(b != NULL);
struct memory_block m = {TEST_CHUNK_ID, TEST_ZONE_ID,
TEST_SIZE_IDX, TEST_BLOCK_OFF};
m.m_ops = &mock_ops;
UT_ASSERT(bucket_insert_block(b, &m) == 0);
UT_ASSERT(b->c_ops->get_rm_exact(b->container, &m) == 0);
bucket_delete(b);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_bucket");
test_bucket_insert_get();
test_bucket_remove();
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 4,892 | 23.465 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pmalloc_oom_mt/obj_pmalloc_oom_mt.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pmalloc_oom_mt.c -- build multithreaded out of memory test
*
*/
#include <stddef.h>
#include "unittest.h"
#define TEST_ALLOC_SIZE (32 * 1024)
#define LAYOUT_NAME "oom_mt"
static int allocated;
static PMEMobjpool *pop;
static void *
oom_worker(void *arg)
{
allocated = 0;
while (pmemobj_alloc(pop, NULL, TEST_ALLOC_SIZE, 0, NULL, NULL) == 0)
allocated++;
PMEMoid iter, iter2;
POBJ_FOREACH_SAFE(pop, iter, iter2)
pmemobj_free(&iter);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_oom_mt");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
os_thread_t t;
os_thread_create(&t, NULL, oom_worker, NULL);
os_thread_join(&t, NULL);
int first_thread_allocated = allocated;
os_thread_create(&t, NULL, oom_worker, NULL);
os_thread_join(&t, NULL);
UT_ASSERTeq(first_thread_allocated, allocated);
pmemobj_close(pop);
DONE(NULL);
}
| 2,680 | 28.461538 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_realloc/vmem_realloc.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_realloc -- unit test for vmem_realloc
*
* usage: vmem_realloc [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_realloc");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
int *test = vmem_realloc(vmp, NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = test_value;
UT_ASSERTeq(test[0], test_value);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
test = vmem_realloc(vmp, test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], test_value);
test[1] = test_value;
test[9] = test_value;
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}
| 2,932 | 28.928571 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_malloc_hooks/vmmalloc_malloc_hooks.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_malloc_hooks.c -- unit test for libvmmalloc malloc hooks
*
* usage: vmmalloc_malloc_hooks
*/
#include <stdlib.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
static void *(*old_malloc_hook) (size_t, const void *);
static void *(*old_realloc_hook) (void *, size_t, const void *);
static void *(*old_memalign_hook) (size_t, size_t, const void *);
static void (*old_free_hook) (void *, const void *);
static int malloc_cnt = 0;
static int realloc_cnt = 0;
static int memalign_cnt = 0;
static int free_cnt = 0;
static void *
hook_malloc(size_t size, const void *caller)
{
void *p;
malloc_cnt++;
__malloc_hook = old_malloc_hook;
p = malloc(size);
old_malloc_hook = __malloc_hook; /* might changed */
__malloc_hook = hook_malloc;
return p;
}
static void *
hook_realloc(void *ptr, size_t size, const void *caller)
{
void *p;
realloc_cnt++;
__realloc_hook = old_realloc_hook;
p = realloc(ptr, size);
old_realloc_hook = __realloc_hook; /* might changed */
__realloc_hook = hook_realloc;
return p;
}
static void *
hook_memalign(size_t alignment, size_t size, const void *caller)
{
void *p;
memalign_cnt++;
__memalign_hook = old_memalign_hook;
p = memalign(alignment, size);
old_memalign_hook = __memalign_hook; /* might changed */
__memalign_hook = hook_memalign;
return p;
}
static void
hook_free(void *ptr, const void *caller)
{
free_cnt++;
__free_hook = old_free_hook;
free(ptr);
old_free_hook = __free_hook; /* might changed */
__free_hook = hook_free;
}
static void
hook_init(void)
{
UT_OUT("installing hooks");
old_malloc_hook = __malloc_hook;
old_realloc_hook = __realloc_hook;
old_memalign_hook = __memalign_hook;
old_free_hook = __free_hook;
__malloc_hook = hook_malloc;
__realloc_hook = hook_realloc;
__memalign_hook = hook_memalign;
__free_hook = hook_free;
}
int
main(int argc, char *argv[])
{
void *ptr;
START(argc, argv, "vmmalloc_malloc_hooks");
hook_init();
ptr = malloc(4321);
free(ptr);
ptr = calloc(1, 4321);
free(ptr);
ptr = malloc(8);
ptr = realloc(ptr, 4321);
free(ptr);
ptr = memalign(16, 4321);
free(ptr);
UT_OUT("malloc %d realloc %d memalign %d free %d",
malloc_cnt, realloc_cnt, memalign_cnt, free_cnt);
DONE(NULL);
}
| 3,837 | 26.028169 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_valloc/vmmalloc_valloc.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_valloc.c -- unit test for libvmmalloc valloc/pvalloc
*
* usage: vmmalloc_valloc [v|p]
*/
#include <sys/param.h>
#include <libvmmalloc.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
static void *(*Valloc)(size_t size);
int
main(int argc, char *argv[])
{
const int test_value = 123456;
size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
size_t min_size = sizeof(int);
size_t max_size = 4 * pagesize;
size_t size;
int *ptr;
START(argc, argv, "vmmalloc_valloc");
if (argc != 2)
UT_FATAL("usage: %s [v|p]", argv[0]);
switch (argv[1][0]) {
case 'v':
UT_OUT("testing valloc");
Valloc = valloc;
break;
case 'p':
UT_OUT("testing pvalloc");
Valloc = pvalloc;
break;
default:
UT_FATAL("usage: %s [v|p]", argv[0]);
}
for (size = min_size; size < max_size; size *= 2) {
ptr = Valloc(size);
/* at least one allocation must succeed */
UT_ASSERT(ptr != NULL);
if (ptr == NULL)
break;
/* ptr should be usable */
*ptr = test_value;
UT_ASSERTeq(*ptr, test_value);
/* check for correct address alignment */
UT_ASSERTeq((uintptr_t)(ptr) & (pagesize - 1), 0);
if (Valloc == pvalloc) {
/* check for correct allocation size */
size_t usable = malloc_usable_size(ptr);
UT_ASSERTeq(usable, roundup(size, pagesize));
}
free(ptr);
}
DONE(NULL);
}
| 2,930 | 28.31 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/log_walker/log_walker.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log_walker.c -- unit test to verify pool's write-protection in debug mode
*
* usage: log_walker file
*
*/
#include <sys/param.h>
#include "unittest.h"
/*
* do_append -- call pmemlog_append() & print result
*/
static void
do_append(PMEMlogpool *plp)
{
const char *str[6] = {
"1st append string\n",
"2nd append string\n",
"3rd append string\n",
"4th append string\n",
"5th append string\n",
"6th append string\n"
};
for (int i = 0; i < 6; ++i) {
int rv = pmemlog_append(plp, str[i], strlen(str[i]));
switch (rv) {
case 0:
UT_OUT("append str[%i] %s", i, str[i]);
break;
case -1:
UT_OUT("!append str[%i] %s", i, str[i]);
break;
default:
UT_OUT("!append: wrong return value");
break;
}
}
}
/*
* try_to_store -- try to store to the buffer 'buf'
*
* It is a walker function for pmemlog_walk
*/
static int
try_to_store(const void *buf, size_t len, void *arg)
{
memset((void *)buf, 0, len);
return 0;
}
/*
* do_walk -- call pmemlog_walk() & print result
*/
static void
do_walk(PMEMlogpool *plp)
{
pmemlog_walk(plp, 0, try_to_store, NULL);
UT_OUT("walk all at once");
}
static ut_jmp_buf_t Jmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
UT_OUT("signal: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
int
main(int argc, char *argv[])
{
PMEMlogpool *plp;
START(argc, argv, "log_walker");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
int fd = OPEN(path, O_RDWR);
/* pre-allocate 2MB of persistent memory */
POSIX_FALLOCATE(fd, (os_off_t)0, (size_t)(2 * 1024 * 1024));
CLOSE(fd);
if ((plp = pmemlog_create(path, 0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemlog_create: %s", path);
/* append some data */
do_append(plp);
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
if (!ut_sigsetjmp(Jmp)) {
do_walk(plp);
}
pmemlog_close(plp);
DONE(NULL);
}
| 3,640 | 23.436242 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_alloc/obj_tx_alloc.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_alloc.c -- unit test for pmemobj_tx_alloc and pmemobj_tx_zalloc
*/
#include <assert.h>
#include <sys/param.h>
#include <string.h>
#include "unittest.h"
#include "libpmemobj.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "tx_alloc"
#define TEST_VALUE_1 1
#define TEST_VALUE_2 2
#define OBJ_SIZE (200 * 1024)
enum type_number {
TYPE_NO_TX,
TYPE_COMMIT,
TYPE_ABORT,
TYPE_ZEROED_COMMIT,
TYPE_ZEROED_ABORT,
TYPE_XCOMMIT,
TYPE_XABORT,
TYPE_XZEROED_COMMIT,
TYPE_XZEROED_ABORT,
TYPE_XNOFLUSHED_COMMIT,
TYPE_COMMIT_NESTED1,
TYPE_COMMIT_NESTED2,
TYPE_ABORT_NESTED1,
TYPE_ABORT_NESTED2,
TYPE_ABORT_AFTER_NESTED1,
TYPE_ABORT_AFTER_NESTED2,
TYPE_OOM,
};
TOID_DECLARE(struct object, TYPE_OOM);
struct object {
size_t value;
char data[OBJ_SIZE - sizeof(size_t)];
};
/*
* do_tx_alloc_oom -- allocates objects until OOM
*/
static void
do_tx_alloc_oom(PMEMobjpool *pop)
{
int do_alloc = 1;
size_t alloc_cnt = 0;
do {
TX_BEGIN(pop) {
TOID(struct object) obj = TX_NEW(struct object);
D_RW(obj)->value = alloc_cnt;
} TX_ONCOMMIT {
alloc_cnt++;
} TX_ONABORT {
do_alloc = 0;
} TX_END
} while (do_alloc);
size_t bitmap_size = howmany(alloc_cnt, 8);
char *bitmap = (char *)MALLOC(bitmap_size);
pmemobj_memset_persist(pop, bitmap, 0, bitmap_size);
size_t obj_cnt = 0;
TOID(struct object) i;
POBJ_FOREACH_TYPE(pop, i) {
UT_ASSERT(D_RO(i)->value < alloc_cnt);
UT_ASSERT(!isset(bitmap, D_RO(i)->value));
setbit(bitmap, D_RO(i)->value);
obj_cnt++;
}
FREE(bitmap);
UT_ASSERTeq(obj_cnt, alloc_cnt);
TOID(struct object) o = POBJ_FIRST(pop, struct object);
while (!TOID_IS_NULL(o)) {
TOID(struct object) next = POBJ_NEXT(o);
POBJ_FREE(&o);
o = next;
}
}
/*
* do_tx_alloc_abort_after_nested -- aborts transaction after allocation
* in nested transaction
*/
static void
do_tx_alloc_abort_after_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT_AFTER_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_ABORT_AFTER_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj1, OID_NULL);
TOID_ASSIGN(obj2, OID_NULL);
} TX_END
TOID(struct object) first;
/* check the obj1 object */
UT_ASSERT(TOID_IS_NULL(obj1));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED1);
UT_ASSERT(TOID_IS_NULL(first));
/* check the obj2 object */
UT_ASSERT(TOID_IS_NULL(obj2));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_AFTER_NESTED2);
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_abort_nested -- aborts transaction in nested transaction
*/
static void
do_tx_alloc_abort_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_ABORT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj2, OID_NULL);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj1, OID_NULL);
} TX_END
TOID(struct object) first;
/* check the obj1 object */
UT_ASSERT(TOID_IS_NULL(obj1));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED1);
UT_ASSERT(TOID_IS_NULL(first));
/* check the obj2 object */
UT_ASSERT(TOID_IS_NULL(obj2));
first.oid = POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT_NESTED2);
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_commit_nested -- allocates two objects, one in nested transaction
*/
static void
do_tx_alloc_commit_nested(PMEMobjpool *pop)
{
TOID(struct object) obj1;
TOID(struct object) obj2;
TX_BEGIN(pop) {
TOID_ASSIGN(obj1, pmemobj_tx_alloc(sizeof(struct object),
TYPE_COMMIT_NESTED1));
UT_ASSERT(!TOID_IS_NULL(obj1));
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
TOID_ASSIGN(obj2, pmemobj_tx_zalloc(
sizeof(struct object),
TYPE_COMMIT_NESTED2));
UT_ASSERT(!TOID_IS_NULL(obj2));
UT_ASSERT(util_is_zeroed(D_RO(obj2),
sizeof(struct object)));
D_RW(obj2)->value = TEST_VALUE_2;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
UT_ASSERTeq(D_RO(obj2)->value, TEST_VALUE_2);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID(struct object) next;
/* check the obj1 object */
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED1));
UT_ASSERT(TOID_EQUALS(first, obj1));
UT_ASSERTeq(D_RO(first)->value, TEST_VALUE_1);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
/* check the obj2 object */
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT_NESTED2));
UT_ASSERT(TOID_EQUALS(first, obj2));
UT_ASSERTeq(D_RO(first)->value, TEST_VALUE_2);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_alloc_abort -- allocates an object and aborts the transaction
*/
static void
do_tx_alloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(sizeof(struct object),
TYPE_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_zerolen -- allocates an object of zero size to trigger tx abort
*/
static void
do_tx_alloc_zerolen(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(0, TYPE_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_alloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_alloc_commit -- allocates and object
*/
static void
do_tx_alloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_alloc(sizeof(struct object),
TYPE_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
next = POBJ_NEXT(first);
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_zalloc_abort -- allocates a zeroed object and aborts the transaction
*/
static void
do_tx_zalloc_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(sizeof(struct object),
TYPE_ZEROED_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_zerolen -- allocate an object of zero size to trigger tx abort
*/
static void
do_tx_zalloc_zerolen(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(0, TYPE_ZEROED_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_zalloc_huge(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_ZEROED_ABORT));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_zalloc_commit -- allocates zeroed object
*/
static void
do_tx_zalloc_commit(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_zalloc(sizeof(struct object),
TYPE_ZEROED_COMMIT));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_ZEROED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
next = POBJ_NEXT(first);
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_xalloc_abort -- allocates a zeroed object and aborts the transaction
*/
static void
do_tx_xalloc_abort(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XABORT, 0));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XZEROED_ABORT, POBJ_XALLOC_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_zerolen -- allocate an object of zero size to trigger tx abort
*/
static void
do_tx_xalloc_zerolen(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(0, TYPE_XABORT, 0));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(0, TYPE_XZEROED_ABORT,
POBJ_XALLOC_ZERO));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_huge -- allocates a huge object to trigger tx abort
*/
static void
do_tx_xalloc_huge(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_XABORT, 0));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XABORT));
UT_ASSERT(TOID_IS_NULL(first));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(PMEMOBJ_MAX_ALLOC_SIZE + 1,
TYPE_XZEROED_ABORT, POBJ_XALLOC_ZERO));
UT_ASSERT(0); /* should not get to this point */
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_ONABORT {
TOID_ASSIGN(obj, OID_NULL);
} TX_END
UT_ASSERT(TOID_IS_NULL(obj));
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_ABORT));
UT_ASSERT(TOID_IS_NULL(first));
}
/*
* do_tx_xalloc_commit -- allocates zeroed object
*/
static void
do_tx_xalloc_commit(PMEMobjpool *pop)
{
/* xalloc 0 */
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XCOMMIT, 0));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XCOMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID(struct object) next;
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
/* xalloc ZERO */
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XZEROED_COMMIT, POBJ_XALLOC_ZERO));
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(util_is_zeroed(D_RO(obj), sizeof(struct object)));
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XZEROED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->value, D_RO(obj)->value);
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_xalloc_noflush -- allocates zeroed object
*/
static void
do_tx_xalloc_noflush(PMEMobjpool *pop)
{
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, pmemobj_tx_xalloc(sizeof(struct object),
TYPE_XNOFLUSHED_COMMIT, POBJ_XALLOC_NO_FLUSH));
UT_ASSERT(!TOID_IS_NULL(obj));
D_RW(obj)->data[OBJ_SIZE - sizeof(size_t) - 1] = TEST_VALUE_1;
/* let pmemcheck find we didn't flush it */
} TX_ONCOMMIT {
UT_ASSERTeq(D_RO(obj)->data[OBJ_SIZE - sizeof(size_t) - 1],
TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID(struct object) first;
TOID_ASSIGN(first, POBJ_FIRST_TYPE_NUM(pop, TYPE_XNOFLUSHED_COMMIT));
UT_ASSERT(TOID_EQUALS(first, obj));
UT_ASSERTeq(D_RO(first)->data[OBJ_SIZE - sizeof(size_t) - 1],
D_RO(obj)->data[OBJ_SIZE - sizeof(size_t) - 1]);
TOID(struct object) next;
TOID_ASSIGN(next, POBJ_NEXT_TYPE_NUM(first.oid));
UT_ASSERT(TOID_IS_NULL(next));
}
/*
* do_tx_root -- retrieve root inside of transaction
*/
static void
do_tx_root(PMEMobjpool *pop)
{
size_t root_size = 24;
TX_BEGIN(pop) {
PMEMoid root = pmemobj_root(pop, root_size);
UT_ASSERT(!OID_IS_NULL(root));
UT_ASSERT(util_is_zeroed(pmemobj_direct(root),
root_size));
UT_ASSERTeq(root_size, pmemobj_root_size(pop));
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
/*
* do_tx_alloc_many -- allocates many objects inside of a single transaction
*/
static void
do_tx_alloc_many(PMEMobjpool *pop)
{
#define TX_ALLOC_COUNT 70 /* bigger than max reservations */
PMEMoid oid, oid2;
POBJ_FOREACH_SAFE(pop, oid, oid2) {
pmemobj_free(&oid);
}
TOID(struct object) first;
TOID_ASSIGN(first, pmemobj_first(pop));
UT_ASSERT(TOID_IS_NULL(first));
PMEMoid oids[TX_ALLOC_COUNT];
TX_BEGIN(pop) {
for (int i = 0; i < TX_ALLOC_COUNT; ++i) {
oids[i] = pmemobj_tx_alloc(1, 0);
UT_ASSERT(!OID_IS_NULL(oids[i]));
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
/* empty tx to make sure there's no leftover state */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
for (int i = 0; i < TX_ALLOC_COUNT; ++i) {
pmemobj_tx_free(oids[i]);
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(first, pmemobj_first(pop));
UT_ASSERT(TOID_IS_NULL(first));
#undef TX_ALLOC_COUNT
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_alloc");
util_init();
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_root(pop);
VALGRIND_WRITE_STATS;
/* alloc */
do_tx_alloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_huge(pop);
VALGRIND_WRITE_STATS;
/* zalloc */
do_tx_zalloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_zalloc_huge(pop);
VALGRIND_WRITE_STATS;
/* xalloc */
do_tx_xalloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_zerolen(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_huge(pop);
VALGRIND_WRITE_STATS;
/* alloc */
do_tx_alloc_commit_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_abort_after_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_oom(pop);
VALGRIND_WRITE_STATS;
do_tx_alloc_many(pop);
VALGRIND_WRITE_STATS;
do_tx_xalloc_noflush(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 20,174 | 22.651817 | 80 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pool_lock/obj_pool_lock.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pool_lock.c -- unit test which checks whether it's possible to
* simultaneously open the same obj pool
*/
#include "unittest.h"
#define LAYOUT "layout"
static void
test_reopen(const char *path)
{
PMEMobjpool *pop1 = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop1)
UT_FATAL("!create");
PMEMobjpool *pop2 = pmemobj_open(path, LAYOUT);
if (pop2)
UT_FATAL("pmemobj_open should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open failed but for unexpected reason");
pmemobj_close(pop1);
pop2 = pmemobj_open(path, LAYOUT);
if (!pop2)
UT_FATAL("pmemobj_open should succeed after close");
pmemobj_close(pop2);
UNLINK(path);
}
#ifndef _WIN32
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
pid_t pid = fork();
PMEMobjpool *pop;
char *path = argv[1];
if (pid < 0)
UT_FATAL("fork failed");
if (pid == 0) {
/* child */
if (sleep)
usleep(sleep);
while (os_access(path, R_OK))
usleep(100 * 1000);
pop = pmemobj_open(path, LAYOUT);
if (pop)
UT_FATAL("pmemobj_open after fork should not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open after fork failed but for "
"unexpected reason");
exit(0);
}
pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!create");
int status;
if (waitpid(pid, &status, 0) < 0)
UT_FATAL("!waitpid failed");
if (!WIFEXITED(status))
UT_FATAL("child process failed");
pmemobj_close(pop);
UNLINK(path);
}
#else
static void
test_open_in_different_process(int argc, char **argv, unsigned sleep)
{
PMEMobjpool *pop;
if (sleep > 0)
return;
char *path = argv[1];
/* before starting the 2nd process, create a pool */
pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!create");
/*
* "X" is pass as an additional param to the new process
* created by ut_spawnv to distinguish second process on Windows
*/
uintptr_t result = ut_spawnv(argc, argv, "X", NULL);
if (result == -1)
UT_FATAL("Create new process failed error: %d", GetLastError());
pmemobj_close(pop);
}
#endif
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pool_lock");
if (argc < 2)
UT_FATAL("usage: %s path", argv[0]);
if (argc == 2) {
test_reopen(argv[1]);
test_open_in_different_process(argc, argv, 0);
for (unsigned i = 1; i < 100000; i *= 2)
test_open_in_different_process(argc, argv, i);
} else if (argc == 3) {
PMEMobjpool *pop;
/* 2nd arg used by windows for 2 process test */
pop = pmemobj_open(argv[1], LAYOUT);
if (pop)
UT_FATAL("pmemobj_open after create process should "
"not succeed");
if (errno != EWOULDBLOCK)
UT_FATAL("!pmemobj_open after create process failed "
"but for unexpected reason");
}
DONE(NULL);
}
| 4,478 | 25.040698 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_pool/blk_pool.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_pool.c -- unit test for pmemblk_create() and pmemblk_open()
*
* usage: blk_pool op path bsize [poolsize mode]
*
* op can be:
* c - create
* o - open
*
* "poolsize" and "mode" arguments are ignored for "open"
*/
#include "unittest.h"
#define MB ((size_t)1 << 20)
static void
pool_create(const char *path, size_t bsize, size_t poolsize, unsigned mode)
{
PMEMblkpool *pbp = pmemblk_create(path, bsize, poolsize, mode);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_create", path);
else {
os_stat_t stbuf;
STAT(path, &stbuf);
UT_OUT("%s: file size %zu usable blocks %zu mode 0%o",
path, stbuf.st_size,
pmemblk_nblock(pbp),
stbuf.st_mode & 0777);
pmemblk_close(pbp);
int result = pmemblk_check(path, bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", path);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", path);
else
UT_ASSERTeq(pmemblk_check(path, bsize * 2), -1);
}
}
static void
pool_open(const char *path, size_t bsize)
{
PMEMblkpool *pbp = pmemblk_open(path, bsize);
if (pbp == NULL)
UT_OUT("!%s: pmemblk_open", path);
else {
UT_OUT("%s: pmemblk_open: Success", path);
pmemblk_close(pbp);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_pool");
if (argc < 4)
UT_FATAL("usage: %s op path bsize [poolsize mode]", argv[0]);
size_t bsize = strtoul(argv[3], NULL, 0);
size_t poolsize;
unsigned mode;
switch (argv[1][0]) {
case 'c':
poolsize = strtoul(argv[4], NULL, 0) * MB; /* in megabytes */
mode = strtoul(argv[5], NULL, 8);
pool_create(argv[2], bsize, poolsize, mode);
break;
case 'o':
pool_open(argv[2], bsize);
break;
default:
UT_FATAL("unknown operation");
}
DONE(NULL);
}
| 3,323 | 26.932773 | 75 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_dummy_funcs/vmmalloc_dummy_funcs.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_dummy_funcs.c -- dummy functions for vmmalloc tests
*/
#include "vmmalloc_dummy_funcs.h"
__attribute__((weak))
void *
aligned_alloc(size_t alignment, size_t size)
{
return NULL;
}
#ifdef __FreeBSD__
__attribute__((weak))
void *
memalign(size_t alignment, size_t size)
{
return NULL;
}
__attribute__((weak))
void *
pvalloc(size_t size)
{
return NULL;
}
/* XXX These exist only to allow the tests to link - they are never used */
void (*__free_hook)(void *, const void *);
void *(*__malloc_hook)(size_t size, const void *);
void *(*__memalign_hook)(size_t alignment, size_t size, const void *);
void *(*__realloc_hook)(void *ptr, size_t size, const void *);
#endif
| 2,289 | 33.179104 | 75 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_dummy_funcs/vmmalloc_dummy_funcs.h | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_weakfuncs.h -- definitions for vmmalloc tests
*/
#ifndef VMMALLOC_WEAKFUNCS_H
#define VMMALLOC_WEAKFUNCS_H
#include <stddef.h>
#ifndef __FreeBSD__
#include <malloc.h>
#endif
void *aligned_alloc(size_t alignment, size_t size);
#ifdef __FreeBSD__
void *memalign(size_t boundary, size_t size);
void *pvalloc(size_t size);
/* XXX These exist only to allow the tests to compile - they are never used */
extern void (*__free_hook)(void *, const void *);
extern void *(*__malloc_hook)(size_t size, const void *);
extern void *(*__memalign_hook)(size_t alignment, size_t size, const void *);
extern void *(*__realloc_hook)(void *ptr, size_t size, const void *);
#endif
#endif
| 2,292 | 37.864407 | 78 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_memcpy/pmem_memcpy.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_memcpy.c -- unit test for doing a memcpy
*
* usage: pmem_memcpy file destoff srcoff length
*
*/
#include "unittest.h"
#include "util_pmem.h"
#include "file.h"
typedef void *pmem_memcpy_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
static void *
pmem_memcpy_persist_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_persist(pmemdest, src, len);
}
static void *
pmem_memcpy_nodrain_wrapper(void *pmemdest, const void *src, size_t len,
unsigned flags)
{
(void) flags;
return pmem_memcpy_nodrain(pmemdest, src, len);
}
/*
* swap_mappings - given to mmapped regions swap them.
*
* Try swapping src and dest by unmapping src, mapping a new dest with
* the original src address as a hint. If successful, unmap original dest.
* Map a new src with the original dest as a hint.
*/
static void
swap_mappings(char **dest, char **src, size_t size, int fd)
{
char *d = *dest;
char *s = *src;
char *td, *ts;
MUNMAP(*src, size);
/* mmap destination using src addr as hint */
td = MMAP(s, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
MUNMAP(*dest, size);
*dest = td;
/* mmap src using original destination addr as a hint */
ts = MMAP(d, size, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS,
-1, 0);
*src = ts;
}
/*
* do_memcpy: Worker function for memcpy
*
* Always work within the boundary of bytes. Fill in 1/2 of the src
* memory with the pattern we want to write. This allows us to check
* that we did not overwrite anything we were not supposed to in the
* dest. Use the non pmem version of the memset/memcpy commands
* so as not to introduce any possible side affects.
*/
static void
do_memcpy(int fd, char *dest, int dest_off, char *src, int src_off,
size_t bytes, const char *file_name, pmem_memcpy_fn fn, unsigned flags)
{
void *ret;
char *buf = MALLOC(bytes);
enum file_type type = util_fd_get_type(fd);
if (type < 0)
UT_FATAL("cannot check type of file with fd %d", fd);
memset(buf, 0, bytes);
memset(dest, 0, bytes);
memset(src, 0, bytes);
util_persist_auto(type == TYPE_DEVDAX, src, bytes);
memset(src, 0x5A, bytes / 4);
util_persist_auto(type == TYPE_DEVDAX, src, bytes / 4);
memset(src + bytes / 4, 0x46, bytes / 4);
util_persist_auto(type == TYPE_DEVDAX, src + bytes / 4,
bytes / 4);
/* dest == src */
ret = fn(dest + dest_off, dest + dest_off, bytes / 2, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
/* len == 0 */
ret = fn(dest + dest_off, src, 0, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
ret = fn(dest + dest_off, src + src_off, bytes / 2, flags);
UT_ASSERTeq(ret, dest + dest_off);
/* memcmp will validate that what I expect in memory. */
if (memcmp(src + src_off, dest + dest_off, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
/* Now validate the contents of the file */
LSEEK(fd, (os_off_t)dest_off, SEEK_SET);
if (READ(fd, buf, bytes / 2) == bytes / 2) {
if (memcmp(src + src_off, buf, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
}
FREE(buf);
}
static unsigned Flags[] = {
0,
PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_NONTEMPORAL,
PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_WC,
PMEM_F_MEM_WB,
PMEM_F_MEM_NOFLUSH,
/* all possible flags */
PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH |
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL |
PMEM_F_MEM_WC | PMEM_F_MEM_WB,
};
/*
* do_memcpy_variants -- do_memcpy wrapper that tests multiple variants
* of memcpy functions
*/
static void
do_memcpy_variants(int fd, char *dest, int dest_off, char *src, int src_off,
size_t bytes, const char *file_name)
{
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy_persist_wrapper, 0);
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
do_memcpy(fd, dest, dest_off, src, src_off, bytes, file_name,
pmem_memcpy, Flags[i]);
}
}
int
main(int argc, char *argv[])
{
int fd;
char *dest;
char *src;
char *dest_orig;
char *src_orig;
size_t mapped_len;
if (argc != 5)
UT_FATAL("usage: %s file srcoff destoff length", argv[0]);
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_memcpy %s %s %s %s %savx %savx512f",
argv[2], argv[3], argv[4], thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
fd = OPEN(argv[1], O_RDWR);
int dest_off = atoi(argv[2]);
int src_off = atoi(argv[3]);
size_t bytes = strtoul(argv[4], NULL, 0);
/* src > dst */
dest_orig = dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL);
if (dest == NULL)
UT_FATAL("!could not map file: %s", argv[1]);
src_orig = src = MMAP(dest + mapped_len, mapped_len,
PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
/*
* Its very unlikely that src would not be > dest. pmem_map_file
* chooses the first unused address >= 1TB, large
* enough to hold the give range, and 1GB aligned. If the
* addresses did not get swapped to allow src > dst, log error
* and allow test to continue.
*/
if (src <= dest) {
swap_mappings(&dest, &src, mapped_len, fd);
if (src <= dest)
UT_FATAL("cannot map files in memory order");
}
enum file_type type = util_fd_get_type(fd);
if (type < 0)
UT_FATAL("cannot check type of file with fd %d", fd);
memset(dest, 0, (2 * bytes));
util_persist_auto(type == TYPE_DEVDAX, dest, 2 * bytes);
memset(src, 0, (2 * bytes));
do_memcpy_variants(fd, dest, dest_off, src, src_off, bytes, argv[1]);
/* dest > src */
swap_mappings(&dest, &src, mapped_len, fd);
if (dest <= src)
UT_FATAL("cannot map files in memory order");
do_memcpy_variants(fd, dest, dest_off, src, src_off, bytes, argv[1]);
int ret = pmem_unmap(dest_orig, mapped_len);
UT_ASSERTeq(ret, 0);
MUNMAP(src_orig, mapped_len);
CLOSE(fd);
DONE(NULL);
}
| 7,772 | 28.667939 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_out_of_memory/vmmalloc_out_of_memory.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_out_of_memory -- unit test for libvmmalloc out_of_memory
*
* usage: vmmalloc_out_of_memory
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "vmmalloc_out_of_memory");
/* allocate all memory */
void *prev = NULL;
for (;;) {
void **next = malloc(sizeof(void *));
if (next == NULL) {
/* out of memory */
break;
}
*next = prev;
prev = next;
}
UT_ASSERTne(prev, NULL);
/* free all allocations */
while (prev != NULL) {
void **act = prev;
prev = *act;
free(act);
}
DONE(NULL);
}
| 2,161 | 29.885714 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_check_allocations/vmmalloc_check_allocations.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_check_allocations -- unit test for
* libvmmalloc check_allocations
*
* usage: vmmalloc_check_allocations
*/
#include "unittest.h"
#define MIN_SIZE (sizeof(int))
#define MAX_SIZE (4L * 1024L * 1024L)
#define MAX_ALLOCS (VMEM_MIN_POOL / MIN_SIZE)
/* buffer for all allocations */
static void *allocs[MAX_ALLOCS];
int
main(int argc, char *argv[])
{
int i, j;
size_t size;
START(argc, argv, "vmmalloc_check_allocations");
for (size = MAX_SIZE; size >= MIN_SIZE; size /= 2) {
UT_OUT("size %zu", size);
memset(allocs, 0, sizeof(allocs));
for (i = 0; i < MAX_ALLOCS; ++i) {
allocs[i] = malloc(size);
if (allocs[i] == NULL) {
/* out of memory in pool */
break;
}
/* fill each allocation with a unique value */
memset(allocs[i], (char)i, size);
}
/* at least one allocation for each size must succeed */
UT_ASSERT(i > 0);
/* check for unexpected modifications of the data */
for (i = 0; i < MAX_ALLOCS && allocs[i] != NULL; ++i) {
char *buffer = allocs[i];
for (j = 0; j < size; ++j) {
if (buffer[j] != (char)i)
UT_FATAL("Content of data object was "
"modified unexpectedly for "
"object size: %zu, id: %d",
size, j);
}
free(allocs[i]);
}
}
DONE(NULL);
}
| 2,866 | 30.163043 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_basic/cto_basic.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_basic.c -- unit test for close-to-open persistence
*
* usage: cto_basic filename
*/
#include "unittest.h"
#define NALLOCS 100
static unsigned *ptrs[NALLOCS * 2];
#define POOL_SIZE (PMEMCTO_MIN_POOL * 2)
static const struct {
size_t size;
size_t spacing;
} Check_sizes[] = {
{.size = 10, .spacing = 8},
{.size = 100, .spacing = 16},
{.size = 200, .spacing = 32},
{.size = 500, .spacing = 64},
{.size = 1000, .spacing = 128},
{.size = 2000, .spacing = 256},
{.size = 3000, .spacing = 512},
{.size = 1 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 2 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 3 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 4 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 5 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 6 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 7 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 8 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 9 * 1024 * 1024, .spacing = 4 * 1024 * 1024}
};
static void
test_alloc(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
ptrs[i] = pmemcto_malloc(pcp, 16 * sizeof(ptrs[0]));
UT_ASSERTne(ptrs[i], NULL);
*(ptrs[i]) = i;
}
}
static void
test_check(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
size_t usize = pmemcto_malloc_usable_size(pcp, ptrs[i]);
UT_ASSERT(usize >= 16 * sizeof(ptrs[0]));
UT_ASSERTeq(*(ptrs[i]), i);
}
}
static void
test_free(PMEMctopool *pcp, unsigned start, unsigned cnt)
{
unsigned i;
for (i = start; i < start + cnt; ++i) {
pmemcto_free(pcp, ptrs[i]);
}
}
static void
do_malloc(PMEMctopool *pcp)
{
size_t sum_alloc = 0;
int i = 0;
/* test with multiple size of allocations from 8MB to 2B */
for (size_t size = 8 * 1024 * 1024; size > 2; ++i, size /= 2) {
ptrs[i] = pmemcto_malloc(pcp, size);
if (ptrs[i] == NULL)
continue;
*ptrs[i] = 0x1111;
UT_ASSERTeq(*ptrs[i], 0x1111);
sum_alloc += size;
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
}
/* allocate more than half of pool size */
UT_ASSERT(sum_alloc * 2 > 8 * 1024 * 1024);
while (i > 0)
pmemcto_free(pcp, ptrs[--i]);
}
static void
do_calloc(PMEMctopool *pcp)
{
for (size_t count = 1; count < 1024; count *= 2) {
for (int i = 0; i < NALLOCS; i++) {
ptrs[i] = pmemcto_calloc(pcp, count, sizeof(ptrs[0]));
UT_ASSERTne(ptrs[i], NULL);
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
/* pmemcto_calloc should return zeroed memory */
for (int j = 0; j < count; j++) {
UT_ASSERTeq(ptrs[i][j], 0);
ptrs[i][j] = 0x2222;
UT_ASSERTeq(ptrs[i][j], 0x2222);
}
}
for (int i = 0; i < NALLOCS; i++)
pmemcto_free(pcp, ptrs[i]);
}
}
static void
do_realloc(PMEMctopool *pcp)
{
int *test = pmemcto_realloc(pcp, NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = 0x3333;
UT_ASSERTeq(test[0], 0x3333);
/* check that pointer came from mem_pool */
UT_ASSERTrange(test, pcp, POOL_SIZE);
test = pmemcto_realloc(pcp, test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], 0x3333);
test[1] = 0x3333;
test[9] = 0x3333;
/* check that pointer came from mem_pool */
UT_ASSERTrange(test, pcp, POOL_SIZE);
pmemcto_free(pcp, test);
}
static void
do_malloc_usable_size(PMEMctopool *pcp)
{
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, NULL), 0);
int i;
for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) {
size_t size = Check_sizes[i].size;
void *ptr = pmemcto_malloc(pcp, size);
UT_ASSERTne(ptr, NULL);
size_t usable_size = pmemcto_malloc_usable_size(pcp, ptr);
UT_ASSERT(usable_size >= size);
if (usable_size - size > Check_sizes[i].spacing) {
UT_FATAL("Size %zu: spacing %zu is bigger"
"than expected: %zu", size,
(usable_size - size), Check_sizes[i].spacing);
}
memset(ptr, 0xEE, usable_size);
pmemcto_free(pcp, ptr);
}
}
static void
do_strdup(PMEMctopool *pcp)
{
const char *text = "Some test text";
const char *text_empty = "";
const wchar_t *wtext = L"Some test text";
const wchar_t *wtext_empty = L"";
char *str1 = pmemcto_strdup(pcp, text);
wchar_t *wcs1 = pmemcto_wcsdup(pcp, wtext);
UT_ASSERTne(str1, NULL);
UT_ASSERTne(wcs1, NULL);
UT_ASSERTeq(strcmp(text, str1), 0);
UT_ASSERTeq(wcscmp(wtext, wcs1), 0);
/* check that pointer came from mem_pool */
UT_ASSERTrange(str1, pcp, POOL_SIZE);
UT_ASSERTrange(wcs1, pcp, POOL_SIZE);
char *str2 = pmemcto_strdup(pcp, text_empty);
wchar_t *wcs2 = pmemcto_wcsdup(pcp, wtext_empty);
UT_ASSERTne(str2, NULL);
UT_ASSERTne(wcs2, NULL);
UT_ASSERTeq(strcmp(text_empty, str2), 0);
UT_ASSERTeq(wcscmp(wtext_empty, wcs2), 0);
/* check that pointer came from mem_pool */
UT_ASSERTrange(str2, pcp, POOL_SIZE);
UT_ASSERTrange(wcs2, pcp, POOL_SIZE);
pmemcto_free(pcp, str1);
pmemcto_free(pcp, wcs1);
pmemcto_free(pcp, str2);
pmemcto_free(pcp, wcs2);
}
int
main(int argc, char *argv[])
{
unsigned *root;
START(argc, argv, "cto_basic");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
UT_OUT("create: %s", argv[1]);
PMEMctopool *pcp = pmemcto_create(argv[1], "cto_basic",
0, S_IWUSR|S_IRUSR);
if (pcp == NULL)
UT_FATAL("!pmemcto_create");
test_alloc(pcp, 0, NALLOCS);
test_check(pcp, 0, NALLOCS);
pmemcto_set_root_pointer(pcp, ptrs[0]);
pmemcto_close(pcp);
PMEMctopool *pcp_old = pcp;
UT_OUT("re-open #1: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
test_check(pcp, 0, NALLOCS);
root = pmemcto_get_root_pointer(pcp);
UT_ASSERTeq(root, ptrs[0]);
test_alloc(pcp, NALLOCS, NALLOCS);
test_check(pcp, NALLOCS, NALLOCS);
pmemcto_set_root_pointer(pcp, ptrs[NALLOCS]);
pmemcto_close(pcp);
UT_OUT("re-open #2: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
test_check(pcp, 0, 2 * NALLOCS);
root = pmemcto_get_root_pointer(pcp);
UT_ASSERTeq(root, ptrs[NALLOCS]);
test_free(pcp, 0, 2 * NALLOCS);
pmemcto_close(pcp);
UT_OUT("re-open #3: %s", argv[1]);
/* reopen */
pcp = pmemcto_open(argv[1], "cto_basic");
if (pcp == NULL)
UT_FATAL("!pmemcto_open");
UT_ASSERTeq(pcp, pcp_old);
do_malloc(pcp);
do_calloc(pcp);
do_realloc(pcp);
do_malloc_usable_size(pcp);
do_strdup(pcp);
pmemcto_close(pcp);
/* try to open the pool when the base address is busy */
void *ptr = mmap(pcp_old, 4096, PROT_READ|PROT_WRITE,
MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED, -1, 0);
UT_ASSERTne(ptr, NULL);
UT_ASSERTeq(ptr, pcp_old);
pcp = pmemcto_open(argv[1], "cto_basic");
UT_ASSERTeq(pcp, NULL);
munmap(ptr, 4096);
int ret = pmemcto_check(argv[1], "cto_basic");
UT_ASSERTeq(ret, 1);
ret = pmemcto_check(argv[1], NULL);
UT_ASSERTeq(ret, 1);
ret = pmemcto_check(argv[1], "xxx");
UT_ASSERTeq(ret, -1);
DONE(NULL);
}
| 8,646 | 25.606154 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_movnt/pmem_movnt.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_movnt.c -- unit test for MOVNT threshold
*
* usage: pmem_movnt
*
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
char *dst;
char *src;
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_movnt %s %savx %savx512f",
thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
src = MEMALIGN(64, 8192);
dst = MEMALIGN(64, 8192);
memset(src, 0x88, 8192);
memset(dst, 0, 8192);
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memcpy_nodrain(dst, src, size);
UT_ASSERTeq(memcmp(src, dst, size), 0);
UT_ASSERTeq(dst[size], 0);
}
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memmove_nodrain(dst, src, size);
UT_ASSERTeq(memcmp(src, dst, size), 0);
UT_ASSERTeq(dst[size], 0);
}
for (size_t size = 1; size <= 4096; size *= 2) {
memset(dst, 0, 4096);
pmem_memset_nodrain(dst, 0x77, size);
UT_ASSERTeq(dst[0], 0x77);
UT_ASSERTeq(dst[size - 1], 0x77);
UT_ASSERTeq(dst[size], 0);
}
ALIGNED_FREE(dst);
ALIGNED_FREE(src);
DONE(NULL);
}
| 2,779 | 29.888889 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_strdup/vmem_strdup.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_strdup.c -- unit test for vmem_strdup
*
* usage: vmem_strdup [directory]
*/
#include "unittest.h"
#include <wchar.h>
int
main(int argc, char *argv[])
{
const char *text = "Some test text";
const char *text_empty = "";
const wchar_t *wtext = L"Some test text";
const wchar_t *wtext_empty = L"";
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_strdup");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
char *str1 = vmem_strdup(vmp, text);
wchar_t *wcs1 = vmem_wcsdup(vmp, wtext);
UT_ASSERTne(str1, NULL);
UT_ASSERTne(wcs1, NULL);
UT_ASSERTeq(strcmp(text, str1), 0);
UT_ASSERTeq(wcscmp(wtext, wcs1), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(str1, mem_pool, VMEM_MIN_POOL);
UT_ASSERTrange(wcs1, mem_pool, VMEM_MIN_POOL);
}
char *str2 = vmem_strdup(vmp, text_empty);
wchar_t *wcs2 = vmem_wcsdup(vmp, wtext_empty);
UT_ASSERTne(str2, NULL);
UT_ASSERTne(wcs2, NULL);
UT_ASSERTeq(strcmp(text_empty, str2), 0);
UT_ASSERTeq(wcscmp(wtext_empty, wcs2), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(str2, mem_pool, VMEM_MIN_POOL);
UT_ASSERTrange(wcs2, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, str1);
vmem_free(vmp, wcs1);
vmem_free(vmp, str2);
vmem_free(vmp, wcs2);
vmem_delete(vmp);
DONE(NULL);
}
| 3,374 | 29.963303 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_memcheck_register/obj_memcheck_register.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_memcheck_register.c - tests that verifies that objects are registered
* correctly in memcheck
*/
#include "unittest.h"
static void
test_create(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "register",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid oid = pmemobj_root(pop, 1024);
TX_BEGIN(pop) {
pmemobj_tx_alloc(1024, 0);
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
pmemobj_close(pop);
}
static void
test_open(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_open(path, "register")) == NULL)
UT_FATAL("!pmemobj_open: %s", path);
PMEMoid oid = pmemobj_root(pop, 1024);
TX_BEGIN(pop) {
pmemobj_tx_add_range(oid, 0, 10);
} TX_END
pmemobj_close(pop);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memcheck_register");
if (argc != 3)
UT_FATAL("usage: %s [c|o] file-name", argv[0]);
switch (argv[1][0]) {
case 'c':
test_create(argv[2]);
break;
case 'o':
test_open(argv[2]);
break;
default:
UT_FATAL("usage: %s [c|o] file-name", argv[0]);
break;
}
DONE(NULL);
}
| 2,731 | 26.877551 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_calloc/vmmalloc_calloc.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_calloc.c -- unit test for libvmmalloc calloc
*
* usage: vmmalloc_calloc
*/
#include "unittest.h"
#include "jemalloc/internal/jemalloc_internal.h"
#include "jemalloc/internal/size_classes.h"
#define DEFAULT_COUNT (SMALL_MAXCLASS / 4)
#define DEFAULT_N 100
/* cfree() has been removed from glibc since version 2.26 */
#ifndef cfree
#define cfree free
#endif
int
main(int argc, char *argv[])
{
const int test_value = 123456;
int count = DEFAULT_COUNT;
int n = DEFAULT_N;
int *ptr;
int i, j;
START(argc, argv, "vmmalloc_calloc");
for (i = 0; i < n; i++) {
ptr = calloc(1, count * sizeof(int));
UT_ASSERTne(ptr, NULL);
/* calloc should return zeroed memory */
for (j = 0; j < count; j++)
UT_ASSERTeq(ptr[j], 0);
for (j = 0; j < count; j++)
ptr[j] = test_value;
for (j = 0; j < count; j++)
UT_ASSERTeq(ptr[j], test_value);
cfree(ptr);
}
DONE(NULL);
}
| 2,506 | 30.734177 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_reorder_basic/obj_reorder_basic.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_reorder_basic.c -- a simple unit test for store reordering
*
* usage: obj_reorder_basic file w|c
* w - write data
* c - check data consistency
*
*/
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "intro_1"
#define MAX_BUF_LEN 10
#define BUF_VALUE 'a'
struct my_root {
size_t len;
char buf[MAX_BUF_LEN];
};
/*
* write_consistent -- (internal) write data in a consistent manner
*/
static void
write_consistent(struct pmemobjpool *pop)
{
PMEMoid root = pmemobj_root(pop, sizeof(struct my_root));
struct my_root *rootp = pmemobj_direct(root);
char buf[MAX_BUF_LEN];
memset(buf, BUF_VALUE, sizeof(buf));
buf[MAX_BUF_LEN - 1] = '\0';
rootp->len = strlen(buf);
pmemobj_persist(pop, &rootp->len, sizeof(rootp->len));
pmemobj_memcpy_persist(pop, rootp->buf, buf, rootp->len);
}
/*
* check_consistency -- (internal) check buf consistency
*/
static int
check_consistency(struct pmemobjpool *pop)
{
PMEMoid root = pmemobj_root(pop, sizeof(struct my_root));
struct my_root *rootp = pmemobj_direct(root);
if (rootp->len == strlen(rootp->buf) && rootp->len != 0)
for (int i = 0; i < MAX_BUF_LEN - 1; ++i)
if (rootp->buf[i] != BUF_VALUE)
return 1;
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_reorder_basic");
util_init();
if (argc != 3 || strchr("wc", argv[1][0]) == 0 || argv[1][1] != '\0')
UT_FATAL("usage: %s w|c file", argv[0]);
PMEMobjpool *pop = pmemobj_open(argv[2], LAYOUT_NAME);
UT_ASSERT(pop != NULL);
char opt = argv[1][0];
VALGRIND_EMIT_LOG("PMREORDER_MARKER_WRITE.BEGIN");
switch (opt) {
case 'w':
{
write_consistent(pop);
break;
}
case 'c':
{
int ret = check_consistency(pop);
pmemobj_close(pop);
END(ret);
}
default:
UT_FATAL("Unrecognized option %c", opt);
}
VALGRIND_EMIT_LOG("PMREORDER_MARKER_WRITE.END");
pmemobj_close(pop);
DONE(NULL);
}
| 3,514 | 26.677165 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_heap_interrupt/mocks_windows.h | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of memops functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_heap_interrupt test.
* It would replace default implementation with mocked functions defined
* in obj_heap_interrupt.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define operation_finish __wrap_operation_finish
#endif
| 2,093 | 41.734694 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_heap_interrupt/obj_heap_interrupt.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_heap_interrupt.c -- unit test for pool heap interruption
*/
#include "heap_layout.h"
#include "memops.h"
#include "unittest.h"
POBJ_LAYOUT_BEGIN(heap_interrupt);
POBJ_LAYOUT_END(heap_interrupt);
static int exit_on_finish = 0;
FUNC_MOCK(operation_finish, void, struct operation_context *ctx)
FUNC_MOCK_RUN_DEFAULT {
if (exit_on_finish)
exit(0);
else
_FUNC_REAL(operation_finish)(ctx);
}
FUNC_MOCK_END
static void
sc0_create(PMEMobjpool *pop)
{
PMEMoid oids[3];
TX_BEGIN(pop) {
oids[0] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
oids[1] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
oids[2] = pmemobj_tx_alloc(CHUNKSIZE - 100, 0);
} TX_END
pmemobj_free(&oids[0]);
exit_on_finish = 1;
pmemobj_free(&oids[1]);
}
/*
* noop_verify -- used in cases in which a successful open means that the test
* have passed successfully.
*/
static void
noop_verify(PMEMobjpool *pop)
{
}
typedef void (*scenario_func)(PMEMobjpool *pop);
static struct {
scenario_func create;
scenario_func verify;
} scenarios[] = {
{sc0_create, noop_verify},
};
int
main(int argc, char *argv[])
{
START(argc, argv, "heap_interrupt");
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(heap_interrupt) != 0);
if (argc != 4)
UT_FATAL("usage: %s file [cmd: c/o] [scenario]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
int exists = argv[2][0] == 'o';
int scenario = atoi(argv[3]);
if (!exists) {
if ((pop = pmemobj_create(path,
POBJ_LAYOUT_NAME(heap_interrupt),
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_FATAL("failed to create pool\n");
}
scenarios[scenario].create(pop);
/* if we get here, something is wrong with function mocking */
UT_ASSERT(0);
} else {
if ((pop = pmemobj_open(path,
POBJ_LAYOUT_NAME(heap_interrupt)))
== NULL) {
UT_FATAL("failed to open pool\n");
}
scenarios[scenario].verify(pop);
}
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 3,671 | 26 | 78 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pmalloc_mt/obj_pmalloc_mt.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pmalloc_mt.c -- multithreaded test of allocator
*/
#include <stdint.h>
#include "file.h"
#include "obj.h"
#include "pmalloc.h"
#include "unittest.h"
#define MAX_THREADS 32
#define MAX_OPS_PER_THREAD 1000
#define ALLOC_SIZE 104
#define REALLOC_SIZE (ALLOC_SIZE * 3)
#define MIX_RERUNS 2
#define CHUNKSIZE (1 << 18)
#define CHUNKS_PER_THREAD 3
static unsigned Threads;
static unsigned Ops_per_thread;
static unsigned Tx_per_thread;
struct root {
uint64_t offs[MAX_THREADS][MAX_OPS_PER_THREAD];
};
struct worker_args {
PMEMobjpool *pop;
struct root *r;
unsigned idx;
};
static void *
alloc_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmalloc(a->pop, &a->r->offs[a->idx][i], ALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
realloc_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
prealloc(a->pop, &a->r->offs[a->idx][i], REALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
free_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pfree(a->pop, &a->r->offs[a->idx][i]);
UT_ASSERTeq(a->r->offs[a->idx][i], 0);
}
return NULL;
}
static void *
mix_worker(void *arg)
{
struct worker_args *a = arg;
/*
* The mix scenario is ran twice to increase the chances of run
* contention.
*/
for (unsigned j = 0; j < MIX_RERUNS; ++j) {
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmalloc(a->pop, &a->r->offs[a->idx][i],
ALLOC_SIZE, 0, 0);
UT_ASSERTne(a->r->offs[a->idx][i], 0);
}
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pfree(a->pop, &a->r->offs[a->idx][i]);
UT_ASSERTeq(a->r->offs[a->idx][i], 0);
}
}
return NULL;
}
static void *
tx_worker(void *arg)
{
struct worker_args *a = arg;
/*
* Allocate objects until exhaustion, once that happens the transaction
* will automatically abort and all of the objects will be freed.
*/
TX_BEGIN(a->pop) {
for (unsigned n = 0; ; ++n) { /* this is NOT an infinite loop */
pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
if (Ops_per_thread != MAX_OPS_PER_THREAD &&
n == Ops_per_thread) {
pmemobj_tx_abort(0);
}
}
} TX_END
return NULL;
}
static void *
tx3_worker(void *arg)
{
struct worker_args *a = arg;
/*
* Allocate N objects, abort, repeat M times. Should reveal issues in
* transaction abort handling.
*/
for (unsigned n = 0; n < Tx_per_thread; ++n) {
TX_BEGIN(a->pop) {
for (unsigned i = 0; i < Ops_per_thread; ++i) {
pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
}
pmemobj_tx_abort(EINVAL);
} TX_END
}
return NULL;
}
static void *
alloc_free_worker(void *arg)
{
struct worker_args *a = arg;
PMEMoid oid;
for (unsigned i = 0; i < Ops_per_thread; ++i) {
int err = pmemobj_alloc(a->pop, &oid, ALLOC_SIZE,
0, NULL, NULL);
UT_ASSERTeq(err, 0);
pmemobj_free(&oid);
}
return NULL;
}
#define OPS_PER_TX 10
#define STEP 8
#define TEST_LANES 4
static void *
tx2_worker(void *arg)
{
struct worker_args *a = arg;
for (unsigned n = 0; n < Tx_per_thread; ++n) {
PMEMoid oids[OPS_PER_TX];
TX_BEGIN(a->pop) {
for (int i = 0; i < OPS_PER_TX; ++i) {
oids[i] = pmemobj_tx_alloc(ALLOC_SIZE, a->idx);
for (unsigned j = 0; j < ALLOC_SIZE;
j += STEP) {
pmemobj_tx_add_range(oids[i], j, STEP);
}
}
} TX_END
TX_BEGIN(a->pop) {
for (int i = 0; i < OPS_PER_TX; ++i)
pmemobj_tx_free(oids[i]);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
return NULL;
}
static void
run_worker(void *(worker_func)(void *arg), struct worker_args args[])
{
os_thread_t t[MAX_THREADS];
for (unsigned i = 0; i < Threads; ++i)
os_thread_create(&t[i], NULL, worker_func, &args[i]);
for (unsigned i = 0; i < Threads; ++i)
os_thread_join(&t[i], NULL);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_pmalloc_mt");
if (argc != 5)
UT_FATAL("usage: %s <threads> <ops/t> <tx/t> [file]", argv[0]);
PMEMobjpool *pop;
Threads = ATOU(argv[1]);
if (Threads > MAX_THREADS)
UT_FATAL("Threads %d > %d", Threads, MAX_THREADS);
Ops_per_thread = ATOU(argv[2]);
if (Ops_per_thread > MAX_OPS_PER_THREAD)
UT_FATAL("Ops per thread %d > %d", Threads, MAX_THREADS);
Tx_per_thread = ATOU(argv[3]);
int exists = util_file_exists(argv[4]);
if (exists < 0)
UT_FATAL("!util_file_exists");
if (!exists) {
pop = pmemobj_create(argv[4], "TEST", (PMEMOBJ_MIN_POOL) +
(MAX_THREADS * CHUNKSIZE * CHUNKS_PER_THREAD),
0666);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
} else {
pop = pmemobj_open(argv[4], "TEST");
if (pop == NULL)
UT_FATAL("!pmemobj_open");
}
PMEMoid oid = pmemobj_root(pop, sizeof(struct root));
struct root *r = pmemobj_direct(oid);
UT_ASSERTne(r, NULL);
struct worker_args args[MAX_THREADS];
for (unsigned i = 0; i < Threads; ++i) {
args[i].pop = pop;
args[i].r = r;
args[i].idx = i;
}
run_worker(alloc_worker, args);
run_worker(realloc_worker, args);
run_worker(free_worker, args);
run_worker(mix_worker, args);
run_worker(alloc_free_worker, args);
/*
* Reduce the number of lanes to a value smaller than the number of
* threads. This will ensure that at least some of the state of the lane
* will be shared between threads. Doing this might reveal bugs related
* to runtime race detection instrumentation.
*/
unsigned old_nlanes = pop->lanes_desc.runtime_nlanes;
pop->lanes_desc.runtime_nlanes = TEST_LANES;
run_worker(tx2_worker, args);
pop->lanes_desc.runtime_nlanes = old_nlanes;
/*
* This workload might create many allocation classes due to pvector,
* keep it last.
*/
if (Threads == MAX_THREADS) /* don't run for short tests */
run_worker(tx_worker, args);
run_worker(tx3_worker, args);
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 7,630 | 22.846875 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_alignment/obj_ctl_alignment.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_alignment.c -- tests for the alloc class alignment
*/
#include "unittest.h"
#define LAYOUT "obj_ctl_alignment"
static PMEMobjpool *pop;
static void
test_fail(void)
{
struct pobj_alloc_class_desc ac;
ac.header_type = POBJ_HEADER_NONE;
ac.unit_size = 1024 - 1;
ac.units_per_block = 100;
ac.alignment = 512;
int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &ac);
UT_ASSERTeq(ret, -1); /* unit_size must be multiple of alignment */
}
static void
test_aligned_allocs(size_t size, size_t alignment, enum pobj_header_type htype)
{
struct pobj_alloc_class_desc ac;
ac.header_type = htype;
ac.unit_size = size;
ac.units_per_block = 100;
ac.alignment = alignment;
int ret = pmemobj_ctl_set(pop, "heap.alloc_class.new.desc", &ac);
UT_ASSERTeq(ret, 0);
PMEMoid oid;
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(ac.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(oid.off % alignment, 0);
UT_ASSERTeq((uintptr_t)pmemobj_direct(oid) % alignment, 0);
ret = pmemobj_xalloc(pop, &oid, 1, 0,
POBJ_CLASS_ID(ac.class_id), NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(oid.off % alignment, 0);
UT_ASSERTeq((uintptr_t)pmemobj_direct(oid) % alignment, 0);
char query[1024];
snprintf(query, 1024, "heap.alloc_class.%u.desc", ac.class_id);
struct pobj_alloc_class_desc read_ac;
ret = pmemobj_ctl_get(pop, query, &read_ac);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(ac.alignment, read_ac.alignment);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_alignment");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL * 10,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
test_fail();
test_aligned_allocs(1024, 512, POBJ_HEADER_NONE);
test_aligned_allocs(1024, 512, POBJ_HEADER_COMPACT);
test_aligned_allocs(64, 64, POBJ_HEADER_COMPACT);
pmemobj_close(pop);
DONE(NULL);
}
| 3,565 | 30.557522 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_memalign/vmmalloc_memalign.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_memalign.c -- unit test for libvmmalloc memalign, posix_memalign
* and aligned_alloc (if available)
*
* usage: vmmalloc_memalign [m|p|a]
*/
#include <stdlib.h>
#include <errno.h>
#include "unittest.h"
#include "vmmalloc_dummy_funcs.h"
#define USAGE "usage: %s [m|p|a]"
#define MIN_ALIGN (2)
#define MAX_ALIGN (4L * 1024L * 1024L)
#define MAX_ALLOCS (100)
/* buffer for all allocations */
static int *allocs[MAX_ALLOCS];
static void *(*Aalloc)(size_t alignment, size_t size);
static void *
posix_memalign_wrap(size_t alignment, size_t size)
{
void *ptr;
int err = posix_memalign(&ptr, alignment, size);
/* ignore OOM */
if (err) {
char buff[UT_MAX_ERR_MSG];
ptr = NULL;
ut_strerror(err, buff, UT_MAX_ERR_MSG);
if (err != ENOMEM)
UT_OUT("posix_memalign: %s", buff);
}
return ptr;
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
size_t alignment;
int i;
START(argc, argv, "vmmalloc_memalign");
if (argc != 2)
UT_FATAL(USAGE, argv[0]);
switch (argv[1][0]) {
case 'm':
UT_OUT("testing memalign");
Aalloc = memalign;
break;
case 'p':
UT_OUT("testing posix_memalign");
Aalloc = posix_memalign_wrap;
break;
case 'a':
UT_OUT("testing aligned_alloc");
Aalloc = aligned_alloc;
break;
default:
UT_FATAL(USAGE, argv[0]);
}
/* test with address alignment from 2B to 4MB */
for (alignment = MAX_ALIGN; alignment >= MIN_ALIGN; alignment /= 2) {
UT_OUT("alignment %zu", alignment);
memset(allocs, 0, sizeof(allocs));
for (i = 0; i < MAX_ALLOCS; ++i) {
allocs[i] = Aalloc(alignment, sizeof(int));
if (allocs[i] == NULL)
break;
/* ptr should be usable */
*allocs[i] = test_value;
UT_ASSERTeq(*allocs[i], test_value);
/* check for correct address alignment */
UT_ASSERTeq(
(uintptr_t)(allocs[i]) & (alignment - 1), 0);
}
/* at least one allocation must succeed */
UT_ASSERT(i > 0);
for (i = 0; i < MAX_ALLOCS && allocs[i] != NULL; ++i)
free(allocs[i]);
}
DONE(NULL);
}
| 3,609 | 26.557252 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list/mocks_windows.h | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of obj list functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_list test.
* It would replace default implementation with mocked functions defined
* in obj_list.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#ifdef WRAP_REAL
#define WRAP_REAL_PMALLOC
#define WRAP_REAL_ULOG
#define WRAP_REAL_LANE
#define WRAP_REAL_HEAP
#define WRAP_REAL_PMEMOBJ
#endif
#ifndef WRAP_REAL_PMALLOC
#define pmalloc __wrap_pmalloc
#define pfree __wrap_pfree
#define pmalloc_construct __wrap_pmalloc_construct
#define prealloc __wrap_prealloc
#define prealloc_construct __wrap_prealloc_construct
#define palloc_usable_size __wrap_palloc_usable_size
#define palloc_reserve __wrap_palloc_reserve
#define palloc_publish __wrap_palloc_publish
#define palloc_defer_free __wrap_palloc_defer_free
#endif
#ifndef WRAP_REAL_ULOG
#define ulog_store __wrap_ulog_store
#define ulog_process __wrap_ulog_process
#endif
#ifndef WRAP_REAL_LANE
#define lane_hold __wrap_lane_hold
#define lane_release __wrap_lane_release
#define lane_recover_and_section_boot __wrap_lane_recover_and_section_boot
#define lane_section_cleanup __wrap_lane_section_cleanup
#endif
#ifndef WRAP_REAL_HEAP
#define heap_boot __wrap_heap_boot
#endif
#ifndef WRAP_REAL_PMEMOBJ
#define pmemobj_alloc __wrap_pmemobj_alloc
#define pmemobj_alloc_usable_size __wrap_pmemobj_alloc_usable_size
#define pmemobj_openU __wrap_pmemobj_open
#define pmemobj_close __wrap_pmemobj_close
#define pmemobj_direct __wrap_pmemobj_direct
#define pmemobj_pool_by_oid __wrap_pmemobj_pool_by_oid
#define pmemobj_pool_by_ptr __wrap_pmemobj_pool_by_ptr
#endif
#if defined(__cplusplus)
}
#endif
| 3,448 | 33.838384 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list/obj_list.h | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_list.h -- unit tests for list module
*/
#include <stddef.h>
#include <sys/param.h>
#include "list.h"
#include "obj.h"
#include "lane.h"
#include "unittest.h"
#include "util.h"
/* offset to "in band" item */
#define OOB_OFF (sizeof(struct oob_header))
/* pmemobj initial heap offset */
#define HEAP_OFFSET 8192
TOID_DECLARE(struct item, 0);
TOID_DECLARE(struct list, 1);
TOID_DECLARE(struct oob_list, 2);
TOID_DECLARE(struct oob_item, 3);
struct item {
int id;
POBJ_LIST_ENTRY(struct item) next;
};
struct oob_header {
char data[48];
};
struct oob_item {
struct oob_header oob;
struct item item;
};
struct oob_list {
struct list_head head;
};
struct list {
POBJ_LIST_HEAD(listhead, struct item) head;
};
enum ulog_fail
{
/* don't fail at all */
NO_FAIL,
/* fail after ulog_store */
FAIL_AFTER_FINISH,
/* fail before ulog_store */
FAIL_BEFORE_FINISH,
/* fail after process */
FAIL_AFTER_PROCESS
};
/* global handle to pmemobj pool */
extern PMEMobjpool *Pop;
/* pointer to heap offset */
extern uint64_t *Heap_offset;
/* list lane section */
extern struct lane Lane;
/* actual item id */
extern int *Id;
/* fail event */
extern enum ulog_fail Ulog_fail;
/* global "in band" lists */
extern TOID(struct list) List;
extern TOID(struct list) List_sec;
/* global "out of band" lists */
extern TOID(struct oob_list) List_oob;
extern TOID(struct oob_list) List_oob_sec;
extern TOID(struct oob_item) *Item;
/* usage macros */
#define FATAL_USAGE()\
UT_FATAL("usage: obj_list <file> [PRnifr]")
#define FATAL_USAGE_PRINT()\
UT_FATAL("usage: obj_list <file> P:<list>")
#define FATAL_USAGE_PRINT_REVERSE()\
UT_FATAL("usage: obj_list <file> R:<list>")
#define FATAL_USAGE_INSERT()\
UT_FATAL("usage: obj_list <file> i:<where>:<num>")
#define FATAL_USAGE_INSERT_NEW()\
UT_FATAL("usage: obj_list <file> n:<where>:<num>:<value>")
#define FATAL_USAGE_REMOVE_FREE()\
UT_FATAL("usage: obj_list <file> f:<list>:<num>:<from>")
#define FATAL_USAGE_REMOVE()\
UT_FATAL("usage: obj_list <file> r:<num>")
#define FATAL_USAGE_MOVE()\
UT_FATAL("usage: obj_list <file> m:<num>:<where>:<num>")
#define FATAL_USAGE_FAIL()\
UT_FATAL("usage: obj_list <file> "\
"F:<after_finish|before_finish|after_process>")
| 3,829 | 28.015152 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list/obj_list_mocks.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_list_mocks.c -- mocks for redo/lane/heap/obj modules
*/
#include <inttypes.h>
#include "valgrind_internal.h"
#include "obj_list.h"
#include "set.h"
/*
* pmem_drain_nop -- no operation for drain on non-pmem memory
*/
static void
pmem_drain_nop(void)
{
/* NOP */
}
/*
* obj_persist -- pmemobj version of pmem_persist w/o replication
*/
static int
obj_persist(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->persist_local(addr, len);
return 0;
}
/*
* obj_flush -- pmemobj version of pmem_flush w/o replication
*/
static int
obj_flush(void *ctx, const void *addr, size_t len, unsigned flags)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->flush_local(addr, len);
return 0;
}
static uintptr_t Pool_addr;
static size_t Pool_size;
static void
obj_msync_nofail(const void *addr, size_t size)
{
uintptr_t addr_ptrt = (uintptr_t)addr;
/*
* Verify msynced range is in the last mapped file range. Useful for
* catching errors which normally would be caught only on Windows by
* win_mmap.c.
*/
if (addr_ptrt < Pool_addr || addr_ptrt >= Pool_addr + Pool_size ||
addr_ptrt + size >= Pool_addr + Pool_size)
UT_FATAL("<0x%" PRIxPTR ",0x%" PRIxPTR "> "
"not in <0x%" PRIxPTR ",0x%" PRIxPTR "> range",
addr_ptrt, addr_ptrt + size, Pool_addr,
Pool_addr + Pool_size);
if (pmem_msync(addr, size))
UT_FATAL("!pmem_msync");
}
/*
* obj_drain -- pmemobj version of pmem_drain w/o replication
*/
static void
obj_drain(void *ctx)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
pop->drain_local();
}
static void *
obj_memcpy(void *ctx, void *dest, const void *src, size_t len,
unsigned flags)
{
return pmem_memcpy(dest, src, len, flags);
}
static void *
obj_memset(void *ctx, void *ptr, int c, size_t sz, unsigned flags)
{
return pmem_memset(ptr, c, sz, flags);
}
/*
* linear_alloc -- allocates `size` bytes (rounded up to 8 bytes) and returns
* offset to the allocated object
*/
static uint64_t
linear_alloc(uint64_t *cur_offset, size_t size)
{
uint64_t ret = *cur_offset;
*cur_offset += roundup(size, sizeof(uint64_t));
return ret;
}
/*
* pmemobj_open -- pmemobj_open mock
*
* This function initializes the pmemobj pool for purposes of this
* unittest.
*/
FUNC_MOCK(pmemobj_open, PMEMobjpool *, const char *fname, const char *layout)
FUNC_MOCK_RUN_DEFAULT
{
size_t size;
int is_pmem;
void *addr = pmem_map_file(fname, 0, 0, 0, &size, &is_pmem);
if (!addr) {
UT_OUT("!%s: pmem_map_file", fname);
return NULL;
}
Pool_addr = (uintptr_t)addr;
Pool_size = size;
Pop = (PMEMobjpool *)addr;
Pop->addr = Pop;
Pop->is_pmem = is_pmem;
Pop->rdonly = 0;
Pop->uuid_lo = 0x12345678;
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->mutex_head,
sizeof(Pop->mutex_head));
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->rwlock_head,
sizeof(Pop->rwlock_head));
VALGRIND_REMOVE_PMEM_MAPPING(&Pop->cond_head,
sizeof(Pop->cond_head));
Pop->mutex_head = NULL;
Pop->rwlock_head = NULL;
Pop->cond_head = NULL;
if (Pop->is_pmem) {
Pop->persist_local = pmem_persist;
Pop->flush_local = pmem_flush;
Pop->drain_local = pmem_drain;
Pop->memcpy_local = pmem_memcpy;
Pop->memset_local = pmem_memset;
} else {
Pop->persist_local = obj_msync_nofail;
Pop->flush_local = obj_msync_nofail;
Pop->drain_local = pmem_drain_nop;
Pop->memcpy_local = pmem_memcpy;
Pop->memset_local = pmem_memset;
}
Pop->p_ops.persist = obj_persist;
Pop->p_ops.flush = obj_flush;
Pop->p_ops.drain = obj_drain;
Pop->p_ops.memcpy = obj_memcpy;
Pop->p_ops.memset = obj_memset;
Pop->p_ops.base = Pop;
struct pmem_ops *p_ops = &Pop->p_ops;
Pop->heap_offset = HEAP_OFFSET;
Pop->heap_size = size - Pop->heap_offset;
uint64_t heap_offset = HEAP_OFFSET;
Heap_offset = (uint64_t *)((uintptr_t)Pop +
linear_alloc(&heap_offset, sizeof(*Heap_offset)));
Id = (int *)((uintptr_t)Pop + linear_alloc(&heap_offset, sizeof(*Id)));
/* Alloc lane layout */
Lane.layout = (struct lane_layout *)((uintptr_t)Pop +
linear_alloc(&heap_offset, LANE_TOTAL_SIZE));
/* Alloc in band lists */
List.oid.pool_uuid_lo = Pop->uuid_lo;
List.oid.off = linear_alloc(&heap_offset, sizeof(struct list));
List_sec.oid.pool_uuid_lo = Pop->uuid_lo;
List_sec.oid.off = linear_alloc(&heap_offset, sizeof(struct list));
/* Alloc out of band lists */
List_oob.oid.pool_uuid_lo = Pop->uuid_lo;
List_oob.oid.off = linear_alloc(&heap_offset, sizeof(struct oob_list));
List_oob_sec.oid.pool_uuid_lo = Pop->uuid_lo;
List_oob_sec.oid.off =
linear_alloc(&heap_offset, sizeof(struct oob_list));
Item = (union oob_item_toid *)((uintptr_t)Pop +
linear_alloc(&heap_offset, sizeof(*Item)));
Item->oid.pool_uuid_lo = Pop->uuid_lo;
Item->oid.off = linear_alloc(&heap_offset, sizeof(struct oob_item));
pmemops_persist(p_ops, Item, sizeof(*Item));
if (*Heap_offset == 0) {
*Heap_offset = heap_offset;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
}
pmemops_persist(p_ops, Pop, HEAP_OFFSET);
Pop->run_id += 2;
pmemops_persist(p_ops, &Pop->run_id, sizeof(Pop->run_id));
Lane.external = operation_new((struct ulog *)&Lane.layout->external,
LANE_REDO_EXTERNAL_SIZE, NULL, NULL, p_ops, LOG_TYPE_REDO);
return Pop;
}
FUNC_MOCK_END
/*
* pmemobj_close -- pmemobj_close mock
*
* Just unmap the mapped area.
*/
FUNC_MOCK(pmemobj_close, void, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
operation_delete(Lane.external);
UT_ASSERTeq(pmem_unmap(Pop,
Pop->heap_size + Pop->heap_offset), 0);
Pop = NULL;
Pool_addr = 0;
Pool_size = 0;
}
FUNC_MOCK_END
/*
* pmemobj_pool_by_ptr -- pmemobj_pool_by_ptr mock
*
* Just return Pop.
*/
FUNC_MOCK_RET_ALWAYS(pmemobj_pool_by_ptr, PMEMobjpool *, Pop, const void *ptr);
/*
* pmemobj_direct -- pmemobj_direct mock
*/
FUNC_MOCK(pmemobj_direct, void *, PMEMoid oid)
FUNC_MOCK_RUN_DEFAULT {
return (void *)((uintptr_t)Pop + oid.off);
}
FUNC_MOCK_END
FUNC_MOCK_RET_ALWAYS(pmemobj_pool_by_oid, PMEMobjpool *, Pop, PMEMoid oid);
/*
* pmemobj_alloc_usable_size -- pmemobj_alloc_usable_size mock
*/
FUNC_MOCK(pmemobj_alloc_usable_size, size_t, PMEMoid oid)
FUNC_MOCK_RUN_DEFAULT {
size_t size = palloc_usable_size(
&Pop->heap, oid.off - OOB_OFF);
return size - OOB_OFF;
}
FUNC_MOCK_END
/*
* pmemobj_alloc -- pmemobj_alloc mock
*
* Allocates an object using pmalloc and return PMEMoid.
*/
FUNC_MOCK(pmemobj_alloc, int, PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num,
pmemobj_constr constructor, void *arg)
FUNC_MOCK_RUN_DEFAULT {
PMEMoid oid = {0, 0};
oid.pool_uuid_lo = 0;
pmalloc(pop, &oid.off, size, 0, 0);
if (oidp) {
*oidp = oid;
if (OBJ_PTR_FROM_POOL(pop, oidp))
pmemops_persist(&Pop->p_ops, oidp,
sizeof(*oidp));
}
return 0;
}
FUNC_MOCK_END
/*
* lane_hold -- lane_hold mock
*
* Returns pointer to list lane section.
*/
FUNC_MOCK(lane_hold, unsigned, PMEMobjpool *pop, struct lane **lane)
FUNC_MOCK_RUN_DEFAULT {
*lane = &Lane;
return 0;
}
FUNC_MOCK_END
/*
* lane_release -- lane_release mock
*
* Always returns success.
*/
FUNC_MOCK_RET_ALWAYS_VOID(lane_release, PMEMobjpool *pop);
/*
* lane_recover_and_section_boot -- lane_recover_and_section_boot mock
*/
FUNC_MOCK(lane_recover_and_section_boot, int, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
ulog_recover((struct ulog *)&Lane.layout->external,
OBJ_OFF_IS_VALID_FROM_CTX, &pop->p_ops);
return 0;
}
FUNC_MOCK_END
/*
* lane_section_cleanup -- lane_section_cleanup mock
*/
FUNC_MOCK(lane_section_cleanup, int, PMEMobjpool *pop)
FUNC_MOCK_RUN_DEFAULT {
return 0;
}
FUNC_MOCK_END
/*
* ulog_store_last -- ulog_store_last mock
*/
FUNC_MOCK(ulog_store, void,
struct ulog *dest,
struct ulog *src, size_t nbytes, size_t redo_base_nbytes,
struct ulog_next *next, const struct pmem_ops *p_ops)
FUNC_MOCK_RUN_DEFAULT {
switch (Ulog_fail) {
case FAIL_AFTER_FINISH:
_FUNC_REAL(ulog_store)(dest, src,
nbytes, redo_base_nbytes,
next, p_ops);
DONEW(NULL);
break;
case FAIL_BEFORE_FINISH:
DONEW(NULL);
break;
default:
_FUNC_REAL(ulog_store)(dest, src,
nbytes, redo_base_nbytes,
next, p_ops);
break;
}
}
FUNC_MOCK_END
/*
* ulog_process -- ulog_process mock
*/
FUNC_MOCK(ulog_process, void, struct ulog *ulog,
ulog_check_offset_fn check, const struct pmem_ops *p_ops)
FUNC_MOCK_RUN_DEFAULT {
_FUNC_REAL(ulog_process)(ulog, check, p_ops);
if (Ulog_fail == FAIL_AFTER_PROCESS) {
DONEW(NULL);
}
}
FUNC_MOCK_END
/*
* heap_boot -- heap_boot mock
*
* Always returns success.
*/
FUNC_MOCK_RET_ALWAYS(heap_boot, int, 0, PMEMobjpool *pop);
| 10,203 | 24.702771 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list/obj_list_mocks_palloc.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_list_mocks_palloc.c -- mocks for palloc/pmalloc modules
*/
#include "obj_list.h"
/*
* pmalloc -- pmalloc mock
*
* Allocates the memory using linear allocator.
* Prints the id of allocated struct oob_item for tracking purposes.
*/
FUNC_MOCK(pmalloc, int, PMEMobjpool *pop, uint64_t *ptr,
size_t size, uint64_t extra_field, uint16_t flags)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop
+ *Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
*ptr = *Heap_offset + sizeof(uint64_t);
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(p_ops, ptr, sizeof(*ptr));
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + *ptr);
*ptr += OOB_OFF;
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(p_ops, ptr, sizeof(*ptr));
item->item.id = *Id;
pmemops_persist(p_ops, &item->item.id, sizeof(item->item.id));
(*Id)++;
pmemops_persist(p_ops, Id, sizeof(*Id));
*Heap_offset = *Heap_offset + sizeof(uint64_t) +
size + OOB_OFF;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
UT_OUT("pmalloc(id = %d)", item->item.id);
return 0;
}
FUNC_MOCK_END
/*
* pfree -- pfree mock
*
* Just prints freeing struct oob_item id. Doesn't free the memory.
*/
FUNC_MOCK(pfree, void, PMEMobjpool *pop, uint64_t *ptr)
FUNC_MOCK_RUN_DEFAULT {
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + *ptr - OOB_OFF);
UT_OUT("pfree(id = %d)", item->item.id);
*ptr = 0;
if (OBJ_PTR_FROM_POOL(pop, ptr))
pmemops_persist(&Pop->p_ops, ptr, sizeof(*ptr));
return;
}
FUNC_MOCK_END
/*
* pmalloc_construct -- pmalloc_construct mock
*
* Allocates the memory using linear allocator and invokes the constructor.
* Prints the id of allocated struct oob_item for tracking purposes.
*/
FUNC_MOCK(pmalloc_construct, int, PMEMobjpool *pop, uint64_t *off,
size_t size, palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t flags, uint16_t class_id)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
*Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
*off = *Heap_offset + sizeof(uint64_t) + OOB_OFF;
if (OBJ_PTR_FROM_POOL(pop, off))
pmemops_persist(p_ops, off, sizeof(*off));
*Heap_offset = *Heap_offset + sizeof(uint64_t) + size;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
void *ptr = (void *)((uintptr_t)Pop + *off);
constructor(pop, ptr, size, arg);
return 0;
}
FUNC_MOCK_END
/*
* prealloc -- prealloc mock
*/
FUNC_MOCK(prealloc, int, PMEMobjpool *pop, uint64_t *off, size_t size,
uint64_t extra_field, uint16_t flags)
FUNC_MOCK_RUN_DEFAULT {
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
*off - sizeof(uint64_t));
struct item *item = (struct item *)((uintptr_t)Pop +
*off + OOB_OFF);
if (*alloc_size >= size) {
*alloc_size = size;
pmemops_persist(&Pop->p_ops, alloc_size,
sizeof(*alloc_size));
UT_OUT("prealloc(id = %d, size = %zu) = true",
item->id,
(size - OOB_OFF) / sizeof(struct item));
return 0;
} else {
UT_OUT("prealloc(id = %d, size = %zu) = false",
item->id,
(size - OOB_OFF) / sizeof(struct item));
return -1;
}
}
FUNC_MOCK_END
/*
* prealloc_construct -- prealloc_construct mock
*/
FUNC_MOCK(prealloc_construct, int, PMEMobjpool *pop, uint64_t *off,
size_t size, palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t flags, uint16_t class_id)
FUNC_MOCK_RUN_DEFAULT {
int ret = __wrap_prealloc(pop, off, size, 0, 0);
if (!ret) {
void *ptr = (void *)((uintptr_t)Pop + *off + OOB_OFF);
constructor(pop, ptr, size, arg);
}
return ret;
}
FUNC_MOCK_END
/*
* palloc_reserve -- palloc_reserve mock
*/
FUNC_MOCK(palloc_reserve, int, struct palloc_heap *heap, size_t size,
palloc_constr constructor, void *arg,
uint64_t extra_field, uint16_t object_flags, uint16_t class_id,
struct pobj_action *act)
FUNC_MOCK_RUN_DEFAULT {
struct pmem_ops *p_ops = &Pop->p_ops;
size = size + OOB_OFF + sizeof(uint64_t) * 2;
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop
+ *Heap_offset);
*alloc_size = size;
pmemops_persist(p_ops, alloc_size, sizeof(*alloc_size));
act->heap.offset = *Heap_offset + sizeof(uint64_t);
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + act->heap.offset);
act->heap.offset += OOB_OFF;
item->item.id = *Id;
pmemops_persist(p_ops, &item->item.id, sizeof(item->item.id));
(*Id)++;
pmemops_persist(p_ops, Id, sizeof(*Id));
*Heap_offset += sizeof(uint64_t) + size + OOB_OFF;
pmemops_persist(p_ops, Heap_offset, sizeof(*Heap_offset));
UT_OUT("pmalloc(id = %d)", item->item.id);
return 0;
}
FUNC_MOCK_END
/*
* palloc_publish -- mock publish, must process operation
*/
FUNC_MOCK(palloc_publish, void, struct palloc_heap *heap,
struct pobj_action *actv, size_t actvcnt,
struct operation_context *ctx)
FUNC_MOCK_RUN_DEFAULT {
operation_finish(ctx);
}
FUNC_MOCK_END
/*
* palloc_defer_free -- pfree mock
*
* Just prints freeing struct oob_item id. Doesn't free the memory.
*/
FUNC_MOCK(palloc_defer_free, void, struct palloc_heap *heap, uint64_t off,
struct pobj_action *act)
FUNC_MOCK_RUN_DEFAULT {
struct oob_item *item =
(struct oob_item *)((uintptr_t)Pop + off - OOB_OFF);
UT_OUT("pfree(id = %d)", item->item.id);
act->heap.offset = off;
return;
}
FUNC_MOCK_END
/*
* pmalloc_usable_size -- pmalloc_usable_size mock
*/
FUNC_MOCK(palloc_usable_size, size_t, struct palloc_heap *heap, uint64_t off)
FUNC_MOCK_RUN_DEFAULT {
uint64_t *alloc_size = (uint64_t *)((uintptr_t)Pop +
off - sizeof(uint64_t));
return (size_t)*alloc_size;
}
FUNC_MOCK_END
| 7,517 | 29.560976 | 77 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_list/obj_list.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_list.c -- unit tests for list module
*/
/*
* XXX - On VC++, this file must be compiled as C++ to have __typeof__ defined.
* However, the rest of the files (libpmemobj source) are still compiled as C.
* To avoid issues with 'C' linkage the entire file is in 'extern "C"' block.
*/
#if defined(__cplusplus) && defined(_MSC_VER)
extern "C" {
/*
* XXX - Templates cannot be used with 'C' linkage, so for the purpose
* of this test, we override template-based definition of __typeof__ with
* a simple alias to decltype.
*/
#define __typeof__(p) decltype(p)
#endif
#include "obj_list.h"
/* global handle to pmemobj pool */
PMEMobjpool *Pop;
/* pointer to heap offset */
uint64_t *Heap_offset;
/* list lane section */
struct lane Lane;
/* actual item id */
int *Id;
/* fail event */
enum ulog_fail Ulog_fail = NO_FAIL;
/* global "in band" lists */
TOID(struct list) List;
TOID(struct list) List_sec;
/* global "out of band" lists */
TOID(struct oob_list) List_oob;
TOID(struct oob_list) List_oob_sec;
TOID(struct oob_item) *Item;
/*
* for each element on list in normal order
*/
#define PLIST_FOREACH(item, list, head, field)\
for ((item) = \
D_RW((list))->head.pe_first;\
!TOID_IS_NULL((item));\
TOID_ASSIGN((item),\
TOID_EQUALS((item),\
D_RW(D_RW((list))->head.pe_first)->field.pe_prev) ?\
OID_NULL : \
D_RW(item)->field.pe_next.oid))
/*
* for each element on list in reverse order
*/
#define PLIST_FOREACH_REVERSE(item, list, head, field)\
for ((item) = \
TOID_IS_NULL(D_RW((list))->head.pe_first) ? D_RW(list)->head.pe_first :\
D_RW(D_RW(list)->head.pe_first)->field.pe_prev;\
!TOID_IS_NULL((item));\
TOID_ASSIGN((item),\
TOID_EQUALS((item),\
D_RW((list))->head.pe_first) ?\
OID_NULL :\
D_RW(item)->field.pe_prev.oid))
/*
* get_item_list -- get nth item from list
*/
static PMEMoid
get_item_list(PMEMoid head, int n)
{
TOID(struct list) list;
TOID_ASSIGN(list, head);
TOID(struct item) item;
if (n >= 0) {
PLIST_FOREACH(item, list, head, next) {
if (n == 0)
return item.oid;
n--;
}
} else {
PLIST_FOREACH_REVERSE(item, list, head, next) {
n++;
if (n == 0)
return item.oid;
}
}
return OID_NULL;
}
/*
* do_print -- print list elements in normal order
*/
static void
do_print(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "P:%d", &L) != 1)
FATAL_USAGE_PRINT();
if (L == 2) {
TOID(struct item) item;
UT_OUT("list:");
PLIST_FOREACH(item, List, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 4) {
TOID(struct item) item;
UT_OUT("list sec:");
PLIST_FOREACH(item, List_sec, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT();
}
}
/*
* do_print_reverse -- print list elements in reverse order
*/
static void
do_print_reverse(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
if (sscanf(arg, "R:%d", &L) != 1)
FATAL_USAGE_PRINT_REVERSE();
if (L == 2) {
TOID(struct item) item;
UT_OUT("list reverse:");
PLIST_FOREACH_REVERSE(item, List, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else if (L == 4) {
TOID(struct item) item;
UT_OUT("list sec reverse:");
PLIST_FOREACH_REVERSE(item, List_sec, head, next) {
UT_OUT("id = %d", D_RO(item)->id);
}
} else {
FATAL_USAGE_PRINT_REVERSE();
}
}
/*
* item_constructor -- constructor which sets the item's id to
* new value
*/
static int
item_constructor(void *ctx, void *ptr, size_t usable_size, void *arg)
{
PMEMobjpool *pop = (PMEMobjpool *)ctx;
int id = *(int *)arg;
struct item *item = (struct item *)ptr;
item->id = id;
pmemops_persist(&pop->p_ops, &item->id, sizeof(item->id));
UT_OUT("constructor(id = %d)", id);
return 0;
}
struct realloc_arg {
void *ptr;
size_t new_size;
size_t old_size;
};
/*
* do_insert_new -- insert new element to list
*/
static void
do_insert_new(PMEMobjpool *pop, const char *arg)
{
int n; /* which element on List */
int before;
int id;
int ret = sscanf(arg, "n:%d:%d:%d", &before, &n, &id);
if (ret == 3) {
ret = list_insert_new_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
sizeof(struct item),
TOID_TYPE_NUM(struct item),
item_constructor,
&id, (PMEMoid *)Item);
if (ret)
UT_FATAL("list_insert_new(List, List_oob) failed");
} else if (ret == 2) {
ret = list_insert_new_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
sizeof(struct item),
TOID_TYPE_NUM(struct item),
NULL, NULL, (PMEMoid *)Item);
if (ret)
UT_FATAL("list_insert_new(List, List_oob) failed");
} else {
FATAL_USAGE_INSERT_NEW();
}
}
/*
* do_insert -- insert element to list
*/
static void
do_insert(PMEMobjpool *pop, const char *arg)
{
int before;
int n; /* which element */
if (sscanf(arg, "i:%d:%d",
&before, &n) != 2)
FATAL_USAGE_INSERT();
PMEMoid it;
pmemobj_alloc(pop, &it,
sizeof(struct oob_item), 0, NULL, NULL);
if (list_insert(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n),
before,
it)) {
UT_FATAL("list_insert(List) failed");
}
}
/*
* do_remove_free -- remove and free element from list
*/
static void
do_remove_free(PMEMobjpool *pop, const char *arg)
{
int L; /* which list */
int n; /* which element */
int N; /* remove from single/both lists */
if (sscanf(arg, "f:%d:%d:%d", &L, &n, &N) != 3)
FATAL_USAGE_REMOVE_FREE();
PMEMoid oid;
if (L == 2) {
oid = get_item_list(List.oid, n);
} else {
FATAL_USAGE_REMOVE_FREE();
}
if (N == 1) {
if (list_remove_free_user(pop,
0,
NULL,
&oid)) {
UT_FATAL("list_remove_free(List_oob) failed");
}
} else if (N == 2) {
if (list_remove_free_user(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
&oid)) {
UT_FATAL("list_remove_free(List_oob, List) failed");
}
} else {
FATAL_USAGE_REMOVE_FREE();
}
}
/*
* do_remove -- remove element from list
*/
static void
do_remove(PMEMobjpool *pop, const char *arg)
{
int n; /* which element */
if (sscanf(arg, "r:%d", &n) != 1)
FATAL_USAGE_REMOVE();
if (list_remove(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, n))) {
UT_FATAL("list_remove(List) failed");
}
}
/*
* do_move -- move element from one list to another
*/
static void
do_move(PMEMobjpool *pop, const char *arg)
{
int n;
int d;
int before;
if (sscanf(arg, "m:%d:%d:%d", &n, &before, &d) != 3)
FATAL_USAGE_MOVE();
if (list_move(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
offsetof(struct item, next),
(struct list_head *)&D_RW(List_sec)->head,
get_item_list(List_sec.oid, d),
before,
get_item_list(List.oid, n))) {
UT_FATAL("list_move(List, List_sec) failed");
}
}
/*
* do_move_one_list -- move element within one list
*/
static void
do_move_one_list(PMEMobjpool *pop, const char *arg)
{
int n;
int d;
int before;
if (sscanf(arg, "M:%d:%d:%d", &n, &before, &d) != 3)
FATAL_USAGE_MOVE();
if (list_move(pop,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
offsetof(struct item, next),
(struct list_head *)&D_RW(List)->head,
get_item_list(List.oid, d),
before,
get_item_list(List.oid, n))) {
UT_FATAL("list_move(List, List) failed");
}
}
/*
* do_fail -- fail after specified event
*/
static void
do_fail(PMEMobjpool *pop, const char *arg)
{
if (strcmp(arg, "F:before_finish") == 0) {
Ulog_fail = FAIL_BEFORE_FINISH;
} else if (strcmp(arg, "F:after_finish") == 0) {
Ulog_fail = FAIL_AFTER_FINISH;
} else if (strcmp(arg, "F:after_process") == 0) {
Ulog_fail = FAIL_AFTER_PROCESS;
} else {
FATAL_USAGE_FAIL();
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_list");
if (argc < 2)
FATAL_USAGE();
const char *path = argv[1];
util_init(); /* to initialize On_valgrind flag */
UT_COMPILE_ERROR_ON(OOB_OFF != 48);
PMEMobjpool *pop = pmemobj_open(path, NULL);
UT_ASSERTne(pop, NULL);
UT_ASSERT(!TOID_IS_NULL(List));
UT_ASSERT(!TOID_IS_NULL(List_oob));
int i;
for (i = 2; i < argc; i++) {
switch (argv[i][0]) {
case 'P':
do_print(pop, argv[i]);
break;
case 'R':
do_print_reverse(pop, argv[i]);
break;
case 'n':
do_insert_new(pop, argv[i]);
break;
case 'i':
do_insert(pop, argv[i]);
break;
case 'f':
do_remove_free(pop, argv[i]);
break;
case 'r':
do_remove(pop, argv[i]);
break;
case 'm':
do_move(pop, argv[i]);
break;
case 'M':
do_move_one_list(pop, argv[i]);
break;
case 'V':
lane_recover_and_section_boot(pop);
break;
case 'F':
do_fail(pop, argv[i]);
break;
default:
FATAL_USAGE();
}
}
pmemobj_close(pop);
DONE(NULL);
}
#if defined(__cplusplus) && defined(_MSC_VER)
}
#endif
| 10,502 | 21.882353 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/blk_rw_mt/blk_rw_mt.c | /*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* blk_rw_mt.c -- unit test for multi-threaded random I/O
*
* usage: blk_rw_mt bsize file seed nthread nops
*
*/
#include "unittest.h"
static size_t Bsize;
/* all I/O below this LBA (increases collisions) */
static const unsigned Nblock = 100;
static unsigned Seed;
static unsigned Nthread;
static unsigned Nops;
static PMEMblkpool *Handle;
/*
* construct -- build a buffer for writing
*/
static void
construct(int *ordp, unsigned char *buf)
{
for (int i = 0; i < Bsize; i++)
buf[i] = *ordp;
(*ordp)++;
if (*ordp > 255)
*ordp = 1;
}
/*
* check -- check for torn buffers
*/
static void
check(unsigned char *buf)
{
unsigned val = *buf;
for (int i = 1; i < Bsize; i++)
if (buf[i] != val) {
UT_OUT("{%u} TORN at byte %d", val, i);
break;
}
}
/*
* worker -- the work each thread performs
*/
static void *
worker(void *arg)
{
long mytid = (long)(intptr_t)arg;
unsigned myseed = Seed + mytid;
unsigned char *buf = MALLOC(Bsize);
int ord = 1;
for (unsigned i = 0; i < Nops; i++) {
os_off_t lba = os_rand_r(&myseed) % Nblock;
if (os_rand_r(&myseed) % 2) {
/* read */
if (pmemblk_read(Handle, buf, lba) < 0)
UT_OUT("!read lba %zu", lba);
else
check(buf);
} else {
/* write */
construct(&ord, buf);
if (pmemblk_write(Handle, buf, lba) < 0)
UT_OUT("!write lba %zu", lba);
}
}
FREE(buf);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "blk_rw_mt");
if (argc != 6)
UT_FATAL("usage: %s bsize file seed nthread nops", argv[0]);
Bsize = strtoul(argv[1], NULL, 0);
const char *path = argv[2];
if ((Handle = pmemblk_create(path, Bsize, 0,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!%s: pmemblk_create", path);
Seed = strtoul(argv[3], NULL, 0);
Nthread = strtoul(argv[4], NULL, 0);
Nops = strtoul(argv[5], NULL, 0);
UT_OUT("%s block size %zu usable blocks %u", argv[1], Bsize, Nblock);
os_thread_t *threads = MALLOC(Nthread * sizeof(os_thread_t));
/* kick off nthread threads */
for (unsigned i = 0; i < Nthread; i++)
PTHREAD_CREATE(&threads[i], NULL, worker, (void *)(intptr_t)i);
/* wait for all the threads to complete */
for (unsigned i = 0; i < Nthread; i++)
PTHREAD_JOIN(&threads[i], NULL);
FREE(threads);
pmemblk_close(Handle);
/* XXX not ready to pass this part of the test yet */
int result = pmemblk_check(path, Bsize);
if (result < 0)
UT_OUT("!%s: pmemblk_check", path);
else if (result == 0)
UT_OUT("%s: pmemblk_check: not consistent", path);
DONE(NULL);
}
| 4,184 | 25.487342 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/set_funcs/set_funcs.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* set_funcs.c -- unit test for pmem*_set_funcs()
*/
#include "unittest.h"
#define EXISTING_FILE "/root"
#define NON_ZERO_POOL_SIZE 1
#define GUARD 0x2BEE5AFEULL
#define EXTRA sizeof(GUARD)
#define OBJ 0
#define BLK 1
#define LOG 2
#define CTO 3
#define VMEM_ 4
#define VMEM_POOLS 4
static struct counters {
int mallocs;
int frees;
int reallocs;
int reallocs_null;
int strdups;
} cnt[5];
static void *
test_malloc(size_t size)
{
unsigned long long *p = malloc(size + EXTRA);
UT_ASSERTne(p, NULL);
*p = GUARD;
return ++p;
}
static void
test_free(void *ptr)
{
if (ptr == NULL)
return;
unsigned long long *p = ptr;
--p;
UT_ASSERTeq(*p, GUARD);
free(p);
}
static void *
test_realloc(void *ptr, size_t size)
{
unsigned long long *p;
if (ptr != NULL) {
p = ptr;
--p;
UT_ASSERTeq(*p, GUARD);
p = realloc(p, size + EXTRA);
} else {
p = malloc(size + EXTRA);
}
UT_ASSERTne(p, NULL);
*p = GUARD;
return ++p;
}
static char *
test_strdup(const char *s)
{
if (s == NULL)
return NULL;
size_t size = strlen(s) + 1;
unsigned long long *p = malloc(size + EXTRA);
UT_ASSERTne(p, NULL);
*p = GUARD;
++p;
strcpy((char *)p, s);
return (char *)p;
}
static void *
obj_malloc(size_t size)
{
cnt[OBJ].mallocs++;
return test_malloc(size);
}
static void
obj_free(void *ptr)
{
if (ptr)
cnt[OBJ].frees++;
test_free(ptr);
}
static void *
obj_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[OBJ].reallocs_null++;
else
cnt[OBJ].reallocs++;
return test_realloc(ptr, size);
}
static char *
obj_strdup(const char *s)
{
cnt[OBJ].strdups++;
return test_strdup(s);
}
static void *
blk_malloc(size_t size)
{
cnt[BLK].mallocs++;
return test_malloc(size);
}
static void
blk_free(void *ptr)
{
if (ptr)
cnt[BLK].frees++;
test_free(ptr);
}
static void *
blk_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[BLK].reallocs_null++;
else
cnt[BLK].reallocs++;
return test_realloc(ptr, size);
}
static char *
blk_strdup(const char *s)
{
cnt[BLK].strdups++;
return test_strdup(s);
}
static void *
log_malloc(size_t size)
{
cnt[LOG].mallocs++;
return test_malloc(size);
}
static void
log_free(void *ptr)
{
if (ptr)
cnt[LOG].frees++;
test_free(ptr);
}
static void *
log_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[LOG].reallocs_null++;
else
cnt[LOG].reallocs++;
return test_realloc(ptr, size);
}
static char *
log_strdup(const char *s)
{
cnt[LOG].strdups++;
return test_strdup(s);
}
static void *
_vmem_malloc(size_t size)
{
cnt[VMEM_].mallocs++;
return test_malloc(size);
}
static void
_vmem_free(void *ptr)
{
if (ptr)
cnt[VMEM_].frees++;
test_free(ptr);
}
static void *
_vmem_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[VMEM_].reallocs_null++;
else
cnt[VMEM_].reallocs++;
return test_realloc(ptr, size);
}
static char *
_vmem_strdup(const char *s)
{
cnt[VMEM_].strdups++;
return test_strdup(s);
}
static void *
cto_malloc(size_t size)
{
cnt[CTO].mallocs++;
return test_malloc(size);
}
static void
cto_free(void *ptr)
{
if (ptr)
cnt[CTO].frees++;
test_free(ptr);
}
static void *
cto_realloc(void *ptr, size_t size)
{
if (ptr == NULL)
cnt[CTO].reallocs_null++;
else
cnt[CTO].reallocs++;
return test_realloc(ptr, size);
}
static char *
cto_strdup(const char *s)
{
cnt[CTO].strdups++;
return test_strdup(s);
}
/*
* There are a few allocations made at first call to pmemobj_open() or
* pmemobj_create(). They are related to some global structures
* holding a list of all open pools. These allocation are not released on
* pmemobj_close(), but in the library destructor. So, we need to take them
* into account when detecting memory leaks.
*
* obj_init/obj_pool_init:
* cuckoo_new - Malloc + Zalloc
* ctree_new - Malloc
* lane_info_ht_boot/lane_info_create:
* cuckoo_new - Malloc + Zalloc
*/
#define OBJ_EXTRA_NALLOC 5
static void
test_obj(const char *path)
{
pmemobj_set_funcs(obj_malloc, obj_free, obj_realloc, obj_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemobj_create(EXISTING_FILE, "", NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMobjpool *pop;
pop = pmemobj_create(path, NULL, PMEMOBJ_MIN_POOL, 0600);
PMEMoid oid;
if (pmemobj_alloc(pop, &oid, 10, 0, NULL, NULL))
UT_FATAL("!alloc");
if (pmemobj_realloc(pop, &oid, 100, 0))
UT_FATAL("!realloc");
pmemobj_free(&oid);
pmemobj_close(pop);
UT_OUT("obj_mallocs: %d", cnt[OBJ].mallocs);
UT_OUT("obj_frees: %d", cnt[OBJ].frees);
UT_OUT("obj_reallocs: %d", cnt[OBJ].reallocs);
UT_OUT("obj_reallocs_null: %d", cnt[OBJ].reallocs_null);
UT_OUT("obj_strdups: %d", cnt[OBJ].strdups);
if (cnt[OBJ].mallocs == 0 || cnt[OBJ].frees == 0)
UT_FATAL("OBJ mallocs: %d, frees: %d", cnt[OBJ].mallocs,
cnt[OBJ].frees);
for (int i = 0; i < 5; ++i) {
if (i == OBJ)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("OBJ allocation used %d functions", i);
}
if (cnt[OBJ].mallocs + cnt[OBJ].strdups + cnt[OBJ].reallocs_null !=
cnt[OBJ].frees + OBJ_EXTRA_NALLOC)
UT_FATAL("OBJ memory leak");
UNLINK(path);
}
static void
test_blk(const char *path)
{
pmemblk_set_funcs(blk_malloc, blk_free, blk_realloc, blk_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemblk_create(EXISTING_FILE, 0, NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMblkpool *blk = pmemblk_create(path, 512, PMEMBLK_MIN_POOL, 0600);
pmemblk_close(blk);
UT_OUT("blk_mallocs: %d", cnt[BLK].mallocs);
UT_OUT("blk_frees: %d", cnt[BLK].frees);
UT_OUT("blk_reallocs: %d", cnt[BLK].reallocs);
UT_OUT("blk_reallocs_null: %d", cnt[BLK].reallocs_null);
UT_OUT("blk_strdups: %d", cnt[BLK].strdups);
if (cnt[BLK].mallocs == 0 || cnt[BLK].frees == 0)
UT_FATAL("BLK mallocs: %d, frees: %d", cnt[BLK].mallocs,
cnt[BLK].frees);
for (int i = 0; i < 5; ++i) {
if (i == BLK)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("BLK allocation used %d functions", i);
}
if (cnt[BLK].mallocs + cnt[BLK].strdups + cnt[BLK].reallocs_null
!= cnt[BLK].frees)
UT_FATAL("BLK memory leak");
UNLINK(path);
}
static void
test_log(const char *path)
{
pmemlog_set_funcs(log_malloc, log_free, log_realloc, log_strdup);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemlog_create(EXISTING_FILE, NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMlogpool *log = pmemlog_create(path, PMEMLOG_MIN_POOL, 0600);
pmemlog_close(log);
UT_OUT("log_mallocs: %d", cnt[LOG].mallocs);
UT_OUT("log_frees: %d", cnt[LOG].frees);
UT_OUT("log_reallocs: %d", cnt[LOG].reallocs);
UT_OUT("log_reallocs_null: %d", cnt[LOG].reallocs_null);
UT_OUT("log_strdups: %d", cnt[LOG].strdups);
if (cnt[LOG].mallocs == 0 || cnt[LOG].frees == 0)
UT_FATAL("LOG mallocs: %d, frees: %d", cnt[LOG].mallocs,
cnt[LOG].frees);
for (int i = 0; i < 5; ++i) {
if (i == LOG)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("LOG allocation used %d functions", i);
}
if (cnt[LOG].mallocs + cnt[LOG].strdups + cnt[LOG].reallocs_null
!= cnt[LOG].frees)
UT_FATAL("LOG memory leak");
UNLINK(path);
}
/*
* There are a few allocations made at first call to pmemcto_malloc(),
* pmemcto_realloc(), etc.
* They are related to some global jemalloc structures in TSD, holding
* a list of all open pools. These allocation are not released on
* pmemcto_close(), but in the library destructor. So, we need to take them
* into account when detecting memory leaks.
* Same applies to errormsg buffer, which is allocated on the first error
* and released in library dtor.
*
* tcache_tsd - 2 * Zalloc
* areanas_tsd - 2 * Zalloc
*/
#define CTO_EXTRA_NALLOC 4
static void
test_cto(const char *path)
{
pmemcto_set_funcs(cto_malloc, cto_free, cto_realloc, cto_strdup, NULL);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
pmemcto_create(EXISTING_FILE, "", NON_ZERO_POOL_SIZE, 0);
memset(cnt, 0, sizeof(cnt));
PMEMctopool *pcp;
pcp = pmemcto_create(path, "test", PMEMCTO_MIN_POOL, 0600);
void *ptr = pmemcto_malloc(pcp, 10);
UT_ASSERTne(ptr, NULL);
ptr = pmemcto_realloc(pcp, ptr, 100);
UT_ASSERTne(ptr, NULL);
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
UT_OUT("cto_mallocs: %d", cnt[CTO].mallocs);
UT_OUT("cto_frees: %d", cnt[CTO].frees);
UT_OUT("cto_reallocs: %d", cnt[CTO].reallocs);
UT_OUT("cto_reallocs_null: %d", cnt[CTO].reallocs_null);
UT_OUT("cto_strdups: %d", cnt[CTO].strdups);
if (cnt[CTO].mallocs == 0 || cnt[CTO].frees == 0)
UT_FATAL("CTO mallocs: %d, frees: %d", cnt[CTO].mallocs,
cnt[CTO].frees);
for (int i = 0; i < 5; ++i) {
if (i == CTO)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("CTO allocation used %d functions", i);
}
if (cnt[CTO].mallocs + cnt[CTO].strdups + cnt[CTO].reallocs_null !=
cnt[CTO].frees + CTO_EXTRA_NALLOC)
UT_FATAL("CTO memory leak");
UNLINK(path);
}
static void
test_vmem(const char *dir)
{
vmem_set_funcs(_vmem_malloc, _vmem_free, _vmem_realloc, _vmem_strdup,
NULL);
/*
* Generate ERR() call, that calls malloc() once,
* but only when it is called for the first time
* (free() is called in the destructor of the library).
*/
vmem_create(EXISTING_FILE, 0);
memset(cnt, 0, sizeof(cnt));
VMEM *v[VMEM_POOLS];
void *ptr[VMEM_POOLS];
for (int i = 0; i < VMEM_POOLS; i++) {
v[i] = vmem_create(dir, VMEM_MIN_POOL);
ptr[i] = vmem_malloc(v[i], 64);
vmem_free(v[i], ptr[i]);
}
for (int i = 0; i < VMEM_POOLS; i++)
vmem_delete(v[i]);
UT_OUT("vmem_mallocs: %d", cnt[VMEM_].mallocs);
UT_OUT("vmem_frees: %d", cnt[VMEM_].frees);
UT_OUT("vmem_reallocs: %d", cnt[VMEM_].reallocs);
UT_OUT("vmem_reallocs_null: %d", cnt[VMEM_].reallocs_null);
UT_OUT("vmem_strdups: %d", cnt[VMEM_].strdups);
if (cnt[VMEM_].mallocs == 0 && cnt[VMEM_].frees == 0)
UT_FATAL("VMEM mallocs: %d, frees: %d", cnt[VMEM_].mallocs,
cnt[VMEM_].frees);
for (int i = 0; i < 5; ++i) {
if (i == VMEM_)
continue;
if (cnt[i].mallocs || cnt[i].frees)
UT_FATAL("VMEM allocation used %d functions", i);
}
if (cnt[VMEM_].mallocs + cnt[VMEM_].strdups + cnt[VMEM_].reallocs_null
> cnt[VMEM_].frees + 4)
UT_FATAL("VMEM memory leak");
}
int
main(int argc, char *argv[])
{
START(argc, argv, "set_funcs");
if (argc < 3)
UT_FATAL("usage: %s file dir", argv[0]);
test_obj(argv[1]);
test_blk(argv[1]);
test_log(argv[1]);
test_cto(argv[1]);
test_vmem(argv[2]);
DONE(NULL);
}
| 12,489 | 21.383513 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_malloc/vmem_malloc.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_malloc.c -- unit test for vmem_malloc
*
* usage: vmem_malloc [directory]
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
START(argc, argv, "vmem_malloc");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
int *test = vmem_malloc(vmp, sizeof(int));
UT_ASSERTne(test, NULL);
*test = test_value;
UT_ASSERTeq(*test, test_value);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(test, mem_pool, VMEM_MIN_POOL);
}
vmem_free(vmp, test);
vmem_delete(vmp);
DONE(NULL);
}
| 2,641 | 29.72093 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_stats/obj_ctl_stats.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_stats.c -- tests for the libpmemobj statistics module
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_stats");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, "ctl", PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
int enabled;
int ret = pmemobj_ctl_get(pop, "stats.enabled", &enabled);
UT_ASSERTeq(enabled, 0);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, NULL, 1, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
size_t allocated;
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(allocated, 0);
enabled = 1;
ret = pmemobj_ctl_set(pop, "stats.enabled", &enabled);
UT_ASSERTeq(ret, 0);
PMEMoid oid;
ret = pmemobj_alloc(pop, &oid, 1, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
size_t oid_size = pmemobj_alloc_usable_size(oid) + 16;
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(allocated, oid_size);
pmemobj_free(&oid);
ret = pmemobj_ctl_get(pop, "stats.heap.curr_allocated", &allocated);
UT_ASSERTeq(ret, 0);
UT_ASSERTeq(allocated, 0);
pmemobj_close(pop);
DONE(NULL);
}
| 2,867 | 31.224719 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/traces_custom_function/traces_custom_function.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* traces_custom_function.c -- unit test for traces with custom print or
* vsnprintf functions
*
* usage: traces_custom_function [v|p]
*
*/
#define LOG_PREFIX "trace_func"
#define LOG_LEVEL_VAR "TRACE_LOG_LEVEL"
#define LOG_FILE_VAR "TRACE_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#include <sys/types.h>
#include <stdarg.h>
#include "pmemcommon.h"
#include "unittest.h"
/*
* print_custom_function -- Custom function to handle output
*
* This is called from the library to print text instead of output to stderr.
*/
static void
print_custom_function(const char *s)
{
if (s) {
UT_OUT("CUSTOM_PRINT: %s", s);
} else {
UT_OUT("CUSTOM_PRINT(NULL)");
}
}
/*
* vsnprintf_custom_function -- Custom vsnprintf implementation
*
* It modifies format by adding @@ in front of each conversion specification.
*/
static int
vsnprintf_custom_function(char *str, size_t size, const char *format,
va_list ap)
{
char *format2 = MALLOC(strlen(format) * 3);
int i = 0;
int ret_val;
while (*format != '\0') {
if (*format == '%') {
format2[i++] = '@';
format2[i++] = '@';
}
format2[i++] = *format++;
}
format2[i++] = '\0';
ret_val = vsnprintf(str, size, format2, ap);
FREE(format2);
return ret_val;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "traces_custom_function");
if (argc != 2)
UT_FATAL("usage: %s [v|p]", argv[0]);
out_set_print_func(print_custom_function);
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
switch (argv[1][0]) {
case 'p': {
LOG(0, "Log level NONE");
LOG(1, "Log level ERROR");
LOG(2, "Log level WARNING");
LOG(3, "Log level INFO");
LOG(4, "Log level DEBUG");
}
break;
case 'v':
out_set_vsnprintf_func(vsnprintf_custom_function);
LOG(0, "no format");
LOG(0, "pointer: %p", (void *)0x12345678);
LOG(0, "string: %s", "Hello world!");
LOG(0, "number: %u", 12345678);
errno = EINVAL;
LOG(0, "!error");
break;
default:
UT_FATAL("usage: %s [v|p]", argv[0]);
}
/* Cleanup */
common_fini();
DONE(NULL);
}
| 3,671 | 26 | 77 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset_foreach/util_poolset_foreach.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_poolset_foreach.c -- unit test for util_poolset_foreach_part()
*
* usage: util_poolset_foreach file...
*/
#include "unittest.h"
#include "set.h"
#include "pmemcommon.h"
#include <errno.h>
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
static int
cb(struct part_file *pf, void *arg)
{
if (pf->is_remote) {
/* remote replica */
const char *node_addr = pf->remote->node_addr;
const char *pool_desc = pf->remote->pool_desc;
char *set_name = (char *)arg;
UT_OUT("%s: %s %s", set_name, node_addr, pool_desc);
} else {
const char *name = pf->part->path;
char *set_name = (char *)arg;
UT_OUT("%s: %s", set_name, name);
}
return 0;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_poolset_foreach");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 2)
UT_FATAL("usage: %s file...",
argv[0]);
for (int i = 1; i < argc; i++) {
char *fname = argv[i];
int ret = util_poolset_foreach_part(fname, cb, fname);
UT_OUT("util_poolset_foreach_part(%s): %d", fname, ret);
}
common_fini();
DONE(NULL);
}
| 2,808 | 30.211111 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_reopen/cto_reopen.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_reopen -- unit test for cto_reopen
*
* usage: cto_reopen filename nrep
*/
#include "unittest.h"
#define ALLOC_SIZE (1024L)
#define NALLOCS 16
#define POOL_SIZE (2 * PMEMCTO_MIN_POOL)
/* buffer for all allocation pointers */
static char *ptrs[NALLOCS];
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_reopen");
if (argc != 3)
UT_FATAL("usage: %s filename nrep", argv[0]);
int nrep = atoi(argv[2]);
PMEMctopool *pcp;
for (int r = 0; r < nrep; r++) {
if (r == 0) {
pcp = pmemcto_create(argv[1], "test",
POOL_SIZE, 0666);
} else {
pcp = pmemcto_open(argv[1], "test");
}
UT_ASSERTne(pcp, NULL);
memset(ptrs, 0, sizeof(ptrs));
int i;
for (i = 0; i < NALLOCS; ++i) {
ptrs[i] = pmemcto_malloc(pcp, ALLOC_SIZE);
if (ptrs[i] == NULL) {
/* out of memory in pool */
break;
}
/* check that pointer came from mem_pool */
UT_ASSERTrange(ptrs[i], pcp, POOL_SIZE);
/* fill each allocation with a unique value */
memset(ptrs[i], (char)i, ALLOC_SIZE);
}
UT_OUT("rep %d cnt %d", r, i);
UT_ASSERTeq(i, NALLOCS);
for (i = 0; i < NALLOCS && ptrs[i] != NULL; ++i)
pmemcto_free(pcp, ptrs[i]);
pmemcto_close(pcp);
}
DONE(NULL);
}
| 2,821 | 28.395833 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_aligned_alloc/vmem_aligned_alloc.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_aligned_alloc.c -- unit test for vmem_aligned_alloc
*
* usage: vmem_aligned_alloc [directory]
*/
#include "unittest.h"
#define MAX_ALLOCS (100)
static int custom_allocs;
static int custom_alloc_calls;
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
VMEM *vmp;
size_t alignment;
unsigned i;
int *ptr;
int *ptrs[MAX_ALLOCS];
START(argc, argv, "vmem_aligned_alloc");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
/* allocate memory for function vmem_create_in_region() */
void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
/* use custom alloc functions to check for memory leaks */
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
/* test with address alignment from 2B to 4MB */
for (alignment = 2; alignment <= 4 * 1024 * 1024; alignment *= 2) {
if (dir == NULL) {
vmp = vmem_create_in_region(mem_pool,
VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
memset(ptrs, 0, MAX_ALLOCS * sizeof(ptrs[0]));
for (i = 0; i < MAX_ALLOCS; ++i) {
ptr = vmem_aligned_alloc(vmp, alignment, sizeof(int));
ptrs[i] = ptr;
/* at least one allocation must succeed */
UT_ASSERT(i != 0 || ptr != NULL);
if (ptr == NULL)
break;
/* ptr should be usable */
*ptr = test_value;
UT_ASSERTeq(*ptr, test_value);
/* check for correct address alignment */
UT_ASSERTeq((uintptr_t)(ptr) & (alignment - 1), 0);
/* check that pointer came from mem_pool */
if (dir == NULL) {
UT_ASSERTrange(ptr, mem_pool, VMEM_MIN_POOL);
}
}
for (i = 0; i < MAX_ALLOCS; ++i) {
if (ptrs[i] == NULL)
break;
vmem_free(vmp, ptrs[i]);
}
vmem_delete(vmp);
}
/* check memory leaks */
UT_ASSERTne(custom_alloc_calls, 0);
UT_ASSERTeq(custom_allocs, 0);
DONE(NULL);
}
| 4,662 | 24.905556 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_pages_purging/vmem_pages_purging.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_pages_purging.c -- unit test for vmem_pages_purging
*
* usage: vmem_pages_purging [-z] directory
*/
#include <getopt.h>
#include "unittest.h"
#include "jemalloc/internal/jemalloc_internal.h"
#include "jemalloc/internal/size_classes.h"
#define DEFAULT_COUNT (SMALL_MAXCLASS / 4)
#define DEFAULT_N 100
static void
usage(char *appname)
{
UT_FATAL("usage: %s <z - use calloc | \
n - do not use calloc> directory ", appname);
}
int
main(int argc, char *argv[])
{
const int test_value = 123456;
char *dir = NULL;
int count = DEFAULT_COUNT;
int n = DEFAULT_N;
VMEM *vmp;
int i, j;
int use_calloc = 0;
START(argc, argv, "vmem_pages_purging");
switch (argv[1][0]) {
case 'z':
use_calloc = 1;
break;
case 'n':
break;
default:
usage(argv[0]);
}
if (argv[2]) {
dir = argv[2];
} else {
usage(argv[0]);
}
vmp = vmem_create(dir, VMEM_MIN_POOL);
if (vmp == NULL)
UT_FATAL("!vmem_create");
for (i = 0; i < n; i++) {
int *test = NULL;
if (use_calloc)
test = vmem_calloc(vmp, 1, count * sizeof(int));
else
test = vmem_malloc(vmp, count * sizeof(int));
UT_ASSERTne(test, NULL);
if (use_calloc) {
/* vmem_calloc should return zeroed memory */
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], 0);
}
for (j = 0; j < count; j++)
test[j] = test_value;
for (j = 0; j < count; j++)
UT_ASSERTeq(test[j], test_value);
vmem_free(vmp, test);
}
vmem_delete(vmp);
DONE(NULL);
}
| 3,052 | 26.504505 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_layout/obj_layout.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_layout.c -- unit test for layout
*
* This test should be modified after every layout change. It's here to prevent
* any accidental layout changes.
*/
#include "util.h"
#include "unittest.h"
#include "sync.h"
#include "heap_layout.h"
#include "lane.h"
#include "tx.h"
#include "ulog.h"
#include "list.h"
#define SIZEOF_CHUNK_HEADER_V3 (8)
#define MAX_CHUNK_V3 (65535 - 7)
#define SIZEOF_CHUNK_V3 (1024ULL * 256)
#define SIZEOF_CHUNK_RUN_HEADER_V3 (16)
#define SIZEOF_ZONE_HEADER_V3 (64)
#define SIZEOF_ZONE_METADATA_V3 (SIZEOF_ZONE_HEADER_V3 +\
SIZEOF_CHUNK_HEADER_V3 * MAX_CHUNK_V3)
#define SIZEOF_HEAP_HDR_V3 (1024)
#define SIZEOF_LEGACY_ALLOCATION_HEADER_V3 (64)
#define SIZEOF_COMPACT_ALLOCATION_HEADER_V3 (16)
#define SIZEOF_LOCK_V3 (64)
#define SIZEOF_PMEMOID_V3 (16)
#define SIZEOF_LIST_ENTRY_V3 (SIZEOF_PMEMOID_V3 * 2)
#define SIZEOF_LIST_HEAD_V3 (SIZEOF_PMEMOID_V3 + SIZEOF_LOCK_V3)
#define SIZEOF_LANE_SECTION_V3 (1024)
#define SIZEOF_LANE_V3 (3 * SIZEOF_LANE_SECTION_V3)
#define SIZEOF_ULOG_V4 (64)
#define SIZEOF_ULOG_BASE_ENTRY_V4 (8)
#define SIZEOF_ULOG_VAL_ENTRY_V4 (16)
#define SIZEOF_ULOG_BUF_ENTRY_V4 (24)
POBJ_LAYOUT_BEGIN(layout);
POBJ_LAYOUT_ROOT(layout, struct foo);
POBJ_LAYOUT_END(layout);
struct foo {
POBJ_LIST_ENTRY(struct foo) f;
};
POBJ_LIST_HEAD(foo_head, struct foo);
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_layout");
UT_COMPILE_ERROR_ON(CHUNKSIZE != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk);
ASSERT_ALIGNED_FIELD(struct chunk, data);
ASSERT_ALIGNED_CHECK(struct chunk);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run) != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_run_header);
ASSERT_ALIGNED_FIELD(struct chunk_run_header, block_size);
ASSERT_ALIGNED_FIELD(struct chunk_run_header, alignment);
ASSERT_ALIGNED_CHECK(struct chunk_run_header);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run_header) !=
SIZEOF_CHUNK_RUN_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_run);
ASSERT_ALIGNED_FIELD(struct chunk_run, hdr);
ASSERT_ALIGNED_FIELD(struct chunk_run, content);
ASSERT_ALIGNED_CHECK(struct chunk_run);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_run) != SIZEOF_CHUNK_V3);
ASSERT_ALIGNED_BEGIN(struct chunk_header);
ASSERT_ALIGNED_FIELD(struct chunk_header, type);
ASSERT_ALIGNED_FIELD(struct chunk_header, flags);
ASSERT_ALIGNED_FIELD(struct chunk_header, size_idx);
ASSERT_ALIGNED_CHECK(struct chunk_header);
UT_COMPILE_ERROR_ON(sizeof(struct chunk_header) !=
SIZEOF_CHUNK_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct zone_header);
ASSERT_ALIGNED_FIELD(struct zone_header, magic);
ASSERT_ALIGNED_FIELD(struct zone_header, size_idx);
ASSERT_ALIGNED_FIELD(struct zone_header, reserved);
ASSERT_ALIGNED_CHECK(struct zone_header);
UT_COMPILE_ERROR_ON(sizeof(struct zone_header) !=
SIZEOF_ZONE_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct zone);
ASSERT_ALIGNED_FIELD(struct zone, header);
ASSERT_ALIGNED_FIELD(struct zone, chunk_headers);
ASSERT_ALIGNED_CHECK(struct zone);
UT_COMPILE_ERROR_ON(sizeof(struct zone) !=
SIZEOF_ZONE_METADATA_V3);
ASSERT_ALIGNED_BEGIN(struct heap_header);
ASSERT_ALIGNED_FIELD(struct heap_header, signature);
ASSERT_ALIGNED_FIELD(struct heap_header, major);
ASSERT_ALIGNED_FIELD(struct heap_header, minor);
ASSERT_ALIGNED_FIELD(struct heap_header, unused);
ASSERT_ALIGNED_FIELD(struct heap_header, chunksize);
ASSERT_ALIGNED_FIELD(struct heap_header, chunks_per_zone);
ASSERT_ALIGNED_FIELD(struct heap_header, reserved);
ASSERT_ALIGNED_FIELD(struct heap_header, checksum);
ASSERT_ALIGNED_CHECK(struct heap_header);
UT_COMPILE_ERROR_ON(sizeof(struct heap_header) !=
SIZEOF_HEAP_HDR_V3);
ASSERT_ALIGNED_BEGIN(struct allocation_header_legacy);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, unused);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, size);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, unused2);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, root_size);
ASSERT_ALIGNED_FIELD(struct allocation_header_legacy, type_num);
ASSERT_ALIGNED_CHECK(struct allocation_header_legacy);
UT_COMPILE_ERROR_ON(sizeof(struct allocation_header_legacy) !=
SIZEOF_LEGACY_ALLOCATION_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct allocation_header_compact);
ASSERT_ALIGNED_FIELD(struct allocation_header_compact, size);
ASSERT_ALIGNED_FIELD(struct allocation_header_compact, extra);
ASSERT_ALIGNED_CHECK(struct allocation_header_compact);
UT_COMPILE_ERROR_ON(sizeof(struct allocation_header_compact) !=
SIZEOF_COMPACT_ALLOCATION_HEADER_V3);
ASSERT_ALIGNED_BEGIN(struct ulog);
ASSERT_ALIGNED_FIELD(struct ulog, checksum);
ASSERT_ALIGNED_FIELD(struct ulog, next);
ASSERT_ALIGNED_FIELD(struct ulog, capacity);
ASSERT_ALIGNED_FIELD(struct ulog, unused);
ASSERT_ALIGNED_CHECK(struct ulog);
UT_COMPILE_ERROR_ON(sizeof(struct ulog) !=
SIZEOF_ULOG_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_base, offset);
ASSERT_ALIGNED_CHECK(struct ulog_entry_base);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_base) !=
SIZEOF_ULOG_BASE_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_val);
ASSERT_ALIGNED_FIELD(struct ulog_entry_val, base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_val, value);
ASSERT_ALIGNED_CHECK(struct ulog_entry_val);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_val) !=
SIZEOF_ULOG_VAL_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(struct ulog_entry_buf);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, base);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, checksum);
ASSERT_ALIGNED_FIELD(struct ulog_entry_buf, size);
ASSERT_ALIGNED_CHECK(struct ulog_entry_buf);
UT_COMPILE_ERROR_ON(sizeof(struct ulog_entry_buf) !=
SIZEOF_ULOG_BUF_ENTRY_V4);
ASSERT_ALIGNED_BEGIN(PMEMoid);
ASSERT_ALIGNED_FIELD(PMEMoid, pool_uuid_lo);
ASSERT_ALIGNED_FIELD(PMEMoid, off);
ASSERT_ALIGNED_CHECK(PMEMoid);
UT_COMPILE_ERROR_ON(sizeof(PMEMoid) !=
SIZEOF_PMEMOID_V3);
UT_COMPILE_ERROR_ON(sizeof(PMEMmutex) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(sizeof(PMEMmutex) != sizeof(PMEMmutex_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(PMEMmutex_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(os_mutex_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMmutex) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(PMEMrwlock) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(PMEMrwlock_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(os_rwlock_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMrwlock) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(PMEMcond) != SIZEOF_LOCK_V3);
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(PMEMcond_internal));
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(os_cond_t));
UT_COMPILE_ERROR_ON(util_alignof(PMEMcond) !=
util_alignof(uint64_t));
UT_COMPILE_ERROR_ON(sizeof(struct foo) != SIZEOF_LIST_ENTRY_V3);
UT_COMPILE_ERROR_ON(sizeof(struct list_entry) != SIZEOF_LIST_ENTRY_V3);
UT_COMPILE_ERROR_ON(sizeof(struct foo_head) != SIZEOF_LIST_HEAD_V3);
UT_COMPILE_ERROR_ON(sizeof(struct list_head) != SIZEOF_LIST_HEAD_V3);
ASSERT_ALIGNED_BEGIN(struct lane_layout);
ASSERT_ALIGNED_FIELD(struct lane_layout, internal);
ASSERT_ALIGNED_FIELD(struct lane_layout, external);
ASSERT_ALIGNED_FIELD(struct lane_layout, undo);
ASSERT_ALIGNED_CHECK(struct lane_layout);
UT_COMPILE_ERROR_ON(sizeof(struct lane_layout) !=
SIZEOF_LANE_V3);
DONE(NULL);
}
| 9,082 | 37.487288 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_add_range_direct/obj_tx_add_range_direct.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_add_range_direct.c -- unit test for pmemobj_tx_add_range_direct
*/
#include <string.h>
#include <stddef.h>
#include "tx.h"
#include "unittest.h"
#include "util.h"
#include "valgrind_internal.h"
#define LAYOUT_NAME "tx_add_range_direct"
#define OBJ_SIZE 1024
enum type_number {
TYPE_OBJ,
TYPE_OBJ_ABORT,
};
TOID_DECLARE(struct object, 0);
struct object {
size_t value;
unsigned char data[OBJ_SIZE - sizeof(size_t)];
};
#define VALUE_OFF (offsetof(struct object, value))
#define VALUE_SIZE (sizeof(size_t))
#define DATA_OFF (offsetof(struct object, data))
#define DATA_SIZE (OBJ_SIZE - sizeof(size_t))
#define TEST_VALUE_1 1
#define TEST_VALUE_2 2
/*
* do_tx_alloc -- do tx allocation with specified type number
*/
static PMEMoid
do_tx_zalloc(PMEMobjpool *pop, unsigned type_num)
{
PMEMoid ret = OID_NULL;
TX_BEGIN(pop) {
ret = pmemobj_tx_zalloc(sizeof(struct object), type_num);
} TX_END
return ret;
}
/*
* do_tx_add_range_alloc_commit -- call add_range_direct on object allocated
* within the same transaction and commit the transaction
*/
static void
do_tx_add_range_alloc_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj)->data, TEST_VALUE_2,
DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj)->data[i], TEST_VALUE_2);
}
/*
* do_tx_add_range_alloc_abort -- call add_range_direct on object allocated
* within the same transaction and abort the transaction
*/
static void
do_tx_add_range_alloc_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TX_BEGIN(pop) {
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ_ABORT));
UT_ASSERT(!TOID_IS_NULL(obj));
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj)->data, TEST_VALUE_2,
DATA_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
TOID_ASSIGN(obj, POBJ_FIRST_TYPE_NUM(pop, TYPE_OBJ_ABORT));
UT_ASSERT(TOID_IS_NULL(obj));
}
/*
* do_tx_add_range_twice_commit -- call add_range_direct one the same area
* twice and commit the transaction
*/
static void
do_tx_add_range_twice_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_2;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_2);
}
/*
* do_tx_add_range_twice_abort -- call add_range_direct one the same area
* twice and abort the transaction
*/
static void
do_tx_add_range_twice_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
UT_ASSERT(!TOID_IS_NULL(obj));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_2;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, 0);
}
/*
* do_tx_add_range_abort_after_nested -- call add_range_direct and
* commit the tx
*/
static void
do_tx_add_range_abort_after_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, 0);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], 0);
}
/*
* do_tx_add_range_abort_nested -- call add_range_direct and
* commit the tx
*/
static void
do_tx_add_range_abort_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, 0);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], 0);
}
/*
* do_tx_add_range_commit_nested -- call add_range_direct and commit the tx
*/
static void
do_tx_add_range_commit_nested(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj1;
TOID(struct object) obj2;
TOID_ASSIGN(obj1, do_tx_zalloc(pop, TYPE_OBJ));
TOID_ASSIGN(obj2, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr1 = (char *)pmemobj_direct(obj1.oid);
ret = pmemobj_tx_add_range_direct(ptr1 + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj1)->value = TEST_VALUE_1;
TX_BEGIN(pop) {
char *ptr2 = (char *)pmemobj_direct(obj2.oid);
ret = pmemobj_tx_add_range_direct(ptr2 + DATA_OFF,
DATA_SIZE);
UT_ASSERTeq(ret, 0);
pmemobj_memset_persist(pop, D_RW(obj2)->data,
TEST_VALUE_2, DATA_SIZE);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj1)->value, TEST_VALUE_1);
size_t i;
for (i = 0; i < DATA_SIZE; i++)
UT_ASSERTeq(D_RO(obj2)->data[i], TEST_VALUE_2);
}
/*
* do_tx_add_range_abort -- call add_range_direct and abort the tx
*/
static void
do_tx_add_range_abort(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, 0);
}
/*
* do_tx_add_range_commit -- call add_range_direct and commit tx
*/
static void
do_tx_add_range_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_add_range_direct(ptr + VALUE_OFF,
VALUE_SIZE);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* do_tx_xadd_range_commit -- call xadd_range_direct and commit tx
*/
static void
do_tx_xadd_range_commit(PMEMobjpool *pop)
{
int ret;
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
char *ptr = (char *)pmemobj_direct(obj.oid);
ret = pmemobj_tx_xadd_range_direct(ptr + VALUE_OFF,
VALUE_SIZE, POBJ_XADD_NO_FLUSH);
UT_ASSERTeq(ret, 0);
D_RW(obj)->value = TEST_VALUE_1;
/* let pmemcheck find we didn't flush it */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* do_tx_commit_and_abort -- use range cache, commit and then abort to make
* sure that it won't affect previously modified data.
*/
static void
do_tx_commit_and_abort(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
TX_SET(obj, value, TEST_VALUE_1); /* this will land in cache */
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
TX_BEGIN(pop) {
pmemobj_tx_abort(-1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
/*
* test_add_direct_macros -- test TX_ADD_DIRECT, TX_ADD_FIELD_DIRECT and
* TX_SET_DIRECT
*/
static void
test_add_direct_macros(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_SET_DIRECT(o, value, TEST_VALUE_1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_ADD_DIRECT(o);
o->value = TEST_VALUE_2;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_2);
TX_BEGIN(pop) {
struct object *o = D_RW(obj);
TX_ADD_FIELD_DIRECT(o, value);
o->value = TEST_VALUE_1;
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
UT_ASSERTeq(D_RO(obj)->value, TEST_VALUE_1);
}
#define MAX_CACHED_RANGES 100
/*
* test_tx_corruption_bug -- test whether tx_adds for small objects from one
* transaction does NOT leak to the next transaction
*/
static void
test_tx_corruption_bug(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
struct object *o = D_RW(obj);
unsigned char i;
UT_COMPILE_ERROR_ON(1.5 * MAX_CACHED_RANGES > 255);
TX_BEGIN(pop) {
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i) {
TX_ADD_DIRECT(&o->data[i]);
o->data[i] = i;
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i)
UT_ASSERTeq((unsigned char)o->data[i], i);
TX_BEGIN(pop) {
for (i = 0; i < 0.1 * MAX_CACHED_RANGES; ++i) {
TX_ADD_DIRECT(&o->data[i]);
o->data[i] = i + 10;
}
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
for (i = 0; i < 1.5 * MAX_CACHED_RANGES; ++i)
UT_ASSERTeq((unsigned char)o->data[i], i);
pmemobj_free(&obj.oid);
}
static void
do_tx_add_range_too_large(PMEMobjpool *pop)
{
TOID(struct object) obj;
TOID_ASSIGN(obj, do_tx_zalloc(pop, TYPE_OBJ));
TX_BEGIN(pop) {
pmemobj_tx_add_range_direct(pmemobj_direct(obj.oid),
PMEMOBJ_MAX_ALLOC_SIZE + 1);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERTne(errno, 0);
errno = 0;
}
static void
do_tx_add_range_lots_of_small_snapshots(PMEMobjpool *pop)
{
size_t s = TX_DEFAULT_RANGE_CACHE_SIZE * 2;
size_t snapshot_s = 8;
PMEMoid obj;
int ret = pmemobj_zalloc(pop, &obj, s, 0);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
for (size_t n = 0; n < s; n += snapshot_s) {
void *addr = (void *)((size_t)pmemobj_direct(obj) + n);
pmemobj_tx_add_range_direct(addr, snapshot_s);
}
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
}
static void
do_tx_add_cache_overflowing_range(PMEMobjpool *pop)
{
/*
* This test adds snapshot to the cache, but in way that results in
* one of the add_range being split into two caches.
*/
size_t s = TX_DEFAULT_RANGE_CACHE_SIZE * 2;
size_t snapshot_s = TX_DEFAULT_RANGE_CACHE_THRESHOLD - 8;
PMEMoid obj;
int ret = pmemobj_zalloc(pop, &obj, s, 0);
UT_ASSERTeq(ret, 0);
TX_BEGIN(pop) {
size_t n = 0;
while (n != s) {
if (n + snapshot_s > s)
snapshot_s = s - n;
void *addr = (void *)((size_t)pmemobj_direct(obj) + n);
pmemobj_tx_add_range_direct(addr, snapshot_s);
memset(addr, 0xc, snapshot_s);
n += snapshot_s;
}
pmemobj_tx_abort(0);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
UT_ASSERT(util_is_zeroed(pmemobj_direct(obj), s));
UT_ASSERTne(errno, 0);
errno = 0;
pmemobj_free(&obj);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_add_range_direct");
util_init();
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL * 4,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_tx_add_range_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_commit_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_abort_after_nested(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_twice_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_twice_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_alloc_commit(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_alloc_abort(pop);
VALGRIND_WRITE_STATS;
do_tx_commit_and_abort(pop);
VALGRIND_WRITE_STATS;
test_add_direct_macros(pop);
VALGRIND_WRITE_STATS;
test_tx_corruption_bug(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_too_large(pop);
VALGRIND_WRITE_STATS;
do_tx_add_range_lots_of_small_snapshots(pop);
VALGRIND_WRITE_STATS;
do_tx_add_cache_overflowing_range(pop);
VALGRIND_WRITE_STATS;
do_tx_xadd_range_commit(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 15,389 | 22.353566 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_many_size_allocs/obj_many_size_allocs.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_many_size_allocs.c -- allocation of many objects with different sizes
*
*/
#include <stddef.h>
#include "unittest.h"
#include "heap.h"
#define LAYOUT_NAME "many_size_allocs"
#define TEST_ALLOC_SIZE 2048
#define LAZY_LOAD_SIZE 10
#define LAZY_LOAD_BIG_SIZE 150
struct cargs {
size_t size;
};
static int
test_constructor(PMEMobjpool *pop, void *addr, void *args)
{
struct cargs *a = args;
/* do not use pmem_memset_persit() here */
pmemobj_memset_persist(pop, addr, a->size % 256, a->size);
return 0;
}
static PMEMobjpool *
test_allocs(PMEMobjpool *pop, const char *path)
{
PMEMoid *oid = MALLOC(sizeof(PMEMoid) * TEST_ALLOC_SIZE);
if (pmemobj_alloc(pop, &oid[0], 0, 0, NULL, NULL) == 0)
UT_FATAL("pmemobj_alloc(0) succeeded");
for (unsigned i = 1; i < TEST_ALLOC_SIZE; ++i) {
struct cargs args = { i };
if (pmemobj_alloc(pop, &oid[i], i, 0,
test_constructor, &args) != 0)
UT_FATAL("!pmemobj_alloc");
UT_ASSERT(!OID_IS_NULL(oid[i]));
}
pmemobj_close(pop);
UT_ASSERT(pmemobj_check(path, LAYOUT_NAME) == 1);
UT_ASSERT((pop = pmemobj_open(path, LAYOUT_NAME)) != NULL);
for (int i = 1; i < TEST_ALLOC_SIZE; ++i) {
pmemobj_free(&oid[i]);
UT_ASSERT(OID_IS_NULL(oid[i]));
}
FREE(oid);
return pop;
}
static PMEMobjpool *
test_lazy_load(PMEMobjpool *pop, const char *path)
{
PMEMoid oid[3];
int ret = pmemobj_alloc(pop, &oid[0], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, &oid[1], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
ret = pmemobj_alloc(pop, &oid[2], LAZY_LOAD_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
pmemobj_close(pop);
UT_ASSERT((pop = pmemobj_open(path, LAYOUT_NAME)) != NULL);
pmemobj_free(&oid[1]);
ret = pmemobj_alloc(pop, &oid[1], LAZY_LOAD_BIG_SIZE, 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
return pop;
}
#define ALLOC_BLOCK_SIZE 64
#define MAX_BUCKET_MAP_ENTRIES (RUN_DEFAULT_SIZE / ALLOC_BLOCK_SIZE)
static void
test_all_classes(PMEMobjpool *pop)
{
for (unsigned i = 1; i <= MAX_BUCKET_MAP_ENTRIES; ++i) {
int err;
int nallocs = 0;
while ((err = pmemobj_alloc(pop, NULL, i * ALLOC_BLOCK_SIZE, 0,
NULL, NULL)) == 0) {
nallocs++;
}
UT_ASSERT(nallocs > 0);
PMEMoid iter, niter;
POBJ_FOREACH_SAFE(pop, iter, niter) {
pmemobj_free(&iter);
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_many_size_allocs");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, LAYOUT_NAME,
0, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
pop = test_lazy_load(pop, path);
pop = test_allocs(pop, path);
test_all_classes(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 4,352 | 25.705521 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_ctl_alloc_class_config/obj_ctl_alloc_class_config.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_ctl_alloc_class_config.c -- tests for the ctl alloc class config
*/
#include "unittest.h"
#define LAYOUT "obj_ctl_alloc_class_config"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_ctl_alloc_class_config");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
struct pobj_alloc_class_desc alloc_class;
int ret;
ret = pmemobj_ctl_get(pop, "heap.alloc_class.128.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
ret = pmemobj_ctl_get(pop, "heap.alloc_class.129.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
ret = pmemobj_ctl_get(pop, "heap.alloc_class.130.desc", &alloc_class);
UT_ASSERTeq(ret, 0);
UT_OUT("%d %lu %d", alloc_class.header_type, alloc_class.unit_size,
alloc_class.units_per_block);
pmemobj_close(pop);
DONE(NULL);
}
| 2,757 | 32.634146 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_action/obj_action.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_action.c -- test the action API
*/
#include <stdlib.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_action"
struct macro_reserve_s {
PMEMoid oid;
uint64_t value;
};
TOID_DECLARE(struct macro_reserve_s, 1);
struct foo {
int bar;
};
struct root {
struct {
PMEMoid oid;
uint64_t value;
} reserved;
struct {
PMEMoid oid;
uint64_t value;
} published;
struct {
PMEMoid oid;
} tx_reserved;
struct {
PMEMoid oid;
} tx_reserved_fulfilled;
struct {
PMEMoid oid;
} tx_published;
};
#define HUGE_ALLOC_SIZE ((1 << 20) * 3)
#define MAX_ACTS 10
static void
test_resv_cancel_huge(PMEMobjpool *pop)
{
PMEMoid oid;
unsigned nallocs = 0;
struct pobj_action *act = (struct pobj_action *)
ZALLOC(sizeof(struct pobj_action) * MAX_ACTS);
do {
oid = pmemobj_reserve(pop, &act[nallocs++], HUGE_ALLOC_SIZE, 0);
} while (!OID_IS_NULL(oid));
pmemobj_cancel(pop, act, nallocs - 1);
unsigned nallocs2 = 0;
do {
oid = pmemobj_reserve(pop, &act[nallocs2++],
HUGE_ALLOC_SIZE, 0);
} while (!OID_IS_NULL(oid));
pmemobj_cancel(pop, act, nallocs2 - 1);
UT_ASSERTeq(nallocs, nallocs2);
FREE(act);
}
static void
test_defer_free(PMEMobjpool *pop)
{
PMEMoid oid;
int ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
struct pobj_action act;
pmemobj_defer_free(pop, oid, &act);
pmemobj_publish(pop, &act, 1);
struct foo *f = (struct foo *)pmemobj_direct(oid);
f->bar = 5; /* should trigger memcheck error */
ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
pmemobj_defer_free(pop, oid, &act);
pmemobj_cancel(pop, &act, 1);
f = (struct foo *)pmemobj_direct(oid);
f->bar = 5; /* should NOT trigger memcheck error */
}
/*
* This function tests if macros included in action.h api compile and
* allocate memory.
*/
static void
test_api_macros(PMEMobjpool *pop)
{
struct pobj_action macro_reserve_act[1];
TOID(struct macro_reserve_s) macro_reserve_p = POBJ_RESERVE_NEW(pop,
struct macro_reserve_s, ¯o_reserve_act[0]);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_RESERVE_ALLOC(pop, struct macro_reserve_s,
sizeof(struct macro_reserve_s), ¯o_reserve_act[0]);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_XRESERVE_NEW(pop, struct macro_reserve_s,
¯o_reserve_act[0], 0);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
macro_reserve_p = POBJ_XRESERVE_ALLOC(pop, struct macro_reserve_s,
sizeof(struct macro_reserve_s), ¯o_reserve_act[0], 0);
UT_ASSERT(!OID_IS_NULL(macro_reserve_p.oid));
pmemobj_publish(pop, macro_reserve_act, 1);
POBJ_FREE(¯o_reserve_p);
}
#define POBJ_MAX_ACTIONS 60
static void
test_many(PMEMobjpool *pop, size_t n)
{
struct pobj_action *act = (struct pobj_action *)
MALLOC(sizeof(struct pobj_action) * n);
PMEMoid *oid = (PMEMoid *)
MALLOC(sizeof(PMEMoid) * n);
for (int i = 0; i < n; ++i) {
oid[i] = pmemobj_reserve(pop, &act[i], 1, 0);
UT_ASSERT(!OID_IS_NULL(oid[i]));
}
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
for (int i = 0; i < n; ++i) {
pmemobj_defer_free(pop, oid[i], &act[i]);
}
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
FREE(oid);
FREE(act);
}
static void
test_many_sets(PMEMobjpool *pop, size_t n)
{
struct pobj_action *act = (struct pobj_action *)
MALLOC(sizeof(struct pobj_action) * n);
PMEMoid oid;
pmemobj_alloc(pop, &oid, sizeof(uint64_t) * n, 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(oid));
uint64_t *values = (uint64_t *)pmemobj_direct(oid);
for (uint64_t i = 0; i < n; ++i)
pmemobj_set_value(pop, &act[i], values + i, i);
UT_ASSERTeq(pmemobj_publish(pop, act, n), 0);
for (uint64_t i = 0; i < n; ++i)
UT_ASSERTeq(*(values + i), i);
pmemobj_free(&oid);
FREE(act);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_action");
if (argc < 2)
UT_FATAL("usage: %s filename", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
PMEMoid root = pmemobj_root(pop, sizeof(struct root));
struct root *rootp = (struct root *)pmemobj_direct(root);
struct pobj_action reserved[2];
struct pobj_action published[2];
struct pobj_action tx_reserved;
struct pobj_action tx_reserved_fulfilled;
struct pobj_action tx_published;
rootp->reserved.oid =
pmemobj_reserve(pop, &reserved[0], sizeof(struct foo), 0);
pmemobj_set_value(pop, &reserved[1], &rootp->reserved.value, 1);
rootp->published.oid =
pmemobj_reserve(pop, &published[0], sizeof(struct foo), 0);
pmemobj_set_value(pop, &published[1], &rootp->published.value, 1);
pmemobj_publish(pop, published, 2);
rootp->tx_reserved.oid =
pmemobj_reserve(pop, &tx_reserved, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_reserved, 1);
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
rootp->tx_reserved_fulfilled.oid =
pmemobj_reserve(pop,
&tx_reserved_fulfilled, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_reserved_fulfilled, 1);
pmemobj_tx_publish(NULL, 0); /* this is to force resv fulfill */
pmemobj_tx_abort(EINVAL);
} TX_ONCOMMIT {
UT_ASSERT(0);
} TX_END
rootp->tx_published.oid =
pmemobj_reserve(pop, &tx_published, sizeof(struct foo), 0);
TX_BEGIN(pop) {
pmemobj_tx_publish(&tx_published, 1);
} TX_ONABORT {
UT_ASSERT(0);
} TX_END
pmemobj_persist(pop, rootp, sizeof(*rootp));
pmemobj_close(pop);
UT_ASSERTeq(pmemobj_check(path, LAYOUT_NAME), 1);
UT_ASSERTne(pop = pmemobj_open(path, LAYOUT_NAME), NULL);
root = pmemobj_root(pop, sizeof(struct root));
rootp = (struct root *)pmemobj_direct(root);
struct foo *reserved_foop =
(struct foo *)pmemobj_direct(rootp->reserved.oid);
reserved_foop->bar = 1; /* should trigger memcheck error */
UT_ASSERTeq(rootp->reserved.value, 0);
struct foo *published_foop =
(struct foo *)pmemobj_direct(rootp->published.oid);
published_foop->bar = 1; /* should NOT trigger memcheck error */
UT_ASSERTeq(rootp->published.value, 1);
struct foo *tx_reserved_foop =
(struct foo *)pmemobj_direct(rootp->tx_reserved.oid);
tx_reserved_foop->bar = 1; /* should trigger memcheck error */
struct foo *tx_reserved_fulfilled_foop =
(struct foo *)pmemobj_direct(rootp->tx_reserved_fulfilled.oid);
tx_reserved_fulfilled_foop->bar = 1; /* should trigger memcheck error */
struct foo *tx_published_foop =
(struct foo *)pmemobj_direct(rootp->tx_published.oid);
tx_published_foop->bar = 1; /* should NOT trigger memcheck error */
test_resv_cancel_huge(pop);
test_defer_free(pop);
test_api_macros(pop);
test_many(pop, POBJ_MAX_ACTIONS * 2);
test_many_sets(pop, POBJ_MAX_ACTIONS * 2);
pmemobj_close(pop);
DONE(NULL);
}
| 8,634 | 25.166667 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_vecq/util_vecq.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_vecq.c -- unit test for vecq implementation
*/
#include "unittest.h"
#include "vecq.h"
struct test {
int foo;
int bar;
};
static void
vecq_test()
{
VECQ(testvec, struct test) v;
VECQ_INIT(&v);
struct test t = {5, 10};
struct test t2 = {10, 15};
int ret;
ret = VECQ_ENQUEUE(&v, t);
UT_ASSERTeq(ret, 0);
ret = VECQ_ENQUEUE(&v, t2);
UT_ASSERTeq(ret, 0);
struct test res = VECQ_FRONT(&v);
UT_ASSERTeq(res.bar, t.bar);
size_t s = VECQ_SIZE(&v);
UT_ASSERTeq(s, 2);
size_t c = VECQ_CAPACITY(&v);
UT_ASSERTeq(c, 64);
res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res.bar, t.bar);
res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res.bar, t2.bar);
VECQ_DELETE(&v);
}
static void
vecq_test_grow()
{
VECQ(testvec, int) v;
VECQ_INIT(&v);
for (int i = 1; i < 1000; ++i) {
int ret = VECQ_ENQUEUE(&v, i);
UT_ASSERTeq(ret, 0);
}
for (int i = 1; i < 1000; ++i) {
int res = VECQ_DEQUEUE(&v);
UT_ASSERTeq(res, i);
}
VECQ_DELETE(&v);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_vecq");
vecq_test();
vecq_test_grow();
DONE(NULL);
}
| 2,673 | 23.990654 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/ex_linkedlist/ex_linkedlist.c | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ex_linkedlist.c - test of linkedlist example
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pmemobj_list.h"
#include "unittest.h"
#define ELEMENT_NO 10
#define PRINT_RES(res, struct_name) do {\
if ((res) == 0) {\
UT_OUT("Outcome for " #struct_name " is correct!");\
} else {\
UT_ERR("Outcome for " #struct_name\
" does not match expected result!!!");\
}\
} while (0)
POBJ_LAYOUT_BEGIN(list);
POBJ_LAYOUT_ROOT(list, struct base);
POBJ_LAYOUT_TOID(list, struct tqueuehead);
POBJ_LAYOUT_TOID(list, struct slisthead);
POBJ_LAYOUT_TOID(list, struct tqnode);
POBJ_LAYOUT_TOID(list, struct snode);
POBJ_LAYOUT_END(list);
POBJ_TAILQ_HEAD(tqueuehead, struct tqnode);
struct tqnode {
int data;
POBJ_TAILQ_ENTRY(struct tqnode) tnd;
};
POBJ_SLIST_HEAD(slisthead, struct snode);
struct snode {
int data;
POBJ_SLIST_ENTRY(struct snode) snd;
};
struct base {
struct tqueuehead tqueue;
struct slisthead slist;
};
static const int expectedResTQ[] = { 111, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 222 };
static const int expectedResSL[] = { 111, 8, 222, 6, 5, 4, 3, 2, 1, 0, 333 };
/*
* dump_tq -- dumps list on standard output
*/
static void
dump_tq(struct tqueuehead *head, const char *str)
{
TOID(struct tqnode) var;
UT_OUT("%s start", str);
POBJ_TAILQ_FOREACH(var, head, tnd)
UT_OUT("%d", D_RW(var)->data);
UT_OUT("%s end", str);
}
/*
* init_tqueue -- initialize tail queue
*/
static void
init_tqueue(PMEMobjpool *pop, struct tqueuehead *head)
{
if (!POBJ_TAILQ_EMPTY(head))
return;
TOID(struct tqnode) node;
TOID(struct tqnode) middleNode;
TOID(struct tqnode) node888;
TOID(struct tqnode) tempNode;
int i = 0;
TX_BEGIN(pop) {
POBJ_TAILQ_INIT(head);
dump_tq(head, "after init");
for (i = 0; i < ELEMENT_NO; ++i) {
node = TX_NEW(struct tqnode);
D_RW(node)->data = i;
if (0 == i) {
middleNode = node;
}
POBJ_TAILQ_INSERT_HEAD(head, node, tnd);
node = TX_NEW(struct tqnode);
D_RW(node)->data = i;
POBJ_TAILQ_INSERT_TAIL(head, node, tnd);
}
dump_tq(head, "after insert[head|tail]");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 666;
POBJ_TAILQ_INSERT_AFTER(middleNode, node, tnd);
dump_tq(head, "after insert_after1");
middleNode = POBJ_TAILQ_NEXT(middleNode, tnd);
node = TX_NEW(struct tqnode);
D_RW(node)->data = 888;
node888 = node;
POBJ_TAILQ_INSERT_BEFORE(middleNode, node, tnd);
dump_tq(head, "after insert_before1");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 555;
POBJ_TAILQ_INSERT_BEFORE(middleNode, node, tnd);
dump_tq(head, "after insert_before2");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 111;
tempNode = POBJ_TAILQ_FIRST(head);
POBJ_TAILQ_INSERT_BEFORE(tempNode, node, tnd);
dump_tq(head, "after insert_before3");
node = TX_NEW(struct tqnode);
D_RW(node)->data = 222;
tempNode = POBJ_TAILQ_LAST(head);
POBJ_TAILQ_INSERT_AFTER(tempNode, node, tnd);
dump_tq(head, "after insert_after2");
tempNode = middleNode;
middleNode = POBJ_TAILQ_PREV(tempNode, tnd);
POBJ_TAILQ_MOVE_ELEMENT_TAIL(head, middleNode, tnd);
dump_tq(head, "after move_element_tail");
POBJ_TAILQ_MOVE_ELEMENT_HEAD(head, tempNode, tnd);
dump_tq(head, "after move_element_head");
tempNode = POBJ_TAILQ_FIRST(head);
POBJ_TAILQ_REMOVE(head, tempNode, tnd);
dump_tq(head, "after remove1");
tempNode = POBJ_TAILQ_LAST(head);
POBJ_TAILQ_REMOVE(head, tempNode, tnd);
dump_tq(head, "after remove2");
POBJ_TAILQ_REMOVE(head, node888, tnd);
dump_tq(head, "after remove3");
} TX_ONABORT {
abort();
} TX_END
}
/*
* dump_sl -- dumps list on standard output
*/
static void
dump_sl(struct slisthead *head, const char *str)
{
TOID(struct snode) var;
UT_OUT("%s start", str);
POBJ_SLIST_FOREACH(var, head, snd)
UT_OUT("%d", D_RW(var)->data);
UT_OUT("%s end", str);
}
/*
* init_slist -- initialize SLIST
*/
static void
init_slist(PMEMobjpool *pop, struct slisthead *head)
{
if (!POBJ_SLIST_EMPTY(head))
return;
TOID(struct snode) node;
TOID(struct snode) tempNode;
int i = 0;
TX_BEGIN(pop) {
POBJ_SLIST_INIT(head);
dump_sl(head, "after init");
for (i = 0; i < ELEMENT_NO; ++i) {
node = TX_NEW(struct snode);
D_RW(node)->data = i;
POBJ_SLIST_INSERT_HEAD(head, node, snd);
}
dump_sl(head, "after insert_head");
tempNode = POBJ_SLIST_FIRST(head);
node = TX_NEW(struct snode);
D_RW(node)->data = 111;
POBJ_SLIST_INSERT_AFTER(tempNode, node, snd);
dump_sl(head, "after insert_after1");
tempNode = POBJ_SLIST_NEXT(node, snd);
node = TX_NEW(struct snode);
D_RW(node)->data = 222;
POBJ_SLIST_INSERT_AFTER(tempNode, node, snd);
dump_sl(head, "after insert_after2");
tempNode = POBJ_SLIST_NEXT(node, snd);
POBJ_SLIST_REMOVE_FREE(head, tempNode, snd);
dump_sl(head, "after remove_free1");
POBJ_SLIST_REMOVE_HEAD(head, snd);
dump_sl(head, "after remove_head");
TOID(struct snode) element = POBJ_SLIST_FIRST(head);
while (!TOID_IS_NULL(D_RO(element)->snd.pe_next)) {
element = D_RO(element)->snd.pe_next;
}
node = TX_NEW(struct snode);
D_RW(node)->data = 333;
POBJ_SLIST_INSERT_AFTER(element, node, snd);
dump_sl(head, "after insert_after3");
element = node;
node = TX_NEW(struct snode);
D_RW(node)->data = 123;
POBJ_SLIST_INSERT_AFTER(element, node, snd);
dump_sl(head, "after insert_after4");
tempNode = POBJ_SLIST_NEXT(node, snd);
POBJ_SLIST_REMOVE_FREE(head, node, snd);
dump_sl(head, "after remove_free2");
} TX_ONABORT {
abort();
} TX_END
}
int
main(int argc, char *argv[])
{
unsigned res = 0;
PMEMobjpool *pop;
const char *path;
START(argc, argv, "ex_linkedlist");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(list) != 4);
if (argc != 2) {
UT_FATAL("usage: %s file-name", argv[0]);
}
path = argv[1];
if (os_access(path, F_OK) != 0) {
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(list),
PMEMOBJ_MIN_POOL, 0666)) == NULL) {
UT_FATAL("!pmemobj_create: %s", path);
}
} else {
if ((pop = pmemobj_open(path,
POBJ_LAYOUT_NAME(list))) == NULL) {
UT_FATAL("!pmemobj_open: %s", path);
}
}
TOID(struct base) base = POBJ_ROOT(pop, struct base);
struct tqueuehead *tqhead = &D_RW(base)->tqueue;
struct slisthead *slhead = &D_RW(base)->slist;
init_tqueue(pop, tqhead);
init_slist(pop, slhead);
int i = 0;
TOID(struct tqnode) tqelement;
POBJ_TAILQ_FOREACH(tqelement, tqhead, tnd) {
if (D_RO(tqelement)->data != expectedResTQ[i]) {
res = 1;
break;
}
i++;
}
PRINT_RES(res, tail queue);
i = 0;
res = 0;
TOID(struct snode) slelement;
POBJ_SLIST_FOREACH(slelement, slhead, snd) {
if (D_RO(slelement)->data != expectedResSL[i]) {
res = 1;
break;
}
i++;
}
PRINT_RES(res, singly linked list);
pmemobj_close(pop);
DONE(NULL);
}
| 8,434 | 25.442006 | 77 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_persist_count/mocks_windows.h | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of pmem functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_persist_count test.
* It would replace default implementation with mocked functions defined
* in obj_persist_count.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define pmem_persist __wrap_pmem_persist
#define pmem_flush __wrap_pmem_flush
#define pmem_drain __wrap_pmem_drain
#define pmem_msync __wrap_pmem_msync
#define pmem_memcpy_persist __wrap_pmem_memcpy_persist
#define pmem_memcpy_nodrain __wrap_pmem_memcpy_nodrain
#define pmem_memcpy __wrap_pmem_memcpy
#define pmem_memmove_persist __wrap_pmem_memmove_persist
#define pmem_memmove_nodrain __wrap_pmem_memmove_nodrain
#define pmem_memmove __wrap_pmem_memmove
#define pmem_memset_persist __wrap_pmem_memset_persist
#define pmem_memset_nodrain __wrap_pmem_memset_nodrain
#define pmem_memset __wrap_pmem_memset
#endif
| 2,645 | 42.377049 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_persist_count/obj_persist_count.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_persist_count.c -- counting number of persists
*/
#define _GNU_SOURCE
#include "obj.h"
#include "pmalloc.h"
#include "unittest.h"
struct ops_counter {
unsigned n_cl_stores;
unsigned n_drain;
unsigned n_pmem_persist;
unsigned n_pmem_msync;
unsigned n_pmem_flush;
unsigned n_pmem_drain;
unsigned n_flush_from_pmem_memcpy;
unsigned n_flush_from_pmem_memset;
unsigned n_drain_from_pmem_memcpy;
unsigned n_drain_from_pmem_memset;
unsigned n_pot_cache_misses;
};
static struct ops_counter ops_counter;
static struct ops_counter tx_counter;
#define FLUSH_ALIGN ((uintptr_t)64)
#define MOVNT_THRESHOLD 256
static unsigned
cl_flushed(const void *addr, size_t len, uintptr_t alignment)
{
uintptr_t start = (uintptr_t)addr & ~(alignment - 1);
uintptr_t end = ((uintptr_t)addr + len + alignment - 1) &
~(alignment - 1);
return (unsigned)(end - start) / FLUSH_ALIGN;
}
#define PMEM_F_MEM_MOVNT (PMEM_F_MEM_WC | PMEM_F_MEM_NONTEMPORAL)
#define PMEM_F_MEM_MOV (PMEM_F_MEM_WB | PMEM_F_MEM_TEMPORAL)
static unsigned
bulk_cl_changed(const void *addr, size_t len, unsigned flags)
{
uintptr_t start = (uintptr_t)addr & ~(FLUSH_ALIGN - 1);
uintptr_t end = ((uintptr_t)addr + len + FLUSH_ALIGN - 1) &
~(FLUSH_ALIGN - 1);
unsigned cl_changed = (unsigned)(end - start) / FLUSH_ALIGN;
int wc; /* write combining */
if (flags & PMEM_F_MEM_NOFLUSH)
wc = 0; /* NOFLUSH always uses temporal instructions */
else if (flags & PMEM_F_MEM_MOVNT)
wc = 1;
else if (flags & PMEM_F_MEM_MOV)
wc = 0;
else if (len < MOVNT_THRESHOLD)
wc = 0;
else
wc = 1;
/* count number of potential cache misses */
if (!wc) {
/*
* When we don't use write combining, it means all
* cache lines may be missing.
*/
ops_counter.n_pot_cache_misses += cl_changed;
} else {
/*
* When we use write combining there won't be any cache misses,
* with an exception of unaligned beginning or end.
*/
if (start != (uintptr_t)addr)
ops_counter.n_pot_cache_misses++;
if (end != ((uintptr_t)addr + len) &&
start + FLUSH_ALIGN != end)
ops_counter.n_pot_cache_misses++;
}
return cl_changed;
}
static void
flush_cl(const void *addr, size_t len)
{
unsigned flushed = cl_flushed(addr, len, FLUSH_ALIGN);
ops_counter.n_cl_stores += flushed;
ops_counter.n_pot_cache_misses += flushed;
}
static void
flush_msync(const void *addr, size_t len)
{
unsigned flushed = cl_flushed(addr, len, Pagesize);
ops_counter.n_cl_stores += flushed;
ops_counter.n_pot_cache_misses += flushed;
}
FUNC_MOCK(pmem_persist, void, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_persist++;
flush_cl(addr, len);
ops_counter.n_drain++;
_FUNC_REAL(pmem_persist)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_msync, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_msync++;
flush_msync(addr, len);
ops_counter.n_drain++;
return _FUNC_REAL(pmem_msync)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_flush, void, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_flush++;
flush_cl(addr, len);
_FUNC_REAL(pmem_flush)(addr, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_drain, void, void)
FUNC_MOCK_RUN_DEFAULT {
ops_counter.n_pmem_drain++;
ops_counter.n_drain++;
_FUNC_REAL(pmem_drain)();
}
FUNC_MOCK_END
static void
memcpy_nodrain_count(void *dest, const void *src, size_t len, unsigned flags)
{
unsigned cl_stores = bulk_cl_changed(dest, len, flags);
if (!(flags & PMEM_F_MEM_NOFLUSH))
ops_counter.n_flush_from_pmem_memcpy += cl_stores;
ops_counter.n_cl_stores += cl_stores;
}
static void
memcpy_persist_count(void *dest, const void *src, size_t len, unsigned flags)
{
memcpy_nodrain_count(dest, src, len, flags);
ops_counter.n_drain_from_pmem_memcpy++;
ops_counter.n_drain++;
}
FUNC_MOCK(pmem_memcpy_persist, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_persist_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memcpy_persist)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memcpy_nodrain, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_nodrain_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memcpy_nodrain)(dest, src, len);
}
FUNC_MOCK_END
static unsigned
sanitize_flags(unsigned flags)
{
if (flags & PMEM_F_MEM_NOFLUSH) {
/* NOFLUSH implies NODRAIN */
flags |= PMEM_F_MEM_NODRAIN;
}
return flags;
}
FUNC_MOCK(pmem_memcpy, void *, void *dest, const void *src, size_t len,
unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memcpy_nodrain_count(dest, src, len, flags);
else
memcpy_persist_count(dest, src, len, flags);
return _FUNC_REAL(pmem_memcpy)(dest, src, len, flags);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove_persist, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_persist_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memmove_persist)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove_nodrain, void *, void *dest, const void *src, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memcpy_nodrain_count(dest, src, len, 0);
return _FUNC_REAL(pmem_memmove_nodrain)(dest, src, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memmove, void *, void *dest, const void *src, size_t len,
unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memcpy_nodrain_count(dest, src, len, flags);
else
memcpy_persist_count(dest, src, len, flags);
return _FUNC_REAL(pmem_memmove)(dest, src, len, flags);
}
FUNC_MOCK_END
static void
memset_nodrain_count(void *dest, size_t len, unsigned flags)
{
unsigned cl_set = bulk_cl_changed(dest, len, flags);
if (!(flags & PMEM_F_MEM_NOFLUSH))
ops_counter.n_flush_from_pmem_memset += cl_set;
ops_counter.n_cl_stores += cl_set;
}
static void
memset_persist_count(void *dest, size_t len, unsigned flags)
{
memset_nodrain_count(dest, len, flags);
ops_counter.n_drain_from_pmem_memset++;
ops_counter.n_drain++;
}
FUNC_MOCK(pmem_memset_persist, void *, void *dest, int c, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memset_persist_count(dest, len, 0);
return _FUNC_REAL(pmem_memset_persist)(dest, c, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memset_nodrain, void *, void *dest, int c, size_t len)
FUNC_MOCK_RUN_DEFAULT {
memset_nodrain_count(dest, len, 0);
return _FUNC_REAL(pmem_memset_nodrain)(dest, c, len);
}
FUNC_MOCK_END
FUNC_MOCK(pmem_memset, void *, void *dest, int c, size_t len, unsigned flags)
FUNC_MOCK_RUN_DEFAULT {
flags = sanitize_flags(flags);
if (flags & PMEM_F_MEM_NODRAIN)
memset_nodrain_count(dest, len, flags);
else
memset_persist_count(dest, len, flags);
return _FUNC_REAL(pmem_memset)(dest, c, len, flags);
}
FUNC_MOCK_END
/*
* reset_counters -- zero all counters
*/
static void
reset_counters(void)
{
memset(&ops_counter, 0, sizeof(ops_counter));
}
/*
* print_reset_counters -- print and then zero all counters
*/
static void
print_reset_counters(const char *task, unsigned tx)
{
#define CNT(name) (ops_counter.name - tx * tx_counter.name)
UT_OUT(
"%-14s %-7d %-10d %-12d %-10d %-10d %-10d %-15d %-17d %-15d %-17d %-23d",
task,
CNT(n_cl_stores),
CNT(n_drain),
CNT(n_pmem_persist),
CNT(n_pmem_msync),
CNT(n_pmem_flush),
CNT(n_pmem_drain),
CNT(n_flush_from_pmem_memcpy),
CNT(n_drain_from_pmem_memcpy),
CNT(n_flush_from_pmem_memset),
CNT(n_drain_from_pmem_memset),
CNT(n_pot_cache_misses));
#undef CNT
reset_counters();
}
#define LARGE_SNAPSHOT ((1 << 10) * 10)
struct foo_large {
uint8_t snapshot[LARGE_SNAPSHOT];
};
struct foo {
int val;
uint64_t dest;
PMEMoid bar;
PMEMoid bar2;
};
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_persist_count");
if (argc != 2)
UT_FATAL("usage: %s file-name", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop;
if ((pop = pmemobj_create(path, "persist_count",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
UT_OUT(
"%-14s %-7s %-10s %-12s %-10s %-10s %-10s %-15s %-17s %-15s %-17s %-23s",
"task",
"cl(all)",
"drain(all)",
"pmem_persist",
"pmem_msync",
"pmem_flush",
"pmem_drain",
"pmem_memcpy_cls",
"pmem_memcpy_drain",
"pmem_memset_cls",
"pmem_memset_drain",
"potential_cache_misses");
print_reset_counters("pool_create", 0);
/* allocate one structure to create a run */
pmemobj_alloc(pop, NULL, sizeof(struct foo), 0, NULL, NULL);
reset_counters();
PMEMoid root = pmemobj_root(pop, sizeof(struct foo));
UT_ASSERT(!OID_IS_NULL(root));
print_reset_counters("root_alloc", 0);
PMEMoid oid;
int ret = pmemobj_alloc(pop, &oid, sizeof(struct foo), 0, NULL, NULL);
UT_ASSERTeq(ret, 0);
print_reset_counters("atomic_alloc", 0);
pmemobj_free(&oid);
print_reset_counters("atomic_free", 0);
struct foo *f = pmemobj_direct(root);
TX_BEGIN(pop) {
} TX_END
memcpy(&tx_counter, &ops_counter, sizeof(ops_counter));
print_reset_counters("tx_begin_end", 0);
TX_BEGIN(pop) {
f->bar = pmemobj_tx_alloc(sizeof(struct foo), 0);
UT_ASSERT(!OID_IS_NULL(f->bar));
} TX_END
print_reset_counters("tx_alloc", 1);
TX_BEGIN(pop) {
f->bar2 = pmemobj_tx_alloc(sizeof(struct foo), 0);
UT_ASSERT(!OID_IS_NULL(f->bar2));
} TX_END
print_reset_counters("tx_alloc_next", 1);
TX_BEGIN(pop) {
pmemobj_tx_free(f->bar);
} TX_END
print_reset_counters("tx_free", 1);
TX_BEGIN(pop) {
pmemobj_tx_free(f->bar2);
} TX_END
print_reset_counters("tx_free_next", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&f->val, sizeof(f->val),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&f->val, sizeof(f->val),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_next", 1);
PMEMoid large_foo;
pmemobj_alloc(pop, &large_foo, sizeof(struct foo_large), 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(large_foo));
reset_counters();
struct foo_large *flarge = pmemobj_direct(large_foo);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&flarge->snapshot,
sizeof(flarge->snapshot),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_large", 1);
TX_BEGIN(pop) {
pmemobj_tx_xadd_range_direct(&flarge->snapshot,
sizeof(flarge->snapshot),
POBJ_XADD_NO_FLUSH);
} TX_END
print_reset_counters("tx_add_lnext", 1);
pmalloc(pop, &f->dest, sizeof(f->val), 0, 0);
print_reset_counters("pmalloc", 0);
pfree(pop, &f->dest);
print_reset_counters("pfree", 0);
uint64_t stack_var;
pmalloc(pop, &stack_var, sizeof(f->val), 0, 0);
print_reset_counters("pmalloc_stack", 0);
pfree(pop, &stack_var);
print_reset_counters("pfree_stack", 0);
pmemobj_close(pop);
DONE(NULL);
}
#ifdef _MSC_VER
/*
* Since libpmemobj is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmemobj_init)
MSVC_DESTR(libpmemobj_fini)
#endif
| 12,490 | 24.439919 | 80 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmem_proto/rpmem_proto.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmem_proto.c -- unit test for rpmem_proto header
*
* The purpose of this test is to make sure the structures which describe
* rpmem protocol messages does not have any padding.
*/
#include "unittest.h"
#include "librpmem.h"
#include "rpmem_proto.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmem_proto");
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr, type);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_hdr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_hdr_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, status);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, type);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_hdr_resp, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_hdr_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_pool_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, signature);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, major);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, incompat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, ro_compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, poolset_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, next_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, prev_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr, user_flags);
ASSERT_ALIGNED_CHECK(struct rpmem_pool_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_pool_attr_packed);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, signature);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, major);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, incompat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, ro_compat_features);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, poolset_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, next_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, prev_uuid);
ASSERT_ALIGNED_FIELD(struct rpmem_pool_attr_packed, user_flags);
ASSERT_ALIGNED_CHECK(struct rpmem_pool_attr_packed);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_ibc_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, port);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, persist_method);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, rkey);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, raddr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_ibc_attr, nlanes);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_ibc_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_common);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, major);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, minor);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, pool_size);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, nlanes);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, provider);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_common, buff_size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_common);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_pool_desc);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_pool_desc, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_pool_desc);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_create);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, c);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, pool_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create, pool_desc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_create);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_create_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create_resp, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_create_resp, ibc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_create_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_open);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, c);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open, pool_desc);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_open);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_open_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, ibc);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_open_resp, pool_attr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_open_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_close);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close, flags);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_close);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_close_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_close_resp, hdr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_close_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_persist);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, flags);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, lane);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, addr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist, size);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_persist);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_persist_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist_resp, flags);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_persist_resp, lane);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_persist_resp);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_set_attr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr, hdr);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr, pool_attr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_set_attr);
ASSERT_ALIGNED_BEGIN(struct rpmem_msg_set_attr_resp);
ASSERT_ALIGNED_FIELD(struct rpmem_msg_set_attr_resp, hdr);
ASSERT_ALIGNED_CHECK(struct rpmem_msg_set_attr_resp);
DONE(NULL);
}
| 7,248 | 43.20122 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/signal_handle/signal_handle.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* signal_handle.c -- unit test for signal_handle
*
*
* operations are: 's', 'a', 'a', 'i', 'v'
* s: testing SIGSEGV with signal_handler_2
* a: testing SIGABRT with signal_handler_1
* a: testing second occurrence of SIGABRT with signal_handler_1
* i: testing SIGILL with signal_handler_2
* v: testing third occurrence of SIGABRT with other signal_handler_3
*
*/
#include "unittest.h"
ut_jmp_buf_t Jmp;
static void
signal_handler_1(int sig)
{
UT_OUT("\tsignal_handler_1: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
static void
signal_handler_2(int sig)
{
UT_OUT("\tsignal_handler_2: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
static void
signal_handler_3(int sig)
{
UT_OUT("\tsignal_handler_3: %s", os_strsignal(sig));
ut_siglongjmp(Jmp);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "signal_handle");
if (argc < 2)
UT_FATAL("usage: %s op:s|a|a|i|v", argv[0]);
struct sigaction v1, v2, v3;
sigemptyset(&v1.sa_mask);
v1.sa_flags = 0;
v1.sa_handler = signal_handler_1;
sigemptyset(&v2.sa_mask);
v2.sa_flags = 0;
v2.sa_handler = signal_handler_2;
SIGACTION(SIGSEGV, &v2, NULL);
SIGACTION(SIGABRT, &v1, NULL);
SIGACTION(SIGABRT, &v2, NULL);
SIGACTION(SIGABRT, &v1, NULL);
SIGACTION(SIGILL, &v2, NULL);
for (int arg = 1; arg < argc; arg++) {
if (strchr("sabiv", argv[arg][0]) == NULL ||
argv[arg][1] != '\0')
UT_FATAL("op must be one of: s, a, a, i, v");
switch (argv[arg][0]) {
case 's':
UT_OUT("Testing SIGSEGV...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGSEGV)) {
UT_OUT("\t SIGSEGV occurrence");
} else {
UT_OUT("\t Issue with SIGSEGV raise");
}
}
break;
case 'a':
UT_OUT("Testing SIGABRT...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGABRT)) {
UT_OUT("\t SIGABRT occurrence");
} else {
UT_OUT("\t Issue with SIGABRT raise");
}
}
break;
case 'i':
UT_OUT("Testing SIGILL...");
if (!ut_sigsetjmp(Jmp)) {
if (!raise(SIGILL)) {
UT_OUT("\t SIGILL occurrence");
} else {
UT_OUT("\t Issue with SIGILL raise");
}
}
break;
case 'v':
if (!ut_sigsetjmp(Jmp)) {
sigemptyset(&v3.sa_mask);
v3.sa_flags = 0;
v3.sa_handler = signal_handler_3;
UT_OUT("Testing SIGABRT...");
SIGACTION(SIGABRT, &v3, NULL);
if (!raise(SIGABRT)) {
UT_OUT("\t SIGABRT occurrence");
} else {
UT_OUT("\t Issue with SIGABRT raise");
}
}
break;
}
}
DONE(NULL);
}
| 4,064 | 25.225806 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_multiple_pools/cto_multiple_pools.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_multiple_pools.c -- unit test for cto_multiple_pools
*
* usage: cto_multiple_pools directory mode npools nthreads
*/
#include "unittest.h"
#define NREPEATS 10
static PMEMctopool **Pools;
static unsigned Npools;
static const char *Dir;
static unsigned *Pool_idx;
static os_thread_t *Threads;
static void *
thread_func_open(void *arg)
{
unsigned start_idx = *(unsigned *)arg;
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
for (int repeat = 0; repeat < NREPEATS; ++repeat) {
for (unsigned idx = 0; idx < Npools; ++idx) {
unsigned pool_id = start_idx + idx;
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
Pools[pool_id] = pmemcto_open(filename, "test");
UT_ASSERTne(Pools[pool_id], NULL);
void *ptr = pmemcto_malloc(Pools[pool_id], sizeof(int));
UT_OUT("pcp %p ptr %p", Pools[pool_id], ptr);
UT_ASSERTne(ptr, NULL);
pmemcto_free(Pools[pool_id], ptr);
pmemcto_close(Pools[pool_id]);
}
}
FREE(filename);
return NULL;
}
static void *
thread_func_create(void *arg)
{
unsigned start_idx = *(unsigned *)arg;
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
for (int repeat = 0; repeat < NREPEATS; ++repeat) {
for (unsigned idx = 0; idx < Npools; ++idx) {
unsigned pool_id = start_idx + idx;
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
/* delete old pool with the same id if exists */
if (Pools[pool_id] != NULL) {
pmemcto_close(Pools[pool_id]);
Pools[pool_id] = NULL;
UNLINK(filename);
}
Pools[pool_id] = pmemcto_create(filename, "test",
PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(Pools[pool_id], NULL);
void *ptr = pmemcto_malloc(Pools[pool_id], sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_free(Pools[pool_id], ptr);
}
}
FREE(filename);
return NULL;
}
static void
test_open(unsigned nthreads)
{
size_t len = strlen(Dir) + 50; /* reserve some space for pool id */
char *filename = MALLOC(sizeof(*filename) * len);
/* create all the pools */
for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id) {
snprintf(filename, len, "%s" OS_DIR_SEP_STR "pool%d",
Dir, pool_id);
UT_OUT("%s", filename);
Pools[pool_id] = pmemcto_create(filename, "test",
PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(Pools[pool_id], NULL);
}
for (unsigned pool_id = 0; pool_id < Npools * nthreads; ++pool_id)
pmemcto_close(Pools[pool_id]);
for (unsigned t = 0; t < nthreads; t++) {
Pool_idx[t] = Npools * t;
PTHREAD_CREATE(&Threads[t], NULL, thread_func_open,
&Pool_idx[t]);
}
for (unsigned t = 0; t < nthreads; t++)
PTHREAD_JOIN(&Threads[t], NULL);
FREE(filename);
}
static void
test_create(unsigned nthreads)
{
/* create and destroy pools multiple times */
for (unsigned t = 0; t < nthreads; t++) {
Pool_idx[t] = Npools * t;
PTHREAD_CREATE(&Threads[t], NULL, thread_func_create,
&Pool_idx[t]);
}
for (unsigned t = 0; t < nthreads; t++)
PTHREAD_JOIN(&Threads[t], NULL);
for (unsigned i = 0; i < Npools * nthreads; ++i) {
if (Pools[i] != NULL) {
pmemcto_close(Pools[i]);
Pools[i] = NULL;
}
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_multiple_pools");
if (argc < 4)
UT_FATAL("usage: %s directory mode npools nthreads", argv[0]);
Dir = argv[1];
char mode = argv[2][0];
Npools = ATOU(argv[3]);
unsigned nthreads = ATOU(argv[4]);
UT_OUT("create %d pools in %d thread(s)", Npools, nthreads);
Pools = CALLOC(Npools * nthreads, sizeof(Pools[0]));
Threads = CALLOC(nthreads, sizeof(Threads[0]));
Pool_idx = CALLOC(nthreads, sizeof(Pool_idx[0]));
switch (mode) {
case 'o':
test_open(nthreads);
break;
case 'c':
test_create(nthreads);
break;
default:
UT_FATAL("unknown mode");
}
FREE(Pools);
FREE(Threads);
FREE(Pool_idx);
DONE(NULL);
}
| 5,600 | 25.545024 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_toid/obj_toid.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_toid.c -- unit test for TOID_VALID, DIRECT_RO, DIRECT_RW macros
*/
#include <sys/param.h>
#include "unittest.h"
#define LAYOUT_NAME "toid"
#define TEST_NUM 5
TOID_DECLARE(struct obj, 0);
struct obj {
int id;
};
/*
* do_toid_valid -- validates if type number is equal to object's metadata
*/
static void
do_toid_valid(PMEMobjpool *pop)
{
TOID(struct obj) obj;
POBJ_NEW(pop, &obj, struct obj, NULL, NULL);
UT_ASSERT(!TOID_IS_NULL(obj));
UT_ASSERT(TOID_VALID(obj));
POBJ_FREE(&obj);
}
/*
* do_toid_no_valid -- validates if type number is not equal to
* object's metadata
*/
static void
do_toid_no_valid(PMEMobjpool *pop)
{
TOID(struct obj) obj;
int ret = pmemobj_alloc(pop, &obj.oid, sizeof(struct obj), TEST_NUM,
NULL, NULL);
UT_ASSERTeq(ret, 0);
UT_ASSERT(!TOID_VALID(obj));
POBJ_FREE(&obj);
}
/*
* do_direct_simple - checks if DIRECT_RW and DIRECT_RO macros correctly
* write and read from member of structure represented by TOID
*/
static void
do_direct_simple(PMEMobjpool *pop)
{
TOID(struct obj) obj;
POBJ_NEW(pop, &obj, struct obj, NULL, NULL);
D_RW(obj)->id = TEST_NUM;
pmemobj_persist(pop, &D_RW(obj)->id, sizeof(D_RW(obj)->id));
UT_ASSERTeq(D_RO(obj)->id, TEST_NUM);
POBJ_FREE(&obj);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_toid");
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
PMEMobjpool *pop;
if ((pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
do_toid_valid(pop);
do_toid_no_valid(pop);
do_direct_simple(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 3,231 | 27.857143 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_check/obj_check.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_check.c -- unit tests for pmemobj_check
*/
#include <stddef.h>
#include "unittest.h"
#include "libpmemobj.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_check");
if (argc < 2 || argc > 5)
UT_FATAL("usage: obj_check <file> [-l <layout>] [-o]");
const char *path = argv[1];
const char *layout = NULL;
PMEMobjpool *pop = NULL;
int open = 0;
for (int i = 2; i < argc; ++i) {
if (strcmp(argv[i], "-o") == 0)
open = 1;
else if (strcmp(argv[i], "-l") == 0) {
layout = argv[i + 1];
i++;
} else
UT_FATAL("Unrecognized argument: %s", argv[i]);
}
if (open) {
pop = pmemobj_open(path, layout);
if (pop == NULL)
UT_OUT("!%s: pmemobj_open", path);
else
UT_OUT("%s: pmemobj_open: Success", path);
}
int ret = pmemobj_check(path, layout);
switch (ret) {
case 1:
UT_OUT("consistent");
break;
case 0:
UT_OUT("not consistent: %s", pmemobj_errormsg());
break;
default:
UT_OUT("error: %s", pmemobj_errormsg());
break;
}
if (pop != NULL)
pmemobj_close(pop);
DONE(NULL);
}
| 2,651 | 28.142857 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/compat_incompat_features/pool_open.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pool_open.c -- a tool for verifying that an obj/blk/log pool opens correctly
*
* usage: pool_open <path> <obj|blk|log> <layout>
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "compat_incompat_features");
if (argc < 3)
UT_FATAL("usage: %s <obj|blk|log|cto> <path>", argv[0]);
char *type = argv[1];
char *path = argv[2];
if (strcmp(type, "obj") == 0) {
PMEMobjpool *pop = pmemobj_open(path, "");
if (pop == NULL) {
UT_FATAL("!%s: pmemobj_open failed", path);
} else {
UT_OUT("%s: pmemobj_open succeeded", path);
pmemobj_close(pop);
}
} else if (strcmp(type, "blk") == 0) {
PMEMblkpool *pop = pmemblk_open(path, 0);
if (pop == NULL) {
UT_FATAL("!%s: pmemblk_open failed", path);
} else {
UT_OUT("%s: pmemblk_open succeeded", path);
pmemblk_close(pop);
}
} else if (strcmp(type, "log") == 0) {
PMEMlogpool *pop = pmemlog_open(path);
if (pop == NULL) {
UT_FATAL("!%s: pmemlog_open failed", path);
} else {
UT_OUT("%s: pmemlog_open succeeded", path);
pmemlog_close(pop);
}
} else if (strcmp(type, "cto") == 0) {
PMEMctopool *pop = pmemcto_open(path, "");
if (pop == NULL) {
UT_FATAL("!%s: pmemcto_open failed", path);
} else {
UT_OUT("%s: pmemcto_open succeeded", path);
pmemcto_close(pop);
}
} else {
UT_FATAL("usage: %s <obj|blk|log|cto> <path>", argv[0]);
}
DONE(NULL);
}
| 2,998 | 33.079545 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset/mocks_windows.h | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of libc functions used in util_poolset
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of util_poolset test.
* It would replace default implementation with mocked functions defined
* in util_poolset.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL_OPEN
#define os_open __wrap_os_open
#endif
#ifndef WRAP_REAL_FALLOCATE
#define os_posix_fallocate __wrap_os_posix_fallocate
#endif
#ifndef WRAP_REAL_PMEM
#define pmem_is_pmem __wrap_pmem_is_pmem
#endif
| 2,245 | 38.403509 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset/util_poolset.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_poolset.c -- unit test for util_pool_create() / util_pool_open()
*
* usage: util_poolset cmd minlen hdrsize [mockopts] setfile ...
*/
#include <stdbool.h>
#include "unittest.h"
#include "pmemcommon.h"
#include "set.h"
#include <errno.h>
#include "mocks.h"
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "TEST_LOG_LEVEL"
#define LOG_FILE_VAR "TEST_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define SIG "PMEMXXX"
#define MIN_PART ((size_t)(1024 * 1024 * 2)) /* 2 MiB */
#define TEST_FORMAT_INCOMPAT_DEFAULT POOL_FEAT_CKSUM_2K
#define TEST_FORMAT_INCOMPAT_CHECK POOL_FEAT_INCOMPAT_VALID
static size_t Extend_size = MIN_PART * 2;
const char *Open_path = "";
os_off_t Fallocate_len = -1;
size_t Is_pmem_len = 0;
/*
* poolset_info -- (internal) dumps poolset info and checks its integrity
*
* Performs the following checks:
* - part_size[i] == rounddown(file_size - pool_hdr_size, Mmap_align)
* - replica_size == sum(part_size)
* - pool_size == min(replica_size)
*/
static void
poolset_info(const char *fname, struct pool_set *set, int o)
{
if (o)
UT_OUT("%s: opened: nreps %d poolsize %zu rdonly %d",
fname, set->nreplicas, set->poolsize,
set->rdonly);
else
UT_OUT("%s: created: nreps %d poolsize %zu zeroed %d",
fname, set->nreplicas, set->poolsize,
set->zeroed);
size_t poolsize = SIZE_MAX;
for (unsigned r = 0; r < set->nreplicas; r++) {
struct pool_replica *rep = set->replica[r];
size_t repsize = 0;
UT_OUT(" replica[%d]: nparts %d nhdrs %d repsize %zu "
"is_pmem %d",
r, rep->nparts, rep->nhdrs, rep->repsize, rep->is_pmem);
for (unsigned i = 0; i < rep->nparts; i++) {
struct pool_set_part *part = &rep->part[i];
UT_OUT(" part[%d] path %s filesize %zu size %zu",
i, part->path, part->filesize, part->size);
size_t partsize =
(part->filesize & ~(Ut_mmap_align - 1));
repsize += partsize;
if (i > 0 && (set->options & OPTION_SINGLEHDR) == 0)
UT_ASSERTeq(part->size,
partsize - Ut_mmap_align); /* XXX */
}
repsize -= (rep->nhdrs - 1) * Ut_mmap_align;
UT_ASSERTeq(rep->repsize, repsize);
UT_ASSERT(rep->resvsize >= repsize);
if (rep->repsize < poolsize)
poolsize = rep->repsize;
}
UT_ASSERTeq(set->poolsize, poolsize);
}
/*
* mock_options -- (internal) parse mock options and enable mocked functions
*/
static int
mock_options(const char *arg)
{
/* reset to defaults */
Open_path = "";
Fallocate_len = -1;
Is_pmem_len = 0;
if (arg[0] != '-' || arg[1] != 'm')
return 0;
switch (arg[2]) {
case 'n':
/* do nothing */
break;
case 'o':
/* open */
Open_path = &arg[4];
break;
case 'f':
/* fallocate */
Fallocate_len = ATOLL(&arg[4]);
break;
case 'p':
/* is_pmem */
Is_pmem_len = ATOULL(&arg[4]);
break;
default:
UT_FATAL("unknown mock option: %c", arg[2]);
}
return 1;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_poolset");
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
if (argc < 3)
UT_FATAL("usage: %s cmd minsize [mockopts] "
"setfile ...", argv[0]);
char *fname;
struct pool_set *set;
int ret;
size_t minsize = strtoul(argv[2], &fname, 0);
for (int arg = 3; arg < argc; arg++) {
arg += mock_options(argv[arg]);
fname = argv[arg];
struct pool_attr attr;
memset(&attr, 0, sizeof(attr));
memcpy(attr.signature, SIG, sizeof(SIG));
attr.major = 1;
switch (argv[1][0]) {
case 'c':
attr.features.incompat = TEST_FORMAT_INCOMPAT_DEFAULT;
ret = util_pool_create(&set, fname, 0, minsize,
MIN_PART, &attr, NULL, REPLICAS_ENABLED);
if (ret == -1)
UT_OUT("!%s: util_pool_create", fname);
else {
/*
* XXX: On Windows pool files are created with
* R/W permissions, so no need for chmod().
*/
#ifndef _WIN32
util_poolset_chmod(set, S_IWUSR | S_IRUSR);
#endif
poolset_info(fname, set, 0);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
break;
case 'o':
attr.features.incompat = TEST_FORMAT_INCOMPAT_CHECK;
ret = util_pool_open(&set, fname, MIN_PART, &attr,
NULL, NULL, 0 /* flags */);
if (ret == -1)
UT_OUT("!%s: util_pool_open", fname);
else {
poolset_info(fname, set, 1);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
break;
case 'e':
attr.features.incompat = TEST_FORMAT_INCOMPAT_CHECK;
ret = util_pool_open(&set, fname, MIN_PART, &attr,
NULL, NULL, 0 /* flags */);
UT_ASSERTeq(ret, 0);
size_t esize = Extend_size;
void *nptr = util_pool_extend(set, &esize, MIN_PART);
if (nptr == NULL)
UT_OUT("!%s: util_pool_extend", fname);
else {
poolset_info(fname, set, 1);
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
break;
}
}
common_fini();
DONE(NULL);
}
| 6,359 | 26.772926 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset/mocks.h | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MOCKS_H
#define MOCKS_H
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
#endif
| 1,731 | 41.243902 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset/mocks_windows.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in util_poolset.c
*/
#include "pmem.h"
#include "util.h"
#include "unittest.h"
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
/*
* os_open -- open mock
*
* due to diffrences in function mocking on linux we are wraping os_open
* but on linux we just wrap open syscall
*/
FUNC_MOCK(os_open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
if (strcmp(Open_path, path) == 0) {
UT_OUT("mocked open: %s", path);
errno = EACCES;
return -1;
}
va_list ap;
va_start(ap, flags);
int mode = va_arg(ap, int);
va_end(ap);
return _FUNC_REAL(os_open)(path, flags, mode);
}
FUNC_MOCK_END
/*
* posix_fallocate -- posix_fallocate mock
*/
FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Fallocate_len == len) {
UT_OUT("mocked fallocate: %ju", len);
return ENOSPC;
}
return _FUNC_REAL(os_posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* pmem_is_pmem -- pmem_is_pmem mock
*/
FUNC_MOCK(pmem_is_pmem, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Is_pmem_len == len) {
UT_OUT("mocked pmem_is_pmem: %zu", len);
return 1;
}
return _FUNC_REAL(pmem_is_pmem)(addr, len);
}
FUNC_MOCK_END
/*
* On Windows libpmem is statically linked to util_poolset test, but we
* don't want its ctor to initialize 'out' module.
*/
/*
* libpmem_init -- load-time initialization for libpmem
*
* Called automatically by the run-time loader.
*/
CONSTRUCTOR(libpmem_init)
void
libpmem_init(void)
{
pmem_init();
}
| 3,200 | 27.837838 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_poolset/mocks_posix.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_posix.c -- mocked functions used in util_poolset.c (Posix version)
*/
#include "unittest.h"
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
/*
* open -- open mock
*/
FUNC_MOCK(open, int, const char *path, int flags, ...)
FUNC_MOCK_RUN_DEFAULT {
if (strcmp(Open_path, path) == 0) {
UT_OUT("mocked open: %s", path);
errno = EACCES;
return -1;
}
va_list ap;
va_start(ap, flags);
int mode = va_arg(ap, int);
va_end(ap);
return _FUNC_REAL(open)(path, flags, mode);
}
FUNC_MOCK_END
/*
* posix_fallocate -- posix_fallocate mock
*/
FUNC_MOCK(posix_fallocate, int, int fd, os_off_t offset, off_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Fallocate_len == len) {
UT_OUT("mocked fallocate: %ju", len);
return ENOSPC;
}
return _FUNC_REAL(posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* pmem_is_pmem -- pmem_is_pmem mock
*/
FUNC_MOCK(pmem_is_pmem, int, const void *addr, size_t len)
FUNC_MOCK_RUN_DEFAULT {
if (Is_pmem_len == len) {
UT_OUT("mocked pmem_is_pmem: %zu", len);
return 1;
}
return _FUNC_REAL(pmem_is_pmem)(addr, len);
}
FUNC_MOCK_END
| 2,727 | 30 | 75 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_include/cto_include.c | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log_include.c -- include test for libpmemlog
*
* this is only a compilation test - do not run this program
*/
#include <libpmemlog.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,795 | 38.043478 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_realloc_inplace/cto_realloc_inplace.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_realloc_inplace -- unit test for pmemcto_realloc
*
* usage: cto_realloc_inplace filename
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_realloc_inplace");
if (argc != 2)
UT_FATAL("usage: %s filename", argv[0]);
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
PMEMCTO_MIN_POOL, 0666);
UT_ASSERTne(pcp, NULL);
int *test1 = pmemcto_malloc(pcp, 12 * 1024 * 1024);
UT_ASSERTne(test1, NULL);
int *test1r = pmemcto_realloc(pcp, test1, 6 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = pmemcto_realloc(pcp, test1, 12 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
test1r = pmemcto_realloc(pcp, test1, 8 * 1024 * 1024);
UT_ASSERTeq(test1r, test1);
int *test2 = pmemcto_malloc(pcp, 4 * 1024 * 1024);
UT_ASSERTne(test2, NULL);
/* 4MB => 16B */
int *test2r = pmemcto_realloc(pcp, test2, 16);
UT_ASSERTeq(test2r, NULL);
/* ... but the usable size is still 4MB. */
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, test2), 4 * 1024 * 1024);
/* 8MB => 16B */
test1r = pmemcto_realloc(pcp, test1, 16);
/*
* If the old size of the allocation is larger than
* the chunk size (4MB), we can reallocate it to 4MB first (in place),
* releasing some space, which makes it possible to do the actual
* shrinking...
*/
UT_ASSERTne(test1r, NULL);
UT_ASSERTne(test1r, test1);
UT_ASSERTeq(pmemcto_malloc_usable_size(pcp, test1r), 16);
/* ... and leaves some memory for new allocations. */
int *test3 = pmemcto_malloc(pcp, 3 * 1024 * 1024);
UT_ASSERTne(test3, NULL);
pmemcto_free(pcp, test1r);
pmemcto_free(pcp, test2r);
pmemcto_free(pcp, test3);
pmemcto_close(pcp);
DONE(NULL);
}
| 3,265 | 31.989899 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/out_err_win/out_err_win.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out_err_win.c -- unit test for error messages
*/
#define LOG_PREFIX "trace"
#define LOG_LEVEL_VAR "TRACE_LOG_LEVEL"
#define LOG_FILE_VAR "TRACE_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#include <sys/types.h>
#include <stdarg.h>
#include "unittest.h"
#include "pmemcommon.h"
int
wmain(int argc, wchar_t *argv[])
{
char buff[UT_MAX_ERR_MSG];
STARTW(argc, argv, "out_err_win");
/* Execute test */
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
errno = 0;
ERR("ERR #%d", 1);
UT_OUT("%S", out_get_errormsgW());
errno = 0;
ERR("!ERR #%d", 2);
UT_OUT("%S", out_get_errormsgW());
errno = EINVAL;
ERR("!ERR #%d", 3);
UT_OUT("%S", out_get_errormsgW());
errno = EBADF;
ut_strerror(errno, buff, UT_MAX_ERR_MSG);
out_err(__FILE__, 100, __func__,
"ERR1: %s:%d", buff, 1234);
UT_OUT("%S", out_get_errormsgW());
errno = EBADF;
ut_strerror(errno, buff, UT_MAX_ERR_MSG);
out_err(NULL, 0, NULL,
"ERR2: %s:%d", buff, 1234);
UT_OUT("%S", out_get_errormsgW());
/* Cleanup */
common_fini();
DONEW(NULL);
}
| 2,689 | 29.568182 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmmalloc_realloc/vmmalloc_realloc.c | /*
* Copyright 2014-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmmalloc_realloc -- unit test for libvmmalloc realloc
*
* usage: vmmalloc_realloc
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
const int test_value = 123456;
START(argc, argv, "vmmalloc_realloc");
int *test = realloc(NULL, sizeof(int));
UT_ASSERTne(test, NULL);
test[0] = test_value;
UT_ASSERTeq(test[0], test_value);
test = realloc(test, sizeof(int) * 10);
UT_ASSERTne(test, NULL);
UT_ASSERTeq(test[0], test_value);
test[1] = test_value;
test[9] = test_value;
free(test);
DONE(NULL);
}
| 2,134 | 32.359375 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_include/pmem_include.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_include.c -- include test for libpmem
*
* this is only a compilation test - do not run this program
*/
#include <libpmem.h>
int
main(int argc, char *argv[])
{
return 0;
}
| 1,786 | 37.021277 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_memset/pmem_memset.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_memset.c -- unit test for doing a memset
*
* usage: pmem_memset file offset length
*/
#include "unittest.h"
#include "util_pmem.h"
#include "file.h"
typedef void *pmem_memset_fn(void *pmemdest, int c, size_t len, unsigned flags);
static void *
pmem_memset_persist_wrapper(void *pmemdest, int c, size_t len, unsigned flags)
{
(void) flags;
return pmem_memset_persist(pmemdest, c, len);
}
static void *
pmem_memset_nodrain_wrapper(void *pmemdest, int c, size_t len, unsigned flags)
{
(void) flags;
return pmem_memset_nodrain(pmemdest, c, len);
}
static void
do_memset(int fd, char *dest, const char *file_name, size_t dest_off,
size_t bytes, pmem_memset_fn fn, unsigned flags)
{
char *buf = MALLOC(bytes);
char *dest1;
char *ret;
enum file_type type = util_fd_get_type(fd);
if (type < 0)
UT_FATAL("cannot check type of file with fd %d", fd);
memset(dest, 0, bytes);
util_persist_auto(type == TYPE_DEVDAX, dest, bytes);
dest1 = MALLOC(bytes);
memset(dest1, 0, bytes);
/*
* This is used to verify that the value of what a non persistent
* memset matches the outcome of the persistent memset. The
* persistent memset will match the file but may not be the
* correct or expected value.
*/
memset(dest1 + dest_off, 0x5A, bytes / 4);
memset(dest1 + dest_off + (bytes / 4), 0x46, bytes / 4);
/* Test the corner cases */
ret = fn(dest + dest_off, 0x5A, 0, flags);
UT_ASSERTeq(ret, dest + dest_off);
UT_ASSERTeq(*(char *)(dest + dest_off), 0);
/*
* Do the actual memset with persistence.
*/
ret = fn(dest + dest_off, 0x5A, bytes / 4, flags);
UT_ASSERTeq(ret, dest + dest_off);
ret = fn(dest + dest_off + (bytes / 4), 0x46, bytes / 4, flags);
UT_ASSERTeq(ret, dest + dest_off + (bytes / 4));
if (memcmp(dest, dest1, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
LSEEK(fd, 0, SEEK_SET);
if (READ(fd, buf, bytes / 2) == bytes / 2) {
if (memcmp(buf, dest, bytes / 2))
UT_FATAL("%s: first %zu bytes do not match",
file_name, bytes / 2);
}
FREE(dest1);
FREE(buf);
}
static unsigned Flags[] = {
0,
PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_NONTEMPORAL,
PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL,
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_NODRAIN,
PMEM_F_MEM_WC,
PMEM_F_MEM_WB,
PMEM_F_MEM_NOFLUSH,
/* all possible flags */
PMEM_F_MEM_NODRAIN | PMEM_F_MEM_NOFLUSH |
PMEM_F_MEM_NONTEMPORAL | PMEM_F_MEM_TEMPORAL |
PMEM_F_MEM_WC | PMEM_F_MEM_WB,
};
static void
do_memset_variants(int fd, char *dest, const char *file_name, size_t dest_off,
size_t bytes)
{
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset_persist_wrapper, 0);
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset_nodrain_wrapper, 0);
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
do_memset(fd, dest, file_name, dest_off, bytes,
pmem_memset, Flags[i]);
if (Flags[i] & PMEMOBJ_F_MEM_NOFLUSH)
pmem_persist(dest, bytes);
}
}
int
main(int argc, char *argv[])
{
int fd;
size_t mapped_len;
char *dest;
if (argc != 4)
UT_FATAL("usage: %s file offset length", argv[0]);
const char *thr = getenv("PMEM_MOVNT_THRESHOLD");
const char *avx = getenv("PMEM_AVX");
const char *avx512f = getenv("PMEM_AVX512F");
START(argc, argv, "pmem_memset %s %s %s %savx %savx512f",
argv[2], argv[3],
thr ? thr : "default",
avx ? "" : "!",
avx512f ? "" : "!");
fd = OPEN(argv[1], O_RDWR);
/* open a pmem file and memory map it */
if ((dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, NULL)) == NULL)
UT_FATAL("!Could not mmap %s\n", argv[1]);
size_t dest_off = strtoul(argv[2], NULL, 0);
size_t bytes = strtoul(argv[3], NULL, 0);
do_memset_variants(fd, dest, argv[1], dest_off, bytes);
UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);
CLOSE(fd);
DONE(NULL);
}
| 5,428 | 28.505435 | 80 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_pool_win/obj_pool_win.c | /*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_pool.c -- unit test for pmemobj_create() and pmemobj_open()
*
* usage: obj_pool op path layout [poolsize mode]
*
* op can be:
* c - create
* o - open
*
* "poolsize" and "mode" arguments are ignored for "open"
*/
#include "unittest.h"
#define MB ((size_t)1 << 20)
static void
pool_create(const wchar_t *path, const wchar_t *layout, size_t poolsize,
unsigned mode)
{
char *upath = ut_toUTF8(path);
PMEMobjpool *pop = pmemobj_createW(path, layout, poolsize, mode);
if (pop == NULL)
UT_OUT("!%s: pmemobj_create", upath);
else {
os_stat_t stbuf;
STATW(path, &stbuf);
UT_OUT("%s: file size %zu mode 0%o",
upath, stbuf.st_size,
stbuf.st_mode & 0777);
pmemobj_close(pop);
int result = pmemobj_checkW(path, layout);
if (result < 0)
UT_OUT("!%s: pmemobj_check", upath);
else if (result == 0)
UT_OUT("%s: pmemobj_check: not consistent", upath);
}
free(upath);
}
static void
pool_open(const wchar_t *path, const wchar_t *layout)
{
char *upath = ut_toUTF8(path);
PMEMobjpool *pop = pmemobj_openW(path, layout);
if (pop == NULL) {
UT_OUT("!%s: pmemobj_open", upath);
} else {
UT_OUT("%s: pmemobj_open: Success", upath);
pmemobj_close(pop);
}
free(upath);
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "obj_pool_win");
if (argc < 4)
UT_FATAL("usage: %s op path layout [poolsize mode]",
ut_toUTF8(argv[0]));
wchar_t *layout = NULL;
size_t poolsize;
unsigned mode;
if (wcscmp(argv[3], L"EMPTY") == 0)
layout = L"";
else if (wcscmp(argv[3], L"NULL") != 0)
layout = argv[3];
switch (argv[1][0]) {
case 'c':
poolsize = wcstoul(argv[4], NULL, 0) * MB; /* in megabytes */
mode = wcstoul(argv[5], NULL, 8);
pool_create(argv[2], layout, poolsize, mode);
break;
case 'o':
pool_open(argv[2], layout);
break;
default:
UT_FATAL("unknown operation");
}
DONEW(NULL);
}
| 3,480 | 26.195313 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/checksum/checksum.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* checksum.c -- unit test for library internal checksum routine
*
* usage: checksum files...
*/
#include <endian.h>
#include "unittest.h"
#include "util.h"
#include <inttypes.h>
/*
* fletcher64 -- compute a Fletcher64 checksum
*
* Gold standard implementation used to compare to the
* util_checksum() being unit tested.
*/
static uint64_t
fletcher64(void *addr, size_t len)
{
UT_ASSERT(len % 4 == 0);
uint32_t *p32 = addr;
uint32_t *p32end = (uint32_t *)((char *)addr + len);
uint32_t lo32 = 0;
uint32_t hi32 = 0;
while (p32 < p32end) {
lo32 += le32toh(*p32);
p32++;
hi32 += lo32;
}
return htole64((uint64_t)hi32 << 32 | lo32);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "checksum");
if (argc < 2)
UT_FATAL("usage: %s files...", argv[0]);
for (int arg = 1; arg < argc; arg++) {
int fd = OPEN(argv[arg], O_RDONLY);
os_stat_t stbuf;
FSTAT(fd, &stbuf);
size_t size = (size_t)stbuf.st_size;
void *addr =
MMAP(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0);
uint64_t *ptr = addr;
/*
* Loop through, selecting successive locations
* where the checksum lives in this block, and
* let util_checksum() insert it so it can be
* verified against the gold standard fletcher64
* routine in this file.
*/
while ((char *)(ptr + 1) < (char *)addr + size) {
/* save whatever was at *ptr */
uint64_t oldval = *ptr;
/* mess with it */
*ptr = htole64(0x123);
/*
* calculate a checksum and have it installed
*/
util_checksum(addr, size, ptr, 1, 0);
uint64_t csum = *ptr;
/*
* verify inserted checksum checks out
*/
UT_ASSERT(util_checksum(addr, size, ptr, 0, 0));
/* put a zero where the checksum was installed */
*ptr = 0;
/* calculate a checksum */
uint64_t gold_csum = fletcher64(addr, size);
/* put the old value back */
*ptr = oldval;
/*
* verify checksum now fails
*/
UT_ASSERT(!util_checksum(addr, size, ptr,
0, 0));
/*
* verify the checksum matched the gold version
*/
UT_ASSERTeq(csum, gold_csum);
UT_OUT("%s:%" PRIu64 " 0x%" PRIx64, argv[arg],
(char *)ptr - (char *)addr, csum);
ptr++;
}
uint64_t *addr2 =
MMAP(NULL, size, PROT_READ|PROT_WRITE,
MAP_PRIVATE, fd, 0);
uint64_t *csum = (uint64_t *)addr;
/*
* put a zero where the checksum will be installed
* in the second map
*/
*addr2 = 0;
for (size_t i = size / 8 - 1; i > 0; i -= 1) {
/* calculate a checksum and have it installed */
util_checksum(addr, size, csum, 1, i * 8);
/*
* put a zero in the second map where an ignored part is
*/
*(addr2 + i) = 0;
/* calculate a checksum */
uint64_t gold_csum = fletcher64(addr2, size);
/*
* verify the checksum matched the gold version
*/
UT_ASSERTeq(*csum, gold_csum);
}
CLOSE(fd);
MUNMAP(addr, size);
MUNMAP(addr2, size);
}
DONE(NULL);
}
| 4,529 | 24.738636 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_fragmentation/obj_fragmentation.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_fragmentation.c -- measures average heap fragmentation
*
* A pretty simplistic test that measures internal fragmentation of the
* allocator for the given size.
*/
#include <stdlib.h>
#include "unittest.h"
#define LAYOUT_NAME "obj_fragmentation"
#define OBJECT_OVERHEAD 64 /* account for the header added to each object */
#define MAX_OVERALL_OVERHEAD 0.10f
/*
* For the best accuracy fragmentation should be measured for one full zone
* because the metadata is preallocated. For reasonable test duration a smaller
* size must be used.
*/
#define DEFAULT_FILE_SIZE ((size_t)(1ULL << 28)) /* 256 megabytes */
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_fragmentation");
if (argc < 3)
UT_FATAL("usage: %s allocsize filename [filesize]", argv[0]);
size_t file_size;
if (argc == 4)
file_size = ATOUL(argv[3]);
else
file_size = DEFAULT_FILE_SIZE;
size_t alloc_size = ATOUL(argv[1]);
const char *path = argv[2];
PMEMobjpool *pop = pmemobj_create(path, LAYOUT_NAME, file_size,
S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create: %s", path);
size_t allocated = 0;
int err = 0;
do {
PMEMoid oid;
err = pmemobj_alloc(pop, &oid, alloc_size, 0, NULL, NULL);
if (err == 0)
allocated += pmemobj_alloc_usable_size(oid) +
OBJECT_OVERHEAD;
} while (err == 0);
float allocated_pct = ((float)allocated / file_size);
float overhead_pct = 1.f - allocated_pct;
UT_ASSERT(overhead_pct <= MAX_OVERALL_OVERHEAD);
pmemobj_close(pop);
DONE(NULL);
}
| 3,122 | 32.223404 | 79 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/traces/traces.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* traces.c -- unit test for traces
*/
#define LOG_PREFIX "ut"
#define LOG_LEVEL_VAR "UT_LOG_LEVEL"
#define LOG_FILE_VAR "UT_LOG_FILE"
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#include <sys/types.h>
#include <stdarg.h>
#include "pmemcommon.h"
#include "unittest.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "traces");
/* Execute test */
common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
MAJOR_VERSION, MINOR_VERSION);
LOG(0, "Log level NONE");
LOG(1, "Log level ERROR");
LOG(2, "Log level WARNING");
LOG(3, "Log level INFO");
LOG(4, "Log level DEBUG");
/* Cleanup */
common_fini();
DONE(NULL);
}
| 2,243 | 32.492537 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_stats/vmem_stats.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_stats.c -- unit test for vmem_stats
*
* usage: vmem_stats 0|1 [opts]
*/
#include "unittest.h"
static int custom_allocs;
static int custom_alloc_calls;
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
int
main(int argc, char *argv[])
{
int expect_custom_alloc = 0;
char *opts = "";
void *mem_pool;
VMEM *vmp_unused;
VMEM *vmp_used;
START(argc, argv, "vmem_stats");
if (argc > 3 || argc < 2) {
UT_FATAL("usage: %s 0|1 [opts]", argv[0]);
} else {
expect_custom_alloc = atoi(argv[1]);
if (argc > 2)
opts = argv[2];
}
if (expect_custom_alloc)
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp_unused = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp_unused == NULL)
UT_FATAL("!vmem_create_in_region");
mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp_used = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
if (vmp_used == NULL)
UT_FATAL("!vmem_create_in_region");
int *test = vmem_malloc(vmp_used, sizeof(int)*100);
UT_ASSERTne(test, NULL);
vmem_stats_print(vmp_unused, opts);
vmem_stats_print(vmp_used, opts);
vmem_free(vmp_used, test);
vmem_delete(vmp_unused);
vmem_delete(vmp_used);
/* check memory leak in custom allocator */
UT_ASSERTeq(custom_allocs, 0);
if (expect_custom_alloc == 0) {
UT_ASSERTeq(custom_alloc_calls, 0);
} else {
UT_ASSERTne(custom_alloc_calls, 0);
}
DONE(NULL);
}
| 4,076 | 25.303226 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_first_next/obj_first_next.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_first_next.c -- unit tests for POBJ_FIRST macro
*/
#include <stddef.h>
#include "libpmemobj.h"
#include "unittest.h"
#define LAYOUT_NAME "obj_first_next"
TOID_DECLARE(struct type, 0);
TOID_DECLARE(struct type_sec, 1);
struct type {
int id;
};
struct type_sec {
int id;
};
static PMEMobjpool *pop;
typedef void (*fn_op)(int id);
typedef void (*fn_void)();
#define FATAL_USAGE()\
UT_FATAL("usage: obj_first_next <file> [Parfn]")
/*
* get_item_type -- get nth item from list
*/
static TOID(struct type)
get_item_type(int n)
{
TOID(struct type) item;
POBJ_FOREACH_TYPE(pop, item) {
if (n == 0)
return item;
n--;
}
return TOID_NULL(struct type);
}
/*
* get_item_type_sec -- get nth item from list
*/
static TOID(struct type_sec)
get_item_type_sec(int n)
{
TOID(struct type_sec) item;
POBJ_FOREACH_TYPE(pop, item) {
if (n == 0)
return item;
n--;
}
return TOID_NULL(struct type_sec);
}
/*
* do_print_type -- print list elements from type collection
*/
static void
do_print_type(void)
{
TOID(struct type) item;
UT_OUT("type:");
POBJ_FOREACH_TYPE(pop, item) {
UT_OUT("id = %d", D_RO(item)->id);
}
}
/*
* do_print_type_sec -- print list elements from type_sec collection
*/
static void
do_print_type_sec(void)
{
TOID(struct type_sec) item;
UT_OUT("type_sec:");
POBJ_FOREACH_TYPE(pop, item) {
UT_OUT("id = %d", D_RO(item)->id);
}
}
static fn_void do_print[] = {do_print_type, do_print_type_sec};
/*
* type_constructor -- constructor which sets the item's id to
* new value
*/
static int
type_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
int id = *(int *)arg;
struct type *item = (struct type *)ptr;
item->id = id;
UT_OUT("constructor(id = %d)", id);
pmemobj_persist(pop, item, sizeof(*item));
return 0;
}
/*
* type_sec_constructor -- constructor which sets the item's id to
* new value
*/
static int
type_sec_constructor(PMEMobjpool *pop, void *ptr, void *arg)
{
int id = *(int *)arg;
struct type_sec *item = (struct type_sec *)ptr;
item->id = id;
UT_OUT("constructor(id = %d)", id);
pmemobj_persist(pop, item, sizeof(*item));
return 0;
}
/*
* do_alloc_type -- allocates new element to type collection
*/
static void
do_alloc_type(int id)
{
TOID(struct type) item;
POBJ_NEW(pop, &item, struct type, type_constructor, &id);
if (TOID_IS_NULL(item))
UT_FATAL("POBJ_NEW");
}
/*
* do_alloc_type_sec -- allocates new element to type_sec collection
*/
static void
do_alloc_type_sec(int id)
{
TOID(struct type_sec) item;
POBJ_NEW(pop, &item, struct type_sec, type_sec_constructor, &id);
if (TOID_IS_NULL(item))
UT_FATAL("POBJ_NEW");
}
static fn_op do_alloc[] = {do_alloc_type, do_alloc_type_sec};
/*
* do_free_type -- remove and free element from type collection
*/
static void
do_free_type(int n)
{
TOID(struct type) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type)))
return;
item = get_item_type(n);
UT_ASSERT(!TOID_IS_NULL(item));
POBJ_FREE(&item);
}
/*
* do_free_type_sec -- remove and free element from type_sec collection
*/
static void
do_free_type_sec(int n)
{
TOID(struct type_sec) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type_sec)))
return;
item = get_item_type_sec(n);
UT_ASSERT(!TOID_IS_NULL(item));
POBJ_FREE(&item);
}
static fn_op do_free[] = {do_free_type, do_free_type_sec};
/*
* do_first_type -- prints id of first object in type collection
*/
static void
do_first_type(void)
{
TOID(struct type) first = POBJ_FIRST(pop, struct type);
UT_OUT("first id = %d", D_RO(first)->id);
}
/*
* do_first_type_sec -- prints id of first object in type_sec collection
*/
static void
do_first_type_sec(void)
{
TOID(struct type_sec) first = POBJ_FIRST(pop, struct type_sec);
UT_OUT("first id = %d", D_RO(first)->id);
}
static fn_void do_first[] = {do_first_type, do_first_type_sec};
/*
* do_next_type -- finds next element from type collection
*/
static void
do_next_type(int n)
{
TOID(struct type) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type)))
return;
item = get_item_type(n);
UT_ASSERT(!TOID_IS_NULL(item));
item = POBJ_NEXT(item);
UT_OUT("next id = %d", D_RO(item)->id);
}
/*
* do_next_type_sec -- finds next element from type_sec collection
*/
static void
do_next_type_sec(int n)
{
TOID(struct type_sec) item;
if (TOID_IS_NULL(POBJ_FIRST(pop, struct type_sec)))
return;
item = get_item_type_sec(n);
UT_ASSERT(!TOID_IS_NULL(item));
item = POBJ_NEXT(item);
UT_OUT("next id = %d", D_RO(item)->id);
}
static fn_op do_next[] = {do_next_type, do_next_type_sec};
/*
* do_cleanup -- de-initialization function
*/
static void
do_cleanup(void)
{
PMEMoid oid, oid_tmp;
POBJ_FOREACH_SAFE(pop, oid, oid_tmp)
pmemobj_free(&oid);
}
static void
test_internal_object_mask(PMEMobjpool *pop)
{
/* allocate root object */
PMEMoid root = pmemobj_root(pop, sizeof(struct type));
TX_BEGIN(pop) {
/* trigger creation of a range cache */
pmemobj_tx_add_range(root, 0, 8);
} TX_END
PMEMoid oid;
pmemobj_alloc(pop, &oid, sizeof(struct type), 0, NULL, NULL);
UT_ASSERT(!OID_IS_NULL(oid));
/* verify that there's no root object nor range cache anywhere */
for (PMEMoid iter = pmemobj_first(pop); !OID_IS_NULL(iter);
iter = pmemobj_next(iter)) {
UT_ASSERT(OID_EQUALS(iter, oid));
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_first_next");
if (argc < 2)
FATAL_USAGE();
const char *path = argv[1];
if ((pop = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
for (int i = 2; i < argc; i++) {
int list_num;
int id;
char type;
if (sscanf(argv[i], "%c:%d:%d", &type, &list_num, &id) == EOF)
UT_FATAL("!sscanf");
switch (type) {
case 'P':
do_print[list_num]();
break;
case 'a':
do_alloc[list_num](id);
break;
case 'r':
do_free[list_num](id);
break;
case 'f':
do_first[list_num]();
break;
case 'n':
do_next[list_num](id);
break;
default:
FATAL_USAGE();
}
}
do_cleanup();
test_internal_object_mask(pop);
pmemobj_close(pop);
DONE(NULL);
}
| 7,669 | 21.426901 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/libpmempool_transform_win/libpmempool_transform_win.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmempool_transform_win -- a unittest for libpmempool transform.
*
*/
#include <stddef.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "unittest.h"
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "libpmempool_transform_win");
if (argc != 4)
UT_FATAL("usage: %s poolset_in poolset_out flags",
ut_toUTF8(argv[0]));
int ret = pmempool_transformW(argv[1], argv[2],
(unsigned)wcstoul(argv[3], NULL, 0));
if (ret)
UT_OUT("result: %d, errno: %d", ret, errno);
else
UT_OUT("result: 0");
DONEW(NULL);
}
| 2,162 | 33.887097 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_recovery/obj_recovery.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_recovery.c -- unit test for pool recovery
*/
#include "unittest.h"
#include "valgrind_internal.h"
#if VG_PMEMCHECK_ENABLED
#define VALGRIND_PMEMCHECK_END_TX VALGRIND_PMC_END_TX
#else
#define VALGRIND_PMEMCHECK_END_TX
#endif
POBJ_LAYOUT_BEGIN(recovery);
POBJ_LAYOUT_ROOT(recovery, struct root);
POBJ_LAYOUT_TOID(recovery, struct foo);
POBJ_LAYOUT_END(recovery);
struct foo {
int bar;
};
struct root {
PMEMmutex lock;
TOID(struct foo) foo;
};
#define BAR_VALUE 5
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_recovery");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(recovery) != 1);
if (argc != 5)
UT_FATAL("usage: %s [file] [lock: y/n] "
"[cmd: c/o] [type: n/f/s]",
argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
int exists = argv[3][0] == 'o';
enum { TEST_NEW, TEST_FREE, TEST_SET } type;
if (argv[4][0] == 'n')
type = TEST_NEW;
else if (argv[4][0] == 'f')
type = TEST_FREE;
else if (argv[4][0] == 's')
type = TEST_SET;
else
UT_FATAL("invalid type");
if (!exists) {
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(recovery),
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_FATAL("failed to create pool\n");
}
} else {
if ((pop = pmemobj_open(path, POBJ_LAYOUT_NAME(recovery)))
== NULL) {
UT_FATAL("failed to open pool\n");
}
}
TOID(struct root) root = POBJ_ROOT(pop, struct root);
int lock_type = TX_PARAM_NONE;
void *lock = NULL;
if (argv[2][0] == 'y') {
lock_type = TX_PARAM_MUTEX;
lock = &D_RW(root)->lock;
}
if (type == TEST_SET) {
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TOID(struct foo) f = TX_NEW(struct foo);
D_RW(root)->foo = f;
D_RW(f)->bar = BAR_VALUE;
} TX_END
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD_FIELD(D_RW(root)->foo, bar);
D_RW(D_RW(root)->foo)->bar = BAR_VALUE * 2;
/*
* Even though flushes are not required inside
* of a transaction, this is done here to
* suppress irrelevant pmemcheck issues, because
* we exit the program before the data is
* flushed, while preserving any real ones.
*/
pmemobj_persist(pop,
&D_RW(D_RW(root)->foo)->bar,
sizeof(int));
/*
* We also need to cleanup the transaction state
* of pmemcheck.
*/
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(D_RW(D_RW(root)->foo)->bar == BAR_VALUE);
}
} else if (type == TEST_NEW) {
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TOID(struct foo) f = TX_NEW(struct foo);
TX_SET(root, foo, f);
pmemobj_persist(pop,
&D_RW(root)->foo,
sizeof(PMEMoid));
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(TOID_IS_NULL(D_RW(root)->foo));
}
} else { /* TEST_FREE */
if (!exists) {
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TOID(struct foo) f = TX_NEW(struct foo);
D_RW(root)->foo = f;
D_RW(f)->bar = BAR_VALUE;
} TX_END
TX_BEGIN_PARAM(pop, lock_type, lock) {
TX_ADD(root);
TX_FREE(D_RW(root)->foo);
D_RW(root)->foo = TOID_NULL(struct foo);
pmemobj_persist(pop,
&D_RW(root)->foo,
sizeof(PMEMoid));
VALGRIND_PMEMCHECK_END_TX;
exit(0); /* simulate a crash */
} TX_END
} else {
UT_ASSERT(!TOID_IS_NULL(D_RW(root)->foo));
}
}
UT_ASSERT(pmemobj_check(path, POBJ_LAYOUT_NAME(recovery)));
pmemobj_close(pop);
DONE(NULL);
}
| 5,112 | 25.220513 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_is_pmem_posix.c -- Posix specific unit test for pmem_is_pmem()
*
* usage: pmem_is_pmem_posix op addr len [op addr len ...]
* where op can be: 'a' (add), 'r' (remove), 't' (test)
*/
#include <stdlib.h>
#include "unittest.h"
#include "mmap.h"
static enum pmem_map_type
str2type(char *str)
{
if (strcmp(str, "DEV_DAX") == 0)
return PMEM_DEV_DAX;
if (strcmp(str, "MAP_SYNC") == 0)
return PMEM_MAP_SYNC;
FATAL("unknown type '%s'", str);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_is_pmem_posix");
if (argc < 4)
UT_FATAL("usage: %s op addr len type [op addr len type ...]",
argv[0]);
/* insert memory regions to the list */
int i;
for (i = 1; i < argc; ) {
UT_ASSERT(i + 2 < argc);
errno = 0;
void *addr = (void *)strtoull(argv[i + 1], NULL, 0);
UT_ASSERTeq(errno, 0);
size_t len = strtoull(argv[i + 2], NULL, 0);
UT_ASSERTeq(errno, 0);
int ret;
switch (argv[i][0]) {
case 'a':
ret = util_range_register(addr, len, "",
str2type(argv[i + 3]));
if (ret != 0)
UT_OUT("%s", pmem_errormsg());
i += 4;
break;
case 'r':
ret = util_range_unregister(addr, len);
UT_ASSERTeq(ret, 0);
i += 3;
break;
case 't':
UT_OUT("addr %p len %zu is_pmem %d",
addr, len, pmem_is_pmem(addr, len));
i += 3;
break;
default:
FATAL("invalid op '%c'", argv[i][0]);
}
}
DONE(NULL);
}
| 2,990 | 27.759615 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_direct_volatile/obj_direct_volatile.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_volatile.c -- unit test for pmemobj_direct_volatile()
*/
#include "unittest.h"
static PMEMobjpool *pop;
struct test {
PMEMvlt(int) count;
};
#define TEST_OBJECTS 100
#define TEST_WORKERS 10
static struct test *tests[TEST_OBJECTS];
static int
test_constructor(void *ptr, void *arg)
{
int *count = ptr;
util_fetch_and_add32(count, 1);
return 0;
}
static void *
test_worker(void *arg)
{
for (int i = 0; i < TEST_OBJECTS; ++i) {
int *count = pmemobj_volatile(pop, &tests[i]->count.vlt,
&tests[i]->count.value, sizeof(tests[i]->count.value),
test_constructor, NULL);
UT_ASSERTne(count, NULL);
UT_ASSERTeq(*count, 1);
}
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_direct_volatile");
if (argc != 2)
UT_FATAL("usage: %s file", argv[0]);
char *path = argv[1];
pop = pmemobj_create(path, "obj_direct_volatile",
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR);
if (pop == NULL)
UT_FATAL("!pmemobj_create");
for (int i = 0; i < TEST_OBJECTS; ++i) {
PMEMoid oid;
pmemobj_zalloc(pop, &oid, sizeof(struct test), 1);
UT_ASSERT(!OID_IS_NULL(oid));
tests[i] = pmemobj_direct(oid);
}
os_thread_t t[TEST_WORKERS];
for (int i = 0; i < TEST_WORKERS; ++i) {
PTHREAD_CREATE(&t[i], NULL, test_worker, NULL);
}
for (int i = 0; i < TEST_WORKERS; ++i) {
PTHREAD_JOIN(&t[i], NULL);
}
for (int i = 0; i < TEST_OBJECTS; ++i) {
UT_ASSERTeq(tests[i]->count.value, 1);
}
pmemobj_close(pop);
DONE(NULL);
}
| 3,075 | 27.220183 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_parse_size/util_parse_size.c | /*
* Copyright 2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_parse_size.c -- unit test for parsing a size
*/
#include "unittest.h"
#include "util.h"
#include <inttypes.h>
int
main(int argc, char *argv[])
{
int ret = 0;
uint64_t size = 0;
START(argc, argv, "util_parse_size");
for (int arg = 1; arg < argc; ++arg) {
ret = util_parse_size(argv[arg], &size);
if (ret == 0) {
UT_OUT("%s - correct %"PRIu64, argv[arg], size);
} else {
UT_OUT("%s - incorrect", argv[arg]);
}
}
DONE(NULL);
}
| 2,058 | 33.316667 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_unmap/pmem_unmap.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_unmap.c -- unit tests for pmem_unmap
*/
#include "unittest.h"
#define KILOBYTE (1 << 10)
#define MEGABYTE (1 << 20)
#define PAGE_4K (4 * KILOBYTE)
#define PAGE_2M (2 * MEGABYTE)
int
main(int argc, char *argv[])
{
START(argc, argv, "pmem_unmap");
const char *path;
unsigned long long len;
int flags;
mode_t mode;
size_t mlenp;
size_t size;
int is_pmem;
char *ret;
os_stat_t stbuf;
if (argc != 2)
UT_FATAL("usage: %s path", argv[0]);
path = argv[1];
len = 0;
flags = 0;
mode = S_IWUSR | S_IRUSR;
STAT(path, &stbuf);
size = (size_t)stbuf.st_size;
UT_ASSERTeq(size, 20 * MEGABYTE);
ret = pmem_map_file(path, len, flags, mode, &mlenp, &is_pmem);
UT_ASSERTeq(pmem_unmap(ret, PAGE_4K), 0);
ret += PAGE_2M;
UT_ASSERTeq(pmem_unmap(ret, PAGE_2M), 0);
ret += PAGE_2M;
UT_ASSERTeq(pmem_unmap(ret, PAGE_2M - 1), 0);
ret += PAGE_2M;
UT_ASSERTne(pmem_unmap(ret, 0), 0);
ret += PAGE_2M - 1;
UT_ASSERTne(pmem_unmap(ret, PAGE_4K), 0);
DONE(NULL);
}
| 2,584 | 28.375 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/rpmemd_util/rpmemd_util_test.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rpmemd_util_test.c -- unit tests for rpmemd_util module
*/
#include "unittest.h"
#include "rpmem_common.h"
#include "rpmemd_log.h"
#include "rpmemd_util.h"
#include "util.h"
/* structure to store results */
struct result {
int ret;
enum rpmem_persist_method persist_method;
int (*persist)(const void *addr, size_t len);
void *(*memcpy_persist)(void *pmemdest, const void *src, size_t len);
};
/* all values to test */
static const enum rpmem_persist_method pms[] =
{RPMEM_PM_GPSPM, RPMEM_PM_APM, MAX_RPMEM_PM};
static const int is_pmems[] = {0, 1};
enum mode {
MODE_VALID,
MODE_INVALID,
MODE_MAX
};
static const int ranges[2][2][2] = {
[MODE_VALID] = {
{0, ARRAY_SIZE(pms) - 1},
{0, ARRAY_SIZE(is_pmems)}
},
[MODE_INVALID] = {
{ARRAY_SIZE(pms) - 1, ARRAY_SIZE(pms)},
{0, ARRAY_SIZE(is_pmems)}
}
};
/* expected results */
static const struct result exp_results[3][2] = {
{
/* GPSPM and is_pmem == false */
{0, RPMEM_PM_GPSPM, pmem_msync, memcpy},
/* GPSPM and is_pmem == true */
{0, RPMEM_PM_GPSPM, rpmemd_pmem_persist,
pmem_memcpy_persist}
}, {
/* APM and is_pmem == false */
{0, RPMEM_PM_GPSPM, pmem_msync, memcpy},
/* APM and is_pmem == true */
{0, RPMEM_PM_APM, rpmemd_flush_fatal,
pmem_memcpy_persist}
}, {
/* persistency method outside of the range */
{1, 0, 0, 0},
{1, 0, 0, 0}
}
};
static void
test_apply_pm_policy(struct result *result, int is_pmem)
{
if (rpmemd_apply_pm_policy(&result->persist_method, &result->persist,
&result->memcpy_persist, is_pmem)) {
goto err;
}
result->ret = 0;
return;
err:
result->ret = 1;
}
#define USAGE() do {\
UT_ERR("usage: %s valid|invalid", argv[0]);\
} while (0)
static void
test(const int pm_range[2], const int is_pmem_range[2])
{
rpmemd_log_level = RPD_LOG_NOTICE;
int ret = rpmemd_log_init("rpmemd_log", NULL, 0);
UT_ASSERTeq(ret, 0);
struct result result;
const struct result *exp_result;
for (int pm_ind = pm_range[0]; pm_ind < pm_range[1]; ++pm_ind) {
for (int is_pmem_ind = is_pmem_range[0];
is_pmem_ind < is_pmem_range[1]; ++is_pmem_ind) {
result.persist_method = pms[pm_ind];
exp_result = &exp_results[pm_ind][is_pmem_ind];
test_apply_pm_policy(&result, is_pmems[is_pmem_ind]);
UT_ASSERTeq(result.ret, exp_result->ret);
if (exp_result->ret == 0) {
UT_ASSERTeq(result.persist_method,
exp_result->persist_method);
UT_ASSERTeq(result.persist,
exp_result->persist);
}
}
}
rpmemd_log_close();
}
int
main(int argc, char *argv[])
{
START(argc, argv, "rpmemd_util");
if (argc < 2) {
USAGE();
return 1;
}
const char *mode_str = argv[1];
enum mode mode = MODE_MAX;
if (strcmp(mode_str, "valid") == 0) {
mode = MODE_VALID;
} else if (strcmp(mode_str, "invalid") == 0) {
mode = MODE_INVALID;
} else {
USAGE();
return 1;
}
UT_ASSERTne(mode, MODE_MAX);
test(ranges[mode][0], ranges[mode][1]);
DONE(NULL);
}
| 4,542 | 25.260116 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_malloc_usable_size/vmem_malloc_usable_size.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_malloc_usable_size.c -- unit test for vmem_malloc_usable_size
*
* usage: vmem_malloc_usable_size [directory]
*/
#include "unittest.h"
#define POOL_SIZE (VMEM_MIN_POOL * 2)
static const struct {
size_t size;
size_t spacing;
} Check_sizes[] = {
{.size = 10, .spacing = 8},
{.size = 100, .spacing = 16},
{.size = 200, .spacing = 32},
{.size = 500, .spacing = 64},
{.size = 1000, .spacing = 128},
{.size = 2000, .spacing = 256},
{.size = 3000, .spacing = 512},
{.size = 1 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 2 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 3 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 4 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 5 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 6 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 7 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 8 * 1024 * 1024, .spacing = 4 * 1024 * 1024},
{.size = 9 * 1024 * 1024, .spacing = 4 * 1024 * 1024}
};
int
main(int argc, char *argv[])
{
char *dir = NULL;
void *mem_pool = NULL;
VMEM *vmp;
void *alloc;
size_t usable_size;
size_t size;
unsigned i;
START(argc, argv, "vmem_malloc_usable_size");
if (argc == 2) {
dir = argv[1];
} else if (argc > 2) {
UT_FATAL("usage: %s [directory]", argv[0]);
}
if (dir == NULL) {
/* allocate memory for function vmem_create_in_region() */
mem_pool = MMAP_ANON_ALIGNED(POOL_SIZE, 4 << 20);
vmp = vmem_create_in_region(mem_pool, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create_in_region");
} else {
vmp = vmem_create(dir, POOL_SIZE);
if (vmp == NULL)
UT_FATAL("!vmem_create");
}
UT_ASSERTeq(vmem_malloc_usable_size(vmp, NULL), 0);
for (i = 0; i < (sizeof(Check_sizes) / sizeof(Check_sizes[0])); ++i) {
size = Check_sizes[i].size;
alloc = vmem_malloc(vmp, size);
UT_ASSERTne(alloc, NULL);
usable_size = vmem_malloc_usable_size(vmp, alloc);
UT_ASSERT(usable_size >= size);
if (usable_size - size > Check_sizes[i].spacing) {
UT_FATAL("Size %zu: spacing %zu is bigger"
"than expected: %zu", size,
(usable_size - size), Check_sizes[i].spacing);
}
memset(alloc, 0xEE, usable_size);
vmem_free(vmp, alloc);
}
UT_ASSERTeq(vmem_check(vmp), 1);
vmem_delete(vmp);
DONE(NULL);
}
| 3,888 | 31.408333 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_direct/obj_direct_non_inline.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_inline.c -- unit test for direct
*/
#define PMEMOBJ_DIRECT_NON_INLINE
#include "unittest.h"
#include "obj_direct.h"
void *
obj_direct_non_inline(PMEMoid oid)
{
UT_OUT("pmemobj_direct non-inlined");
return pmemobj_direct(oid);
}
| 1,847 | 38.319149 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_direct/obj_direct.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct.c -- unit test for pmemobj_direct()
*/
#include "obj.h"
#include "unittest.h"
#include "obj_direct.h"
#define MAX_PATH_LEN 255
#define LAYOUT_NAME "direct"
static os_mutex_t lock1;
static os_mutex_t lock2;
static os_cond_t sync_cond1;
static os_cond_t sync_cond2;
static int cond1;
static int cond2;
static PMEMoid thread_oid;
static void *
obj_direct(PMEMoid oid)
{
void *ptr1 = obj_direct_inline(oid);
void *ptr2 = obj_direct_non_inline(oid);
UT_ASSERTeq(ptr1, ptr2);
return ptr1;
}
static void *
test_worker(void *arg)
{
/* check before pool is closed, then let main continue */
UT_ASSERTne(obj_direct(thread_oid), NULL);
os_mutex_lock(&lock1);
cond1 = 1;
os_cond_signal(&sync_cond1);
os_mutex_unlock(&lock1);
/* wait for main thread to free & close, then check */
os_mutex_lock(&lock2);
while (!cond2)
os_cond_wait(&sync_cond2, &lock2);
os_mutex_unlock(&lock2);
UT_ASSERTeq(obj_direct(thread_oid), NULL);
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_direct");
if (argc != 3)
UT_FATAL("usage: %s [directory] [# of pools]", argv[0]);
unsigned npools = ATOU(argv[2]);
const char *dir = argv[1];
int r;
os_mutex_init(&lock1);
os_mutex_init(&lock2);
os_cond_init(&sync_cond1);
os_cond_init(&sync_cond2);
cond1 = cond2 = 0;
PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMobjpool *));
UT_ASSERTne(pops, NULL);
size_t length = strlen(dir) + MAX_PATH_LEN;
char *path = MALLOC(length);
for (unsigned i = 0; i < npools; ++i) {
int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d",
dir, i);
if (ret < 0 || ret >= length)
UT_FATAL("snprintf: %d", ret);
pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR);
if (pops[i] == NULL)
UT_FATAL("!pmemobj_create");
}
PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid));
UT_ASSERTne(oids, NULL);
PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid));
UT_ASSERTne(tmpoids, NULL);
oids[0] = OID_NULL;
UT_ASSERTeq(obj_direct(oids[0]), NULL);
for (unsigned i = 0; i < npools; ++i) {
oids[i] = (PMEMoid) {pops[i]->uuid_lo, 0};
UT_ASSERTeq(obj_direct(oids[i]), NULL);
uint64_t off = pops[i]->heap_offset;
oids[i] = (PMEMoid) {pops[i]->uuid_lo, off};
UT_ASSERTeq((char *)obj_direct(oids[i]) - off,
(char *)pops[i]);
r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL);
UT_ASSERTeq(r, 0);
}
r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL);
UT_ASSERTeq(r, 0);
UT_ASSERTne(obj_direct(thread_oid), NULL);
os_thread_t t;
PTHREAD_CREATE(&t, NULL, test_worker, NULL);
/* wait for the worker thread to perform the first check */
os_mutex_lock(&lock1);
while (!cond1)
os_cond_wait(&sync_cond1, &lock1);
os_mutex_unlock(&lock1);
for (unsigned i = 0; i < npools; ++i) {
UT_ASSERTne(obj_direct(tmpoids[i]), NULL);
pmemobj_free(&tmpoids[i]);
UT_ASSERTeq(obj_direct(tmpoids[i]), NULL);
pmemobj_close(pops[i]);
UT_ASSERTeq(obj_direct(oids[i]), NULL);
}
/* signal the worker that we're free and closed */
os_mutex_lock(&lock2);
cond2 = 1;
os_cond_signal(&sync_cond2);
os_mutex_unlock(&lock2);
PTHREAD_JOIN(&t, NULL);
os_cond_destroy(&sync_cond1);
os_cond_destroy(&sync_cond2);
os_mutex_destroy(&lock1);
os_mutex_destroy(&lock2);
FREE(pops);
FREE(tmpoids);
FREE(oids);
DONE(NULL);
}
| 4,939 | 27.228571 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_direct/obj_direct_inline.c | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct_inline.c -- unit test for direct
*/
#include "unittest.h"
#include "obj_direct.h"
void *
obj_direct_inline(PMEMoid oid)
{
UT_OUT("pmemobj_direct inlined");
return pmemobj_direct(oid);
}
| 1,804 | 39.111111 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_direct/obj_direct.h | /*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_direct.h -- unit test for pmemobj_direct()
*/
#ifndef OBJ_DIRECT_H
#define OBJ_DIRECT_H 1
#include "libpmemobj.h"
void *obj_direct_inline(PMEMoid oid);
void *obj_direct_non_inline(PMEMoid oid);
#endif /* OBJ_DIRECT_H */
| 1,831 | 39.711111 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_memcheck/obj_memcheck.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "unittest.h"
#include "valgrind_internal.h"
/*
* Layout definition
*/
POBJ_LAYOUT_BEGIN(mc);
POBJ_LAYOUT_ROOT(mc, struct root);
POBJ_LAYOUT_TOID(mc, struct struct1);
POBJ_LAYOUT_END(mc);
struct struct1 {
int fld;
int dyn[];
};
struct root {
TOID(struct struct1) s1;
TOID(struct struct1) s2;
};
static void
test_memcheck_bug(void)
{
#if VG_MEMCHECK_ENABLED
volatile char tmp[100];
VALGRIND_CREATE_MEMPOOL(tmp, 0, 0);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 8, 16);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 8);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 8, 16);
VALGRIND_MAKE_MEM_NOACCESS(tmp, 8);
tmp[7] = 0x66;
#endif
}
static void
test_memcheck_bug2(void)
{
#if VG_MEMCHECK_ENABLED
volatile char tmp[1000];
VALGRIND_CREATE_MEMPOOL(tmp, 0, 0);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 128, 128);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 128);
VALGRIND_MEMPOOL_ALLOC(tmp, tmp + 256, 128);
VALGRIND_MEMPOOL_FREE(tmp, tmp + 256);
/*
* This should produce warning:
* Address ... is 0 bytes inside a block of size 128 bytes freed.
* instead, it produces a warning:
* Address ... is 0 bytes after a block of size 128 freed
*/
int *data = (int *)(tmp + 256);
*data = 0x66;
#endif
}
static void
test_everything(const char *path)
{
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, POBJ_LAYOUT_NAME(mc),
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create: %s", path);
struct root *rt = D_RW(POBJ_ROOT(pop, struct root));
POBJ_ALLOC(pop, &rt->s1, struct struct1, sizeof(struct struct1),
NULL, NULL);
struct struct1 *s1 = D_RW(rt->s1);
struct struct1 *s2;
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
s2 = D_RW(rt->s2);
POBJ_FREE(&rt->s2);
/* read of uninitialized variable */
if (s1->fld)
UT_OUT("%d", 1);
/* write to freed object */
s2->fld = 7;
pmemobj_persist(pop, s2, sizeof(*s2));
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
s2 = D_RW(rt->s2);
memset(s2, 0, pmemobj_alloc_usable_size(rt->s2.oid));
s2->fld = 12; /* ok */
/* invalid write */
s2->dyn[100000] = 9;
/* invalid write */
s2->dyn[1000] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1));
POBJ_REALLOC(pop, &rt->s2, struct struct1,
sizeof(struct struct1) + 100 * sizeof(int));
s2 = D_RW(rt->s2);
s2->dyn[0] = 9; /* ok */
pmemobj_persist(pop, s2, sizeof(struct struct1) + 100 * sizeof(int));
POBJ_FREE(&rt->s2);
/* invalid write to REALLOCated and FREEd object */
s2->dyn[0] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 100 * sizeof(int));
POBJ_ALLOC(pop, &rt->s2, struct struct1, sizeof(struct struct1),
NULL, NULL);
POBJ_REALLOC(pop, &rt->s2, struct struct1,
sizeof(struct struct1) + 30 * sizeof(int));
s2 = D_RW(rt->s2);
s2->dyn[0] = 0;
s2->dyn[29] = 29;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 30 * sizeof(int));
POBJ_FREE(&rt->s2);
s2->dyn[0] = 9;
pmemobj_persist(pop, s2, sizeof(struct struct1) + 30 * sizeof(int));
pmemobj_close(pop);
}
static void usage(const char *a)
{
UT_FATAL("usage: %s [m|t] file-name", a);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_memcheck");
/* root doesn't count */
UT_COMPILE_ERROR_ON(POBJ_LAYOUT_TYPES_NUM(mc) != 1);
if (argc < 2)
usage(argv[0]);
if (strcmp(argv[1], "m") == 0)
test_memcheck_bug();
else if (strcmp(argv[1], "t") == 0) {
if (argc < 3)
usage(argv[0]);
test_everything(argv[2]);
} else
usage(argv[0]);
test_memcheck_bug2();
DONE(NULL);
}
| 5,106 | 25.324742 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/cto_valgrind/cto_valgrind.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* cto_valgrind.c -- unit test for Valgrind instrumentation in libpmemcto
*
* usage: cto_valgrind filename <test-number>
*
* test-number can be a number from 0 to 6
*/
#include "unittest.h"
#include "set.h"
#include "cto.h"
int
main(int argc, char *argv[])
{
START(argc, argv, "cto_valgrind");
if (argc != 3)
UT_FATAL("usage: %s filename <test-number>", argv[0]);
PMEMctopool *pcp = pmemcto_create(argv[1], "test",
2 * PMEMCTO_MIN_POOL, 0600);
UT_ASSERTne(pcp, NULL);
int test_case = atoi(argv[2]);
int *ptr;
switch (test_case) {
case 0: {
UT_OUT("remove all allocations and close pool");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
break;
}
case 1: {
UT_OUT("free after close");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_close(pcp);
pmemcto_free(pcp, ptr);
break;
}
case 2: {
UT_OUT("only close pool");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
pmemcto_close(pcp);
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
break;
}
case 3: {
UT_OUT("memory leaks");
ptr = pmemcto_malloc(pcp, sizeof(int));
UT_ASSERTne(ptr, NULL);
/* prevent reporting leaked memory as still reachable */
ptr = NULL;
/* prevent reporting memory leaks in set */
util_poolset_free(pcp->set);
break;
}
case 4: {
UT_OUT("heap block overrun");
ptr = pmemcto_malloc(pcp, 12 * sizeof(int));
UT_ASSERTne(ptr, NULL);
/* heap block overrun */
ptr[12] = 7;
pmemcto_free(pcp, ptr);
pmemcto_close(pcp);
break;
}
case 5: {
UT_OUT("close & re-open");
int *ptrs[5];
ptrs[0] = pmemcto_malloc(pcp, sizeof(int));
ptrs[1] = pmemcto_malloc(pcp, 256 * sizeof(int));
ptrs[2] = pmemcto_malloc(pcp, 16384);
ptrs[3] = pmemcto_malloc(pcp, 3 * 1024 * 1024);
ptrs[4] = pmemcto_malloc(pcp, 8 * 1024 * 1024);
UT_ASSERTne(ptrs[0], NULL);
UT_ASSERTne(ptrs[1], NULL);
UT_ASSERTne(ptrs[2], NULL);
UT_ASSERTne(ptrs[3], NULL);
UT_ASSERTne(ptrs[4], NULL);
*ptrs[0] = 55;
*ptrs[1] = 55;
*ptrs[2] = 55;
*ptrs[3] = 55;
*ptrs[4] = 55;
pmemcto_close(pcp);
pcp = pmemcto_open(argv[1], "test");
UT_ASSERTne(pcp, NULL);
*ptrs[0] = 77;
*ptrs[1] = 77;
*ptrs[2] = 77;
*ptrs[3] = 77;
*ptrs[4] = 77;
pmemcto_free(pcp, ptrs[0]);
pmemcto_free(pcp, ptrs[1]);
pmemcto_free(pcp, ptrs[2]);
pmemcto_free(pcp, ptrs[3]);
pmemcto_free(pcp, ptrs[4]);
*ptrs[0] = 99; /* XXX not detected */
*ptrs[1] = 99; /* XXX not detected */
*ptrs[2] = 99; /* XXX not detected */
*ptrs[3] = 99;
*ptrs[4] = 99;
pmemcto_close(pcp);
break;
}
default: {
UT_FATAL("unknown test-number");
}
}
DONE(NULL);
}
| 4,421 | 26.465839 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_extend/obj_extend.c | /*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_extend.c -- pool extension tests
*
*/
#include <stddef.h>
#include "unittest.h"
#define ALLOC_SIZE (((1 << 20) * 2) - 16) /* 2 megabytes - 16 bytes (hdr) */
#define RESV_SIZE ((1 << 29) + ((1 << 20) * 8)) /* 512 + 8 megabytes */
#define FRAG 0.9
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_extend");
if (argc < 2)
UT_FATAL("usage: %s file-name [alloc-size] [opath]", argv[0]);
const char *path = argv[1];
PMEMobjpool *pop = NULL;
if ((pop = pmemobj_create(path, "obj_extend",
0, S_IWUSR | S_IRUSR)) == NULL) {
UT_ERR("pmemobj_create: %s", pmemobj_errormsg());
exit(0);
}
size_t alloc_size;
if (argc > 2)
alloc_size = ATOUL(argv[2]);
else
alloc_size = ALLOC_SIZE;
const char *opath = path;
if (argc > 3)
opath = argv[3];
size_t allocated = 0;
PMEMoid oid;
while (pmemobj_alloc(pop, &oid, alloc_size, 0, NULL, NULL) == 0) {
allocated += pmemobj_alloc_usable_size(oid);
}
UT_ASSERT(allocated > (RESV_SIZE * FRAG));
pmemobj_close(pop);
if ((pop = pmemobj_open(opath, "obj_extend")) != NULL) {
pmemobj_close(pop);
int result = pmemobj_check(opath, "obj_extend");
UT_ASSERTeq(result, 1);
} else {
UT_ERR("pmemobj_open: %s", pmemobj_errormsg());
}
DONE(NULL);
}
| 2,845 | 28.957895 | 76 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/util_badblock/util_badblock.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_badblock.c -- unit test for the linux bad block API
*
*/
#include "unittest.h"
#include "util.h"
#include "out.h"
#include "set.h"
#include "os_dimm.h"
#include "os_badblock.h"
#include "badblock.h"
#define MIN_POOL ((size_t)(1024 * 1024 * 8)) /* 8 MiB */
#define MIN_PART ((size_t)(1024 * 1024 * 2)) /* 2 MiB */
/*
* do_list -- (internal) list bad blocks in the file
*/
static void
do_list(const char *path)
{
int ret;
struct badblocks *bbs = badblocks_new();
if (bbs == NULL)
UT_FATAL("!badblocks_new");
ret = os_badblocks_get(path, bbs);
if (ret)
UT_FATAL("!os_badblocks_get");
if (bbs->bb_cnt == 0 || bbs->bbv == NULL) {
UT_OUT("No bad blocks found.");
goto exit_free;
}
UT_OUT("Found %u bad block(s):", bbs->bb_cnt);
unsigned b;
for (b = 0; b < bbs->bb_cnt; b++) {
UT_OUT("%llu %u",
bbs->bbv[b].offset >> 9,
bbs->bbv[b].length >> 9);
}
exit_free:
badblocks_delete(bbs);
}
/*
* do_clear -- (internal) clear bad blocks in the file
*/
static void
do_clear(const char *path)
{
if (os_badblocks_clear_all(path))
UT_FATAL("!os_badblocks_clear_all: %s", path);
}
/*
* do_create -- (internal) create a pool
*/
static void
do_create(const char *path)
{
struct pool_set *set;
struct pool_attr attr;
unsigned nlanes = 1;
memset(&attr, 0, sizeof(attr));
if (util_pool_create(&set, path, 0, MIN_POOL, MIN_PART,
&attr, &nlanes, REPLICAS_ENABLED) != 0)
UT_FATAL("!util_pool_create: %s", path);
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
/*
* do_open -- (internal) open a pool
*/
static void
do_open(const char *path)
{
struct pool_set *set;
const struct pool_attr attr;
unsigned nlanes = 1;
if (util_pool_open(&set, path, MIN_PART,
&attr, &nlanes, NULL, 0) != 0) {
UT_FATAL("!util_pool_open: %s", path);
}
util_poolset_close(set, DO_NOT_DELETE_PARTS);
}
int
main(int argc, char *argv[])
{
START(argc, argv, "util_badblock");
util_init();
out_init("UTIL_BADBLOCK", "UTIL_BADBLOCK", "", 1, 0);
if (argc < 3)
UT_FATAL("usage: %s file op:l|c|r|o", argv[0]);
const char *path = argv[1];
/* go through all arguments one by one */
for (int arg = 2; arg < argc; arg++) {
if (argv[arg][1] != '\0')
UT_FATAL(
"op must be l, c, r or o (l=list, c=clear, r=create, o=open)");
switch (argv[arg][0]) {
case 'l':
do_list(path);
break;
case 'c':
do_clear(path);
break;
case 'r':
do_create(path);
break;
case 'o':
do_open(path);
break;
default:
UT_FATAL(
"op must be l, c, r or o (l=list, c=clear, r=create, o=open)");
break;
}
}
out_fini();
DONE(NULL);
}
| 4,202 | 23.017143 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_mem/obj_mem.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_mem.c -- simple test for pmemobj_memcpy, pmemobj_memmove and
* pmemobj_memset that verifies nothing blows up on pmemobj side.
* Real consistency tests are for libpmem.
*/
#include "unittest.h"
static unsigned Flags[] = {
0,
PMEMOBJ_F_MEM_NODRAIN,
PMEMOBJ_F_MEM_NONTEMPORAL,
PMEMOBJ_F_MEM_TEMPORAL,
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_TEMPORAL,
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_NODRAIN,
PMEMOBJ_F_MEM_WC,
PMEMOBJ_F_MEM_WB,
PMEMOBJ_F_MEM_NOFLUSH,
/* all possible flags */
PMEMOBJ_F_MEM_NODRAIN | PMEMOBJ_F_MEM_NOFLUSH |
PMEMOBJ_F_MEM_NONTEMPORAL | PMEMOBJ_F_MEM_TEMPORAL |
PMEMOBJ_F_MEM_WC | PMEMOBJ_F_MEM_WB,
};
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_mem");
if (argc != 2)
UT_FATAL("usage: %s [directory]", argv[0]);
PMEMobjpool *pop = pmemobj_create(argv[1], "obj_mem", 0,
S_IWUSR | S_IRUSR);
if (!pop)
UT_FATAL("!pmemobj_create");
struct root {
char c[4096];
};
struct root *r = pmemobj_direct(pmemobj_root(pop, sizeof(struct root)));
for (int i = 0; i < ARRAY_SIZE(Flags); ++i) {
unsigned f = Flags[i];
pmemobj_memset(pop, &r->c[0], 0x77, 2048, f);
pmemobj_memset(pop, &r->c[2048], 0xff, 2048, f);
pmemobj_memcpy(pop, &r->c[2048 + 7], &r->c[0], 100, f);
pmemobj_memcpy(pop, &r->c[2048 + 1024], &r->c[0] + 17, 128, f);
pmemobj_memmove(pop, &r->c[125], &r->c[150], 100, f);
pmemobj_memmove(pop, &r->c[350], &r->c[325], 100, f);
if (f & PMEMOBJ_F_MEM_NOFLUSH)
pmemobj_persist(pop, r, sizeof(*r));
}
pmemobj_close(pop);
DONE(NULL);
}
| 3,159 | 31.244898 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_valgr_simple/pmem_valgr_simple.c | /*
* Copyright 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_valgr_simple.c -- simple unit test using pmemcheck
*
* usage: pmem_valgr_simple file
*/
#include "unittest.h"
int
main(int argc, char *argv[])
{
size_t mapped_len;
char *dest;
int is_pmem;
START(argc, argv, "pmem_valgr_simple");
if (argc != 4)
UT_FATAL("usage: %s file offset length", argv[0]);
int dest_off = atoi(argv[2]);
size_t bytes = strtoul(argv[3], NULL, 0);
dest = pmem_map_file(argv[1], 0, 0, 0, &mapped_len, &is_pmem);
if (dest == NULL)
UT_FATAL("!Could not mmap %s\n", argv[1]);
/* these will not be made persistent */
*(int *)dest = 4;
/* this will be made persistent */
uint64_t *tmp64dst = (void *)((uintptr_t)dest + 4096);
*tmp64dst = 50;
if (is_pmem) {
pmem_persist(tmp64dst, sizeof(*tmp64dst));
} else {
UT_ASSERTeq(pmem_msync(tmp64dst, sizeof(*tmp64dst)), 0);
}
uint16_t *tmp16dst = (void *)((uintptr_t)dest + 1024);
*tmp16dst = 21;
/* will appear as flushed/fenced in valgrind log */
pmem_flush(tmp16dst, sizeof(*tmp16dst));
/* shows strange behavior of memset in some cases */
memset(dest + dest_off, 0, bytes);
UT_ASSERTeq(pmem_unmap(dest, mapped_len), 0);
DONE(NULL);
}
| 2,755 | 31.423529 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_mt/obj_tx_mt.c | /*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_mt.c -- multi-threaded test for pmemobj_tx_*
*
* It checks that objects are removed from transactions before on abort/commit
* phase.
*/
#include "unittest.h"
#define THREADS 8
#define LOOPS 8
static PMEMobjpool *pop;
static PMEMoid tab;
static os_mutex_t mtx;
static void *
tx_alloc_free(void *arg)
{
volatile int locked;
for (int i = 0; i < LOOPS; ++i) {
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
tab = pmemobj_tx_zalloc(128, 1);
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
pmemobj_tx_free(tab);
tab = OID_NULL;
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
}
return NULL;
}
static void *
tx_snap(void *arg)
{
volatile int locked;
for (int i = 0; i < LOOPS; ++i) {
locked = 0;
TX_BEGIN(pop) {
os_mutex_lock(&mtx);
locked = 1;
if (!OID_IS_NULL(tab))
pmemobj_tx_add_range(tab, 0, 8);
} TX_ONCOMMIT {
if (locked)
os_mutex_unlock(&mtx);
} TX_ONABORT {
if (locked)
os_mutex_unlock(&mtx);
} TX_END
locked = 0;
}
return NULL;
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_mt");
os_mutex_init(&mtx);
if (argc != 2)
UT_FATAL("usage: %s [file]", argv[0]);
if ((pop = pmemobj_create(argv[1], "mt", PMEMOBJ_MIN_POOL,
S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
int i = 0;
os_thread_t *threads = MALLOC(THREADS * sizeof(threads[0]));
for (int j = 0; j < THREADS / 2; ++j) {
PTHREAD_CREATE(&threads[i++], NULL, tx_alloc_free, NULL);
PTHREAD_CREATE(&threads[i++], NULL, tx_snap, NULL);
}
while (i > 0)
PTHREAD_JOIN(&threads[--i], NULL);
pmemobj_close(pop);
os_mutex_destroy(&mtx);
FREE(threads);
DONE(NULL);
}
| 3,515 | 24.294964 | 78 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/vmem_custom_alloc/vmem_custom_alloc.c | /*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vmem_custom_alloc.c -- unit test for vmem_custom_alloc
*
* usage: vmem_custom_alloc (0-2) [directory]
*/
#include "unittest.h"
#define TEST_STRING_VALUE "Some test text, to check memory"
#define TEST_REPEAT_CREATE_POOLS (20)
static int custom_allocs;
static int custom_alloc_calls;
static int expect_malloc;
/*
* malloc_null -- custom malloc function with error
*
* This function updates statistics about custom alloc functions,
* and returns NULL.
*/
static void *
malloc_null(size_t size)
{
++custom_alloc_calls;
#ifdef _WIN32
/*
* Because Windows version requires UTF-16 string conversion
* which requires four malloc calls and one free to succeed due to
* long path support
*/
if (custom_alloc_calls < 6) {
custom_allocs++;
return malloc(size);
}
#endif
errno = ENOMEM;
return NULL;
}
/*
* malloc_custom -- custom malloc function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory.
*/
static void *
malloc_custom(size_t size)
{
++custom_alloc_calls;
++custom_allocs;
return malloc(size);
}
/*
* free_custom -- custom free function
*
* This function updates statistics about custom alloc functions,
* and frees allocated memory.
*/
static void
free_custom(void *ptr)
{
++custom_alloc_calls;
--custom_allocs;
free(ptr);
}
/*
* realloc_custom -- custom realloc function
*
* This function updates statistics about custom alloc functions,
* and returns reallocated memory.
*/
static void *
realloc_custom(void *ptr, size_t size)
{
++custom_alloc_calls;
return realloc(ptr, size);
}
/*
* strdup_custom -- custom strdup function
*
* This function updates statistics about custom alloc functions,
* and returns allocated memory with a duplicated string.
*/
static char *
strdup_custom(const char *s)
{
++custom_alloc_calls;
++custom_allocs;
return strdup(s);
}
/*
* pool_test -- test pool
*
* This function creates a memory pool in a file (if dir is not NULL),
* or in RAM (if dir is NULL) and allocates memory for the test.
*/
static void
pool_test(const char *dir)
{
VMEM *vmp = NULL;
if (dir != NULL) {
vmp = vmem_create(dir, VMEM_MIN_POOL);
} else {
/* allocate memory for function vmem_create_in_region() */
void *mem_pool = MMAP_ANON_ALIGNED(VMEM_MIN_POOL, 4 << 20);
vmp = vmem_create_in_region(mem_pool, VMEM_MIN_POOL);
}
if (vmp == NULL) {
if (dir == NULL) {
UT_FATAL("!vmem_create_in_region");
} else {
UT_FATAL("!vmem_create");
}
}
char *test = vmem_malloc(vmp, strlen(TEST_STRING_VALUE) + 1);
if (expect_malloc == 0) {
UT_ASSERTeq(test, NULL);
} else {
strcpy(test, TEST_STRING_VALUE);
UT_ASSERTeq(strcmp(test, TEST_STRING_VALUE), 0);
UT_ASSERT(vmem_malloc_usable_size(vmp, test) > 0);
vmem_free(vmp, test);
}
vmem_delete(vmp);
}
int
main(int argc, char *argv[])
{
int expect_custom_alloc = 0;
START(argc, argv, "vmem_custom_alloc");
if (argc < 2 || argc > 3 || strlen(argv[1]) != 1)
UT_FATAL("usage: %s (0-2) [directory]", argv[0]);
switch (argv[1][0]) {
case '0': {
/* use default allocator */
expect_custom_alloc = 0;
expect_malloc = 1;
break;
}
case '1': {
/* error in custom malloc function */
expect_custom_alloc = 1;
expect_malloc = 0;
vmem_set_funcs(malloc_null, free_custom,
realloc_custom, strdup_custom, NULL);
break;
}
case '2': {
/* use custom alloc functions */
expect_custom_alloc = 1;
expect_malloc = 1;
vmem_set_funcs(malloc_custom, free_custom,
realloc_custom, strdup_custom, NULL);
break;
}
default: {
UT_FATAL("usage: %s (0-2) [directory]", argv[0]);
break;
}
}
if (argc == 3) {
pool_test(argv[2]);
} else {
int i;
/* repeat create pool */
for (i = 0; i < TEST_REPEAT_CREATE_POOLS; ++i)
pool_test(NULL);
}
/* check memory leak in custom allocator */
UT_ASSERTeq(custom_allocs, 0);
if (expect_custom_alloc == 0) {
UT_ASSERTeq(custom_alloc_calls, 0);
} else {
UT_ASSERTne(custom_alloc_calls, 0);
}
DONE(NULL);
}
| 5,623 | 23.34632 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/win_mmap_dtor/win_mmap_dtor.c | /*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* win_mmap_dtor.c -- unit test for windows mmap destructor
*/
#include "unittest.h"
#include "os.h"
#include "win_mmap.h"
#define KILOBYTE (1 << 10)
#define MEGABYTE (1 << 20)
unsigned long long Mmap_align;
int
main(int argc, char *argv[])
{
START(argc, argv, "win_mmap_dtor");
if (argc != 2)
UT_FATAL("usage: %s path", argv[0]);
SYSTEM_INFO si;
GetSystemInfo(&si);
/* set pagesize for mmap */
Mmap_align = si.dwAllocationGranularity;
const char *path = argv[1];
int fd = os_open(path, O_RDWR);
UT_ASSERTne(fd, -1);
/*
* Input file has size equal to 2MB, but the mapping is 3MB.
* In this case mmap should map whole file and reserve 1MB
* of virtual address space for remaining part of the mapping.
*/
void *addr = mmap(NULL, 3 * MEGABYTE, PROT_READ, MAP_SHARED, fd, 0);
UT_ASSERTne(addr, MAP_FAILED);
MEMORY_BASIC_INFORMATION basic_info;
SIZE_T bytes_returned;
bytes_returned = VirtualQuery(addr, &basic_info,
sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, 2 * MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_COMMIT);
bytes_returned = VirtualQuery((char *)addr + 2 * MEGABYTE,
&basic_info, sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
UT_ASSERTeq(basic_info.RegionSize, MEGABYTE);
UT_ASSERTeq(basic_info.State, MEM_RESERVE);
win_mmap_fini();
bytes_returned = VirtualQuery((char *)addr + 2 * MEGABYTE,
&basic_info, sizeof(basic_info));
UT_ASSERTeq(bytes_returned, sizeof(basic_info));
/*
* region size can be bigger than 1MB because there was probably
* free space after this mapping
*/
UT_ASSERTeq(basic_info.State, MEM_FREE);
DONE(NULL);
}
| 3,293 | 30.673077 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file_win/mocks_windows.h | /*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of libc functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem
* files, when compiled for the purpose of pmem_map_file test.
* It would replace default implementation with mocked functions defined
* in pmem_map_file.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define os_posix_fallocate __wrap_os_posix_fallocate
#define os_ftruncate __wrap_os_ftruncate
#endif
| 2,123 | 41.48 | 74 | h |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file_win/mocks_windows.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.c -- mocked functions used in pmem_map_file.c
* (Windows-specific)
*/
#include "unittest.h"
#define MAX_LEN (4 * 1024 * 1024)
/*
* posix_fallocate -- interpose on libc posix_fallocate()
*/
FUNC_MOCK(os_posix_fallocate, int, int fd, os_off_t offset, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("posix_fallocate: off %ju len %ju", offset, len);
if (len > MAX_LEN)
return ENOSPC;
return _FUNC_REAL(os_posix_fallocate)(fd, offset, len);
}
FUNC_MOCK_END
/*
* ftruncate -- interpose on libc ftruncate()
*/
FUNC_MOCK(os_ftruncate, int, int fd, os_off_t len)
FUNC_MOCK_RUN_DEFAULT {
UT_OUT("ftruncate: len %ju", len);
if (len > MAX_LEN) {
errno = ENOSPC;
return -1;
}
return _FUNC_REAL(os_ftruncate)(fd, len);
}
FUNC_MOCK_END
| 2,383 | 34.58209 | 74 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/pmem_map_file_win/pmem_map_file_win.c | /*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmem_map_file_win.c -- unit test for mapping persistent memory for raw access
*
* usage: pmem_map_file_win file
*/
#define _GNU_SOURCE
#include "unittest.h"
#include <stdlib.h>
#define CHECK_BYTES 4096 /* bytes to compare before/after map call */
ut_jmp_buf_t Jmp;
/*
* signal_handler -- called on SIGSEGV
*/
static void
signal_handler(int sig)
{
ut_siglongjmp(Jmp);
}
#define PMEM_FILE_ALL_FLAGS\
(PMEM_FILE_CREATE|PMEM_FILE_EXCL|PMEM_FILE_SPARSE|PMEM_FILE_TMPFILE)
static int device_dax = 0;
/*
* parse_flags -- parse 'flags' string
*/
static int
parse_flags(const wchar_t *flags_str)
{
int ret = 0;
while (*flags_str != L'\0') {
switch (*flags_str) {
case L'0':
case L'-':
/* no flags */
break;
case L'T':
ret |= PMEM_FILE_TMPFILE;
break;
case L'S':
ret |= PMEM_FILE_SPARSE;
break;
case L'C':
ret |= PMEM_FILE_CREATE;
break;
case L'E':
ret |= PMEM_FILE_EXCL;
break;
case L'X':
/* not supported flag */
ret |= (PMEM_FILE_ALL_FLAGS + 1);
break;
case L'D':
device_dax = 1;
break;
default:
UT_FATAL("unknown flags: %c", *flags_str);
}
flags_str++;
};
return ret;
}
/*
* do_check -- check the mapping
*/
static void
do_check(int fd, void *addr, size_t mlen)
{
/* arrange to catch SEGV */
struct sigaction v;
sigemptyset(&v.sa_mask);
v.sa_flags = 0;
v.sa_handler = signal_handler;
SIGACTION(SIGSEGV, &v, NULL);
char pat[CHECK_BYTES];
char buf[CHECK_BYTES];
/* write some pattern to the file */
memset(pat, 0x5A, CHECK_BYTES);
WRITE(fd, pat, CHECK_BYTES);
if (memcmp(pat, addr, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
/* fill up mapped region with new pattern */
memset(pat, 0xA5, CHECK_BYTES);
memcpy(addr, pat, CHECK_BYTES);
UT_ASSERTeq(pmem_msync(addr, CHECK_BYTES), 0);
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
if (!ut_sigsetjmp(Jmp)) {
/* same memcpy from above should now fail */
memcpy(addr, pat, CHECK_BYTES);
} else {
UT_OUT("unmap successful");
}
LSEEK(fd, (os_off_t)0, SEEK_SET);
if (READ(fd, buf, CHECK_BYTES) == CHECK_BYTES) {
if (memcmp(pat, buf, CHECK_BYTES))
UT_OUT("first %d bytes do not match", CHECK_BYTES);
}
}
int
wmain(int argc, wchar_t *argv[])
{
STARTW(argc, argv, "pmem_map_file_win");
int fd;
void *addr;
size_t mlen;
size_t *mlenp;
const wchar_t *path;
unsigned long long len;
int flags;
int mode;
int is_pmem;
int *is_pmemp;
int use_mlen;
int use_is_pmem;
if (argc < 7)
UT_FATAL("usage: %s path len flags mode use_mlen "
"use_is_pmem ...", ut_toUTF8(argv[0]));
for (int i = 1; i + 5 < argc; i += 6) {
path = argv[i];
len = wcstoull(argv[i + 1], NULL, 0);
flags = parse_flags(argv[i + 2]);
mode = wcstol(argv[i + 3], NULL, 8);
use_mlen = _wtoi(argv[i + 4]);
use_is_pmem = _wtoi(argv[i + 5]);
mlen = SIZE_MAX;
if (use_mlen)
mlenp = &mlen;
else
mlenp = NULL;
if (use_is_pmem)
is_pmemp = &is_pmem;
else
is_pmemp = NULL;
char *upath = ut_toUTF8(path);
char *uflags = ut_toUTF8(argv[i + 2]);
UT_OUT("%s %lld %s %o %d %d",
upath, len, uflags, mode, use_mlen, use_is_pmem);
free(uflags);
free(upath);
addr = pmem_map_fileW(path, len, flags, mode, mlenp, is_pmemp);
if (addr == NULL) {
UT_OUT("!pmem_map_file");
continue;
}
if (use_mlen) {
UT_ASSERTne(mlen, SIZE_MAX);
UT_OUT("mapped_len %zu", mlen);
} else {
mlen = len;
}
if (addr) {
if ((flags & PMEM_FILE_TMPFILE) == 0 && !device_dax) {
fd = WOPEN(argv[i], O_RDWR);
if (!use_mlen) {
os_stat_t stbuf;
FSTAT(fd, &stbuf);
mlen = stbuf.st_size;
}
if (fd != -1) {
do_check(fd, addr, mlen);
(void) CLOSE(fd);
} else {
UT_OUT("!cannot open file: %s",
argv[i]);
}
} else {
UT_ASSERTeq(pmem_unmap(addr, mlen), 0);
}
}
}
DONEW(NULL);
}
/*
* Since libpmem is linked statically, we need to invoke its ctor/dtor.
*/
MSVC_CONSTR(libpmem_init)
MSVC_DESTR(libpmem_fini)
| 5,587 | 22.380753 | 80 | c |
null | NearPMSW-main/nearpm/checkpointing/redis-NDP-chekpoint/deps/pmdk/src/test/obj_tx_locks/obj_tx_locks.c | /*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* obj_tx_locks.c -- unit test for transaction locks
*/
#include "unittest.h"
#define LAYOUT_NAME "direct"
#define NUM_LOCKS 2
#define NUM_THREADS 10
#define TEST_VALUE_A 5
#define TEST_VALUE_B 10
#define TEST_VALUE_C 15
#define BEGIN_TX(pop, mutexes, rwlocks)\
TX_BEGIN_PARAM((pop), TX_PARAM_MUTEX,\
&(mutexes)[0], TX_PARAM_MUTEX, &(mutexes)[1], TX_PARAM_RWLOCK,\
&(rwlocks)[0], TX_PARAM_RWLOCK, &(rwlocks)[1], TX_PARAM_NONE)
#define BEGIN_TX_OLD(pop, mutexes, rwlocks)\
TX_BEGIN_LOCK((pop), TX_LOCK_MUTEX,\
&(mutexes)[0], TX_LOCK_MUTEX, &(mutexes)[1], TX_LOCK_RWLOCK,\
&(rwlocks)[0], TX_LOCK_RWLOCK, &(rwlocks)[1], TX_LOCK_NONE)
struct transaction_data {
PMEMmutex mutexes[NUM_LOCKS];
PMEMrwlock rwlocks[NUM_LOCKS];
int a;
int b;
int c;
};
static PMEMobjpool *Pop;
/*
* do_tx -- (internal) thread-friendly transaction
*/
static void *
do_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_ONABORT { /* not called */
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_tx_old -- (internal) thread-friendly transaction, tests deprecated macros
*/
static void *
do_tx_old(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX_OLD(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_ONABORT { /* not called */
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_aborted_tx -- (internal) thread-friendly aborted transaction
*/
static void *
do_aborted_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
pmemobj_tx_abort(EINVAL);
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
data->a = TEST_VALUE_B;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_nested_tx-- (internal) thread-friendly nested transaction
*/
static void *
do_nested_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
} TX_ONCOMMIT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_END
} TX_ONCOMMIT {
data->c = TEST_VALUE_C;
} TX_END
return NULL;
}
/*
* do_aborted_nested_tx -- (internal) thread-friendly aborted nested transaction
*/
static void *
do_aborted_nested_tx(void *arg)
{
struct transaction_data *data = arg;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_C;
BEGIN_TX(Pop, data->mutexes, data->rwlocks) {
data->a = TEST_VALUE_A;
pmemobj_tx_abort(EINVAL);
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
data->a = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
data->b = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->b == TEST_VALUE_B);
data->c = TEST_VALUE_C;
} TX_END
data->a = TEST_VALUE_B;
} TX_ONCOMMIT { /* not called */
UT_ASSERT(data->a == TEST_VALUE_A);
data->c = TEST_VALUE_C;
} TX_ONABORT {
UT_ASSERT(data->a == TEST_VALUE_A);
UT_ASSERT(data->b == TEST_VALUE_B);
UT_ASSERT(data->c == TEST_VALUE_C);
data->a = TEST_VALUE_B;
} TX_FINALLY {
UT_ASSERT(data->a == TEST_VALUE_B);
data->b = TEST_VALUE_A;
} TX_END
return NULL;
}
static void
run_mt_test(void *(*worker)(void *), void *arg)
{
os_thread_t thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i) {
PTHREAD_CREATE(&thread[i], NULL, worker, arg);
}
for (int i = 0; i < NUM_THREADS; ++i) {
PTHREAD_JOIN(&thread[i], NULL);
}
}
int
main(int argc, char *argv[])
{
START(argc, argv, "obj_tx_locks");
if (argc > 3)
UT_FATAL("usage: %s <file> [m]", argv[0]);
if ((Pop = pmemobj_create(argv[1], LAYOUT_NAME,
PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR)) == NULL)
UT_FATAL("!pmemobj_create");
int multithread = 0;
if (argc == 3) {
multithread = (argv[2][0] == 'm');
if (!multithread)
UT_FATAL("wrong test type supplied %c", argv[1][0]);
}
PMEMoid root = pmemobj_root(Pop, sizeof(struct transaction_data));
struct transaction_data *test_obj =
(struct transaction_data *)pmemobj_direct(root);
if (multithread) {
run_mt_test(do_tx, test_obj);
} else {
do_tx(test_obj);
do_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_aborted_tx, test_obj);
} else {
do_aborted_tx(test_obj);
do_aborted_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_nested_tx, test_obj);
} else {
do_nested_tx(test_obj);
do_nested_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
if (multithread) {
run_mt_test(do_aborted_nested_tx, test_obj);
} else {
do_aborted_nested_tx(test_obj);
do_aborted_nested_tx(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_B);
UT_ASSERT(test_obj->b == TEST_VALUE_A);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
/* test that deprecated macros still work */
UT_COMPILE_ERROR_ON((int)TX_LOCK_NONE != (int)TX_PARAM_NONE);
UT_COMPILE_ERROR_ON((int)TX_LOCK_MUTEX != (int)TX_PARAM_MUTEX);
UT_COMPILE_ERROR_ON((int)TX_LOCK_RWLOCK != (int)TX_PARAM_RWLOCK);
if (multithread) {
run_mt_test(do_tx_old, test_obj);
} else {
do_tx_old(test_obj);
do_tx_old(test_obj);
}
UT_ASSERT(test_obj->a == TEST_VALUE_A);
UT_ASSERT(test_obj->b == TEST_VALUE_B);
UT_ASSERT(test_obj->c == TEST_VALUE_C);
pmemobj_close(Pop);
DONE(NULL);
}
| 7,682 | 24.695652 | 80 | c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.