From 6b87300b5a354cf377f164eecd914e80171a69e6 Mon Sep 17 00:00:00 2001 From: WenTao Ou Date: Thu, 7 Apr 2022 23:56:44 +0800 Subject: [PATCH] Add building test without RTTI (#1294) --- .github/workflows/ci.yml | 22 +++ api/include/opentelemetry/common/macros.h | 16 +++ ci/README.md | 2 + ci/do_ci.sh | 12 +- examples/multi_processor/main.cc | 12 +- .../opentelemetry/exporters/etw/etw_logger.h | 2 +- .../opentelemetry/exporters/etw/etw_tracer.h | 4 +- .../opentelemetry/exporters/etw/utils.h | 17 +-- .../memory/in_memory_span_exporter.h | 2 +- .../opentelemetry/sdk/_metrics/controller.h | 6 + .../sdk/_metrics/sync_instruments.h | 14 ++ .../sdk/_metrics/ungrouped_processor.h | 56 ++++++++ sdk/src/_metrics/meter.cc | 14 +- sdk/test/_metrics/metric_instrument_test.cc | 126 ++++++++++-------- sdk/test/metrics/meter_provider_sdk_test.cc | 2 +- sdk/test/trace/tracer_provider_test.cc | 6 +- sdk/test/trace/tracer_test.cc | 4 +- 17 files changed, 226 insertions(+), 91 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b0af15acb..7030c719d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -216,6 +216,28 @@ jobs: - name: run tests run: ./ci/do_ci.sh bazel.noexcept + bazel_nortti: + name: Bazel nortti + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: Mount Bazel Cache + uses: actions/cache@v3 + env: + cache-name: bazel_cache + with: + path: /home/runner/.cache/bazel + key: bazel_nortti + - name: setup + run: | + sudo ./ci/setup_thrift.sh dependencies_only + sudo ./ci/setup_ci_environment.sh + sudo ./ci/install_bazelisk.sh + - name: run tests + run: ./ci/do_ci.sh bazel.nortti + bazel_asan: name: Bazel asan config runs-on: ubuntu-latest diff --git a/api/include/opentelemetry/common/macros.h b/api/include/opentelemetry/common/macros.h index 8c2b6bd175..982e368ce3 100644 --- a/api/include/opentelemetry/common/macros.h +++ b/api/include/opentelemetry/common/macros.h @@ -24,3 +24,19 @@ #else # define OPENTELEMETRY_MAYBE_UNUSED #endif + +#ifndef OPENTELEMETRY_RTTI_ENABLED +# if defined(__clang__) +# if __has_feature(cxx_rtti) +# define OPENTELEMETRY_RTTI_ENABLED +# endif +# elif defined(__GNUG__) +# if defined(__GXX_RTTI) +# define OPENTELEMETRY_RTTI_ENABLED +# endif +# elif defined(_MSC_VER) +# if defined(_CPPRTTI) +# define OPENTELEMETRY_RTTI_ENABLED +# endif +# endif +#endif diff --git a/ci/README.md b/ci/README.md index d315965962..14a6107eb8 100644 --- a/ci/README.md +++ b/ci/README.md @@ -12,6 +12,8 @@ CI tests can be run on docker by invoking the script `./ci/run_docker.sh * `bazel.legacy.test`: build bazel targets and run tests for the targets meant to work with older compilers. * `bazel.noexcept`: build bazel targets and run tests with exceptions disabled. +* `bazel.nortti`: build bazel targets and run tests with runtime type + identification disabled. * `bazel.asan`: build bazel targets and run tests with AddressSanitizer. * `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer. * `bazel.valgrind`: build bazel targets and run tests under the valgrind memory diff --git a/ci/do_ci.sh b/ci/do_ci.sh index f9fc8ed215..008e983842 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -59,7 +59,11 @@ mkdir -p "${BUILD_DIR}" [ -z "${PLUGIN_DIR}" ] && export PLUGIN_DIR=$HOME/plugin mkdir -p "${PLUGIN_DIR}" -BAZEL_OPTIONS="--copt=-DENABLE_METRICS_PREVIEW --copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST" +BAZEL_OPTIONS="--copt=-DENABLE_LOGS_PREVIEW --copt=-DENABLE_TEST" +# Previous legacy metrics use virtual drive, which can not be used without RTTI +if [[ "$1" != "bazel.nortti" ]]; then + BAZEL_OPTIONS="$BAZEL_OPTIONS --copt=-DENABLE_METRICS_PREVIEW" +fi BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors" # https://github.com/bazelbuild/bazel/issues/4341 @@ -221,6 +225,12 @@ elif [[ "$1" == "bazel.noexcept" ]]; then bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... exit 0 +elif [[ "$1" == "bazel.nortti" ]]; then + # there are some exceptions and error handling code from the Prometheus and Jaeger Clients + # that make this test always fail. ignore Prometheus and Jaeger exporters in the noexcept here. + bazel $BAZEL_STARTUP_OPTIONS build --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... + bazel $BAZEL_STARTUP_OPTIONS test --cxxopt=-fno-rtti --build_tag_filters=-jaeger $BAZEL_TEST_OPTIONS -- //... -//exporters/prometheus/... -//exporters/jaeger/... + exit 0 elif [[ "$1" == "bazel.asan" ]]; then bazel $BAZEL_STARTUP_OPTIONS test --config=asan $BAZEL_TEST_OPTIONS //... exit 0 diff --git a/examples/multi_processor/main.cc b/examples/multi_processor/main.cc index f57da5e228..2b722b6688 100644 --- a/examples/multi_processor/main.cc +++ b/examples/multi_processor/main.cc @@ -20,21 +20,19 @@ namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; namespace nostd = opentelemetry::nostd; -InMemorySpanExporter *memory_span_exporter; - namespace { -void initTracer() +InMemorySpanExporter *initTracer() { auto exporter1 = std::unique_ptr( new opentelemetry::exporter::trace::OStreamSpanExporter); auto processor1 = std::unique_ptr( new trace_sdk::SimpleSpanProcessor(std::move(exporter1))); - auto exporter2 = std::unique_ptr(new InMemorySpanExporter()); + InMemorySpanExporter *memory_span_exporter = new InMemorySpanExporter(); + auto exporter2 = std::unique_ptr(memory_span_exporter); // fetch the exporter for dumping data later - memory_span_exporter = dynamic_cast(exporter2.get()); auto processor2 = std::unique_ptr( new trace_sdk::SimpleSpanProcessor(std::move(exporter2))); @@ -44,6 +42,8 @@ void initTracer() provider->AddProcessor(std::move(processor2)); // Set the global trace provider trace_api::Provider::SetTracerProvider(std::move(provider)); + + return memory_span_exporter; } void dumpSpans(std::vector> &spans) @@ -81,7 +81,7 @@ void dumpSpans(std::vector> &spans) int main() { // Removing this line will leave the default noop TracerProvider in place. - initTracer(); + InMemorySpanExporter *memory_span_exporter = initTracer(); foo_library(); auto memory_spans = memory_span_exporter->GetData()->GetSpans(); diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h index 6f3a394b0d..84f6b6970f 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_logger.h @@ -110,7 +110,7 @@ class Logger : public opentelemetry::logs::Logger common::SystemTimestamp timestamp) noexcept override { -# ifdef RTTI_ENABLED +# ifdef OPENTELEMETRY_RTTI_ENABLED common::KeyValueIterable &attribs = const_cast(attributes); Properties *evt = dynamic_cast(&attribs); // Properties *res = dynamic_cast(&resr); diff --git a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h index a946e70a6f..65fe2770f2 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/etw_tracer.h @@ -377,7 +377,7 @@ class Tracer : public opentelemetry::trace::Tracer const opentelemetry::trace::SpanContextKeyValueIterable &links, const opentelemetry::trace::StartSpanOptions &options = {}) noexcept override { -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED common::KeyValueIterable &attribs = const_cast(attributes); Properties *evt = dynamic_cast(&attribs); if (evt != nullptr) @@ -531,7 +531,7 @@ class Tracer : public opentelemetry::trace::Tracer common::SystemTimestamp timestamp, const common::KeyValueIterable &attributes) noexcept { -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED common::KeyValueIterable &attribs = const_cast(attributes); Properties *evt = dynamic_cast(&attribs); if (evt != nullptr) diff --git a/exporters/etw/include/opentelemetry/exporters/etw/utils.h b/exporters/etw/include/opentelemetry/exporters/etw/utils.h index f1f2898954..8b0a015821 100644 --- a/exporters/etw/include/opentelemetry/exporters/etw/utils.h +++ b/exporters/etw/include/opentelemetry/exporters/etw/utils.h @@ -12,6 +12,7 @@ #include #include +#include "opentelemetry/common/macros.h" #include "opentelemetry/exporters/etw/uuid.h" #include "opentelemetry/version.h" @@ -25,22 +26,6 @@ # pragma comment(lib, "Ole32.Lib") #endif -#ifndef RTTI_ENABLED -# if defined(__clang__) -# if __has_feature(cxx_rtti) -# define RTTI_ENABLED -# endif -# elif defined(__GNUG__) -# if defined(__GXX_RTTI) -# define RTTI_ENABLED -# endif -# elif defined(_MSC_VER) -# if defined(_CPPRTTI) -# define RTTI_ENABLED -# endif -# endif -#endif - OPENTELEMETRY_BEGIN_NAMESPACE namespace utils diff --git a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h index 3e47ccb177..28b7bc34e8 100644 --- a/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h +++ b/exporters/memory/include/opentelemetry/exporters/memory/in_memory_span_exporter.h @@ -54,7 +54,7 @@ class InMemorySpanExporter final : public opentelemetry::sdk::trace::SpanExporte for (auto &recordable : recordables) { auto span = std::unique_ptr( - dynamic_cast(recordable.release())); + static_cast(recordable.release())); if (span != nullptr) { data_->Add(std::move(span)); diff --git a/sdk/include/opentelemetry/sdk/_metrics/controller.h b/sdk/include/opentelemetry/sdk/_metrics/controller.h index 9d80787bcd..66a57a2efa 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/controller.h +++ b/sdk/include/opentelemetry/sdk/_metrics/controller.h @@ -9,7 +9,9 @@ # include # include # include + # include "opentelemetry/_metrics/instrument.h" +# include "opentelemetry/common/macros.h" # include "opentelemetry/nostd/unique_ptr.h" # include "opentelemetry/sdk/_metrics/exporter.h" # include "opentelemetry/sdk/_metrics/meter.h" @@ -120,7 +122,11 @@ class PushController void tick() { this->mu_.lock(); +# ifdef OPENTELEMETRY_RTTI_ENABLED std::vector collected = dynamic_cast(meter_.get())->Collect(); +# else + std::vector collected = static_cast(meter_.get())->Collect(); +# endif for (const auto &rec : collected) { processor_->process(rec); diff --git a/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h b/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h index 46274571af..80d9b6092d 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h +++ b/sdk/include/opentelemetry/sdk/_metrics/sync_instruments.h @@ -9,7 +9,9 @@ # include # include # include + # include "opentelemetry/_metrics/sync_instruments.h" +# include "opentelemetry/common/macros.h" # include "opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h" # include "opentelemetry/sdk/_metrics/aggregator/min_max_sum_count_aggregator.h" # include "opentelemetry/sdk/_metrics/instrument.h" @@ -156,7 +158,11 @@ class Counter final : public SynchronousInstrument, public opentelemetry::met { toDelete.push_back(x.first); } +# ifdef OPENTELEMETRY_RTTI_ENABLED auto agg_ptr = dynamic_cast *>(x.second.get())->GetAggregator(); +# else + auto agg_ptr = static_cast *>(x.second.get())->GetAggregator(); +# endif if (agg_ptr->is_updated()) { agg_ptr->checkpoint(); @@ -287,7 +293,11 @@ class UpDownCounter final : public SynchronousInstrument, { toDelete.push_back(x.first); } +# ifdef OPENTELEMETRY_RTTI_ENABLED auto agg_ptr = dynamic_cast *>(x.second.get())->GetAggregator(); +# else + auto agg_ptr = static_cast *>(x.second.get())->GetAggregator(); +# endif if (agg_ptr->is_updated()) { agg_ptr->checkpoint(); @@ -417,7 +427,11 @@ class ValueRecorder final : public SynchronousInstrument, { toDelete.push_back(x.first); } +# ifdef OPENTELEMETRY_RTTI_ENABLED auto agg_ptr = dynamic_cast *>(x.second.get())->GetAggregator(); +# else + auto agg_ptr = static_cast *>(x.second.get())->GetAggregator(); +# endif if (agg_ptr->is_updated()) { agg_ptr->checkpoint(); diff --git a/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h b/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h index 5894144c7f..cc13ae52b6 100644 --- a/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h +++ b/sdk/include/opentelemetry/sdk/_metrics/ungrouped_processor.h @@ -5,6 +5,8 @@ #ifdef ENABLE_METRICS_PREVIEW # include + +# include "opentelemetry/common/macros.h" # include "opentelemetry/sdk/_metrics/aggregator/counter_aggregator.h" # include "opentelemetry/sdk/_metrics/aggregator/exact_aggregator.h" # include "opentelemetry/sdk/_metrics/aggregator/gauge_aggregator.h" @@ -216,12 +218,19 @@ class UngroupedMetricsProcessor : public MetricsProcessor auto agg_kind = batch_agg->get_aggregator_kind(); if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Counter) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_counter = std::dynamic_pointer_cast>(batch_agg); std::shared_ptr> temp_record_agg_counter = std::dynamic_pointer_cast>(record_agg); +# else + std::shared_ptr> temp_batch_agg_counter = + std::static_pointer_cast>(batch_agg); + std::shared_ptr> temp_record_agg_counter = + std::static_pointer_cast>(record_agg); +# endif auto temp_batch_agg_raw_counter = temp_batch_agg_counter.get(); auto temp_record_agg_raw_counter = temp_record_agg_counter.get(); @@ -229,6 +238,7 @@ class UngroupedMetricsProcessor : public MetricsProcessor } else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::MinMaxSumCount) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_mmsc = std::dynamic_pointer_cast>( @@ -238,6 +248,17 @@ class UngroupedMetricsProcessor : public MetricsProcessor temp_record_agg_mmsc = std::dynamic_pointer_cast>( record_agg); +# else + std::shared_ptr> + temp_batch_agg_mmsc = + std::static_pointer_cast>( + batch_agg); + + std::shared_ptr> + temp_record_agg_mmsc = + std::static_pointer_cast>( + record_agg); +# endif auto temp_batch_agg_raw_mmsc = temp_batch_agg_mmsc.get(); auto temp_record_agg_raw_mmsc = temp_record_agg_mmsc.get(); @@ -246,11 +267,19 @@ class UngroupedMetricsProcessor : public MetricsProcessor } else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Gauge) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_gauge = std::dynamic_pointer_cast>(batch_agg); std::shared_ptr> temp_record_agg_gauge = std::dynamic_pointer_cast>(record_agg); +# else + std::shared_ptr> temp_batch_agg_gauge = + std::static_pointer_cast>(batch_agg); + + std::shared_ptr> temp_record_agg_gauge = + std::static_pointer_cast>(record_agg); +# endif auto temp_batch_agg_raw_gauge = temp_batch_agg_gauge.get(); auto temp_record_agg_raw_gauge = temp_record_agg_gauge.get(); @@ -259,12 +288,19 @@ class UngroupedMetricsProcessor : public MetricsProcessor } else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Sketch) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_sketch = std::dynamic_pointer_cast>(batch_agg); std::shared_ptr> temp_record_agg_sketch = std::dynamic_pointer_cast>(record_agg); +# else + std::shared_ptr> temp_batch_agg_sketch = + std::static_pointer_cast>(batch_agg); + std::shared_ptr> temp_record_agg_sketch = + std::static_pointer_cast>(record_agg); +# endif auto temp_batch_agg_raw_sketch = temp_batch_agg_sketch.get(); auto temp_record_agg_raw_sketch = temp_record_agg_sketch.get(); @@ -272,6 +308,7 @@ class UngroupedMetricsProcessor : public MetricsProcessor } else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Histogram) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_histogram = std::dynamic_pointer_cast>( @@ -281,6 +318,17 @@ class UngroupedMetricsProcessor : public MetricsProcessor temp_record_agg_histogram = std::dynamic_pointer_cast>( record_agg); +# else + std::shared_ptr> + temp_batch_agg_histogram = + std::static_pointer_cast>( + batch_agg); + + std::shared_ptr> + temp_record_agg_histogram = + std::static_pointer_cast>( + record_agg); +# endif auto temp_batch_agg_raw_histogram = temp_batch_agg_histogram.get(); auto temp_record_agg_raw_histogram = temp_record_agg_histogram.get(); @@ -289,11 +337,19 @@ class UngroupedMetricsProcessor : public MetricsProcessor } else if (agg_kind == opentelemetry::sdk::metrics::AggregatorKind::Exact) { +# ifdef OPENTELEMETRY_RTTI_ENABLED std::shared_ptr> temp_batch_agg_exact = std::dynamic_pointer_cast>(batch_agg); std::shared_ptr> temp_record_agg_exact = std::dynamic_pointer_cast>(record_agg); +# else + std::shared_ptr> temp_batch_agg_exact = + std::static_pointer_cast>(batch_agg); + + std::shared_ptr> temp_record_agg_exact = + std::static_pointer_cast>(record_agg); +# endif auto temp_batch_agg_raw_exact = temp_batch_agg_exact.get(); auto temp_record_agg_raw_exact = temp_record_agg_exact.get(); diff --git a/sdk/src/_metrics/meter.cc b/sdk/src/_metrics/meter.cc index 5207865b9c..f48eccfbd6 100644 --- a/sdk/src/_metrics/meter.cc +++ b/sdk/src/_metrics/meter.cc @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_METRICS_PREVIEW + # include "opentelemetry/sdk/_metrics/meter.h" +# include "opentelemetry/common/macros.h" namespace metrics_api = opentelemetry::metrics; @@ -664,7 +666,11 @@ void Meter::CollectSingleSyncInstrument( i++; return; } - auto cast_ptr = std::dynamic_pointer_cast>(i->second); +# ifdef OPENTELEMETRY_RTTI_ENABLED + auto cast_ptr = std::dynamic_pointer_cast>(i->second); +# else + auto cast_ptr = std::static_pointer_cast>(i->second); +# endif std::vector new_records = cast_ptr->GetRecords(); records.insert(records.begin(), new_records.begin(), new_records.end()); } @@ -734,7 +740,11 @@ void Meter::CollectSingleAsyncInstrument( i++; return; } - auto cast_ptr = std::dynamic_pointer_cast>(i->second); +# ifdef OPENTELEMETRY_RTTI_ENABLED + auto cast_ptr = std::dynamic_pointer_cast>(i->second); +# else + auto cast_ptr = std::static_pointer_cast>(i->second); +# endif std::vector new_records = cast_ptr->GetRecords(); records.insert(records.begin(), new_records.begin(), new_records.end()); } diff --git a/sdk/test/_metrics/metric_instrument_test.cc b/sdk/test/_metrics/metric_instrument_test.cc index 089baf1211..28df53fc32 100644 --- a/sdk/test/_metrics/metric_instrument_test.cc +++ b/sdk/test/_metrics/metric_instrument_test.cc @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #ifdef ENABLE_METRICS_PREVIEW + # include # include # include @@ -9,11 +10,19 @@ # include # include # include + +# include "opentelemetry/common/macros.h" # include "opentelemetry/sdk/_metrics/async_instruments.h" # include "opentelemetry/sdk/_metrics/sync_instruments.h" namespace metrics_api = opentelemetry::metrics; +# ifdef OPENTELEMETRY_RTTI_ENABLED +# define METRICS_TEST_TYPE_CAST(TO, FROM) dynamic_cast(FROM) +# else +# define METRICS_TEST_TYPE_CAST(TO, FROM) static_cast(FROM) +# endif + OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { @@ -37,12 +46,15 @@ TEST(ApiSdkConversion, async) auto labelkv = common::KeyValueIterableView{labels}; alpha->observe(123456, labelkv); - EXPECT_EQ(dynamic_cast *>(alpha.get())->GetRecords()[0].GetLabels(), + EXPECT_EQ(METRICS_TEST_TYPE_CAST(AsynchronousInstrument *, alpha.get()) + ->GetRecords()[0] + .GetLabels(), "{key587:value264}"); alpha->observe(123456, labelkv); - AggregatorVariant canCollect = - dynamic_cast *>(alpha.get())->GetRecords()[0].GetAggregator(); + AggregatorVariant canCollect = METRICS_TEST_TYPE_CAST(AsynchronousInstrument *, alpha.get()) + ->GetRecords()[0] + .GetAggregator(); EXPECT_EQ(nostd::holds_alternative>>(canCollect), false); EXPECT_EQ(nostd::holds_alternative>>(canCollect), true); EXPECT_EQ(nostd::get>>(canCollect)->get_checkpoint()[0], 123456); @@ -292,11 +304,13 @@ TEST(Counter, StressAdd) second.join(); third.join(); - EXPECT_EQ(dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundCounter *, + alpha->boundInstruments_[KvToString(labelkv)].get()) ->GetAggregator() ->get_values()[0], 2000); - EXPECT_EQ(dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundCounter *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) ->GetAggregator() ->get_values()[0], 3000); @@ -343,16 +357,16 @@ TEST(IntUpDownCounter, StressAdd) third.join(); fourth.join(); - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) - ->GetAggregator() - ->get_values()[0], - 12340 * 2); - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) - ->GetAggregator() - ->get_values()[0], - 56780 - 12340); + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundUpDownCounter *, + alpha->boundInstruments_[KvToString(labelkv)].get()) + ->GetAggregator() + ->get_values()[0], + 12340 * 2); + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundUpDownCounter *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) + ->GetAggregator() + ->get_values()[0], + 56780 - 12340); } void RecorderCallback(std::shared_ptr> in, @@ -396,47 +410,47 @@ TEST(IntValueRecorder, StressRecord) third.join(); fourth.join(); - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) - ->GetAggregator() - ->get_values()[0], - 0); // min - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) - ->GetAggregator() - ->get_values()[1], - 49); // max - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) - ->GetAggregator() - ->get_values()[2], - 1525); // sum - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv)].get()) - ->GetAggregator() - ->get_values()[3], - 75); // count - - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) - ->GetAggregator() - ->get_values()[0], - -99); // min - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) - ->GetAggregator() - ->get_values()[1], - 24); // max - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) - ->GetAggregator() - ->get_values()[2], - -4650); // sum - EXPECT_EQ( - dynamic_cast *>(alpha->boundInstruments_[KvToString(labelkv1)].get()) - ->GetAggregator() - ->get_values()[3], - 125); // count + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv)].get()) + ->GetAggregator() + ->get_values()[0], + 0); // min + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv)].get()) + ->GetAggregator() + ->get_values()[1], + 49); // max + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv)].get()) + ->GetAggregator() + ->get_values()[2], + 1525); // sum + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv)].get()) + ->GetAggregator() + ->get_values()[3], + 75); // count + + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) + ->GetAggregator() + ->get_values()[0], + -99); // min + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) + ->GetAggregator() + ->get_values()[1], + 24); // max + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) + ->GetAggregator() + ->get_values()[2], + -4650); // sum + EXPECT_EQ(METRICS_TEST_TYPE_CAST(BoundValueRecorder *, + alpha->boundInstruments_[KvToString(labelkv1)].get()) + ->GetAggregator() + ->get_values()[3], + 125); // count } TEST(Instruments, NoUpdateNoRecord) diff --git a/sdk/test/metrics/meter_provider_sdk_test.cc b/sdk/test/metrics/meter_provider_sdk_test.cc index 3c059cc44c..4a2792c3a7 100644 --- a/sdk/test/metrics/meter_provider_sdk_test.cc +++ b/sdk/test/metrics/meter_provider_sdk_test.cc @@ -68,7 +68,7 @@ TEST(MeterProvider, GetMeter) ASSERT_NE(m3, m6); // Should be an sdk::trace::Tracer with the processor attached. -# ifdef RTTI_ENABLED +# ifdef OPENTELEMETRY_RTTI_ENABLED auto sdkMeter1 = dynamic_cast(m1.get()); # else auto sdkMeter1 = static_cast(m1.get()); diff --git a/sdk/test/trace/tracer_provider_test.cc b/sdk/test/trace/tracer_provider_test.cc index d72d6bd40f..498f66127d 100644 --- a/sdk/test/trace/tracer_provider_test.cc +++ b/sdk/test/trace/tracer_provider_test.cc @@ -39,7 +39,7 @@ TEST(TracerProvider, GetTracer) ASSERT_NE(t3, t6); // Should be an sdk::trace::Tracer with the processor attached. -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED auto sdkTracer1 = dynamic_cast(t1.get()); #else auto sdkTracer1 = static_cast(t1.get()); @@ -53,7 +53,7 @@ TEST(TracerProvider, GetTracer) std::make_shared(std::move(processors2), Resource::Create({}), std::unique_ptr(new AlwaysOffSampler()), std::unique_ptr(new RandomIdGenerator))); -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED auto sdkTracer2 = dynamic_cast(tp2.GetTracer("test").get()); #else auto sdkTracer2 = static_cast(tp2.GetTracer("test").get()); @@ -65,7 +65,7 @@ TEST(TracerProvider, GetTracer) ASSERT_EQ(instrumentation_library1.GetVersion(), ""); // Should be an sdk::trace::Tracer with the processor attached. -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED auto sdkTracer3 = dynamic_cast(t3.get()); #else auto sdkTracer3 = static_cast(t3.get()); diff --git a/sdk/test/trace/tracer_test.cc b/sdk/test/trace/tracer_test.cc index dc806b079f..15a7566b9b 100644 --- a/sdk/test/trace/tracer_test.cc +++ b/sdk/test/trace/tracer_test.cc @@ -347,7 +347,7 @@ TEST(Tracer, GetSampler) // Create a Tracer with a default AlwaysOnSampler auto tracer_on = initTracer(nullptr); -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED auto &t1 = std::dynamic_pointer_cast(tracer_on)->GetSampler(); #else auto &t1 = std::static_pointer_cast(tracer_on)->GetSampler(); @@ -357,7 +357,7 @@ TEST(Tracer, GetSampler) // Create a Tracer with a AlwaysOffSampler auto tracer_off = initTracer(nullptr, new AlwaysOffSampler()); -#ifdef RTTI_ENABLED +#ifdef OPENTELEMETRY_RTTI_ENABLED auto &t2 = std::dynamic_pointer_cast(tracer_off)->GetSampler(); #else auto &t2 = std::static_pointer_cast(tracer_off)->GetSampler();