Skip to content

Commit 858bb06

Browse files
committed
x
1 parent ce7ee13 commit 858bb06

File tree

8 files changed

+38
-26
lines changed

8 files changed

+38
-26
lines changed

.github/workflows/reusable_proxy_lib.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
- name: Build UMF
5555
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
5656

57+
- name: Run "ctest --output-on-failure" without proxy library
58+
working-directory: ${{env.BUILD_DIR}}
59+
run: ctest --output-on-failure
60+
5761
- name: Run "ctest --output-on-failure" with proxy library
5862
working-directory: ${{env.BUILD_DIR}}
5963
run: LD_PRELOAD=./lib/libumf_proxy.so ctest --output-on-failure

src/coarse/coarse.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
#include "utils_concurrency.h"
2323
#include "utils_log.h"
2424

25-
#ifdef _WIN32
26-
UTIL_ONCE_FLAG Log_initialized = UTIL_ONCE_FLAG_INIT;
27-
#else
28-
void __attribute__((constructor)) coarse_init(void) { utils_log_init(); }
29-
void __attribute__((destructor)) coarse_destroy(void) {}
30-
#endif /* _WIN32 */
31-
3225
typedef struct coarse_t {
3326
// handle of the memory provider
3427
void *provider;
@@ -883,9 +876,7 @@ static umf_result_t coarse_get_stats_no_lock(coarse_t *coarse,
883876
// PUBLIC API
884877

885878
umf_result_t coarse_new(coarse_params_t *coarse_params, coarse_t **pcoarse) {
886-
#ifdef _WIN32
887-
utils_init_once(&Log_initialized, utils_log_init);
888-
#endif /* _WIN32 */
879+
utils_log_init();
889880

890881
if (coarse_params == NULL || pcoarse == NULL) {
891882
LOG_ERR("coarse parameters or handle is missing");

src/libumf_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include <umf.h>
1111

12-
void __attribute__((constructor)) umfCreate(void) { (void)umfInit(); }
12+
void __attribute__((constructor(102))) umfCreate(void) { (void)umfInit(); }
1313

14-
void __attribute__((destructor)) umfDestroy(void) { (void)umfTearDown(); }
14+
void __attribute__((destructor(102))) umfDestroy(void) { (void)umfTearDown(); }
1515

1616
void libumfInit(void) {
1717
// do nothing, additional initialization not needed

src/proxy_lib/proxy_lib_linux.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (C) 2024 Intel Corporation
3+
* Copyright (C) 2024-2025 Intel Corporation
44
*
55
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
66
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -9,15 +9,10 @@
99

1010
#include "proxy_lib.h"
1111

12-
// The priority 102 is used, because the constructor should be called as the second one
13-
// (just after the first constructor of the base allocator with priority 101)
14-
// and the destructor as the last but one (just before the last destructor
15-
// of the base allocator with priority 101), because this library
16-
// provides the memory allocation API.
17-
void __attribute__((constructor(102))) proxy_lib_create(void) {
12+
void __attribute__((constructor(101))) proxy_lib_create(void) {
1813
proxy_lib_create_common();
1914
}
2015

21-
void __attribute__((destructor(102))) proxy_lib_destroy(void) {
16+
void __attribute__((destructor(101))) proxy_lib_destroy(void) {
2217
proxy_lib_destroy_common();
2318
}

src/utils/utils_load_library.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ void *utils_open_library(const char *filename, int userFlags) {
7979
LOG_FATAL("dlopen(%s) failed with error: %s", filename, dlerror());
8080
}
8181

82+
LOG_DEBUG("Opened library %s with handle %p", filename, handle);
83+
8284
return handle;
8385
}
8486

85-
int utils_close_library(void *handle) { return dlclose(handle); }
87+
int utils_close_library(void *handle) {
88+
LOG_DEBUG("Closing library handle %p", handle);
89+
90+
return dlclose(handle);
91+
}
8692

8793
void *utils_get_symbol_addr(void *handle, const char *symbol,
8894
const char *libname) {

src/utils/utils_log.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "ctl/ctl_internal.h"
3131
#include "utils_assert.h"
3232
#include "utils_common.h"
33+
#include "utils_concurrency.h"
3334
#include "utils_log.h"
3435

3536
#define UMF_MAGIC_STR "\x00@(#) "
@@ -60,6 +61,8 @@ char const __umf_str_1__all_cmake_vars[] =
6061
#define MAX_FILE_PATH 256
6162
#define MAX_ENV_LEN 2048
6263

64+
static UTIL_ONCE_FLAG initOnce = UTIL_ONCE_FLAG_INIT;
65+
6366
typedef struct {
6467
bool enableTimestamp;
6568
bool enablePid;
@@ -247,7 +250,7 @@ void utils_plog(utils_log_level_t level, const char *func, const char *format,
247250

248251
static const char *bool_to_str(int b) { return b ? "yes" : "no"; }
249252

250-
void utils_log_init(void) {
253+
static void utils_log_init_once(void) {
251254
const char *envVar = getenv("UMF_LOG");
252255

253256
if (!envVar) {
@@ -342,6 +345,14 @@ void utils_log_init(void) {
342345
bool_to_str(loggerConfig.enableTimestamp));
343346
}
344347

348+
void utils_log_init(void) { utils_init_once(&initOnce, utils_log_init_once); }
349+
350+
void utils_log_init_test(void) {
351+
// this function is used in tests to initialize the logging system
352+
// without using the utils_init_once to test various logging scenarios
353+
utils_log_init_once();
354+
}
355+
345356
// this is needed for logger unit test
346357
#ifndef DISABLE_CTL_LOGGER
347358
static umf_result_t

src/utils/utils_log.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ typedef enum {
3737
#define LOG_PFATAL(...) utils_plog(LOG_FATAL, __func__, __VA_ARGS__);
3838

3939
void utils_log_init(void);
40+
41+
// this function is used in tests to initialize the logging system
42+
void utils_log_init_test(void);
43+
4044
#ifdef _WIN32
4145
void utils_log(utils_log_level_t level, const char *func, const char *format,
4246
...);

test/utils/utils_log.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void helper_log_init(const char *var) {
128128
env_variable = var;
129129
fopen_count = 0;
130130
fput_count = 0;
131-
utils_log_init();
131+
utils_log_init_test();
132132
env_variable = NULL;
133133
EXPECT_EQ(fopen_count, expect_fopen_count);
134134
EXPECT_EQ(fput_count, expect_fput_count);
@@ -161,8 +161,8 @@ TEST_F(test, parseEnv_errors) {
161161
helper_checkConfig(&b, &loggerConfig);
162162
helper_log_init("_level:debug");
163163
helper_checkConfig(&b, &loggerConfig);
164-
expected_message =
165-
"[ERROR UMF] utils_log_init: Cannot open output file - path too long\n";
164+
expected_message = "[ERROR UMF] utils_log_init_once: Cannot open output "
165+
"file - path too long\n";
166166
std::string test_env = "output:file," + std::string(300, 'x');
167167
helper_log_init(test_env.c_str());
168168
}
@@ -247,7 +247,8 @@ TEST_F(test, parseEnv) {
247247
expect_fput_count = 1;
248248
if (expected_filename.size() > MAX_FILE_PATH) {
249249
expected_message =
250-
"[ERROR UMF] utils_log_init: Cannot open "
250+
"[ERROR UMF] utils_log_init_once: Cannot "
251+
"open "
251252
"output file - path too long\n";
252253
}
253254
}

0 commit comments

Comments
 (0)