-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: pmemobj_log_function UT scaffolding
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
- Loading branch information
Showing
5 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
obj_log_function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright 2024, Intel Corporation | ||
|
||
TARGET = obj_log_function | ||
OBJS = obj_log_function.o | ||
|
||
BUILD_STATIC_DEBUG=n | ||
BUILD_STATIC_NONDEBUG=n | ||
|
||
# 'internal' is required for proper mock integration | ||
# 'debug' is required for debug version of core/log.o that provides | ||
# implementation of 'out_log()' that is used by 'ut_log_function()' | ||
LIBPMEMOBJ=internal-debug | ||
|
||
include ../Makefile.inc | ||
LDFLAGS += $(call extract_funcs, obj_log_function.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!../env.py | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright 2024, Intel Corporation | ||
# | ||
|
||
|
||
import testframework as t | ||
from testframework import granularity as g | ||
|
||
|
||
@g.require_granularity(g.ANY) | ||
# The 'debug' build is chosen arbitrarily to ensure these tests are run only | ||
# once. No dynamic libraries are used nor .static_* builds are available. | ||
@t.require_build('debug') | ||
class CORE_LOG(t.BaseTest): | ||
test_type = t.Short | ||
|
||
def run(self, ctx): | ||
ctx.exec('obj_log_function', self.test_case) | ||
|
||
|
||
class TEST0(CORE_LOG): | ||
test_case = 'test_set_log_function' | ||
|
||
|
||
class TEST1(CORE_LOG): | ||
test_case = 'test_set_log_function_EAGAIN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/* Copyright 2024, Intel Corporation */ | ||
|
||
/* | ||
* core_log_default_function.c -- unit test for core_log_default_function | ||
*/ | ||
|
||
#undef _GNU_SOURCE | ||
#include <string.h> | ||
#include <syslog.h> | ||
#include <stdbool.h> | ||
|
||
#include "unittest.h" | ||
#include "log_internal.h" | ||
#include "log_default.h" | ||
#include "libpmemobj/log.h" | ||
|
||
#define NO_ARGS_CONSUMED 0 | ||
|
||
#define VALIDATED_CALL 127 | ||
#define CALLED (VALIDATED_CALL + 1) | ||
|
||
#define PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK ((pmemobj_log_function *) 0xA1C5D68F) | ||
|
||
static struct { | ||
int ret; | ||
} Core_log_set_function; | ||
|
||
FUNC_MOCK(core_log_set_function, int, core_log_function *log_function) | ||
FUNC_MOCK_RUN(VALIDATED_CALL) { | ||
UT_ASSERT((void *)log_function == | ||
(void *)PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); | ||
return Core_log_set_function.ret; | ||
} | ||
FUNC_MOCK_RUN_DEFAULT { | ||
return _FUNC_REAL(core_log_set_function)(log_function); | ||
} | ||
FUNC_MOCK_END | ||
|
||
/* | ||
* Check: | ||
* - if core_log_set_function is called with proper argument | ||
* - if pmemobj_log_set_function return 0 (no error) | ||
* - no errno is set | ||
*/ | ||
static int | ||
test_set_log_function(const struct test_case *tc, int argc, char *argv[]) | ||
{ | ||
errno = NO_ERRNO; | ||
Core_log_set_function.ret = 0; | ||
FUNC_MOCK_RCOUNTER_SET(core_log_set_function, VALIDATED_CALL); | ||
int ret = pmemobj_log_set_function(PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); | ||
UT_ASSERTeq(ret, 0); | ||
UT_ASSERTeq(errno, NO_ERRNO); | ||
UT_ASSERTeq(RCOUNTER(core_log_set_function), CALLED); | ||
|
||
return NO_ARGS_CONSUMED; | ||
} | ||
|
||
/* | ||
* core_log_set_function() with EAGAIN error | ||
* Check: | ||
* - if core_log_set_function is called with proper argument | ||
* - if pmemobj_log_set_function return 1 (error via errno) | ||
* - errno is set to EAGAIN | ||
*/ | ||
static int | ||
test_set_log_function_EAGAIN(const struct test_case *tc, int argc, char *argv[]) | ||
{ | ||
errno = NO_ERRNO; | ||
Core_log_set_function.ret = EAGAIN; | ||
FUNC_MOCK_RCOUNTER_SET(core_log_set_function, VALIDATED_CALL); | ||
int ret = pmemobj_log_set_function(PMEMOBJ_LOG_CUSTOM_FUNCTION_MOCK); | ||
UT_ASSERTeq(ret, 1); | ||
UT_ASSERTeq(errno, EAGAIN); | ||
UT_ASSERTeq(RCOUNTER(core_log_set_function), CALLED); | ||
|
||
return NO_ARGS_CONSUMED; | ||
} | ||
|
||
static struct test_case test_cases[] = { | ||
TEST_CASE(test_set_log_function), | ||
TEST_CASE(test_set_log_function_EAGAIN), | ||
}; | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
START(argc, argv, "obj_log_function"); | ||
TEST_CASE_PROCESS(argc, argv, test_cases, ARRAY_SIZE(test_cases)); | ||
DONE(NULL); | ||
} |