Skip to content

Commit a6946e6

Browse files
committed
merged from upstream
2 parents ac01b8c + 902ee88 commit a6946e6

File tree

3 files changed

+109
-98
lines changed

3 files changed

+109
-98
lines changed

api/test/singleton/CMakeLists.txt

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,53 @@
33

44
include(GoogleTest)
55

6-
# Header only singletons are not available in windows yet.
7-
8-
if(NOT WIN32)
9-
10-
add_library(component_a STATIC component_a.cc)
11-
target_link_libraries(component_a opentelemetry_api)
12-
13-
add_library(component_b STATIC component_b.cc)
14-
target_link_libraries(component_b opentelemetry_api)
15-
16-
add_library(component_c SHARED component_c.cc)
17-
set_target_properties(component_c PROPERTIES CXX_VISIBILITY_PRESET default)
18-
target_link_libraries(component_c opentelemetry_api)
19-
20-
add_library(component_d SHARED component_d.cc)
21-
set_target_properties(component_d PROPERTIES CXX_VISIBILITY_PRESET hidden)
22-
target_link_libraries(component_d opentelemetry_api)
23-
24-
add_library(component_e SHARED component_e.cc)
25-
set_target_properties(component_e PROPERTIES CXX_VISIBILITY_PRESET default)
26-
target_link_libraries(component_e opentelemetry_api)
27-
28-
add_library(component_f SHARED component_f.cc)
29-
set_target_properties(component_f PROPERTIES CXX_VISIBILITY_PRESET hidden)
30-
target_link_libraries(component_f opentelemetry_api)
31-
32-
add_library(component_g SHARED component_g.cc)
33-
set_target_properties(component_g PROPERTIES CXX_VISIBILITY_PRESET default)
34-
target_link_libraries(component_g opentelemetry_api)
35-
36-
add_library(component_h SHARED component_h.cc)
37-
set_target_properties(component_h PROPERTIES CXX_VISIBILITY_PRESET hidden)
38-
target_link_libraries(component_h opentelemetry_api)
39-
40-
add_executable(singleton_test singleton_test.cc)
41-
42-
# Not linking with component_g and component_h on purpose
43-
target_link_libraries(
44-
singleton_test
45-
component_a
46-
component_b
47-
component_c
48-
component_d
49-
component_e
50-
component_f
51-
${GTEST_BOTH_LIBRARIES}
52-
${CMAKE_THREAD_LIBS_INIT}
53-
${CMAKE_DL_LIBS}
54-
opentelemetry_api)
55-
56-
gtest_add_tests(
57-
TARGET singleton_test
58-
TEST_PREFIX singleton.
59-
TEST_LIST singleton_test)
60-
61-
endif()
6+
add_library(component_a STATIC component_a.cc)
7+
target_link_libraries(component_a opentelemetry_api)
8+
9+
add_library(component_b STATIC component_b.cc)
10+
target_link_libraries(component_b opentelemetry_api)
11+
12+
add_library(component_c SHARED component_c.cc)
13+
set_target_properties(component_c PROPERTIES CXX_VISIBILITY_PRESET default)
14+
target_link_libraries(component_c opentelemetry_api)
15+
16+
add_library(component_d SHARED component_d.cc)
17+
set_target_properties(component_d PROPERTIES CXX_VISIBILITY_PRESET hidden)
18+
target_link_libraries(component_d opentelemetry_api)
19+
20+
add_library(component_e SHARED component_e.cc)
21+
set_target_properties(component_e PROPERTIES CXX_VISIBILITY_PRESET default)
22+
target_link_libraries(component_e opentelemetry_api)
23+
24+
add_library(component_f SHARED component_f.cc)
25+
set_target_properties(component_f PROPERTIES CXX_VISIBILITY_PRESET hidden)
26+
target_link_libraries(component_f opentelemetry_api)
27+
28+
add_library(component_g SHARED component_g.cc)
29+
set_target_properties(component_g PROPERTIES CXX_VISIBILITY_PRESET default)
30+
target_link_libraries(component_g opentelemetry_api)
31+
32+
add_library(component_h SHARED component_h.cc)
33+
set_target_properties(component_h PROPERTIES CXX_VISIBILITY_PRESET hidden)
34+
target_link_libraries(component_h opentelemetry_api)
35+
36+
add_executable(singleton_test singleton_test.cc)
37+
38+
# Not linking with component_g and component_h on purpose
39+
target_link_libraries(
40+
singleton_test
41+
component_a
42+
component_b
43+
component_c
44+
component_d
45+
component_e
46+
component_f
47+
${GTEST_BOTH_LIBRARIES}
48+
${CMAKE_THREAD_LIBS_INIT}
49+
${CMAKE_DL_LIBS}
50+
opentelemetry_api)
51+
52+
gtest_add_tests(
53+
TARGET singleton_test
54+
TEST_PREFIX singleton.
55+
TEST_LIST singleton_test)

