-
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.
The conversion of hex to binary did not handle odd-length inputs correctly. The output was zero-padded on the right rather than the left. On little endian machines, the second to last entry received the 0.
- 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]); | ||
} | ||
} |