Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit b825a09

Browse files
author
Isaac Hier
committed
Improve test case, build static lib
1 parent 391231f commit b825a09

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

CMakeLists.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,24 @@ set(srcs
4848
"src/opentracing-c/tracer.c"
4949
"src/opentracing-c/tracer.h"
5050
"src/opentracing-c/value.h")
51+
52+
add_library(opentracingc-static STATIC ${srcs})
53+
set_target_properties(opentracingc-static PROPERTIES OUTPUT_NAME opentracingc)
54+
5155
add_library(opentracingc SHARED ${srcs})
52-
target_include_directories(opentracingc PUBLIC
53-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
54-
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
55-
$<INSTALL_INTERFACE:include>)
56-
target_compile_options(opentracingc PUBLIC ${flags} ${coverage_flags})
56+
57+
foreach(lib opentracingc opentracingc-static)
58+
target_include_directories(${lib} PUBLIC
59+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
60+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
61+
$<INSTALL_INTERFACE:include>)
62+
target_compile_options(${lib} PUBLIC ${flags})
63+
endforeach()
5764

5865
if(BUILD_TESTING)
66+
target_compile_options(opentracingc-static PUBLIC ${coverage_flags})
5967
add_executable(tracer_test "test/tracer_test.c")
60-
target_link_libraries(tracer_test PUBLIC opentracingc)
68+
target_link_libraries(tracer_test PUBLIC opentracingc-static)
6169
add_test(tracer_test tracer_test)
6270
if(OPENTRACINGC_COVERAGE)
6371
setup_target_for_coverage(NAME tracer_test_coverage EXECUTABLE tracer_test)

cmake/toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
set(CMAKE_C_STANDARD_REQUIRED ON)
22
set(CMAKE_C_STANDARD 90)
3-
set(CMAKE_C_EXTENSIONS ON)
3+
set(CMAKE_C_EXTENSIONS OFF)

src/opentracing-c/tracer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,13 @@ opentracing_tracer* opentracing_global_tracer(void)
205205
return global_tracer;
206206
}
207207

208-
void opentracing_set_global_tracer(opentracing_tracer* tracer)
208+
void opentracing_init_global_tracer(opentracing_tracer* tracer)
209209
{
210210
assert(tracer != NULL);
211211
assert(global_tracer != NULL);
212+
if (global_tracer == tracer) {
213+
return;
214+
}
212215
((opentracing_destructible*) global_tracer)
213216
->destroy((opentracing_destructible*) global_tracer);
214217
global_tracer = tracer;

test/tracer_test.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
#include <assert.h>
22
#include <opentracing-c/tracer.h>
3+
#include <string.h>
34

45
int main()
56
{
6-
opentracing_tracer* tracer = opentracing_global_tracer();
7-
opentracing_span* span = tracer->start_span(tracer, "a");
7+
opentracing_tracer* tracer;
8+
opentracing_span* span;
9+
opentracing_span_context* span_context;
10+
int return_code;
11+
opentracing_value value;
12+
tracer = opentracing_global_tracer();
13+
span = tracer->start_span(tracer, "a");
814
assert(span != NULL);
915
assert(span->span_context(span) != NULL);
1016
assert(span->tracer(span) == tracer);
17+
value = (opentracing_value){opentracing_value_bool, {opentracing_true}};
18+
assert(span->set_operation_name(span, "b"));
19+
assert(span->set_tag(span, "test", &value));
20+
assert(span->log_fields(span, NULL, 0));
21+
assert(span->set_baggage_item(span, "key", "value"));
22+
assert(strlen(span->baggage_item(span, "key")) == 0);
23+
1124
span->finish(span);
1225
((opentracing_destructible*) span)
1326
->destroy((opentracing_destructible*) span);
27+
28+
return_code = tracer->extract(
29+
tracer, opentracing_propagation_format_binary, NULL, &span_context);
30+
assert(return_code == 0);
31+
assert(span_context != NULL);
32+
return_code = tracer->inject(
33+
tracer, opentracing_propagation_format_text_map, NULL, span_context);
34+
((opentracing_destructible*) span_context)
35+
->destroy((opentracing_destructible*) span_context);
36+
37+
opentracing_init_global_tracer(opentracing_global_tracer());
1438
return 0;
1539
}

0 commit comments

Comments
 (0)