api/test/singleton/singleton_test.cc

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
#include <gtest/gtest.h>
55
#include <stdint.h>
66

7-
/*
8-
TODO:
9-
Once singleton are supported for windows,
10-
expand this test to use ::LoadLibrary, ::GetProcAddress, ::FreeLibrary
11-
*/
127
#ifdef _WIN32
138
# include <windows.h>
149
#else
@@ -58,51 +53,56 @@ void do_something()
5853
*/
5954

6055
/* Call do_something_in_g() */
61-
#ifdef _WIN32
56+
57+
# ifdef _WIN32
6258
HMODULE component_g = LoadLibraryA("component_g.dll");
63-
#else
59+
# else
6460
void *component_g = dlopen("libcomponent_g.so", RTLD_NOW);
65-
#endif
61+
# endif
62+
6663
EXPECT_NE(component_g, nullptr);
6764

68-
#ifdef _WIN32
65+
# ifdef _WIN32
6966
auto *func_g = reinterpret_cast<void (*)()>(GetProcAddress(component_g, "do_something_in_g"));
70-
#else
67+
# else
7168
auto *func_g = reinterpret_cast<void (*)()>(dlsym(component_g, "do_something_in_g"));
72-
#endif
69+
# endif
70+
7371
EXPECT_NE(func_g, nullptr);
7472

7573
(*func_g)();
7674

77-
#ifdef _WIN32
75+
# ifdef _WIN32
7876
FreeLibrary(component_g);
79-
#else
77+
# else
8078
dlclose(component_g);
81-
#endif
79+
# endif
8280

8381
/* Call do_something_in_h() */
8482

85-
#ifdef _WIN32
83+
# ifdef _WIN32
8684
HMODULE component_h = LoadLibraryA("component_h.dll");
87-
#else
85+
# else
8886
void *component_h = dlopen("libcomponent_h.so", RTLD_NOW);
89-
#endif
87+
# endif
88+
9089
EXPECT_NE(component_h, nullptr);
9190

92-
#ifdef _WIN32
91+
# ifdef _WIN32
9392
auto *func_h = reinterpret_cast<void (*)()>(GetProcAddress(component_h, "do_something_in_h"));
94-
#else
93+
# else
9594
auto *func_h = reinterpret_cast<void (*)()>(dlsym(component_h, "do_something_in_h"));
96-
#endif
95+
# endif
96+
9797
EXPECT_NE(func_h, nullptr);
9898

9999
(*func_h)();
100100

101-
#ifdef _WIN32
101+
# ifdef _WIN32
102102
FreeLibrary(component_h);
103-
#else
103+
# else
104104
dlclose(component_h);
105-
#endif
105+
# endif
106106
}
107107

108108
int span_a_lib_count = 0;
@@ -339,6 +339,14 @@ void cleanup_otel()
339339
trace_api::Provider::SetTracerProvider(provider);
340340
}
341341

