-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Propagation: fix for hex conversion to binary for odd hex strin…
…gs (#2533)
- Loading branch information
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") | ||
|
||
cc_test( | ||
name = "hex_test", | ||
srcs = [ | ||
"hex_test.cc", | ||
], | ||
tags = [ | ||
"api", | ||
"test", | ||
"trace", | ||
], | ||
deps = [ | ||
"//api", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
foreach(testname hex_test) | ||
add_executable(${testname} "${testname}.cc") | ||
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES} | ||
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api) | ||
gtest_add_tests( | ||
TARGET ${testname} | ||
TEST_PREFIX trace. | ||
TEST_LIST ${testname}) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "opentelemetry/trace/propagation/detail/hex.h" | ||
|
||
#include <map> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace opentelemetry; | ||
|
||
TEST(HexTest, ConvertOddLength) | ||
{ | ||
const int kLength = 16; | ||
std::string trace_id_hex = "78cfcfec62ae9e9"; | ||
uint8_t trace_id[kLength]; | ||
trace::propagation::detail::HexToBinary(trace_id_hex, trace_id, sizeof(trace_id)); | ||
|
||
const uint8_t expected_trace_id[kLength] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x7, 0x8c, 0xfc, 0xfe, 0xc6, 0x2a, 0xe9, 0xe9}; | ||
|
||
for (int i = 0; i < kLength; ++i) | ||
{ | ||
EXPECT_EQ(trace_id[i], expected_trace_id[i]); | ||
} | ||
} | ||
|
||
TEST(HexTest, ConvertEvenLength) | ||
{ | ||
const int kLength = 16; | ||
std::string trace_id_hex = "078cfcfec62ae9e9"; | ||
uint8_t trace_id[kLength]; | ||
trace::propagation::detail::HexToBinary(trace_id_hex, trace_id, sizeof(trace_id)); | ||
|
||
const uint8_t expected_trace_id[kLength] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, | ||
0x7, 0x8c, 0xfc, 0xfe, 0xc6, 0x2a, 0xe9, 0xe9}; | ||
|
||
for (int i = 0; i < kLength; ++i) | ||
{ | ||
EXPECT_EQ(trace_id[i], expected_trace_id[i]); | ||
} | ||
} |
c7a88c4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
2
.BM_BaselineBuffer/2
7307143.211364746
ns/iter2995665.244385096
ns/iter2.44
BM_BaselineBuffer/4
8328287.601470947
ns/iter2513576.860297216
ns/iter3.31
BM_LockFreeBuffer/2
3124939.441680908
ns/iter975008.3350298698
ns/iter3.21
BM_LockFreeBuffer/4
10638144.01626587
ns/iter1110630.0977320452
ns/iter9.58
This comment was automatically generated by workflow using github-action-benchmark.