|
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 |
| -#ifndef _WIN32 |
| 7 | +#ifdef _WIN32 |
| 8 | +# include <windows.h> |
| 9 | +#else |
13 | 10 | # include <dlfcn.h>
|
14 | 11 | #endif
|
15 | 12 |
|
@@ -58,28 +55,57 @@ void do_something()
|
58 | 55 | #ifndef BAZEL_BUILD
|
59 | 56 | /* Call do_something_in_g() */
|
60 | 57 |
|
| 58 | +# ifdef _WIN32 |
| 59 | + HMODULE component_g = LoadLibraryA("component_g.dll"); |
| 60 | +# else |
61 | 61 | void *component_g = dlopen("libcomponent_g.so", RTLD_NOW);
|
| 62 | +# endif |
| 63 | + |
62 | 64 | EXPECT_NE(component_g, nullptr);
|
63 | 65 |
|
| 66 | +# ifdef _WIN32 |
| 67 | + auto *func_g = reinterpret_cast<void (*)()>(GetProcAddress(component_g, "do_something_in_g")); |
| 68 | +# else |
64 | 69 | auto *func_g = reinterpret_cast<void (*)()>(dlsym(component_g, "do_something_in_g"));
|
| 70 | +# endif |
| 71 | + |
65 | 72 | EXPECT_NE(func_g, nullptr);
|
66 | 73 |
|
67 | 74 | (*func_g)();
|
68 | 75 |
|
| 76 | +# ifdef _WIN32 |
| 77 | + FreeLibrary(component_g); |
| 78 | +# else |
69 | 79 | dlclose(component_g);
|
| 80 | +# endif |
70 | 81 |
|
71 | 82 | /* Call do_something_in_h() */
|
72 | 83 |
|
| 84 | +# ifdef _WIN32 |
| 85 | + HMODULE component_h = LoadLibraryA("component_h.dll"); |
| 86 | +# else |
73 | 87 | void *component_h = dlopen("libcomponent_h.so", RTLD_NOW);
|
| 88 | +# endif |
| 89 | + |
74 | 90 | EXPECT_NE(component_h, nullptr);
|
75 | 91 |
|
| 92 | +# ifdef _WIN32 |
| 93 | + auto *func_h = reinterpret_cast<void (*)()>(GetProcAddress(component_h, "do_something_in_h")); |
| 94 | +# else |
76 | 95 | auto *func_h = reinterpret_cast<void (*)()>(dlsym(component_h, "do_something_in_h"));
|
| 96 | +# endif |
| 97 | + |
77 | 98 | EXPECT_NE(func_h, nullptr);
|
78 | 99 |
|
79 | 100 | (*func_h)();
|
80 | 101 |
|
| 102 | +# ifdef _WIN32 |
| 103 | + FreeLibrary(component_h); |
| 104 | +# else |
81 | 105 | dlclose(component_h);
|
82 |
| -#endif |
| 106 | +# endif |
| 107 | + |
| 108 | +#endif /* BAZEL_BUILD */ |
83 | 109 | }
|
84 | 110 |
|
85 | 111 | int span_a_lib_count = 0;
|
@@ -316,6 +342,14 @@ void cleanup_otel()
|
316 | 342 | trace_api::Provider::SetTracerProvider(provider);
|
317 | 343 | }
|
318 | 344 |
|
| 345 | +// TODO: Remove once windows api singletons are supported. |
| 346 | +// See https://github.com/open-telemetry/opentelemetry-cpp/issues/2534 |
| 347 | +#ifdef _WIN32 |
| 348 | +# define RUN_FAILING_WINDOWS_TEST 0 |
| 349 | +#else |
| 350 | +# define RUN_FAILING_WINDOWS_TEST 1 |
| 351 | +#endif |
| 352 | + |
319 | 353 | TEST(SingletonTest, Uniqueness)
|
320 | 354 | {
|
321 | 355 | do_something();
|
@@ -357,26 +391,31 @@ TEST(SingletonTest, Uniqueness)
|
357 | 391 | EXPECT_EQ(span_b_lib_count, 1);
|
358 | 392 | EXPECT_EQ(span_b_f1_count, 2);
|
359 | 393 | EXPECT_EQ(span_b_f2_count, 1);
|
360 |
| - EXPECT_EQ(span_c_lib_count, 1); |
361 |
| - EXPECT_EQ(span_c_f1_count, 2); |
362 |
| - EXPECT_EQ(span_c_f2_count, 1); |
363 |
| - EXPECT_EQ(span_d_lib_count, 1); |
364 |
| - EXPECT_EQ(span_d_f1_count, 2); |
365 |
| - EXPECT_EQ(span_d_f2_count, 1); |
366 |
| - EXPECT_EQ(span_e_lib_count, 1); |
367 |
| - EXPECT_EQ(span_e_f1_count, 2); |
368 |
| - EXPECT_EQ(span_e_f2_count, 1); |
369 |
| - EXPECT_EQ(span_f_lib_count, 1); |
370 |
| - EXPECT_EQ(span_f_f1_count, 2); |
371 |
| - EXPECT_EQ(span_f_f2_count, 1); |
| 394 | + |
| 395 | +#if RUN_FAILING_WINDOWS_TEST |
| 396 | + EXPECT_EQ(span_c_lib_count, 1); // Fails with shared libraries on Windows |
| 397 | + EXPECT_EQ(span_c_f1_count, 2); // Fails with shared libraries on Windows |
| 398 | + EXPECT_EQ(span_c_f2_count, 1); // Fails with shared libraries on Windows |
| 399 | + EXPECT_EQ(span_d_lib_count, 1); // Fails with shared libraries on Windows |
| 400 | + EXPECT_EQ(span_d_f1_count, 2); // Fails with shared libraries on Windows |
| 401 | + EXPECT_EQ(span_d_f2_count, 1); // Fails with shared libraries on Windows |
| 402 | + EXPECT_EQ(span_e_lib_count, 1); // Fails with shared libraries on Windows |
| 403 | + EXPECT_EQ(span_e_f1_count, 2); // Fails with shared libraries on Windows |
| 404 | + EXPECT_EQ(span_e_f2_count, 1); // Fails with shared libraries on Windows |
| 405 | + EXPECT_EQ(span_f_lib_count, 1); // Fails with shared libraries on Windows |
| 406 | + EXPECT_EQ(span_f_f1_count, 2); // Fails with shared libraries on Windows |
| 407 | + EXPECT_EQ(span_f_f2_count, 1); // Fails with shared libraries on Windows |
| 408 | +#endif |
372 | 409 |
|
373 | 410 | #ifndef BAZEL_BUILD
|
374 |
| - EXPECT_EQ(span_g_lib_count, 1); |
375 |
| - EXPECT_EQ(span_g_f1_count, 2); |
376 |
| - EXPECT_EQ(span_g_f2_count, 1); |
377 |
| - EXPECT_EQ(span_h_lib_count, 1); |
378 |
| - EXPECT_EQ(span_h_f1_count, 2); |
379 |
| - EXPECT_EQ(span_h_f2_count, 1); |
| 411 | +# if RUN_FAILING_WINDOWS_TEST |
| 412 | + EXPECT_EQ(span_g_lib_count, 1); // Fails with shared libraries on Windows |
| 413 | + EXPECT_EQ(span_g_f1_count, 2); // Fails with shared libraries on Windows |
| 414 | + EXPECT_EQ(span_g_f2_count, 1); // Fails with shared libraries on Windows |
| 415 | + EXPECT_EQ(span_h_lib_count, 1); // Fails with shared libraries on Windows |
| 416 | + EXPECT_EQ(span_h_f1_count, 2); // Fails with shared libraries on Windows |
| 417 | + EXPECT_EQ(span_h_f2_count, 1); // Fails with shared libraries on Windows |
| 418 | +# endif |
380 | 419 | #endif
|
381 | 420 |
|
382 | 421 | EXPECT_EQ(unknown_span_count, 0);
|
|
0 commit comments