Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: various clang fixes #6045

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ jobs:
basic_build:
name: Basic build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- CC: gcc
CXX: g++
- CC: clang
CXX: clang++
steps:
- name: Clone the git repo
uses: actions/checkout@v3
Expand All @@ -61,6 +69,8 @@ jobs:
- name: Build sources
env:
NDCTL_ENABLE: n # just to speed up the job
CC: ${{ matrix.CC }}
CXX: ${{ matrix.CXX }}
run: make -j$(nproc) test


Expand Down
2 changes: 1 addition & 1 deletion src/test/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ endif
PAREN=(
extract_funcs = $(shell \
awk -F '[$(PAREN),]' \
'/(FUNC_MOCK_RET_ALWAYS|FUNC_MOCK_RET_ALWAYS_VOID|FUNC_MOCK)\$(PAREN)[^,]/ \
'/(FUNC_MOCK_RET_ALWAYS|FUNC_MOCK_RET_ALWAYS_VOID|FUNC_MOCK|FUNC_MOCK_NONSTATIC)\$(PAREN)[^,]/ \
{ \
print "-Wl,--wrap=" $$2 \
}' $(1) )
Expand Down
9 changes: 5 additions & 4 deletions src/test/core_log/core_log_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ struct vsnprintf_ctx Vsnprintf_;
struct strerror_r_ctx Strerror_r;
struct log_function_ctx Log_function_;

FUNC_MOCK(last_error_msg_get, const char *, void)
FUNC_MOCK_NONSTATIC(last_error_msg_get, const char *, void)
FUNC_MOCK_RUN_DEFAULT {
return LAST_ERROR_MSG_MOCK;
}
FUNC_MOCK_END

FUNC_MOCK(vsnprintf, int, char *__restrict __s, size_t __maxlen,
FUNC_MOCK_NONSTATIC(vsnprintf, int, char *__restrict __s, size_t __maxlen,
const char *__restrict __format, va_list __arg)
FUNC_MOCK_RUN(VALIDATED_CALL) {
if (Common.use_last_error_msg) {
Expand All @@ -43,7 +43,8 @@ FUNC_MOCK_RUN_DEFAULT {
}
FUNC_MOCK_END

FUNC_MOCK(__xpg_strerror_r, int, int __errnum, char *__buf, size_t __buflen)
FUNC_MOCK_NONSTATIC(__xpg_strerror_r, int, int __errnum, char *__buf,
size_t __buflen)
FUNC_MOCK_RUN_DEFAULT {
UT_ASSERTeq(__errnum, DUMMY_ERRNO1);
UT_ASSERTeq(__buf, Strerror_r.exp__buf);
Expand All @@ -62,7 +63,7 @@ FUNC_MOCK_RUN_DEFAULT {
}
FUNC_MOCK_END

FUNC_MOCK(core_log_default_function, void, enum core_log_level level,
FUNC_MOCK_NONSTATIC(core_log_default_function, void, enum core_log_level level,
const char *file_name, const int line_no, const char *function_name,
const char *message)
FUNC_MOCK_RUN(VALIDATED_CALL) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/core_log/core_log_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ extern struct log_function_ctx {

/* mocks */

extern unsigned RCOUNTER(last_error_msg_get);
extern unsigned RCOUNTER(vsnprintf);
extern unsigned RCOUNTER(__xpg_strerror_r);
extern unsigned RCOUNTER(core_log_default_function);
FUNC_MOCK_EXTERN(last_error_msg_get);
FUNC_MOCK_EXTERN(vsnprintf);
FUNC_MOCK_EXTERN(__xpg_strerror_r);
FUNC_MOCK_EXTERN(core_log_default_function);

/* helpers */

Expand Down
8 changes: 4 additions & 4 deletions src/test/core_log_function_mt/core_log_function_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LOG_FUNC(log_func7)
LOG_FUNC(log_func8)
LOG_FUNC(log_func9)

core_log_function *log_funcs[] = {
static core_log_function *log_funcs[] = {
log_func0,
log_func1,
log_func2,
Expand All @@ -55,9 +55,9 @@ core_log_function *log_funcs[] = {

#define N_LOG_FUNCS ARRAY_SIZE(log_funcs)

os_mutex_t mutex;
os_cond_t cond;
unsigned threads_waiting;
static os_mutex_t mutex;
static os_cond_t cond;
static unsigned threads_waiting;

static void *
helper_set(void *arg)
Expand Down
8 changes: 4 additions & 4 deletions src/test/core_log_threshold_mt/core_log_threshold_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

#define OP_REDO 4096

struct helper_ctx {
static struct helper_ctx {
enum core_log_threshold threshold;
int idx;
} helper_ctx_ [TOTAL_THREADS];

os_mutex_t mutex;
os_cond_t cond;
unsigned threads_waiting;
static os_mutex_t mutex;
static os_cond_t cond;
static unsigned threads_waiting;

static void *
helper_set(void *arg)
Expand Down
3 changes: 2 additions & 1 deletion src/test/unittest/README
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ This directory contains the unit test framework used by
the Persistent Memory Development Kit unit tests.

This framework provides a support for mock objects. To mock an interface use
FUNC_MOCK_RET_ALWAYS or FUNC_MOCK macros in the test code.
FUNC_MOCK_RET_ALWAYS, FUNC_MOCK_RET_ALWAYS_VOID, FUNC_MOCK or
FUNC_MOCK_NONSTATIC macros in the test code.

The FUNC_MOCK_RET_ALWAYS is quite straightforward, it simply takes a function
name and a value that the given function has to return. For example:
Expand Down
13 changes: 11 additions & 2 deletions src/test/unittest/unittest.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,22 @@ int ut_thread_join(const char *file, int line, const char *func,
#define FUNC_MOCK_RCOUNTER_SET(name, val)\
RCOUNTER(name) = val;

#define FUNC_MOCK(name, ret_type, ...)\
#define _FUNC_MOCK(type, name, ret_type, ...)\
_FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\
unsigned RCOUNTER(name);\
type 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(name, ret_type, ...) \
_FUNC_MOCK(static, name, ret_type, ##__VA_ARGS__)

#define FUNC_MOCK_NONSTATIC(name, ret_type, ...) \
_FUNC_MOCK(, name, ret_type, ##__VA_ARGS__)

#define FUNC_MOCK_EXTERN(name) \
extern unsigned RCOUNTER(name)

#define FUNC_MOCK_DLLIMPORT(name, ret_type, ...)\
__declspec(dllimport) _FUNC_REAL_DECL(name, ret_type, ##__VA_ARGS__)\
static unsigned RCOUNTER(name);\
Expand Down
Loading