repo
stringlengths 1
152
⌀ | file
stringlengths 15
205
| code
stringlengths 0
41.6M
| file_length
int64 0
41.6M
| avg_line_length
float64 0
1.81M
| max_line_length
int64 0
12.7M
| extension_type
stringclasses 90
values |
---|---|---|---|---|---|---|
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmemobj/ulog.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2020, Intel Corporation */
/*
* ulog.h -- unified log public interface
*/
#ifndef LIBPMEMOBJ_ULOG_H
#define LIBPMEMOBJ_ULOG_H 1
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include "vec.h"
#include "pmemops.h"
#include<x86intrin.h>
////cmd write optimization
/*
struct ulog_cmd_packet{
uint32_t ulog_offset : 32;
uint32_t base_offset : 32;
uint32_t src : 32;
uint32_t size : 32;
};
*/
struct ulog_entry_base {
uint64_t offset; /* offset with operation type flag */
};
/*
* ulog_entry_val -- log entry
*/
struct ulog_entry_val {
struct ulog_entry_base base;
uint64_t value; /* value to be applied */
};
/*
* ulog_entry_buf - ulog buffer entry
*/
struct ulog_entry_buf {
struct ulog_entry_base base; /* offset with operation type flag */
uint64_t checksum; /* checksum of the entire log entry */
uint64_t size; /* size of the buffer to be modified */
uint8_t data[]; /* content to fill in */
};
#define ULOG_UNUSED ((CACHELINE_SIZE - 40) / 8)
/*
* This structure *must* be located at a cacheline boundary. To achieve this,
* the next field is always allocated with extra padding, and then the offset
* is additionally aligned.
*/
#define ULOG(capacity_bytes) {\
/* 64 bytes of metadata */\
uint64_t checksum; /* checksum of ulog header and its entries */\
uint64_t next; /* offset of ulog extension */\
uint64_t capacity; /* capacity of this ulog in bytes */\
uint64_t gen_num; /* generation counter */\
uint64_t flags; /* ulog flags */\
uint64_t unused[ULOG_UNUSED]; /* must be 0 */\
uint8_t data[capacity_bytes]; /* N bytes of data */\
}\
#define SIZEOF_ULOG(base_capacity)\
(sizeof(struct ulog) + base_capacity)
/*
* Ulog buffer allocated by the user must be marked by this flag.
* It is important to not free it at the end:
* what user has allocated - user should free himself.
*/
#define ULOG_USER_OWNED (1U << 0)
/* use this for allocations of aligned ulog extensions */
#define SIZEOF_ALIGNED_ULOG(base_capacity)\
ALIGN_UP(SIZEOF_ULOG(base_capacity + (2 * CACHELINE_SIZE)), CACHELINE_SIZE)
struct ulog ULOG(0);
VEC(ulog_next, uint64_t);
typedef uint64_t ulog_operation_type;
#define ULOG_OPERATION_SET (0b000ULL << 61ULL)
#define ULOG_OPERATION_AND (0b001ULL << 61ULL)
#define ULOG_OPERATION_OR (0b010ULL << 61ULL)
#define ULOG_OPERATION_BUF_SET (0b101ULL << 61ULL)
#define ULOG_OPERATION_BUF_CPY (0b110ULL << 61ULL)
#define ULOG_BIT_OPERATIONS (ULOG_OPERATION_AND | ULOG_OPERATION_OR)
/* immediately frees all associated ulog structures */
#define ULOG_FREE_AFTER_FIRST (1U << 0)
/* increments gen_num of the first, preallocated, ulog */
#define ULOG_INC_FIRST_GEN_NUM (1U << 1)
/* informs if there was any buffer allocated by user in the tx */
#define ULOG_ANY_USER_BUFFER (1U << 2)
typedef int (*ulog_check_offset_fn)(void *ctx, uint64_t offset);
typedef int (*ulog_extend_fn)(void *, uint64_t *, uint64_t);
typedef int (*ulog_entry_cb)(struct ulog_entry_base *e, void *arg,
const struct pmem_ops *p_ops);
typedef int (*ulog_entry_cb_ndp)(struct ulog_entry_base *e, struct ulog_entry_base *f, void *arg,
const struct pmem_ops *p_ops);
typedef void (*ulog_free_fn)(void *base, uint64_t *next);
typedef int (*ulog_rm_user_buffer_fn)(void *, void *addr);
struct ulog *ulog_next(struct ulog *ulog, const struct pmem_ops *p_ops);
void ulog_construct(uint64_t offset, size_t capacity, uint64_t gen_num,
int flush, uint64_t flags, const struct pmem_ops *p_ops);
size_t ulog_capacity(struct ulog *ulog, size_t ulog_base_bytes,
const struct pmem_ops *p_ops);
void ulog_rebuild_next_vec(struct ulog *ulog, struct ulog_next *next,
const struct pmem_ops *p_ops);
int ulog_foreach_entry(struct ulog *ulog,
ulog_entry_cb cb, void *arg, const struct pmem_ops *ops, struct ulog *ulognvm);
int ulog_foreach_entry_ndp(struct ulog *ulogdram, struct ulog *ulognvm,
ulog_entry_cb_ndp cb, void *arg, const struct pmem_ops *ops);
int ulog_reserve(struct ulog *ulog,
size_t ulog_base_nbytes, size_t gen_num,
int auto_reserve, size_t *new_capacity_bytes,
ulog_extend_fn extend, struct ulog_next *next,
const struct pmem_ops *p_ops);
void ulog_store(struct ulog *dest,
struct ulog *src, size_t nbytes, size_t ulog_base_nbytes,
size_t ulog_total_capacity,
struct ulog_next *next, const struct pmem_ops *p_ops);
int ulog_free_next(struct ulog *u, const struct pmem_ops *p_ops,
ulog_free_fn ulog_free, ulog_rm_user_buffer_fn user_buff_remove,
uint64_t flags);
void ulog_clobber(struct ulog *dest, struct ulog_next *next,
const struct pmem_ops *p_ops);
int ulog_clobber_data(struct ulog *dest,
size_t nbytes, size_t ulog_base_nbytes,
struct ulog_next *next, ulog_free_fn ulog_free,
ulog_rm_user_buffer_fn user_buff_remove,
const struct pmem_ops *p_ops, unsigned flags);
void ulog_clobber_entry(const struct ulog_entry_base *e,
const struct pmem_ops *p_ops);
void ulog_process(struct ulog *ulog, ulog_check_offset_fn check,
const struct pmem_ops *p_ops);
void ulog_process_ndp(struct ulog *ulognvm, struct ulog *ulogdeam, ulog_check_offset_fn check,
const struct pmem_ops *p_ops);
size_t ulog_base_nbytes(struct ulog *ulog);
int ulog_recovery_needed(struct ulog *ulog, int verify_checksum);
struct ulog *ulog_by_offset(size_t offset, const struct pmem_ops *p_ops);
uint64_t ulog_entry_offset(const struct ulog_entry_base *entry);
ulog_operation_type ulog_entry_type(
const struct ulog_entry_base *entry);
struct ulog_entry_val *ulog_entry_val_create(struct ulog *ulog,
size_t offset, uint64_t *dest, uint64_t value,
ulog_operation_type type,
const struct pmem_ops *p_ops);
#ifdef USE_NDP_CLOBBER
struct ulog_entry_buf *
ulog_entry_buf_create(struct ulog *ulog, size_t offset,
uint64_t gen_num, uint64_t *dest, const void *src, uint64_t size,
ulog_operation_type type, const struct pmem_ops *p_ops, int clear_next_header);
#else
struct ulog_entry_buf *
ulog_entry_buf_create(struct ulog *ulog, size_t offset,
uint64_t gen_num, uint64_t *dest, const void *src, uint64_t size,
ulog_operation_type type, const struct pmem_ops *p_ops);
#endif
void ulog_entry_apply(const struct ulog_entry_base *e, int persist,
const struct pmem_ops *p_ops);
void ulog_entry_apply_ndp(const struct ulog_entry_base *e, const struct ulog_entry_base *f, int persist,
const struct pmem_ops *p_ops);
size_t ulog_entry_size(const struct ulog_entry_base *entry);
void ulog_recover(struct ulog *ulog, ulog_check_offset_fn check,
const struct pmem_ops *p_ops);
int ulog_check(struct ulog *ulog, ulog_check_offset_fn check,
const struct pmem_ops *p_ops);
#endif
| 6,600 | 32.170854 | 104 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/common_badblock.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2020, Intel Corporation
#
# src/test/common_badblock.sh -- commons for the following tests:
# - util_badblock
# - pmempool_create
# - pmempool_info
#
LOG=out${UNITTEST_NUM}.log
UNITTEST_DIRNAME=$(echo $UNITTEST_NAME | cut -d'/' -f1)
COMMAND_MOUNTED_DIRS="\
mount | grep -e $UNITTEST_DIRNAME | cut -d' ' -f1 | xargs && true"
COMMAND_NDCTL_NFIT_TEST_INIT="\
sudo modprobe nfit_test &>>$PREP_LOG_FILE && \
sudo ndctl disable-region all &>>$PREP_LOG_FILE && \
sudo ndctl zero-labels all &>>$PREP_LOG_FILE && \
sudo ndctl enable-region all &>>$PREP_LOG_FILE"
COMMAND_NDCTL_NFIT_TEST_FINI="\
sudo ndctl disable-region all &>>$PREP_LOG_FILE && \
sudo modprobe -r nfit_test &>>$PREP_LOG_FILE"
#
# badblock_test_init -- initialize badblock test based on underlying hardware
#
# Input arguments:
# 1) device type (dax_device|block_device)
# 2) mount directory (in case of block device type)
#
function badblock_test_init() {
case "$1"
in
dax_device|block_device)
;;
*)
usage "bad device type: $1"
;;
esac
DEVTYPE=$1
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
ndctl_nfit_test_init
fi
if [ "$DEVTYPE" == "dax_device" ]; then
DEVICE=$(badblock_test_get_dax_device)
elif [ "$DEVTYPE" == "block_device" ]; then
DEVICE=$(badblock_test_get_block_device)
prepare_mount_dir $DEVICE $2
fi
NAMESPACE=$(ndctl_get_namespace_of_device $DEVICE)
FULLDEV="/dev/$DEVICE"
# current unit tests support only block sizes less or equal 4096 bytes
require_max_block_size $FULLDEV 4096
}
#
# badblock_test_init_node -- initialize badblock test based on underlying
# hardware on a remote node
#
# Input arguments:
# 1) remote node number
# 2) device type (dax_device|block_device)
# 3) for block device: mount directory
# for dax device on real pmem: dax device index on a given node
#
function badblock_test_init_node() {
case "$2"
in
dax_device|block_device)
;;
*)
usage "bad device type: $2"
;;
esac
DEVTYPE=$2
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
ndctl_nfit_test_init_node $1
fi
if [ "$DEVTYPE" == "dax_device" ]; then
DEVICE=$(badblock_test_get_dax_device_node $1 $3)
elif [ "$DEVTYPE" == "block_device" ]; then
DEVICE=$(badblock_test_get_block_device_node $1)
prepare_mount_dir_node $1 $DEVICE $3
fi
NAMESPACE=$(ndctl_get_namespace_of_device_node $1 $DEVICE)
FULLDEV="/dev/$DEVICE"
}
#
# badblock_test_get_dax_device -- get name of the dax device
#
function badblock_test_get_dax_device() {
DEVICE=""
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
DEVICE=$(ndctl_nfit_test_get_dax_device)
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
DEVICE=$(real_pmem_get_dax_device)
fi
echo $DEVICE
}
#
# badblock_test_get_dax_device_node -- get name of the dax device on a given
# remote node
# Input arguments:
# 1) remote node number
# 2) For real pmem: device dax index on a given node
#
function badblock_test_get_dax_device_node() {
DEVICE=""
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
DEVICE=$(ndctl_nfit_test_get_dax_device_node $1)
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
DEVICE=$(real_pmem_get_dax_device_node $1 $2)
fi
echo $DEVICE
}
#
# badblock_test_get_block_device -- get name of the block device
#
function badblock_test_get_block_device() {
DEVICE=""
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
DEVICE=$(ndctl_nfit_test_get_block_device)
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
DEVICE=$(real_pmem_get_block_device)
fi
echo "$DEVICE"
}
#
# badblock_test_get_block_device_node -- get name of the block device on a given
# remote node
#
function badblock_test_get_block_device_node() {
DEVICE=""
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
DEVICE=$(ndctl_nfit_test_get_block_device_node $1)
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
DEVICE=$(real_pmem_get_block_device_node $1)
fi
echo "$DEVICE"
}
#
# prepare_mount_dir -- prepare the mount directory for provided device
#
# Input arguments:
# 1) device name
# 2) mount directory
#
function prepare_mount_dir() {
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
local FULLDEV="/dev/$1"
ndctl_nfit_test_mount_pmem $FULLDEV $2
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
if [ ! -d $2 ]; then
mkdir -p $2
fi
fi
}
#
# prepare_mount_dir_node -- prepare the mount directory for provided device
# on a given remote node
#
# Input arguments:
# 1) remote node number
# 2) device name
# 3) mount directory
#
function prepare_mount_dir_node() {
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
local FULLDEV="/dev/$2"
ndctl_nfit_test_mount_pmem_node $1 $FULLDEV $3
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
if [ ! -d $3 ]; then
run_on_node $1 "mkdir -p $3"
fi
fi
}
#
# real_pmem_get_dax_device -- get real pmem dax device name
#
function real_pmem_get_dax_device() {
local FULLDEV=${DEVICE_DAX_PATH[0]}
DEVICE=${FULLDEV##*/}
echo $DEVICE
}
#
# real_pmem_get_dax_device_node -- get real pmem dax device name on a given
# remote node
#
# Input arguments:
# 1) remote node number
# 2) device dax index number
#
function real_pmem_get_dax_device_node() {
local node=$1
local devdax_index=$2
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
local FULLDEV=${device_dax_path[$devdax_index]}
DEVICE=${FULLDEV##*/}
echo $DEVICE
}
#
# real_pmem_get_block_device -- get real pmem block device name
#
function real_pmem_get_block_device() {
local FULL_DEV=$(mount | grep $PMEM_FS_DIR | cut -f 1 -d" ")
DEVICE=${FULL_DEV##*/}
echo $DEVICE
}
#
# real_pmem_get_block_device_node -- get real pmem block device name on a given
# remote node
#
function real_pmem_get_block_device_node() {
local FULL_DEV=$(expect_normal_exit run_on_node $1 mount | grep $PMEM_FS_DIR | cut -f 1 -d" ")
DEVICE=${FULL_DEV##*/}
echo $DEVICE
}
#
# ndctl_nfit_test_init -- reset all regions and reload the nfit_test module
#
function ndctl_nfit_test_init() {
sudo ndctl disable-region all &>>$PREP_LOG_FILE
if ! sudo modprobe -r nfit_test &>>$PREP_LOG_FILE; then
MOUNTED_DIRS="$(eval $COMMAND_MOUNTED_DIRS)"
[ "$MOUNTED_DIRS" ] && sudo umount $MOUNTED_DIRS
sudo ndctl disable-region all &>>$PREP_LOG_FILE
sudo modprobe -r nfit_test
fi
expect_normal_exit $COMMAND_NDCTL_NFIT_TEST_INIT
}
#
# ndctl_nfit_test_init_node -- reset all regions and reload the nfit_test
# module on a remote node
#
function ndctl_nfit_test_init_node() {
run_on_node $1 "sudo ndctl disable-region all &>>$PREP_LOG_FILE"
if ! run_on_node $1 "sudo modprobe -r nfit_test &>>$PREP_LOG_FILE"; then
MOUNTED_DIRS="$(run_on_node $1 $COMMAND_MOUNTED_DIRS)"
run_on_node $1 "\
[ \"$MOUNTED_DIRS\" ] && sudo umount $MOUNTED_DIRS; \
sudo ndctl disable-region all &>>$PREP_LOG_FILE; \
sudo modprobe -r nfit_test"
fi
expect_normal_exit run_on_node $1 "$COMMAND_NDCTL_NFIT_TEST_INIT"
}
#
# badblock_test_fini -- clean badblock test based on underlying hardware
#
# Input arguments:
# 1) pmem mount directory to be umounted (optional)
#
function badblock_test_fini() {
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
ndctl_nfit_test_fini $1
fi
}
#
# badblock_test_fini_node() -- clean badblock test based on underlying hardware
# on a given remote node
#
# Input arguments:
# 1) node number
# 2) pmem mount directory to be umounted (optional)
#
function badblock_test_fini_node() {
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
ndctl_nfit_test_fini_node $1 $2
fi
}
#
# ndctl_nfit_test_fini -- clean badblock test ran on nfit_test based on underlying hardware
#
function ndctl_nfit_test_fini() {
MOUNT_DIR=$1
[ $MOUNT_DIR ] && sudo umount $MOUNT_DIR &>> $PREP_LOG_FILE
expect_normal_exit $COMMAND_NDCTL_NFIT_TEST_FINI
}
#
# ndctl_nfit_test_fini_node -- disable all regions, remove the nfit_test module
# and (optionally) umount the pmem block device on a remote node
#
# Input arguments:
# 1) node number
# 2) pmem mount directory to be umounted
#
function ndctl_nfit_test_fini_node() {
MOUNT_DIR=$2
[ $MOUNT_DIR ] && expect_normal_exit run_on_node $1 "sudo umount $MOUNT_DIR &>> $PREP_LOG_FILE"
expect_normal_exit run_on_node $1 "$COMMAND_NDCTL_NFIT_TEST_FINI"
}
#
# ndctl_nfit_test_mount_pmem -- mount a pmem block device
#
# Input arguments:
# 1) path of a pmem block device
# 2) mount directory
#
function ndctl_nfit_test_mount_pmem() {
FULLDEV=$1
MOUNT_DIR=$2
expect_normal_exit "\
sudo mkfs.ext4 $FULLDEV &>>$PREP_LOG_FILE && \
sudo mkdir -p $MOUNT_DIR &>>$PREP_LOG_FILE && \
sudo mount $FULLDEV $MOUNT_DIR &>>$PREP_LOG_FILE && \
sudo chmod 0777 $MOUNT_DIR"
}
#
# ndctl_nfit_test_mount_pmem_node -- mount a pmem block device on a remote node
#
# Input arguments:
# 1) number of a node
# 2) path of a pmem block device
# 3) mount directory
#
function ndctl_nfit_test_mount_pmem_node() {
FULLDEV=$2
MOUNT_DIR=$3
expect_normal_exit run_on_node $1 "\
sudo mkfs.ext4 $FULLDEV &>>$PREP_LOG_FILE && \
sudo mkdir -p $MOUNT_DIR &>>$PREP_LOG_FILE && \
sudo mount $FULLDEV $MOUNT_DIR &>>$PREP_LOG_FILE && \
sudo chmod 0777 $MOUNT_DIR"
}
#
# ndctl_nfit_test_get_device -- create a namespace and get name of the pmem device
# of the nfit_test module
#
# Input argument:
# 1) mode of the namespace (devdax or fsdax)
#
function ndctl_nfit_test_get_device() {
MODE=$1
DEVTYPE=""
[ "$MODE" == "devdax" ] && DEVTYPE="chardev"
[ "$MODE" == "fsdax" ] && DEVTYPE="blockdev"
[ "$DEVTYPE" == "" ] && echo "ERROR: wrong namespace mode: $MODE" >&2 && exit 1
BUS="nfit_test.0"
REGION=$(ndctl list -b $BUS -t pmem -Ri | sed "/dev/!d;s/[\", ]//g;s/dev://g" | tail -1)
DEVICE=$(sudo ndctl create-namespace -b $BUS -r $REGION -f -m $MODE -a 4096 | sed "/$DEVTYPE/!d;s/[\", ]//g;s/$DEVTYPE://g")
echo $DEVICE
}
#
# ndctl_nfit_test_get_device_node -- create a namespace and get name of the pmem device
# of the nfit_test module on a remote node
#
# Input argument:
# 1) mode of the namespace (devdax or fsdax)
#
function ndctl_nfit_test_get_device_node() {
MODE=$2
DEVTYPE=""
[ "$MODE" == "devdax" ] && DEVTYPE="chardev"
[ "$MODE" == "fsdax" ] && DEVTYPE="blockdev"
[ "$DEVTYPE" == "" ] && echo "ERROR: wrong namespace mode: $MODE" >&2 && exit 1
BUS="nfit_test.0"
REGION=$(expect_normal_exit run_on_node $1 ndctl list -b $BUS -t pmem -Ri | sed "/dev/!d;s/[\", ]//g;s/dev://g" | tail -1)
DEVICE=$(expect_normal_exit run_on_node $1 sudo ndctl create-namespace -b $BUS -r $REGION -f -m $MODE -a 4096 | sed "/$DEVTYPE/!d;s/[\", ]//g;s/$DEVTYPE://g")
echo $DEVICE
}
#
# ndctl_nfit_test_get_dax_device -- create a namespace and get name of the dax device
# of the nfit_test module
#
function ndctl_nfit_test_get_dax_device() {
# XXX needed by libndctl (it should be removed when it is not needed)
sudo chmod o+rw /dev/ndctl*
DEVICE=$(ndctl_nfit_test_get_device devdax)
sudo chmod o+rw /dev/$DEVICE
echo $DEVICE
}
#
# ndctl_nfit_test_get_dax_device_node -- create a namespace and get name of
# the pmem dax device of the nfit_test
# module on a remote node
#
function ndctl_nfit_test_get_dax_device_node() {
DEVICE=$(ndctl_nfit_test_get_device_node $1 devdax)
echo $DEVICE
}
#
# ndctl_nfit_test_get_block_device -- create a namespace and get name of the pmem block device
# of the nfit_test module
#
function ndctl_nfit_test_get_block_device() {
DEVICE=$(ndctl_nfit_test_get_device fsdax)
echo $DEVICE
}
#
# ndctl_nfit_test_get_block_device_node -- create a namespace and get name of
# the pmem block device of the nfit_test
# module on a remote node
#
function ndctl_nfit_test_get_block_device_node() {
DEVICE=$(ndctl_nfit_test_get_device_node $1 fsdax)
echo $DEVICE
}
#
# ndctl_nfit_test_grant_access -- grant accesses required by libndctl
#
# XXX needed by libndctl (it should be removed when these extra access rights are not needed)
#
# Input argument:
# 1) a name of pmem device
#
function ndctl_nfit_test_grant_access() {
BUS="nfit_test.0"
REGION=$(ndctl list -b $BUS -t pmem -Ri | sed "/dev/!d;s/[\", ]//g;s/dev://g" | tail -1)
expect_normal_exit "\
sudo chmod o+rw /dev/nmem* && \
sudo chmod o+r /sys/bus/nd/devices/ndbus*/$REGION/*/resource && \
sudo chmod o+r /sys/bus/nd/devices/ndbus*/$REGION/resource"
}
#
# ndctl_nfit_test_grant_access_node -- grant accesses required by libndctl on a node
#
# XXX needed by libndctl (it should be removed when these extra access rights are not needed)
#
# Input arguments:
# 1) node number
# 2) name of pmem device
#
function ndctl_nfit_test_grant_access_node() {
BUS="nfit_test.0"
REGION=$(expect_normal_exit run_on_node $1 ndctl list -b $BUS -t pmem -Ri | sed "/dev/!d;s/[\", ]//g;s/dev://g" | tail -1)
expect_normal_exit run_on_node $1 "\
sudo chmod o+rw /dev/nmem* && \
sudo chmod o+r /sys/bus/nd/devices/ndbus*/$REGION/*/resource && \
sudo chmod o+r /sys/bus/nd/devices/ndbus*/$REGION/resource"
}
#
# ndctl_requires_extra_access -- checks whether ndctl will require extra
# file permissions for bad-block iteration
#
# Input argument:
# 1) Mode of the namespace
#
function ndctl_requires_extra_access()
{
# Tests require additional permissions for badblock iteration if they
# are ran on device dax or with ndctl version prior to v63.
if [ "$1" != "fsdax" ] || ! is_ndctl_enabled $PMEMPOOL$EXESUFFIX ; then
return 0
fi
return 1
}
#
# ndctl_nfit_test_get_namespace_of_device -- get namespace of the pmem device
#
# Input argument:
# 1) a name of pmem device
#
function ndctl_get_namespace_of_device() {
local DEVICE=$1
NAMESPACE=$(ndctl list | grep -e "$DEVICE" -e namespace | grep -B1 -e "$DEVICE" | head -n1 | cut -d'"' -f4)
MODE=$(ndctl list -n "$NAMESPACE" | grep mode | cut -d'"' -f4)
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ] && ndctl_requires_extra_access $MODE; then
ndctl_nfit_test_grant_access $DEVICE
fi
echo "$NAMESPACE"
}
#
# ndctl_nfit_test_get_namespace_of_device_node -- get namespace of the pmem device on a remote node
#
# Input arguments:
# 1) node number
# 2) name of pmem device
#
function ndctl_get_namespace_of_device_node() {
local DEVICE=$2
NAMESPACE=$(expect_normal_exit run_on_node $1 ndctl list | grep -e "$DEVICE" -e namespace | grep -B1 -e "$DEVICE" | head -n1 | cut -d'"' -f4)
MODE=$(expect_normal_exit run_on_node $1 ndctl list -n "$NAMESPACE" | grep mode | cut -d'"' -f4)
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ] && ndctl_requires_extra_access $MODE; then
ndctl_nfit_test_grant_access_node $1 $DEVICE
fi
echo $NAMESPACE
}
#
# ndctl_inject_error -- inject error (bad blocks) to the namespace
#
# Input arguments:
# 1) namespace
# 2) the first bad block
# 3) number of bad blocks
#
function ndctl_inject_error() {
local namespace=$1
local block=$2
local count=$3
echo "# sudo ndctl inject-error --block=$block --count=$count $namespace" >> $PREP_LOG_FILE
expect_normal_exit "sudo ndctl inject-error --block=$block --count=$count $namespace" &>> $PREP_LOG_FILE
echo "# sudo ndctl start-scrub" >> $PREP_LOG_FILE
expect_normal_exit "sudo ndctl start-scrub" &>> $PREP_LOG_FILE
echo "# sudo ndctl wait-scrub" >> $PREP_LOG_FILE
expect_normal_exit "sudo ndctl wait-scrub" &>> $PREP_LOG_FILE
echo "(done: ndctl wait-scrub)" >> $PREP_LOG_FILE
}
#
# ndctl_inject_error_node -- inject error (bad blocks) to the namespace on
# a given remote node
#
# Input arguments:
# 1) node
# 2) namespace
# 3) the first bad block
# 4) number of bad blocks
#
function ndctl_inject_error_node() {
local node=$1
local namespace=$2
local block=$3
local count=$4
echo "# sudo ndctl inject-error --block=$block --count=$count $namespace" >> $PREP_LOG_FILE
expect_normal_exit run_on_node $node "sudo ndctl inject-error --block=$block --count=$count $namespace" &>> $PREP_LOG_FILE
echo "# sudo ndctl start-scrub" >> $PREP_LOG_FILE
expect_normal_exit run_on_node $node "sudo ndctl start-scrub" &>> $PREP_LOG_FILE
echo "# sudo ndctl wait-scrub" >> $PREP_LOG_FILE
expect_normal_exit run_on_node $node "sudo ndctl wait-scrub" &>> $PREP_LOG_FILE
echo "(done: ndctl wait-scrub)" >> $PREP_LOG_FILE
}
#
# ndctl_uninject_error -- clear bad block error present in the namespace
#
# Input arguments:
# 1) full device name (error clearing process requires writing to device)
# 2) namespace
# 3) the first bad block
# 4) number of bad blocks
#
function ndctl_uninject_error() {
# explicit uninjection is not required on nfit_test since any error
# injections made during the tests are eventually cleaned up in _fini
# function by reloading the whole namespace
if [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
local fulldev=$1
local namespace=$2
local block=$3
local count=$4
expect_normal_exit "sudo ndctl inject-error --uninject --block=$block --count=$count $namespace >> $PREP_LOG_FILE 2>&1"
if [ "$DEVTYPE" == "block_device" ]; then
expect_normal_exit "sudo dd if=/dev/zero of=$fulldev bs=512 seek=$block count=$count \
oflag=direct >> $PREP_LOG_FILE 2>&1"
elif [ "$DEVTYPE" == "dax_device" ]; then
expect_normal_exit "$DAXIO$EXESUFFIX -i /dev/zero -o $fulldev -s $block -l $count >> $PREP_LOG_FILE 2>&1"
fi
fi
}
#
# ndctl_uninject_error_node -- clear bad block error present in the
# namespace on a given remote node
#
# Input arguments:
# 1) node
# 2) full device name (error clearing process requires writing to device)
# 3) namespace
# 4) the first bad block
# 5) number of bad blocks
#
function ndctl_uninject_error_node() {
# explicit uninjection is not required on nfit_test since any error
# injections made during the tests are eventually cleaned up in _fini
# function by reloading the whole namespace
if [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
local node=$1
local fulldev=$2
local namespace=$3
local block=$4
local count=$5
expect_normal_exit run_on_node $node "sudo ndctl inject-error --uninject --block=$block --count=$count \
$namespace >> $PREP_LOG_FILE 2>&1"
if [ "$DEVTYPE" == "block_device" ]; then
expect_normal_exit run_on_node $node "sudo dd if=/dev/zero of=$fulldev bs=512 seek=$block count=$count \
oflag=direct >> $PREP_LOG_FILE 2>&1"
elif [ "$DEVTYPE" == "dax_device" ]; then
expect_normal_exit run_on_node $node "$DAXIO$EXESUFFIX -i /dev/zero -o $fulldev -s $block -l $count \
>> $PREP_LOG_FILE 2>&1"
fi
fi
}
#
# print_bad_blocks -- print all bad blocks (count, offset and length)
# in the given namespace or "No bad blocks found"
# if there are no bad blocks
#
# Input arguments:
# 1) namespace
#
function print_bad_blocks {
# XXX sudo should be removed when it is not needed
sudo ndctl list -M -n $1 | \
grep -e "badblock_count" -e "offset" -e "length" >> $LOG \
|| echo "No bad blocks found" >> $LOG
}
#
# expect_bad_blocks -- verify if there are required bad blocks
# in the given namespace and fail if they are not there
#
# Input arguments:
# 1) namespace
#
function expect_bad_blocks {
# XXX sudo should be removed when it is not needed
sudo ndctl list -M -n $1 | grep -e "badblock_count" -e "offset" -e "length" >> $LOG && true
if [ $? -ne 0 ]; then
# XXX sudo should be removed when it is not needed
sudo ndctl list -M &>> $PREP_LOG_FILE && true
msg "====================================================================="
msg "Error occurred, the preparation log ($PREP_LOG_FILE) is listed below:"
msg ""
cat $PREP_LOG_FILE
msg "====================================================================="
msg ""
fatal "Error: ndctl failed to inject or retain bad blocks"
fi
}
#
# expect_bad_blocks_node -- verify if there are required bad blocks
# in the given namespace on the given node
# and fail if they are not there
#
# Input arguments:
# 1) node number
# 2) namespace
#
function expect_bad_blocks_node {
# XXX sudo should be removed when it is not needed
expect_normal_exit run_on_node $1 sudo ndctl list -M -n $2 | \
grep -e "badblock_count" -e "offset" -e "length" >> $LOG \
|| fatal "Error: ndctl failed to inject or retain bad blocks (node $1)"
}
| 20,737 | 28.838849 | 159 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/libpmempool_rm_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# libpmempool_rm_remote/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 285 | 19.428571 | 55 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_obc/rpmem_obc_test_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmem_obc_test_common.h -- common declarations for rpmem_obc test
*/
#include "unittest.h"
#include "out.h"
#include "librpmem.h"
#include "rpmem.h"
#include "rpmem_proto.h"
#include "rpmem_common.h"
#include "rpmem_util.h"
#include "rpmem_obc.h"
#define POOL_SIZE 1024
#define NLANES 32
#define NLANES_RESP 16
#define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS
#define POOL_DESC "pool_desc"
#define RKEY 0xabababababababab
#define RADDR 0x0101010101010101
#define PORT 1234
#define BUFF_SIZE 8192
#define POOL_ATTR_INIT {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 3,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS012345",\
}
#define POOL_ATTR_ALT {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 7,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "012345USER_FLAGS",\
}
static const struct rpmem_pool_attr POOL_ATTR = POOL_ATTR_INIT;
struct server {
int fd_in;
int fd_out;
};
void set_rpmem_cmd(const char *fmt, ...);
struct server *srv_init(void);
void srv_fini(struct server *s);
void srv_recv(struct server *s, void *buff, size_t len);
void srv_send(struct server *s, const void *buff, size_t len);
void srv_wait_disconnect(struct server *s);
void client_connect_wait(struct rpmem_obc *rpc, char *target);
/*
* Since the server may disconnect the connection at any moment
* from the client's perspective, execute the test in a loop so
* the moment when the connection is closed will be possibly different.
*/
#define ECONNRESET_LOOP 10
void server_econnreset(struct server *s, const void *msg, size_t len);
TEST_CASE_DECLARE(client_enotconn);
TEST_CASE_DECLARE(client_connect);
TEST_CASE_DECLARE(client_monitor);
TEST_CASE_DECLARE(server_monitor);
TEST_CASE_DECLARE(server_wait);
TEST_CASE_DECLARE(client_create);
TEST_CASE_DECLARE(server_create);
TEST_CASE_DECLARE(server_create_econnreset);
TEST_CASE_DECLARE(server_create_eproto);
TEST_CASE_DECLARE(server_create_error);
TEST_CASE_DECLARE(client_open);
TEST_CASE_DECLARE(server_open);
TEST_CASE_DECLARE(server_open_econnreset);
TEST_CASE_DECLARE(server_open_eproto);
TEST_CASE_DECLARE(server_open_error);
TEST_CASE_DECLARE(client_close);
TEST_CASE_DECLARE(server_close);
TEST_CASE_DECLARE(server_close_econnreset);
TEST_CASE_DECLARE(server_close_eproto);
TEST_CASE_DECLARE(server_close_error);
TEST_CASE_DECLARE(client_set_attr);
TEST_CASE_DECLARE(server_set_attr);
TEST_CASE_DECLARE(server_set_attr_econnreset);
TEST_CASE_DECLARE(server_set_attr_eproto);
TEST_CASE_DECLARE(server_set_attr_error);
| 2,951 | 26.082569 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_obc/setup.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2019, Intel Corporation
#
# src/test/rpmem_obc/setup.sh -- common setup for rpmem_obc tests
#
set -e
require_nodes 2
require_node_log_files 1 $RPMEM_LOG_FILE
RPMEM_CMD="\"cd ${NODE_TEST_DIR[0]} && UNITTEST_FORCE_QUIET=1 \
LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[0]}:$REMOTE_LD_LIBRARY_PATH \
./rpmem_obc$EXESUFFIX\""
export_vars_node 1 RPMEM_CMD
| 428 | 22.833333 | 69 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_granularity/pmem2_granularity.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019, Intel Corporation */
/*
* pmem2_granularity.h -- header file for windows mocks
* for pmem2_granularity
*/
#ifndef PMEM2_GRANULARITY_H
#define PMEM2_GRANULARITY_H 1
extern size_t Is_nfit;
extern size_t Pc_type;
extern size_t Pc_capabilities;
#endif
| 314 | 18.6875 | 55 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_granularity/mocks_dax_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019, Intel Corporation */
/*
* mocks_dax_windows.h -- redefinitions of GetVolumeInformationByHandleW
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmem2
* files, when compiled for the purpose of pmem2_granularity test.
* It would replace default implementation with mocked functions defined
* in mocks_windows.c
*
* This WRAP_REAL define could also be passed as a preprocessor definition.
*/
#ifndef MOCKS_WINDOWS_H
#define MOCKS_WINDOWS_H 1
#include <windows.h>
#ifndef WRAP_REAL
#define GetVolumeInformationByHandleW __wrap_GetVolumeInformationByHandleW
BOOL
__wrap_GetVolumeInformationByHandleW(HANDLE hFile, LPWSTR lpVolumeNameBuffer,
DWORD nVolumeNameSize, LPDWORD lpVolumeSerialNumber,
LPDWORD lpMaximumComponentLength, LPDWORD lpFileSystemFlags,
LPWSTR lpFileSystemNameBuffer, DWORD nFileSystemNameSize);
#endif
#endif
| 956 | 28.90625 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_sync_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2018, Intel Corporation
#
#
# pmempool_sync_remote/config.sh -- test configuration
#
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 265 | 19.461538 | 54 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_sync_remote/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2020, Intel Corporation
#
#
# pmempool_sync_remote/common.sh -- pmempool sync with remote replication
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER
setup
init_rpmem_on_node 1 0
require_node_log_files 1 pmemobj$UNITTEST_NUM.log
require_node_log_files 1 pmempool$UNITTEST_NUM.log
PMEMOBJCLI_SCRIPT="pmemobjcli.script"
copy_files_to_node 1 ${NODE_TEST_DIR[1]} $PMEMOBJCLI_SCRIPT
POOLSET_LOCAL="local_pool.set"
#
# configure_poolsets -- configure pool set files for test
# usage: configure_poolsets <local replicas> <remote replicas>
#
function configure_poolsets() {
local n_local=$1
local n_remote=$2
local poolset_args="8M:${NODE_DIR[1]}/pool.part.1:x
8M:${NODE_DIR[1]}/pool.part.2:x"
for i in $(seq 0 $((n_local - 1))); do
poolset_args="$poolset_args R 8M:${NODE_DIR[1]}/pool.$i.part.1:x
8M:${NODE_DIR[1]}/pool.$i.part.2:x"
done
for i in $(seq 0 $((n_remote - 1))); do
POOLSET_REMOTE[$i]="remote_pool.$i.set"
create_poolset $DIR/${POOLSET_REMOTE[$i]}\
8M:${NODE_DIR[0]}remote.$i.part.1:x\
8M:${NODE_DIR[0]}remote.$i.part.2:x
copy_files_to_node 0 ${NODE_DIR[0]} $DIR/${POOLSET_REMOTE[$i]}
poolset_args="$poolset_args m ${NODE_ADDR[0]}:${POOLSET_REMOTE[$i]}"
done
create_poolset $DIR/$POOLSET_LOCAL $poolset_args
copy_files_to_node 1 ${NODE_DIR[1]} $DIR/$POOLSET_LOCAL
expect_normal_exit run_on_node 1 ../pmempool rm -sf ${NODE_DIR[1]}$POOLSET_LOCAL
expect_normal_exit run_on_node 1 ../pmempool create obj ${NODE_DIR[1]}$POOLSET_LOCAL
expect_normal_exit run_on_node 1 ../pmemobjcli -s $PMEMOBJCLI_SCRIPT ${NODE_DIR[1]}$POOLSET_LOCAL > /dev/null
}
DUMP_INFO_LOG="../pmempool info -lHZCOoAa"
DUMP_INFO_LOG_REMOTE="$DUMP_INFO_LOG -f obj"
DUMP_INFO_SED="sed -e '/^Checksum/d' -e '/^Creation/d'"
DUMP_INFO_SED_REMOTE="$DUMP_INFO_SED -e '/^Previous part UUID/d' -e '/^Next part UUID/d'"
function dump_info_log() {
local node=$1
local rep=$2
local poolset=$3
local name=$4
local ignore=$5
local sed_cmd="$DUMP_INFO_SED"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG -p $rep $poolset | $sed_cmd > $name\""
}
function dump_info_log_remote() {
local node=$1
local poolset=$2
local name=$3
local ignore=$4
local sed_cmd="$DUMP_INFO_SED_REMOTE"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG_REMOTE $poolset | $sed_cmd > $name\""
}
function diff_log() {
local node=$1
local f1=$2
local f2=$3
expect_normal_exit run_on_node $node "\"[ -s $f1 ] && [ -s $f2 ] && diff $f1 $f2\""
}
exec_pmemobjcli_script() {
local node=$1
local script=$2
local poolset=$3
local out=$4
expect_normal_exit run_on_node $node "\"../pmemobjcli -s $script $poolset > $out \""
}
| 2,911 | 25 | 110 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_sync/setup.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2020, IBM Corporation
#
PARTSIZE=$(($(getconf PAGESIZE)/1024*2))
POOLSIZE_REP=$(($PARTSIZE*3))
| 168 | 20.125 | 40 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_fip/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
#
# src/test/rpmem_fip/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=none
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 288 | 19.642857 | 52 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_fip/rpmem_fip_oob.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016, Intel Corporation */
/*
* rpmem_fip_sock.h -- simple oob connection implementation for exchanging
* required RDMA related data
*/
#include <stdint.h>
#include <netinet/in.h>
typedef struct rpmem_ssh client_t;
client_t *client_exchange(struct rpmem_target_info *info,
unsigned nlanes,
enum rpmem_provider provider,
struct rpmem_resp_attr *resp);
void client_close_begin(client_t *c);
void client_close_end(client_t *c);
void server_exchange_begin(unsigned *lanes, enum rpmem_provider *provider,
char **addr);
void server_exchange_end(struct rpmem_resp_attr resp);
void server_close_begin(void);
void server_close_end(void);
void set_rpmem_cmd(const char *fmt, ...);
| 743 | 24.655172 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_fip/setup.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2019, Intel Corporation
#
# src/test/rpmem_fip/setup.sh -- common setup for rpmem_fip tests
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER
require_node_log_files 0 $RPMEM_LOG_FILE $RPMEMD_LOG_FILE
require_node_log_files 1 $RPMEM_LOG_FILE $RPMEMD_LOG_FILE
SRV=srv${UNITTEST_NUM}.pid
clean_remote_node 0 $SRV
RPMEM_CMD="\"cd ${NODE_TEST_DIR[0]} && RPMEMD_LOG_LEVEL=\$RPMEMD_LOG_LEVEL RPMEMD_LOG_FILE=\$RPMEMD_LOG_FILE UNITTEST_FORCE_QUIET=1 \
LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[0]}:$REMOTE_LD_LIBRARY_PATH \
./rpmem_fip$EXESUFFIX\""
export_vars_node 1 RPMEM_CMD
if [ -n ${RPMEM_MAX_NLANES+x} ]; then
export_vars_node 1 RPMEM_MAX_NLANES
fi
| 786 | 28.148148 | 133 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/tools/anonymous_mmap/check_max_mmap.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018, Intel Corporation
#
# src/test/tools/anonymous_mmap/check_max_mmap.sh -- checks how many DAX
# devices can be mapped under Valgrind and saves the number in
# src/test/tools/anonymous_mmap/max_dax_devices.
#
DIR_CHECK_MAX_MMAP="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
FILE_MAX_DAX_DEVICES="$DIR_CHECK_MAX_MMAP/max_dax_devices"
ANONYMOUS_MMAP="$DIR_CHECK_MAX_MMAP/anonymous_mmap.static-nondebug"
source "$DIR_CHECK_MAX_MMAP/../../testconfig.sh"
#
# get_devdax_size -- get the size of a device dax
#
function get_devdax_size() {
local device=$1
local path=${DEVICE_DAX_PATH[$device]}
local major_hex=$(stat -c "%t" $path)
local minor_hex=$(stat -c "%T" $path)
local major_dec=$((16#$major_hex))
local minor_dec=$((16#$minor_hex))
cat /sys/dev/char/$major_dec:$minor_dec/size
}
function msg_skip() {
echo "0" > "$FILE_MAX_DAX_DEVICES"
echo "$0: SKIP: $*"
exit 0
}
function msg_failed() {
echo "$0: FATAL: $*" >&2
exit 1
}
# check if DEVICE_DAX_PATH specifies at least one DAX device
if [ ${#DEVICE_DAX_PATH[@]} -lt 1 ]; then
msg_skip "DEVICE_DAX_PATH does not specify path to DAX device."
fi
# check if valgrind package is installed
VALGRINDEXE=`which valgrind 2>/dev/null`
ret=$?
if [ $ret -ne 0 ]; then
msg_skip "Valgrind required."
fi
# check if memcheck tool is installed
$VALGRINDEXE --tool=memcheck --help 2>&1 | grep -qi "memcheck is Copyright (c)" && true
if [ $? -ne 0 ]; then
msg_skip "Valgrind with memcheck required."
fi
# check if anonymous_mmap tool is built
if [ ! -f "${ANONYMOUS_MMAP}" ]; then
msg_failed "${ANONYMOUS_MMAP} does not exist"
fi
# checks how many DAX devices can be mmapped under Valgrind and save the number
# in $FILE_MAX_DAX_DEVICES file
bytes="0"
max_devices="0"
for index in ${!DEVICE_DAX_PATH[@]}
do
if [ ! -e "${DEVICE_DAX_PATH[$index]}" ]; then
msg_failed "${DEVICE_DAX_PATH[$index]} does not exist"
fi
curr=$(get_devdax_size $index)
if [[ curr -eq 0 ]]; then
msg_failed "size of DAX device pointed by DEVICE_DAX_PATH[$index] equals 0."
fi
$VALGRINDEXE --tool=memcheck --quiet $ANONYMOUS_MMAP $((bytes + curr))
status=$?
if [[ status -ne 0 ]]; then
break
fi
bytes=$((bytes + curr))
max_devices=$((max_devices + 1))
done
echo "$max_devices" > "$FILE_MAX_DAX_DEVICES"
echo "$0: maximum possible anonymous mmap under Valgrind: $bytes bytes, equals to size of $max_devices DAX device(s). Value saved in $FILE_MAX_DAX_DEVICES."
| 2,524 | 26.445652 | 156 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/tools/ctrld/signals_linux.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* signals_linux.h - Signal definitions for Linux
*/
#ifndef _SIGNALS_LINUX_H
#define _SIGNALS_LINUX_H 1
#define SIGNAL_2_STR(sig) [sig] = #sig
static const char *signal2str[] = {
SIGNAL_2_STR(SIGHUP), /* 1 */
SIGNAL_2_STR(SIGINT), /* 2 */
SIGNAL_2_STR(SIGQUIT), /* 3 */
SIGNAL_2_STR(SIGILL), /* 4 */
SIGNAL_2_STR(SIGTRAP), /* 5 */
SIGNAL_2_STR(SIGABRT), /* 6 */
SIGNAL_2_STR(SIGBUS), /* 7 */
SIGNAL_2_STR(SIGFPE), /* 8 */
SIGNAL_2_STR(SIGKILL), /* 9 */
SIGNAL_2_STR(SIGUSR1), /* 10 */
SIGNAL_2_STR(SIGSEGV), /* 11 */
SIGNAL_2_STR(SIGUSR2), /* 12 */
SIGNAL_2_STR(SIGPIPE), /* 13 */
SIGNAL_2_STR(SIGALRM), /* 14 */
SIGNAL_2_STR(SIGTERM), /* 15 */
SIGNAL_2_STR(SIGSTKFLT), /* 16 */
SIGNAL_2_STR(SIGCHLD), /* 17 */
SIGNAL_2_STR(SIGCONT), /* 18 */
SIGNAL_2_STR(SIGSTOP), /* 19 */
SIGNAL_2_STR(SIGTSTP), /* 20 */
SIGNAL_2_STR(SIGTTIN), /* 21 */
SIGNAL_2_STR(SIGTTOU), /* 22 */
SIGNAL_2_STR(SIGURG), /* 23 */
SIGNAL_2_STR(SIGXCPU), /* 24 */
SIGNAL_2_STR(SIGXFSZ), /* 25 */
SIGNAL_2_STR(SIGVTALRM), /* 26 */
SIGNAL_2_STR(SIGPROF), /* 27 */
SIGNAL_2_STR(SIGWINCH), /* 28 */
SIGNAL_2_STR(SIGPOLL), /* 29 */
SIGNAL_2_STR(SIGPWR), /* 30 */
SIGNAL_2_STR(SIGSYS) /* 31 */
};
#define SIGNALMAX SIGSYS
#endif
| 1,322 | 27.148936 | 49 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/tools/ctrld/signals_freebsd.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* signals_fbsd.h - Signal definitions for FreeBSD
*/
#ifndef _SIGNALS_FBSD_H
#define _SIGNALS_FBSD_H 1
#define SIGNAL_2_STR(sig) [sig] = #sig
static const char *signal2str[] = {
SIGNAL_2_STR(SIGHUP), /* 1 */
SIGNAL_2_STR(SIGINT), /* 2 */
SIGNAL_2_STR(SIGQUIT), /* 3 */
SIGNAL_2_STR(SIGILL), /* 4 */
SIGNAL_2_STR(SIGTRAP), /* 5 */
SIGNAL_2_STR(SIGABRT), /* 6 */
SIGNAL_2_STR(SIGEMT), /* 7 */
SIGNAL_2_STR(SIGFPE), /* 8 */
SIGNAL_2_STR(SIGKILL), /* 9 */
SIGNAL_2_STR(SIGBUS), /* 10 */
SIGNAL_2_STR(SIGSEGV), /* 11 */
SIGNAL_2_STR(SIGSYS), /* 12 */
SIGNAL_2_STR(SIGPIPE), /* 13 */
SIGNAL_2_STR(SIGALRM), /* 14 */
SIGNAL_2_STR(SIGTERM), /* 15 */
SIGNAL_2_STR(SIGURG), /* 16 */
SIGNAL_2_STR(SIGSTOP), /* 17 */
SIGNAL_2_STR(SIGTSTP), /* 18 */
SIGNAL_2_STR(SIGCONT), /* 19 */
SIGNAL_2_STR(SIGCHLD), /* 20 */
SIGNAL_2_STR(SIGTTIN), /* 21 */
SIGNAL_2_STR(SIGTTOU), /* 22 */
SIGNAL_2_STR(SIGIO), /* 23 */
SIGNAL_2_STR(SIGXCPU), /* 24 */
SIGNAL_2_STR(SIGXFSZ), /* 25 */
SIGNAL_2_STR(SIGVTALRM), /* 26 */
SIGNAL_2_STR(SIGPROF), /* 27 */
SIGNAL_2_STR(SIGWINCH), /* 28 */
SIGNAL_2_STR(SIGINFO), /* 29 */
SIGNAL_2_STR(SIGUSR1), /* 30 */
SIGNAL_2_STR(SIGUSR2), /* 31 */
SIGNAL_2_STR(SIGTHR), /* 32 */
SIGNAL_2_STR(SIGLIBRT) /* 33 */
};
#define SIGNALMAX SIGLIBRT
#endif
| 1,386 | 26.74 | 50 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/libpmempool_feature/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2019, Intel Corporation
#
# src/test/libpmempool_feature/common.sh -- common part of libpmempool_feature tests
#
POOL=$DIR/pool.obj
OUT=out${UNITTEST_NUM}.log
LOG=grep${UNITTEST_NUM}.log
QUERY_PATTERN="query"
ERROR_PATTERN="<1> \\[feature.c:.*\\]"
exit_func=expect_normal_exit
sds_enabled=$(is_ndctl_enabled ./libpmempool_feature$EXESUFFIX; echo $?)
# libpmempool_feature_query_abnormal -- query feature with expected
# abnormal result
#
# usage: libpmempool_feature_query_abnormal <enum-pmempool_feature>
function libpmempool_feature_query_abnormal() {
# query feature
expect_abnormal_exit ./libpmempool_feature$EXESUFFIX $POOL q $1
if [ -f "$PMEMPOOL_LOG_FILE" ]; then
cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG
fi
}
# libpmempool_feature_query -- query feature
#
# usage: libpmempool_feature_query <enum-pmempool_feature>
function libpmempool_feature_query() {
# query feature
expect_normal_exit ./libpmempool_feature$EXESUFFIX $POOL q $1
cat $OUT | grep "$QUERY_PATTERN" >> $LOG
# verify query with pmempool info
set +e
count=$(expect_normal_exit $PMEMPOOL$EXESUFFIX info $POOL | grep -c "$1")
set -e
if [ "$count" = "0" ]; then
echo "pmempool info: $1 is NOT set" >> $LOG
else
echo "pmempool info: $1 is set" >> $LOG
fi
# check if pool is still valid
expect_normal_exit $PMEMPOOL$EXESUFFIX check $POOL >> /dev/null
}
# libpmempool_feature_enable -- enable feature
#
# usage: libpmempool_feature_enable <enum-pmempool_feature> [no-query]
function libpmempool_feature_enable() {
$exit_func ./libpmempool_feature$EXESUFFIX $POOL e $1
if [ "$exit_func" == "expect_abnormal_exit" ]; then
if [ -f "$PMEMPOOL_LOG_FILE" ]; then
cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG
fi
fi
if [ "x$2" != "xno-query" ]; then
libpmempool_feature_query $1
fi
}
# libpmempool_feature_disable -- disable feature
#
# usage: libpmempool_feature_disable <enum-pmempool_feature> [no-query]
function libpmempool_feature_disable() {
$exit_func ./libpmempool_feature$EXESUFFIX $POOL d $1
if [ "$exit_func" == "expect_abnormal_exit" ]; then
if [ -f "$PMEMPOOL_LOG_FILE" ]; then
cat $PMEMPOOL_LOG_FILE | grep "$ERROR_PATTERN" >> $LOG
fi
fi
if [ "x$2" != "xno-query" ]; then
libpmempool_feature_query $1
fi
}
| 2,340 | 27.204819 | 84 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_memset/memset_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* memset_common.h -- header file for common memset utilities
*/
#ifndef MEMSET_COMMON_H
#define MEMSET_COMMON_H 1
#include "unittest.h"
#include "file.h"
extern unsigned Flags[10];
typedef void *(*memset_fn)(void *pmemdest, int c, size_t len, unsigned flags);
typedef void (*persist_fn)(const void *ptr, size_t len);
void
do_memset(int fd, char *dest, const char *file_name, size_t dest_off,
size_t bytes, memset_fn fn, unsigned flags, persist_fn p);
#endif
| 552 | 22.041667 | 78 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/sync-remotes/copy-to-remote-nodes.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2018, Intel Corporation
#
# copy-to-remote-nodes.sh -- helper script used to sync remote nodes
#
set -e
if [ ! -f ../testconfig.sh ]; then
echo "SKIP: testconfig.sh does not exist"
exit 0
fi
# defined only to be able to source unittest.sh
UNITTEST_NAME=sync-remotes
UNITTEST_NUM=0
# Override default FS (any).
# This is not a real test, so it should not depend on whether
# PMEM_FS_DIR/NON_PMEM_FS_DIR are set.
FS=none
. ../unittest/unittest.sh
COPY_TYPE=$1
shift
case "$COPY_TYPE" in
common)
copy_common_to_remote_nodes $* > /dev/null
exit 0
;;
test)
copy_test_to_remote_nodes $* > /dev/null
exit 0
;;
esac
echo "Error: unknown copy type: $COPY_TYPE"
exit 1
| 788 | 17.785714 | 68 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_check/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# pmempool_check/config.sh -- test configuration
#
# Extend timeout for TEST5, as it may take a few minutes
# when run on a non-pmem file system.
CONF_TIMEOUT[5]='10m'
| 271 | 18.428571 | 56 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_check/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2020, Intel Corporation
#
#
# pmempool_check/common.sh -- checking pools helpers
#
LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG
LAYOUT=OBJ_LAYOUT$SUFFIX
POOLSET=$DIR/poolset
# pmemspoil_corrupt_replica_sds -- corrupt shutdown state
#
# usage: pmemspoil_corrupt_replica_sds <replica>
function pmemspoil_corrupt_replica_sds() {
local replica=$1
expect_normal_exit $PMEMSPOIL --replica $replica $POOLSET \
pool_hdr.shutdown_state.usc=999 \
pool_hdr.shutdown_state.dirty=1 \
"pool_hdr.shutdown_state.f:checksum_gen"
}
# pmempool_check_sds_init -- shutdown state unittest init
#
# usage: pmempool_check_sds [enable-sds]
function pmempool_check_sds_init() {
# initialize poolset
create_poolset $POOLSET \
8M:$DIR/part00:x \
r 8M:$DIR/part10:x
# enable SHUTDOWN_STATE feature
if [ "x$1" == "xenable-sds" ]; then
local conf="sds.at_create=1"
fi
PMEMOBJ_CONF="${PMEMOBJ_CONF}$conf;"
expect_normal_exit $PMEMPOOL$EXESUFFIX create --layout=$LAYOUT obj $POOLSET
}
# pmempool_check_sds -- perform shutdown state unittest
#
# usage: pmempool_check_sds <scenario>
function pmempool_check_sds() {
# corrupt poolset replicas
pmemspoil_corrupt_replica_sds 0
pmemspoil_corrupt_replica_sds 1
# verify it is corrupted
expect_abnormal_exit $PMEMPOOL$EXESUFFIX check $POOLSET >> $LOG 2>/dev/null
exit_func=expect_normal_exit
# perform fixes
case "$1" in
fix_second_replica_only)
echo -e "n\ny\n" | expect_normal_exit $PMEMPOOL$EXESUFFIX check -vr $POOLSET >> $LOG 2>/dev/null
;;
fix_first_replica)
echo -e "y\n" | expect_normal_exit $PMEMPOOL$EXESUFFIX check -vr $POOLSET >> $LOG 2>/dev/null
;;
fix_no_replicas)
echo -e "n\nn\n" | expect_abnormal_exit $PMEMPOOL$EXESUFFIX check -vr $POOLSET >> $LOG 2>/dev/null
exit_func=expect_abnormal_exit
;;
*)
fatal "unittest_sds: undefined scenario '$1'"
;;
esac
#verify result
$exit_func $PMEMPOOL$EXESUFFIX check $POOLSET >> $LOG 2>/dev/null
}
| 2,010 | 25.460526 | 100 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/unittest.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* unittest.h -- the mundane stuff shared by all unit tests
*
* we want unit tests to be very thorough and check absolutely everything
* in order to nail down the test case as precisely as possible and flag
* anything at all unexpected. as a result, most unit tests are 90% code
* checking stuff that isn't really interesting to what is being tested.
* to help address this, the macros defined here include all the boilerplate
* error checking which prints information and exits on unexpected errors.
*
* the result changes this code:
*
* if ((buf = malloc(size)) == NULL) {
* fprintf(stderr, "cannot allocate %d bytes for buf\n", size);
* exit(1);
* }
*
* into this code:
*
* buf = MALLOC(size);
*
* and the error message includes the calling context information (file:line).
* in general, using the all-caps version of a call means you're using the
* unittest.h version which does the most common checking for you. so
* calling VMEM_CREATE() instead of vmem_create() returns the same
* thing, but can never return an error since the unit test library checks for
* it. * for routines like vmem_delete() there is no corresponding
* VMEM_DELETE() because there's no error to check for.
*
* all unit tests should use the same initialization:
*
* START(argc, argv, "brief test description", ...);
*
* all unit tests should use these exit calls:
*
* DONE("message", ...);
* UT_FATAL("message", ...);
*
* uniform stderr and stdout messages:
*
* UT_OUT("message", ...);
* UT_ERR("message", ...);
*
* in all cases above, the message is printf-like, taking variable args.
* the message can be NULL. it can start with "!" in which case the "!" is
* skipped and the message gets the errno string appended to it, like this:
*
* if (somesyscall(..) < 0)
* UT_FATAL("!my message");
*/
#ifndef _UNITTEST_H
#define _UNITTEST_H 1
#include <libpmem.h>
#include <libpmem2.h>
#include <libpmemblk.h>
#include <libpmemlog.h>
#include <libpmemobj.h>
#include <libpmempool.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <setjmp.h>
#include <time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/file.h>
#ifndef __FreeBSD__
#include <sys/mount.h>
#endif
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <dirent.h>
/* XXX: move OS abstraction layer out of common */
#include "os.h"
#include "os_thread.h"
#include "util.h"
int ut_get_uuid_str(char *);
#define UT_MAX_ERR_MSG 128
#define UT_POOL_HDR_UUID_STR_LEN 37 /* uuid string length */
#define UT_POOL_HDR_UUID_GEN_FILE "/proc/sys/kernel/random/uuid"
/* XXX - fix this temp hack dup'ing util_strerror when we get mock for win */
void ut_strerror(int errnum, char *buff, size_t bufflen);
/* XXX - eliminate duplicated definitions in unittest.h and util.h */
#ifdef _WIN32
static inline int ut_util_statW(const wchar_t *path,
os_stat_t *st_bufp) {
int retVal = _wstat64(path, st_bufp);
/* clear unused bits to avoid confusion */
st_bufp->st_mode &= 0600;
return retVal;
}
#endif
/*
* unit test support...
*/
void ut_start(const char *file, int line, const char *func,
int argc, char * const argv[], const char *fmt, ...)
__attribute__((format(printf, 6, 7)));
void ut_startW(const char *file, int line, const char *func,
int argc, wchar_t * const argv[], const char *fmt, ...)
__attribute__((format(printf, 6, 7)));
void NORETURN ut_done(const char *file, int line, const char *func,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void NORETURN ut_fatal(const char *file, int line, const char *func,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void NORETURN ut_end(const char *file, int line, const char *func,
int ret);
void ut_out(const char *file, int line, const char *func,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void ut_err(const char *file, int line, const char *func,
const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
/* indicate the start of the test */
#ifndef _WIN32
#define START(argc, argv, ...)\
ut_start(__FILE__, __LINE__, __func__, argc, argv, __VA_ARGS__)
#else
#define START(argc, argv, ...)\
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc);\
for (int i = 0; i < argc; i++) {\
argv[i] = ut_toUTF8(wargv[i]);\
if (argv[i] == NULL) {\
for (i--; i >= 0; i--)\
free(argv[i]);\
UT_FATAL("Error during arguments conversion\n");\
}\
}\
ut_start(__FILE__, __LINE__, __func__, argc, argv, __VA_ARGS__)
#endif
/* indicate the start of the test */
#define STARTW(argc, argv, ...)\
ut_startW(__FILE__, __LINE__, __func__, argc, argv, __VA_ARGS__)
/* normal exit from test */
#ifndef _WIN32
#define DONE(...)\
ut_done(__FILE__, __LINE__, __func__, __VA_ARGS__)
#else
#define DONE(...)\
for (int i = argc; i > 0; i--)\
free(argv[i - 1]);\
ut_done(__FILE__, __LINE__, __func__, __VA_ARGS__)
#endif
#define DONEW(...)\
ut_done(__FILE__, __LINE__, __func__, __VA_ARGS__)
#define END(ret, ...)\
ut_end(__FILE__, __LINE__, __func__, ret)
/* fatal error detected */
#define UT_FATAL(...)\
ut_fatal(__FILE__, __LINE__, __func__, __VA_ARGS__)
/* normal output */
#define UT_OUT(...)\
ut_out(__FILE__, __LINE__, __func__, __VA_ARGS__)
/* error output */
#define UT_ERR(...)\
ut_err(__FILE__, __LINE__, __func__, __VA_ARGS__)
/*
* assertions...
*/
/* assert a condition is true at runtime */
#define UT_ASSERT_rt(cnd)\
((void)((cnd) || (ut_fatal(__FILE__, __LINE__, __func__,\
"assertion failure: %s", #cnd), 0)))
/* assertion with extra info printed if assertion fails at runtime */
#define UT_ASSERTinfo_rt(cnd, info) \
((void)((cnd) || (ut_fatal(__FILE__, __LINE__, __func__,\
"assertion failure: %s (%s)", #cnd, info), 0)))
/* assert two integer values are equal at runtime */
#define UT_ASSERTeq_rt(lhs, rhs)\
((void)(((lhs) == (rhs)) || (ut_fatal(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)), 0)))
/* assert two integer values are not equal at runtime */
#define UT_ASSERTne_rt(lhs, rhs)\
((void)(((lhs) != (rhs)) || (ut_fatal(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)), 0)))
#if defined(__CHECKER__)
#define UT_COMPILE_ERROR_ON(cond)
#define UT_ASSERT_COMPILE_ERROR_ON(cond)
#elif defined(_MSC_VER)
#define UT_COMPILE_ERROR_ON(cond) C_ASSERT(!(cond))
/* XXX - can't be done with C_ASSERT() unless we have __builtin_constant_p() */
#define UT_ASSERT_COMPILE_ERROR_ON(cond) (void)(cond)
#else
#define UT_COMPILE_ERROR_ON(cond) ((void)sizeof(char[(cond) ? -1 : 1]))
#ifndef __cplusplus
#define UT_ASSERT_COMPILE_ERROR_ON(cond) UT_COMPILE_ERROR_ON(cond)
#else /* __cplusplus */
/*
* XXX - workaround for https://github.com/pmem/issues/issues/189
*/
#define UT_ASSERT_COMPILE_ERROR_ON(cond) UT_ASSERT_rt(!(cond))
#endif /* __cplusplus */
#endif /* _MSC_VER */
/* assert a condition is true */
#define UT_ASSERT(cnd)\
do {\
/*\
* Detect useless asserts on always true expression. Please use\
* UT_COMPILE_ERROR_ON(!cnd) or UT_ASSERT_rt(cnd) in such\
* cases.\
*/\
if (__builtin_constant_p(cnd))\
UT_ASSERT_COMPILE_ERROR_ON(cnd);\
UT_ASSERT_rt(cnd);\
} while (0)
/* assertion with extra info printed if assertion fails */
#define UT_ASSERTinfo(cnd, info) \
do {\
/* See comment in UT_ASSERT. */\
if (__builtin_constant_p(cnd))\
UT_ASSERT_COMPILE_ERROR_ON(cnd);\
UT_ASSERTinfo_rt(cnd, info);\
} while (0)
/* assert two integer values are equal */
#define UT_ASSERTeq(lhs, rhs)\
do {\
/* See comment in UT_ASSERT. */\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
UT_ASSERT_COMPILE_ERROR_ON((lhs) == (rhs));\
UT_ASSERTeq_rt(lhs, rhs);\
} while (0)
/* assert two integer values are not equal */
#define UT_ASSERTne(lhs, rhs)\
do {\
/* See comment in UT_ASSERT. */\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
UT_ASSERT_COMPILE_ERROR_ON((lhs) != (rhs));\
UT_ASSERTne_rt(lhs, rhs);\
} while (0)
/* assert pointer is fits range of [start, start + size) */
#define UT_ASSERTrange(ptr, start, size)\
((void)(((uintptr_t)(ptr) >= (uintptr_t)(start) &&\
(uintptr_t)(ptr) < (uintptr_t)(start) + (uintptr_t)(size)) ||\
(ut_fatal(__FILE__, __LINE__, __func__,\
"assert failure: %s (%p) is outside range [%s (%p), %s (%p))", #ptr,\
(void *)(ptr), #start, (void *)(start), #start"+"#size,\
(void *)((uintptr_t)(start) + (uintptr_t)(size))), 0)))
/*
* memory allocation...
*/
void *ut_malloc(const char *file, int line, const char *func, size_t size);
void *ut_calloc(const char *file, int line, const char *func,
size_t nmemb, size_t size);
void ut_free(const char *file, int line, const char *func, void *ptr);
void ut_aligned_free(const char *file, int line, const char *func, void *ptr);
void *ut_realloc(const char *file, int line, const char *func,
void *ptr, size_t size);
char *ut_strdup(const char *file, int line, const char *func,
const char *str);
void *ut_pagealignmalloc(const char *file, int line, const char *func,
size_t size);
void *ut_memalign(const char *file, int line, const char *func,
size_t alignment, size_t size);
void *ut_mmap_anon_aligned(const char *file, int line, const char *func,
size_t alignment, size_t size);
int ut_munmap_anon_aligned(const char *file, int line, const char *func,
void *start, size_t size);
/* a malloc() that can't return NULL */
#define MALLOC(size)\
ut_malloc(__FILE__, __LINE__, __func__, size)
/* a calloc() that can't return NULL */
#define CALLOC(nmemb, size)\
ut_calloc(__FILE__, __LINE__, __func__, nmemb, size)
/* a malloc() of zeroed memory */
#define ZALLOC(size)\
ut_calloc(__FILE__, __LINE__, __func__, 1, size)
#define FREE(ptr)\
ut_free(__FILE__, __LINE__, __func__, ptr)
#define ALIGNED_FREE(ptr)\
ut_aligned_free(__FILE__, __LINE__, __func__, ptr)
/* a realloc() that can't return NULL */
#define REALLOC(ptr, size)\
ut_realloc(__FILE__, __LINE__, __func__, ptr, size)
/* a strdup() that can't return NULL */
#define STRDUP(str)\
ut_strdup(__FILE__, __LINE__, __func__, str)
/* a malloc() that only returns page aligned memory */
#define PAGEALIGNMALLOC(size)\
ut_pagealignmalloc(__FILE__, __LINE__, __func__, size)
/* a malloc() that returns memory with given alignment */
#define MEMALIGN(alignment, size)\
ut_memalign(__FILE__, __LINE__, __func__, alignment, size)
/*
* A mmap() that returns anonymous memory with given alignment and guard
* pages.
*/
#define MMAP_ANON_ALIGNED(size, alignment)\
ut_mmap_anon_aligned(__FILE__, __LINE__, __func__, alignment, size)
#define MUNMAP_ANON_ALIGNED(start, size)\
ut_munmap_anon_aligned(__FILE__, __LINE__, __func__, start, size)
/*
* file operations
*/
int ut_open(const char *file, int line, const char *func, const char *path,
int flags, ...);
int ut_wopen(const char *file, int line, const char *func, const wchar_t *path,
int flags, ...);
int ut_close(const char *file, int line, const char *func, int fd);
FILE *ut_fopen(const char *file, int line, const char *func, const char *path,
const char *mode);
int ut_fclose(const char *file, int line, const char *func, FILE *stream);
int ut_unlink(const char *file, int line, const char *func, const char *path);
size_t ut_write(const char *file, int line, const char *func, int fd,
const void *buf, size_t len);
size_t ut_read(const char *file, int line, const char *func, int fd,
void *buf, size_t len);
os_off_t ut_lseek(const char *file, int line, const char *func, int fd,
os_off_t offset, int whence);
int ut_posix_fallocate(const char *file, int line, const char *func, int fd,
os_off_t offset, os_off_t len);
int ut_stat(const char *file, int line, const char *func, const char *path,
os_stat_t *st_bufp);
int ut_statW(const char *file, int line, const char *func, const wchar_t *path,
os_stat_t *st_bufp);
int ut_fstat(const char *file, int line, const char *func, int fd,
os_stat_t *st_bufp);
void *ut_mmap(const char *file, int line, const char *func, void *addr,
size_t length, int prot, int flags, int fd, os_off_t offset);
int ut_munmap(const char *file, int line, const char *func, void *addr,
size_t length);
int ut_mprotect(const char *file, int line, const char *func, void *addr,
size_t len, int prot);
int ut_ftruncate(const char *file, int line, const char *func,
int fd, os_off_t length);
long long ut_strtoll(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
long ut_strtol(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
int ut_strtoi(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
unsigned long long ut_strtoull(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
unsigned long ut_strtoul(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
unsigned ut_strtou(const char *file, int line, const char *func,
const char *nptr, char **endptr, int base);
int ut_snprintf(const char *file, int line, const char *func,
char *str, size_t size, const char *format, ...);
/* an open() that can't return < 0 */
#define OPEN(path, ...)\
ut_open(__FILE__, __LINE__, __func__, path, __VA_ARGS__)
/* a _wopen() that can't return < 0 */
#define WOPEN(path, ...)\
ut_wopen(__FILE__, __LINE__, __func__, path, __VA_ARGS__)
/* a close() that can't return -1 */
#define CLOSE(fd)\
ut_close(__FILE__, __LINE__, __func__, fd)
/* an fopen() that can't return != 0 */
#define FOPEN(path, mode)\
ut_fopen(__FILE__, __LINE__, __func__, path, mode)
/* a fclose() that can't return != 0 */
#define FCLOSE(stream)\
ut_fclose(__FILE__, __LINE__, __func__, stream)
/* an unlink() that can't return -1 */
#define UNLINK(path)\
ut_unlink(__FILE__, __LINE__, __func__, path)
/* a write() that can't return -1 */
#define WRITE(fd, buf, len)\
ut_write(__FILE__, __LINE__, __func__, fd, buf, len)
/* a read() that can't return -1 */
#define READ(fd, buf, len)\
ut_read(__FILE__, __LINE__, __func__, fd, buf, len)
/* a lseek() that can't return -1 */
#define LSEEK(fd, offset, whence)\
ut_lseek(__FILE__, __LINE__, __func__, fd, offset, whence)
#define POSIX_FALLOCATE(fd, off, len)\
ut_posix_fallocate(__FILE__, __LINE__, __func__, fd, off, len)
#define FSTAT(fd, st_bufp)\
ut_fstat(__FILE__, __LINE__, __func__, fd, st_bufp)
/* a mmap() that can't return MAP_FAILED */
#define MMAP(addr, len, prot, flags, fd, offset)\
ut_mmap(__FILE__, __LINE__, __func__, addr, len, prot, flags, fd, offset);
/* a munmap() that can't return -1 */
#define MUNMAP(addr, length)\
ut_munmap(__FILE__, __LINE__, __func__, addr, length);
/* a mprotect() that can't return -1 */
#define MPROTECT(addr, len, prot)\
ut_mprotect(__FILE__, __LINE__, __func__, addr, len, prot);
#define STAT(path, st_bufp)\
ut_stat(__FILE__, __LINE__, __func__, path, st_bufp)
#define STATW(path, st_bufp)\
ut_statW(__FILE__, __LINE__, __func__, path, st_bufp)
#define FTRUNCATE(fd, length)\
ut_ftruncate(__FILE__, __LINE__, __func__, fd, length)
#define ATOU(nptr) STRTOU(nptr, NULL, 10)
#define ATOUL(nptr) STRTOUL(nptr, NULL, 10)
#define ATOULL(nptr) STRTOULL(nptr, NULL, 10)
#define ATOI(nptr) STRTOI(nptr, NULL, 10)
#define ATOL(nptr) STRTOL(nptr, NULL, 10)
#define ATOLL(nptr) STRTOLL(nptr, NULL, 10)
#define STRTOULL(nptr, endptr, base)\
ut_strtoull(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define STRTOUL(nptr, endptr, base)\
ut_strtoul(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define STRTOL(nptr, endptr, base)\
ut_strtol(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define STRTOLL(nptr, endptr, base)\
ut_strtoll(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define STRTOU(nptr, endptr, base)\
ut_strtou(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define STRTOI(nptr, endptr, base)\
ut_strtoi(__FILE__, __LINE__, __func__, nptr, endptr, base)
#define SNPRINTF(str, size, format, ...) \
ut_snprintf(__FILE__, __LINE__, __func__, \
str, size, format, __VA_ARGS__)
#ifndef _WIN32
#define ut_jmp_buf_t sigjmp_buf
#define ut_siglongjmp(b) siglongjmp(b, 1)
#define ut_sigsetjmp(b) sigsetjmp(b, 1)
#else
#define ut_jmp_buf_t jmp_buf
#define ut_siglongjmp(b) longjmp(b, 1)
#define ut_sigsetjmp(b) setjmp(b)
#endif
void ut_suppress_errmsg(void);
void ut_unsuppress_errmsg(void);
void ut_suppress_crt_assert(void);
void ut_unsuppress_crt_assert(void);
/*
* signals...
*/
int ut_sigaction(const char *file, int line, const char *func,
int signum, struct sigaction *act, struct sigaction *oldact);
/* a sigaction() that can't return an error */
#define SIGACTION(signum, act, oldact)\
ut_sigaction(__FILE__, __LINE__, __func__, signum, act, oldact)
/*
* pthreads...
*/
int ut_thread_create(const char *file, int line, const char *func,
os_thread_t *__restrict thread,
const os_thread_attr_t *__restrict attr,
void *(*start_routine)(void *), void *__restrict arg);
int ut_thread_join(const char *file, int line, const char *func,
os_thread_t *thread, void **value_ptr);
/* a os_thread_create() that can't return an error */
#define THREAD_CREATE(thread, attr, start_routine, arg)\
ut_thread_create(__FILE__, __LINE__, __func__,\
thread, attr, start_routine, arg)
/* a os_thread_join() that can't return an error */
#define THREAD_JOIN(thread, value_ptr)\
ut_thread_join(__FILE__, __LINE__, __func__, thread, value_ptr)
/*
* processes...
*/
#ifdef _WIN32
intptr_t ut_spawnv(int argc, const char **argv, ...);
#endif
/*
* mocks...
*
* NOTE: On Linux, function mocking is implemented using wrapper functions.
* See "--wrap" option of the GNU linker.
* There is no such feature in VC++, so on Windows we do the mocking at
* compile time, by redefining symbol names:
* - all the references to <symbol> are replaced with <__wrap_symbol>
* in all the compilation units, except the one where the <symbol> is
* defined and the test source file
* - the original definition of <symbol> is replaced with <__real_symbol>
* - a wrapper function <__wrap_symbol> must be defined in the test program
* (it may still call the original function via <__real_symbol>)
* Such solution seems to be sufficient for the purpose of our tests, even
* though it has some limitations. I.e. it does no work well with malloc/free,
* so to wrap the system memory allocator functions, we use the built-in
* feature of all the PMDK libraries, allowing to override default memory
* allocator with the custom one.
*/
#ifndef _WIN32
#define _FUNC_REAL_DECL(name, ret_type, ...)\
ret_type __real_##name(__VA_ARGS__) __attribute__((unused));
#else
#define _FUNC_REAL_DECL(name, ret_type, ...)\
ret_type name(__VA_ARGS__);
#endif
#ifndef _WIN32
#define _FUNC_REAL(name)\
__real_##name
#else
#define _FUNC_REAL(name)\
name
#endif
#define RCOUNTER(name)\
_rcounter##name
#define FUNC_MOCK_RCOUNTER_SET(name, val)\
RCOUNTER(name) = val;
#define FUNC_MOCK(name, ret_type, ...)\
_FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\
static unsigned RCOUNTER(name);\
ret_type __wrap_##name(__VA_ARGS__);\
ret_type __wrap_##name(__VA_ARGS__) {\
switch (util_fetch_and_add32(&RCOUNTER(name), 1)) {
#define FUNC_MOCK_DLLIMPORT(name, ret_type, ...)\
__declspec(dllimport) _FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\
static unsigned RCOUNTER(name);\
ret_type __wrap_##name(__VA_ARGS__);\
ret_type __wrap_##name(__VA_ARGS__) {\
switch (util_fetch_and_add32(&RCOUNTER(name), 1)) {
#define FUNC_MOCK_END\
}}
#define FUNC_MOCK_RUN(run)\
case run:
#define FUNC_MOCK_RUN_DEFAULT\
default:
#define FUNC_MOCK_RUN_RET(run, ret)\
case run: return (ret);
#define FUNC_MOCK_RUN_RET_DEFAULT_REAL(name, ...)\
default: return _FUNC_REAL(name)(__VA_ARGS__);
#define FUNC_MOCK_RUN_RET_DEFAULT(ret)\
default: return (ret);
#define FUNC_MOCK_RET_ALWAYS(name, ret_type, ret, ...)\
FUNC_MOCK(name, ret_type, __VA_ARGS__)\
FUNC_MOCK_RUN_RET_DEFAULT(ret);\
FUNC_MOCK_END
#define FUNC_MOCK_RET_ALWAYS_VOID(name, ...)\
FUNC_MOCK(name, void, __VA_ARGS__)\
default: return;\
FUNC_MOCK_END
extern unsigned long Ut_pagesize;
extern unsigned long long Ut_mmap_align;
extern os_mutex_t Sigactions_lock;
void ut_dump_backtrace(void);
void ut_sighandler(int);
void ut_register_sighandlers(void);
uint16_t ut_checksum(uint8_t *addr, size_t len);
char *ut_toUTF8(const wchar_t *wstr);
wchar_t *ut_toUTF16(const char *wstr);
struct test_case {
const char *name;
int (*func)(const struct test_case *tc, int argc, char *argv[]);
};
/*
* get_tc -- return test case of specified name
*/
static inline const struct test_case *
get_tc(const char *name, const struct test_case *test_cases, size_t ntests)
{
for (size_t i = 0; i < ntests; i++) {
if (strcmp(name, test_cases[i].name) == 0)
return &test_cases[i];
}
return NULL;
}
static inline void
TEST_CASE_PROCESS(int argc, char *argv[],
const struct test_case *test_cases, size_t ntests)
{
if (argc < 2)
UT_FATAL("usage: %s <test case> [<args>]", argv[0]);
for (int i = 1; i < argc; i++) {
char *str_test = argv[i];
const int args_off = i + 1;
const struct test_case *tc = get_tc(str_test,
test_cases, ntests);
if (!tc)
UT_FATAL("unknown test case -- '%s'", str_test);
int ret = tc->func(tc, argc - args_off, &argv[args_off]);
if (ret < 0)
UT_FATAL("test return value cannot be negative");
i += ret;
}
}
#define TEST_CASE_DECLARE(_name)\
int \
_name(const struct test_case *tc, int argc, char *argv[])
#define TEST_CASE(_name)\
{\
.name = #_name,\
.func = (_name),\
}
#define STR(x) #x
#define ASSERT_ALIGNED_BEGIN(type) do {\
size_t off = 0;\
const char *last = "(none)";\
type t;
#define ASSERT_ALIGNED_FIELD(type, field) do {\
if (offsetof(type, field) != off)\
UT_FATAL("%s: padding, missing field or fields not in order between "\
"'%s' and '%s' -- offset %lu, real offset %lu",\
STR(type), last, STR(field), off, offsetof(type, field));\
off += sizeof(t.field);\
last = STR(field);\
} while (0)
#define ASSERT_FIELD_SIZE(field, size) do {\
UT_COMPILE_ERROR_ON(size != sizeof(t.field));\
} while (0)
#define ASSERT_OFFSET_CHECKPOINT(type, checkpoint) do {\
if (off != checkpoint)\
UT_FATAL("%s: violated offset checkpoint -- "\
"checkpoint %lu, real offset %lu",\
STR(type), checkpoint, off);\
} while (0)
#define ASSERT_ALIGNED_CHECK(type)\
if (off != sizeof(type))\
UT_FATAL("%s: missing field or padding after '%s': "\
"sizeof(%s) = %lu, fields size = %lu",\
STR(type), last, STR(type), sizeof(type), off);\
} while (0)
/*
* AddressSanitizer
*/
#ifdef __clang__
#if __has_feature(address_sanitizer)
#define UT_DEFINE_ASAN_POISON
#endif
#else
#ifdef __SANITIZE_ADDRESS__
#define UT_DEFINE_ASAN_POISON
#endif
#endif
#ifdef UT_DEFINE_ASAN_POISON
void __asan_poison_memory_region(void const volatile *addr, size_t size);
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
#define ASAN_POISON_MEMORY_REGION(addr, size) \
__asan_poison_memory_region((addr), (size))
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
__asan_unpoison_memory_region((addr), (size))
#else
#define ASAN_POISON_MEMORY_REGION(addr, size) \
((void)(addr), (void)(size))
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
((void)(addr), (void)(size))
#endif
#ifdef __cplusplus
}
#endif
#endif /* unittest.h */
| 23,907 | 29.769627 | 79 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* ut_pmem2.h -- utility helper functions for libpmem tests
*/
#ifndef UT_PMEM2_H
#define UT_PMEM2_H 1
#include "ut_pmem2_config.h"
#include "ut_pmem2_map.h"
#include "ut_pmem2_source.h"
#include "ut_pmem2_utils.h"
#endif /* UT_PMEM2_H */
| 333 | 18.647059 | 59 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_config.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* ut_pmem2_config.h -- utility helper functions for libpmem2 config tests
*/
#ifndef UT_PMEM2_CONFIG_H
#define UT_PMEM2_CONFIG_H 1
#include "ut_fh.h"
/* a pmem2_config_new() that can't return NULL */
#define PMEM2_CONFIG_NEW(cfg) \
ut_pmem2_config_new(__FILE__, __LINE__, __func__, cfg)
/* a pmem2_config_set_required_store_granularity() doesn't return an error */
#define PMEM2_CONFIG_SET_GRANULARITY(cfg, g) \
ut_pmem2_config_set_required_store_granularity \
(__FILE__, __LINE__, __func__, cfg, g)
/* a pmem2_config_delete() that can't return NULL */
#define PMEM2_CONFIG_DELETE(cfg) \
ut_pmem2_config_delete(__FILE__, __LINE__, __func__, cfg)
void ut_pmem2_config_new(const char *file, int line, const char *func,
struct pmem2_config **cfg);
void ut_pmem2_config_set_required_store_granularity(const char *file,
int line, const char *func, struct pmem2_config *cfg,
enum pmem2_granularity g);
void ut_pmem2_config_delete(const char *file, int line, const char *func,
struct pmem2_config **cfg);
#endif /* UT_PMEM2_CONFIG_H */
| 1,152 | 30.162162 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_utils.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019, Intel Corporation */
/*
* ut_pmem2_utils.h -- utility helper functions for libpmem2 tests
*/
#ifndef UT_PMEM2_UTILS_H
#define UT_PMEM2_UTILS_H 1
/* veryfies error code and prints appropriate error message in case of error */
#define UT_PMEM2_EXPECT_RETURN(value, expected) \
ut_pmem2_expect_return(__FILE__, __LINE__, __func__, \
value, expected)
void ut_pmem2_expect_return(const char *file, int line, const char *func,
int value, int expected);
#endif /* UT_PMEM2_UTILS_H */
| 552 | 26.65 | 79 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_fh.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* ut_fh.h -- OS-independent file handle / file descriptor interface
*/
#ifndef UT_FH_H
#define UT_FH_H
#include "os.h"
struct FHandle;
enum file_handle_type { FH_FD, FH_HANDLE };
#define FH_ACCMODE (7)
#define FH_READ (1 << 0)
#define FH_WRITE (1 << 1)
#define FH_RDWR (FH_READ | FH_WRITE)
#define FH_EXEC (1 << 2)
#define FH_CREAT (1 << 3)
#define FH_EXCL (1 << 4)
#define FH_TRUNC (1 << 5)
/* needs directory, on Windows it creates publicly visible file */
#define FH_TMPFILE (1 << 6)
#define FH_DIRECTORY (1 << 7)
#define UT_FH_OPEN(type, path, flags, ...) \
ut_fh_open(__FILE__, __LINE__, __func__, type, path, \
flags, ##__VA_ARGS__)
#define UT_FH_TRUNCATE(fhandle, size) \
ut_fh_truncate(__FILE__, __LINE__, __func__, fhandle, size)
#define UT_FH_GET_FD(fhandle) \
ut_fh_get_fd(__FILE__, __LINE__, __func__, fhandle)
#ifdef _WIN32
#define UT_FH_GET_HANDLE(fhandle) \
ut_fh_get_handle(__FILE__, __LINE__, __func__, fhandle)
#endif
#define UT_FH_CLOSE(fhandle) \
ut_fh_close(__FILE__, __LINE__, __func__, fhandle)
struct FHandle *ut_fh_open(const char *file, int line, const char *func,
enum file_handle_type type, const char *path, int flags, ...);
void ut_fh_truncate(const char *file, int line, const char *func,
struct FHandle *f, os_off_t length);
void ut_fh_close(const char *file, int line, const char *func,
struct FHandle *f);
enum file_handle_type ut_fh_get_handle_type(struct FHandle *fh);
int ut_fh_get_fd(const char *file, int line, const char *func,
struct FHandle *f);
#ifdef _WIN32
HANDLE ut_fh_get_handle(const char *file, int line, const char *func,
struct FHandle *f);
#endif
#endif
| 1,761 | 24.536232 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_map.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* ut_pmem2_map.h -- utility helper functions for libpmem2 map tests
*/
#ifndef UT_PMEM2_MAP_H
#define UT_PMEM2_MAP_H 1
/* a pmem2_map() that can't return NULL */
#define PMEM2_MAP(cfg, src, map) \
ut_pmem2_map(__FILE__, __LINE__, __func__, cfg, src, map)
void ut_pmem2_map(const char *file, int line, const char *func,
struct pmem2_config *cfg, struct pmem2_source *src,
struct pmem2_map **map);
#endif /* UT_PMEM2_MAP_H */
| 522 | 25.15 | 68 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_source.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* ut_pmem2_source.h -- utility helper functions for libpmem2 source tests
*/
#ifndef UT_PMEM2_SOURCE_H
#define UT_PMEM2_SOURCE_H 1
#include "ut_fh.h"
/* a pmem2_config_set_fd() that can't return NULL */
#define PMEM2_SOURCE_FROM_FD(src, fd) \
ut_pmem2_source_from_fd(__FILE__, __LINE__, __func__, src, fd)
/* a pmem2_config_set_fd() that can't return NULL */
#define PMEM2_SOURCE_FROM_FH(src, fh) \
ut_pmem2_source_from_fh(__FILE__, __LINE__, __func__, src, fh)
/* a pmem2_source_alignment() that can't return an error */
#define PMEM2_SOURCE_ALIGNMENT(src, al) \
ut_pmem2_source_alignment(__FILE__, __LINE__, __func__, src, al)
/* a pmem2_source_delete() that can't return NULL */
#define PMEM2_SOURCE_DELETE(src) \
ut_pmem2_source_delete(__FILE__, __LINE__, __func__, src)
/* a pmem2_source_source() that can't return NULL */
#define PMEM2_SOURCE_SIZE(src, size) \
ut_pmem2_source_size(__FILE__, __LINE__, __func__, src, size)
void ut_pmem2_source_from_fd(const char *file, int line, const char *func,
struct pmem2_source **src, int fd);
void ut_pmem2_source_from_fh(const char *file, int line, const char *func,
struct pmem2_source **src, struct FHandle *fhandle);
void ut_pmem2_source_alignment(const char *file, int line, const char *func,
struct pmem2_source *src, size_t *alignment);
void ut_pmem2_source_delete(const char *file, int line, const char *func,
struct pmem2_source **src);
void ut_pmem2_source_size(const char *file, int line, const char *func,
struct pmem2_source *src, size_t *size);
#endif /* UT_PMEM2_SOURCE_H */
| 1,667 | 33.040816 | 76 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_setup.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* ut_pmem2_setup.h -- libpmem2 setup functions using non-public API
* (only for unit tests)
*/
#ifndef UT_PMEM2_SETUP_H
#define UT_PMEM2_SETUP_H 1
#include "ut_fh.h"
void ut_pmem2_prepare_config(struct pmem2_config *cfg,
struct pmem2_source **src, struct FHandle **fh,
enum file_handle_type fh_type, const char *path, size_t length,
size_t offset, int access);
#endif /* UT_PMEM2_SETUP_H */
| 486 | 23.35 | 68 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/unittest.sh | #
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2014-2020, 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.
#
set -e
# make sure we have a well defined locale for string operations here
export LC_ALL="C"
#export LC_ALL="en_US.UTF-8"
if ! [ -f ../envconfig.sh ]; then
echo >&2 "envconfig.sh is missing -- is the tree built?"
exit 1
fi
. ../testconfig.sh
. ../envconfig.sh
if [ -t 1 ]; then
IS_TERMINAL_STDOUT=YES
fi
if [ -t 2 ]; then
IS_TERMINAL_STDERR=YES
fi
function is_terminal() {
local fd
fd=$1
case $(eval "echo \${IS_TERMINAL_${fd}}") in
YES) : ;;
*) false ;;
esac
}
function interactive_color() {
local color fd
color=$1
fd=$2
shift 2
if is_terminal ${fd} && command -v tput >/dev/null; then
echo "$(tput setaf $color || :)$*$(tput sgr0 || :)"
else
echo "$*"
fi
}
function interactive_red() {
interactive_color 1 "$@"
}
function interactive_green() {
interactive_color 2 "$@"
}
function verbose_msg() {
if [ "$UNITTEST_LOG_LEVEL" -ge 2 ]; then
echo "$*"
fi
}
function msg() {
if [ "$UNITTEST_LOG_LEVEL" -ge 1 ]; then
echo "$*"
fi
}
function fatal() {
echo "$*" >&2
exit 1
}
if [ -z "${UNITTEST_NAME}" ]; then
CURDIR=$(basename $(pwd))
SCRIPTNAME=$(basename $0)
export UNITTEST_NAME=$CURDIR/$SCRIPTNAME
export UNITTEST_NUM=$(echo $SCRIPTNAME | sed "s/TEST//")
fi
# defaults
[ "$UNITTEST_LOG_LEVEL" ] || UNITTEST_LOG_LEVEL=2
[ "$GREP" ] || GREP="grep -a"
[ "$TEST" ] || TEST=check
[ "$FS" ] || FS=any
[ "$BUILD" ] || BUILD=debug
[ "$CHECK_TYPE" ] || CHECK_TYPE=auto
[ "$CHECK_POOL" ] || CHECK_POOL=0
[ "$VERBOSE" ] || VERBOSE=0
[ -n "${SUFFIX+x}" ] || SUFFIX="😘⠏⠍⠙⠅ɗPMDKӜ⥺🙋"
export UNITTEST_LOG_LEVEL GREP TEST FS BUILD CHECK_TYPE CHECK_POOL VERBOSE SUFFIX
TOOLS=../tools
LIB_TOOLS="../../tools"
# Paths to some useful tools
[ "$PMEMPOOL" ] || PMEMPOOL=$LIB_TOOLS/pmempool/pmempool
[ "$DAXIO" ] || DAXIO=$LIB_TOOLS/daxio/daxio
[ "$PMEMSPOIL" ] || PMEMSPOIL=$TOOLS/pmemspoil/pmemspoil.static-nondebug
[ "$BTTCREATE" ] || BTTCREATE=$TOOLS/bttcreate/bttcreate.static-nondebug
[ "$PMEMWRITE" ] || PMEMWRITE=$TOOLS/pmemwrite/pmemwrite
[ "$PMEMALLOC" ] || PMEMALLOC=$TOOLS/pmemalloc/pmemalloc
[ "$PMEMOBJCLI" ] || PMEMOBJCLI=$TOOLS/pmemobjcli/pmemobjcli
[ "$PMEMDETECT" ] || PMEMDETECT=$TOOLS/pmemdetect/pmemdetect.static-nondebug
[ "$PMREORDER" ] || PMREORDER=$LIB_TOOLS/pmreorder/pmreorder.py
[ "$FIP" ] || FIP=$TOOLS/fip/fip
[ "$DDMAP" ] || DDMAP=$TOOLS/ddmap/ddmap
[ "$CMPMAP" ] || CMPMAP=$TOOLS/cmpmap/cmpmap
[ "$EXTENTS" ] || EXTENTS=$TOOLS/extents/extents
[ "$FALLOCATE_DETECT" ] || FALLOCATE_DETECT=$TOOLS/fallocate_detect/fallocate_detect.static-nondebug
[ "$OBJ_VERIFY" ] || OBJ_VERIFY=$TOOLS/obj_verify/obj_verify
[ "$USC_PERMISSION" ] || USC_PERMISSION=$TOOLS/usc_permission_check/usc_permission_check.static-nondebug
[ "$ANONYMOUS_MMAP" ] || ANONYMOUS_MMAP=$TOOLS/anonymous_mmap/anonymous_mmap.static-nondebug
# force globs to fail if they don't match
shopt -s failglob
# number of remote nodes required in the current unit test
NODES_MAX=-1
# sizes of alignments
SIZE_4KB=4096
SIZE_2MB=2097152
readonly PAGE_SIZE=$(getconf PAGESIZE)
# PMEMOBJ limitations
PMEMOBJ_MAX_ALLOC_SIZE=17177771968
# SSH and SCP options
SSH_OPTS="-o BatchMode=yes"
SCP_OPTS="-o BatchMode=yes -r -p"
NDCTL_MIN_VERSION="63"
# list of common files to be copied to all remote nodes
DIR_SRC="../.."
FILES_COMMON_DIR="\
$DIR_SRC/test/*.supp \
$DIR_SRC/tools/rpmemd/rpmemd \
$DIR_SRC/tools/pmempool/pmempool \
$DIR_SRC/test/tools/extents/extents \
$DIR_SRC/test/tools/obj_verify/obj_verify \
$DIR_SRC/test/tools/ctrld/ctrld \
$DIR_SRC/test/tools/fip/fip"
# Portability
VALGRIND_SUPP="--suppressions=../ld.supp \
--suppressions=../memcheck-libunwind.supp \
--suppressions=../memcheck-ndctl.supp"
if [ "$(uname -s)" = "FreeBSD" ]; then
DATE="gdate"
DD="gdd"
FALLOCATE="mkfile"
VM_OVERCOMMIT="[ $(sysctl vm.overcommit | awk '{print $2}') == 0 ]"
RM_ONEFS="-x"
STAT_MODE="-f%Lp"
STAT_PERM="-f%Sp"
STAT_SIZE="-f%z"
STRACE="truss"
VALGRIND_SUPP="$VALGRIND_SUPP --suppressions=../freebsd.supp"
else
DATE="date"
DD="dd"
FALLOCATE="fallocate -l"
VM_OVERCOMMIT="[ $(cat /proc/sys/vm/overcommit_memory) != 2 ]"
RM_ONEFS="--one-file-system"
STAT_MODE="-c%a"
STAT_PERM="-c%A"
STAT_SIZE="-c%s"
STRACE="strace"
fi
# array of lists of PID files to be cleaned in case of an error
NODE_PID_FILES[0]=""
case "$BUILD"
in
debug|static-debug)
if [ -z "$PMDK_LIB_PATH_DEBUG" ]; then
PMDK_LIB_PATH=../../debug
REMOTE_PMDK_LIB_PATH=../debug
else
PMDK_LIB_PATH=$PMDK_LIB_PATH_DEBUG
REMOTE_PMDK_LIB_PATH=$PMDK_LIB_PATH_DEBUG
fi
;;
nondebug|static-nondebug)
if [ -z "$PMDK_LIB_PATH_NONDEBUG" ]; then
PMDK_LIB_PATH=../../nondebug
REMOTE_PMDK_LIB_PATH=../nondebug
else
PMDK_LIB_PATH=$PMDK_LIB_PATH_NONDEBUG
REMOTE_PMDK_LIB_PATH=$PMDK_LIB_PATH_NONDEBUG
fi
;;
esac
export LD_LIBRARY_PATH=$PMDK_LIB_PATH:$GLOBAL_LIB_PATH:$LD_LIBRARY_PATH
export REMOTE_LD_LIBRARY_PATH=$REMOTE_PMDK_LIB_PATH:$GLOBAL_LIB_PATH:\$LD_LIBRARY_PATH
export PATH=$GLOBAL_PATH:$PATH
export REMOTE_PATH=$GLOBAL_PATH:\$PATH
export PKG_CONFIG_PATH=$GLOBAL_PKG_CONFIG_PATH:$PKG_CONFIG_PATH
export REMOTE_PKG_CONFIG_PATH=$GLOBAL_PKG_CONFIG_PATH:\$PKG_CONFIG_PATH
#
# When running static binary tests, append the build type to the binary
#
case "$BUILD"
in
static-*)
EXESUFFIX=.$BUILD
;;
esac
#
# The variable DIR is constructed so the test uses that directory when
# constructing test files. DIR is chosen based on the fs-type for
# this test, and if the appropriate fs-type doesn't have a directory
# defined in testconfig.sh, the test is skipped.
#
# This behavior can be overridden by setting DIR. For example:
# DIR=/force/test/dir ./TEST0
#
curtestdir=`basename $PWD`
# just in case
if [ ! "$curtestdir" ]; then
fatal "curtestdir does not have a value"
fi
curtestdir=test_$curtestdir
if [ ! "$UNITTEST_NUM" ]; then
fatal "UNITTEST_NUM does not have a value"
fi
if [ ! "$UNITTEST_NAME" ]; then
fatal "UNITTEST_NAME does not have a value"
fi
REAL_FS=$FS
if [ "$DIR" ]; then
DIR=$DIR/$curtestdir$UNITTEST_NUM
else
case "$FS"
in
pmem)
# if a variable is set - it must point to a valid directory
if [ "$PMEM_FS_DIR" == "" ]; then
fatal "$UNITTEST_NAME: PMEM_FS_DIR is not set"
fi
DIR=$PMEM_FS_DIR/$DIRSUFFIX/$curtestdir$UNITTEST_NUM
if [ "$PMEM_FS_DIR_FORCE_PMEM" = "1" ] || [ "$PMEM_FS_DIR_FORCE_PMEM" = "2" ]; then
export PMEM_IS_PMEM_FORCE=1
fi
;;
non-pmem)
# if a variable is set - it must point to a valid directory
if [ "$NON_PMEM_FS_DIR" == "" ]; then
fatal "$UNITTEST_NAME: NON_PMEM_FS_DIR is not set"
fi
DIR=$NON_PMEM_FS_DIR/$DIRSUFFIX/$curtestdir$UNITTEST_NUM
;;
any)
if [ "$PMEM_FS_DIR" != "" ]; then
DIR=$PMEM_FS_DIR/$DIRSUFFIX/$curtestdir$UNITTEST_NUM
REAL_FS=pmem
if [ "$PMEM_FS_DIR_FORCE_PMEM" = "1" ] || [ "$PMEM_FS_DIR_FORCE_PMEM" = "2" ]; then
export PMEM_IS_PMEM_FORCE=1
fi
elif [ "$NON_PMEM_FS_DIR" != "" ]; then
DIR=$NON_PMEM_FS_DIR/$DIRSUFFIX/$curtestdir$UNITTEST_NUM
REAL_FS=non-pmem
else
fatal "$UNITTEST_NAME: fs-type=any and both env vars are empty"
fi
;;
none)
DIR=/dev/null/not_existing_dir/$DIRSUFFIX/$curtestdir$UNITTEST_NUM
;;
*)
verbose_msg "$UNITTEST_NAME: SKIP fs-type $FS (not configured)"
exit 0
;;
esac
fi
#
# The default is to turn on library logging to level 3 and save it to local files.
# Tests that don't want it on, should override these environment variables.
#
export PMEM_LOG_LEVEL=3
export PMEM_LOG_FILE=pmem$UNITTEST_NUM.log
export PMEMBLK_LOG_LEVEL=3
export PMEMBLK_LOG_FILE=pmemblk$UNITTEST_NUM.log
export PMEMLOG_LOG_LEVEL=3
export PMEMLOG_LOG_FILE=pmemlog$UNITTEST_NUM.log
export PMEMOBJ_LOG_LEVEL=3
export PMEMOBJ_LOG_FILE=pmemobj$UNITTEST_NUM.log
export PMEMPOOL_LOG_LEVEL=3
export PMEMPOOL_LOG_FILE=pmempool$UNITTEST_NUM.log
export PMREORDER_LOG_FILE=pmreorder$UNITTEST_NUM.log
export OUT_LOG_FILE=out$UNITTEST_NUM.log
export ERR_LOG_FILE=err$UNITTEST_NUM.log
export TRACE_LOG_FILE=trace$UNITTEST_NUM.log
export PREP_LOG_FILE=prep$UNITTEST_NUM.log
export VALGRIND_LOG_FILE=${CHECK_TYPE}${UNITTEST_NUM}.log
export VALIDATE_VALGRIND_LOG=1
export RPMEM_LOG_LEVEL=3
export RPMEM_LOG_FILE=rpmem$UNITTEST_NUM.log
export RPMEMD_LOG_LEVEL=info
export RPMEMD_LOG_FILE=rpmemd$UNITTEST_NUM.log
export REMOTE_VARS="
RPMEMD_LOG_FILE
RPMEMD_LOG_LEVEL
RPMEM_LOG_FILE
RPMEM_LOG_LEVEL
PMEM_LOG_FILE
PMEM_LOG_LEVEL
PMEMOBJ_LOG_FILE
PMEMOBJ_LOG_LEVEL
PMEMPOOL_LOG_FILE
PMEMPOOL_LOG_LEVEL"
[ "$UT_DUMP_LINES" ] || UT_DUMP_LINES=30
export CHECK_POOL_LOG_FILE=check_pool_${BUILD}_${UNITTEST_NUM}.log
# In case a lock is required for Device DAXes
DEVDAX_LOCK=../devdax.lock
#
# store_exit_on_error -- store on a stack a sign that reflects the current state
# of the 'errexit' shell option
#
function store_exit_on_error() {
if [ "${-#*e}" != "$-" ]; then
estack+=-
else
estack+=+
fi
}
#
# restore_exit_on_error -- restore the state of the 'errexit' shell option
#
function restore_exit_on_error() {
if [ -z $estack ]; then
fatal "error: store_exit_on_error function has to be called first"
fi
eval "set ${estack:${#estack}-1:1}e"
estack=${estack%?}
}
#
# disable_exit_on_error -- store the state of the 'errexit' shell option and
# disable it
#
function disable_exit_on_error() {
store_exit_on_error
set +e
}
#
# get_files -- print list of files in the current directory matching the given regex to stdout
#
# This function has been implemented to workaround a race condition in
# `find`, which fails if any file disappears in the middle of the operation.
#
# example, to list all *.log files in the current directory
# get_files ".*\.log"
function get_files() {
disable_exit_on_error
ls -1 | grep -E "^$*$"
restore_exit_on_error
}
#
# get_executables -- print list of executable files in the current directory to stdout
#
# This function has been implemented to workaround a race condition in
# `find`, which fails if any file disappears in the middle of the operation.
#
function get_executables() {
disable_exit_on_error
for c in *
do
if [ -f $c -a -x $c ]
then
echo "$c"
fi
done
restore_exit_on_error
}
#
# convert_to_bytes -- converts the string with K, M, G or T suffixes
# to bytes
#
# example:
# "1G" --> "1073741824"
# "2T" --> "2199023255552"
# "3k" --> "3072"
# "1K" --> "1024"
# "10" --> "10"
#
function convert_to_bytes() {
size="$(echo $1 | tr '[:upper:]' '[:lower:]')"
if [[ $size == *kib ]]
then size=$(($(echo $size | tr -d 'kib') * 1024))
elif [[ $size == *mib ]]
then size=$(($(echo $size | tr -d 'mib') * 1024 * 1024))
elif [[ $size == *gib ]]
then size=$(($(echo $size | tr -d 'gib') * 1024 * 1024 * 1024))
elif [[ $size == *tib ]]
then size=$(($(echo $size | tr -d 'tib') * 1024 * 1024 * 1024 * 1024))
elif [[ $size == *pib ]]
then size=$(($(echo $size | tr -d 'pib') * 1024 * 1024 * 1024 * 1024 * 1024))
elif [[ $size == *kb ]]
then size=$(($(echo $size | tr -d 'kb') * 1000))
elif [[ $size == *mb ]]
then size=$(($(echo $size | tr -d 'mb') * 1000 * 1000))
elif [[ $size == *gb ]]
then size=$(($(echo $size | tr -d 'gb') * 1000 * 1000 * 1000))
elif [[ $size == *tb ]]
then size=$(($(echo $size | tr -d 'tb') * 1000 * 1000 * 1000 * 1000))
elif [[ $size == *pb ]]
then size=$(($(echo $size | tr -d 'pb') * 1000 * 1000 * 1000 * 1000 * 1000))
elif [[ $size == *b ]]
then size=$(($(echo $size | tr -d 'b')))
elif [[ $size == *k ]]
then size=$(($(echo $size | tr -d 'k') * 1024))
elif [[ $size == *m ]]
then size=$(($(echo $size | tr -d 'm') * 1024 * 1024))
elif [[ $size == *g ]]
then size=$(($(echo $size | tr -d 'g') * 1024 * 1024 * 1024))
elif [[ $size == *t ]]
then size=$(($(echo $size | tr -d 't') * 1024 * 1024 * 1024 * 1024))
elif [[ $size == *p ]]
then size=$(($(echo $size | tr -d 'p') * 1024 * 1024 * 1024 * 1024 * 1024))
fi
echo "$size"
}
#
# create_file -- create zeroed out files of a given length
#
# example, to create two files, each 1GB in size:
# create_file 1G testfile1 testfile2
#
function create_file() {
size=$(convert_to_bytes $1)
shift
for file in $*
do
$DD if=/dev/zero of=$file bs=1M count=$size iflag=count_bytes status=none >> $PREP_LOG_FILE
done
}
#
# create_nonzeroed_file -- create non-zeroed files of a given length
#
# A given first kilobytes of the file is zeroed out.
#
# example, to create two files, each 1GB in size, with first 4K zeroed
# create_nonzeroed_file 1G 4K testfile1 testfile2
#
function create_nonzeroed_file() {
offset=$(convert_to_bytes $2)
size=$(($(convert_to_bytes $1) - $offset))
shift 2
for file in $*
do
truncate -s ${offset} $file >> $PREP_LOG_FILE
$DD if=/dev/zero bs=1K count=${size} iflag=count_bytes 2>>$PREP_LOG_FILE | tr '\0' '\132' >> $file
done
}
#
# create_holey_file -- create holey files of a given length
#
# examples:
# create_holey_file 1024k testfile1 testfile2
# create_holey_file 2048M testfile1 testfile2
# create_holey_file 234 testfile1
# create_holey_file 2340b testfile1
#
# Input unit size is in bytes with optional suffixes like k, KB, M, etc.
#
function create_holey_file() {
size=$(convert_to_bytes $1)
shift
for file in $*
do
truncate -s ${size} $file >> $PREP_LOG_FILE
done
}
#
# create_poolset -- create a dummy pool set
#
# Creates a pool set file using the provided list of part sizes and paths.
# Optionally, it also creates the selected part files (zeroed, partially zeroed
# or non-zeroed) with requested size and mode. The actual file size may be
# different than the part size in the pool set file.
# 'r' or 'R' on the list of arguments indicate the beginning of the next
# replica set and 'm' or 'M' the beginning of the next remote replica set.
# 'o' or 'O' indicates the next argument is a pool set option.
# A remote replica requires two parameters: a target node and a pool set
# descriptor.
#
# Each part argument has the following format:
# psize:ppath[:cmd[:fsize[:mode]]]
#
# where:
# psize - part size or AUTO (only for DAX device)
# ppath - path
# cmd - (optional) can be:
# x - do nothing (may be skipped if there's no 'fsize', 'mode')
# z - create zeroed (holey) file
# n - create non-zeroed file
# h - create non-zeroed file, but with zeroed header (first page)
# d - create directory
# fsize - (optional) the actual size of the part file (if 'cmd' is not 'x')
# mode - (optional) same format as for 'chmod' command
#
# Each remote replica argument has the following format:
# node:desc
#
# where:
# node - target node
# desc - pool set descriptor
#
# example:
# The following command define a pool set consisting of two parts: 16MB
# and 32MB, a local replica with only one part of 48MB and a remote replica.
# The first part file is not created, the second is zeroed. The only replica
# part is non-zeroed. Also, the last file is read-only and its size
# does not match the information from pool set file. The last but one line
# describes a remote replica. The SINGLEHDR poolset option is set, so only
# the first part in each replica contains a pool header. The remote poolset
# also has to have the SINGLEHDR option.
#
# create_poolset ./pool.set 16M:testfile1 32M:testfile2:z \
# R 48M:testfile3:n:11M:0400 \
# M remote_node:remote_pool.set \
# O SINGLEHDR
#
function create_poolset() {
psfile=$1
shift 1
echo "PMEMPOOLSET" > $psfile
while [ "$1" ]
do
if [ "$1" = "M" ] || [ "$1" = "m" ] # remote replica
then
shift 1
cmd=$1
shift 1
# extract last ":" separated segment as descriptor
# extract everything before last ":" as node address
# this extraction method is compatible with IPv6 and IPv4
node=${cmd%:*}
desc=${cmd##*:}
echo "REPLICA $node $desc" >> $psfile
continue
fi
if [ "$1" = "R" ] || [ "$1" = "r" ]
then
echo "REPLICA" >> $psfile
shift 1
continue
fi
if [ "$1" = "O" ] || [ "$1" = "o" ]
then
echo "OPTION $2" >> $psfile
shift 2
continue
fi
cmd=$1
fparms=(${cmd//:/ })
shift 1
fsize=${fparms[0]}
fpath=${fparms[1]}
cmd=${fparms[2]}
asize=${fparms[3]}
mode=${fparms[4]}
if [ ! $asize ]; then
asize=$fsize
fi
if [ "$asize" != "AUTO" ]; then
asize=$(convert_to_bytes $asize)
fi
case "$cmd"
in
x)
# do nothing
;;
z)
# zeroed (holey) file
truncate -s $asize $fpath >> $PREP_LOG_FILE
;;
n)
# non-zeroed file
$DD if=/dev/zero bs=$asize count=1 2>>$PREP_LOG_FILE | tr '\0' '\132' >> $fpath
;;
h)
# non-zeroed file, except page size header
truncate -s $PAGE_SIZE $fpath >> prep$UNITTEST_NUM.log
$DD if=/dev/zero bs=$asize count=1 2>>$PREP_LOG_FILE | tr '\0' '\132' >> $fpath
truncate -s $asize $fpath >> $PREP_LOG_FILE
;;
d)
mkdir -p $fpath
;;
esac
if [ $mode ]; then
chmod $mode $fpath
fi
echo "$fsize $fpath" >> $psfile
done
}
function dump_last_n_lines() {
if [ "$1" != "" -a -f "$1" ]; then
ln=`wc -l < $1`
if [ $ln -gt $UT_DUMP_LINES ]; then
echo -e "Last $UT_DUMP_LINES lines of $1 below (whole file has $ln lines)." >&2
ln=$UT_DUMP_LINES
else
echo -e "$1 below." >&2
fi
paste -d " " <(yes $UNITTEST_NAME $1 | head -n $ln) <(tail -n $ln $1) >&2
echo >&2
fi
}
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810295
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=780173
# https://bugs.kde.org/show_bug.cgi?id=303877
#
# valgrind issues an unsuppressable warning when exceeding
# the brk segment, causing matching failures. We can safely
# ignore it because malloc() will fallback to mmap() anyway.
function valgrind_ignore_warnings() {
cat $1 | grep -v \
-e "WARNING: Serious error when reading debug info" \
-e "When reading debug info from " \
-e "Ignoring non-Dwarf2/3/4 block in .debug_info" \
-e "Last block truncated in .debug_info; ignoring" \
-e "parse_CU_Header: is neither DWARF2 nor DWARF3 nor DWARF4" \
-e "brk segment overflow" \
-e "see section Limitations in user manual" \
-e "Warning: set address range perms: large range"\
-e "further instances of this message will not be shown"\
-e "get_Form_contents: DW_FORM_GNU_strp_alt used, but no alternate .debug_str"\
> $1.tmp
mv $1.tmp $1
}
#
# valgrind_ignore_messages -- cuts off Valgrind messages that are irrelevant
# to the correctness of the test, but changes during Valgrind rebase
# usage: valgrind_ignore_messages <log-file>
#
function valgrind_ignore_messages() {
if [ -e "$1.match" ]; then
cat $1 | grep -v \
-e "For lists of detected and suppressed errors, rerun with: -s" \
-e "For counts of detected and suppressed errors, rerun with: -v" \
> $1.tmp
mv $1.tmp $1
fi
}
#
# get_trace -- return tracing tool command line if applicable
# usage: get_trace <check type> <log file> [<node>]
#
function get_trace() {
if [ "$1" == "none" ]; then
echo "$TRACE"
return
fi
local exe=$VALGRINDEXE
local check_type=$1
local log_file=$2
local opts="$VALGRIND_OPTS"
local node=-1
[ "$#" -eq 3 ] && node=$3
if [ "$check_type" = "memcheck" -a "$MEMCHECK_DONT_CHECK_LEAKS" != "1" ]; then
opts="$opts --leak-check=full"
fi
if [ "$check_type" = "pmemcheck" ]; then
# Before Skylake, Intel CPUs did not have clflushopt instruction, so
# pmem_flush and pmem_persist both translated to clflush.
# This means that missing pmem_drain after pmem_flush could only be
# detected on Skylake+ CPUs.
# This option tells pmemcheck to expect fence (sfence or
# VALGRIND_PMC_DO_FENCE client request, used by pmem_drain) after
# clflush and makes pmemcheck output the same on pre-Skylake and
# post-Skylake CPUs.
opts="$opts --expect-fence-after-clflush=yes"
fi
opts="$opts $VALGRIND_SUPP"
if [ "$node" -ne -1 ]; then
exe=${NODE_VALGRINDEXE[$node]}
opts="$opts"
case "$check_type" in
memcheck)
opts="$opts --suppressions=../memcheck-libibverbs.supp"
;;
helgrind)
opts="$opts --suppressions=../helgrind-cxgb4.supp"
opts="$opts --suppressions=../helgrind-libfabric.supp"
;;
drd)
opts="$opts --suppressions=../drd-libfabric.supp"
;;
esac
fi
echo "$exe --tool=$check_type --log-file=$log_file $opts $TRACE"
return
}
#
# validate_valgrind_log -- validate valgrind log
# usage: validate_valgrind_log <log-file>
#
function validate_valgrind_log() {
[ "$VALIDATE_VALGRIND_LOG" != "1" ] && return
# fail if there are valgrind errors found or
# if it detects overlapping chunks
if [ ! -e "$1.match" ] && grep \
-e "ERROR SUMMARY: [^0]" \
-e "Bad mempool" \
$1 >/dev/null ;
then
msg=$(interactive_red STDERR "failed")
echo -e "$UNITTEST_NAME $msg with Valgrind. See $1. Last 20 lines below." >&2
paste -d " " <(yes $UNITTEST_NAME $1 | head -n 20) <(tail -n 20 $1) >&2
false
fi
}
#
# expect_normal_exit -- run a given command, expect it to exit 0
#
# if VALGRIND_DISABLED is not empty valgrind tool will be omitted
#
function expect_normal_exit() {
local VALGRIND_LOG_FILE=${CHECK_TYPE}${UNITTEST_NUM}.log
local N=$2
# in case of a remote execution disable valgrind check if valgrind is not
# enabled on node
local _CHECK_TYPE=$CHECK_TYPE
if [ "x$VALGRIND_DISABLED" != "x" ]; then
_CHECK_TYPE=none
fi
if [ "$1" == "run_on_node" -o "$1" == "run_on_node_background" ]; then
if [ -z $(is_valgrind_enabled_on_node $N) ]; then
_CHECK_TYPE="none"
fi
else
N=-1
fi
if [ -n "$TRACE" ]; then
case "$1"
in
*_on_node*)
msg "$UNITTEST_NAME: SKIP: TRACE is not supported if test is executed on remote nodes"
exit 0
esac
fi
local trace=$(get_trace $_CHECK_TYPE $VALGRIND_LOG_FILE $N)
if [ "$MEMCHECK_DONT_CHECK_LEAKS" = "1" -a "$CHECK_TYPE" = "memcheck" ]; then
export OLD_ASAN_OPTIONS="${ASAN_OPTIONS}"
export ASAN_OPTIONS="detect_leaks=0 ${ASAN_OPTIONS}"
fi
if [ "$CHECK_TYPE" = "helgrind" ]; then
export VALGRIND_OPTS="--suppressions=../helgrind-log.supp"
fi
if [ "$CHECK_TYPE" = "memcheck" ]; then
export VALGRIND_OPTS="$VALGRIND_OPTS --suppressions=../memcheck-dlopen.supp"
fi
local REMOTE_VALGRIND_LOG=0
if [ "$CHECK_TYPE" != "none" ]; then
case "$1"
in
run_on_node)
REMOTE_VALGRIND_LOG=1
trace="$1 $2 $trace"
[ $# -ge 2 ] && shift 2 || shift $#
;;
run_on_node_background)
trace="$1 $2 $3 $trace"
[ $# -ge 3 ] && shift 3 || shift $#
;;
wait_on_node|wait_on_node_port|kill_on_node)
[ "$1" = "wait_on_node" ] && REMOTE_VALGRIND_LOG=1
trace="$1 $2 $3 $4"
[ $# -ge 4 ] && shift 4 || shift $#
;;
esac
fi
if [ "$CHECK_TYPE" = "drd" ]; then
export VALGRIND_OPTS="$VALGRIND_OPTS --suppressions=../drd-log.supp"
fi
disable_exit_on_error
eval $ECHO $trace "$*"
ret=$?
if [ $REMOTE_VALGRIND_LOG -eq 1 ]; then
for node in $CHECK_NODES
do
local new_log_file=node\_$node\_$VALGRIND_LOG_FILE
copy_files_from_node $node "." ${NODE_TEST_DIR[$node]}/$VALGRIND_LOG_FILE
mv $VALGRIND_LOG_FILE $new_log_file
done
fi
restore_exit_on_error
if [ "$ret" -ne "0" ]; then
if [ "$ret" -gt "128" ]; then
msg="crashed (signal $(($ret - 128)))"
else
msg="failed with exit code $ret"
fi
msg=$(interactive_red STDERR $msg)
if [ -f $ERR_LOG_FILE ]; then
if [ "$UNITTEST_LOG_LEVEL" -ge "1" ]; then
echo -e "$UNITTEST_NAME $msg. $ERR_LOG_FILE below." >&2
cat $ERR_LOG_FILE >&2
else
echo -e "$UNITTEST_NAME $msg. $ERR_LOG_FILE above." >&2
fi
else
echo -e "$UNITTEST_NAME $msg." >&2
fi
# ignore Ctrl-C
if [ $ret != 130 ]; then
for f in $(get_files ".*[a-zA-Z_]${UNITTEST_NUM}\.log"); do
dump_last_n_lines $f
done
fi
[ $NODES_MAX -ge 0 ] && clean_all_remote_nodes
false
fi
if [ "$CHECK_TYPE" != "none" ]; then
if [ $REMOTE_VALGRIND_LOG -eq 1 ]; then
for node in $CHECK_NODES
do
local log_file=node\_$node\_$VALGRIND_LOG_FILE
valgrind_ignore_warnings $new_log_file
valgrind_ignore_messages $new_log_file
validate_valgrind_log $new_log_file
done
else
if [ -f $VALGRIND_LOG_FILE ]; then
valgrind_ignore_warnings $VALGRIND_LOG_FILE
valgrind_ignore_messages $VALGRIND_LOG_FILE
validate_valgrind_log $VALGRIND_LOG_FILE
fi
fi
fi
if [ "$MEMCHECK_DONT_CHECK_LEAKS" = "1" -a "$CHECK_TYPE" = "memcheck" ]; then
export ASAN_OPTIONS="${OLD_ASAN_OPTIONS}"
fi
}
#
# expect_abnormal_exit -- run a given command, expect it to exit non-zero
#
function expect_abnormal_exit() {
if [ -n "$TRACE" ]; then
case "$1"
in
*_on_node*)
msg "$UNITTEST_NAME: SKIP: TRACE is not supported if test is executed on remote nodes"
exit 0
esac
fi
if [ "$CHECK_TYPE" = "drd" ]; then
export VALGRIND_OPTS="$VALGRIND_OPTS --suppressions=../drd-log.supp"
fi
disable_exit_on_error
eval $ECHO ASAN_OPTIONS="detect_leaks=0 ${ASAN_OPTIONS}" $TRACE "$*"
ret=$?
restore_exit_on_error
if [ "$ret" -eq "0" ]; then
msg=$(interactive_red STDERR "succeeded")
echo -e "$UNITTEST_NAME command $msg unexpectedly." >&2
[ $NODES_MAX -ge 0 ] && clean_all_remote_nodes
false
fi
}
#
# check_pool -- run pmempool check on specified pool file
#
function check_pool() {
if [ "$CHECK_POOL" == "1" ]
then
if [ "$VERBOSE" != "0" ]
then
echo "$UNITTEST_NAME: checking consistency of pool ${1}"
fi
${PMEMPOOL}.static-nondebug check $1 2>&1 1>>$CHECK_POOL_LOG_FILE
fi
}
#
# check_pools -- run pmempool check on specified pool files
#
function check_pools() {
if [ "$CHECK_POOL" == "1" ]
then
for f in $*
do
check_pool $f
done
fi
}
#
# require_unlimited_vm -- require unlimited virtual memory
#
# This implies requirements for:
# - overcommit_memory enabled (/proc/sys/vm/overcommit_memory is 0 or 1)
# - unlimited virtual memory (ulimit -v is unlimited)
#
function require_unlimited_vm() {
$VM_OVERCOMMIT && [ $(ulimit -v) = "unlimited" ] && return
msg "$UNITTEST_NAME: SKIP required: overcommit_memory enabled and unlimited virtual memory"
exit 0
}
#
# require_linked_with_ndctl -- require an executable linked with libndctl
#
# usage: require_linked_with_ndctl <executable-file>
#
function require_linked_with_ndctl() {
[ "$1" == "" -o ! -x "$1" ] && \
fatal "$UNITTEST_NAME: ERROR: require_linked_with_ndctl() requires one argument - an executable file"
local lddndctl=$(ldd $1 | $GREP -ce "libndctl")
[ "$lddndctl" == "1" ] && return
msg "$UNITTEST_NAME: SKIP required: executable $1 linked with libndctl"
exit 0
}
#
# require_sudo_allowed -- require sudo command is allowed
#
function require_sudo_allowed() {
if [ "$ENABLE_SUDO_TESTS" != "y" ]; then
msg "$UNITTEST_NAME: SKIP: tests using 'sudo' are not enabled in testconfig.sh (ENABLE_SUDO_TESTS)"
exit 0
fi
if ! sh -c "timeout --signal=SIGKILL --kill-after=3s 3s sudo date" >/dev/null 2>&1
then
msg "$UNITTEST_NAME: SKIP required: sudo allowed"
exit 0
fi
}
#
# require_sudo_allowed_node -- require sudo command on a remote node
#
# usage: require_sudo_allowed_node <node-number>
#
function require_sudo_allowed_node() {
if [ "$ENABLE_SUDO_TESTS" != "y" ]; then
msg "$UNITTEST_NAME: SKIP: tests using 'sudo' are not enabled in testconfig.sh (ENABLE_SUDO_TESTS)"
exit 0
fi
if ! run_on_node $1 "timeout --signal=SIGKILL --kill-after=3s 3s sudo date" >/dev/null 2>&1
then
msg "$UNITTEST_NAME: SKIP required: sudo allowed on node $1"
exit 0
fi
}
#
# require_no_superuser -- require user without superuser rights
#
function require_no_superuser() {
local user_id=$(id -u)
[ "$user_id" != "0" ] && return
msg "$UNITTEST_NAME: SKIP required: run without superuser rights"
exit 0
}
#
# require_no_freebsd -- Skip test on FreeBSD
#
function require_no_freebsd() {
[ "$(uname -s)" != "FreeBSD" ] && return
msg "$UNITTEST_NAME: SKIP: Not supported on FreeBSD"
exit 0
}
#
# require_procfs -- Skip test if /proc is not mounted
#
function require_procfs() {
mount | grep -q "/proc" && return
msg "$UNITTEST_NAME: SKIP: /proc not mounted"
exit 0
}
#
# require_arch -- Skip tests if the running platform not matches
# any of the input list.
#
function require_arch() {
for i in "$@"; do
[[ "$(uname -m)" == "$i" ]] && return
done
msg "$UNITTEST_NAME: SKIP: Only supported on $1"
exit 0
}
#
# exclude_arch -- Skip tests if the running platform matches
# any of the input list.
#
function exclude_arch() {
for i in "$@"; do
if [[ "$(uname -m)" == "$i" ]]; then
msg "$UNITTEST_NAME: SKIP: Not supported on $1"
exit 0
fi
done
}
#
# require_x86_64 -- Skip tests if the running platform is not x86_64
#
function require_x86_64() {
require_arch x86_64
}
#
# require_ppc64 -- Skip tests if the running platform is not ppc64 or ppc64le
#
function require_ppc64() {
require_arch "ppc64" "ppc64le" "ppc64el"
}
#
# exclude_ppc64 -- Skip tests if the running platform is ppc64 or ppc64le
#
function exclude_ppc64() {
exclude_arch "ppc64" "ppc64le" "ppc64el"
}
#
# require_test_type -- only allow script to continue for a certain test type
#
function require_test_type() {
req_test_type=1
for type in $*
do
case "$TEST"
in
all)
# "all" is a synonym of "short + medium + long"
return
;;
check)
# "check" is a synonym of "short + medium"
[ "$type" = "short" -o "$type" = "medium" ] && return
;;
*)
[ "$type" = "$TEST" ] && return
;;
esac
done
verbose_msg "$UNITTEST_NAME: SKIP test-type $TEST ($* required)"
exit 0
}
#
# require_dev_dax_region -- check if region id file exist for dev dax
#
function require_dev_dax_region() {
local prefix="$UNITTEST_NAME: SKIP"
local cmd="$PMEMDETECT -r"
for path in ${DEVICE_DAX_PATH[@]}
do
disable_exit_on_error
out=$($cmd $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" == "0" ]; then
continue
elif [ "$ret" == "1" ]; then
msg "$prefix $out"
exit 0
else
fatal "$UNITTEST_NAME: pmemdetect: $out"
fi
done
DEVDAX_TO_LOCK=1
}
#
# lock_devdax -- acquire a lock on Device DAXes
#
lock_devdax() {
exec {DEVDAX_LOCK_FD}> $DEVDAX_LOCK
flock $DEVDAX_LOCK_FD
}
#
# unlock_devdax -- release a lock on Device DAXes
#
unlock_devdax() {
flock -u $DEVDAX_LOCK_FD
eval "exec ${DEVDAX_LOCK_FD}>&-"
}
#
# require_dev_dax_node -- common function for require_dax_devices and
# node_require_dax_device
#
# usage: require_dev_dax_node <N devices> [<node>]
#
function require_dev_dax_node() {
req_dax_dev=1
if [ "$req_dax_dev_align" == "1" ]; then
fatal "$UNITTEST_NAME: Do not use 'require_(node_)dax_devices' and "
"'require_(node_)dax_device_alignments' together. Use the latter instead."
fi
local min=$1
local node=$2
if [ -n "$node" ]; then
local DIR=${NODE_WORKING_DIR[$node]}/$curtestdir
local prefix="$UNITTEST_NAME: SKIP NODE $node:"
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
if [ ${#device_dax_path[@]} -lt $min ]; then
msg "$prefix NODE_${node}_DEVICE_DAX_PATH does not specify enough dax devices (min: $min)"
exit 0
fi
local cmd="ssh $SSH_OPTS ${NODE[$node]} cd $DIR && LD_LIBRARY_PATH=$REMOTE_LD_LIBRARY_PATH ../pmemdetect -d"
else
local prefix="$UNITTEST_NAME: SKIP"
if [ ${#DEVICE_DAX_PATH[@]} -lt $min ]; then
msg "$prefix DEVICE_DAX_PATH does not specify enough dax devices (min: $min)"
exit 0
fi
local device_dax_path=${DEVICE_DAX_PATH[@]}
local cmd="$PMEMDETECT -d"
fi
for path in ${device_dax_path[@]}
do
disable_exit_on_error
out=$($cmd $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" == "0" ]; then
continue
elif [ "$ret" == "1" ]; then
msg "$prefix $out"
exit 0
else
fatal "$UNITTEST_NAME: pmemdetect: $out"
fi
done
DEVDAX_TO_LOCK=1
}
#
# require_ndctl_enable -- check NDCTL_ENABLE value and skip test if set to 'n'
#
function require_ndctl_enable() {
if ! is_ndctl_enabled $PMEMPOOL$EXE &> /dev/null ; then
msg "$UNITTEST_NAME: SKIP: ndctl is disabled - binary not compiled with libndctl"
exit 0
fi
return 0
}
#
# require_dax_devices -- only allow script to continue if there is a required
# number of Device DAX devices and ndctl is available
#
function require_dax_devices() {
require_ndctl_enable
require_pkg libndctl "$NDCTL_MIN_VERSION"
REQUIRE_DAX_DEVICES=$1
require_dev_dax_node $1
}
#
# require_node_dax_device -- only allow script to continue if specified node
# has enough Device DAX devices defined in testconfig.sh
#
function require_node_dax_device() {
validate_node_number $1
require_dev_dax_node $2 $1
}
#
# require_no_unicode -- overwrite unicode suffix to empty string
#
function require_no_unicode() {
export SUFFIX=""
}
#
# get_node_devdax_path -- get path of a Device DAX device on a node
#
# usage: get_node_devdax_path <node> <device>
#
get_node_devdax_path() {
local node=$1
local device=$2
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
echo ${device_dax_path[$device]}
}
#
# dax_device_zero -- zero all local dax devices
#
dax_device_zero() {
for path in ${DEVICE_DAX_PATH[@]}
do
${PMEMPOOL}.static-debug rm -f $path
done
}
#
# node_dax_device_zero -- zero all dax devices on a node
#
node_dax_device_zero() {
local node=$1
local DIR=${NODE_WORKING_DIR[$node]}/$curtestdir
local prefix="$UNITTEST_NAME: SKIP NODE $node:"
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
local cmd="ssh $SSH_OPTS ${NODE[$node]} cd $DIR && LD_LIBRARY_PATH=$REMOTE_LD_LIBRARY_PATH ../pmempool rm -f"
for path in ${device_dax_path[@]}
do
disable_exit_on_error
out=$($cmd $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" == "0" ]; then
continue
elif [ "$ret" == "1" ]; then
msg "$prefix $out"
exit 0
else
fatal "$UNITTEST_NAME: pmempool rm: $out"
fi
done
}
#
# get_devdax_size -- get the size of a device dax
#
function get_devdax_size() {
local device=$1
local path=${DEVICE_DAX_PATH[$device]}
local major_hex=$(stat -c "%t" $path)
local minor_hex=$(stat -c "%T" $path)
local major_dec=$((16#$major_hex))
local minor_dec=$((16#$minor_hex))
cat /sys/dev/char/$major_dec:$minor_dec/size
}
#
# get_node_devdax_size -- get the size of a device dax on a node
#
function get_node_devdax_size() {
local node=$1
local device=$2
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
local path=${device_dax_path[$device]}
local cmd_prefix="ssh $SSH_OPTS ${NODE[$node]} "
disable_exit_on_error
out=$($cmd_prefix stat -c %t $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" != "0" ]; then
fatal "$UNITTEST_NAME: stat on node $node: $out"
fi
local major=$((16#$out))
disable_exit_on_error
out=$($cmd_prefix stat -c %T $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" != "0" ]; then
fatal "$UNITTEST_NAME: stat on node $node: $out"
fi
local minor=$((16#$out))
disable_exit_on_error
out=$($cmd_prefix "cat /sys/dev/char/$major:$minor/size" 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" != "0" ]; then
fatal "$UNITTEST_NAME: stat on node $node: $out"
fi
echo $out
}
#
# require_dax_device_node_alignments -- only allow script to continue if
# the internal Device DAX alignments on a remote nodes are as specified.
# If necessary, it sorts DEVICE_DAX_PATH entries to match
# the requested alignment order.
#
# usage: require_node_dax_device_alignments <node> <alignment1> [ alignment2 ... ]
#
function require_node_dax_device_alignments() {
req_dax_dev_align=1
if [ "$req_dax_dev" == "$1" ]; then
fatal "$UNITTEST_NAME: Do not use 'require_(node_)dax_devices' and "
"'require_(node_)dax_device_alignments' together. Use the latter instead."
fi
local node=$1
shift
if [ "$node" == "-1" ]; then
local device_dax_path=(${DEVICE_DAX_PATH[@]})
local cmd="$PMEMDETECT -a"
else
local device_dax_path=(${NODE_DEVICE_DAX_PATH[$node]})
local DIR=${NODE_WORKING_DIR[$node]}/$curtestdir
local cmd="ssh $SSH_OPTS ${NODE[$node]} cd $DIR && LD_LIBRARY_PATH=$REMOTE_LD_LIBRARY_PATH ../pmemdetect -a"
fi
local cnt=${#device_dax_path[@]}
local j=0
for alignment in $*
do
for (( i=j; i<cnt; i++ ))
do
path=${device_dax_path[$i]}
disable_exit_on_error
out=$($cmd $alignment $path 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" == "0" ]; then
if [ $i -ne $j ]; then
# swap device paths
tmp=${device_dax_path[$j]}
device_dax_path[$j]=$path
device_dax_path[$i]=$tmp
if [ "$node" == "-1" ]; then
DEVICE_DAX_PATH=(${device_dax_path[@]})
else
NODE_DEVICE_DAX_PATH[$node]=${device_dax_path[@]}
fi
fi
break
fi
done
if [ $i -eq $cnt ]; then
if [ "$node" == "-1" ]; then
msg "$UNITTEST_NAME: SKIP DEVICE_DAX_PATH"\
"does not specify enough dax devices or they don't have required alignments (min: $#, alignments: $*)"
else
msg "$UNITTEST_NAME: SKIP NODE $node: NODE_${node}_DEVICE_DAX_PATH"\
"does not specify enough dax devices or they don't have required alignments (min: $#, alignments: $*)"
fi
exit 0
fi
j=$(( j + 1 ))
done
}
#
# require_dax_device_alignments -- only allow script to continue if
# the internal Device DAX alignments are as specified.
# If necessary, it sorts DEVICE_DAX_PATH entries to match
# the requested alignment order.
#
# usage: require_dax_device_alignments alignment1 [ alignment2 ... ]
#
require_dax_device_alignments() {
require_node_dax_device_alignments -1 $*
}
#
# disable_eatmydata -- ensure invalid msyncs fail
#
# Distros (and people) like to use eatmydata to kill fsync-likes during builds
# and testing. This is nice for speed, but we actually rely on msync failing
# in some tests.
#
disable_eatmydata() {
export LD_PRELOAD="${LD_PRELOAD/#libeatmydata.so/}"
export LD_PRELOAD="${LD_PRELOAD/ libeatmydata.so/}"
export LD_PRELOAD="${LD_PRELOAD/:libeatmydata.so/}"
}
#
# require_fs_type -- only allow script to continue for a certain fs type
#
function require_fs_type() {
req_fs_type=1
for type in $*
do
# treat any as either pmem or non-pmem
[ "$type" = "$FS" ] ||
([ -n "${FORCE_FS:+x}" ] && [ "$type" = "any" ] &&
[ "$FS" != "none" ]) && return
done
verbose_msg "$UNITTEST_NAME: SKIP fs-type $FS ($* required)"
exit 0
}
#
# require_native_fallocate -- verify if filesystem supports fallocate
#
function require_native_fallocate() {
require_fs_type pmem non-pmem
set +e
$FALLOCATE_DETECT $1
status=$?
set -e
if [ $status -eq 1 ]; then
msg "$UNITTEST_NAME: SKIP: filesystem does not support fallocate"
exit 0
elif [ $status -ne 0 ]; then
msg "$UNITTEST_NAME: fallocate_detect failed"
exit 1
fi
}
#
# require_usc_permission -- verify if usc can be read with current permissions
#
function require_usc_permission() {
set +e
$USC_PERMISSION $1 2> $DIR/usc_permission.txt
status=$?
set -e
# check if there were any messages printed to stderr, skip test if there were
usc_stderr=$(cat $DIR/usc_permission.txt | wc -c)
rm -f $DIR/usc_permission.txt
if [ $status -eq 1 ] || [ $usc_stderr -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP: missing permissions to read usc"
exit 0
elif [ $status -ne 0 ]; then
msg "$UNITTEST_NAME: usc_permission_check failed"
exit 1
fi
}
#
# require_fs_name -- verify if the $DIR is on the required file system
#
# Must be AFTER setup() because $DIR must exist
#
function require_fs_name() {
fsname=`df $DIR -PT | awk '{if (NR == 2) print $2}'`
for name in $*
do
if [ "$name" == "$fsname" ]; then
return
fi
done
msg "$UNITTEST_NAME: SKIP file system $fsname ($* required)"
exit 0
}
#
# require_build_type -- only allow script to continue for a certain build type
#
function require_build_type() {
for type in $*
do
[ "$type" = "$BUILD" ] && return
done
verbose_msg "$UNITTEST_NAME: SKIP build-type $BUILD ($* required)"
exit 0
}
#
# require_command -- only allow script to continue if specified command exists
#
function require_command() {
if ! which $1 >/dev/null 2>&1; then
msg "$UNITTEST_NAME: SKIP: '$1' command required"
exit 0
fi
}
#
# require_command_node -- only allow script to continue if specified command exists on a remote node
#
# usage: require_command_node <node-number>
#
function require_command_node() {
if ! run_on_node $1 "which $2 >/dev/null 2>&1"; then
msg "$UNITTEST_NAME: SKIP: node $1: '$2' command required"
exit 0
fi
}
#
# require_kernel_module -- only allow script to continue if specified kernel module exists
#
# usage: require_kernel_module <module_name> [path_to_modinfo]
#
function require_kernel_module() {
MODULE=$1
MODINFO=$2
if [ "$MODINFO" == "" ]; then
set +e
[ "$MODINFO" == "" ] && \
MODINFO=$(which modinfo 2>/dev/null)
set -e
[ "$MODINFO" == "" ] && \
[ -x /usr/sbin/modinfo ] && MODINFO=/usr/sbin/modinfo
[ "$MODINFO" == "" ] && \
[ -x /sbin/modinfo ] && MODINFO=/sbin/modinfo
[ "$MODINFO" == "" ] && \
msg "$UNITTEST_NAME: SKIP: modinfo command required" && \
exit 0
else
[ ! -x $MODINFO ] && \
msg "$UNITTEST_NAME: SKIP: modinfo command required" && \
exit 0
fi
$MODINFO -F name $MODULE &>/dev/null && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP: '$MODULE' kernel module required"
exit 0
fi
}
#
# require_kernel_module_node -- only allow script to continue if specified kernel module exists on a remote node
#
# usage: require_kernel_module_node <node> <module_name> [path_to_modinfo]
#
function require_kernel_module_node() {
NODE_N=$1
MODULE=$2
MODINFO=$3
if [ "$MODINFO" == "" ]; then
set +e
[ "$MODINFO" == "" ] && \
MODINFO=$(run_on_node $NODE_N which modinfo 2>/dev/null)
set -e
[ "$MODINFO" == "" ] && \
run_on_node $NODE_N "test -x /usr/sbin/modinfo" && MODINFO=/usr/sbin/modinfo
[ "$MODINFO" == "" ] && \
run_on_node $NODE_N "test -x /sbin/modinfo" && MODINFO=/sbin/modinfo
[ "$MODINFO" == "" ] && \
msg "$UNITTEST_NAME: SKIP: node $NODE_N: modinfo command required" && \
exit 0
else
run_on_node $NODE_N "test ! -x $MODINFO" && \
msg "$UNITTEST_NAME: SKIP: node $NODE_N: modinfo command required" && \
exit 0
fi
run_on_node $NODE_N "$MODINFO -F name $MODULE &>/dev/null" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP: node $NODE_N: '$MODULE' kernel module required"
exit 0
fi
}
#
# require_pkg -- only allow script to continue if specified package exists
# usage: require_pkg <package name> [<package minimal version>]
#
function require_pkg() {
if ! command -v pkg-config 1>/dev/null
then
msg "$UNITTEST_NAME: SKIP pkg-config required"
exit 0
fi
local COMMAND="pkg-config $1"
local MSG="$UNITTEST_NAME: SKIP '$1' package"
if [ "$#" -eq "2" ]; then
COMMAND="$COMMAND --atleast-version $2"
MSG="$MSG (version >= $2)"
fi
MSG="$MSG required"
if ! $COMMAND
then
msg "$MSG"
exit 0
fi
}
#
# require_node_pkg -- only allow script to continue if specified package exists
# on specified node
# usage: require_node_pkg <node> <package name> [<package minimal version>]
#
function require_node_pkg() {
validate_node_number $1
local N=$1
shift
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
local COMMAND="${NODE_ENV[$N]}"
if [ -n "${NODE_LD_LIBRARY_PATH[$N]}" ]; then
local PKG_CONFIG_PATH=${NODE_LD_LIBRARY_PATH[$N]//:/\/pkgconfig:}/pkgconfig
COMMAND="$COMMAND PKG_CONFIG_PATH=\$PKG_CONFIG_PATH:$PKG_CONFIG_PATH"
fi
COMMAND="$COMMAND PKG_CONFIG_PATH=$REMOTE_PKG_CONFIG_PATH"
COMMAND="$COMMAND pkg-config $1"
MSG="$UNITTEST_NAME: SKIP NODE $N: '$1' package"
if [ "$#" -eq "2" ]; then
COMMAND="$COMMAND --atleast-version $2"
MSG="$MSG (version >= $2)"
fi
MSG="$MSG required"
disable_exit_on_error
run_command ssh $SSH_OPTS ${NODE[$N]} "$COMMAND" 2>&1
ret=$?
restore_exit_on_error
if [ "$ret" == 1 ]; then
msg "$MSG"
exit 0
fi
}
#
# configure_valgrind -- only allow script to continue when settings match
#
function configure_valgrind() {
case "$1"
in
memcheck|pmemcheck|helgrind|drd|force-disable)
;;
*)
usage "bad test-type: $1"
;;
esac
if [ "$CHECK_TYPE" == "none" ]; then
if [ "$1" == "force-disable" ]; then
msg "$UNITTEST_NAME: all valgrind tests disabled"
elif [ "$2" = "force-enable" ]; then
CHECK_TYPE="$1"
require_valgrind_tool $1 $3
elif [ "$2" = "force-disable" ]; then
CHECK_TYPE=none
else
fatal "invalid parameter"
fi
else
if [ "$1" == "force-disable" ]; then
msg "$UNITTEST_NAME: SKIP RUNTESTS script parameter $CHECK_TYPE tries to enable valgrind test when all valgrind tests are disabled in TEST"
exit 0
elif [ "$CHECK_TYPE" != "$1" -a "$2" == "force-enable" ]; then
msg "$UNITTEST_NAME: SKIP RUNTESTS script parameter $CHECK_TYPE tries to enable different valgrind test than one defined in TEST"
exit 0
elif [ "$CHECK_TYPE" == "$1" -a "$2" == "force-disable" ]; then
msg "$UNITTEST_NAME: SKIP RUNTESTS script parameter $CHECK_TYPE tries to enable test defined in TEST as force-disable"
exit 0
fi
require_valgrind_tool $CHECK_TYPE $3
fi
if [ "$UT_VALGRIND_SKIP_PRINT_MISMATCHED" == 1 ]; then
export UT_SKIP_PRINT_MISMATCHED=1
fi
}
#
# valgrind_version_no_check -- returns Valgrind version without checking
# for valgrind first
#
function valgrind_version_no_check() {
$VALGRINDEXE --version | sed "s/valgrind-\([0-9]*\)\.\([0-9]*\).*/\1*100+\2/" | bc
}
#
# require_valgrind -- continue script execution only if
# valgrind package is installed
#
function require_valgrind() {
# bc is used inside valgrind_version_no_check
require_command bc
require_no_asan
disable_exit_on_error
VALGRINDEXE=`which valgrind 2>/dev/null`
local ret=$?
restore_exit_on_error
if [ $ret -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP valgrind required"
exit 0
fi
[ $NODES_MAX -lt 0 ] && return;
if [ ! -z "$1" ]; then
available=$(valgrind_version_no_check)
required=`echo $1 | sed "s/\([0-9]*\)\.\([0-9]*\).*/\1*100+\2/" | bc`
if [ $available -lt $required ]; then
msg "$UNITTEST_NAME: SKIP valgrind required (ver $1 or later)"
exit 0
fi
fi
for N in $NODES_SEQ; do
if [ "${NODE_VALGRINDEXE[$N]}" = "" ]; then
disable_exit_on_error
NODE_VALGRINDEXE[$N]=$(ssh $SSH_OPTS ${NODE[$N]} "which valgrind 2>/dev/null")
ret=$?
restore_exit_on_error
if [ $ret -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP valgrind required on remote node #$N"
exit 0
fi
fi
done
}
#
# valgrind_version -- returns Valgrind version
#
function valgrind_version() {
require_valgrind
valgrind_version_no_check
}
#
# require_valgrind_tool -- continue script execution only if valgrind with
# specified tool is installed
#
# usage: require_valgrind_tool <tool> [<binary>]
#
function require_valgrind_tool() {
require_valgrind
local tool=$1
local binary=$2
local dir=.
[ -d "$2" ] && dir="$2" && binary=
pushd "$dir" > /dev/null
[ -n "$binary" ] || binary=$(get_executables)
if [ -z "$binary" ]; then
fatal "require_valgrind_tool: error: no binary found"
fi
strings ${binary} 2>&1 | \
grep -q "compiled with support for Valgrind $tool" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP not compiled with support for Valgrind $tool"
exit 0
fi
if [ "$tool" == "helgrind" ]; then
valgrind --tool=$tool --help 2>&1 | \
grep -qi "$tool is Copyright (c)" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP Valgrind with $tool required"
exit 0;
fi
fi
if [ "$tool" == "pmemcheck" ]; then
out=`valgrind --tool=$tool --help 2>&1` && true
echo "$out" | grep -qi "$tool is Copyright (c)" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP Valgrind with $tool required"
exit 0;
fi
echo "$out" | grep -qi "expect-fence-after-clflush" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP pmemcheck does not support --expect-fence-after-clflush option. Please update it to the latest version."
exit 0;
fi
fi
popd > /dev/null
return 0
}
#
# set_valgrind_exe_name -- set the actual Valgrind executable name
#
# On some systems (Ubuntu), "valgrind" is a shell script that calls
# the actual executable "valgrind.bin".
# The wrapper script doesn't work well with LD_PRELOAD, so we want
# to call Valgrind directly.
#
function set_valgrind_exe_name() {
if [ "$VALGRINDEXE" = "" ]; then
fatal "set_valgrind_exe_name: error: valgrind is not set up"
fi
local VALGRINDDIR=`dirname $VALGRINDEXE`
if [ -x $VALGRINDDIR/valgrind.bin ]; then
VALGRINDEXE=$VALGRINDDIR/valgrind.bin
fi
[ $NODES_MAX -lt 0 ] && return;
for N in $NODES_SEQ; do
local COMMAND="\
[ -x $(dirname ${NODE_VALGRINDEXE[$N]})/valgrind.bin ] && \
echo $(dirname ${NODE_VALGRINDEXE[$N]})/valgrind.bin || \
echo ${NODE_VALGRINDEXE[$N]}"
NODE_VALGRINDEXE[$N]=$(ssh $SSH_OPTS ${NODE[$N]} $COMMAND)
if [ $? -ne 0 ]; then
fatal ${NODE_VALGRINDEXE[$N]}
fi
done
}
#
# require_no_asan_for - continue script execution only if passed binary does
# NOT require libasan
#
function require_no_asan_for() {
disable_exit_on_error
nm $1 | grep -q __asan_
ASAN_ENABLED=$?
restore_exit_on_error
if [ "$ASAN_ENABLED" == "0" ]; then
msg "$UNITTEST_NAME: SKIP: ASAN enabled"
exit 0
fi
}
#
# require_cxx11 -- continue script execution only if C++11 supporting compiler
# is installed
#
function require_cxx11() {
[ "$CXX" ] || CXX=c++
CXX11_AVAILABLE=`echo "int main(){return 0;}" |\
$CXX -std=c++11 -x c++ -o /dev/null - 2>/dev/null &&\
echo y || echo n`
if [ "$CXX11_AVAILABLE" == "n" ]; then
msg "$UNITTEST_NAME: SKIP: C++11 required"
exit 0
fi
}
#
# require_no_asan - continue script execution only if libpmem does NOT require
# libasan
#
function require_no_asan() {
case "$BUILD"
in
debug)
require_no_asan_for ../../debug/libpmem.so
;;
nondebug)
require_no_asan_for ../../nondebug/libpmem.so
;;
static-debug)
require_no_asan_for ../../debug/libpmem.a
;;
static-nondebug)
require_no_asan_for ../../nondebug/libpmem.a
;;
esac
}
#
# require_tty - continue script execution only if standard output is a terminal
#
function require_tty() {
if ! tty >/dev/null; then
msg "$UNITTEST_NAME: SKIP no terminal"
exit 0
fi
}
#
# require_binary -- continue script execution only if the binary has been compiled
#
# In case of conditional compilation, skip this test.
#
function require_binary() {
if [ -z "$1" ]; then
fatal "require_binary: error: binary not provided"
fi
if [ ! -x "$1" ]; then
msg "$UNITTEST_NAME: SKIP no binary found"
exit 0
fi
return
}
#
# require_sds -- continue script execution only if binary is compiled with
# shutdown state support
#
# usage: require_sds <binary>
#
function require_sds() {
local binary=$1
local dir=.
if [ -z "$binary" ]; then
fatal "require_sds: error: no binary found"
fi
strings ${binary} 2>&1 | \
grep -q "compiled with support for shutdown state" && true
if [ $? -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP not compiled with support for shutdown state"
exit 0
fi
return 0
}
#
# require_no_sds -- continue script execution only if binary is NOT compiled with
# shutdown state support
#
# usage: require_no_sds <binary>
#
function require_no_sds() {
local binary=$1
local dir=.
if [ -z "$binary" ]; then
fatal "require_sds: error: no binary found"
fi
set +e
found=$(strings ${binary} 2>&1 | \
grep -c "compiled with support for shutdown state")
set -e
if [ "$found" -ne "0" ]; then
msg "$UNITTEST_NAME: SKIP compiled with support for shutdown state"
exit 0
fi
return 0
}
#
# is_ndctl_enabled -- check if binary is compiled with libndctl
#
# usage: is_ndctl_enabled <binary>
#
function is_ndctl_enabled() {
local binary=$1
local dir=.
if [ -z "$binary" ]; then
fatal "is_ndctl_enabled: error: no binary found"
fi
strings ${binary} 2>&1 | \
grep -q "compiled with libndctl" && true
return $?
}
#
# require_bb_enabled_by_default -- check if the binary has bad block
# checking feature enabled by default
#
# usage: require_bb_enabled_by_default <binary>
#
function require_bb_enabled_by_default() {
if ! is_ndctl_enabled $1 &> /dev/null ; then
msg "$UNITTEST_NAME: SKIP bad block checking feature disabled by default"
exit 0
fi
return 0
}
#
# require_bb_disabled_by_default -- check if the binary does not have bad
# block checking feature enabled by default
#
# usage: require_bb_disabled_by_default <binary>
#
function require_bb_disabled_by_default() {
if is_ndctl_enabled $1 &> /dev/null ; then
msg "$UNITTEST_NAME: SKIP bad block checking feature enabled by default"
exit 0
fi
return 0
}
#
# check_absolute_path -- continue script execution only if $DIR path is
# an absolute path; do not resolve symlinks
#
function check_absolute_path() {
if [ "${DIR:0:1}" != "/" ]; then
fatal "Directory \$DIR has to be an absolute path. $DIR was given."
fi
}
#
# run_command -- run a command in a verbose or quiet way
#
function run_command()
{
local COMMAND="$*"
if [ "$VERBOSE" != "0" ]; then
echo "$ $COMMAND"
$COMMAND
else
$COMMAND
fi
}
#
# validate_node_number -- validate a node number
#
function validate_node_number() {
[ $1 -gt $NODES_MAX ] \
&& fatal "error: node number ($1) greater than maximum allowed node number ($NODES_MAX)"
return 0
}
#
# clean_remote_node -- usage: clean_remote_node <node> <list-of-pid-files>
#
function clean_remote_node() {
validate_node_number $1
local N=$1
shift
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
# register the list of PID files to be cleaned in case of an error
NODE_PID_FILES[$N]="${NODE_PID_FILES[$N]} $*"
# clean the remote node
disable_exit_on_error
for pidfile in ${NODE_PID_FILES[$N]}; do
require_ctrld_err $N $pidfile
run_command ssh $SSH_OPTS ${NODE[$N]} "\
cd $DIR && [ -f $pidfile ] && \
../ctrld $pidfile kill SIGINT && \
../ctrld $pidfile wait 1 ; \
rm -f $pidfile"
done;
restore_exit_on_error
return 0
}
#
# clean_all_remote_nodes -- clean all remote nodes in case of an error
#
function clean_all_remote_nodes() {
msg "$UNITTEST_NAME: CLEAN (cleaning processes on remote nodes)"
local N=0
disable_exit_on_error
for N in $NODES_SEQ; do
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
for pidfile in ${NODE_PID_FILES[$N]}; do
run_command ssh $SSH_OPTS ${NODE[$N]} "\
cd $DIR && [ -f $pidfile ] && \
../ctrld $pidfile kill SIGINT && \
../ctrld $pidfile wait 1 ; \
rm -f $pidfile"
done
done
restore_exit_on_error
return 0
}
#
# export_vars_node -- export specified variables on specified node
#
function export_vars_node() {
local N=$1
shift
validate_node_number $N
for var in "$@"; do
NODE_ENV[$N]="${NODE_ENV[$N]} $var=${!var}"
done
}
#
# require_nodes_libfabric -- only allow script to continue if libfabric with
# optionally specified provider is available on
# specified node
# usage: require_nodes_libfabric <node> <provider> [<libfabric-version>]
#
function require_node_libfabric() {
validate_node_number $1
local N=$1
local provider=$2
# Minimal required version of libfabric.
# Keep in sync with requirements in src/common.inc.
local version=${3:-1.4.2}
require_pkg libfabric "$version"
# fi_info can be found in libfabric-bin
require_command fi_info
require_node_pkg $N libfabric "$version"
require_command_node $N fi_info
if [ "$RPMEM_PROVIDER" == "verbs" ]; then
if ! fi_info --list | grep -q verbs; then
msg "$UNITTEST_NAME: SKIP libfabric not compiled with verbs provider"
exit 0
fi
if ! run_on_node $N "fi_info --list | grep -q verbs"; then
msg "$UNITTEST_NAME: SKIP libfabric on node $N not compiled with verbs provider"
exit 0
fi
fi
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
local COMMAND="$COMMAND ${NODE_ENV[$N]}"
COMMAND="$COMMAND LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[$N]}:$REMOTE_LD_LIBRARY_PATH"
COMMAND="$COMMAND ../fip ${NODE_ADDR[$N]} $provider"
disable_exit_on_error
fip_out=$(ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && $COMMAND" 2>&1)
ret=$?
restore_exit_on_error
if [ "$ret" == "0" ]; then
return
elif [ "$ret" == "1" ]; then
msg "$UNITTEST_NAME: SKIP NODE $N: $fip_out"
exit 0
else
fatal "NODE $N: require_libfabric $provider: $fip_out"
fi
}
#
# check_if_node_is_reachable -- check if the $1 node is reachable
#
function check_if_node_is_reachable() {
disable_exit_on_error
run_command ssh $SSH_OPTS ${NODE[$1]} exit
local ret=$?
restore_exit_on_error
return $ret
}
#
# require_nodes -- only allow script to continue for a certain number
# of defined and reachable nodes
#
# Input arguments:
# NODE[] - (required) array of nodes' addresses
# NODE_WORKING_DIR[] - (required) array of nodes' working directories
#
function require_nodes() {
local N_NODES=${#NODE[@]}
local N=$1
[ -z "$N" ] \
&& fatal "require_nodes: missing reguired parameter: number of nodes"
# if it has already been called, check if number of required nodes is bigger than previously
[ -n "$NODES_MAX" ] \
&& [ $(($N - 1)) -le $NODES_MAX ] && return
[ $N -gt $N_NODES ] \
&& msg "$UNITTEST_NAME: SKIP: requires $N node(s), but $N_NODES node(s) provided" \
&& exit 0
NODES_MAX=$(($N - 1))
NODES_SEQ=$(seq -s' ' 0 $NODES_MAX)
# check if all required nodes are reachable
for N in $NODES_SEQ; do
# validate node's address
[ "${NODE[$N]}" = "" ] \
&& msg "$UNITTEST_NAME: SKIP: address of node #$N is not provided" \
&& exit 0
# validate the working directory
[ "${NODE_WORKING_DIR[$N]}" = "" ] \
&& fatal "error: working directory for node #$N (${NODE[$N]}) is not provided"
# check if the node is reachable
check_if_node_is_reachable $N
[ $? -ne 0 ] \
&& fatal "error: node #$N (${NODE[$N]}) is unreachable"
# clear the list of PID files for each node
NODE_PID_FILES[$N]=""
NODE_TEST_DIR[$N]=${NODE_WORKING_DIR[$N]}/$curtestdir
NODE_DIR[$N]=${NODE_WORKING_DIR[$N]}/$curtestdir/data/
require_node_log_files $N $ERR_LOG_FILE $OUT_LOG_FILE $TRACE_LOG_FILE
if [ "$CHECK_TYPE" != "none" -a "${NODE_VALGRINDEXE[$N]}" = "" ]; then
disable_exit_on_error
NODE_VALGRINDEXE[$N]=$(ssh $SSH_OPTS ${NODE[$N]} "which valgrind 2>/dev/null")
local ret=$?
restore_exit_on_error
if [ $ret -ne 0 ]; then
msg "$UNITTEST_NAME: SKIP valgrind required on remote node #$N"
exit 0
fi
fi
done
# remove all log files of the current unit test from the required nodes
# and export the 'log' variables to these nodes
for N in $NODES_SEQ; do
for f in $(get_files "node_${N}.*${UNITTEST_NUM}\.log"); do
rm -f $f
done
export_vars_node $N $REMOTE_VARS
done
# register function to clean all remote nodes in case of an error or SIGINT
trap clean_all_remote_nodes ERR SIGINT
return 0
}
#
# check_files_on_node -- check if specified files exist on given node
#
function check_files_on_node() {
validate_node_number $1
local N=$1
shift
local REMOTE_DIR=${NODE_DIR[$N]}
run_command ssh $SSH_OPTS ${NODE[$N]} "for f in $*; do if [ ! -f $REMOTE_DIR/\$f ]; then echo \"Missing file \$f on node #$N\" 1>&2; exit 1; fi; done"
}
#
# check_no_files_on_node -- check if specified files does not exist on given node
#
function check_no_files_on_node() {
validate_node_number $1
local N=$1
shift
local REMOTE_DIR=${NODE_DIR[$N]}
run_command ssh $SSH_OPTS ${NODE[$N]} "for f in $*; do if [ -f $REMOTE_DIR/\$f ]; then echo \"Not deleted file \$f on node #$N\" 1>&2; exit 1; fi; done"
}
#
# copy_files_to_node -- copy all required files to the given remote node
# usage: copy_files_to_node <node> <destination dir> <file_1> [<file_2>] ...
#
function copy_files_to_node() {
validate_node_number $1
local N=$1
local DEST_DIR=$2
shift 2
[ $# -eq 0 ] &&\
fatal "error: copy_files_to_node(): no files provided"
# copy all required files
run_command scp $SCP_OPTS $@ ${NODE[$N]}:$DEST_DIR > /dev/null
return 0
}
#
# copy_files_from_node -- copy all required files from the given remote node
# usage: copy_files_from_node <node> <destination_dir> <file_1> [<file_2>] ...
#
function copy_files_from_node() {
validate_node_number $1
local N=$1
local DEST_DIR=$2
[ ! -d $DEST_DIR ] &&\
fatal "error: destination directory $DEST_DIR does not exist"
shift 2
[ $# -eq 0 ] &&\
fatal "error: copy_files_from_node(): no files provided"
# compress required files, copy and extract
local temp_file=node_${N}_temp_file.tar
files=""
dir_name=""
files=$(basename -a $@)
dir_name=$(dirname $1)
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $dir_name && tar -czf $temp_file $files"
run_command scp $SCP_OPTS ${NODE[$N]}:$dir_name/$temp_file $DEST_DIR > /dev/null
cd $DEST_DIR \
&& tar -xzf $temp_file \
&& rm $temp_file \
&& cd - > /dev/null
return 0
}
#
# copy_log_files -- copy log files from remote node
#
function copy_log_files() {
local NODE_SCP_LOG_FILES[0]=""
for N in $NODES_SEQ; do
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
for file in ${NODE_LOG_FILES[$N]}; do
NODE_SCP_LOG_FILES[$N]="${NODE_SCP_LOG_FILES[$N]} ${NODE[$N]}:$DIR/${file}"
done
[ "${NODE_SCP_LOG_FILES[$N]}" ] && run_command scp $SCP_OPTS ${NODE_SCP_LOG_FILES[$N]} . &>> $PREP_LOG_FILE
for file in ${NODE_LOG_FILES[$N]}; do
[ -f $file ] && mv $file node_${N}_${file}
done
done
}
#
# rm_files_from_node -- removes all listed files from the given remote node
# usage: rm_files_from_node <node> <file_1> [<file_2>] ...
#
function rm_files_from_node() {
validate_node_number $1
local N=$1
shift
[ $# -eq 0 ] &&\
fatal "error: rm_files_from_node(): no files provided"
run_command ssh $SSH_OPTS ${NODE[$N]} "rm -f $@"
return 0
}
#
#
# require_node_log_files -- store log files which must be copied from
# specified node on failure
#
function require_node_log_files() {
validate_node_number $1
local N=$1
shift
NODE_LOG_FILES[$N]="${NODE_LOG_FILES[$N]} $*"
}
#
# require_ctrld_err -- store ctrld's log files to copy from specified
# node on failure
#
function require_ctrld_err() {
local N=$1
local PID_FILE=$2
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
for cmd in run wait kill wait_port; do
NODE_LOG_FILES[$N]="${NODE_LOG_FILES[$N]} $PID_FILE.$cmd.ctrld.log"
done
}
#
# run_on_node -- usage: run_on_node <node> <command>
#
# Run the <command> in background on the remote <node>.
# LD_LIBRARY_PATH for the n-th remote node can be provided
# in the array NODE_LD_LIBRARY_PATH[n]
#
function run_on_node() {
validate_node_number $1
local N=$1
shift
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
local COMMAND="UNITTEST_NUM=$UNITTEST_NUM UNITTEST_NAME=$UNITTEST_NAME"
COMMAND="$COMMAND UNITTEST_LOG_LEVEL=1"
COMMAND="$COMMAND ${NODE_ENV[$N]}"
COMMAND="$COMMAND PATH=$REMOTE_PATH"
COMMAND="$COMMAND LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[$N]}:$REMOTE_LD_LIBRARY_PATH $*"
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && $COMMAND"
ret=$?
if [ "$ret" -ne "0" ]; then
copy_log_files
fi
return $ret
}
#
# run_on_node_background -- usage:
# run_on_node_background <node> <pid-file> <command>
#
# Run the <command> in background on the remote <node>
# and create a <pid-file> for this process.
# LD_LIBRARY_PATH for the n-th remote node
# can be provided in the array NODE_LD_LIBRARY_PATH[n]
#
function run_on_node_background() {
validate_node_number $1
local N=$1
local PID_FILE=$2
shift
shift
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
local COMMAND="UNITTEST_NUM=$UNITTEST_NUM UNITTEST_NAME=$UNITTEST_NAME"
COMMAND="$COMMAND UNITTEST_LOG_LEVEL=1"
COMMAND="$COMMAND ${NODE_ENV[$N]}"
COMMAND="$COMMAND PATH=$REMOTE_PATH"
COMMAND="$COMMAND LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[$N]}:$REMOTE_LD_LIBRARY_PATH"
COMMAND="$COMMAND ../ctrld $PID_FILE run $RUNTEST_TIMEOUT $*"
# register the PID file to be cleaned in case of an error
NODE_PID_FILES[$N]="${NODE_PID_FILES[$N]} $PID_FILE"
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && $COMMAND"
ret=$?
if [ "$ret" -ne "0" ]; then
copy_log_files
fi
return $ret
}
#
# wait_on_node -- usage: wait_on_node <node> <pid-file> [<timeout>]
#
# Wait until the process with the <pid-file> on the <node>
# exits or <timeout> expires.
#
function wait_on_node() {
validate_node_number $1
local N=$1
local PID_FILE=$2
local TIMEOUT=$3
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && ../ctrld $PID_FILE wait $TIMEOUT"
ret=$?
if [ "$ret" -ne "0" ]; then
copy_log_files
fi
return $ret
}
#
# wait_on_node_port -- usage: wait_on_node_port <node> <pid-file> <portno>
#
# Wait until the process with the <pid-file> on the <node>
# opens the port <portno>.
#
function wait_on_node_port() {
validate_node_number $1
local N=$1
local PID_FILE=$2
local PORTNO=$3
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && ../ctrld $PID_FILE wait_port $PORTNO"
ret=$?
if [ "$ret" -ne "0" ]; then
copy_log_files
fi
return $ret
}
#
# kill_on_node -- usage: kill_on_node <node> <pid-file> <signo>
#
# Send the <signo> signal to the process with the <pid-file>
# on the <node>.
#
function kill_on_node() {
validate_node_number $1
local N=$1
local PID_FILE=$2
local SIGNO=$3
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
run_command ssh $SSH_OPTS ${NODE[$N]} "cd $DIR && ../ctrld $PID_FILE kill $SIGNO"
ret=$?
if [ "$ret" -ne "0" ]; then
copy_log_files
fi
return $ret
}
#
# obj_pool_desc_size -- returns the obj_pool_desc_size macro value
# in bytes which is two times the actual pagesize.
#
# This should be use to calculate the minimum zero size for pool
# creation on some tests.
#
function obj_pool_desc_size() {
echo "$(expr $(getconf PAGESIZE) \* 2)"
}
#
# log_pool_desc_size -- returns the minimum size of pool header
# in bytes which is two times the actual pagesize.
#
# This should be use to calculate the minimum zero size for pool
# creation on some tests.
#
function log_pool_desc_size() {
echo "$(expr $(getconf PAGESIZE) \* 2)"
}
#
# blk_pool_desc_size -- returns the minimum size of pool header
# in bytes which is two times the actual pagesize.
#
# This should be use to calculate the minimum zero size for pool
# creation on some tests.
#
function blk_pool_desc_size() {
echo "$(expr $(getconf PAGESIZE) \* 2)"
}
#
# create_holey_file_on_node -- create holey files of a given length
# usage: create_holey_file_on_node <node> <size>
#
# example, to create two files, each 1GB in size on node 0:
# create_holey_file_on_node 0 1G testfile1 testfile2
#
# Input unit size is in bytes with optional suffixes like k, KB, M, etc.
#
function create_holey_file_on_node() {
validate_node_number $1
local N=$1
size=$(convert_to_bytes $2)
shift 2
for file in $*
do
run_on_node $N truncate -s ${size} $file >> $PREP_LOG_FILE
done
}
#
# require_mmap_under_valgrind -- only allow script to continue if mapping is
# possible under Valgrind with required length
# (sum of required DAX devices size).
# This function is being called internally in
# setup() function.
#
function require_mmap_under_valgrind() {
local FILE_MAX_DAX_DEVICES="../tools/anonymous_mmap/max_dax_devices"
if [ -z "$REQUIRE_DAX_DEVICES" ]; then
return
fi
if [ ! -f "$FILE_MAX_DAX_DEVICES" ]; then
fatal "$FILE_MAX_DAX_DEVICES not found. Run make test."
fi
if [ "$REQUIRE_DAX_DEVICES" -gt "$(< $FILE_MAX_DAX_DEVICES)" ]; then
msg "$UNITTEST_NAME: SKIP: anonymous mmap under Valgrind not possible for $REQUIRE_DAX_DEVICES DAX device(s)."
exit 0
fi
}
#
# setup -- print message that test setup is commencing
#
function setup() {
DIR=$DIR$SUFFIX
# writes test working directory to temporary file
# that allows read location of data after test failure
if [ -f "$TEMP_LOC" ]; then
echo "$DIR" > $TEMP_LOC
fi
# test type must be explicitly specified
if [ "$req_test_type" != "1" ]; then
fatal "error: required test type is not specified"
fi
# fs type "none" must be explicitly enabled
if [ "$FS" = "none" -a "$req_fs_type" != "1" ]; then
exit 0
fi
# fs type "any" must be explicitly enabled
if [ "$FS" = "any" -a "$req_fs_type" != "1" ]; then
exit 0
fi
if [ "$CHECK_TYPE" != "none" ]; then
require_valgrind
# detect possible Valgrind mmap issues and skip uncertain tests
require_mmap_under_valgrind
export VALGRIND_LOG_FILE=$CHECK_TYPE${UNITTEST_NUM}.log
MCSTR="/$CHECK_TYPE"
else
MCSTR=""
fi
[ -n "$RPMEM_PROVIDER" ] && PROV="/$RPMEM_PROVIDER"
[ -n "$RPMEM_PM" ] && PM="/$RPMEM_PM"
msg "$UNITTEST_NAME: SETUP ($TEST/$REAL_FS/$BUILD$MCSTR$PROV$PM)"
for f in $(get_files ".*[a-zA-Z_]${UNITTEST_NUM}\.log"); do
rm -f $f
done
# $DIR has to be an absolute path
check_absolute_path
if [ "$FS" != "none" ]; then
if [ -d "$DIR" ]; then
rm $RM_ONEFS -rf -- $DIR
fi
mkdir -p $DIR
fi
if [ "$TM" = "1" ]; then
start_time=$($DATE +%s.%N)
fi
if [ "$DEVDAX_TO_LOCK" == 1 ]; then
lock_devdax
fi
export PMEMBLK_CONF="fallocate.at_create=0;"
export PMEMOBJ_CONF="fallocate.at_create=0;"
export PMEMLOG_CONF="fallocate.at_create=0;"
}
#
# check_log_empty -- if match file does not exist, assume log should be empty
#
function check_log_empty() {
if [ ! -f ${1}.match ] && [ $(get_size $1) -ne 0 ]; then
echo "unexpected output in $1"
dump_last_n_lines $1
exit 1
fi
}
#
# check_local -- check local test results (using .match files)
#
function check_local() {
if [ "$UT_SKIP_PRINT_MISMATCHED" == 1 ]; then
option=-q
fi
check_log_empty $ERR_LOG_FILE
FILES=$(get_files "[^0-9w]*${UNITTEST_NUM}\.log\.match")
if [ -n "$FILES" ]; then
../match $option $FILES
fi
}
#
# match -- execute match
#
function match() {
../match $@
}
#
# check -- check local or remote test results (using .match files)
#
function check() {
if [ $NODES_MAX -lt 0 ]; then
check_local
else
FILES=$(get_files "node_[0-9]+_[^0-9w]*${UNITTEST_NUM}\.log\.match")
local NODE_MATCH_FILES[0]=""
local NODE_SCP_MATCH_FILES[0]=""
for file in $FILES; do
local N=`echo $file | cut -d"_" -f2`
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
local FILE=`echo $file | cut -d"_" -f3 | sed "s/\.match$//g"`
validate_node_number $N
NODE_MATCH_FILES[$N]="${NODE_MATCH_FILES[$N]} $FILE"
NODE_SCP_MATCH_FILES[$N]="${NODE_SCP_MATCH_FILES[$N]} ${NODE[$N]}:$DIR/$FILE"
done
for N in $NODES_SEQ; do
[ "${NODE_SCP_MATCH_FILES[$N]}" ] && run_command scp $SCP_OPTS ${NODE_SCP_MATCH_FILES[$N]} . > /dev/null
for file in ${NODE_MATCH_FILES[$N]}; do
mv $file node_${N}_${file}
done
done
if [ "$UT_SKIP_PRINT_MISMATCHED" == 1 ]; then
option=-q
fi
for N in $NODES_SEQ; do
check_log_empty node_${N}_${ERR_LOG_FILE}
done
if [ -n "$FILES" ]; then
match $option $FILES
fi
fi
# Move logs to build folder
LOG_DIR=logs/$TEST/$REAL_FS/$BUILD$MCSTR$PROV$PM
if [ ! -d $LOG_DIR ]; then mkdir --parents $LOG_DIR; fi
for f in $(get_files ".*[a-zA-Z_]${UNITTEST_NUM}\.log"); do
mv -f $f $LOG_DIR/$f
done
}
#
# pass -- print message that the test has passed
#
function pass() {
if [ "$DEVDAX_TO_LOCK" == 1 ]; then
unlock_devdax
fi
if [ "$TM" = "1" ]; then
end_time=$($DATE +%s.%N)
start_time_sec=$($DATE -d "0 $start_time sec" +%s)
end_time_sec=$($DATE -d "0 $end_time sec" +%s)
days=$(((end_time_sec - start_time_sec) / (24*3600)))
days=$(printf "%03d" $days)
tm=$($DATE -d "0 $end_time sec - $start_time sec" +%H:%M:%S.%N)
tm=$(echo "$days:$tm" | sed -e "s/^000://g" -e "s/^00://g" -e "s/^00://g" -e "s/\([0-9]*\)\.\([0-9][0-9][0-9]\).*/\1.\2/")
tm="\t\t\t[$tm s]"
else
tm=""
fi
msg=$(interactive_green STDOUT "PASS")
if [ "$UNITTEST_LOG_LEVEL" -ge 1 ]; then
echo -e "$UNITTEST_NAME: $msg$tm"
fi
if [ "$FS" != "none" ]; then
rm $RM_ONEFS -rf -- $DIR
fi
}
# Length of pool file's signature
SIG_LEN=8
# Offset and length of pmemobj layout
LAYOUT_OFFSET=$(getconf PAGE_SIZE)
LAYOUT_LEN=1024
# Length of arena's signature
ARENA_SIG_LEN=16
# Signature of BTT Arena
ARENA_SIG="BTT_ARENA_INFO"
# Offset to first arena
ARENA_OFF=$(($(getconf PAGE_SIZE) * 2))
#
# check_file -- check if file exists and print error message if not
#
check_file()
{
if [ ! -f $1 ]
then
fatal "Missing file: ${1}"
fi
}
#
# check_files -- check if files exist and print error message if not
#
check_files()
{
for file in $*
do
check_file $file
done
}
#
# check_no_file -- check if file has been deleted and print error message if not
#
check_no_file()
{
if [ -f $1 ]
then
fatal "Not deleted file: ${1}"
fi
}
#
# check_no_files -- check if files has been deleted and print error message if not
#
check_no_files()
{
for file in $*
do
check_no_file $file
done
}
#
# get_size -- return size of file (0 if file does not exist)
#
get_size()
{
if [ ! -f $1 ]; then
echo "0"
else
stat $STAT_SIZE $1
fi
}
#
# get_mode -- return mode of file
#
get_mode()
{
stat $STAT_MODE $1
}
#
# check_size -- validate file size
#
check_size()
{
local size=$1
local file=$2
local file_size=$(get_size $file)
if [[ $size != $file_size ]]
then
fatal "error: wrong size ${file_size} != ${size}"
fi
}
#
# check_mode -- validate file mode
#
check_mode()
{
local mode=$1
local file=$2
local file_mode=$(get_mode $file)
if [[ $mode != $file_mode ]]
then
fatal "error: wrong mode ${file_mode} != ${mode}"
fi
}
#
# check_signature -- check if file contains specified signature
#
check_signature()
{
local sig=$1
local file=$2
local file_sig=$($DD if=$file bs=1 count=$SIG_LEN 2>/dev/null | tr -d \\0)
if [[ $sig != $file_sig ]]
then
fatal "error: $file: signature doesn't match ${file_sig} != ${sig}"
fi
}
#
# check_signatures -- check if multiple files contain specified signature
#
check_signatures()
{
local sig=$1
shift 1
for file in $*
do
check_signature $sig $file
done
}
#
# check_layout -- check if pmemobj pool contains specified layout
#
check_layout()
{
local layout=$1
local file=$2
local file_layout=$($DD if=$file bs=1\
skip=$LAYOUT_OFFSET count=$LAYOUT_LEN 2>/dev/null | tr -d \\0)
if [[ $layout != $file_layout ]]
then
fatal "error: layout doesn't match ${file_layout} != ${layout}"
fi
}
#
# check_arena -- check if file contains specified arena signature
#
check_arena()
{
local file=$1
local sig=$($DD if=$file bs=1 skip=$ARENA_OFF count=$ARENA_SIG_LEN 2>/dev/null | tr -d \\0)
if [[ $sig != $ARENA_SIG ]]
then
fatal "error: can't find arena signature"
fi
}
#
# dump_pool_info -- dump selected pool metadata and/or user data
#
function dump_pool_info() {
# ignore selected header fields that differ by definition
${PMEMPOOL}.static-nondebug info $* | sed -e "/^UUID/,/^Checksum/d"
}
#
# compare_replicas -- check replicas consistency by comparing `pmempool info` output
#
function compare_replicas() {
disable_exit_on_error
diff <(dump_pool_info $1 $2) <(dump_pool_info $1 $3) -I "^path" -I "^size"
restore_exit_on_error
}
#
# get_node_dir -- returns node dir for current test
# usage: get_node_dir <node>
#
function get_node_dir() {
validate_node_number $1
echo ${NODE_WORKING_DIR[$1]}/$curtestdir
}
#
# init_rpmem_on_node -- prepare rpmem environment variables on node
# usage: init_rpmem_on_node <master-node> <slave-node-1> [<slave-node-2> ...]
#
# example:
# The following command initialize rpmem environment variables on the node 1
# to perform replication to node 0, node 2 and node 3.
# Additionally:
# - on node 2 rpmemd pid will be stored in file.pid
# - on node 3 no pid file will be created (SKIP) and rpmemd will use
# file.conf config file
#
# init_rpmem_on_node 1 0 2:file.pid 3:SKIP:file.conf
#
function init_rpmem_on_node() {
local master=$1
shift
validate_node_number $master
case "$RPMEM_PM" in
APM|GPSPM)
;;
*)
msg "$UNITTEST_NAME: SKIP required: RPMEM_PM is invalid or empty"
exit 0
;;
esac
# Workaround for SIGSEGV in the infinipath-psm during abort
# The infinipath-psm is registering a signal handler and do not unregister
# it when rpmem handle is dlclosed. SIGABRT (potentially any other signal)
# would try to call the signal handler which does not exist after dlclose.
# Issue require a fix in the infinipath-psm or the libfabric.
IPATH_NO_BACKTRACE=1
export_vars_node $master IPATH_NO_BACKTRACE
RPMEM_CMD=""
local SEPARATOR="|"
for slave in "$@"
do
slave=(${slave//:/ })
conf=${slave[2]}
pid=${slave[1]}
slave=${slave[0]}
validate_node_number $slave
local poolset_dir=${NODE_DIR[$slave]}
if [ -n "${RPMEM_POOLSET_DIR[$slave]}" ]; then
poolset_dir=${RPMEM_POOLSET_DIR[$slave]}
fi
local trace=
if [ -n "$(is_valgrind_enabled_on_node $slave)" ]; then
log_file=${CHECK_TYPE}${UNITTEST_NUM}.log
trace=$(get_trace $CHECK_TYPE $log_file $slave)
fi
if [ -n "$pid" -a "$pid" != "SKIP" ]; then
trace="$trace ../ctrld $pid exe"
fi
if [ -n ${UNITTEST_DO_NOT_CHECK_OPEN_FILES+x} ]; then
export_vars_node $slave UNITTEST_DO_NOT_CHECK_OPEN_FILES
fi
if [ -n ${IPATH_NO_BACKTRACE+x} ]; then
export_vars_node $slave IPATH_NO_BACKTRACE
fi
CMD="cd ${NODE_TEST_DIR[$slave]} && "
# Force pmem for APM. Otherwise in case of lack of a pmem rpmemd will
# silently fallback to GPSPM.
[ "$RPMEM_PM" == "APM" ] && CMD="$CMD PMEM_IS_PMEM_FORCE=1"
CMD="$CMD ${NODE_ENV[$slave]}"
CMD="$CMD PATH=$REMOTE_PATH"
CMD="$CMD LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[$slave]}:$REMOTE_LD_LIBRARY_PATH"
CMD="$CMD $trace ../rpmemd"
CMD="$CMD --log-file=$RPMEMD_LOG_FILE"
CMD="$CMD --log-level=$RPMEMD_LOG_LEVEL"
CMD="$CMD --poolset-dir=$poolset_dir"
if [ -n "$conf" ]; then
CMD="$CMD --config=$conf"
fi
if [ "$RPMEM_PM" == "APM" ]; then
CMD="$CMD --persist-apm"
fi
if [ "$RPMEM_CMD" ]; then
RPMEM_CMD="$RPMEM_CMD$SEPARATOR$CMD"
else
RPMEM_CMD=$CMD
fi
require_node_log_files $slave rpmemd$UNITTEST_NUM.log
done
RPMEM_CMD="\"$RPMEM_CMD\""
RPMEM_ENABLE_SOCKETS=0
RPMEM_ENABLE_VERBS=0
case "$RPMEM_PROVIDER" in
sockets)
RPMEM_ENABLE_SOCKETS=1
;;
verbs)
RPMEM_ENABLE_VERBS=1
;;
*)
msg "$UNITTEST_NAME: SKIP required: RPMEM_PROVIDER is invalid or empty"
exit 0
;;
esac
export_vars_node $master RPMEM_CMD
export_vars_node $master RPMEM_ENABLE_SOCKETS
export_vars_node $master RPMEM_ENABLE_VERBS
if [ -n ${UNITTEST_DO_NOT_CHECK_OPEN_FILES+x} ]; then
export_vars_node $master UNITTEST_DO_NOT_CHECK_OPEN_FILES
fi
if [ -n ${PMEMOBJ_NLANES+x} ]; then
export_vars_node $master PMEMOBJ_NLANES
fi
if [ -n ${RPMEM_MAX_NLANES+x} ]; then
export_vars_node $master RPMEM_MAX_NLANES
fi
require_node_log_files $master rpmem$UNITTEST_NUM.log
require_node_log_files $master $PMEMOBJ_LOG_FILE
}
#
# init_valgrind_on_node -- prepare valgrind on nodes
# usage: init_valgrind_on_node <node list>
#
function init_valgrind_on_node() {
# When librpmem is preloaded libfabric does not close all opened files
# before list of opened files is checked.
local UNITTEST_DO_NOT_CHECK_OPEN_FILES=1
local LD_PRELOAD=../$BUILD/librpmem.so
CHECK_NODES=""
for node in "$@"
do
validate_node_number $node
export_vars_node $node LD_PRELOAD
export_vars_node $node UNITTEST_DO_NOT_CHECK_OPEN_FILES
CHECK_NODES="$CHECK_NODES $node"
done
}
#
# is_valgrind_enabled_on_node -- echo the node number if the node has
# initialized valgrind environment by calling
# init_valgrind_on_node
# usage: is_valgrind_enabled_on_node <node>
#
function is_valgrind_enabled_on_node() {
for node in $CHECK_NODES
do
if [ "$node" -eq "$1" ]; then
echo $1
return
fi
done
return
}
#
# pack_all_libs -- put all libraries and their links to one tarball
#
function pack_all_libs() {
local LIBS_TAR_DIR=$(pwd)/$1
cd $DIR_SRC
tar -cf $LIBS_TAR_DIR ./debug/*.so* ./nondebug/*.so*
cd - > /dev/null
}
#
# copy_common_to_remote_nodes -- copy common files to all remote nodes
#
function copy_common_to_remote_nodes() {
local NODES_ALL_MAX=$((${#NODE[@]} - 1))
local NODES_ALL_SEQ=$(seq -s' ' 0 $NODES_ALL_MAX)
DIR_SYNC=$1
if [ "$DIR_SYNC" != "" ]; then
[ ! -d $DIR_SYNC ] \
&& fatal "error: $DIR_SYNC does not exist or is not a directory"
fi
# add all libraries to the 'to-copy' list
local LIBS_TAR=libs.tar
pack_all_libs $LIBS_TAR
if [ "$DIR_SYNC" != "" -a "$(ls $DIR_SYNC)" != "" ]; then
FILES_COMMON_DIR="$DIR_SYNC/* $LIBS_TAR"
else
FILES_COMMON_DIR="$FILES_COMMON_DIR $LIBS_TAR"
fi
for N in $NODES_ALL_SEQ; do
# validate node's address
[ "${NODE[$N]}" = "" ] \
&& fatal "error: address of node #$N is not provided"
check_if_node_is_reachable $N
[ $? -ne 0 ] \
&& msg "warning: node #$N (${NODE[$N]}) is unreachable, skipping..." \
&& continue
# validate the working directory
[ "${NODE_WORKING_DIR[$N]}" = "" ] \
&& msg ": warning: working directory for node #$N (${NODE[$N]}) is not provided, skipping..." \
&& continue
# create the working dir if it does not exist
run_command ssh $SSH_OPTS ${NODE[$N]} "mkdir -p ${NODE_WORKING_DIR[$N]}"
# copy all common files
run_command scp $SCP_OPTS $FILES_COMMON_DIR ${NODE[$N]}:${NODE_WORKING_DIR[$N]} > /dev/null
# unpack libraries
run_command ssh $SSH_OPTS ${NODE[$N]} "cd ${NODE_WORKING_DIR[$N]} \
&& tar -xf $LIBS_TAR && rm -f $LIBS_TAR"
done
rm -f $LIBS_TAR
}
#
# copy_test_to_remote_nodes -- copy all unit test binaries to all remote nodes
#
function copy_test_to_remote_nodes() {
local NODES_ALL_MAX=$((${#NODE[@]} - 1))
local NODES_ALL_SEQ=$(seq -s' ' 0 $NODES_ALL_MAX)
for N in $NODES_ALL_SEQ; do
# validate node's address
[ "${NODE[$N]}" = "" ] \
&& fatal "error: address of node #$N is not provided"
check_if_node_is_reachable $N
[ $? -ne 0 ] \
&& msg "warning: node #$N (${NODE[$N]}) is unreachable, skipping..." \
&& continue
# validate the working directory
[ "${NODE_WORKING_DIR[$N]}" = "" ] \
&& msg ": warning: working directory for node #$N (${NODE[$N]}) is not provided, skipping..." \
&& continue
local DIR=${NODE_WORKING_DIR[$N]}/$curtestdir
# create a new test dir
run_command ssh $SSH_OPTS ${NODE[$N]} "rm -rf $DIR && mkdir -p $DIR"
# create the working data dir
run_command ssh $SSH_OPTS ${NODE[$N]} "mkdir -p \
${DIR}/data"
# copy all required files
[ $# -gt 0 ] && run_command scp $SCP_OPTS $* ${NODE[$N]}:$DIR > /dev/null
done
return 0
}
#
# enable_log_append -- turn on appending to the log files rather than truncating them
# It also removes all log files created by tests: out*.log, err*.log and trace*.log
#
function enable_log_append() {
rm -f $OUT_LOG_FILE
rm -f $ERR_LOG_FILE
rm -f $TRACE_LOG_FILE
export UNITTEST_LOG_APPEND=1
}
# clean data directory on all remote
# nodes if remote test failed
if [ "$CLEAN_FAILED_REMOTE" == "y" ]; then
NODES_ALL=$((${#NODE[@]} - 1))
MYPID=$$
for ((i=0;i<=$NODES_ALL;i++));
do
if [[ -z "${NODE_WORKING_DIR[$i]}" || -z "$curtestdir" ]]; then
echo "Invalid path to tests data: ${NODE_WORKING_DIR[$i]}/$curtestdir/data/"
exit 1
fi
N[$i]=${NODE_WORKING_DIR[$i]}/$curtestdir/data/
run_command ssh $SSH_OPTS ${NODE[$i]} "rm -rf ${N[$i]}; mkdir ${N[$i]}"
if [ $? -eq 0 ]; then
verbose_msg "Removed data from: ${NODE[$i]}:${N[$i]}"
fi
done
exit 0
fi
# calculate the minimum of two or more numbers
minimum() {
local min=$1
shift
for val in $*; do
if [[ "$val" < "$min" ]]; then
min=$val
fi
done
echo $min
}
#
# count_lines - count number of lines that match pattern $1 in file $2
#
function count_lines() {
# grep returns 1 on no match
disable_exit_on_error
$GREP -ce "$1" $2
restore_exit_on_error
}
#
# get_pmemcheck_version() - return pmemcheck API major or minor version
# usage: get_pmemcheck_version <0|1>
#
function get_pmemcheck_version()
{
PMEMCHECK_VERSION=$($VALGRINDEXE --tool=pmemcheck true 2>&1 \
| head -n 1 | sed "s/.*-\([0-9.]*\),.*/\1/")
OIFS=$IFS
IFS="."
PMEMCHECK_MAJ_MIN=($PMEMCHECK_VERSION)
IFS=$OIFS
PMEMCHECK_VERSION_PART=${PMEMCHECK_MAJ_MIN[$1]}
echo "$PMEMCHECK_VERSION_PART"
}
#
# require_pmemcheck_version_ge - check if pmemcheck API
# version is greater or equal to required value
# usage: require_pmemcheck_version_ge <major> <minor> [binary]
#
function require_pmemcheck_version_ge()
{
require_valgrind_tool pmemcheck $3
REQUIRE_MAJOR=$1
REQUIRE_MINOR=$2
PMEMCHECK_MAJOR=$(get_pmemcheck_version 0)
PMEMCHECK_MINOR=$(get_pmemcheck_version 1)
# compare MAJOR
if [ $PMEMCHECK_MAJOR -gt $REQUIRE_MAJOR ]; then
return 0
fi
# compare MINOR
if [ $PMEMCHECK_MAJOR -eq $REQUIRE_MAJOR ]; then
if [ $PMEMCHECK_MINOR -ge $REQUIRE_MINOR ]; then
return 0
fi
fi
msg "$UNITTEST_NAME: SKIP pmemcheck API version:" \
"$PMEMCHECK_MAJOR.$PMEMCHECK_MINOR" \
"is less than required" \
"$REQUIRE_MAJOR.$REQUIRE_MINOR"
exit 0
}
#
# require_pmemcheck_version_lt - check if pmemcheck API
# version is less than required value
# usage: require_pmemcheck_version_lt <major> <minor> [binary]
#
function require_pmemcheck_version_lt()
{
require_valgrind_tool pmemcheck $3
REQUIRE_MAJOR=$1
REQUIRE_MINOR=$2
PMEMCHECK_MAJOR=$(get_pmemcheck_version 0)
PMEMCHECK_MINOR=$(get_pmemcheck_version 1)
# compare MAJOR
if [ $PMEMCHECK_MAJOR -lt $REQUIRE_MAJOR ]; then
return 0
fi
# compare MINOR
if [ $PMEMCHECK_MAJOR -eq $REQUIRE_MAJOR ]; then
if [ $PMEMCHECK_MINOR -lt $REQUIRE_MINOR ]; then
return 0
fi
fi
msg "$UNITTEST_NAME: SKIP pmemcheck API version:" \
"$PMEMCHECK_MAJOR.$PMEMCHECK_MINOR" \
"is greater or equal than" \
"$REQUIRE_MAJOR.$REQUIRE_MINOR"
exit 0
}
#
# require_python_3 -- check if python3 is available
#
function require_python3()
{
if hash python3 &>/dev/null;
then
PYTHON_EXE=python3
else
PYTHON_EXE=python
fi
case "$($PYTHON_EXE --version 2>&1)" in
*" 3."*)
return
;;
*)
msg "$UNITTEST_NAME: SKIP: required python version 3"
exit 0
;;
esac
}
#
# require_pmreorder -- check all necessary conditions to run pmreorder
# usage: require_pmreorder [binary]
#
function require_pmreorder()
{
# python3 and valgrind are necessary
require_python3
# pmemcheck is required to generate store_log
configure_valgrind pmemcheck force-enable $1
# pmreorder tool does not support unicode yet
require_no_unicode
}
#
# pmreorder_run_tool -- run pmreorder with parameters and return exit status
#
# 1 - reorder engine type [nochecker|full|noreorder|partial|accumulative]
# 2 - marker-engine pairs in format: MARKER=ENGINE,MARKER1=ENGINE1 or
# config file in json format: { "MARKER":"ENGINE","MARKER1":"ENGINE1" }
# 3 - the path to the checker binary/library and remaining parameters which
# will be passed to the consistency checker binary.
# If you are using a library checker, prepend '-n funcname'
#
function pmreorder_run_tool()
{
rm -f pmreorder$UNITTEST_NUM.log
disable_exit_on_error
$PYTHON_EXE $PMREORDER \
-l store_log$UNITTEST_NUM.log \
-o pmreorder$UNITTEST_NUM.log \
-r $1 \
-x $2 \
-p "$3"
ret=$?
restore_exit_on_error
echo $ret
}
#
# pmreorder_expect_success -- run pmreoreder with forwarded parameters,
# expect it to exit zero
#
function pmreorder_expect_success()
{
ret=$(pmreorder_run_tool "$@" | tail -n1)
if [ "$ret" -ne "0" ]; then
msg=$(interactive_red STDERR "failed with exit code $ret")
# exit code 130 - script terminated by user (Control-C)
if [ "$ret" -ne "130" ]; then
echo -e "$UNITTEST_NAME $msg." >&2
dump_last_n_lines $PMREORDER_LOG_FILE
fi
false
fi
}
#
# pmreorder_expect_failure -- run pmreoreder with forwarded parameters,
# expect it to exit non zero
#
function pmreorder_expect_failure()
{
ret=$(pmreorder_run_tool "$@" | tail -n1)
if [ "$ret" -eq "0" ]; then
msg=$(interactive_red STDERR "succeeded")
echo -e "$UNITTEST_NAME command $msg unexpectedly." >&2
false
fi
}
#
# pmreorder_create_store_log -- perform a reordering test
#
# This function expects 5 additional parameters. They are in order:
# 1 - the pool file to be tested
# 2 - the application and necessary parameters to run pmemcheck logging
#
function pmreorder_create_store_log()
{
#copy original file and perform store logging
cp $1 "$1.pmr"
rm -f store_log$UNITTEST_NUM.log
$VALGRINDEXE \
--tool=pmemcheck -q \
--log-stores=yes \
--print-summary=no \
--log-file=store_log$UNITTEST_NUM.log \
--log-stores-stacktraces=yes \
--log-stores-stacktraces-depth=2 \
--expect-fence-after-clflush=yes \
$2
# uncomment this line for debug purposes
# mv $1 "$1.bak"
mv "$1.pmr" $1
}
#
# require_free_space -- check if there is enough free space to run the test
# Example, checking if there is 1 GB of free space on disk:
# require_free_space 1G
#
function require_free_space() {
req_free_space=$(convert_to_bytes $1)
# actually require 5% or 8MB (whichever is higher) more, just in case
# file system requires some space for its meta data
pct=$((5 * $req_free_space / 100))
abs=$(convert_to_bytes 8M)
if [ $pct -gt $abs ]; then
req_free_space=$(($req_free_space + $pct))
else
req_free_space=$(($req_free_space + $abs))
fi
output=$(df -k $DIR)
found=false
i=1
for elem in $(echo "$output" | head -1); do
if [ ${elem:0:5} == "Avail" ]; then
found=true
break
else
let "i+=1"
fi
done
if [ $found = true ]; then
row=$(echo "$output" | tail -1)
free_space=$(( $(echo $row | awk "{print \$$i}")*1024 ))
else
msg "$UNITTEST_NAME: SKIP: unable to check free space"
exit 0
fi
if [ $free_space -lt $req_free_space ]; then
msg "$UNITTEST_NAME: SKIP: not enough free space ($1 required)"
exit 0
fi
}
#
# require_max_devdax_size -- checks that dev dax is smaller than requested
#
# usage: require_max_devdax_size <dev-dax-num> <max-size>
#
function require_max_devdax_size() {
cur_sz=$(get_devdax_size 0)
max_size=$2
if [ $cur_sz -ge $max_size ]; then
msg "$UNITTEST_NAME: SKIP: DevDAX $1 is too big for this test (max $2 required)"
exit 0
fi
}
#
# require_max_block_size -- checks that block size is smaller or equal than requested
#
# usage: require_max_block_size <file> <max-block-size>
#
function require_max_block_size() {
cur_sz=$(stat --file-system --format=%S $1)
max_size=$2
if [ $cur_sz -gt $max_size ]; then
msg "$UNITTEST_NAME: SKIP: block size of $1 is too big for this test (max $2 required)"
exit 0
fi
}
#
# require_badblock_tests_enabled - check if tests for bad block support are not enabled
# Input arguments:
# 1) test device type
#
function require_badblock_tests_enabled() {
require_sudo_allowed
require_command ndctl
require_bb_enabled_by_default $PMEMPOOL$EXESUFFIX
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
require_kernel_module nfit_test
# nfit_test dax device is created by the test and is
# used directly - no device dax path is needed to be provided by the
# user. Some tests though may use an additional filesystem for the
# pool replica - hence 'any' filesystem is required.
if [ $1 == "dax_device" ]; then
require_fs_type any
# nfit_test block device is created by the test and mounted on
# a filesystem of any type provided by the user
elif [ $1 == "block_device" ]; then
require_fs_type any
fi
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
if [ $1 == "dax_device" ]; then
require_fs_type any
require_dax_devices 1
require_binary $DAXIO$EXESUFFIX
elif [ $1 == "block_device" ]; then
require_fs_type pmem
fi
else
msg "$UNITTEST_NAME: SKIP: bad block tests are not enabled in testconfig.sh"
exit 0
fi
}
#
# require_badblock_tests_enabled_node - check if tests for bad block support are not enabled
# on given remote node
#
function require_badblock_tests_enabled_node() {
require_sudo_allowed_node $1
require_command_node $1 ndctl
require_bb_enabled_by_default $PMEMPOOL$EXESUFFIX
if [ "$BADBLOCK_TEST_TYPE" == "nfit_test" ]; then
require_kernel_module_node $1 nfit_test
elif [ "$BADBLOCK_TEST_TYPE" == "real_pmem" ]; then
:
else
msg "$UNITTEST_NAME: SKIP: bad block tests are not enabled in testconfig.sh"
exit 0
fi
require_sudo_allowed
require_kernel_module nfit_test
require_command ndctl
}
#
# create_recovery_file - create bad block recovery file
#
# Usage: create_recovery_file <file> [<offset_1> <length_1> ...]
#
# Offsets and length should be in page sizes.
#
function create_recovery_file() {
[ $# -lt 1 ] && fatal "create_recovery_file(): not enough parameters: $*"
FILE=$1
shift
rm -f $FILE
while [ $# -ge 2 ]; do
OFFSET=$1
LENGTH=$2
shift 2
echo "$(($OFFSET * $PAGE_SIZE)) $(($LENGTH * $PAGE_SIZE))" >> $FILE
done
# write the finish flag
echo "0 0" >> $FILE
}
#
# zero_blocks - zero blocks in a file
#
# Usage: zero_blocks <file> <offset> <length>
#
# Offsets and length should be in page sizes.
#
function zero_blocks() {
[ $# -lt 3 ] && fatal "zero_blocks(): not enough parameters: $*"
FILE=$1
shift
while [ $# -ge 2 ]; do
OFFSET=$1
LENGTH=$2
shift 2
dd if=/dev/zero of=$FILE bs=$PAGE_SIZE seek=$OFFSET count=$LENGTH conv=notrunc status=none
done
}
#
# turn_on_checking_bad_blocks -- set the compat_feature POOL_FEAT_CHECK_BAD_BLOCKS on
#
function turn_on_checking_bad_blocks()
{
FILE=$1
expect_normal_exit "$PMEMPOOL feature -e CHECK_BAD_BLOCKS $FILE &>> $PREP_LOG_FILE"
}
#
# turn_on_checking_bad_blocks_node -- set the compat_feature POOL_FEAT_CHECK_BAD_BLOCKS on
#
function turn_on_checking_bad_blocks_node()
{
FILE=$2
expect_normal_exit run_on_node $1 "../pmempool feature -e CHECK_BAD_BLOCKS $FILE &>> $PREP_LOG_FILE"
}
| 95,035 | 23.943832 | 153 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/unittest/ut_pmem2_setup_integration.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* ut_pmem2_setup_integration.h -- libpmem2 setup functions using public API
* (for integration tests)
*/
#ifndef UT_PMEM2_SETUP_INTEGRATION_H
#define UT_PMEM2_SETUP_INTEGRATION_H 1
#include "ut_fh.h"
/* a prepare_config() that can't set wrong value */
#define PMEM2_PREPARE_CONFIG_INTEGRATION(cfg, src, fd, g) \
ut_pmem2_prepare_config_integration( \
__FILE__, __LINE__, __func__, cfg, src, fd, g)
void ut_pmem2_prepare_config_integration(const char *file, int line,
const char *func, struct pmem2_config **cfg, struct pmem2_source **src,
int fd, enum pmem2_granularity granularity);
#endif /* UT_PMEM2_SETUP_INTEGRATION_H */
| 728 | 29.375 | 76 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_memblock/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016, Intel Corporation */
/*
* mocks_windows.h -- redefinitions of memops functions
*
* This file is Windows-specific.
*
* This file should be included (i.e. using Forced Include) by libpmemobj
* files, when compiled for the purpose of obj_memblock test.
* It would replace default implementation with mocked functions defined
* in obj_memblock.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define operation_add_typed_entry __wrap_operation_add_typed_entry
#define operation_add_entry __wrap_operation_add_entry
#endif
| 634 | 29.238095 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_sds/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2020, Intel Corporation */
/*
* mocks_windows.h -- redefinitions of dimm functions
*/
#ifndef WRAP_REAL
#define pmem2_source_device_usc __wrap_pmem2_source_device_usc
#define pmem2_source_device_idU __wrap_pmem2_source_device_id
#endif
| 299 | 24 | 62 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/util_sds/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2020, Intel Corporation */
/*
* mocks_windows.h -- redefinitions of dimm functions
*/
#ifndef WRAP_REAL
#define pmem2_source_device_usc __wrap_pmem2_source_device_usc
#define pmem2_source_device_idU __wrap_pmem2_source_device_id
#endif
| 299 | 24 | 62 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_tx_add_range/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# obj_tx_add_range/config.sh -- test configuration
#
# Extend timeout for this test, as it may take a few minutes
# when run on a non-pmem file system.
CONF_GLOBAL_TIMEOUT='10m'
| 281 | 19.142857 | 60 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem_has_auto_flush_win/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018, Intel Corporation */
/*
* 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
| 988 | 33.103448 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem_has_auto_flush_win/pmem_has_auto_flush_win.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018, Intel Corporation */
/*
* 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
| 338 | 20.1875 | 61 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/ex_librpmem_fibonacci/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# ex_librpmem_fibonacci/config.sh -- test configuration
#
# Filesystem-DAX cannot be used for RDMA
# since it is missing support in Linux kernel
CONF_GLOBAL_FS_TYPE=non-pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=medium
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
CONF_TEST_TYPE[2]=long
| 431 | 20.6 | 55 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_heap_interrupt/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* 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
| 578 | 27.95 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_list/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* 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
| 1,933 | 26.628571 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_list/obj_list.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2018, Intel Corporation */
/*
* 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>")
| 2,314 | 21.475728 | 59 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/blk_rw_mt/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# blk_rw_mt/config.sh -- test configuration
#
# Extend timeout for this test, as it may take a few minutes
# when run on a non-pmem file system.
CONF_GLOBAL_TIMEOUT='10m'
| 274 | 18.642857 | 60 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/ex_librpmem_hello/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# ex_librpmem_hello/config.sh -- test configuration
#
# Filesystem-DAX cannot be used for RDMA
# since it is missing support in Linux kernel
CONF_GLOBAL_FS_TYPE=non-pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=short
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 402 | 21.388889 | 51 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/ex_librpmem_manpage/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# ex_librpmem_manpage/config.sh -- test configuration
#
# Filesystem-DAX cannot be used for RDMA
# since it is missing support in Linux kernel
CONF_GLOBAL_FS_TYPE=non-pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=short
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 404 | 21.5 | 53 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_persist_count/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* 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
| 1,130 | 34.34375 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/compat_incompat_features/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2019, Intel Corporation
#
#
# compat_incompat_features/common.sh -- common stuff for compat/incompat feature
# flags tests
#
ERR=err${UNITTEST_NUM}.log
ERR_TEMP=err${UNITTEST_NUM}_part.log
LOG=out${UNITTEST_NUM}.log
LOG_TEMP=out${UNITTEST_NUM}_part.log
rm -f $LOG && touch $LOG
rm -f $LOG_TEMP && touch $LOG_TEMP
rm -f $ERR && touch $ERR
rm -f $ERR_TEMP && touch $ERR_TEMP
LAYOUT=OBJ_LAYOUT$SUFFIX
POOLSET=$DIR/pool.set
POOL_TYPES=(obj blk log)
# pmempool create arguments:
declare -A create_args
create_args[obj]="obj $POOLSET"
create_args[blk]="blk 512 $POOLSET"
create_args[log]="log $POOLSET"
# Known compat flags:
# Known incompat flags:
let "POOL_FEAT_SINGLEHDR = 0x0001"
let "POOL_FEAT_CKSUM_2K = 0x0002"
let "POOL_FEAT_SDS = 0x0004"
# Unknown compat flags:
UNKNOWN_COMPAT=(2 4 8 1024)
# Unknown incompat flags:
UNKNOWN_INCOMPAT=(8 15 1111)
# set compat flags in header
set_compat() {
local part=$1
local flag=$2
expect_normal_exit $PMEMSPOIL $part pool_hdr.features.compat=$flag \
"pool_hdr.f:checksum_gen"
}
# set incompat flags in header
set_incompat() {
local part=$1
local flag=$2
expect_normal_exit $PMEMSPOIL $part pool_hdr.features.incompat=$flag \
"pool_hdr.f:checksum_gen"
}
| 1,326 | 22.280702 | 80 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/util_poolset/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2017, Intel Corporation */
/*
* 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
| 730 | 25.107143 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/util_poolset/mocks.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2015-2017, Intel Corporation */
#ifndef MOCKS_H
#define MOCKS_H
extern const char *Open_path;
extern os_off_t Fallocate_len;
extern size_t Is_pmem_len;
#endif
| 216 | 17.083333 | 44 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_direct/obj_direct.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017, Intel Corporation */
/*
* 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 */
| 316 | 18.8125 | 49 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_defrag_advanced/pgraph.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* pgraph.h -- persistent graph representation
*/
#ifndef OBJ_DEFRAG_ADV_PGRAPH
#define OBJ_DEFRAG_ADV_PGRAPH
#include <libpmemobj/base.h>
struct pgraph_params
{
unsigned graph_copies;
};
struct pnode_t
{
unsigned node_id;
unsigned edges_num;
size_t pattern_size;
size_t size;
PMEMoid edges[];
};
struct pgraph_t
{
unsigned nodes_num;
PMEMoid nodes[];
};
void pgraph_new(PMEMobjpool *pop, PMEMoid *oidp, struct vgraph_t *vgraph,
struct pgraph_params *params, rng_t *rngp);
void pgraph_delete(PMEMoid *oidp);
void pgraph_print(struct pgraph_t *graph, const char *dump);
#endif /* pgraph.h */
| 695 | 16.4 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_defrag_advanced/vgraph.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* vgraph.h -- volatile graph representation
*/
#ifndef OBJ_DEFRAG_ADV_VGRAPH
#define OBJ_DEFRAG_ADV_VGRAPH
#include "rand.h"
struct vgraph_params
{
unsigned max_nodes; /* max # of nodes per graph */
unsigned max_edges; /* max # of edges per node */
/* # of nodes is between [max_nodes - range_nodes, max_nodes] */
unsigned range_nodes;
/* # of edges is between [max_edges - range_edges, max_edges] */
unsigned range_edges;
unsigned min_pattern_size;
unsigned max_pattern_size;
};
struct vnode_t
{
unsigned node_id;
unsigned edges_num; /* # of edges starting from this node */
unsigned *edges; /* ids of nodes the edges are pointing to */
/* the persistent node attributes */
size_t pattern_size; /* size of the pattern allocated after the node */
size_t psize; /* the total size of the node */
};
struct vgraph_t
{
unsigned nodes_num;
struct vnode_t node[];
};
unsigned rand_range(unsigned min, unsigned max, rng_t *rngp);
struct vgraph_t *vgraph_new(struct vgraph_params *params, rng_t *rngp);
void vgraph_delete(struct vgraph_t *graph);
#endif
| 1,158 | 23.145833 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_tx_mt/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# obj_tx_mt/config.sh -- test configuration
#
# Extend timeout for this test, as it may take a few minutes
# when run on a non-pmem file system.
CONF_GLOBAL_TIMEOUT='10m'
| 274 | 18.642857 | 60 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem_map_file_win/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2017, Intel Corporation */
/*
* 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
| 608 | 28 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_rpmem_heap_state/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
#
# obj_rpmem_heap_state/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 290 | 19.785714 | 54 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_addr_ext/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# rpmem_addr_ext/config.sh -- test configuration file
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=GPSPM
| 289 | 19.714286 | 53 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_badblock_mocks/pmem2_badblock_mocks.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* pmem2_badblock_mocks.h -- definitions for pmem2_badblock_mocks test
*/
#include "extent.h"
/* fd bits 6-8: type of device */
#define FD_REG_FILE (1 << 6) /* regular file */
#define FD_CHR_DEV (2 << 6) /* character device */
#define FD_DIRECTORY (3 << 6) /* directory */
#define FD_BLK_DEV (4 << 6) /* block device */
/* fd bits 4-5: ndctl mode */
#define MODE_NO_DEVICE (1 << 4) /* did not found any matching device */
#define MODE_NAMESPACE (2 << 4) /* namespace mode */
#define MODE_REGION (3 << 4) /* region mode */
/* fd bits 0-3: number of test */
/* masks */
#define MASK_DEVICE 0b0111000000 /* bits 6-8: device mask */
#define MASK_MODE 0b0000110000 /* bits 4-5: mode mask */
#define MASK_TEST 0b0000001111 /* bits 0-3: test mask */
/* checks */
#define IS_MODE_NO_DEVICE(x) ((x & MASK_MODE) == MODE_NO_DEVICE)
#define IS_MODE_NAMESPACE(x) ((x & MASK_MODE) == MODE_NAMESPACE)
#define IS_MODE_REGION(x) ((x & MASK_MODE) == MODE_REGION)
/* default block size: 1kB */
#define BLK_SIZE_1KB 1024
/* default size of device: 1 GiB */
#define DEV_SIZE_1GB (1024 * 1024 * 1024)
struct badblock *get_nth_hw_badblock(unsigned test, unsigned *i_bb);
int get_extents(int fd, struct extents **exts);
| 1,290 | 31.275 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmemd_obc/setup.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2019, Intel Corporation
#
# src/test/rpmemd_obc/setup.sh -- common setup for rpmemd_obc tests
#
require_nodes 2
require_node_log_files 1 $RPMEM_LOG_FILE
RPMEM_CMD="\"cd ${NODE_TEST_DIR[0]} && UNITTEST_FORCE_QUIET=1"
RPMEM_CMD="$RPMEM_CMD RPMEMD_LOG_FILE=$RPMEMD_LOG_FILE"
RPMEM_CMD="$RPMEM_CMD RPMEMD_LOG_LEVEL=$RPMEMD_LOG_LEVEL"
RPMEM_CMD="$RPMEM_CMD LD_LIBRARY_PATH=${NODE_LD_LIBRARY_PATH[0]}:$REMOTE_LD_LIBRARY_PATH"
RPMEM_CMD="$RPMEM_CMD ./rpmemd_obc$EXESUFFIX\""
export_vars_node 1 RPMEM_CMD
| 578 | 29.473684 | 89 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmemd_obc/rpmemd_obc_test_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmemd_obc_test_common.h -- common declarations for rpmemd_obc test
*/
#include "unittest.h"
#include "librpmem.h"
#include "rpmem_proto.h"
#include "rpmem_common.h"
#include "rpmem_ssh.h"
#include "rpmem_util.h"
#include "rpmemd_log.h"
#include "rpmemd_obc.h"
#define PORT 1234
#define RKEY 0x0123456789abcdef
#define RADDR 0xfedcba9876543210
#define PERSIST_METHOD RPMEM_PM_APM
#define POOL_ATTR_INIT {\
.signature = "<RPMEM>",\
.major = 1,\
.compat_features = 2,\
.incompat_features = 3,\
.ro_compat_features = 4,\
.poolset_uuid = "POOLSET_UUID0123",\
.uuid = "UUID0123456789AB",\
.next_uuid = "NEXT_UUID0123456",\
.prev_uuid = "PREV_UUID0123456",\
.user_flags = "USER_FLAGS012345",\
}
#define POOL_ATTR_ALT {\
.signature = "<ALT>",\
.major = 5,\
.compat_features = 6,\
.incompat_features = 7,\
.ro_compat_features = 8,\
.poolset_uuid = "UUID_POOLSET_ALT",\
.uuid = "ALT_UUIDCDEFFEDC",\
.next_uuid = "456UUID_NEXT_ALT",\
.prev_uuid = "UUID012_ALT_PREV",\
.user_flags = "012345USER_FLAGS",\
}
#define POOL_SIZE 0x0001234567abcdef
#define NLANES 0x123
#define NLANES_RESP 16
#define PROVIDER RPMEM_PROV_LIBFABRIC_SOCKETS
#define POOL_DESC "pool.set"
#define BUFF_SIZE 8192
static const char pool_desc[] = POOL_DESC;
#define POOL_DESC_SIZE (sizeof(pool_desc) / sizeof(pool_desc[0]))
struct rpmem_ssh *clnt_connect(char *target);
void clnt_wait_disconnect(struct rpmem_ssh *ssh);
void clnt_send(struct rpmem_ssh *ssh, const void *buff, size_t len);
void clnt_recv(struct rpmem_ssh *ssh, void *buff, size_t len);
void clnt_close(struct rpmem_ssh *ssh);
enum conn_wait_close {
CONN_CLOSE,
CONN_WAIT_CLOSE,
};
void set_rpmem_cmd(const char *fmt, ...);
extern struct rpmemd_obc_requests REQ_CB;
struct req_cb_arg {
int resp;
unsigned long long types;
int force_ret;
int ret;
int status;
};
static const struct rpmem_msg_hdr MSG_HDR = {
.type = RPMEM_MSG_TYPE_CLOSE,
.size = sizeof(struct rpmem_msg_hdr),
};
static const struct rpmem_msg_create CREATE_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_CREATE,
.size = sizeof(struct rpmem_msg_create),
},
.c = {
.major = RPMEM_PROTO_MAJOR,
.minor = RPMEM_PROTO_MINOR,
.pool_size = POOL_SIZE,
.nlanes = NLANES,
.provider = PROVIDER,
.buff_size = BUFF_SIZE,
},
.pool_attr = POOL_ATTR_INIT,
.pool_desc = {
.size = POOL_DESC_SIZE,
},
};
static const struct rpmem_msg_open OPEN_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_OPEN,
.size = sizeof(struct rpmem_msg_open),
},
.c = {
.major = RPMEM_PROTO_MAJOR,
.minor = RPMEM_PROTO_MINOR,
.pool_size = POOL_SIZE,
.nlanes = NLANES,
.provider = PROVIDER,
.buff_size = BUFF_SIZE,
},
.pool_desc = {
.size = POOL_DESC_SIZE,
},
};
static const struct rpmem_msg_close CLOSE_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_CLOSE,
.size = sizeof(struct rpmem_msg_close),
},
};
static const struct rpmem_msg_set_attr SET_ATTR_MSG = {
.hdr = {
.type = RPMEM_MSG_TYPE_SET_ATTR,
.size = sizeof(struct rpmem_msg_set_attr),
},
.pool_attr = POOL_ATTR_ALT,
};
TEST_CASE_DECLARE(server_accept_sim);
TEST_CASE_DECLARE(server_accept_sim_fork);
TEST_CASE_DECLARE(client_accept_sim);
TEST_CASE_DECLARE(server_accept_seq);
TEST_CASE_DECLARE(server_accept_seq_fork);
TEST_CASE_DECLARE(client_accept_seq);
TEST_CASE_DECLARE(client_bad_msg_hdr);
TEST_CASE_DECLARE(server_bad_msg);
TEST_CASE_DECLARE(server_msg_noresp);
TEST_CASE_DECLARE(server_msg_resp);
TEST_CASE_DECLARE(client_econnreset);
TEST_CASE_DECLARE(server_econnreset);
TEST_CASE_DECLARE(client_create);
TEST_CASE_DECLARE(server_open);
TEST_CASE_DECLARE(client_close);
TEST_CASE_DECLARE(server_close);
TEST_CASE_DECLARE(client_open);
TEST_CASE_DECLARE(client_set_attr);
| 3,791 | 23 | 70 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_memcpy/memcpy_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* memcpy_common.h -- header file for common memcpy utilities
*/
#ifndef MEMCPY_COMMON_H
#define MEMCPY_COMMON_H 1
#include "unittest.h"
#include "file.h"
typedef void *(*memcpy_fn)(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void (*persist_fn)(const void *ptr, size_t len);
extern unsigned Flags[10];
void do_memcpy(int fd, char *dest, int dest_off, char *src, int src_off,
size_t bytes, size_t mapped_len, const char *file_name, memcpy_fn fn,
unsigned flags, persist_fn p);
#endif
| 611 | 23.48 | 73 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_check_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# obj_check_remote/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=medium
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=all
| 313 | 19.933333 | 50 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_rm_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# pmempool_rm_remote/config.sh -- test configuration
#
set -e
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=GPSPM
| 295 | 18.733333 | 52 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_rpmem_basic_integration/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
#
# obj_rpmem_basic_integration/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=medium
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
CONF_RPMEM_PROVIDER[9]=verbs
CONF_RPMEM_PROVIDER[10]=verbs
CONF_RPMEM_PROVIDER[11]=verbs
CONF_RPMEM_PROVIDER[13]=verbs
CONF_RPMEM_PROVIDER[14]=verbs
CONF_RPMEM_PROVIDER[15]=verbs
CONF_RPMEM_PROVIDER[16]=verbs
CONF_RPMEM_PROVIDER[17]=verbs
CONF_RPMEM_PROVIDER[18]=verbs
CONF_RPMEM_VALGRIND[9]=y
CONF_RPMEM_VALGRIND[10]=y
CONF_RPMEM_VALGRIND[11]=y
CONF_RPMEM_VALGRIND[13]=y
CONF_RPMEM_VALGRIND[14]=y
CONF_RPMEM_VALGRIND[15]=y
CONF_RPMEM_VALGRIND[16]=y
CONF_RPMEM_VALGRIND[17]=y
CONF_RPMEM_VALGRIND[18]=y
| 830 | 22.742857 | 61 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem_map_file/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2017, Intel Corporation */
/*
* 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
| 608 | 28 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_movnt_align/movnt_align_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* movnt_align_common.h -- header file for common movnt_align test utilities
*/
#ifndef MOVNT_ALIGN_COMMON_H
#define MOVNT_ALIGN_COMMON_H 1
#include "unittest.h"
#include "file.h"
#define N_BYTES (Ut_pagesize * 2)
extern char *Src;
extern char *Dst;
extern char *Scratch;
extern unsigned Flags[10];
typedef void *(*mem_fn)(void *, const void *, size_t);
typedef void *pmem_memcpy_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void *pmem_memmove_fn(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void *pmem_memset_fn(void *pmemdest, int c, size_t len, unsigned flags);
void check_memmove(size_t doff, size_t soff, size_t len, pmem_memmove_fn fn,
unsigned flags);
void check_memcpy(size_t doff, size_t soff, size_t len, pmem_memcpy_fn fn,
unsigned flags);
void check_memset(size_t off, size_t len, pmem_memset_fn fn, unsigned flags);
#endif
| 989 | 26.5 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_basic_integration/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# obj_basic_integration/config.sh -- test configuration
#
# Extend timeout for this test, as it may take a few minutes
# when run on a non-pmem file system.
CONF_GLOBAL_TIMEOUT='10m'
| 286 | 19.5 | 60 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_feature/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2020, Intel Corporation
#
# src/test/pmempool_feature/common.sh -- common part of pmempool_feature tests
#
# for feature values please see: pmempool feature help
PART_SIZE=$(convert_to_bytes 10M)
# define files and directories
POOLSET=$DIR/testset
TEST_SET_LOCAL=testset_local
TEST_SET_REMOTE=testset_remote
LOG=grep${UNITTEST_NUM}.log
pmempool_exe=$PMEMPOOL$EXESUFFIX
exit_func=expect_normal_exit
sds_enabled=$(is_ndctl_enabled $pmempool_exe; echo $?)
# pmempool_feature_query -- query feature
#
# usage: pmempool_feature_query <feature> [<query-exit-type>]
function pmempool_feature_query() {
query_exit_type=${2-normal}
query_exit_func=expect_${query_exit_type}_exit
val=$($query_exit_func $pmempool_exe feature -q $1 $POOLSET 2>> $LOG)
if [ "$query_exit_type" == "normal" ]; then
echo "query $1 result is $val" &>> $LOG
fi
}
# pmempool_feature_enable -- enable feature
#
# usage: pmempool_feature_enable <feature> [no-query]
function pmempool_feature_enable() {
$exit_func $pmempool_exe feature -e $1 $POOLSET &>> $LOG
if [ "x$2" != "xno-query" ]; then
pmempool_feature_query $1
fi
}
# pmempool_feature_disable -- disable feature
#
# usage: pmempool_feature_disable <feature> [no-query]
function pmempool_feature_disable() {
$exit_func $pmempool_exe feature -d $1 $POOLSET '&>>' $LOG
if [ "x$2" != "xno-query" ]; then
pmempool_feature_query $1
fi
}
# pmempool_feature_create_poolset -- create poolset
#
# usage: pmempool_feature_create_poolset <poolset-type>
function pmempool_feature_create_poolset() {
POOLSET_TYPE=$1
case "$1" in
"no_dax_device")
create_poolset $POOLSET \
$PART_SIZE:$DIR/testfile11:x \
$PART_SIZE:$DIR/testfile12:x \
r \
$PART_SIZE:$DIR/testfile21:x \
$PART_SIZE:$DIR/testfile22:x \
r \
$PART_SIZE:$DIR/testfile31:x
;;
"dax_device")
create_poolset $POOLSET \
AUTO:$DEVICE_DAX_PATH
;;
"remote")
create_poolset $DIR/$TEST_SET_LOCAL \
$PART_SIZE:${NODE_DIR[1]}/testfile_local11:x \
$PART_SIZE:${NODE_DIR[1]}/testfile_local12:x \
m ${NODE_ADDR[0]}:$TEST_SET_REMOTE
create_poolset $DIR/$TEST_SET_REMOTE \
$PART_SIZE:${NODE_DIR[0]}/testfile_remote21:x \
$PART_SIZE:${NODE_DIR[0]}/testfile_remote22:x
copy_files_to_node 0 ${NODE_DIR[0]} $DIR/$TEST_SET_REMOTE
copy_files_to_node 1 ${NODE_DIR[1]} $DIR/$TEST_SET_LOCAL
rm_files_from_node 1 \
${NODE_DIR[1]}testfile_local11 ${NODE_DIR[1]}testfile_local12
rm_files_from_node 0 \
${NODE_DIR[0]}testfile_remote21 ${NODE_DIR[0]}testfile_remote22
POOLSET="${NODE_DIR[1]}/$TEST_SET_LOCAL"
;;
esac
expect_normal_exit $pmempool_exe rm -f $POOLSET
# create pool
# pmempool create under valgrind pmemcheck takes too long
# it is not part of the test so it is run here without valgrind
VALGRIND_DISABLED=y expect_normal_exit $pmempool_exe create obj $POOLSET
}
# pmempool_feature_test_SINGLEHDR -- test SINGLEHDR
function pmempool_feature_test_SINGLEHDR() {
exit_func=expect_abnormal_exit
pmempool_feature_enable "SINGLEHDR" "no-query" # UNSUPPORTED
pmempool_feature_disable "SINGLEHDR" "no-query" # UNSUPPORTED
exit_func=expect_normal_exit
pmempool_feature_query "SINGLEHDR"
}
# pmempool_feature_test_CKSUM_2K -- test CKSUM_2K
function pmempool_feature_test_CKSUM_2K() {
# PMEMPOOL_FEAT_CHCKSUM_2K is enabled by default
pmempool_feature_query "CKSUM_2K"
# SHUTDOWN_STATE is disabled on Linux if PMDK is compiled with old ndctl
# enable it to interfere toggling CKSUM_2K
if [ $sds_enabled -eq 1 ]; then
pmempool_feature_enable SHUTDOWN_STATE "no-query"
fi
# disable PMEMPOOL_FEAT_SHUTDOWN_STATE prior to success
exit_func=expect_abnormal_exit
pmempool_feature_disable "CKSUM_2K" # should fail
exit_func=expect_normal_exit
pmempool_feature_disable "SHUTDOWN_STATE"
pmempool_feature_disable "CKSUM_2K" # should succeed
pmempool_feature_enable "CKSUM_2K"
}
# pmempool_feature_test_SHUTDOWN_STATE -- test SHUTDOWN_STATE
function pmempool_feature_test_SHUTDOWN_STATE() {
pmempool_feature_query "SHUTDOWN_STATE"
if [ $sds_enabled -eq 0 ]; then
pmempool_feature_disable SHUTDOWN_STATE
fi
# PMEMPOOL_FEAT_SHUTDOWN_STATE requires PMEMPOOL_FEAT_CHCKSUM_2K
pmempool_feature_disable "CKSUM_2K"
exit_func=expect_abnormal_exit
pmempool_feature_enable "SHUTDOWN_STATE" # should fail
exit_func=expect_normal_exit
pmempool_feature_enable "CKSUM_2K"
pmempool_feature_enable "SHUTDOWN_STATE" # should succeed
}
# pmempool_feature_test_CHECK_BAD_BLOCKS -- test SHUTDOWN_STATE
function pmempool_feature_test_CHECK_BAD_BLOCKS() {
# PMEMPOOL_FEAT_CHECK_BAD_BLOCKS is disabled by default
pmempool_feature_query "CHECK_BAD_BLOCKS"
pmempool_feature_enable "CHECK_BAD_BLOCKS"
pmempool_feature_disable "CHECK_BAD_BLOCKS"
}
# pmempool_feature_remote_init -- initialization remote replics
function pmempool_feature_remote_init() {
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER
init_rpmem_on_node 1 0
pmempool_exe="run_on_node 1 ../pmempool"
}
# pmempool_feature_test_remote -- run remote tests
function pmempool_feature_test_remote() {
# create pool
expect_normal_exit $pmempool_exe rm -f $POOLSET
expect_normal_exit $pmempool_exe create obj $POOLSET
# poolset with remote replicas are not supported
exit_func=expect_abnormal_exit
pmempool_feature_enable $1 no-query
pmempool_feature_disable $1 no-query
pmempool_feature_query $1 abnormal
}
| 5,473 | 28.430108 | 78 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_info_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# pmempool_info_remote/config.sh -- test configuration
#
set -e
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=GPSPM
| 297 | 18.866667 | 54 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/ex_librpmem_basic/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2019, Intel Corporation
#
#
# ex_librpmem_basic/config.sh -- test configuration
#
# Filesystem-DAX cannot be used for RDMA
# since it is missing support in Linux kernel
CONF_GLOBAL_FS_TYPE=non-pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_TEST_TYPE=short
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 402 | 21.388889 | 51 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_transform_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# pmempool_transform_remote/config.sh -- configuration of unit tests
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 298 | 20.357143 | 68 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_transform_remote/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2018, Intel Corporation
#
#
# pmempool_transform_remote/common.sh -- commons for pmempool transform tests
# with remote replication
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER
setup
init_rpmem_on_node 1 0
require_node_log_files 1 pmemobj$UNITTEST_NUM.log
require_node_log_files 1 pmempool$UNITTEST_NUM.log
LOG=out${UNITTEST_NUM}.log
LOG_TEMP=out${UNITTEST_NUM}_part.log
rm -f $LOG && touch $LOG
rm -f $LOG_TEMP && touch $LOG_TEMP
rm_files_from_node 0 ${NODE_TEST_DIR[0]}/$LOG
rm_files_from_node 1 ${NODE_TEST_DIR[1]}/$LOG
LAYOUT=OBJ_LAYOUT
POOLSET_LOCAL_IN=poolset.in
POOLSET_LOCAL_OUT=poolset.out
POOLSET_REMOTE=poolset.remote
POOLSET_REMOTE1=poolset.remote1
POOLSET_REMOTE2=poolset.remote2
# CLI scripts for writing and reading some data hitting all the parts
WRITE_SCRIPT="pmemobjcli.write.script"
READ_SCRIPT="pmemobjcli.read.script"
copy_files_to_node 1 ${NODE_DIR[1]} $WRITE_SCRIPT $READ_SCRIPT
DUMP_INFO_LOG="../pmempool info"
DUMP_INFO_LOG_REMOTE="$DUMP_INFO_LOG -f obj"
DUMP_INFO_SED="sed -e '/^Checksum/d' -e '/^Creation/d' -e '/^Previous replica UUID/d' -e '/^Next replica UUID/d'"
DUMP_INFO_SED_REMOTE="$DUMP_INFO_SED -e '/^Previous part UUID/d' -e '/^Next part UUID/d'"
function dump_info_log() {
local node=$1
local poolset=$2
local name=$3
local ignore=$4
local sed_cmd="$DUMP_INFO_SED"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG $poolset | $sed_cmd >> $name\""
}
function dump_info_log_remote() {
local node=$1
local poolset=$2
local name=$3
local ignore=$4
local sed_cmd="$DUMP_INFO_SED_REMOTE"
if [ -n "$ignore" ]; then
sed_cmd="$sed_cmd -e '/^$ignore/d'"
fi
expect_normal_exit run_on_node $node "\"$DUMP_INFO_LOG_REMOTE $poolset | $sed_cmd >> $name\""
}
function diff_log() {
local node=$1
local f1=$2
local f2=$3
expect_normal_exit run_on_node $node "\"[ -s $f1 ] && [ -s $f2 ] && diff $f1 $f2\""
}
exec_pmemobjcli_script() {
local node=$1
local script=$2
local poolset=$3
local out=$4
expect_normal_exit run_on_node $node "\"../pmemobjcli -s $script $poolset > $out \""
}
| 2,298 | 23.98913 | 113 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmempool_feature_remote/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018, Intel Corporation
#
#
# pmempool_feature_remote/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
# pmempool feature does not support poolsets with remote replicas
# unittest contains only negative scenarios so no point to loop over
# all providers and persistency methods
CONF_GLOBAL_RPMEM_PROVIDER=sockets
CONF_GLOBAL_RPMEM_PMETHOD=GPSPM
| 468 | 26.588235 | 68 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_basic/common_pm_policy.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2018, Intel Corporation
#
# src/test/rpmem_basic/common_pm_policy.sh -- common part for TEST[10-11] scripts
#
set -e
LOG=rpmemd$UNITTEST_NUM.log
OUT=out$UNITTEST_NUM.log
rm -f $OUT
# create poolset and upload
run_on_node 0 "rm -rf ${RPMEM_POOLSET_DIR[0]} && mkdir -p ${RPMEM_POOLSET_DIR[0]} && mkdir -p ${NODE_DIR[0]}$POOLS_PART"
create_poolset $DIR/pool.set 8M:$PART_DIR/pool.part0 8M:$PART_DIR/pool.part1
copy_files_to_node 0 ${RPMEM_POOLSET_DIR[0]} $DIR/pool.set
# create pool and close it - local pool from file
SIMPLE_ARGS="test_create 0 pool.set ${NODE_ADDR[0]} pool 8M none test_close 0"
function test_pm_policy()
{
# initialize pmem
PMEM_IS_PMEM_FORCE=$1
export_vars_node 0 PMEM_IS_PMEM_FORCE
init_rpmem_on_node 1 0
# remove rpmemd log and pool parts
run_on_node 0 "rm -rf $PART_DIR && mkdir -p $PART_DIR && rm -f $LOG"
# execute, get log
expect_normal_exit run_on_node 1 ./rpmem_basic$EXESUFFIX $SIMPLE_ARGS
copy_files_from_node 0 . ${NODE_TEST_DIR[0]}/$LOG
# extract persist method and flush function
cat $LOG | $GREP -A2 "persistency policy:" >> $OUT
}
| 1,160 | 28.769231 | 120 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_basic/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2018, Intel Corporation
#
#
# rpmem_basic/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=any
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
CONF_RPMEM_PMETHOD[10]=APM
CONF_RPMEM_PMETHOD[11]=GPSPM
# Sockets provider does not detect fi_cq_signal so it does not return
# from fi_cq_sread. It causes this test to hang sporadically.
# https://github.com/ofiwg/libfabric/pull/3645
CONF_RPMEM_PROVIDER[12]=verbs
| 547 | 23.909091 | 69 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_basic/setup2to1.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
# src/test/rpmem_basic/setup2to1.sh -- common part for TEST[7-] scripts
#
POOLS_DIR=pools
POOLS_PART=pool_parts
TEST_LOG_FILE=test$UNITTEST_NUM.log
TEST_LOG_LEVEL=3
#
# This unit test requires 4 nodes, but nodes #0 and #3 should be the same
# physical machine - they should have the same NODE[n] addresses but
# different NODE_ADDR[n] addresses in order to test "2-to-1" configuration.
# Node #1 is being replicated to the node #0 and node #2 is being replicated
# to the node #3.
#
require_nodes 4
REPLICA[1]=0
REPLICA[2]=3
for node in 1 2; do
require_node_libfabric ${node} $RPMEM_PROVIDER
require_node_libfabric ${REPLICA[${node}]} $RPMEM_PROVIDER
export_vars_node ${node} TEST_LOG_FILE
export_vars_node ${node} TEST_LOG_LEVEL
require_node_log_files ${node} $PMEM_LOG_FILE
require_node_log_files ${node} $RPMEM_LOG_FILE
require_node_log_files ${node} $TEST_LOG_FILE
require_node_log_files ${REPLICA[${node}]} $RPMEMD_LOG_FILE
REP_ADDR[${node}]=${NODE_ADDR[${REPLICA[${node}]}]}
PART_DIR[${node}]=${NODE_DIR[${REPLICA[${node}]}]}$POOLS_PART
RPMEM_POOLSET_DIR[${REPLICA[${node}]}]=${NODE_DIR[${REPLICA[${node}]}]}$POOLS_DIR
init_rpmem_on_node ${node} ${REPLICA[${node}]}
PID_FILE[${node}]="pidfile${UNITTEST_NUM}-${node}.pid"
clean_remote_node ${node} ${PID_FILE[${node}]}
done
| 1,484 | 29.306122 | 82 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/rpmem_basic/setup.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
# src/test/rpmem_basic/setup.sh -- common part for TEST* scripts
#
set -e
require_nodes 2
require_node_libfabric 0 $RPMEM_PROVIDER $SETUP_LIBFABRIC_VERSION
require_node_libfabric 1 $RPMEM_PROVIDER $SETUP_LIBFABRIC_VERSION
require_node_log_files 0 $RPMEMD_LOG_FILE
require_node_log_files 1 $RPMEM_LOG_FILE
require_node_log_files 1 $PMEM_LOG_FILE
POOLS_DIR=pools
POOLS_PART=pool_parts
PART_DIR=${NODE_DIR[0]}/$POOLS_PART
RPMEM_POOLSET_DIR[0]=${NODE_DIR[0]}$POOLS_DIR
if [ -z "$SETUP_MANUAL_INIT_RPMEM" ]; then
init_rpmem_on_node 1 0
fi
| 642 | 24.72 | 65 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/pmem2_memmove/memmove_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* memmove_common.h -- header file for common memmove_common test utilities
*/
#ifndef MEMMOVE_COMMON_H
#define MEMMOVE_COMMON_H 1
#include "unittest.h"
#include "file.h"
extern unsigned Flags[10];
#define USAGE() do { UT_FATAL("usage: %s file b:length [d:{offset}] "\
"[s:{offset}] [o:{0|1}]", argv[0]); } while (0)
typedef void *(*memmove_fn)(void *pmemdest, const void *src, size_t len,
unsigned flags);
typedef void (*persist_fn)(const void *ptr, size_t len);
void do_memmove(char *dst, char *src, const char *file_name,
size_t dest_off, size_t src_off, size_t bytes,
memmove_fn fn, unsigned flags, persist_fn p);
void verify_contents(const char *file_name, int test, const char *buf1,
const char *buf2, size_t len);
#endif
| 832 | 25.870968 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_rpmem_heap_interrupt/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2017, Intel Corporation
#
#
# src/test/obj_rpmem_heap_interrupt/config.sh -- test configuration
#
CONF_GLOBAL_FS_TYPE=pmem
CONF_GLOBAL_BUILD_TYPE="debug nondebug"
CONF_GLOBAL_RPMEM_PROVIDER=all
CONF_GLOBAL_RPMEM_PMETHOD=all
| 303 | 20.714286 | 67 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/libpmempool_backup/config.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017, Intel Corporation
#
#
# libpmempool_backup/config.sh -- test configuration
#
# Extend timeout for TEST0, as it may take more than a minute
# when run on a non-pmem file system.
CONF_TIMEOUT[0]='10m'
| 280 | 19.071429 | 61 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/libpmempool_backup/common.sh | #!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2018, Intel Corporation
#
#
# libpmempool_backup/common.sh -- functions for libpmempool_backup unittest
#
set -e
POOLSET=$DIR/pool.set
BACKUP=_backup
REPLICA=_replica
POOL_PART=$DIR/pool.part
OUT=out${UNITTEST_NUM}.log
OUT_TEMP=out${UNITTEST_NUM}_temp.log
DIFF=diff${UNITTEST_NUM}.log
rm -f $LOG $DIFF $OUT_TEMP && touch $LOG $DIFF $OUT_TEMP
# params for blk, log and obj pools
POOL_TYPES=( blk log obj )
POOL_CREATE_PARAMS=( "--write-layout 512" "" "--layout test_layout" )
POOL_CHECK_PARAMS=( "-smgB" "-s" "-soOaAbZH -l -C" )
POOL_OBJ=2
# create_poolset_variation -- create one from the tested poolset variation
# usage: create_poolset_variation <variation-id> [<suffix>]
#
function create_poolset_variation() {
local sfx=""
local variation=$1
shift
if [ $# -gt 0 ]; then
sfx=$1
fi
case "$variation"
in
1)
# valid poolset file
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
20M:${POOL_PART}4$sfx:x
;;
2)
# valid poolset file with replica
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
20M:${POOL_PART}4$sfx:x \
r 80M:${POOL_PART}${REPLICA}$sfx:x
;;
3)
# other number of parts
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
40M:${POOL_PART}3$sfx:x
;;
4)
# no poolset
# return without check_file
return
;;
5)
# empty
create_poolset $POOLSET$sfx
;;
6)
# other size of part
create_poolset $POOLSET$sfx \
20M:${POOL_PART}1$sfx:x \
20M:${POOL_PART}2$sfx:x \
20M:${POOL_PART}3$sfx:x \
21M:${POOL_PART}4$sfx:x
;;
esac
check_file $POOLSET$sfx
}
#
# backup_and_compare -- perform backup and compare backup result with original
# if compare parameters are provided
# usage: backup_and_compare <poolset> <type> [<compare-params>]
#
function backup_and_compare () {
local poolset=$1
local type=$2
shift 2
# backup
expect_normal_exit ../libpmempool_api/libpmempool_test$EXESUFFIX \
-b $poolset$BACKUP -t $type -r 1 $poolset
cat $OUT >> $OUT_TEMP
# compare
if [ $# -gt 0 ]; then
compare_replicas "$1" $poolset $poolset$BACKUP >> $DIFF
fi
}
ALL_POOL_PARTS="${POOL_PART}1 ${POOL_PART}2 ${POOL_PART}3 ${POOL_PART}4 \
${POOL_PART}${REPLICA}"
ALL_POOL_BACKUP_PARTS="${POOL_PART}1$BACKUP ${POOL_PART}2$BACKUP \
${POOL_PART}3$BACKUP ${POOL_PART}4$BACKUP \
${POOL_PART}${BACKUP}${REPLICA}"
#
# backup_cleanup -- perform cleanup between test cases
#
function backup_cleanup() {
rm -f $POOLSET$BACKUP $ALL_POOL_PARTS $ALL_POOL_BACKUP_PARTS
}
| 2,691 | 21.621849 | 78 | sh |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/test/obj_sync/mocks_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2017, Intel Corporation */
/*
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mocks_windows.h -- redefinitions of pthread 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_sync test.
* It would replace default implementation with mocked functions defined
* in obj_sync.c.
*
* These defines could be also passed as preprocessor definitions.
*/
#ifndef WRAP_REAL
#define os_mutex_init __wrap_os_mutex_init
#define os_rwlock_init __wrap_os_rwlock_init
#define os_cond_init __wrap_os_cond_init
#endif
| 2,265 | 41.754717 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_fip_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2019, Intel Corporation */
/*
* rpmem_fip_common.h -- common definitions for librpmem and rpmemd
*/
#ifndef RPMEM_FIP_COMMON_H
#define RPMEM_FIP_COMMON_H 1
#include <string.h>
#include <netinet/in.h>
#include <rdma/fabric.h>
#include <rdma/fi_cm.h>
#include <rdma/fi_rma.h>
#ifdef __cplusplus
extern "C" {
#endif
#define RPMEM_FIVERSION FI_VERSION(1, 4)
#define RPMEM_FIP_CQ_WAIT_MS 100
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
/*
* rpmem_fip_node -- client or server node type
*/
enum rpmem_fip_node {
RPMEM_FIP_NODE_CLIENT,
RPMEM_FIP_NODE_SERVER,
MAX_RPMEM_FIP_NODE,
};
/*
* rpmem_fip_probe -- list of providers
*/
struct rpmem_fip_probe {
unsigned providers;
size_t max_wq_size[MAX_RPMEM_PROV];
};
/*
* rpmem_fip_probe -- returns true if specified provider is available
*/
static inline int
rpmem_fip_probe(struct rpmem_fip_probe probe, enum rpmem_provider provider)
{
return (probe.providers & (1U << provider)) != 0;
}
/*
* rpmem_fip_probe_any -- returns true if any provider is available
*/
static inline int
rpmem_fip_probe_any(struct rpmem_fip_probe probe)
{
return probe.providers != 0;
}
int rpmem_fip_probe_get(const char *target, struct rpmem_fip_probe *probe);
struct fi_info *rpmem_fip_get_hints(enum rpmem_provider provider);
int rpmem_fip_read_eq_check(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t exp_event, fid_t exp_fid, int timeout);
int rpmem_fip_read_eq(struct fid_eq *eq, struct fi_eq_cm_entry *entry,
uint32_t *event, int timeout);
size_t rpmem_fip_cq_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_wq_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_rx_size(enum rpmem_persist_method pm,
enum rpmem_fip_node node);
size_t rpmem_fip_max_nlanes(struct fi_info *fi);
void rpmem_fip_print_info(struct fi_info *fi);
#ifdef __cplusplus
}
#endif
#endif
| 1,992 | 21.144444 | 76 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_common_log.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016, Intel Corporation */
/*
* rpmem_common_log.h -- common log macros for librpmem and rpmemd
*/
#if defined(RPMEMC_LOG_RPMEM) && defined(RPMEMC_LOG_RPMEMD)
#error Both RPMEMC_LOG_RPMEM and RPMEMC_LOG_RPMEMD defined
#elif !defined(RPMEMC_LOG_RPMEM) && !defined(RPMEMC_LOG_RPMEMD)
#define RPMEMC_LOG(level, fmt, args...) do {} while (0)
#define RPMEMC_DBG(level, fmt, args...) do {} while (0)
#define RPMEMC_FATAL(fmt, args...) do {} while (0)
#define RPMEMC_ASSERT(cond) do {} while (0)
#elif defined(RPMEMC_LOG_RPMEM)
#include "out.h"
#include "rpmem_util.h"
#define RPMEMC_LOG(level, fmt, args...) RPMEM_LOG(level, fmt, ## args)
#define RPMEMC_DBG(level, fmt, args...) RPMEM_DBG(fmt, ## args)
#define RPMEMC_FATAL(fmt, args...) RPMEM_FATAL(fmt, ## args)
#define RPMEMC_ASSERT(cond) RPMEM_ASSERT(cond)
#else
#include "rpmemd_log.h"
#define RPMEMC_LOG(level, fmt, args...) RPMEMD_LOG(level, fmt, ## args)
#define RPMEMC_DBG(level, fmt, args...) RPMEMD_DBG(fmt, ## args)
#define RPMEMC_FATAL(fmt, args...) RPMEMD_FATAL(fmt, ## args)
#define RPMEMC_ASSERT(cond) RPMEMD_ASSERT(cond)
#endif
| 1,160 | 28.769231 | 71 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_common.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2019, Intel Corporation */
/*
* rpmem_common.h -- common definitions for librpmem and rpmemd
*/
#ifndef RPMEM_COMMON_H
#define RPMEM_COMMON_H 1
/*
* Values for SO_KEEPALIVE socket option
*/
#define RPMEM_CMD_ENV "RPMEM_CMD"
#define RPMEM_SSH_ENV "RPMEM_SSH"
#define RPMEM_DEF_CMD "rpmemd"
#define RPMEM_DEF_SSH "ssh"
#define RPMEM_PROV_SOCKET_ENV "RPMEM_ENABLE_SOCKETS"
#define RPMEM_PROV_VERBS_ENV "RPMEM_ENABLE_VERBS"
#define RPMEM_MAX_NLANES_ENV "RPMEM_MAX_NLANES"
#define RPMEM_WQ_SIZE_ENV "RPMEM_WORK_QUEUE_SIZE"
#define RPMEM_ACCEPT_TIMEOUT 30000
#define RPMEM_CONNECT_TIMEOUT 30000
#define RPMEM_MONITOR_TIMEOUT 1000
#include <stdint.h>
#include <sys/socket.h>
#include <netdb.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* rpmem_err -- error codes
*/
enum rpmem_err {
RPMEM_SUCCESS = 0,
RPMEM_ERR_BADPROTO = 1,
RPMEM_ERR_BADNAME = 2,
RPMEM_ERR_BADSIZE = 3,
RPMEM_ERR_BADNLANES = 4,
RPMEM_ERR_BADPROVIDER = 5,
RPMEM_ERR_FATAL = 6,
RPMEM_ERR_FATAL_CONN = 7,
RPMEM_ERR_BUSY = 8,
RPMEM_ERR_EXISTS = 9,
RPMEM_ERR_PROVNOSUP = 10,
RPMEM_ERR_NOEXIST = 11,
RPMEM_ERR_NOACCESS = 12,
RPMEM_ERR_POOL_CFG = 13,
MAX_RPMEM_ERR,
};
/*
* rpmem_persist_method -- remote persist operation method
*/
enum rpmem_persist_method {
RPMEM_PM_GPSPM = 1, /* General Purpose Server Persistency Method */
RPMEM_PM_APM = 2, /* Appliance Persistency Method */
MAX_RPMEM_PM,
};
const char *rpmem_persist_method_to_str(enum rpmem_persist_method pm);
/*
* rpmem_provider -- supported providers
*/
enum rpmem_provider {
RPMEM_PROV_UNKNOWN = 0,
RPMEM_PROV_LIBFABRIC_VERBS = 1,
RPMEM_PROV_LIBFABRIC_SOCKETS = 2,
MAX_RPMEM_PROV,
};
enum rpmem_provider rpmem_provider_from_str(const char *str);
const char *rpmem_provider_to_str(enum rpmem_provider provider);
/*
* rpmem_req_attr -- arguments for open/create request
*/
struct rpmem_req_attr {
size_t pool_size;
unsigned nlanes;
size_t buff_size;
enum rpmem_provider provider;
const char *pool_desc;
};
/*
* rpmem_resp_attr -- return arguments from open/create request
*/
struct rpmem_resp_attr {
unsigned short port;
uint64_t rkey;
uint64_t raddr;
unsigned nlanes;
enum rpmem_persist_method persist_method;
};
#define RPMEM_HAS_USER 0x1
#define RPMEM_HAS_SERVICE 0x2
#define RPMEM_FLAGS_USE_IPV4 0x4
#define RPMEM_MAX_USER (32 + 1) /* see useradd(8) + 1 for '\0' */
#define RPMEM_MAX_NODE (255 + 1) /* see gethostname(2) + 1 for '\0' */
#define RPMEM_MAX_SERVICE (NI_MAXSERV + 1) /* + 1 for '\0' */
#define RPMEM_HDR_SIZE 4096
#define RPMEM_CLOSE_FLAGS_REMOVE 0x1
#define RPMEM_DEF_BUFF_SIZE 8192
struct rpmem_target_info {
char user[RPMEM_MAX_USER];
char node[RPMEM_MAX_NODE];
char service[RPMEM_MAX_SERVICE];
unsigned flags;
};
extern unsigned Rpmem_max_nlanes;
extern unsigned Rpmem_wq_size;
extern int Rpmem_fork_unsafe;
int rpmem_b64_write(int sockfd, const void *buf, size_t len, int flags);
int rpmem_b64_read(int sockfd, void *buf, size_t len, int flags);
const char *rpmem_get_ip_str(const struct sockaddr *addr);
struct rpmem_target_info *rpmem_target_parse(const char *target);
void rpmem_target_free(struct rpmem_target_info *info);
int rpmem_xwrite(int fd, const void *buf, size_t len, int flags);
int rpmem_xread(int fd, void *buf, size_t len, int flags);
char *rpmem_get_ssh_conn_addr(void);
#ifdef __cplusplus
}
#endif
#endif
| 3,404 | 23.321429 | 72 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_proto.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2019, Intel Corporation */
/*
* rpmem_proto.h -- rpmem protocol definitions
*/
#ifndef RPMEM_PROTO_H
#define RPMEM_PROTO_H 1
#include <stdint.h>
#include <endian.h>
#include "librpmem.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PACKED __attribute__((packed))
#define RPMEM_PROTO "tcp"
#define RPMEM_PROTO_MAJOR 0
#define RPMEM_PROTO_MINOR 1
#define RPMEM_SIG_SIZE 8
#define RPMEM_UUID_SIZE 16
#define RPMEM_PROV_SIZE 32
#define RPMEM_USER_SIZE 16
/*
* rpmem_msg_type -- type of messages
*/
enum rpmem_msg_type {
RPMEM_MSG_TYPE_CREATE = 1, /* create request */
RPMEM_MSG_TYPE_CREATE_RESP = 2, /* create request response */
RPMEM_MSG_TYPE_OPEN = 3, /* open request */
RPMEM_MSG_TYPE_OPEN_RESP = 4, /* open request response */
RPMEM_MSG_TYPE_CLOSE = 5, /* close request */
RPMEM_MSG_TYPE_CLOSE_RESP = 6, /* close request response */
RPMEM_MSG_TYPE_SET_ATTR = 7, /* set attributes request */
/* set attributes request response */
RPMEM_MSG_TYPE_SET_ATTR_RESP = 8,
MAX_RPMEM_MSG_TYPE,
};
/*
* rpmem_pool_attr_packed -- a packed version
*/
struct rpmem_pool_attr_packed {
char signature[RPMEM_POOL_HDR_SIG_LEN]; /* pool signature */
uint32_t major; /* format major version number */
uint32_t compat_features; /* mask: compatible "may" features */
uint32_t incompat_features; /* mask: "must support" features */
uint32_t ro_compat_features; /* mask: force RO if unsupported */
unsigned char poolset_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* pool uuid */
unsigned char uuid[RPMEM_POOL_HDR_UUID_LEN]; /* first part uuid */
unsigned char next_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* next pool uuid */
unsigned char prev_uuid[RPMEM_POOL_HDR_UUID_LEN]; /* prev pool uuid */
unsigned char user_flags[RPMEM_POOL_USER_FLAGS_LEN]; /* user flags */
} PACKED;
/*
* rpmem_msg_ibc_attr -- in-band connection attributes
*
* Used by create request response and open request response.
* Contains essential information to proceed with in-band connection
* initialization.
*/
struct rpmem_msg_ibc_attr {
uint32_t port; /* RDMA connection port */
uint32_t persist_method; /* persist method */
uint64_t rkey; /* remote key */
uint64_t raddr; /* remote address */
uint32_t nlanes; /* number of lanes */
} PACKED;
/*
* rpmem_msg_pool_desc -- remote pool descriptor
*/
struct rpmem_msg_pool_desc {
uint32_t size; /* size of pool descriptor */
uint8_t desc[0]; /* pool descriptor, null-terminated string */
} PACKED;
/*
* rpmem_msg_hdr -- message header which consists of type and size of message
*
* The type must be one of the rpmem_msg_type values.
*/
struct rpmem_msg_hdr {
uint32_t type; /* type of message */
uint64_t size; /* size of message */
uint8_t body[0];
} PACKED;
/*
* rpmem_msg_hdr_resp -- message response header which consists of type, size
* and status.
*
* The type must be one of the rpmem_msg_type values.
*/
struct rpmem_msg_hdr_resp {
uint32_t status; /* response status */
uint32_t type; /* type of message */
uint64_t size; /* size of message */
} PACKED;
/*
* rpmem_msg_common -- common fields for open/create messages
*/
struct rpmem_msg_common {
uint16_t major; /* protocol version major number */
uint16_t minor; /* protocol version minor number */
uint64_t pool_size; /* minimum required size of a pool */
uint32_t nlanes; /* number of lanes used by initiator */
uint32_t provider; /* provider */
uint64_t buff_size; /* buffer size for inline persist */
} PACKED;
/*
* rpmem_msg_create -- create request message
*
* The type of message must be set to RPMEM_MSG_TYPE_CREATE.
* The size of message must be set to
* sizeof(struct rpmem_msg_create) + pool_desc_size
*/
struct rpmem_msg_create {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_msg_common c;
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
} PACKED;
/*
* rpmem_msg_create_resp -- create request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_CREATE_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_create_resp).
*/
struct rpmem_msg_create_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
} PACKED;
/*
* rpmem_msg_open -- open request message
*
* The type of message must be set to RPMEM_MSG_TYPE_OPEN.
* The size of message must be set to
* sizeof(struct rpmem_msg_open) + pool_desc_size
*/
struct rpmem_msg_open {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_msg_common c;
struct rpmem_msg_pool_desc pool_desc; /* pool descriptor */
} PACKED;
/*
* rpmem_msg_open_resp -- open request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_OPEN_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_open_resp)
*/
struct rpmem_msg_open_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
struct rpmem_msg_ibc_attr ibc; /* in-band connection attributes */
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
} PACKED;
/*
* rpmem_msg_close -- close request message
*
* The type of message must be set to RPMEM_MSG_TYPE_CLOSE
* The size of message must be set to sizeof(struct rpmem_msg_close)
*/
struct rpmem_msg_close {
struct rpmem_msg_hdr hdr; /* message header */
uint32_t flags; /* flags */
} PACKED;
/*
* rpmem_msg_close_resp -- close request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_CLOSE_RESP
* The size of message must be set to sizeof(struct rpmem_msg_close_resp)
*/
struct rpmem_msg_close_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
/* no more fields */
} PACKED;
#define RPMEM_FLUSH_WRITE 0U /* flush / persist using RDMA WRITE */
#define RPMEM_DEEP_PERSIST 1U /* deep persist operation */
#define RPMEM_PERSIST_SEND 2U /* persist using RDMA SEND */
#define RPMEM_COMPLETION 4U /* schedule command with a completion */
/* the two least significant bits are reserved for mode of persist */
#define RPMEM_FLUSH_PERSIST_MASK 0x3U
#define RPMEM_PERSIST_MAX 2U /* maximum valid persist value */
/*
* rpmem_msg_persist -- remote persist message
*/
struct rpmem_msg_persist {
uint32_t flags; /* lane flags */
uint32_t lane; /* lane identifier */
uint64_t addr; /* remote memory address */
uint64_t size; /* remote memory size */
uint8_t data[];
};
/*
* rpmem_msg_persist_resp -- remote persist response message
*/
struct rpmem_msg_persist_resp {
uint32_t flags; /* lane flags */
uint32_t lane; /* lane identifier */
};
/*
* rpmem_msg_set_attr -- set attributes request message
*
* The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR.
* The size of message must be set to sizeof(struct rpmem_msg_set_attr)
*/
struct rpmem_msg_set_attr {
struct rpmem_msg_hdr hdr; /* message header */
struct rpmem_pool_attr_packed pool_attr; /* pool attributes */
} PACKED;
/*
* rpmem_msg_set_attr_resp -- set attributes request response message
*
* The type of message must be set to RPMEM_MSG_TYPE_SET_ATTR_RESP.
* The size of message must be set to sizeof(struct rpmem_msg_set_attr_resp).
*/
struct rpmem_msg_set_attr_resp {
struct rpmem_msg_hdr_resp hdr; /* message header */
} PACKED;
/*
* XXX Begin: Suppress gcc conversion warnings for FreeBSD be*toh macros.
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
/*
* rpmem_ntoh_msg_ibc_attr -- convert rpmem_msg_ibc attr to host byte order
*/
static inline void
rpmem_ntoh_msg_ibc_attr(struct rpmem_msg_ibc_attr *ibc)
{
ibc->port = be32toh(ibc->port);
ibc->persist_method = be32toh(ibc->persist_method);
ibc->rkey = be64toh(ibc->rkey);
ibc->raddr = be64toh(ibc->raddr);
}
/*
* rpmem_ntoh_msg_pool_desc -- convert rpmem_msg_pool_desc to host byte order
*/
static inline void
rpmem_ntoh_msg_pool_desc(struct rpmem_msg_pool_desc *pool_desc)
{
pool_desc->size = be32toh(pool_desc->size);
}
/*
* rpmem_ntoh_pool_attr -- convert rpmem_pool_attr to host byte order
*/
static inline void
rpmem_ntoh_pool_attr(struct rpmem_pool_attr_packed *attr)
{
attr->major = be32toh(attr->major);
attr->ro_compat_features = be32toh(attr->ro_compat_features);
attr->incompat_features = be32toh(attr->incompat_features);
attr->compat_features = be32toh(attr->compat_features);
}
/*
* rpmem_ntoh_msg_hdr -- convert rpmem_msg_hdr to host byte order
*/
static inline void
rpmem_ntoh_msg_hdr(struct rpmem_msg_hdr *hdrp)
{
hdrp->type = be32toh(hdrp->type);
hdrp->size = be64toh(hdrp->size);
}
/*
* rpmem_hton_msg_hdr -- convert rpmem_msg_hdr to network byte order
*/
static inline void
rpmem_hton_msg_hdr(struct rpmem_msg_hdr *hdrp)
{
rpmem_ntoh_msg_hdr(hdrp);
}
/*
* rpmem_ntoh_msg_hdr_resp -- convert rpmem_msg_hdr_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
{
hdrp->status = be32toh(hdrp->status);
hdrp->type = be32toh(hdrp->type);
hdrp->size = be64toh(hdrp->size);
}
/*
* rpmem_hton_msg_hdr_resp -- convert rpmem_msg_hdr_resp to network byte order
*/
static inline void
rpmem_hton_msg_hdr_resp(struct rpmem_msg_hdr_resp *hdrp)
{
rpmem_ntoh_msg_hdr_resp(hdrp);
}
/*
* rpmem_ntoh_msg_common -- convert rpmem_msg_common to host byte order
*/
static inline void
rpmem_ntoh_msg_common(struct rpmem_msg_common *msg)
{
msg->major = be16toh(msg->major);
msg->minor = be16toh(msg->minor);
msg->pool_size = be64toh(msg->pool_size);
msg->nlanes = be32toh(msg->nlanes);
msg->provider = be32toh(msg->provider);
msg->buff_size = be64toh(msg->buff_size);
}
/*
* rpmem_hton_msg_common -- convert rpmem_msg_common to network byte order
*/
static inline void
rpmem_hton_msg_common(struct rpmem_msg_common *msg)
{
rpmem_ntoh_msg_common(msg);
}
/*
* rpmem_ntoh_msg_create -- convert rpmem_msg_create to host byte order
*/
static inline void
rpmem_ntoh_msg_create(struct rpmem_msg_create *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_msg_common(&msg->c);
rpmem_ntoh_pool_attr(&msg->pool_attr);
rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
}
/*
* rpmem_hton_msg_create -- convert rpmem_msg_create to network byte order
*/
static inline void
rpmem_hton_msg_create(struct rpmem_msg_create *msg)
{
rpmem_ntoh_msg_create(msg);
}
/*
* rpmem_ntoh_msg_create_resp -- convert rpmem_msg_create_resp to host byte
* order
*/
static inline void
rpmem_ntoh_msg_create_resp(struct rpmem_msg_create_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
rpmem_ntoh_msg_ibc_attr(&msg->ibc);
}
/*
* rpmem_hton_msg_create_resp -- convert rpmem_msg_create_resp to network byte
* order
*/
static inline void
rpmem_hton_msg_create_resp(struct rpmem_msg_create_resp *msg)
{
rpmem_ntoh_msg_create_resp(msg);
}
/*
* rpmem_ntoh_msg_open -- convert rpmem_msg_open to host byte order
*/
static inline void
rpmem_ntoh_msg_open(struct rpmem_msg_open *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_msg_common(&msg->c);
rpmem_ntoh_msg_pool_desc(&msg->pool_desc);
}
/*
* XXX End: Suppress gcc conversion warnings for FreeBSD be*toh macros
*/
#pragma GCC diagnostic pop
/*
* rpmem_hton_msg_open -- convert rpmem_msg_open to network byte order
*/
static inline void
rpmem_hton_msg_open(struct rpmem_msg_open *msg)
{
rpmem_ntoh_msg_open(msg);
}
/*
* rpmem_ntoh_msg_open_resp -- convert rpmem_msg_open_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_open_resp(struct rpmem_msg_open_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
rpmem_ntoh_msg_ibc_attr(&msg->ibc);
rpmem_ntoh_pool_attr(&msg->pool_attr);
}
/*
* rpmem_hton_msg_open_resp -- convert rpmem_msg_open_resp to network byte order
*/
static inline void
rpmem_hton_msg_open_resp(struct rpmem_msg_open_resp *msg)
{
rpmem_ntoh_msg_open_resp(msg);
}
/*
* rpmem_ntoh_msg_set_attr -- convert rpmem_msg_set_attr to host byte order
*/
static inline void
rpmem_ntoh_msg_set_attr(struct rpmem_msg_set_attr *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
rpmem_ntoh_pool_attr(&msg->pool_attr);
}
/*
* rpmem_hton_msg_set_attr -- convert rpmem_msg_set_attr to network byte order
*/
static inline void
rpmem_hton_msg_set_attr(struct rpmem_msg_set_attr *msg)
{
rpmem_ntoh_msg_set_attr(msg);
}
/*
* rpmem_ntoh_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to host byte
* order
*/
static inline void
rpmem_ntoh_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_hton_msg_set_attr_resp -- convert rpmem_msg_set_attr_resp to network
* byte order
*/
static inline void
rpmem_hton_msg_set_attr_resp(struct rpmem_msg_set_attr_resp *msg)
{
rpmem_hton_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_ntoh_msg_close -- convert rpmem_msg_close to host byte order
*/
static inline void
rpmem_ntoh_msg_close(struct rpmem_msg_close *msg)
{
rpmem_ntoh_msg_hdr(&msg->hdr);
}
/*
* rpmem_hton_msg_close -- convert rpmem_msg_close to network byte order
*/
static inline void
rpmem_hton_msg_close(struct rpmem_msg_close *msg)
{
rpmem_ntoh_msg_close(msg);
}
/*
* rpmem_ntoh_msg_close_resp -- convert rpmem_msg_close_resp to host byte order
*/
static inline void
rpmem_ntoh_msg_close_resp(struct rpmem_msg_close_resp *msg)
{
rpmem_ntoh_msg_hdr_resp(&msg->hdr);
}
/*
* rpmem_hton_msg_close_resp -- convert rpmem_msg_close_resp to network byte
* order
*/
static inline void
rpmem_hton_msg_close_resp(struct rpmem_msg_close_resp *msg)
{
rpmem_ntoh_msg_close_resp(msg);
}
/*
* pack_rpmem_pool_attr -- copy pool attributes to a packed structure
*/
static inline void
pack_rpmem_pool_attr(const struct rpmem_pool_attr *src,
struct rpmem_pool_attr_packed *dst)
{
memcpy(dst->signature, src->signature, sizeof(src->signature));
dst->major = src->major;
dst->compat_features = src->compat_features;
dst->incompat_features = src->incompat_features;
dst->ro_compat_features = src->ro_compat_features;
memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
}
/*
* unpack_rpmem_pool_attr -- copy pool attributes to an unpacked structure
*/
static inline void
unpack_rpmem_pool_attr(const struct rpmem_pool_attr_packed *src,
struct rpmem_pool_attr *dst)
{
memcpy(dst->signature, src->signature, sizeof(src->signature));
dst->major = src->major;
dst->compat_features = src->compat_features;
dst->incompat_features = src->incompat_features;
dst->ro_compat_features = src->ro_compat_features;
memcpy(dst->poolset_uuid, src->poolset_uuid, sizeof(dst->poolset_uuid));
memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
memcpy(dst->next_uuid, src->next_uuid, sizeof(dst->next_uuid));
memcpy(dst->prev_uuid, src->prev_uuid, sizeof(dst->prev_uuid));
memcpy(dst->user_flags, src->user_flags, sizeof(dst->user_flags));
}
#ifdef __cplusplus
}
#endif
#endif
| 15,016 | 26.503663 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_fip_lane.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2017, Intel Corporation */
/*
* rpmem_fip_lane.h -- rpmem fabric provider lane definition
*/
#include <sched.h>
#include <stdint.h>
#include "sys_util.h"
/*
* rpmem_fip_lane -- basic lane structure
*
* This structure consist of a synchronization object and a return value.
* It is possible to wait on the lane for specified event. The event can be
* signalled by another thread which can pass the return value if required.
*
* The sync variable can store up to 64 different events, each event on
* separate bit.
*/
struct rpmem_fip_lane {
os_spinlock_t lock;
int ret;
uint64_t sync;
};
/*
* rpmem_fip_lane_init -- initialize basic lane structure
*/
static inline int
rpmem_fip_lane_init(struct rpmem_fip_lane *lanep)
{
lanep->ret = 0;
lanep->sync = 0;
return util_spin_init(&lanep->lock, PTHREAD_PROCESS_PRIVATE);
}
/*
* rpmem_fip_lane_fini -- deinitialize basic lane structure
*/
static inline void
rpmem_fip_lane_fini(struct rpmem_fip_lane *lanep)
{
util_spin_destroy(&lanep->lock);
}
/*
* rpmem_fip_lane_busy -- return true if lane has pending events
*/
static inline int
rpmem_fip_lane_busy(struct rpmem_fip_lane *lanep)
{
util_spin_lock(&lanep->lock);
int ret = lanep->sync != 0;
util_spin_unlock(&lanep->lock);
return ret;
}
/*
* rpmem_fip_lane_begin -- begin waiting for specified event(s)
*/
static inline void
rpmem_fip_lane_begin(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
lanep->ret = 0;
lanep->sync |= sig;
util_spin_unlock(&lanep->lock);
}
static inline int
rpmem_fip_lane_is_busy(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
int ret = (lanep->sync & sig) != 0;
util_spin_unlock(&lanep->lock);
return ret;
}
static inline int
rpmem_fip_lane_ret(struct rpmem_fip_lane *lanep)
{
util_spin_lock(&lanep->lock);
int ret = lanep->ret;
util_spin_unlock(&lanep->lock);
return ret;
}
/*
* rpmem_fip_lane_wait -- wait for specified event(s)
*/
static inline int
rpmem_fip_lane_wait(struct rpmem_fip_lane *lanep, uint64_t sig)
{
while (rpmem_fip_lane_is_busy(lanep, sig))
sched_yield();
return rpmem_fip_lane_ret(lanep);
}
/*
* rpmem_fip_lane_signal -- signal lane about specified event
*/
static inline void
rpmem_fip_lane_signal(struct rpmem_fip_lane *lanep, uint64_t sig)
{
util_spin_lock(&lanep->lock);
lanep->sync &= ~sig;
util_spin_unlock(&lanep->lock);
}
/*
* rpmem_fip_lane_signal -- signal lane about specified event and store
* return value
*/
static inline void
rpmem_fip_lane_sigret(struct rpmem_fip_lane *lanep, uint64_t sig, int ret)
{
util_spin_lock(&lanep->lock);
lanep->ret = ret;
lanep->sync &= ~sig;
util_spin_unlock(&lanep->lock);
}
| 2,754 | 20.523438 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/rpmem_common/rpmem_fip_msg.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* rpmem_fip_msg.h -- simple wrappers for fi_rma(3) and fi_msg(3) functions
*/
#ifndef RPMEM_FIP_MSG_H
#define RPMEM_FIP_MSG_H 1
#include <rdma/fi_rma.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* rpmem_fip_rma -- helper struct for RMA operation
*/
struct rpmem_fip_rma {
struct fi_msg_rma msg; /* message structure */
struct iovec msg_iov; /* IO vector buffer */
struct fi_rma_iov rma_iov; /* RMA IO vector buffer */
void *desc; /* local memory descriptor */
uint64_t flags; /* RMA operation flags */
};
/*
* rpmem_fip_msg -- helper struct for MSG operation
*/
struct rpmem_fip_msg {
struct fi_msg msg; /* message structure */
struct iovec iov; /* IO vector buffer */
void *desc; /* local memory descriptor */
uint64_t flags; /* MSG operation flags */
};
/*
* rpmem_fip_rma_init -- initialize RMA helper struct
*/
static inline void
rpmem_fip_rma_init(struct rpmem_fip_rma *rma, void *desc,
fi_addr_t addr, uint64_t rkey, void *context, uint64_t flags)
{
memset(rma, 0, sizeof(*rma));
rma->desc = desc;
rma->flags = flags;
rma->rma_iov.key = rkey;
rma->msg.context = context;
rma->msg.addr = addr;
rma->msg.desc = &rma->desc;
rma->msg.rma_iov = &rma->rma_iov;
rma->msg.rma_iov_count = 1;
rma->msg.msg_iov = &rma->msg_iov;
rma->msg.iov_count = 1;
}
/*
* rpmem_fip_msg_init -- initialize MSG helper struct
*/
static inline void
rpmem_fip_msg_init(struct rpmem_fip_msg *msg, void *desc, fi_addr_t addr,
void *context, void *buff, size_t len, uint64_t flags)
{
memset(msg, 0, sizeof(*msg));
msg->desc = desc;
msg->flags = flags;
msg->iov.iov_base = buff;
msg->iov.iov_len = len;
msg->msg.context = context;
msg->msg.addr = addr;
msg->msg.desc = &msg->desc;
msg->msg.msg_iov = &msg->iov;
msg->msg.iov_count = 1;
}
/*
* rpmem_fip_writemsg -- wrapper for fi_writemsg
*/
static inline int
rpmem_fip_writemsg(struct fid_ep *ep, struct rpmem_fip_rma *rma,
const void *buff, size_t len, uint64_t addr)
{
rma->rma_iov.addr = addr;
rma->rma_iov.len = len;
rma->msg_iov.iov_base = (void *)buff;
rma->msg_iov.iov_len = len;
return (int)fi_writemsg(ep, &rma->msg, rma->flags);
}
/*
* rpmem_fip_readmsg -- wrapper for fi_readmsg
*/
static inline int
rpmem_fip_readmsg(struct fid_ep *ep, struct rpmem_fip_rma *rma,
void *buff, size_t len, uint64_t addr)
{
rma->rma_iov.addr = addr;
rma->rma_iov.len = len;
rma->msg_iov.iov_base = buff;
rma->msg_iov.iov_len = len;
return (int)fi_readmsg(ep, &rma->msg, rma->flags);
}
/*
* rpmem_fip_sendmsg -- wrapper for fi_sendmsg
*/
static inline int
rpmem_fip_sendmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg, size_t len)
{
msg->iov.iov_len = len;
return (int)fi_sendmsg(ep, &msg->msg, msg->flags);
}
/*
* rpmem_fip_recvmsg -- wrapper for fi_recvmsg
*/
static inline int
rpmem_fip_recvmsg(struct fid_ep *ep, struct rpmem_fip_msg *msg)
{
return (int)fi_recvmsg(ep, &msg->msg, msg->flags);
}
/*
* rpmem_fip_msg_get_pmsg -- returns message buffer as a persist message
*/
static inline struct rpmem_msg_persist *
rpmem_fip_msg_get_pmsg(struct rpmem_fip_msg *msg)
{
return (struct rpmem_msg_persist *)msg->iov.iov_base;
}
/*
* rpmem_fip_msg_get_pres -- returns message buffer as a persist response
*/
static inline struct rpmem_msg_persist_resp *
rpmem_fip_msg_get_pres(struct rpmem_fip_msg *msg)
{
return (struct rpmem_msg_persist_resp *)msg->iov.iov_base;
}
#ifdef __cplusplus
}
#endif
#endif
| 3,494 | 22.77551 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmempool/replica.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2020, Intel Corporation */
/*
* replica.h -- module for synchronizing and transforming poolset
*/
#ifndef REPLICA_H
#define REPLICA_H
#include "libpmempool.h"
#include "pool.h"
#include "badblocks.h"
#ifdef __cplusplus
extern "C" {
#endif
#define UNDEF_REPLICA UINT_MAX
#define UNDEF_PART UINT_MAX
/*
* A part marked as broken does not exist or is damaged so that
* it cannot be opened and has to be recreated.
*/
#define IS_BROKEN (1U << 0)
/*
* A replica marked as inconsistent exists but has inconsistent metadata
* (e.g. inconsistent parts or replicas linkage)
*/
#define IS_INCONSISTENT (1U << 1)
/*
* A part or replica marked in this way has bad blocks inside.
*/
#define HAS_BAD_BLOCKS (1U << 2)
/*
* A part marked in this way has bad blocks in the header
*/
#define HAS_CORRUPTED_HEADER (1U << 3)
/*
* A flag which can be passed to sync_replica() to indicate that the function is
* called by pmempool_transform
*/
#define IS_TRANSFORMED (1U << 10)
/*
* Number of lanes utilized when working with remote replicas
*/
#define REMOTE_NLANES 1
/*
* Helping structures for storing part's health status
*/
struct part_health_status {
unsigned flags;
struct badblocks bbs; /* structure with bad blocks */
char *recovery_file_name; /* name of bad block recovery file */
int recovery_file_exists; /* bad block recovery file exists */
};
/*
* Helping structures for storing replica and poolset's health status
*/
struct replica_health_status {
unsigned nparts;
unsigned nhdrs;
/* a flag for the replica */
unsigned flags;
/* effective size of a pool, valid only for healthy replica */
size_t pool_size;
/* flags for each part */
struct part_health_status part[];
};
struct poolset_health_status {
unsigned nreplicas;
/* a flag for the poolset */
unsigned flags;
/* health statuses for each replica */
struct replica_health_status *replica[];
};
/* get index of the (r)th replica health status */
static inline unsigned
REP_HEALTHidx(struct poolset_health_status *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r) % set->nreplicas;
}
/* get index of the (r + 1)th replica health status */
static inline unsigned
REPN_HEALTHidx(struct poolset_health_status *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r + 1) % set->nreplicas;
}
/* get (p)th part health status */
static inline unsigned
PART_HEALTHidx(struct replica_health_status *rep, unsigned p)
{
ASSERTne(rep->nparts, 0);
return (rep->nparts + p) % rep->nparts;
}
/* get (r)th replica health status */
static inline struct replica_health_status *
REP_HEALTH(struct poolset_health_status *set, unsigned r)
{
return set->replica[REP_HEALTHidx(set, r)];
}
/* get (p)th part health status */
static inline unsigned
PART_HEALTH(struct replica_health_status *rep, unsigned p)
{
return rep->part[PART_HEALTHidx(rep, p)].flags;
}
uint64_t replica_get_part_offset(struct pool_set *set,
unsigned repn, unsigned partn);
void replica_align_badblock_offset_length(size_t *offset, size_t *length,
struct pool_set *set_in, unsigned repn, unsigned partn);
size_t replica_get_part_data_len(struct pool_set *set_in, unsigned repn,
unsigned partn);
uint64_t replica_get_part_data_offset(struct pool_set *set_in, unsigned repn,
unsigned part);
/*
* is_dry_run -- (internal) check whether only verification mode is enabled
*/
static inline bool
is_dry_run(unsigned flags)
{
/*
* PMEMPOOL_SYNC_DRY_RUN and PMEMPOOL_TRANSFORM_DRY_RUN
* have to have the same value in order to use this common function.
*/
ASSERT_COMPILE_ERROR_ON(PMEMPOOL_SYNC_DRY_RUN !=
PMEMPOOL_TRANSFORM_DRY_RUN);
return flags & PMEMPOOL_SYNC_DRY_RUN;
}
/*
* fix_bad_blocks -- (internal) fix bad blocks - it causes reading or creating
* bad blocks recovery files
* (depending on if they exist or not)
*/
static inline bool
fix_bad_blocks(unsigned flags)
{
return flags & PMEMPOOL_SYNC_FIX_BAD_BLOCKS;
}
int replica_remove_all_recovery_files(struct poolset_health_status *set_hs);
int replica_remove_part(struct pool_set *set, unsigned repn, unsigned partn,
int fix_bad_blocks);
int replica_create_poolset_health_status(struct pool_set *set,
struct poolset_health_status **set_hsp);
void replica_free_poolset_health_status(struct poolset_health_status *set_s);
int replica_check_poolset_health(struct pool_set *set,
struct poolset_health_status **set_hs,
int called_from_sync, unsigned flags);
int replica_is_part_broken(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs);
int replica_has_bad_blocks(unsigned repn, struct poolset_health_status *set_hs);
int replica_part_has_bad_blocks(struct part_health_status *phs);
int replica_part_has_corrupted_header(unsigned repn, unsigned partn,
struct poolset_health_status *set_hs);
unsigned replica_find_unbroken_part(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_broken(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_consistent(unsigned repn,
struct poolset_health_status *set_hs);
int replica_is_replica_healthy(unsigned repn,
struct poolset_health_status *set_hs);
unsigned replica_find_healthy_replica(
struct poolset_health_status *set_hs);
unsigned replica_find_replica_healthy_header(
struct poolset_health_status *set_hs);
int replica_is_poolset_healthy(struct poolset_health_status *set_hs);
int replica_is_poolset_transformed(unsigned flags);
ssize_t replica_get_pool_size(struct pool_set *set, unsigned repn);
int replica_check_part_sizes(struct pool_set *set, size_t min_size);
int replica_check_part_dirs(struct pool_set *set);
int replica_check_local_part_dir(struct pool_set *set, unsigned repn,
unsigned partn);
int replica_open_replica_part_files(struct pool_set *set, unsigned repn);
int replica_open_poolset_part_files(struct pool_set *set);
int replica_sync(struct pool_set *set_in, struct poolset_health_status *set_hs,
unsigned flags);
int replica_transform(struct pool_set *set_in, struct pool_set *set_out,
unsigned flags);
#ifdef __cplusplus
}
#endif
#endif
| 6,216 | 28.325472 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmempool/check.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* check.h -- internal definitions for logic performing check
*/
#ifndef CHECK_H
#define CHECK_H
#ifdef __cplusplus
extern "C" {
#endif
int check_init(PMEMpoolcheck *ppc);
struct check_status *check_step(PMEMpoolcheck *ppc);
void check_fini(PMEMpoolcheck *ppc);
int check_is_end(struct check_data *data);
struct pmempool_check_status *check_status_get(struct check_status *status);
#ifdef _WIN32
void convert_status_cache(PMEMpoolcheck *ppc, char *buf, size_t size);
#endif
#ifdef __cplusplus
}
#endif
#endif
| 607 | 18.612903 | 76 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmempool/check_util.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* check_util.h -- internal definitions check util
*/
#ifndef CHECK_UTIL_H
#define CHECK_UTIL_H
#include <time.h>
#include <limits.h>
#include <sys/param.h>
#ifdef __cplusplus
extern "C" {
#endif
#define CHECK_STEP_COMPLETE UINT_MAX
#define CHECK_INVALID_QUESTION UINT_MAX
#define REQUIRE_ADVANCED "the following error can be fixed using " \
"PMEMPOOL_CHECK_ADVANCED flag"
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
/* check control context */
struct check_data;
struct arena;
/* queue of check statuses */
struct check_status;
/* container storing state of all check steps */
#define PREFIX_MAX_SIZE 30
typedef struct {
unsigned init_done;
unsigned step;
unsigned replica;
unsigned part;
int single_repl;
int single_part;
struct pool_set *set;
int is_dev_dax;
struct pool_hdr *hdrp;
/* copy of the pool header in host byte order */
struct pool_hdr hdr;
int hdr_valid;
/*
* If pool header has been modified this field indicates that
* the pool parameters structure requires refresh.
*/
int pool_hdr_modified;
unsigned healthy_replicas;
struct pool_hdr *next_part_hdrp;
struct pool_hdr *prev_part_hdrp;
struct pool_hdr *next_repl_hdrp;
struct pool_hdr *prev_repl_hdrp;
int next_part_hdr_valid;
int prev_part_hdr_valid;
int next_repl_hdr_valid;
int prev_repl_hdr_valid;
/* valid poolset uuid */
uuid_t *valid_puuid;
/* valid part uuid */
uuid_t *valid_uuid;
/* valid part pool header */
struct pool_hdr *valid_part_hdrp;
int valid_part_done;
unsigned valid_part_replica;
char prefix[PREFIX_MAX_SIZE];
struct arena *arenap;
uint64_t offset;
uint32_t narena;
uint8_t *bitmap;
uint8_t *dup_bitmap;
uint8_t *fbitmap;
struct list *list_inval;
struct list *list_flog_inval;
struct list *list_unmap;
struct {
int btti_header;
int btti_backup;
} valid;
struct {
struct btt_info btti;
uint64_t btti_offset;
} pool_valid;
} location;
/* check steps */
void check_bad_blocks(PMEMpoolcheck *ppc);
void check_backup(PMEMpoolcheck *ppc);
void check_pool_hdr(PMEMpoolcheck *ppc);
void check_pool_hdr_uuids(PMEMpoolcheck *ppc);
void check_sds(PMEMpoolcheck *ppc);
void check_log(PMEMpoolcheck *ppc);
void check_blk(PMEMpoolcheck *ppc);
void check_btt_info(PMEMpoolcheck *ppc);
void check_btt_map_flog(PMEMpoolcheck *ppc);
void check_write(PMEMpoolcheck *ppc);
struct check_data *check_data_alloc(void);
void check_data_free(struct check_data *data);
uint32_t check_step_get(struct check_data *data);
void check_step_inc(struct check_data *data);
location *check_get_step_data(struct check_data *data);
void check_end(struct check_data *data);
int check_is_end_util(struct check_data *data);
int check_status_create(PMEMpoolcheck *ppc, enum pmempool_check_msg_type type,
uint32_t arg, const char *fmt, ...) FORMAT_PRINTF(4, 5);
void check_status_release(PMEMpoolcheck *ppc, struct check_status *status);
void check_clear_status_cache(struct check_data *data);
struct check_status *check_pop_question(struct check_data *data);
struct check_status *check_pop_error(struct check_data *data);
struct check_status *check_pop_info(struct check_data *data);
bool check_has_error(struct check_data *data);
bool check_has_answer(struct check_data *data);
int check_push_answer(PMEMpoolcheck *ppc);
struct pmempool_check_status *check_status_get_util(
struct check_status *status);
int check_status_is(struct check_status *status,
enum pmempool_check_msg_type type);
/* create info status */
#define CHECK_INFO(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO, 0, __VA_ARGS__)
/* create info status and append error message based on errno */
#define CHECK_INFO_ERRNO(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_INFO,\
(uint32_t)errno, __VA_ARGS__)
/* create error status */
#define CHECK_ERR(ppc, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_ERROR, 0, __VA_ARGS__)
/* create question status */
#define CHECK_ASK(ppc, question, ...)\
check_status_create(ppc, PMEMPOOL_CHECK_MSG_TYPE_QUESTION, question,\
__VA_ARGS__)
#define CHECK_NOT_COMPLETE(loc, steps)\
((loc)->step != CHECK_STEP_COMPLETE &&\
((steps)[(loc)->step].check != NULL ||\
(steps)[(loc)->step].fix != NULL))
int check_answer_loop(PMEMpoolcheck *ppc, location *data,
void *ctx, int fail_on_no,
int (*callback)(PMEMpoolcheck *, location *, uint32_t, void *ctx));
int check_questions_sequence_validate(PMEMpoolcheck *ppc);
const char *check_get_time_str(time_t time);
const char *check_get_uuid_str(uuid_t uuid);
const char *check_get_pool_type_str(enum pool_type type);
void check_insert_arena(PMEMpoolcheck *ppc, struct arena *arenap);
#ifdef _WIN32
void cache_to_utf8(struct check_data *data, char *buf, size_t size);
#endif
#define CHECK_IS(ppc, flag)\
util_flag_isset((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
#define CHECK_IS_NOT(ppc, flag)\
util_flag_isclr((ppc)->args.flags, PMEMPOOL_CHECK_ ## flag)
#define CHECK_WITHOUT_FIXING(ppc)\
CHECK_IS_NOT(ppc, REPAIR) || CHECK_IS(ppc, DRY_RUN)
#ifdef __cplusplus
}
#endif
#endif
| 5,143 | 25.111675 | 78 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmempool/pmempool.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2018, Intel Corporation */
/*
* pmempool.h -- internal definitions for libpmempool
*/
#ifndef PMEMPOOL_H
#define PMEMPOOL_H
#ifdef __cplusplus
extern "C" {
#endif
#define PMEMPOOL_LOG_PREFIX "libpmempool"
#define PMEMPOOL_LOG_LEVEL_VAR "PMEMPOOL_LOG_LEVEL"
#define PMEMPOOL_LOG_FILE_VAR "PMEMPOOL_LOG_FILE"
enum check_result {
CHECK_RESULT_CONSISTENT,
CHECK_RESULT_NOT_CONSISTENT,
CHECK_RESULT_ASK_QUESTIONS,
CHECK_RESULT_PROCESS_ANSWERS,
CHECK_RESULT_REPAIRED,
CHECK_RESULT_CANNOT_REPAIR,
CHECK_RESULT_ERROR,
CHECK_RESULT_INTERNAL_ERROR
};
/*
* pmempool_check_ctx -- context and arguments for check command
*/
struct pmempool_check_ctx {
struct pmempool_check_args args;
char *path;
char *backup_path;
struct check_data *data;
struct pool_data *pool;
enum check_result result;
unsigned sync_required;
};
#ifdef __cplusplus
}
#endif
#endif
| 927 | 17.938776 | 64 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmempool/pool.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2016-2019, Intel Corporation */
/*
* pool.h -- internal definitions for pool processing functions
*/
#ifndef POOL_H
#define POOL_H
#include <stdbool.h>
#include <sys/types.h>
#include "libpmemobj.h"
#include "queue.h"
#include "set.h"
#include "log.h"
#include "blk.h"
#include "btt_layout.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "alloc.h"
#include "fault_injection.h"
enum pool_type {
POOL_TYPE_UNKNOWN = (1 << 0),
POOL_TYPE_LOG = (1 << 1),
POOL_TYPE_BLK = (1 << 2),
POOL_TYPE_OBJ = (1 << 3),
POOL_TYPE_BTT = (1 << 4),
POOL_TYPE_ANY = POOL_TYPE_UNKNOWN | POOL_TYPE_LOG |
POOL_TYPE_BLK | POOL_TYPE_OBJ | POOL_TYPE_BTT,
};
struct pool_params {
enum pool_type type;
char signature[POOL_HDR_SIG_LEN];
features_t features;
size_t size;
mode_t mode;
int is_poolset;
int is_part;
int is_dev_dax;
int is_pmem;
union {
struct {
uint64_t bsize;
} blk;
struct {
char layout[PMEMOBJ_MAX_LAYOUT];
} obj;
};
};
struct pool_set_file {
int fd;
char *fname;
void *addr;
size_t size;
struct pool_set *poolset;
time_t mtime;
mode_t mode;
};
struct arena {
PMDK_TAILQ_ENTRY(arena) next;
struct btt_info btt_info;
uint32_t id;
bool valid;
bool zeroed;
uint64_t offset;
uint8_t *flog;
size_t flogsize;
uint32_t *map;
size_t mapsize;
};
struct pool_data {
struct pool_params params;
struct pool_set_file *set_file;
int blk_no_layout;
union {
struct pool_hdr pool;
struct pmemlog log;
struct pmemblk blk;
} hdr;
enum {
UUID_NOP = 0,
UUID_FROM_BTT,
UUID_NOT_FROM_BTT,
} uuid_op;
struct arena bttc;
PMDK_TAILQ_HEAD(arenashead, arena) arenas;
uint32_t narenas;
};
struct pool_data *pool_data_alloc(PMEMpoolcheck *ppc);
void pool_data_free(struct pool_data *pool);
void pool_params_from_header(struct pool_params *params,
const struct pool_hdr *hdr);
int pool_set_parse(struct pool_set **setp, const char *path);
void *pool_set_file_map(struct pool_set_file *file, uint64_t offset);
int pool_read(struct pool_data *pool, void *buff, size_t nbytes,
uint64_t off);
int pool_write(struct pool_data *pool, const void *buff, size_t nbytes,
uint64_t off);
int pool_copy(struct pool_data *pool, const char *dst_path, int overwrite);
int pool_set_part_copy(struct pool_set_part *dpart,
struct pool_set_part *spart, int overwrite);
int pool_memset(struct pool_data *pool, uint64_t off, int c, size_t count);
unsigned pool_set_files_count(struct pool_set_file *file);
int pool_set_file_map_headers(struct pool_set_file *file, int rdonly, int prv);
void pool_set_file_unmap_headers(struct pool_set_file *file);
void pool_hdr_default(enum pool_type type, struct pool_hdr *hdrp);
enum pool_type pool_hdr_get_type(const struct pool_hdr *hdrp);
enum pool_type pool_set_type(struct pool_set *set);
const char *pool_get_pool_type_str(enum pool_type type);
int pool_btt_info_valid(struct btt_info *infop);
int pool_blk_get_first_valid_arena(struct pool_data *pool,
struct arena *arenap);
int pool_blk_bsize_valid(uint32_t bsize, uint64_t fsize);
uint64_t pool_next_arena_offset(struct pool_data *pool, uint64_t header_offset);
uint64_t pool_get_first_valid_btt(struct pool_data *pool,
struct btt_info *infop, uint64_t offset, bool *zeroed);
size_t pool_get_min_size(enum pool_type);
#if FAULT_INJECTION
void
pmempool_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at);
int
pmempool_fault_injection_enabled(void);
#else
static inline void
pmempool_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at)
{
abort();
}
static inline int
pmempool_fault_injection_enabled(void)
{
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
#endif
| 3,712 | 21.640244 | 80 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem/pmem.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* pmem.h -- internal definitions for libpmem
*/
#ifndef PMEM_H
#define PMEM_H
#include <stddef.h>
#include "alloc.h"
#include "fault_injection.h"
#include "util.h"
#include "valgrind_internal.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PMEM_LOG_PREFIX "libpmem"
#define PMEM_LOG_LEVEL_VAR "PMEM_LOG_LEVEL"
#define PMEM_LOG_FILE_VAR "PMEM_LOG_FILE"
typedef int (*is_pmem_func)(const void *addr, size_t len);
void pmem_init(void);
void pmem_os_init(is_pmem_func *func);
int is_pmem_detect(const void *addr, size_t len);
void *pmem_map_register(int fd, size_t len, const char *path, int is_dev_dax);
#if FAULT_INJECTION
void
pmem_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at);
int
pmem_fault_injection_enabled(void);
#else
static inline void
pmem_inject_fault_at(enum pmem_allocation_type type, int nth,
const char *at)
{
abort();
}
static inline int
pmem_fault_injection_enabled(void)
{
return 0;
}
#endif
#ifdef __cplusplus
}
#endif
#endif
| 1,089 | 17.474576 | 78 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/auto_flush_windows.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2019, Intel Corporation */
#ifndef PMEM2_AUTO_FLUSH_WINDOWS_H
#define PMEM2_AUTO_FLUSH_WINDOWS_H 1
#define ACPI_SIGNATURE 0x41435049 /* hex value of ACPI signature */
#define NFIT_REV_SIGNATURE 0x5449464e /* hex value of htonl(NFIT) signature */
#define NFIT_STR_SIGNATURE "NFIT"
#define NFIT_SIGNATURE_LEN 4
#define NFIT_OEM_ID_LEN 6
#define NFIT_OEM_TABLE_ID_LEN 8
#define NFIT_MAX_STRUCTURES 8
#define PCS_RESERVED 3
#define PCS_RESERVED_2 4
#define PCS_TYPE_NUMBER 7
/* check if bit on 'bit' position in number 'num' is set */
#define CHECK_BIT(num, bit) (((num) >> (bit)) & 1)
/*
* sets alignment of members of structure
*/
#pragma pack(1)
struct platform_capabilities
{
uint16_t type;
uint16_t length;
uint8_t highest_valid;
uint8_t reserved[PCS_RESERVED];
uint32_t capabilities;
uint8_t reserved2[PCS_RESERVED_2];
};
struct nfit_header
{
uint8_t signature[NFIT_SIGNATURE_LEN];
uint32_t length;
uint8_t revision;
uint8_t checksum;
uint8_t oem_id[NFIT_OEM_ID_LEN];
uint8_t oem_table_id[NFIT_OEM_TABLE_ID_LEN];
uint32_t oem_revision;
uint8_t creator_id[4];
uint32_t creator_revision;
uint32_t reserved;
};
#pragma pack()
#endif
| 1,215 | 22.843137 | 78 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/region_namespace.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* region_namespace.h -- internal definitions for libpmem2
* common region related functions
*/
#ifndef PMDK_REGION_NAMESPACE_H
#define PMDK_REGION_NAMESPACE_H 1
#include "os.h"
#include "pmem2_utils.h"
#include "source.h"
#ifdef __cplusplus
extern "C" {
#endif
int pmem2_get_region_id(const struct pmem2_source *src, unsigned *region_id);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_REGION_NAMESPACE_H */
| 520 | 18.296296 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/config.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* config.h -- internal definitions for pmem2_config
*/
#ifndef PMEM2_CONFIG_H
#define PMEM2_CONFIG_H
#include "libpmem2.h"
#define PMEM2_GRANULARITY_INVALID ((enum pmem2_granularity) (-1))
#define PMEM2_ADDRESS_ANY 0 /* default value of the address request type */
struct pmem2_config {
/* offset from the beginning of the file */
size_t offset;
size_t length; /* length of the mapping */
/* persistence granularity requested by user */
void *addr; /* address of the mapping */
int addr_request; /* address request type */
enum pmem2_granularity requested_max_granularity;
enum pmem2_sharing_type sharing; /* the way the file will be mapped */
unsigned protection_flag;
};
void pmem2_config_init(struct pmem2_config *cfg);
int pmem2_config_validate_length(const struct pmem2_config *cfg,
size_t file_len, size_t alignment);
int pmem2_config_validate_addr_alignment(const struct pmem2_config *cfg,
const struct pmem2_source *src);
#endif /* PMEM2_CONFIG_H */
| 1,070 | 28.75 | 75 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/auto_flush.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2018-2019, Intel Corporation */
/*
* auto_flush.h -- auto flush detection functionality
*/
#ifndef PMEM2_AUTO_FLUSH_H
#define PMEM2_AUTO_FLUSH_H 1
#ifdef __cplusplus
extern "C" {
#endif
int pmem2_auto_flush(void);
#ifdef __cplusplus
}
#endif
#endif
| 311 | 13.181818 | 53 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/map.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2019-2020, Intel Corporation */
/*
* map.h -- internal definitions for libpmem2
*/
#ifndef PMEM2_MAP_H
#define PMEM2_MAP_H
#include <stddef.h>
#include <stdbool.h>
#include "libpmem2.h"
#include "os.h"
#include "source.h"
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*pmem2_deep_flush_fn)(struct pmem2_map *map,
void *ptr, size_t size);
struct pmem2_map {
void *addr; /* base address */
size_t reserved_length; /* length of the mapping reservation */
size_t content_length; /* length of the mapped content */
/* effective persistence granularity */
enum pmem2_granularity effective_granularity;
pmem2_persist_fn persist_fn;
pmem2_flush_fn flush_fn;
pmem2_drain_fn drain_fn;
pmem2_deep_flush_fn deep_flush_fn;
pmem2_memmove_fn memmove_fn;
pmem2_memcpy_fn memcpy_fn;
pmem2_memset_fn memset_fn;
struct pmem2_source source;
};
enum pmem2_granularity get_min_granularity(bool eADR, bool is_pmem,
enum pmem2_sharing_type sharing);
struct pmem2_map *pmem2_map_find(const void *addr, size_t len);
int pmem2_register_mapping(struct pmem2_map *map);
int pmem2_unregister_mapping(struct pmem2_map *map);
void pmem2_map_init(void);
void pmem2_map_fini(void);
int pmem2_validate_offset(const struct pmem2_config *cfg,
size_t *offset, size_t alignment);
#ifdef __cplusplus
}
#endif
#endif /* map.h */
| 1,426 | 22.016129 | 67 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/deep_flush.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* deep_flush.h -- functions for deep flush functionality
*/
#ifndef PMEM2_DEEP_FLUSH_H
#define PMEM2_DEEP_FLUSH_H 1
#include "map.h"
#ifdef __cplusplus
extern "C" {
#endif
int pmem2_deep_flush_write(unsigned region_id);
int pmem2_deep_flush_dax(struct pmem2_map *map, void *ptr, size_t size);
int pmem2_deep_flush_page(struct pmem2_map *map, void *ptr, size_t size);
int pmem2_deep_flush_cache(struct pmem2_map *map, void *ptr, size_t size);
int pmem2_deep_flush_byte(struct pmem2_map *map, void *ptr, size_t size);
#ifdef __cplusplus
}
#endif
#endif
| 644 | 22.035714 | 74 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/ravl_interval.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2020, Intel Corporation */
/*
* ravl_interval.h -- internal definitions for ravl_interval
*/
#ifndef RAVL_INTERVAL_H
#define RAVL_INTERVAL_H
#include "libpmem2.h"
#include "os_thread.h"
#include "ravl.h"
struct ravl_interval;
struct ravl_interval_node;
typedef size_t ravl_interval_min(void *addr);
typedef size_t ravl_interval_max(void *addr);
struct ravl_interval *ravl_interval_new(ravl_interval_min *min,
ravl_interval_min *max);
void ravl_interval_delete(struct ravl_interval *ri);
int ravl_interval_insert(struct ravl_interval *ri, void *addr);
int ravl_interval_remove(struct ravl_interval *ri,
struct ravl_interval_node *rin);
struct ravl_interval_node *ravl_interval_find_equal(struct ravl_interval *ri,
void *addr);
struct ravl_interval_node *ravl_interval_find(struct ravl_interval *ri,
void *addr);
void *ravl_interval_data(struct ravl_interval_node *rin);
#endif
| 947 | 27.727273 | 77 | h |
null | NearPMSW-main/nearpm/shadow/pmdkArrSwap-sd/src/libpmem2/pmem2_arch.h | // SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2014-2020, Intel Corporation */
/*
* pmem2_arch.h -- core-arch interface
*/
#ifndef PMEM2_ARCH_H
#define PMEM2_ARCH_H
#include <stddef.h>
#include "libpmem2.h"
#include "util.h"
#include "valgrind_internal.h"
#ifdef __cplusplus
extern "C" {
#endif
struct pmem2_arch_info;
typedef void (*fence_func)(void);
typedef void (*flush_func)(const void *, size_t);
typedef void *(*memmove_nodrain_func)(void *pmemdest, const void *src,
size_t len, unsigned flags, flush_func flush);
typedef void *(*memset_nodrain_func)(void *pmemdest, int c, size_t len,
unsigned flags, flush_func flush);
struct pmem2_arch_info {
memmove_nodrain_func memmove_nodrain;
memmove_nodrain_func memmove_nodrain_eadr;
memset_nodrain_func memset_nodrain;
memset_nodrain_func memset_nodrain_eadr;
flush_func flush;
fence_func fence;
int flush_has_builtin_fence;
};
void pmem2_arch_init(struct pmem2_arch_info *info);
/*
* flush_empty_nolog -- (internal) do not flush the CPU cache
*/
static force_inline void
flush_empty_nolog(const void *addr, size_t len)
{
/* NOP, but tell pmemcheck about it */
VALGRIND_DO_FLUSH(addr, len);
}
void *memmove_nodrain_generic(void *pmemdest, const void *src, size_t len,
unsigned flags, flush_func flush);
void *memset_nodrain_generic(void *pmemdest, int c, size_t len, unsigned flags,
flush_func flush);
#ifdef __cplusplus
}
#endif
#endif
| 1,427 | 22.8 | 79 | h |
Subsets and Splits