-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common: core_log_set/get_threshold MT unit tests
Signed-off-by: Jan Michalski <jan.michalski@intel.com>
- Loading branch information
Showing
6 changed files
with
171 additions
and
20 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
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 @@ | ||
core_log_mt |
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,12 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright 2024, Intel Corporation | ||
|
||
TARGET = core_log_mt | ||
OBJS = core_log_mt.o | ||
|
||
BUILD_STATIC_DEBUG=n | ||
BUILD_STATIC_NONDEBUG=n | ||
|
||
LIBPMEMCORE=nondebug | ||
|
||
include ../Makefile.inc |
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,45 @@ | ||
#!../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) | ||
@t.require_build('nondebug') | ||
class CORE_LOG_MT(t.BaseTest): | ||
test_type = t.Short | ||
|
||
def run(self, ctx): | ||
ctx.exec('core_log_mt', self.test_case) | ||
|
||
|
||
class THRESHOLD(CORE_LOG_MT): | ||
test_case = 'test_threshold' | ||
|
||
|
||
class THRESHOLD_AUX(CORE_LOG_MT): | ||
test_case = 'test_threshold_aux' | ||
|
||
|
||
@t.require_valgrind_enabled('helgrind') | ||
class TEST0(THRESHOLD): | ||
pass | ||
|
||
|
||
@t.require_valgrind_enabled('drd') | ||
class TEST1(THRESHOLD): | ||
pass | ||
|
||
|
||
@t.require_valgrind_enabled('helgrind') | ||
class TEST2(THRESHOLD_AUX): | ||
pass | ||
|
||
|
||
@t.require_valgrind_enabled('drd') | ||
class TEST3(THRESHOLD_AUX): | ||
pass |
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,105 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
/* Copyright 2024, Intel Corporation */ | ||
|
||
/* | ||
* core_log_internal.c -- unit test to CORE_LOG_... | ||
*/ | ||
|
||
#include "unittest.h" | ||
#include "log_internal.h" | ||
|
||
#define NO_ARGS_CONSUMED 0 | ||
|
||
#define THREADS_IN_GROUP 10 | ||
#define TOTAL_THREADS (THREADS_IN_GROUP * 2) | ||
#define OP_REDO 4096 | ||
|
||
struct test_threshold_helper_ctx { | ||
enum core_log_threshold threshold; | ||
enum core_log_level level; | ||
} threshold_helper_ [TOTAL_THREADS]; | ||
|
||
static void * | ||
test_threshold_helper_set(void *arg) | ||
{ | ||
struct test_threshold_helper_ctx *ctx = | ||
(struct test_threshold_helper_ctx *)arg; | ||
for (int i = 0; i < OP_REDO; ++i) { | ||
core_log_set_threshold(ctx->threshold, ctx->level); | ||
} | ||
return NULL; | ||
} | ||
|
||
static void * | ||
test_threshold_helper_get(void *arg) | ||
{ | ||
struct test_threshold_helper_ctx *ctx = | ||
(struct test_threshold_helper_ctx *)arg; | ||
for (int i = 0; i < OP_REDO; ++i) { | ||
core_log_get_threshold(ctx->threshold, &ctx->level); | ||
} | ||
(void) ctx->level; | ||
return NULL; | ||
} | ||
|
||
static void | ||
test_threshold_helper(enum core_log_threshold threshold) | ||
{ | ||
os_thread_t threads[TOTAL_THREADS]; | ||
|
||
/* core_log_set_threshold() threads */ | ||
for (int idx = 0; idx < THREADS_IN_GROUP; idx++) { | ||
threshold_helper_[idx].threshold = threshold; | ||
threshold_helper_[idx].level = | ||
(enum core_log_level)(idx % CORE_LOG_LEVEL_MAX); | ||
THREAD_CREATE(&threads[idx], 0, test_threshold_helper_set, | ||
(void *)&threshold_helper_[idx]); | ||
} | ||
|
||
/* core_log_get_threshold() threads */ | ||
for (int idx = THREADS_IN_GROUP; idx < TOTAL_THREADS; idx++) { | ||
threshold_helper_[idx].threshold = threshold; | ||
THREAD_CREATE(&threads[idx], 0, test_threshold_helper_get, | ||
(void *)&threshold_helper_[idx]); | ||
} | ||
|
||
for (int idx = 0; idx < TOTAL_THREADS; idx++) { | ||
void *retval; | ||
THREAD_JOIN(&threads[idx], &retval); | ||
} | ||
} | ||
|
||
/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD, ...) in parallel. */ | ||
static int | ||
test_threshold(const struct test_case *tc, int argc, char *argv[]) | ||
{ | ||
test_threshold_helper(CORE_LOG_THRESHOLD); | ||
return NO_ARGS_CONSUMED; | ||
} | ||
|
||
/* Run core_log_set/get_threshold(CORE_LOG_THRESHOLD_AUX, ...) in parallel. */ | ||
static int | ||
test_threshold_aux(const struct test_case *tc, int argc, char *argv[]) | ||
{ | ||
test_threshold_helper(CORE_LOG_THRESHOLD_AUX); | ||
return NO_ARGS_CONSUMED; | ||
} | ||
|
||
/* | ||
* A Valgrind tool external to the test binary is assumed to monitor | ||
* the execution and assess synchronisation correctness. | ||
*/ | ||
static struct test_case test_cases[] = { | ||
TEST_CASE(test_threshold), | ||
TEST_CASE(test_threshold_aux), | ||
}; | ||
|
||
#define NTESTS ARRAY_SIZE(test_cases) | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
START(argc, argv, "core_log_mt"); | ||
TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); | ||
DONE(NULL); | ||
} |