342+
// TODO: Remove once windows api singletons are supported.
343+
// See https://github.com/open-telemetry/opentelemetry-cpp/issues/2534
344+
#ifdef _WIN32
345+
# define RUN_FAILING_WINDOWS_TEST 1
346+
#else
347+
# define RUN_FAILING_WINDOWS_TEST 1
348+
#endif
349+
342350
TEST(SingletonTest, Uniqueness)
343351
{
344352
do_something();
@@ -380,25 +388,32 @@ TEST(SingletonTest, Uniqueness)
380388
EXPECT_EQ(span_b_lib_count, 1);
381389
EXPECT_EQ(span_b_f1_count, 2);
382390
EXPECT_EQ(span_b_f2_count, 1);
383-
EXPECT_EQ(span_c_lib_count, 1);
384-
EXPECT_EQ(span_c_f1_count, 2);
385-
EXPECT_EQ(span_c_f2_count, 1);
386-
EXPECT_EQ(span_d_lib_count, 1);
387-
EXPECT_EQ(span_d_f1_count, 2);
388-
EXPECT_EQ(span_d_f2_count, 1);
389-
EXPECT_EQ(span_e_lib_count, 1);
390-
EXPECT_EQ(span_e_f1_count, 2);
391-
EXPECT_EQ(span_e_f2_count, 1);
392-
EXPECT_EQ(span_f_lib_count, 1);
393-
EXPECT_EQ(span_f_f1_count, 2);
394-
EXPECT_EQ(span_f_f2_count, 1);
395-
396-
EXPECT_EQ(span_g_lib_count, 1);
397-
EXPECT_EQ(span_g_f1_count, 2);
398-
EXPECT_EQ(span_g_f2_count, 1);
399-
EXPECT_EQ(span_h_lib_count, 1);
400-
EXPECT_EQ(span_h_f1_count, 2);
401-
EXPECT_EQ(span_h_f2_count, 1);
391+
392+
#if RUN_FAILING_WINDOWS_TEST
393+
EXPECT_EQ(span_c_lib_count, 1); // Fails with shared libraries on Windows
394+
EXPECT_EQ(span_c_f1_count, 2); // Fails with shared libraries on Windows
395+
EXPECT_EQ(span_c_f2_count, 1); // Fails with shared libraries on Windows
396+
EXPECT_EQ(span_d_lib_count, 1); // Fails with shared libraries on Windows
397+
EXPECT_EQ(span_d_f1_count, 2); // Fails with shared libraries on Windows
398+
EXPECT_EQ(span_d_f2_count, 1); // Fails with shared libraries on Windows
399+
EXPECT_EQ(span_e_lib_count, 1); // Fails with shared libraries on Windows
400+
EXPECT_EQ(span_e_f1_count, 2); // Fails with shared libraries on Windows
401+
EXPECT_EQ(span_e_f2_count, 1); // Fails with shared libraries on Windows
402+
EXPECT_EQ(span_f_lib_count, 1); // Fails with shared libraries on Windows
403+
EXPECT_EQ(span_f_f1_count, 2); // Fails with shared libraries on Windows
404+
EXPECT_EQ(span_f_f2_count, 1); // Fails with shared libraries on Windows
405+
#endif
406+
407+
#ifndef BAZEL_BUILD
408+
# if RUN_FAILING_WINDOWS_TEST
409+
EXPECT_EQ(span_g_lib_count, 1); // Fails with shared libraries on Windows
410+
EXPECT_EQ(span_g_f1_count, 2); // Fails with shared libraries on Windows
411+
EXPECT_EQ(span_g_f2_count, 1); // Fails with shared libraries on Windows
412+
EXPECT_EQ(span_h_lib_count, 1); // Fails with shared libraries on Windows
413+
EXPECT_EQ(span_h_f1_count, 2); // Fails with shared libraries on Windows
414+
EXPECT_EQ(span_h_f2_count, 1); // Fails with shared libraries on Windows
415+
# endif
416+
#endif
402417

403418
EXPECT_EQ(unknown_span_count, 0);
404419

ci/do_ci.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ $PLUGIN_DIR = Join-Path "$SRC_DIR" "plugin"
2727

2828
$VCPKG_DIR = Join-Path "$SRC_DIR" "tools" "vcpkg"
2929

30+
$Env:CTEST_OUTPUT_ON_FAILURE = "1"
31+
3032
switch ($action) {
3133
"bazel.build" {
3234
bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS --action_env=VCPKG_DIR=$VCPKG_DIR --deleted_packages=opentracing-shim -- //...

0 commit comments

Comments
 (0)