Skip to content

Commit db0a771

Browse files
committed
x
1 parent ce7ee13 commit db0a771

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
#include "utils_common.h"
3333
#include "utils_log.h"
3434

35+
#ifndef DISABLE_SINGLE_LOGGER
36+
#include "utils_concurrency.h"
37+
#endif
38+
3539
#define UMF_MAGIC_STR "\x00@(#) "
3640
#define UMF_PREF_STR "Intel(R) "
3741
#define UMF_PREFIX UMF_MAGIC_STR UMF_PREF_STR
@@ -60,6 +64,10 @@ char const __umf_str_1__all_cmake_vars[] =
6064
#define MAX_FILE_PATH 256
6165
#define MAX_ENV_LEN 2048
6266

67+
#ifndef DISABLE_CTL_LOGGER
68+
static UTIL_ONCE_FLAG initOnce = UTIL_ONCE_FLAG_INIT;
69+
#endif
70+
6371
typedef struct {
6472
bool enableTimestamp;
6573
bool enablePid;
@@ -247,7 +255,7 @@ void utils_plog(utils_log_level_t level, const char *func, const char *format,
247255

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

250-
void utils_log_init(void) {
258+
static void utils_log_init_once(void) {
251259
const char *envVar = getenv("UMF_LOG");
252260

253261
if (!envVar) {
@@ -343,6 +351,12 @@ void utils_log_init(void) {
343351
}
344352

345353
// this is needed for logger unit test
354+
#ifndef DISABLE_SINGLE_LOGGER
355+
void utils_log_init(void) { utils_init_once(&initOnce, utils_log_init_once); }
356+
#else // DISABLE_SINGLE_LOGGER
357+
void utils_log_init(void) { utils_log_init_once(); }
358+
#endif
359+
346360
#ifndef DISABLE_CTL_LOGGER
347361
static umf_result_t
348362
CTL_READ_HANDLER(timestamp)(void *ctx, umf_ctl_query_source_t source, void *arg,

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int mock_strerror_windows(char *buff, size_t s, int errnum) {
9797

9898
extern "C" {
9999
#define DISABLE_CTL_LOGGER 1
100+
#define DISABLE_SINGLE_LOGGER 1
100101
const char *env_variable = "";
101102
#define fopen(A, B) mock_fopen(A, B)
102103
#define fputs(A, B) mock_fputs(A, B)
@@ -161,8 +162,8 @@ TEST_F(test, parseEnv_errors) {
161162
helper_checkConfig(&b, &loggerConfig);
162163
helper_log_init("_level:debug");
163164
helper_checkConfig(&b, &loggerConfig);
164-
expected_message =
165-
"[ERROR UMF] utils_log_init: Cannot open output file - path too long\n";
165+
expected_message = "[ERROR UMF] utils_log_init_once: Cannot open output "
166+
"file - path too long\n";
166167
std::string test_env = "output:file," + std::string(300, 'x');
167168
helper_log_init(test_env.c_str());
168169
}
@@ -247,7 +248,8 @@ TEST_F(test, parseEnv) {
247248
expect_fput_count = 1;
248249
if (expected_filename.size() > MAX_FILE_PATH) {
249250
expected_message =
250-
"[ERROR UMF] utils_log_init: Cannot open "
251+
"[ERROR UMF] utils_log_init_once: Cannot "
252+
"open "
251253
"output file - path too long\n";
252254
}
253255
}

0 commit comments

Comments
 (0)