Skip to content

Commit ef45764

Browse files
update
1 parent 8b4fde5 commit ef45764

File tree

9 files changed

+75
-60
lines changed

9 files changed

+75
-60
lines changed

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@ else ()
2626
file(GLOB format_files
2727
${CMAKE_SOURCE_DIR}/cy/*.[ch]
2828
${CMAKE_SOURCE_DIR}/examples/*.[ch]
29-
${CMAKE_SOURCE_DIR}/tests/*.[ch]pp
29+
${CMAKE_SOURCE_DIR}/tests/*/*.[ch]
30+
${CMAKE_SOURCE_DIR}/tests/*/*.[ch]pp
3031
)
3132
message(STATUS "Using clang-format: ${clang_format}; files: ${format_files}")
3233
add_custom_target(format COMMAND ${clang_format} -i -fallback-style=none -style=file --verbose ${format_files})
3334
endif ()
3435

3536
# Build options
36-
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
37-
set(c_cxx_flags "\
38-
-Wall -Wextra -pedantic -fstrict-aliasing -Wundef -Wconversion -Wsign-conversion -Wmissing-declarations -Wtype-limits \
39-
")
4037
# C
4138
set(CMAKE_C_STANDARD 11)
4239
set(CMAKE_C_STANDARD_REQUIRED ON)
4340
set(CMAKE_C_EXTENSIONS OFF)
44-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${c_cxx_flags}")
41+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -fstrict-aliasing -Wundef -Wconversion")
42+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-declarations")
4543
# C++
4644
set(CMAKE_CXX_STANDARD 20)
4745
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4846
set(CMAKE_CXX_EXTENSIONS OFF)
49-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${c_cxx_flags} -Wsign-promo -Wzero-as-null-pointer-constant")
47+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -fstrict-aliasing -Wundef -Wconversion")
48+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion -Wmissing-declarations")
49+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-promo -Wzero-as-null-pointer-constant")
5050

5151
include_directories(${CMAKE_SOURCE_DIR}/lib)
5252

cy/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ cmake_minimum_required(VERSION 3.24)
44
project(cy C)
55
add_library(cy STATIC ${CMAKE_CURRENT_SOURCE_DIR}/cy.c)
66
target_include_directories(cy SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
7+
set_target_properties(cy PROPERTIES COMPILE_WARNING_AS_ERROR ON)

cy/cy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@
8888
#include <assert.h>
8989
#include <string.h>
9090

91+
// TODO FIXME REMOVE WHEN REFACTORING DONE
92+
#pragma GCC diagnostic ignored "-Wunused-function"
93+
9194
#if __STDC_VERSION__ < 201112L
9295
#define static_assert(x, ...) typedef char _static_assert_gl(_static_assertion_, __LINE__)[(x) ? 1 : -1]
9396
#define _static_assert_gl(a, b) _static_assert_gl_impl(a, b)

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ function(cy_gen_test name compile_flags link_flags c_standard)
3030
C_STANDARD ${c_standard}
3131
C_STANDARD_REQUIRED ON
3232
C_EXTENSIONS OFF
33+
COMPILE_WARNING_AS_ERROR OFF
34+
C_CLANG_TIDY ""
35+
CXX_CLANG_TIDY ""
3336
)
3437

3538
add_executable(${name} ${ARGN} src/helpers.c platform_stubs/message.c)
@@ -52,6 +55,9 @@ function(cy_gen_test name compile_flags link_flags c_standard)
5255
CXX_STANDARD 20
5356
CXX_STANDARD_REQUIRED ON
5457
CXX_EXTENSIONS OFF
58+
COMPILE_WARNING_AS_ERROR ON
59+
C_CLANG_TIDY ""
60+
CXX_CLANG_TIDY ""
5561
)
5662
set_property(GLOBAL APPEND PROPERTY CY_TEST_EXECUTABLE_TARGETS ${name})
5763
add_test(NAME "run_${name}" COMMAND ${name})

tests/platform_stubs/message.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
typedef struct
77
{
8-
cy_message_t base;
9-
size_t skip_offset;
10-
size_t payload_size;
8+
cy_message_t base;
9+
size_t skip_offset;
10+
size_t payload_size;
1111
unsigned char payload[];
1212
} test_message_t;
1313

@@ -24,7 +24,10 @@ static void test_message_skip(cy_message_t* const msg, const size_t offset)
2424
self->skip_offset += smaller(offset, available);
2525
}
2626

27-
static size_t test_message_read(const cy_message_t* const msg, const size_t offset, const size_t size, void* const output)
27+
static size_t test_message_read(const cy_message_t* const msg,
28+
const size_t offset,
29+
const size_t size,
30+
void* const output)
2831
{
2932
const test_message_t* const self = (const test_message_t*)msg;
3033
if ((output == NULL) || (self->skip_offset > self->payload_size)) {
@@ -57,9 +60,9 @@ static void test_message_destroy(cy_message_t* const msg)
5760
assert(g_live_count > 0U);
5861
g_live_count--;
5962
g_destroy_count++;
60-
self->base.vtable = NULL;
63+
self->base.vtable = NULL;
6164
self->base.refcount = 0;
62-
self->skip_offset = self->payload_size;
65+
self->skip_offset = self->payload_size;
6366
free(self);
6467
}
6568

@@ -80,9 +83,9 @@ cy_message_t* cy_test_message_make(const void* const data, const size_t size)
8083
return NULL;
8184
}
8285
self->base.refcount = 1U;
83-
self->base.vtable = &g_vtable;
84-
self->skip_offset = 0U;
85-
self->payload_size = size;
86+
self->base.vtable = &g_vtable;
87+
self->skip_offset = 0U;
88+
self->payload_size = size;
8689
if (size > 0U) {
8790
memcpy(self->payload, data, size);
8891
}

tests/src/helpers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ uint64_t cy_test_deserialize_u64(const unsigned char in[8])
3333
return out;
3434
}
3535

36-
void cy_test_make_message_header(unsigned char out[16], const uint8_t type, const uint64_t tag56, const uint64_t topic_hash)
36+
void cy_test_make_message_header(unsigned char out[16],
37+
const uint8_t type,
38+
const uint64_t tag56,
39+
const uint64_t topic_hash)
3740
{
3841
out[0] = (unsigned char)(type & 31U);
3942
cy_test_serialize_u56(&out[1], tag56);

tests/src/test_api_rx.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,32 @@
88
#include <cstdlib>
99
#include <cstring>
1010

11-
namespace
12-
{
11+
namespace {
1312
constexpr std::uint8_t HeaderMsgBestEffort = 0U;
1413
constexpr std::uint8_t HeaderMsgReliable = 1U;
1514
constexpr std::uint8_t HeaderMsgAck = 2U;
1615

1716
struct arrival_capture_t
1817
{
19-
std::size_t count{0};
20-
std::array<std::uint64_t, 16> tags{};
21-
std::array<unsigned char, 16> first_payload_byte{};
18+
std::size_t count{ 0 };
19+
std::array<std::uint64_t, 16> tags{};
20+
std::array<unsigned char, 16> first_payload_byte{};
2221
};
2322

2423
struct test_platform_t
2524
{
2625
cy_t cy{};
2726
cy_vtable_t vtable{};
2827

29-
cy_us_t now{0};
30-
std::uint64_t random_state{1U};
28+
cy_us_t now{ 0 };
29+
std::uint64_t random_state{ 1U };
3130

32-
std::size_t p2p_count{0};
31+
std::size_t p2p_count{ 0 };
3332
std::array<unsigned char, 16> last_p2p{};
34-
std::size_t p2p_extent{0};
33+
std::size_t p2p_extent{ 0 };
3534

36-
std::size_t subscription_error_count{0};
37-
cy_err_t last_subscription_error{CY_OK};
35+
std::size_t subscription_error_count{ 0 };
36+
cy_err_t last_subscription_error{ CY_OK };
3837
};
3938

4039
static test_platform_t* platform_from(cy_t* const cy) { return reinterpret_cast<test_platform_t*>(cy); }
@@ -94,7 +93,7 @@ extern "C" void platform_topic_destroy(cy_topic_t* const topic) { std::free(topi
9493

9594
extern "C" void platform_p2p_extent(cy_t* const cy, const size_t extent) { platform_from(cy)->p2p_extent = extent; }
9695

97-
extern "C" cy_err_t platform_p2p(cy_t* const cy,
96+
extern "C" cy_err_t platform_p2p(cy_t* const cy,
9897
const cy_p2p_context_t* const p2p_context,
9998
const cy_us_t deadline,
10099
const std::uint64_t remote_id,
@@ -112,8 +111,8 @@ extern "C" cy_err_t platform_p2p(cy_t* const cy,
112111
if ((frag->size == 0U) || (frag->data == nullptr)) {
113112
continue;
114113
}
115-
const std::size_t to_copy = (self->last_p2p.size() - copied < frag->size) ? (self->last_p2p.size() - copied)
116-
: frag->size;
114+
const std::size_t to_copy =
115+
(self->last_p2p.size() - copied < frag->size) ? (self->last_p2p.size() - copied) : frag->size;
117116
std::memcpy(&self->last_p2p[copied], frag->data, to_copy);
118117
copied += to_copy;
119118
}
@@ -145,7 +144,7 @@ extern "C" void on_arrival_capture(cy_subscriber_t* const sub, const cy_arrival_
145144

146145
static void platform_init(test_platform_t* const self)
147146
{
148-
*self = test_platform_t{};
147+
*self = test_platform_t{};
149148
self->vtable.now = platform_now;
150149
self->vtable.realloc = platform_realloc;
151150
self->vtable.random = platform_random;
@@ -172,7 +171,7 @@ static void dispatch_message(test_platform_t* const self,
172171
{
173172
std::array<unsigned char, 17> wire{};
174173
cy_test_make_message_header(wire.data(), type, tag, cy_topic_hash(topic));
175-
wire[16] = payload_byte;
174+
wire[16] = payload_byte;
176175
cy_message_t* const msg = cy_test_message_make(wire.data(), wire.size());
177176
TEST_ASSERT_NOT_NULL(msg);
178177

@@ -192,9 +191,9 @@ static void test_api_malformed_header_drops_message(void)
192191
std::array<unsigned char, 3> wire = { 0x01U, 0x02U, 0x03U };
193192
cy_message_t* const msg = cy_test_message_make(wire.data(), wire.size());
194193
TEST_ASSERT_NOT_NULL(msg);
195-
cy_message_ts_t mts;
196-
mts.timestamp = 10;
197-
mts.content = msg;
194+
cy_message_ts_t mts;
195+
mts.timestamp = 10;
196+
mts.content = msg;
198197
const cy_p2p_context_t p2p = { { 0 } };
199198

200199
cy_on_message(&platform.cy, p2p, 0U, 1234U, mts);
@@ -209,7 +208,7 @@ static void test_api_reliable_duplicate_acked_once_to_application(void)
209208
platform_init(&platform);
210209
cy_test_message_reset_counters();
211210

212-
arrival_capture_t capture{};
211+
arrival_capture_t capture{};
213212
cy_subscriber_t* const sub = cy_subscribe(&platform.cy, wkv_key("rx/dup"), 256U);
214213
TEST_ASSERT_NOT_NULL(sub);
215214

@@ -237,7 +236,7 @@ static void test_api_ordered_subscriber_timeout_flush(void)
237236
platform_init(&platform);
238237
cy_test_message_reset_counters();
239238

240-
arrival_capture_t capture{};
239+
arrival_capture_t capture{};
241240
cy_subscriber_t* const sub = cy_subscribe_ordered(&platform.cy, wkv_key("rx/ord"), 256U, 10);
242241
TEST_ASSERT_NOT_NULL(sub);
243242

tests/src/test_intrusive_dedup.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ static void dedup_fixture_init(dedup_fixture_t* const self)
2929
static void dedup_owner_init(cy_topic_t* const owner, dedup_fixture_t* const fixture)
3030
{
3131
memset(owner, 0, sizeof(*owner));
32-
owner->cy = &fixture->cy;
32+
owner->cy = &fixture->cy;
3333
owner->sub_index_dedup_by_remote_id = NULL;
34-
owner->sub_list_dedup_by_recency = LIST_EMPTY;
34+
owner->sub_list_dedup_by_recency = LIST_EMPTY;
3535
}
3636

37-
static dedup_t* dedup_make_state(cy_topic_t* const owner, const uint64_t remote_id, const uint64_t tag, const cy_us_t now)
37+
static dedup_t* dedup_make_state(cy_topic_t* const owner,
38+
const uint64_t remote_id,
39+
const uint64_t tag,
40+
const cy_us_t now)
3841
{
3942
dedup_factory_context_t ctx = { .owner = owner, .remote_id = remote_id, .tag = tag, .now = now };
4043
cy_tree_t* const tree = dedup_factory(&ctx);

tests/src/test_intrusive_reordering.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ static void* fixture_realloc(cy_t* const cy, void* const ptr, const size_t size)
3838
return realloc(ptr, size);
3939
}
4040

41-
static cy_us_t fixture_now(const cy_t* const cy)
42-
{
43-
return ((const reorder_fixture_t*)cy)->now;
44-
}
41+
static cy_us_t fixture_now(const cy_t* const cy) { return ((const reorder_fixture_t*)cy)->now; }
4542

4643
static void on_arrival(cy_subscriber_t* const sub, const cy_arrival_t arrival)
4744
{
@@ -64,27 +61,27 @@ static void reorder_env_init(reorder_env_t* const self)
6461

6562
self->root.cy = &self->fixture.cy;
6663

67-
self->sub.root = &self->root;
68-
self->sub.params.extent = 0;
69-
self->sub.params.reordering_window = 20;
70-
self->sub.params.reordering_capacity = 8;
64+
self->sub.root = &self->root;
65+
self->sub.params.extent = 0;
66+
self->sub.params.reordering_window = 20;
67+
self->sub.params.reordering_capacity = 8;
7168
self->sub.index_reordering_by_remote_id = NULL;
72-
self->sub.list_reordering_by_recency = LIST_EMPTY;
73-
self->sub.callback = on_arrival;
74-
self->sub.user_context = CY_USER_CONTEXT_EMPTY;
75-
self->sub.user_context.ptr[0] = &self->capture;
69+
self->sub.list_reordering_by_recency = LIST_EMPTY;
70+
self->sub.callback = on_arrival;
71+
self->sub.user_context = CY_USER_CONTEXT_EMPTY;
72+
self->sub.user_context.ptr[0] = &self->capture;
7673

7774
self->topic.cy = &self->fixture.cy;
7875
self->topic.hash = 0xABCDEFULL;
7976

80-
self->rr.timeout = OLGA_EVENT_INIT;
81-
self->rr.remote_id = 42U;
82-
self->rr.subscriber = &self->sub;
83-
self->rr.topic = &self->topic;
84-
self->rr.substitutions.count = 0;
77+
self->rr.timeout = OLGA_EVENT_INIT;
78+
self->rr.remote_id = 42U;
79+
self->rr.subscriber = &self->sub;
80+
self->rr.topic = &self->topic;
81+
self->rr.substitutions.count = 0;
8582
self->rr.substitutions.substitutions = NULL;
86-
self->rr.interned_count = 0;
87-
self->rr.interned_by_lin_tag = NULL;
83+
self->rr.interned_count = 0;
84+
self->rr.interned_by_lin_tag = NULL;
8885
reordering_resequence(&self->rr, 8U);
8986
}
9087

0 commit comments

Comments
 (0)