|
4 | 4 | #include <gtest/gtest.h> |
5 | 5 | #include <stdint.h> |
6 | 6 |
|
7 | | -/* |
8 | | - TODO: |
9 | | - Once singleton are supported for windows, |
10 | | - expand this test to use ::LoadLibrary, ::GetProcAddress, ::FreeLibrary |
11 | | -*/ |
12 | 7 | #ifdef _WIN32 |
13 | 8 | # include <windows.h> |
14 | 9 | #else |
@@ -58,51 +53,56 @@ void do_something() |
58 | 53 | */ |
59 | 54 |
|
60 | 55 | /* Call do_something_in_g() */ |
61 | | -#ifdef _WIN32 |
| 56 | + |
| 57 | +# ifdef _WIN32 |
62 | 58 | HMODULE component_g = LoadLibraryA("component_g.dll"); |
63 | | -#else |
| 59 | +# else |
64 | 60 | void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); |
65 | | -#endif |
| 61 | +# endif |
| 62 | + |
66 | 63 | EXPECT_NE(component_g, nullptr); |
67 | 64 |
|
68 | | -#ifdef _WIN32 |
| 65 | +# ifdef _WIN32 |
69 | 66 | auto *func_g = reinterpret_cast<void (*)()>(GetProcAddress(component_g, "do_something_in_g")); |
70 | | -#else |
| 67 | +# else |
71 | 68 | auto *func_g = reinterpret_cast<void (*)()>(dlsym(component_g, "do_something_in_g")); |
72 | | -#endif |
| 69 | +# endif |
| 70 | + |
73 | 71 | EXPECT_NE(func_g, nullptr); |
74 | 72 |
|
75 | 73 | (*func_g)(); |
76 | 74 |
|
77 | | -#ifdef _WIN32 |
| 75 | +# ifdef _WIN32 |
78 | 76 | FreeLibrary(component_g); |
79 | | -#else |
| 77 | +# else |
80 | 78 | dlclose(component_g); |
81 | | -#endif |
| 79 | +# endif |
82 | 80 |
|
83 | 81 | /* Call do_something_in_h() */ |
84 | 82 |
|
85 | | -#ifdef _WIN32 |
| 83 | +# ifdef _WIN32 |
86 | 84 | HMODULE component_h = LoadLibraryA("component_h.dll"); |
87 | | -#else |
| 85 | +# else |
88 | 86 | void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); |
89 | | -#endif |
| 87 | +# endif |
| 88 | + |
90 | 89 | EXPECT_NE(component_h, nullptr); |
91 | 90 |
|
92 | | -#ifdef _WIN32 |
| 91 | +# ifdef _WIN32 |
93 | 92 | auto *func_h = reinterpret_cast<void (*)()>(GetProcAddress(component_h, "do_something_in_h")); |
94 | | -#else |
| 93 | +# else |
95 | 94 | auto *func_h = reinterpret_cast<void (*)()>(dlsym(component_h, "do_something_in_h")); |
96 | | -#endif |
| 95 | +# endif |
| 96 | + |
97 | 97 | EXPECT_NE(func_h, nullptr); |
98 | 98 |
|
99 | 99 | (*func_h)(); |
100 | 100 |
|
101 | | -#ifdef _WIN32 |
| 101 | +# ifdef _WIN32 |
102 | 102 | FreeLibrary(component_h); |
103 | | -#else |
| 103 | +# else |
104 | 104 | dlclose(component_h); |
105 | | -#endif |
| 105 | +# endif |
106 | 106 | } |
107 | 107 |
|
108 | 108 | int span_a_lib_count = 0; |
@@ -339,6 +339,14 @@ void cleanup_otel() |
339 | 339 | trace_api::Provider::SetTracerProvider(provider); |
340 | 340 | } |
341 | 341 |
|
| 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 | + |
342 | 350 | TEST(SingletonTest, Uniqueness) |
343 | 351 | { |
344 | 352 | do_something(); |
@@ -380,25 +388,32 @@ TEST(SingletonTest, Uniqueness) |
380 | 388 | EXPECT_EQ(span_b_lib_count, 1); |
381 | 389 | EXPECT_EQ(span_b_f1_count, 2); |
382 | 390 | 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 |
402 | 417 |
|
403 | 418 | EXPECT_EQ(unknown_span_count, 0); |
404 | 419 |
|
|
0 commit comments