From aad01dd785366462d891ddecc897b5afc32c2b40 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 30 May 2023 14:57:04 +0200 Subject: [PATCH 01/10] Expand api singleton test to cover libraries loaded with dlopen(). --- api/test/singleton/CMakeLists.txt | 10 ++++ api/test/singleton/component_c.h | 2 +- api/test/singleton/component_d.h | 2 +- api/test/singleton/component_e.h | 2 +- api/test/singleton/component_f.h | 2 +- api/test/singleton/component_g.cc | 52 ++++++++++++++++++ api/test/singleton/component_h.cc | 52 ++++++++++++++++++ api/test/singleton/singleton_test.cc | 79 ++++++++++++++++++++++++++++ 8 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 api/test/singleton/component_g.cc create mode 100644 api/test/singleton/component_h.cc diff --git a/api/test/singleton/CMakeLists.txt b/api/test/singleton/CMakeLists.txt index a92233fca3..ba41fef8b2 100644 --- a/api/test/singleton/CMakeLists.txt +++ b/api/test/singleton/CMakeLists.txt @@ -29,8 +29,17 @@ if(NOT WIN32) set_target_properties(component_f PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(component_f opentelemetry_api) + add_library(component_g SHARED component_g.cc) + set_target_properties(component_g PROPERTIES CXX_VISIBILITY_PRESET default) + target_link_libraries(component_g opentelemetry_api) + + add_library(component_h SHARED component_h.cc) + set_target_properties(component_h PROPERTIES CXX_VISIBILITY_PRESET hidden) + target_link_libraries(component_h opentelemetry_api) + add_executable(singleton_test singleton_test.cc) + # Not linking with component_g and component_h on purpose target_link_libraries( singleton_test component_a @@ -41,6 +50,7 @@ if(NOT WIN32) component_f ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + -ldl opentelemetry_api) gtest_add_tests( diff --git a/api/test/singleton/component_c.h b/api/test/singleton/component_c.h index 31193da2df..11b8c96223 100644 --- a/api/test/singleton/component_c.h +++ b/api/test/singleton/component_c.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #if defined(_MSC_VER) -// component_c is a DDL +// component_c is a DLL # ifdef BUILD_COMPONENT_C __declspec(dllexport) diff --git a/api/test/singleton/component_d.h b/api/test/singleton/component_d.h index be65f4b5ac..1090014c2d 100644 --- a/api/test/singleton/component_d.h +++ b/api/test/singleton/component_d.h @@ -4,7 +4,7 @@ // Make the entry point visible, loaded dynamically #if defined(_MSC_VER) -// component_d is a DDL +// component_d is a DLL # ifdef BUILD_COMPONENT_D __declspec(dllexport) diff --git a/api/test/singleton/component_e.h b/api/test/singleton/component_e.h index 53782d76f7..223a1f3a8a 100644 --- a/api/test/singleton/component_e.h +++ b/api/test/singleton/component_e.h @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #if defined(_MSC_VER) -// component_e is a DDL +// component_e is a DLL # ifdef BUILD_COMPONENT_E __declspec(dllexport) diff --git a/api/test/singleton/component_f.h b/api/test/singleton/component_f.h index e042ba5bb3..80334de5aa 100644 --- a/api/test/singleton/component_f.h +++ b/api/test/singleton/component_f.h @@ -4,7 +4,7 @@ // Make the entry point visible, loaded dynamically #if defined(_MSC_VER) -// component_f is a DDL +// component_f is a DLL # ifdef BUILD_COMPONENT_F __declspec(dllexport) diff --git a/api/test/singleton/component_g.cc b/api/test/singleton/component_g.cc new file mode 100644 index 0000000000..f38722ac90 --- /dev/null +++ b/api/test/singleton/component_g.cc @@ -0,0 +1,52 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_E + +#include "component_e.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("G", "70.7"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::f2")); + + f1(); + f1(); +} + + +#if defined(_MSC_VER) +// component_g is a DLL + +__declspec(dllexport) + +#else +// component_g is a shared library (*.so) +// component_g is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + +extern "C" +void do_something_in_g() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::library")); + + f2(); +} diff --git a/api/test/singleton/component_h.cc b/api/test/singleton/component_h.cc new file mode 100644 index 0000000000..b19510f25b --- /dev/null +++ b/api/test/singleton/component_h.cc @@ -0,0 +1,52 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/nostd/shared_ptr.h" +#include "opentelemetry/trace/provider.h" +#include "opentelemetry/version.h" + +#define BUILD_COMPONENT_E + +#include "component_e.h" + +namespace trace = opentelemetry::trace; +namespace nostd = opentelemetry::nostd; + +static nostd::shared_ptr get_tracer() +{ + auto provider = trace::Provider::GetTracerProvider(); + return provider->GetTracer("H", "80.8"); +} + +static void f1() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f1")); +} + +static void f2() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::f2")); + + f1(); + f1(); +} + + +#if defined(_MSC_VER) +// component_g is a DLL + +__declspec(dllexport) + +#else +// component_g is a shared library (*.so) +// component_g is compiled with visibility("hidden"), +__attribute__((visibility("default"))) +#endif + +extern "C" +void do_something_in_h() +{ + auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::library")); + + f2(); +} diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 20a956d4a8..9a49500cc1 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -5,6 +5,7 @@ #include #include +#include #include "component_a.h" #include "component_b.h" @@ -30,6 +31,30 @@ void do_something() do_something_in_d(); do_something_in_e(); do_something_in_f(); + + /* Call do_something_in_g() */ + + void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); + assert(component_g != nullptr); + + auto *func_g = (void(*)())dlsym(component_g, "do_something_in_g"); + assert(func_g != nullptr); + + (*func_g)(); + + dlclose(component_g); + + /* Call do_something_in_h() */ + + void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); + assert(component_h != nullptr); + + auto *func_h = (void(*)())dlsym(component_h, "do_something_in_h"); + assert(func_h != nullptr); + + (*func_h)(); + + dlclose(component_h); } int span_a_lib_count = 0; @@ -50,6 +75,12 @@ int span_e_f2_count = 0; int span_f_lib_count = 0; int span_f_f1_count = 0; int span_f_f2_count = 0; +int span_g_lib_count = 0; +int span_g_f1_count = 0; +int span_g_f2_count = 0; +int span_h_lib_count = 0; +int span_h_f1_count = 0; +int span_h_f2_count = 0; int unknown_span_count = 0; void reset_counts() @@ -72,6 +103,12 @@ void reset_counts() span_f_lib_count = 0; span_f_f1_count = 0; span_f_f2_count = 0; + span_g_lib_count = 0; + span_g_f1_count = 0; + span_g_f2_count = 0; + span_h_lib_count = 0; + span_h_f1_count = 0; + span_h_f2_count = 0; unknown_span_count = 0; } @@ -162,6 +199,30 @@ class MyTracer : public trace::Tracer { span_f_f2_count++; } + else if (name == "G::library") + { + span_g_lib_count++; + } + else if (name == "G::f1") + { + span_g_f1_count++; + } + else if (name == "G::f2") + { + span_g_f2_count++; + } + else if (name == "H::library") + { + span_h_lib_count++; + } + else if (name == "H::f1") + { + span_h_f1_count++; + } + else if (name == "H::f2") + { + span_h_f2_count++; + } else { unknown_span_count++; @@ -236,6 +297,12 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 0); EXPECT_EQ(span_f_f1_count, 0); EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); EXPECT_EQ(unknown_span_count, 0); reset_counts(); @@ -261,6 +328,12 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 1); EXPECT_EQ(span_f_f1_count, 2); EXPECT_EQ(span_f_f2_count, 1); + EXPECT_EQ(span_g_lib_count, 1); + EXPECT_EQ(span_g_f1_count, 2); + EXPECT_EQ(span_g_f2_count, 1); + EXPECT_EQ(span_h_lib_count, 1); + EXPECT_EQ(span_h_f1_count, 2); + EXPECT_EQ(span_h_f2_count, 1); EXPECT_EQ(unknown_span_count, 0); reset_counts(); @@ -286,5 +359,11 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 0); EXPECT_EQ(span_f_f1_count, 0); EXPECT_EQ(span_f_f2_count, 0); + EXPECT_EQ(span_g_lib_count, 0); + EXPECT_EQ(span_g_f1_count, 0); + EXPECT_EQ(span_g_f2_count, 0); + EXPECT_EQ(span_h_lib_count, 0); + EXPECT_EQ(span_h_f1_count, 0); + EXPECT_EQ(span_h_f2_count, 0); EXPECT_EQ(unknown_span_count, 0); } From a3c5a35707a6321a8608d52c30b3e68f6fed80a7 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 30 May 2023 17:52:10 +0200 Subject: [PATCH 02/10] cleanup --- api/test/singleton/component_g.cc | 18 ++++-------------- api/test/singleton/component_h.cc | 12 ++++-------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/api/test/singleton/component_g.cc b/api/test/singleton/component_g.cc index f38722ac90..49732d9b1f 100644 --- a/api/test/singleton/component_g.cc +++ b/api/test/singleton/component_g.cc @@ -5,10 +5,6 @@ #include "opentelemetry/trace/provider.h" #include "opentelemetry/version.h" -#define BUILD_COMPONENT_E - -#include "component_e.h" - namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; @@ -31,20 +27,14 @@ static void f2() f1(); } +extern "C" #if defined(_MSC_VER) -// component_g is a DLL - -__declspec(dllexport) - -#else -// component_g is a shared library (*.so) -// component_g is compiled with visibility("hidden"), -__attribute__((visibility("default"))) + // component_g is a DLL + __declspec(dllexport) #endif -extern "C" -void do_something_in_g() + void do_something_in_g() { auto scoped_span = trace::Scope(get_tracer()->StartSpan("G::library")); diff --git a/api/test/singleton/component_h.cc b/api/test/singleton/component_h.cc index b19510f25b..30223bb935 100644 --- a/api/test/singleton/component_h.cc +++ b/api/test/singleton/component_h.cc @@ -5,10 +5,6 @@ #include "opentelemetry/trace/provider.h" #include "opentelemetry/version.h" -#define BUILD_COMPONENT_E - -#include "component_e.h" - namespace trace = opentelemetry::trace; namespace nostd = opentelemetry::nostd; @@ -31,11 +27,12 @@ static void f2() f1(); } +extern "C" #if defined(_MSC_VER) -// component_g is a DLL + // component_g is a DLL -__declspec(dllexport) + __declspec(dllexport) #else // component_g is a shared library (*.so) @@ -43,8 +40,7 @@ __declspec(dllexport) __attribute__((visibility("default"))) #endif -extern "C" -void do_something_in_h() + void do_something_in_h() { auto scoped_span = trace::Scope(get_tracer()->StartSpan("H::library")); From 5bc4b831268988450097db720394accce1a985df Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 30 May 2023 18:20:02 +0200 Subject: [PATCH 03/10] Fixed bazel, format --- api/test/singleton/BUILD | 30 ++++++++++++++++++++++++++++ api/test/singleton/singleton_test.cc | 6 +++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index 5522284509..b08ec1b99b 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -117,6 +117,36 @@ cc_library( ], ) +cc_library( + name = "component_g", + srcs = [ + "component_g.cc", + ], + copts = select({ + "//bazel:windows": DEFAULT_WIN_COPTS, + "//conditions:default": DEFAULT_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + +cc_library( + name = "component_h", + srcs = [ + "component_h.cc", + ], + copts = select({ + "//bazel:windows": HIDDEN_WIN_COPTS, + "//conditions:default": HIDDEN_NOWIN_COPTS, + }), + linkstatic = False, + deps = [ + "//api", + ], +) + cc_test( name = "singleton_test", srcs = [ diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 9a49500cc1..d4f6ba953b 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include "component_a.h" #include "component_b.h" @@ -37,7 +37,7 @@ void do_something() void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); assert(component_g != nullptr); - auto *func_g = (void(*)())dlsym(component_g, "do_something_in_g"); + auto *func_g = (void (*)())dlsym(component_g, "do_something_in_g"); assert(func_g != nullptr); (*func_g)(); @@ -49,7 +49,7 @@ void do_something() void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); assert(component_h != nullptr); - auto *func_h = (void(*)())dlsym(component_h, "do_something_in_h"); + auto *func_h = (void (*)())dlsym(component_h, "do_something_in_h"); assert(func_h != nullptr); (*func_h)(); From b3bbf04ec5a6af4ff4f338de652d0e038caeddec Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 30 May 2023 19:00:21 +0200 Subject: [PATCH 04/10] cleanup --- api/test/singleton/BUILD | 3 +++ api/test/singleton/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index b08ec1b99b..d577e79aaf 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -153,6 +153,9 @@ cc_test( "singleton_test.cc", ], linkstatic = False, + linkopts = [ + "-ldl", + ], tags = [ "api", "test", diff --git a/api/test/singleton/CMakeLists.txt b/api/test/singleton/CMakeLists.txt index ba41fef8b2..450308cd82 100644 --- a/api/test/singleton/CMakeLists.txt +++ b/api/test/singleton/CMakeLists.txt @@ -50,7 +50,7 @@ if(NOT WIN32) component_f ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - -ldl + ${CMAKE_DL_LIBS} opentelemetry_api) gtest_add_tests( From 96c6b190b15e46b3705affdf4d8c5305fafcc882 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 30 May 2023 21:34:48 +0200 Subject: [PATCH 05/10] bazel cleanup --- api/test/singleton/BUILD | 4 ++-- api/test/singleton/singleton_test.cc | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index d577e79aaf..a14e4ef425 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -118,7 +118,7 @@ cc_library( ) cc_library( - name = "component_g", + name = "libcomponent_g.so", srcs = [ "component_g.cc", ], @@ -133,7 +133,7 @@ cc_library( ) cc_library( - name = "component_h", + name = "libcomponent_h.so", srcs = [ "component_h.cc", ], diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index d4f6ba953b..f02aa459fd 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -3,7 +3,6 @@ #include -#include #include #include @@ -35,10 +34,10 @@ void do_something() /* Call do_something_in_g() */ void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); - assert(component_g != nullptr); + EXPECT_NE(component_g, nullptr); auto *func_g = (void (*)())dlsym(component_g, "do_something_in_g"); - assert(func_g != nullptr); + EXPECT_NE(func_g, nullptr); (*func_g)(); @@ -47,10 +46,10 @@ void do_something() /* Call do_something_in_h() */ void *component_h = dlopen("libcomponent_h.so", RTLD_NOW); - assert(component_h != nullptr); + EXPECT_NE(component_h, nullptr); auto *func_h = (void (*)())dlsym(component_h, "do_something_in_h"); - assert(func_h != nullptr); + EXPECT_NE(func_h, nullptr); (*func_h)(); From 154c75620347afffe181ba2792838a2b7b172c40 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 1 Jun 2023 21:33:45 +0200 Subject: [PATCH 06/10] Work around for bazel --- api/test/singleton/BUILD | 28 ++++++++++++++++++++++------ api/test/singleton/singleton_test.cc | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index a14e4ef425..aeb7e9e0ff 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -117,8 +117,9 @@ cc_library( ], ) -cc_library( - name = "libcomponent_g.so", +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_g", srcs = [ "component_g.cc", ], @@ -126,14 +127,15 @@ cc_library( "//bazel:windows": DEFAULT_WIN_COPTS, "//conditions:default": DEFAULT_NOWIN_COPTS, }), - linkstatic = False, + linkshared = True, deps = [ "//api", ], ) -cc_library( - name = "libcomponent_h.so", +# no cc_shared_library in bazel 4.2 +cc_binary( + name = "component_h", srcs = [ "component_h.cc", ], @@ -141,13 +143,27 @@ cc_library( "//bazel:windows": HIDDEN_WIN_COPTS, "//conditions:default": HIDDEN_NOWIN_COPTS, }), - linkstatic = False, + linkshared = True, deps = [ "//api", ], ) +# +# To build this test alone: +# - bazel build //api/test/singleton:singleton_test +# - bazel build //api/test/singleton:component_g +# - bazel build //api/test/singleton:component_h +# +# Note that singleton_test does not depend on +# component_g and component_h, on purpose. +# +# To run this test: +# bazel test //api/test/singleton:singleton_test +# + cc_test( + copts = ["-DBUILD_WITH_BAZEL=1"], name = "singleton_test", srcs = [ "singleton_test.cc", diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index f02aa459fd..3882dd9182 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -31,6 +31,17 @@ void do_something() do_something_in_e(); do_something_in_f(); +/* + See https://github.com/bazelbuild/bazel/issues/4218 + + There is no way to set LD_LIBRARY_PATH in bazel, + for dlopen() to find the library. + + Verified manually that dlopen("/full/path/to/libcomponent_g.so") works, + and that the test passes in this case. +*/ + +#ifndef BUILD_WITH_BAZEL /* Call do_something_in_g() */ void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); @@ -54,6 +65,7 @@ void do_something() (*func_h)(); dlclose(component_h); +#endif } int span_a_lib_count = 0; @@ -327,12 +339,16 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_lib_count, 1); EXPECT_EQ(span_f_f1_count, 2); EXPECT_EQ(span_f_f2_count, 1); + +#ifndef BUILD_WITH_BAZEL EXPECT_EQ(span_g_lib_count, 1); EXPECT_EQ(span_g_f1_count, 2); EXPECT_EQ(span_g_f2_count, 1); EXPECT_EQ(span_h_lib_count, 1); EXPECT_EQ(span_h_f1_count, 2); EXPECT_EQ(span_h_f2_count, 1); +#endif + EXPECT_EQ(unknown_span_count, 0); reset_counts(); From 121060768cdfeae6e1c0e4b036e52b06a7a916c9 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 1 Jun 2023 21:40:57 +0200 Subject: [PATCH 07/10] Fixed format --- api/test/singleton/BUILD | 4 ++-- api/test/singleton/singleton_test.cc | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index aeb7e9e0ff..349296903a 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -163,15 +163,15 @@ cc_binary( # cc_test( - copts = ["-DBUILD_WITH_BAZEL=1"], name = "singleton_test", srcs = [ "singleton_test.cc", ], - linkstatic = False, + copts = ["-DBUILD_WITH_BAZEL=1"], linkopts = [ "-ldl", ], + linkstatic = False, tags = [ "api", "test", diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 3882dd9182..2efd3a6b01 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -31,15 +31,15 @@ void do_something() do_something_in_e(); do_something_in_f(); -/* - See https://github.com/bazelbuild/bazel/issues/4218 + /* + See https://github.com/bazelbuild/bazel/issues/4218 - There is no way to set LD_LIBRARY_PATH in bazel, - for dlopen() to find the library. + There is no way to set LD_LIBRARY_PATH in bazel, + for dlopen() to find the library. - Verified manually that dlopen("/full/path/to/libcomponent_g.so") works, - and that the test passes in this case. -*/ + Verified manually that dlopen("/full/path/to/libcomponent_g.so") works, + and that the test passes in this case. + */ #ifndef BUILD_WITH_BAZEL /* Call do_something_in_g() */ From 6342a7be721375c28e8452c69d8963b329697a27 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 5 Jun 2023 10:21:42 +0200 Subject: [PATCH 08/10] Work around, build break on windows. --- api/test/singleton/singleton_test.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 2efd3a6b01..59884f22fc 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -3,7 +3,15 @@ #include -#include +/* + TODO: + Once singleton are supported for windows, + expand this test to use ::LoadLibrary, ::GetProcAddress, ::FreeLibrary +*/ +#ifndef _WIN32 +# include +#endif + #include #include "component_a.h" From e0b11cf3f202e5517efd6517feba7b090d000f35 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Tue, 20 Jun 2023 09:19:07 +0200 Subject: [PATCH 09/10] Build cleanup --- api/test/singleton/BUILD | 2 +- api/test/singleton/singleton_test.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/test/singleton/BUILD b/api/test/singleton/BUILD index 349296903a..cdd1ed7cf4 100644 --- a/api/test/singleton/BUILD +++ b/api/test/singleton/BUILD @@ -167,7 +167,7 @@ cc_test( srcs = [ "singleton_test.cc", ], - copts = ["-DBUILD_WITH_BAZEL=1"], + defines = ["BAZEL_BUILD"], linkopts = [ "-ldl", ], diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 59884f22fc..44a445e5bd 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -49,7 +49,7 @@ void do_something() and that the test passes in this case. */ -#ifndef BUILD_WITH_BAZEL +#ifndef BAZEL_BUILD /* Call do_something_in_g() */ void *component_g = dlopen("libcomponent_g.so", RTLD_NOW); @@ -348,7 +348,7 @@ TEST(SingletonTest, Uniqueness) EXPECT_EQ(span_f_f1_count, 2); EXPECT_EQ(span_f_f2_count, 1); -#ifndef BUILD_WITH_BAZEL +#ifndef BAZEL_BUILD EXPECT_EQ(span_g_lib_count, 1); EXPECT_EQ(span_g_f1_count, 2); EXPECT_EQ(span_g_f2_count, 1); From cee851e7bb3042144dcc69fafb9e653efd6494e6 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 30 Jun 2023 17:00:42 +0200 Subject: [PATCH 10/10] Cleanup --- api/test/singleton/component_h.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/test/singleton/component_h.cc b/api/test/singleton/component_h.cc index 30223bb935..b486536fc2 100644 --- a/api/test/singleton/component_h.cc +++ b/api/test/singleton/component_h.cc @@ -30,13 +30,13 @@ static void f2() extern "C" #if defined(_MSC_VER) - // component_g is a DLL + // component_h is a DLL __declspec(dllexport) #else -// component_g is a shared library (*.so) -// component_g is compiled with visibility("hidden"), +// component_h is a shared library (*.so) +// component_h is compiled with visibility("hidden"), __attribute__((visibility("default"))) #endif