Merge pull request #259 from Ostrokrzew/ut_debug
Unify ocf_env for regular use and unit tests
This commit is contained in:
commit
5caaa5e4a6
9
env/posix/ocf_env.c
vendored
9
env/posix/ocf_env.c
vendored
@ -7,6 +7,7 @@
|
|||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
|
|
||||||
|
/* ALLOCATOR */
|
||||||
struct _env_allocator {
|
struct _env_allocator {
|
||||||
/*!< Memory pool ID unique name */
|
/*!< Memory pool ID unique name */
|
||||||
char *name;
|
char *name;
|
||||||
@ -45,7 +46,6 @@ void *env_allocator_new(env_allocator *allocator)
|
|||||||
return &item->data;
|
return &item->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...)
|
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...)
|
||||||
{
|
{
|
||||||
char name[OCF_ALLOCATOR_NAME_MAX] = { '\0' };
|
char name[OCF_ALLOCATOR_NAME_MAX] = { '\0' };
|
||||||
@ -110,8 +110,7 @@ void env_allocator_destroy(env_allocator *allocator)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** DEBUGING *** */
|
/* DEBUGING */
|
||||||
|
|
||||||
#define ENV_TRACE_DEPTH 16
|
#define ENV_TRACE_DEPTH 16
|
||||||
|
|
||||||
void env_stack_trace(void)
|
void env_stack_trace(void)
|
||||||
@ -129,13 +128,13 @@ void env_stack_trace(void)
|
|||||||
free(messages);
|
free(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** CRC *** */
|
/* CRC */
|
||||||
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len)
|
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len)
|
||||||
{
|
{
|
||||||
return crc32(crc, data, len);
|
return crc32(crc, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** execution contexts *** */
|
/* EXECUTION CONTEXTS */
|
||||||
pthread_mutex_t *exec_context_mutex;
|
pthread_mutex_t *exec_context_mutex;
|
||||||
|
|
||||||
static void __attribute__((constructor)) init_execution_context(void)
|
static void __attribute__((constructor)) init_execution_context(void)
|
||||||
|
143
env/posix/ocf_env.h
vendored
143
env/posix/ocf_env.h
vendored
@ -15,12 +15,9 @@
|
|||||||
|
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <linux/stddef.h>
|
#include <linux/stddef.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -41,6 +38,15 @@
|
|||||||
/* linux sector 512-bytes */
|
/* linux sector 512-bytes */
|
||||||
#define ENV_SECTOR_SHIFT 9
|
#define ENV_SECTOR_SHIFT 9
|
||||||
|
|
||||||
|
#define OCF_ALLOCATOR_NAME_MAX 128
|
||||||
|
|
||||||
|
#define PAGE_SIZE 4096
|
||||||
|
|
||||||
|
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
||||||
|
#define min(a,b) MIN(a,b)
|
||||||
|
|
||||||
|
#define ENV_PRIu64 "lu"
|
||||||
|
|
||||||
typedef uint8_t u8;
|
typedef uint8_t u8;
|
||||||
typedef uint16_t u16;
|
typedef uint16_t u16;
|
||||||
typedef uint32_t u32;
|
typedef uint32_t u32;
|
||||||
@ -49,19 +55,16 @@ typedef uint64_t u64;
|
|||||||
typedef uint64_t sector_t;
|
typedef uint64_t sector_t;
|
||||||
|
|
||||||
#define __packed __attribute__((packed))
|
#define __packed __attribute__((packed))
|
||||||
#define __aligned(x) __attribute__((aligned(x)))
|
|
||||||
|
|
||||||
#define likely(cond) __builtin_expect(!!(cond), 1)
|
#define likely(cond) __builtin_expect(!!(cond), 1)
|
||||||
#define unlikely(cond) __builtin_expect(!!(cond), 0)
|
#define unlikely(cond) __builtin_expect(!!(cond), 0)
|
||||||
|
|
||||||
#define min(a,b) MIN(a,b)
|
/* MEMORY MANAGEMENT */
|
||||||
|
#define ENV_MEM_NORMAL 0
|
||||||
#define OCF_ALLOCATOR_NAME_MAX 128
|
#define ENV_MEM_NOIO 0
|
||||||
|
#define ENV_MEM_ATOMIC 0
|
||||||
#define PAGE_SIZE 4096
|
|
||||||
|
|
||||||
/* *** DEBUGING *** */
|
|
||||||
|
|
||||||
|
/* DEBUGING */
|
||||||
#define ENV_WARN(cond, fmt...) printf(fmt)
|
#define ENV_WARN(cond, fmt...) printf(fmt)
|
||||||
#define ENV_WARN_ON(cond) ;
|
#define ENV_WARN_ON(cond) ;
|
||||||
#define ENV_WARN_ONCE(cond, fmt...) ENV_WARN(cond, fmt)
|
#define ENV_WARN_ONCE(cond, fmt...) ENV_WARN(cond, fmt)
|
||||||
@ -69,11 +72,36 @@ typedef uint64_t sector_t;
|
|||||||
#define ENV_BUG() assert(0)
|
#define ENV_BUG() assert(0)
|
||||||
#define ENV_BUG_ON(cond) do { if (cond) ENV_BUG(); } while (0)
|
#define ENV_BUG_ON(cond) do { if (cond) ENV_BUG(); } while (0)
|
||||||
|
|
||||||
/* *** MEMORY MANAGEMENT *** */
|
/* MISC UTILITIES */
|
||||||
#define ENV_MEM_NORMAL 0
|
#define container_of(ptr, type, member) ({ \
|
||||||
#define ENV_MEM_NOIO 0
|
const typeof(((type *)0)->member)*__mptr = (ptr); \
|
||||||
#define ENV_MEM_ATOMIC 0
|
(type *)((char *)__mptr - offsetof(type, member)); })
|
||||||
|
|
||||||
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
|
||||||
|
|
||||||
|
/* STRING OPERATIONS */
|
||||||
|
#define env_memcpy(dest, dmax, src, slen) ({ \
|
||||||
|
memcpy(dest, src, min(dmax, slen)); \
|
||||||
|
0; \
|
||||||
|
})
|
||||||
|
#define env_memset(dest, dmax, val) ({ \
|
||||||
|
memset(dest, val, dmax); \
|
||||||
|
0; \
|
||||||
|
})
|
||||||
|
#define env_memcmp(s1, s1max, s2, s2max, diff) ({ \
|
||||||
|
*diff = memcmp(s1, s2, min(s1max, s2max)); \
|
||||||
|
0; \
|
||||||
|
})
|
||||||
|
#define env_strdup strndup
|
||||||
|
#define env_strnlen(s, smax) strnlen(s, smax)
|
||||||
|
#define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, min(slen1, slen2))
|
||||||
|
#define env_strncpy(dest, dmax, src, slen) ({ \
|
||||||
|
strncpy(dest, src, min(dmax - 1, slen)); \
|
||||||
|
dest[dmax - 1] = '\0'; \
|
||||||
|
0; \
|
||||||
|
})
|
||||||
|
|
||||||
|
/* MEMORY MANAGEMENT */
|
||||||
static inline void *env_malloc(size_t size, int flags)
|
static inline void *env_malloc(size_t size, int flags)
|
||||||
{
|
{
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
@ -109,9 +137,7 @@ static inline void env_vfree(const void *ptr)
|
|||||||
free((void *)ptr);
|
free((void *)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SECURE MEMORY MANAGEMENT */
|
||||||
/* *** SECURE MEMORY MANAGEMENT *** */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* OCF adapter can opt to take additional steps to securely allocate and free
|
* OCF adapter can opt to take additional steps to securely allocate and free
|
||||||
* memory used by OCF to store cache metadata. This is to prevent other
|
* memory used by OCF to store cache metadata. This is to prevent other
|
||||||
@ -157,8 +183,7 @@ static inline uint64_t env_get_free_memory(void)
|
|||||||
return sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
|
return sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** ALLOCATOR *** */
|
/* ALLOCATOR */
|
||||||
|
|
||||||
typedef struct _env_allocator env_allocator;
|
typedef struct _env_allocator env_allocator;
|
||||||
|
|
||||||
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...);
|
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...);
|
||||||
@ -169,8 +194,7 @@ void *env_allocator_new(env_allocator *allocator);
|
|||||||
|
|
||||||
void env_allocator_del(env_allocator *allocator, void *item);
|
void env_allocator_del(env_allocator *allocator, void *item);
|
||||||
|
|
||||||
/* *** MUTEX *** */
|
/* MUTEX */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_mutex_t m;
|
pthread_mutex_t m;
|
||||||
} env_mutex;
|
} env_mutex;
|
||||||
@ -209,8 +233,7 @@ static inline int env_mutex_destroy(env_mutex *mutex)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** RECURSIVE MUTEX *** */
|
/* RECURSIVE MUTEX */
|
||||||
|
|
||||||
typedef env_mutex env_rmutex;
|
typedef env_mutex env_rmutex;
|
||||||
|
|
||||||
static inline int env_rmutex_init(env_rmutex *rmutex)
|
static inline int env_rmutex_init(env_rmutex *rmutex)
|
||||||
@ -247,7 +270,7 @@ static inline int env_rmutex_destroy(env_rmutex *rmutex)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** RW SEMAPHORE *** */
|
/* RW SEMAPHORE */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_rwlock_t lock;
|
pthread_rwlock_t lock;
|
||||||
} env_rwsem;
|
} env_rwsem;
|
||||||
@ -292,7 +315,7 @@ static inline int env_rwsem_destroy(env_rwsem *s)
|
|||||||
return pthread_rwlock_destroy(&s->lock);
|
return pthread_rwlock_destroy(&s->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** COMPLETION *** */
|
/* COMPLETION */
|
||||||
struct completion {
|
struct completion {
|
||||||
sem_t sem;
|
sem_t sem;
|
||||||
};
|
};
|
||||||
@ -319,8 +342,7 @@ static inline void env_completion_destroy(env_completion *completion)
|
|||||||
sem_destroy(&completion->sem);
|
sem_destroy(&completion->sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** ATOMIC VARIABLES *** */
|
/* ATOMIC VARIABLES */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile int counter;
|
volatile int counter;
|
||||||
} env_atomic;
|
} env_atomic;
|
||||||
@ -444,8 +466,7 @@ static inline long env_atomic64_cmpxchg(env_atomic64 *a, long old_v, long new_v)
|
|||||||
return __sync_val_compare_and_swap(&a->counter, old_v, new_v);
|
return __sync_val_compare_and_swap(&a->counter, old_v, new_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** SPIN LOCKS *** */
|
/* SPIN LOCKS */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_spinlock_t lock;
|
pthread_spinlock_t lock;
|
||||||
} env_spinlock;
|
} env_spinlock;
|
||||||
@ -483,8 +504,7 @@ static inline void env_spinlock_destroy(env_spinlock *l)
|
|||||||
ENV_BUG_ON(pthread_spin_destroy(&l->lock));
|
ENV_BUG_ON(pthread_spin_destroy(&l->lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** RW LOCKS *** */
|
/* RW LOCKS */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pthread_rwlock_t lock;
|
pthread_rwlock_t lock;
|
||||||
} env_rwlock;
|
} env_rwlock;
|
||||||
@ -519,27 +539,7 @@ static inline void env_rwlock_destroy(env_rwlock *l)
|
|||||||
ENV_BUG_ON(pthread_rwlock_destroy(&l->lock));
|
ENV_BUG_ON(pthread_rwlock_destroy(&l->lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** WAITQUEUE *** */
|
/* BIT OPERATIONS */
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
sem_t sem;
|
|
||||||
} env_waitqueue;
|
|
||||||
|
|
||||||
#define env_waitqueue_wait(w, condition) \
|
|
||||||
({ \
|
|
||||||
int __ret = 0; \
|
|
||||||
if (!(condition)) \
|
|
||||||
sem_wait(&w.sem); \
|
|
||||||
__ret = __ret; \
|
|
||||||
})
|
|
||||||
|
|
||||||
static inline void env_waitqueue_destroy(env_waitqueue *w)
|
|
||||||
{
|
|
||||||
sem_destroy(&w->sem);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *** BIT OPERATIONS *** */
|
|
||||||
|
|
||||||
static inline void env_bit_set(int nr, volatile void *addr)
|
static inline void env_bit_set(int nr, volatile void *addr)
|
||||||
{
|
{
|
||||||
char *byte = (char *)addr + (nr >> 3);
|
char *byte = (char *)addr + (nr >> 3);
|
||||||
@ -565,6 +565,7 @@ static inline bool env_bit_test(int nr, const volatile unsigned long *addr)
|
|||||||
return !!(*byte & mask);
|
return !!(*byte & mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SCHEDULING */
|
||||||
static inline int env_in_interrupt(void)
|
static inline int env_in_interrupt(void)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@ -597,8 +598,7 @@ static inline uint64_t env_secs_to_ticks(uint64_t j)
|
|||||||
return j * 1000000;
|
return j * 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** SORTING *** */
|
/* SORTING */
|
||||||
|
|
||||||
static inline void env_sort(void *base, size_t num, size_t size,
|
static inline void env_sort(void *base, size_t num, size_t size,
|
||||||
int (*cmp_fn)(const void *, const void *),
|
int (*cmp_fn)(const void *, const void *),
|
||||||
void (*swap_fn)(void *, void *, int size))
|
void (*swap_fn)(void *, void *, int size))
|
||||||
@ -606,36 +606,7 @@ static inline void env_sort(void *base, size_t num, size_t size,
|
|||||||
qsort(base, num, size, cmp_fn);
|
qsort(base, num, size, cmp_fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *** STRING OPERATIONS *** */
|
/* TIME */
|
||||||
#define env_memset(dest, dmax, val) ({ \
|
|
||||||
memset(dest, val, dmax); \
|
|
||||||
0; \
|
|
||||||
})
|
|
||||||
#define env_memcpy(dest, dmax, src, slen) ({ \
|
|
||||||
memcpy(dest, src, min(dmax, slen)); \
|
|
||||||
0; \
|
|
||||||
})
|
|
||||||
#define env_memcmp(s1, s1max, s2, s2max, diff) ({ \
|
|
||||||
*diff = memcmp(s1, s2, min(s1max, s2max)); \
|
|
||||||
0; \
|
|
||||||
})
|
|
||||||
#define env_strdup strndup
|
|
||||||
#define env_strnlen(s, smax) strnlen(s, smax)
|
|
||||||
#define env_strncmp(s1, slen1, s2, slen2) strncmp(s1, s2, min(slen1, slen2))
|
|
||||||
#define env_strncpy(dest, dmax, src, slen) ({ \
|
|
||||||
strncpy(dest, src, min(dmax - 1, slen)); \
|
|
||||||
dest[dmax - 1] = '\0'; \
|
|
||||||
0; \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* *** MISC UTILITIES *** */
|
|
||||||
#define container_of(ptr, type, member) ({ \
|
|
||||||
const typeof(((type *)0)->member)*__mptr = (ptr); \
|
|
||||||
(type *)((char *)__mptr - offsetof(type, member)); })
|
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
|
|
||||||
|
|
||||||
/* *** TIME *** */
|
|
||||||
static inline void env_msleep(uint64_t n)
|
static inline void env_msleep(uint64_t n)
|
||||||
{
|
{
|
||||||
usleep(n * 1000);
|
usleep(n * 1000);
|
||||||
@ -647,8 +618,6 @@ struct env_timeval {
|
|||||||
|
|
||||||
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len);
|
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len);
|
||||||
|
|
||||||
#define ENV_PRIu64 "lu"
|
|
||||||
|
|
||||||
unsigned env_get_execution_context(void);
|
unsigned env_get_execution_context(void);
|
||||||
void env_put_execution_context(unsigned ctx);
|
void env_put_execution_context(unsigned ctx);
|
||||||
unsigned env_get_execution_context_count(void);
|
unsigned env_get_execution_context_count(void);
|
||||||
|
2
env/posix/ocf_env_headers.h
vendored
2
env/posix/ocf_env_headers.h
vendored
@ -11,7 +11,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* TODO: Move prefix printing to context logger. */
|
/* TODO: Move prefix printing to context logger. */
|
||||||
#define OCF_LOGO "Intel(R) OCF"
|
#define OCF_LOGO "OCF"
|
||||||
#define OCF_PREFIX_SHORT "[" OCF_LOGO "] "
|
#define OCF_PREFIX_SHORT "[" OCF_LOGO "] "
|
||||||
#define OCF_PREFIX_LONG "Open CAS Framework"
|
#define OCF_PREFIX_LONG "Open CAS Framework"
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
* @brief OCF cache API
|
* @brief OCF cache API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ocf_types.h"
|
|
||||||
#include "ocf_volume.h"
|
#include "ocf_volume.h"
|
||||||
#include "ocf_ctx.h"
|
#include "ocf_ctx.h"
|
||||||
#include "ocf_def.h"
|
#include "ocf_def.h"
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#ifndef __OCF_CORE_H__
|
#ifndef __OCF_CORE_H__
|
||||||
#define __OCF_CORE_H__
|
#define __OCF_CORE_H__
|
||||||
|
|
||||||
#include "ocf_types.h"
|
|
||||||
#include "ocf_volume.h"
|
#include "ocf_volume.h"
|
||||||
#include "ocf_io.h"
|
#include "ocf_io.h"
|
||||||
#include "ocf_mngt.h"
|
#include "ocf_mngt.h"
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
* @brief OCF library context API
|
* @brief OCF library context API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ocf_types.h"
|
|
||||||
#include "ocf_volume.h"
|
#include "ocf_volume.h"
|
||||||
#include "ocf_logger.h"
|
#include "ocf_logger.h"
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#ifndef __OCF_MNGT_H__
|
#ifndef __OCF_MNGT_H__
|
||||||
#define __OCF_MNGT_H__
|
#define __OCF_MNGT_H__
|
||||||
|
|
||||||
#include "ocf_types.h"
|
|
||||||
#include "ocf_cache.h"
|
#include "ocf_cache.h"
|
||||||
#include "ocf_core.h"
|
#include "ocf_core.h"
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
#include "ocf_types.h"
|
#include "ocf_types.h"
|
||||||
#include "ocf_env.h"
|
#include "ocf_env.h"
|
||||||
#include "ocf_err.h"
|
|
||||||
|
|
||||||
struct ocf_io;
|
struct ocf_io;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class TestGenerator(object):
|
|||||||
def get_autowrap_file_include(self, test_file_path):
|
def get_autowrap_file_include(self, test_file_path):
|
||||||
autowrap_file = test_file_path.rsplit(".", 1)[0]
|
autowrap_file = test_file_path.rsplit(".", 1)[0]
|
||||||
autowrap_file = autowrap_file.replace(self.main_UT_dir, "")
|
autowrap_file = autowrap_file.replace(self.main_UT_dir, "")
|
||||||
autowrap_file += "_generated_warps.c"
|
autowrap_file += "_generated_wraps.c"
|
||||||
return "#include \"" + autowrap_file + "\"\n\n"
|
return "#include \"" + autowrap_file + "\"\n\n"
|
||||||
|
|
||||||
def get_includes(self, abs_path_to_tested_file):
|
def get_includes(self, abs_path_to_tested_file):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python3.6
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright(c) 2012-2018 Intel Corporation
|
# Copyright(c) 2012-2018 Intel Corporation
|
||||||
@ -42,6 +42,7 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
script_dir_abs_path = ""
|
script_dir_abs_path = ""
|
||||||
|
|
||||||
main_UT_dir = ""
|
main_UT_dir = ""
|
||||||
|
main_env_dir = ""
|
||||||
main_tested_dir = ""
|
main_tested_dir = ""
|
||||||
|
|
||||||
ctags_path = ""
|
ctags_path = ""
|
||||||
@ -70,6 +71,7 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
self.set_ctags_path()
|
self.set_ctags_path()
|
||||||
|
|
||||||
self.set_main_UT_dir()
|
self.set_main_UT_dir()
|
||||||
|
self.set_main_env_dir()
|
||||||
self.set_main_tested_dir()
|
self.set_main_tested_dir()
|
||||||
|
|
||||||
self.test_catalogues_list = tests_config.DIRECTORIES_WITH_TESTS_LIST
|
self.test_catalogues_list = tests_config.DIRECTORIES_WITH_TESTS_LIST
|
||||||
@ -141,7 +143,7 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
|
|
||||||
def get_autowrap_file_path(self, test_file_path):
|
def get_autowrap_file_path(self, test_file_path):
|
||||||
wrap_file_path = test_file_path.rsplit('.', 1)[0]
|
wrap_file_path = test_file_path.rsplit('.', 1)[0]
|
||||||
wrap_file_path = wrap_file_path + "_generated_warps.c"
|
wrap_file_path = wrap_file_path + "_generated_wraps.c"
|
||||||
return wrap_file_path
|
return wrap_file_path
|
||||||
|
|
||||||
def prepare_autowraps(self, test_file_path, preprocessed_file_path):
|
def prepare_autowraps(self, test_file_path, preprocessed_file_path):
|
||||||
@ -158,7 +160,10 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
with open(preprocessed_file_path) as f:
|
with open(preprocessed_file_path) as f:
|
||||||
code = f.readlines()
|
code = f.readlines()
|
||||||
for function in functions_to_wrap:
|
for function in functions_to_wrap:
|
||||||
if function.startswith("env_") or function.startswith("bug"):
|
if function.startswith("env_") or function.startswith("bug") \
|
||||||
|
or function.startswith("memcpy"):
|
||||||
|
# added memcpy function to list of ignored functions
|
||||||
|
# because this is macro
|
||||||
continue
|
continue
|
||||||
for tag in tags_list:
|
for tag in tags_list:
|
||||||
if function in tag:
|
if function in tag:
|
||||||
@ -171,7 +176,7 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
wrap_file_path = self.get_main_UT_dir() + self.get_autowrap_file_path(test_file_path)
|
wrap_file_path = self.get_main_UT_dir() + self.get_autowrap_file_path(test_file_path)
|
||||||
|
|
||||||
with open(wrap_file_path, "w") as f:
|
with open(wrap_file_path, "w") as f:
|
||||||
f.write("/* This is file is generated by UT framework */\n")
|
f.write("/* This file is generated by UT framework */\n")
|
||||||
for wrap in wrap_list:
|
for wrap in wrap_list:
|
||||||
f.write(wrap + "\n")
|
f.write(wrap + "\n")
|
||||||
|
|
||||||
@ -655,6 +660,9 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
def get_main_UT_dir(self):
|
def get_main_UT_dir(self):
|
||||||
return os.path.normpath(self.main_UT_dir) + os.sep
|
return os.path.normpath(self.main_UT_dir) + os.sep
|
||||||
|
|
||||||
|
def get_main_env_dir(self):
|
||||||
|
return os.path.normpath(self.main_env_dir) + os.sep
|
||||||
|
|
||||||
def get_main_tested_dir(self):
|
def get_main_tested_dir(self):
|
||||||
return os.path.normpath(self.main_tested_dir) + os.sep
|
return os.path.normpath(self.main_tested_dir) + os.sep
|
||||||
|
|
||||||
@ -673,6 +681,17 @@ class UnitTestsSourcesGenerator(object):
|
|||||||
def get_includes_to_copy_dict(self):
|
def get_includes_to_copy_dict(self):
|
||||||
return self.includes_to_copy_dict
|
return self.includes_to_copy_dict
|
||||||
|
|
||||||
|
def set_main_env_dir(self):
|
||||||
|
main_env_dir = os.path.normpath(os.path.normpath(self.get_script_dir_path()
|
||||||
|
+ os.sep
|
||||||
|
+ tests_config.
|
||||||
|
MAIN_DIRECTORY_OF_ENV_FILES))
|
||||||
|
if not os.path.isdir(main_env_dir):
|
||||||
|
print("Given path to main env directory is wrong!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
self.main_env_dir = main_env_dir
|
||||||
|
|
||||||
def set_main_UT_dir(self):
|
def set_main_UT_dir(self):
|
||||||
main_UT_dir = os.path.normpath(os.path.normpath(self.get_script_dir_path()
|
main_UT_dir = os.path.normpath(os.path.normpath(self.get_script_dir_path()
|
||||||
+ os.sep
|
+ os.sep
|
||||||
|
@ -19,10 +19,46 @@ def run_command(args):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def rmv_cmd(trgt):
|
||||||
|
"""Remove target with force"""
|
||||||
|
result = run_command(["rm", "-rf", trgt])
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise Exception("Removing {} before testing failed!".
|
||||||
|
format(os.path.dirname(os.path.realpath(__file__))
|
||||||
|
+ trgt))
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup():
|
||||||
|
"""Delete files created by unit tests"""
|
||||||
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
test_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS)
|
||||||
|
result = run_command(["cd", test_dir])
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise Exception("Cleanup before testing failed!")
|
||||||
|
|
||||||
|
# r=root, d=directories, f = files
|
||||||
|
for r, d, f in os.walk(test_dir):
|
||||||
|
for file in f:
|
||||||
|
if '_generated_wrap' in file:
|
||||||
|
rmv_cmd(file)
|
||||||
|
|
||||||
|
rmv_cmd("preprocessed_sources_repository")
|
||||||
|
rmv_cmd("sources_to_test_repository")
|
||||||
|
rmv_cmd("build")
|
||||||
|
|
||||||
|
result = run_command(["cd", script_path])
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise Exception("Cleanup before testing failed!")
|
||||||
|
|
||||||
|
|
||||||
|
cleanup()
|
||||||
|
|
||||||
script_path = os.path.dirname(os.path.realpath(__file__))
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
main_UT_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS)
|
main_UT_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_UNIT_TESTS)
|
||||||
|
|
||||||
|
main_env_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_ENV_FILES)
|
||||||
|
|
||||||
main_tested_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_TESTED_PROJECT)
|
main_tested_dir = os.path.join(script_path, tests_config.MAIN_DIRECTORY_OF_TESTED_PROJECT)
|
||||||
|
|
||||||
if not os.path.isdir(os.path.join(main_UT_dir, "ocf_env", "ocf")):
|
if not os.path.isdir(os.path.join(main_UT_dir, "ocf_env", "ocf")):
|
||||||
@ -31,6 +67,12 @@ if not os.path.isdir(os.path.join(main_UT_dir, "ocf_env", "ocf")):
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise Exception("Cannot create ocf_env/ocf directory!")
|
raise Exception("Cannot create ocf_env/ocf directory!")
|
||||||
|
|
||||||
|
result = run_command(["ln", "-fs",
|
||||||
|
os.path.join(main_env_dir, "*"),
|
||||||
|
os.path.join(main_UT_dir, "ocf_env")])
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise Exception("Preparing env sources for testing failed!")
|
||||||
|
|
||||||
result = run_command(["cp", "-r",
|
result = run_command(["cp", "-r",
|
||||||
os.path.join(main_tested_dir, "inc", "*"),
|
os.path.join(main_tested_dir, "inc", "*"),
|
||||||
os.path.join(main_UT_dir, "ocf_env", "ocf")])
|
os.path.join(main_UT_dir, "ocf_env", "ocf")])
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
MAIN_DIRECTORY_OF_TESTED_PROJECT = "../../../"
|
MAIN_DIRECTORY_OF_TESTED_PROJECT = "../../../"
|
||||||
|
|
||||||
|
MAIN_DIRECTORY_OF_ENV_FILES = MAIN_DIRECTORY_OF_TESTED_PROJECT + "env/posix/"
|
||||||
|
|
||||||
MAIN_DIRECTORY_OF_UNIT_TESTS = "../tests/"
|
MAIN_DIRECTORY_OF_UNIT_TESTS = "../tests/"
|
||||||
|
|
||||||
# Paths to all directories, in which tests are stored. All paths should be relative to
|
# Paths to all directories, in which tests are stored. All paths should be relative to
|
||||||
|
@ -15,7 +15,7 @@ framework_script_path = os.path.join(script_path, "../framework/add_new_test_fil
|
|||||||
framework_script_path = os.path.normpath(framework_script_path)
|
framework_script_path = os.path.normpath(framework_script_path)
|
||||||
status, output = commands.getstatusoutput(framework_script_path + " " + args)
|
status, output = commands.getstatusoutput(framework_script_path + " " + args)
|
||||||
|
|
||||||
print output
|
print(output)
|
||||||
|
|
||||||
if status == 0:
|
if status == 0:
|
||||||
path = output.split(" ", 1)[0]
|
path = output.split(" ", 1)[0]
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "../concurrency/ocf_cache_line_concurrency.h"
|
#include "../concurrency/ocf_cache_line_concurrency.h"
|
||||||
#include "../ocf_def_priv.h"
|
#include "../ocf_def_priv.h"
|
||||||
|
|
||||||
#include "cleaning/alru.c/cleaning_policy_alru_initialize_part_test_generated_warps.c"
|
#include "cleaning/alru.c/cleaning_policy_alru_initialize_part_test_generated_wraps.c"
|
||||||
|
|
||||||
|
|
||||||
static void cleaning_policy_alru_initialize_test01(void **state)
|
static void cleaning_policy_alru_initialize_test01(void **state)
|
||||||
@ -58,7 +58,7 @@ static void cleaning_policy_alru_initialize_test01(void **state)
|
|||||||
|
|
||||||
assert_int_equal(result, 0);
|
assert_int_equal(result, 0);
|
||||||
|
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.size, 0);
|
assert_int_equal(env_atomic_read(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size), 0);
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, collision_table_entries);
|
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, collision_table_entries);
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, collision_table_entries);
|
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, collision_table_entries);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ static void cleaning_policy_alru_initialize_test02(void **state)
|
|||||||
cache.device = test_malloc(sizeof(struct ocf_cache_device));
|
cache.device = test_malloc(sizeof(struct ocf_cache_device));
|
||||||
cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime));
|
cache.device->runtime_meta = test_malloc(sizeof(struct ocf_superblock_runtime));
|
||||||
|
|
||||||
cache.user_parts[part_id].runtime->cleaning.policy.alru.size = 1;
|
env_atomic_set(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size, 1);
|
||||||
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head = -collision_table_entries;
|
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head = -collision_table_entries;
|
||||||
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail = -collision_table_entries;
|
cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail = -collision_table_entries;
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ static void cleaning_policy_alru_initialize_test02(void **state)
|
|||||||
|
|
||||||
assert_int_equal(result, 0);
|
assert_int_equal(result, 0);
|
||||||
|
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.size, 1);
|
assert_int_equal(env_atomic_read(&cache.user_parts[part_id].runtime->cleaning.policy.alru.size), 1);
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, -collision_table_entries);
|
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_head, -collision_table_entries);
|
||||||
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, -collision_table_entries);
|
assert_int_equal(cache.user_parts[part_id].runtime->cleaning.policy.alru.lru_tail, -collision_table_entries);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "../mngt/ocf_mngt_common.h"
|
#include "../mngt/ocf_mngt_common.h"
|
||||||
#include "../metadata/metadata.h"
|
#include "../metadata/metadata.h"
|
||||||
|
|
||||||
#include "cleaning/cleaning.c/ocf_cleaner_run_test_generated_warps.c"
|
#include "cleaning/cleaning.c/ocf_cleaner_run_test_generated_wraps.c"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mocked functions. Here we must deliver functions definitions which are not
|
* Mocked functions. Here we must deliver functions definitions which are not
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "ocf_metadata_concurrency.h"
|
#include "ocf_metadata_concurrency.h"
|
||||||
#include "../metadata/metadata_misc.h"
|
#include "../metadata/metadata_misc.h"
|
||||||
|
|
||||||
#include "concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency_generated_warps.c"
|
#include "concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency_generated_wraps.c"
|
||||||
|
|
||||||
void __wrap_ocf_metadata_hash_lock(struct ocf_metadata_lock *metadata_lock,
|
void __wrap_ocf_metadata_hash_lock(struct ocf_metadata_lock *metadata_lock,
|
||||||
ocf_cache_line_t hash, int rw)
|
ocf_cache_line_t hash, int rw)
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "../utils/utils_cache_line.h"
|
#include "../utils/utils_cache_line.h"
|
||||||
|
|
||||||
#include "metadata/metadata_collision.c/metadata_collision_generated_warps.c"
|
#include "metadata/metadata_collision.c/metadata_collision_generated_wraps.c"
|
||||||
|
|
||||||
static void metadata_hash_func_test01(void **state)
|
static void metadata_hash_func_test01(void **state)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ ocf_mngt_cache_mode_has_lazy_write
|
|||||||
#include "../ocf_ctx_priv.h"
|
#include "../ocf_ctx_priv.h"
|
||||||
#include "../cleaning/cleaning.h"
|
#include "../cleaning/cleaning.h"
|
||||||
|
|
||||||
#include "mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test_generated_warps.c"
|
#include "mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test_generated_wraps.c"
|
||||||
/*
|
/*
|
||||||
* Mocked functions
|
* Mocked functions
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include "../ocf_ctx_priv.h"
|
#include "../ocf_ctx_priv.h"
|
||||||
#include "../cleaning/cleaning.h"
|
#include "../cleaning/cleaning.h"
|
||||||
|
|
||||||
#include "mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold_generated_warps.c"
|
#include "mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold_generated_wraps.c"
|
||||||
|
|
||||||
int __wrap_ocf_log_raw(ocf_logger_t logger, ocf_logger_lvl_t lvl,
|
int __wrap_ocf_log_raw(ocf_logger_t logger, ocf_logger_lvl_t lvl,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "../eviction/ops.h"
|
#include "../eviction/ops.h"
|
||||||
#include "ocf_env.h"
|
#include "ocf_env.h"
|
||||||
|
|
||||||
#include "mngt/ocf_mngt_io_class.c/ocf_mngt_io_class_generated_warps.c"
|
#include "mngt/ocf_mngt_io_class.c/ocf_mngt_io_class_generated_wraps.c"
|
||||||
|
|
||||||
/* Functions mocked for testing purposes */
|
/* Functions mocked for testing purposes */
|
||||||
bool __wrap_ocf_part_is_added(struct ocf_user_part *part)
|
bool __wrap_ocf_part_is_added(struct ocf_user_part *part)
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
add_library(ocf_env ocf_env.c)
|
add_library(ocf_env ocf_env.c /usr/include/sys/types.h /usr/include/setjmp.h /usr/include/cmocka.h)
|
||||||
target_link_libraries(ocf_env pthread)
|
add_definitions(-Dstatic= -Dinline= )
|
||||||
|
target_link_libraries(ocf_env pthread z)
|
||||||
|
@ -1,543 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(c) 2012-2018 Intel Corporation
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "ocf_env.h"
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <cmocka.h>
|
|
||||||
|
|
||||||
void bug_on(int cond)
|
|
||||||
{
|
|
||||||
/* Wrap this to use your implementation */
|
|
||||||
assert_false(cond);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *env_malloc(size_t size, int flags)
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *env_zalloc(size_t size, int flags)
|
|
||||||
{
|
|
||||||
return calloc(1, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_free(const void *ptr)
|
|
||||||
{
|
|
||||||
return free((void *) ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *env_vmalloc(size_t size)
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *env_vzalloc(size_t size)
|
|
||||||
{
|
|
||||||
return calloc(1, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_vfree(const void *ptr)
|
|
||||||
{
|
|
||||||
return free((void *) ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t env_get_free_memory(void)
|
|
||||||
{
|
|
||||||
return sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *** ALLOCATOR *** */
|
|
||||||
|
|
||||||
struct _env_allocator {
|
|
||||||
/*!< Memory pool ID unique name */
|
|
||||||
char *name;
|
|
||||||
|
|
||||||
/*!< Size of specific item of memory pool */
|
|
||||||
uint32_t item_size;
|
|
||||||
|
|
||||||
/*!< Number of currently allocated items in pool */
|
|
||||||
env_atomic count;
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t env_allocator_align(size_t size)
|
|
||||||
{
|
|
||||||
if (size <= 2)
|
|
||||||
return size;
|
|
||||||
return (1ULL << 32) >> __builtin_clz(size - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct _env_allocator_item {
|
|
||||||
uint32_t flags;
|
|
||||||
uint32_t cpu;
|
|
||||||
char data[];
|
|
||||||
};
|
|
||||||
|
|
||||||
void *env_allocator_new(env_allocator *allocator)
|
|
||||||
{
|
|
||||||
struct _env_allocator_item *item = NULL;
|
|
||||||
|
|
||||||
item = calloc(1, allocator->item_size);
|
|
||||||
if (item) {
|
|
||||||
item->cpu = 0;
|
|
||||||
env_atomic_inc(&allocator->count);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &item->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
env_allocator *env_allocator_create(uint32_t size, const char *name)
|
|
||||||
{
|
|
||||||
env_allocator *allocator = calloc(1, sizeof(*allocator));
|
|
||||||
|
|
||||||
allocator->item_size = size + sizeof(struct _env_allocator_item);
|
|
||||||
|
|
||||||
allocator->name = strdup(name);
|
|
||||||
|
|
||||||
return allocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_allocator_del(env_allocator *allocator, void *obj)
|
|
||||||
{
|
|
||||||
struct _env_allocator_item *item;
|
|
||||||
|
|
||||||
item = container_of(obj, struct _env_allocator_item, data);
|
|
||||||
|
|
||||||
env_atomic_dec(&allocator->count);
|
|
||||||
|
|
||||||
free(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_allocator_destroy(env_allocator *allocator)
|
|
||||||
{
|
|
||||||
if (allocator) {
|
|
||||||
if (env_atomic_read(&allocator->count)) {
|
|
||||||
fprintf(stderr, "Not all object deallocated\n");
|
|
||||||
ENV_WARN(true, "Cleanup problem\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
free(allocator->name);
|
|
||||||
free(allocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *** COMPLETION *** */
|
|
||||||
|
|
||||||
void env_completion_init(env_completion *completion)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(completion);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_completion_wait(env_completion *completion)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(completion);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_completion_complete(env_completion *completion)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(completion);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int env_mutex_init(env_mutex *mutex)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_mutex_destroy(env_mutex *mutex)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_mutex_lock(env_mutex *mutex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_mutex_lock_interruptible(env_mutex *mutex)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_mutex_unlock(env_mutex *mutex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_rmutex_init(env_rmutex *rmutex)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(rmutex);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rmutex_lock(env_rmutex *rmutex)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(rmutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_rmutex_lock_interruptible(env_rmutex *rmutex)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(rmutex);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rmutex_unlock(env_rmutex *rmutex)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(rmutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_rwsem_init(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwsem_up_read(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwsem_down_read(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_rwsem_down_read_trylock(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwsem_up_write(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwsem_down_write(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_rwsem_down_write_trylock(env_rwsem *s)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(s);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_read(const env_atomic *a)
|
|
||||||
{
|
|
||||||
return *a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic_set(env_atomic *a, int i)
|
|
||||||
{
|
|
||||||
*a = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic_add(int i, env_atomic *a)
|
|
||||||
{
|
|
||||||
*a += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic_sub(int i, env_atomic *a)
|
|
||||||
{
|
|
||||||
*a -= i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic_inc(env_atomic *a)
|
|
||||||
{
|
|
||||||
++*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic_dec(env_atomic *a)
|
|
||||||
{
|
|
||||||
--*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool env_atomic_dec_and_test(env_atomic *a)
|
|
||||||
{
|
|
||||||
return --*a == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_add_return(int i, env_atomic *a)
|
|
||||||
{
|
|
||||||
return *a+=i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_sub_return(int i, env_atomic *a)
|
|
||||||
{
|
|
||||||
return *a-=i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_inc_return(env_atomic *a)
|
|
||||||
{
|
|
||||||
return ++*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_dec_return(env_atomic *a)
|
|
||||||
{
|
|
||||||
return --*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_cmpxchg(env_atomic *a, int old, int new_value)
|
|
||||||
{
|
|
||||||
int oldval = *a;
|
|
||||||
if (oldval == old)
|
|
||||||
*a = new_value;
|
|
||||||
return oldval;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_atomic_add_unless(env_atomic *a, int i, int u)
|
|
||||||
{
|
|
||||||
int c, old;
|
|
||||||
c = *a;
|
|
||||||
for (;;) {
|
|
||||||
if (c == (u))
|
|
||||||
break;
|
|
||||||
old = env_atomic_cmpxchg((a), c, c + (i));
|
|
||||||
if (old == c)
|
|
||||||
break;
|
|
||||||
c = old;
|
|
||||||
}
|
|
||||||
return c != (u);
|
|
||||||
}
|
|
||||||
|
|
||||||
long env_atomic64_read(const env_atomic64 *a)
|
|
||||||
{
|
|
||||||
return *a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic64_set(env_atomic64 *a, long i)
|
|
||||||
{
|
|
||||||
*a=i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic64_add(long i, env_atomic64 *a)
|
|
||||||
{
|
|
||||||
*a += i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic64_sub(long i, env_atomic64 *a)
|
|
||||||
{
|
|
||||||
*a -= i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic64_inc(env_atomic64 *a)
|
|
||||||
{
|
|
||||||
++*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_atomic64_dec(env_atomic64 *a)
|
|
||||||
{
|
|
||||||
--*a;
|
|
||||||
}
|
|
||||||
|
|
||||||
long env_atomic64_cmpxchg(env_atomic64 *a, long old, long new)
|
|
||||||
{
|
|
||||||
long oldval = *a;
|
|
||||||
if (oldval == old)
|
|
||||||
*a = new;
|
|
||||||
return oldval;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_spinlock_init(env_spinlock *l)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_spinlock_destroy(env_spinlock *l)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_spinlock_lock(env_spinlock *l)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_spinlock_trylock(env_spinlock *l)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_spinlock_unlock(env_spinlock *l)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwlock_init(env_rwlock *l)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwlock_read_lock(env_rwlock *l)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwlock_read_unlock(env_rwlock *l)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwlock_write_lock(env_rwlock *l)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_rwlock_write_unlock(env_rwlock *l)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected_ptr(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_bit_set(int nr, volatile void *addr)
|
|
||||||
{
|
|
||||||
char *byte = (char *) addr + (nr >> 3);
|
|
||||||
char mask = 1 << (nr & 7);
|
|
||||||
|
|
||||||
__sync_or_and_fetch(byte, mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_bit_clear(int nr, volatile void *addr)
|
|
||||||
{
|
|
||||||
char *byte = (char *) addr + (nr >> 3);
|
|
||||||
char mask = 1 << (nr & 7);
|
|
||||||
|
|
||||||
mask = ~mask;
|
|
||||||
__sync_and_and_fetch(byte, mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool env_bit_test(int nr, const volatile unsigned long *addr)
|
|
||||||
{
|
|
||||||
const char *byte = (char *) addr + (nr >> 3);
|
|
||||||
char mask = 1 << (nr & 7);
|
|
||||||
|
|
||||||
return !!(*byte & mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *** SCHEDULING *** */
|
|
||||||
|
|
||||||
void env_touch_softlockup_wd(void)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_in_interrupt(void)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t env_get_tick_count(void)
|
|
||||||
{
|
|
||||||
struct timeval tv;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t env_ticks_to_msecs(uint64_t j)
|
|
||||||
{
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t env_ticks_to_secs(uint64_t j)
|
|
||||||
{
|
|
||||||
return j / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t env_secs_to_ticks(uint64_t j)
|
|
||||||
{
|
|
||||||
return j * 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_memset(void *dest, size_t count, int ch)
|
|
||||||
{
|
|
||||||
memset(dest, ch, count);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_memcpy(void *dest, size_t destsz, const void * src, size_t count)
|
|
||||||
{
|
|
||||||
if (destsz < count)
|
|
||||||
memcpy(dest, src, destsz);
|
|
||||||
else
|
|
||||||
memcpy(dest, src, count);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_memcmp(const void *str1, size_t n1, const void *str2, size_t n2,
|
|
||||||
int *diff)
|
|
||||||
{
|
|
||||||
size_t n = n1 > n2 ? n2 : n1;
|
|
||||||
|
|
||||||
*diff = memcmp(str1, str2, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_strncpy(char * dest, size_t destsz, const char *src, size_t count)
|
|
||||||
{
|
|
||||||
if (destsz < count)
|
|
||||||
strncpy(dest, src, destsz);
|
|
||||||
else
|
|
||||||
strncpy(dest, src, count);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t env_strnlen(const char *str, size_t strsz)
|
|
||||||
{
|
|
||||||
return strlen(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_sort(void *base, size_t num, size_t size,
|
|
||||||
int (*cmp_fn)(const void *, const void *),
|
|
||||||
void (*swap_fn)(void *, void *, int size))
|
|
||||||
{
|
|
||||||
qsort(base, num, size, cmp_fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
int env_strncmp(const char * str1, const char * str2, size_t num)
|
|
||||||
{
|
|
||||||
return strncmp(str1, str2, num);
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_msleep(uint64_t n)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* *** CRC *** */
|
|
||||||
|
|
||||||
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len)
|
|
||||||
{
|
|
||||||
function_called();
|
|
||||||
check_expected(crc);
|
|
||||||
check_expected(len);
|
|
||||||
check_expected_ptr(data);
|
|
||||||
return mock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void env_cond_resched(void)
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,344 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(c) 2012-2018 Intel Corporation
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __LIBOCF_ENV_H__
|
|
||||||
#define __LIBOCF_ENV_H__
|
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#endif
|
|
||||||
#ifndef __USE_GNU
|
|
||||||
#define __USE_GNU
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <linux/limits.h>
|
|
||||||
#include <linux/stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#include "ocf_env_list.h"
|
|
||||||
|
|
||||||
typedef uint8_t u8;
|
|
||||||
typedef uint16_t u16;
|
|
||||||
typedef uint32_t u32;
|
|
||||||
typedef uint64_t u64;
|
|
||||||
|
|
||||||
typedef uint64_t sector_t;
|
|
||||||
|
|
||||||
#define ENV_PRIu64 "lu"
|
|
||||||
|
|
||||||
#define __packed __attribute__((packed))
|
|
||||||
#define __aligned(x) __attribute__((aligned(x)))
|
|
||||||
|
|
||||||
/* linux sector 512-bytes */
|
|
||||||
#define ENV_SECTOR_SHIFT 9
|
|
||||||
|
|
||||||
#define PAGE_SIZE 4096
|
|
||||||
|
|
||||||
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
|
|
||||||
|
|
||||||
/* *** MEMORY MANAGEMENT *** */
|
|
||||||
|
|
||||||
#define ENV_MEM_NORMAL 0
|
|
||||||
#define ENV_MEM_NOIO 1
|
|
||||||
#define ENV_MEM_ATOMIC 2
|
|
||||||
|
|
||||||
#define ENV_WARN(cond, fmt, args...) ({})
|
|
||||||
|
|
||||||
#define ENV_WARN_ON(cond) ({ \
|
|
||||||
if (unlikely(cond)) \
|
|
||||||
fprintf(stderr, "WARNING (%s:%d)\n", \
|
|
||||||
__FILE__, __LINE__); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define ENV_BUG() ({ \
|
|
||||||
fprintf(stderr, "BUG (%s:%d)\n", \
|
|
||||||
__FILE__, __LINE__); \
|
|
||||||
assert(0); \
|
|
||||||
abort(); \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define ENV_BUG_ON(cond) ({ \
|
|
||||||
int eval = cond; \
|
|
||||||
if (eval) { \
|
|
||||||
print_message("%s:%u BUG: %s\n", __FILE__, __LINE__, #cond); \
|
|
||||||
bug_on(eval); \
|
|
||||||
} \
|
|
||||||
})
|
|
||||||
|
|
||||||
#define container_of(ptr, type, member) ({ \
|
|
||||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
||||||
(type *)( (char *)__mptr - offsetof(type, member) );})
|
|
||||||
|
|
||||||
/* ATOMICS */
|
|
||||||
#ifndef atomic_read
|
|
||||||
#define atomic_read(ptr) (*(__typeof__(*ptr) *volatile) (ptr))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef atomic_set
|
|
||||||
#define atomic_set(ptr, i) ((*(__typeof__(*ptr) *volatile) (ptr)) = (i))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define likely(x) (x)
|
|
||||||
#define unlikely(x) (x)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Bug on for testing
|
|
||||||
*/
|
|
||||||
void bug_on(int cond);
|
|
||||||
|
|
||||||
void *env_malloc(size_t size, int flags);
|
|
||||||
|
|
||||||
void *env_zalloc(size_t size, int flags);
|
|
||||||
|
|
||||||
void env_free(const void *ptr);
|
|
||||||
|
|
||||||
void *env_vmalloc(size_t size);
|
|
||||||
|
|
||||||
void *env_vzalloc(size_t size);
|
|
||||||
|
|
||||||
void env_vfree(const void *ptr);
|
|
||||||
|
|
||||||
uint64_t env_get_free_memory(void);
|
|
||||||
|
|
||||||
/* *** ALLOCATOR *** */
|
|
||||||
|
|
||||||
typedef struct _env_allocator env_allocator;
|
|
||||||
|
|
||||||
env_allocator *env_allocator_create(uint32_t size, const char *name);
|
|
||||||
|
|
||||||
void env_allocator_destroy(env_allocator *allocator);
|
|
||||||
|
|
||||||
void *env_allocator_new(env_allocator *allocator);
|
|
||||||
|
|
||||||
void env_allocator_del(env_allocator *allocator, void *item);
|
|
||||||
|
|
||||||
/* *** MUTEX *** */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
pthread_mutex_t m;
|
|
||||||
} env_mutex;
|
|
||||||
|
|
||||||
int env_mutex_init(env_mutex *mutex);
|
|
||||||
|
|
||||||
int env_mutex_destroy(env_mutex *mutex);
|
|
||||||
|
|
||||||
void env_mutex_lock(env_mutex *mutex);
|
|
||||||
|
|
||||||
int env_mutex_lock_interruptible(env_mutex *mutex);
|
|
||||||
|
|
||||||
void env_mutex_unlock(env_mutex *mutex);
|
|
||||||
|
|
||||||
/* *** RECURSIVE MUTEX *** */
|
|
||||||
|
|
||||||
typedef env_mutex env_rmutex;
|
|
||||||
|
|
||||||
int env_rmutex_init(env_rmutex *rmutex);
|
|
||||||
|
|
||||||
void env_rmutex_lock(env_rmutex *rmutex);
|
|
||||||
|
|
||||||
int env_rmutex_lock_interruptible(env_rmutex *rmutex);
|
|
||||||
|
|
||||||
void env_rmutex_unlock(env_rmutex *rmutex);
|
|
||||||
|
|
||||||
/* *** RW SEMAPHORE *** */
|
|
||||||
typedef struct {
|
|
||||||
pthread_rwlock_t lock;
|
|
||||||
} env_rwsem;
|
|
||||||
|
|
||||||
int env_rwsem_init(env_rwsem *s);
|
|
||||||
|
|
||||||
void env_rwsem_up_read(env_rwsem *s);
|
|
||||||
|
|
||||||
void env_rwsem_down_read(env_rwsem *s);
|
|
||||||
|
|
||||||
int env_rwsem_down_read_trylock(env_rwsem *s);
|
|
||||||
|
|
||||||
void env_rwsem_up_write(env_rwsem *s);
|
|
||||||
|
|
||||||
void env_rwsem_down_write(env_rwsem *s);
|
|
||||||
|
|
||||||
int env_rwsem_down_write_trylock(env_rwsem *s);
|
|
||||||
|
|
||||||
/* *** ATOMIC VARIABLES *** */
|
|
||||||
|
|
||||||
typedef int env_atomic;
|
|
||||||
|
|
||||||
typedef long env_atomic64;
|
|
||||||
|
|
||||||
int env_atomic_read(const env_atomic *a);
|
|
||||||
|
|
||||||
void env_atomic_set(env_atomic *a, int i);
|
|
||||||
|
|
||||||
void env_atomic_add(int i, env_atomic *a);
|
|
||||||
|
|
||||||
void env_atomic_sub(int i, env_atomic *a);
|
|
||||||
|
|
||||||
void env_atomic_inc(env_atomic *a);
|
|
||||||
|
|
||||||
void env_atomic_dec(env_atomic *a);
|
|
||||||
|
|
||||||
bool env_atomic_dec_and_test(env_atomic *a);
|
|
||||||
|
|
||||||
int env_atomic_add_return(int i, env_atomic *a);
|
|
||||||
|
|
||||||
int env_atomic_sub_return(int i, env_atomic *a);
|
|
||||||
|
|
||||||
int env_atomic_inc_return(env_atomic *a);
|
|
||||||
|
|
||||||
int env_atomic_dec_return(env_atomic *a);
|
|
||||||
|
|
||||||
int env_atomic_cmpxchg(env_atomic *a, int old, int new_value);
|
|
||||||
|
|
||||||
int env_atomic_add_unless(env_atomic *a, int i, int u);
|
|
||||||
|
|
||||||
long env_atomic64_read(const env_atomic64 *a);
|
|
||||||
|
|
||||||
void env_atomic64_set(env_atomic64 *a, long i);
|
|
||||||
|
|
||||||
void env_atomic64_add(long i, env_atomic64 *a);
|
|
||||||
|
|
||||||
void env_atomic64_sub(long i, env_atomic64 *a);
|
|
||||||
|
|
||||||
void env_atomic64_inc(env_atomic64 *a);
|
|
||||||
|
|
||||||
void env_atomic64_dec(env_atomic64 *a);
|
|
||||||
|
|
||||||
long env_atomic64_cmpxchg(env_atomic64 *a, long old, long new);
|
|
||||||
|
|
||||||
typedef int Coroutine;
|
|
||||||
|
|
||||||
/* *** COMPLETION *** */
|
|
||||||
struct completion {
|
|
||||||
bool completed;
|
|
||||||
bool waiting;
|
|
||||||
Coroutine *co;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct completion env_completion;
|
|
||||||
|
|
||||||
void env_completion_init(env_completion *completion);
|
|
||||||
void env_completion_wait(env_completion *completion);
|
|
||||||
void env_completion_complete(env_completion *completion);
|
|
||||||
|
|
||||||
/* *** SPIN LOCKS *** */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
} env_spinlock;
|
|
||||||
|
|
||||||
int env_spinlock_init(env_spinlock *l);
|
|
||||||
|
|
||||||
int env_spinlock_destroy(env_spinlock *l);
|
|
||||||
|
|
||||||
void env_spinlock_lock(env_spinlock *l);
|
|
||||||
|
|
||||||
int env_spinlock_trylock(env_spinlock *l);
|
|
||||||
|
|
||||||
void env_spinlock_unlock(env_spinlock *l);
|
|
||||||
|
|
||||||
#define env_spinlock_lock_irqsave(l, flags) \
|
|
||||||
env_spinlock_lock(l); (void)flags;
|
|
||||||
|
|
||||||
#define env_spinlock_unlock_irqrestore(l, flags) \
|
|
||||||
env_spinlock_unlock(l); (void)flags;
|
|
||||||
|
|
||||||
/* *** RW LOCKS *** */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
} env_rwlock;
|
|
||||||
|
|
||||||
void env_rwlock_init(env_rwlock *l);
|
|
||||||
|
|
||||||
void env_rwlock_read_lock(env_rwlock *l);
|
|
||||||
|
|
||||||
void env_rwlock_read_unlock(env_rwlock *l);
|
|
||||||
|
|
||||||
void env_rwlock_write_lock(env_rwlock *l);
|
|
||||||
|
|
||||||
void env_rwlock_write_unlock(env_rwlock *l);
|
|
||||||
|
|
||||||
/* *** WAITQUEUE *** */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool waiting;
|
|
||||||
bool completed;
|
|
||||||
Coroutine *co;
|
|
||||||
} env_waitqueue;
|
|
||||||
|
|
||||||
#define env_waitqueue_wait(w, condition) \
|
|
||||||
({ \
|
|
||||||
int __ret = 0; \
|
|
||||||
if (!(condition) && !w.completed) { \
|
|
||||||
w.waiting = true; \
|
|
||||||
} \
|
|
||||||
w.co = NULL; \
|
|
||||||
w.waiting = false; \
|
|
||||||
w.completed = false; \
|
|
||||||
__ret = __ret; \
|
|
||||||
})
|
|
||||||
|
|
||||||
/* *** BIT OPERATIONS *** */
|
|
||||||
|
|
||||||
void env_bit_set(int nr, volatile void *addr);
|
|
||||||
|
|
||||||
void env_bit_clear(int nr, volatile void *addr);
|
|
||||||
|
|
||||||
bool env_bit_test(int nr, const volatile unsigned long *addr);
|
|
||||||
|
|
||||||
/* *** SCHEDULING *** */
|
|
||||||
|
|
||||||
void env_touch_softlockup_wd(void);
|
|
||||||
|
|
||||||
int env_in_interrupt(void);
|
|
||||||
|
|
||||||
uint64_t env_get_tick_count(void);
|
|
||||||
|
|
||||||
uint64_t env_ticks_to_msecs(uint64_t j);
|
|
||||||
|
|
||||||
uint64_t env_ticks_to_secs(uint64_t j);
|
|
||||||
|
|
||||||
uint64_t env_secs_to_ticks(uint64_t j);
|
|
||||||
|
|
||||||
/* *** STRING OPERATIONS *** */
|
|
||||||
|
|
||||||
int env_memset(void *dest, size_t count, int ch);
|
|
||||||
|
|
||||||
int env_memcpy(void *dest, size_t destsz, const void * src, size_t count);
|
|
||||||
|
|
||||||
int env_memcmp(const void *str1, size_t n1, const void *str2, size_t n2,
|
|
||||||
int *diff);
|
|
||||||
|
|
||||||
int env_strncpy(char * dest, size_t destsz, const char *src, size_t srcsz);
|
|
||||||
|
|
||||||
size_t env_strnlen(const char *str, size_t strsz);
|
|
||||||
|
|
||||||
int env_strncmp(const char * str1, const char * str2, size_t num);
|
|
||||||
|
|
||||||
/* *** SORTING *** */
|
|
||||||
|
|
||||||
void env_sort(void *base, size_t num, size_t size,
|
|
||||||
int (*cmp_fn)(const void *, const void *),
|
|
||||||
void (*swap_fn)(void *, void *, int size));
|
|
||||||
|
|
||||||
void env_msleep(uint64_t n);
|
|
||||||
|
|
||||||
/* *** CRC *** */
|
|
||||||
|
|
||||||
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len);
|
|
||||||
|
|
||||||
void env_cond_resched(void);
|
|
||||||
|
|
||||||
#endif /* __OCF_ENV_H__ */
|
|
@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(c) 2012-2018 Intel Corporation
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __OCF_ENV_HEADERS_H__
|
|
||||||
#define __OCF_ENV_HEADERS_H__
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#endif /* __OCF_ENV_HEADERS_H__ */
|
|
@ -1,146 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(c) 2012-2018 Intel Corporation
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __OCF_LIST_H__
|
|
||||||
#define __OCF_LIST_H__
|
|
||||||
|
|
||||||
#define LIST_POISON1 ((void *)0x101)
|
|
||||||
#define LIST_POISON2 ((void *)0x202)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List entry structure mimicking linux kernel based one.
|
|
||||||
*/
|
|
||||||
struct list_head {
|
|
||||||
struct list_head *next;
|
|
||||||
struct list_head *prev;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* start an empty list
|
|
||||||
*/
|
|
||||||
#define INIT_LIST_HEAD(l) { (l)->prev = l; (l)->next = l; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add item to list head.
|
|
||||||
* @param it list entry to be added
|
|
||||||
* @param l1 list main node (head)
|
|
||||||
*/
|
|
||||||
static inline void list_add(struct list_head *it, struct list_head *l1)
|
|
||||||
{
|
|
||||||
it->prev = l1;
|
|
||||||
it->next = l1->next;
|
|
||||||
|
|
||||||
l1->next->prev = it;
|
|
||||||
l1->next = it;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add item it to tail.
|
|
||||||
* @param it list entry to be added
|
|
||||||
* @param l1 list main node (head)
|
|
||||||
*/
|
|
||||||
static inline void list_add_tail(struct list_head *it, struct list_head *l1)
|
|
||||||
{
|
|
||||||
it->prev = l1->prev;
|
|
||||||
it->next = l1;
|
|
||||||
|
|
||||||
l1->prev->next = it;
|
|
||||||
l1->prev = it;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if a list is empty (return true)
|
|
||||||
* @param l1 list main node (head)
|
|
||||||
*/
|
|
||||||
static inline int list_empty(struct list_head *l1)
|
|
||||||
{
|
|
||||||
return l1->next == l1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delete an entry from a list
|
|
||||||
* @param it list entry to be deleted
|
|
||||||
*/
|
|
||||||
static inline void list_del(struct list_head *it)
|
|
||||||
{
|
|
||||||
it->next->prev = it->prev;
|
|
||||||
it->prev->next = it->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract an entry.
|
|
||||||
* @param list_head_i list head item, from which entry is extracted
|
|
||||||
* @param item_type type (struct) of list entry
|
|
||||||
* @param field_name name of list_head field within item_type
|
|
||||||
*/
|
|
||||||
#define list_entry(list_head_i, item_type, field_name) \
|
|
||||||
(item_type *)(((void*)(list_head_i)) - offsetof(item_type, field_name))
|
|
||||||
|
|
||||||
#define list_first_entry(list_head_i, item_type, field_name) \
|
|
||||||
list_entry((list_head_i)->next, item_type, field_name)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param iterator uninitialized list_head pointer, to be used as iterator
|
|
||||||
* @param plist list head (main node)
|
|
||||||
*/
|
|
||||||
#define list_for_each(iterator, plist) \
|
|
||||||
for (iterator = (plist)->next; \
|
|
||||||
(iterator)->next != (plist)->next; \
|
|
||||||
iterator = (iterator)->next)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe version of list_for_each which works even if entries are deleted during
|
|
||||||
* loop.
|
|
||||||
* @param iterator uninitialized list_head pointer, to be used as iterator
|
|
||||||
* @param q another uninitialized list_head, used as helper
|
|
||||||
* @param plist list head (main node)
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Algorithm handles situation, where q is deleted.
|
|
||||||
* consider in example 3 element list with header h:
|
|
||||||
*
|
|
||||||
* h -> 1 -> 2 -> 3 ->
|
|
||||||
*1. i q
|
|
||||||
*
|
|
||||||
*2. i q
|
|
||||||
*
|
|
||||||
*3. q i
|
|
||||||
*/
|
|
||||||
#define list_for_each_safe(iterator, q, plist) \
|
|
||||||
for (iterator = (q = (plist)->next->next)->prev; \
|
|
||||||
(q) != (plist)->next; \
|
|
||||||
iterator = (q = (q)->next)->prev)
|
|
||||||
|
|
||||||
#define _list_entry_helper(item, head, field_name) \
|
|
||||||
list_entry(head, typeof(*item), field_name)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterate over list entries.
|
|
||||||
* @param list pointer to list item (iterator)
|
|
||||||
* @param plist pointer to list_head item
|
|
||||||
* @param field_name name of list_head field in list entry
|
|
||||||
*/
|
|
||||||
#define list_for_each_entry(item, plist, field_name) \
|
|
||||||
for (item = _list_entry_helper(item, (plist)->next, field_name); \
|
|
||||||
_list_entry_helper(item, (item)->field_name.next, field_name) !=\
|
|
||||||
_list_entry_helper(item, (plist)->next, field_name); \
|
|
||||||
item = _list_entry_helper(item, (item)->field_name.next, field_name))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Safe version of list_for_each_entry which works even if entries are deleted
|
|
||||||
* during loop.
|
|
||||||
* @param list pointer to list item (iterator)
|
|
||||||
* @param q another pointer to list item, used as helper
|
|
||||||
* @param plist pointer to list_head item
|
|
||||||
* @param field_name name of list_head field in list entry
|
|
||||||
*/
|
|
||||||
#define list_for_each_entry_safe(item, q, plist, field_name) \
|
|
||||||
for (item = _list_entry_helper(item, (plist)->next, field_name), \
|
|
||||||
q = _list_entry_helper(item, (item)->field_name.next, field_name); \
|
|
||||||
_list_entry_helper(item, (item)->field_name.next, field_name) != \
|
|
||||||
_list_entry_helper(item, (plist)->next, field_name); \
|
|
||||||
item = q, q = _list_entry_helper(q, (q)->field_name.next, field_name))
|
|
||||||
|
|
||||||
#endif
|
|
@ -33,7 +33,7 @@
|
|||||||
#include "ocf/ocf.h"
|
#include "ocf/ocf.h"
|
||||||
#include "metadata/metadata.h"
|
#include "metadata/metadata.h"
|
||||||
|
|
||||||
#include "ocf_freelist.c/ocf_freelist_get_put_generated_warps.c"
|
#include "ocf_freelist.c/ocf_freelist_get_put_generated_wraps.c"
|
||||||
|
|
||||||
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "ocf/ocf.h"
|
#include "ocf/ocf.h"
|
||||||
#include "metadata/metadata.h"
|
#include "metadata/metadata.h"
|
||||||
|
|
||||||
#include "ocf_freelist.c/ocf_freelist_init_generated_warps.c"
|
#include "ocf_freelist.c/ocf_freelist_init_generated_wraps.c"
|
||||||
|
|
||||||
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include "ocf/ocf.h"
|
#include "ocf/ocf.h"
|
||||||
#include "metadata/metadata.h"
|
#include "metadata/metadata.h"
|
||||||
|
|
||||||
#include "ocf_freelist.c/ocf_freelist_get_put_generated_warps.c"
|
#include "ocf_freelist.c/ocf_freelist_get_put_generated_wraps.c"
|
||||||
|
|
||||||
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "ocf/ocf.h"
|
#include "ocf/ocf.h"
|
||||||
#include "metadata/metadata.h"
|
#include "metadata/metadata.h"
|
||||||
|
|
||||||
#include "ocf_freelist.c/ocf_freelist_populate_generated_warps.c"
|
#include "ocf_freelist.c/ocf_freelist_populate_generated_wraps.c"
|
||||||
|
|
||||||
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
ocf_cache_line_t __wrap_ocf_metadata_collision_table_entries(ocf_cache_t cache)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_dec_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_dec_generated_wraps.c"
|
||||||
|
|
||||||
static void ocf_refcnt_dec_test01(void **state)
|
static void ocf_refcnt_dec_test01(void **state)
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_freeze_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_freeze_generated_wraps.c"
|
||||||
|
|
||||||
static void ocf_refcnt_freeze_test01(void **state)
|
static void ocf_refcnt_freeze_test01(void **state)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_inc_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_inc_generated_wraps.c"
|
||||||
|
|
||||||
static void ocf_refcnt_inc_test(void **state)
|
static void ocf_refcnt_inc_test(void **state)
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_init_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_init_generated_wraps.c"
|
||||||
|
|
||||||
static void ocf_refcnt_init_test(void **state)
|
static void ocf_refcnt_init_test(void **state)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_register_zero_cb_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_register_zero_cb_generated_wraps.c"
|
||||||
|
|
||||||
static void zero_cb(void *ctx)
|
static void zero_cb(void *ctx)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "../utils/utils_refcnt.h"
|
#include "../utils/utils_refcnt.h"
|
||||||
|
|
||||||
#include "utils/utils_refcnt.c/utils_refcnt_unfreeze_generated_warps.c"
|
#include "utils/utils_refcnt.c/utils_refcnt_unfreeze_generated_wraps.c"
|
||||||
|
|
||||||
static void ocf_refcnt_unfreeze_test01(void **state)
|
static void ocf_refcnt_unfreeze_test01(void **state)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user